libyui-qt  2.52.4
YQIntField.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQIntField.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #include <qspinbox.h>
27 
28 #define YUILogComponent "qt-ui"
29 #include <yui/YUILog.h>
30 
31 #include "utf8.h"
32 #include "YQUI.h"
33 #include <yui/YEvent.h>
34 #include "YQIntField.h"
35 #include "YQSignalBlocker.h"
36 #include "YQWidgetCaption.h"
37 #include <QVBoxLayout>
38 
39 using std::string;
40 
41 
42 
43 YQIntField::YQIntField( YWidget * parent,
44  const string & label,
45  int minValue,
46  int maxValue,
47  int initialValue )
48  : QFrame( (QWidget *) parent->widgetRep() )
49  , YIntField( parent, label, minValue, maxValue )
50 {
51  QVBoxLayout* layout = new QVBoxLayout( this );
52  setLayout( layout );
53 
54  setWidgetRep( this );
55 
56  layout->setSpacing( YQWidgetSpacing );
57  layout->setMargin( YQWidgetMargin );
58 
59  _caption = new YQWidgetCaption( this, label );
60  YUI_CHECK_NEW( _caption );
61  layout->addWidget( _caption );
62 
63  _qt_spinBox = new QSpinBox(this);
64  _qt_spinBox->setMinimum(minValue);
65  _qt_spinBox->setMaximum(maxValue);
66  _qt_spinBox->setSingleStep(1);
67 
68  YUI_CHECK_NEW( _qt_spinBox );
69  layout->addWidget( _qt_spinBox );
70 
71  _qt_spinBox->setValue( initialValue );
72 
73  _caption->setBuddy( _qt_spinBox );
74 
75  setValue( initialValue );
76 
77  connect( _qt_spinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
78  this, &pclass(this)::valueChangedSlot );
79 }
80 
81 
83 {
84  // NOP
85 }
86 
87 
88 int
90 {
91  return _qt_spinBox->value();
92 }
93 
94 
95 void
97 {
98  YQSignalBlocker sigBlocker( _qt_spinBox );
99  _qt_spinBox->setValue( newValue );
100 }
101 
102 
103 void
105 {
106  if ( notify() )
107  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
108  emit valueChanged( newValue );
109 }
110 
111 
112 void
113 YQIntField::setLabel( const string & newLabel )
114 {
115  YIntField::setLabel( newLabel );
116  _caption->setText( newLabel );
117 }
118 
119 
120 void
121 YQIntField::setEnabled( bool enabled )
122 {
123  _caption->setEnabled ( enabled );
124  _qt_spinBox->setEnabled( enabled );
125  YWidget::setEnabled( enabled );
126 }
127 
128 
129 int
131 {
132  return sizeHint().width();
133 }
134 
135 
136 int
138 {
139  return sizeHint().height();
140 }
141 
142 
143 void
144 YQIntField::setSize( int newWidth, int newHeight )
145 {
146  resize( newWidth, newHeight );
147 }
148 
149 
150 bool
152 {
153  _qt_spinBox->setFocus();
154 
155  return true;
156 }
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQIntField.cc:151
virtual void setValueInternal(int val)
Set the current value (the number entered by the user or set from the outside) of this IntField...
Definition: YQIntField.cc:96
virtual void setText(const std::string &newText)
Change the text and handle visibility: If the new text is empty, hide this widget.
virtual int value()
Get the current value (the number entered by the user or set from the outside) of this IntField...
Definition: YQIntField.cc:89
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
Definition: YQUI.cc:480
virtual void setEnabled(bool enabled)
Sets the widget&#39;s enabled state.
Definition: YQIntField.cc:121
void valueChanged(int newValue)
Emitted when the value changes (regardless of the notify flag).
void valueChangedSlot(int newValue)
Slot for "value changed".
Definition: YQIntField.cc:104
virtual ~YQIntField()
Destructor.
Definition: YQIntField.cc:82
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
Definition: YQIntField.cc:113
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQIntField.cc:137
YQIntField(YWidget *parent, const std::string &label, int minValue, int maxValue, int initialValue)
Constructor.
Definition: YQIntField.cc:43
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQIntField.cc:130
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:83
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQIntField.cc:144