libyui-qt  2.47.1.1
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 YQIntField::YQIntField( YWidget * parent,
40  const std::string & label,
41  int minValue,
42  int maxValue,
43  int initialValue )
44  : QFrame( (QWidget *) parent->widgetRep() )
45  , YIntField( parent, label, minValue, maxValue )
46 {
47  QVBoxLayout* layout = new QVBoxLayout( this );
48  setLayout( layout );
49 
50  setWidgetRep( this );
51 
52  layout->setSpacing( YQWidgetSpacing );
53  layout->setMargin( YQWidgetMargin );
54 
55  _caption = new YQWidgetCaption( this, label );
56  YUI_CHECK_NEW( _caption );
57  layout->addWidget( _caption );
58 
59  _qt_spinBox = new QSpinBox(this);
60  _qt_spinBox->setMinimum(minValue);
61  _qt_spinBox->setMaximum(maxValue);
62  _qt_spinBox->setSingleStep(1);
63 
64  YUI_CHECK_NEW( _qt_spinBox );
65  layout->addWidget( _qt_spinBox );
66 
67  _qt_spinBox->setValue( initialValue );
68 
69  _caption->setBuddy( _qt_spinBox );
70 
71  setValue( initialValue );
72 
73  connect( _qt_spinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
74  this, &pclass(this)::valueChangedSlot );
75 }
76 
77 
79 {
80  // NOP
81 }
82 
83 
84 int
86 {
87  return _qt_spinBox->value();
88 }
89 
90 
91 void
93 {
94  YQSignalBlocker sigBlocker( _qt_spinBox );
95  _qt_spinBox->setValue( newValue );
96 }
97 
98 
99 void
101 {
102  if ( notify() )
103  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
104  emit valueChanged( newValue );
105 }
106 
107 
108 void
109 YQIntField::setLabel( const std::string & newLabel )
110 {
111  YIntField::setLabel( newLabel );
112  _caption->setText( newLabel );
113 }
114 
115 
116 void
117 YQIntField::setEnabled( bool enabled )
118 {
119  _caption->setEnabled ( enabled );
120  _qt_spinBox->setEnabled( enabled );
121  YWidget::setEnabled( enabled );
122 }
123 
124 
125 int
127 {
128  return sizeHint().width();
129 }
130 
131 
132 int
134 {
135  return sizeHint().height();
136 }
137 
138 
139 void
140 YQIntField::setSize( int newWidth, int newHeight )
141 {
142  resize( newWidth, newHeight );
143 }
144 
145 
146 bool
148 {
149  _qt_spinBox->setFocus();
150 
151  return true;
152 }
153 
154 
155 #include "YQIntField.moc"
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:147
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:92
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:85
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:494
virtual void setEnabled(bool enabled)
Sets the widget&#39;s enabled state.
Definition: YQIntField.cc:117
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:100
virtual ~YQIntField()
Destructor.
Definition: YQIntField.cc:78
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:109
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQIntField.cc:133
YQIntField(YWidget *parent, const std::string &label, int minValue, int maxValue, int initialValue)
Constructor.
Definition: YQIntField.cc:39
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQIntField.cc:126
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:80
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQIntField.cc:140