]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQIntField.cc
remove one FIXME
[duncan/yast2-qt4.git] / src / YQIntField.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQIntField.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #include <qspinbox.h>
21
22 #define y2log_component "qt-ui"
23 #include <ycp/y2log.h>
24
25 #include "utf8.h"
26 #include "YQUI.h"
27 #include "YEvent.h"
28 #include "YQIntField.h"
29 #include "YQSignalBlocker.h"
30 #include "YQWidgetCaption.h"
31 #include <QVBoxLayout>
32
33 YQIntField::YQIntField( YWidget *       parent,
34                         const string &  label,
35                         int             minValue,
36                         int             maxValue,
37                         int             initialValue )
38     : QFrame( (QWidget *) parent->widgetRep() )
39     , YIntField( parent, label, minValue, maxValue )
40 {
41     QVBoxLayout* layout = new QVBoxLayout( this );
42     setLayout( layout );
43
44     setWidgetRep( this );
45
46     layout->setSpacing( YQWidgetSpacing );
47     layout->setMargin( YQWidgetMargin );
48
49     _caption    = new YQWidgetCaption( this, label );
50     YUI_CHECK_NEW( _caption );
51     layout->addWidget( _caption );
52
53     _qt_spinBox = new QSpinBox(this);
54     _qt_spinBox->setMinimum(minValue);
55     _qt_spinBox->setMaximum(maxValue);
56     _qt_spinBox->setSingleStep(1);
57
58     YUI_CHECK_NEW( _qt_spinBox );
59     layout->addWidget( _qt_spinBox );
60
61     _qt_spinBox->setValue( initialValue );
62
63     _caption->setBuddy( _qt_spinBox );
64
65     setValue( initialValue );
66
67     connect( _qt_spinBox, SIGNAL( valueChanged    ( int ) ),
68              this,        SLOT  ( valueChangedSlot( int ) ) );
69 }
70
71
72 YQIntField::~YQIntField()
73 {
74     // NOP
75 }
76
77
78 int
79 YQIntField::value()
80 {
81     return _qt_spinBox->value();
82 }
83
84
85 void
86 YQIntField::setValueInternal( int newValue )
87 {
88     YQSignalBlocker sigBlocker( _qt_spinBox );
89     _qt_spinBox->setValue( newValue );
90 }
91
92
93 void
94 YQIntField::valueChangedSlot( int newValue )
95 {
96     if ( notify() )
97         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
98     emit valueChanged( newValue );
99 }
100
101
102 void
103 YQIntField::setLabel( const string & newLabel )
104 {
105     YIntField::setLabel( newLabel );
106     _caption->setText( newLabel );
107 }
108
109
110 void
111 YQIntField::setEnabled( bool enabled )
112 {
113     _caption->setEnabled  ( enabled );
114     _qt_spinBox->setEnabled( enabled );
115     YWidget::setEnabled( enabled );
116 }
117
118
119 int
120 YQIntField::preferredWidth()
121 {
122     return sizeHint().width();
123 }
124
125
126 int
127 YQIntField::preferredHeight()
128 {
129     return sizeHint().height();
130 }
131
132
133 void
134 YQIntField::setSize( int newWidth, int newHeight )
135 {
136     resize( newWidth, newHeight );
137 }
138
139
140 bool
141 YQIntField::setKeyboardFocus()
142 {
143     _qt_spinBox->setFocus();
144
145     return true;
146 }
147
148
149 #include "YQIntField.moc"