]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQSlider.cc
don't reset the changes file
[duncan/yast2-qt4.git] / src / YQSlider.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQSlider.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19 #include <QSlider>
20 #include <QSpinBox>
21 #include <QLabel>
22 #include <QVBoxLayout>
23
24 #define y2log_component "qt-ui"
25 #include <ycp/y2log.h>
26
27 #include "utf8.h"
28 #include "YQUI.h"
29 #include "YEvent.h"
30 #include "YQSlider.h"
31 #include "YQSignalBlocker.h"
32 #include "YQWidgetCaption.h"
33
34
35 YQSlider::YQSlider( YWidget *           parent,
36                     const string &      label,
37                     int                 minValue,
38                     int                 maxValue,
39                     int                 initialValue,
40                     bool                reverseLayout )
41
42     : QFrame( (QWidget *) parent->widgetRep() )
43     , YSlider( parent, label, minValue, maxValue )
44 {
45     setWidgetRep( this );
46
47     QVBoxLayout* layout = new QVBoxLayout( this );
48     setLayout( layout );
49
50     layout->setSpacing( YQWidgetSpacing );
51     layout->setMargin ( YQWidgetMargin );
52
53     _caption = new YQWidgetCaption( this, label );
54     YUI_CHECK_NEW( _caption );
55     layout->addWidget( _caption );
56
57     _hbox = new QFrame( this );
58     YUI_CHECK_NEW( _hbox );
59     layout->addWidget( _hbox );
60
61     layout = new QVBoxLayout( _hbox );
62     _hbox->setLayout( layout );
63
64     layout->setMargin ( YQWidgetMargin );
65     layout->setSpacing( YQWidgetSpacing );
66
67     if ( reverseLayout )
68     {
69         _qt_spinBox = new QSpinBox( _hbox );
70         _qt_spinBox->setMinimum(minValue);
71         _qt_spinBox->setMaximum(maxValue);
72         _qt_spinBox->setSingleStep(1);
73         layout->addWidget( _qt_spinBox );
74     }
75     else
76     {
77         _caption->setAlignment( Qt::AlignRight );
78     }
79
80     _qt_slider = new QSlider( Qt::Horizontal, _hbox );
81     _qt_slider->setMinimum(minValue);
82     _qt_slider->setMaximum(maxValue);
83     _qt_slider->setPageStep(1);
84     YUI_CHECK_NEW( _qt_slider );
85     layout->addWidget( _qt_slider );
86
87     if ( ! reverseLayout )
88     {
89         _qt_spinBox = new QSpinBox( _hbox );
90         _qt_spinBox->setMinimum(minValue);
91         _qt_spinBox->setMaximum(maxValue);
92         _qt_spinBox->setSingleStep(1);
93       
94         layout->addWidget( _qt_spinBox );
95     }
96     YUI_CHECK_NEW( _qt_spinBox );
97
98     _qt_spinBox->setValue( initialValue );
99     _caption->setBuddy( _qt_spinBox );
100
101     setValue( initialValue );
102
103     connect( _qt_spinBox, SIGNAL( valueChanged(int) ),
104              _qt_slider,  SLOT  ( setValue    (int) ) );
105
106     connect( _qt_slider,  SIGNAL( valueChanged(int) ),
107              _qt_spinBox, SLOT  ( setValue    (int) ) );
108
109     connect( _qt_spinBox, SIGNAL( valueChanged    (int) ),
110              this,        SLOT  ( valueChangedSlot(int) ) );
111 }
112
113
114 YQSlider::~YQSlider()
115 {
116     // NOP
117 }
118
119
120 int
121 YQSlider::value()
122 {
123     return _qt_spinBox->value();
124 }
125
126
127 void
128 YQSlider::setValueInternal( int newValue )
129 {
130     YQSignalBlocker sigBlocker1( _qt_spinBox );
131     YQSignalBlocker sigBlocker2( _qt_slider  );
132     _qt_slider->setValue ( newValue );
133     _qt_spinBox->setValue( newValue );
134 }
135
136
137 void
138 YQSlider::valueChangedSlot( int newValue )
139 {
140     if ( notify() )
141         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
142
143     emit valueChanged( newValue );
144 }
145
146
147 void
148 YQSlider::setEnabled( bool enabled )
149 {
150     _caption->setEnabled  ( enabled );
151     _qt_slider->setEnabled ( enabled );
152     _qt_spinBox->setEnabled( enabled );
153     YWidget::setEnabled( enabled );
154 }
155
156
157 int
158 YQSlider::preferredWidth()
159 {
160     int hintWidth = !_caption->isHidden() ? _caption->sizeHint().width() : 0;
161
162     // Arbitrary value - there is no really good default
163     return max( 200, hintWidth );
164 }
165
166
167 int
168 YQSlider::preferredHeight()
169 {
170     return sizeHint().height();
171 }
172
173
174 void
175 YQSlider::setSize( int newWidth, int newHeight )
176 {
177     resize( newWidth, newHeight );
178 }
179
180
181 void
182 YQSlider::setLabel( const string & newLabel )
183 {
184     _caption->setText( newLabel );
185     YSlider::setLabel( newLabel );
186 }
187
188
189 bool
190 YQSlider::setKeyboardFocus()
191 {
192     _qt_spinBox->setFocus();
193
194     return true;
195 }
196
197
198 #include "YQSlider.moc"