]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQIntField.cc
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[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( minValue, maxValue,
54                                 1, // step
55                                 this );
56     YUI_CHECK_NEW( _qt_spinBox );
57     layout->addWidget( _qt_spinBox );
58
59     _qt_spinBox->setValue( initialValue );
60
61     _caption->setBuddy( _qt_spinBox );
62
63     setValue( initialValue );
64
65     connect( _qt_spinBox, SIGNAL( valueChanged    ( int ) ),
66              this,        SLOT  ( valueChangedSlot( int ) ) );
67 }
68
69
70 YQIntField::~YQIntField()
71 {
72     // NOP
73 }
74
75
76 int
77 YQIntField::value()
78 {
79     return _qt_spinBox->value();
80 }
81
82
83 void
84 YQIntField::setValueInternal( int newValue )
85 {
86     YQSignalBlocker sigBlocker( _qt_spinBox );
87     _qt_spinBox->setValue( newValue );
88 }
89
90
91 void
92 YQIntField::valueChangedSlot( int newValue )
93 {
94     if ( notify() )
95         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
96     emit valueChanged( newValue );
97 }
98
99
100 void
101 YQIntField::setLabel( const string & newLabel )
102 {
103     YIntField::setLabel( newLabel );
104     _caption->setText( newLabel );
105 }
106
107
108 void
109 YQIntField::setEnabled( bool enabled )
110 {
111     _caption->setEnabled  ( enabled );
112     _qt_spinBox->setEnabled( enabled );
113     YWidget::setEnabled( enabled );
114 }
115
116
117 int
118 YQIntField::preferredWidth()
119 {
120     return sizeHint().width();
121 }
122
123
124 int
125 YQIntField::preferredHeight()
126 {
127     return sizeHint().height();
128 }
129
130
131 void
132 YQIntField::setSize( int newWidth, int newHeight )
133 {
134     resize( newWidth, newHeight );
135 }
136
137
138 bool
139 YQIntField::setKeyboardFocus()
140 {
141     _qt_spinBox->setFocus();
142
143     return true;
144 }
145
146
147 #include "YQIntField.moc"