1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
23 #include <QVBoxLayout>
25 #define y2log_component "qt-ui"
26 #include <ycp/y2log.h>
32 #include "YQSignalBlocker.h"
33 #include "YQWidgetCaption.h"
36 YQSlider::YQSlider( YWidget * parent,
43 : QFrame( (QWidget *) parent->widgetRep() )
44 , YSlider( parent, label, minValue, maxValue )
48 QVBoxLayout* layout = new QVBoxLayout( this );
51 layout->setSpacing( YQWidgetSpacing );
52 layout->setMargin ( YQWidgetMargin );
54 _caption = new YQWidgetCaption( this, label );
55 YUI_CHECK_NEW( _caption );
56 layout->addWidget( _caption );
58 _hbox = new QFrame( this );
59 YUI_CHECK_NEW( _hbox );
60 layout->addWidget( _hbox );
62 layout = new QVBoxLayout( _hbox );
63 _hbox->setLayout( layout );
65 layout->setMargin ( YQWidgetMargin );
66 layout->setSpacing( YQWidgetSpacing );
70 _qt_spinBox = new QSpinBox( minValue, maxValue,
73 layout->addWidget( _qt_spinBox );
77 _caption->setAlignment( Qt::AlignRight );
80 _qt_slider = new QSlider( minValue, maxValue,
83 Qt::Horizontal, _hbox );
84 YUI_CHECK_NEW( _qt_slider );
85 layout->addWidget( _qt_slider );
87 if ( ! reverseLayout )
89 _qt_spinBox = new QSpinBox( minValue, maxValue,
92 layout->addWidget( _qt_spinBox );
94 YUI_CHECK_NEW( _qt_spinBox );
96 _qt_spinBox->setValue( initialValue );
97 _caption->setBuddy( _qt_spinBox );
99 setValue( initialValue );
101 connect( _qt_spinBox, SIGNAL( valueChanged(int) ),
102 _qt_slider, SLOT ( setValue (int) ) );
104 connect( _qt_slider, SIGNAL( valueChanged(int) ),
105 _qt_spinBox, SLOT ( setValue (int) ) );
107 connect( _qt_spinBox, SIGNAL( valueChanged (int) ),
108 this, SLOT ( valueChangedSlot(int) ) );
112 YQSlider::~YQSlider()
121 return _qt_spinBox->value();
126 YQSlider::setValueInternal( int newValue )
128 YQSignalBlocker sigBlocker1( _qt_spinBox );
129 YQSignalBlocker sigBlocker2( _qt_slider );
130 _qt_slider->setValue ( newValue );
131 _qt_spinBox->setValue( newValue );
136 YQSlider::valueChangedSlot( int newValue )
139 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
141 emit valueChanged( newValue );
146 YQSlider::setEnabled( bool enabled )
148 _caption->setEnabled ( enabled );
149 _qt_slider->setEnabled ( enabled );
150 _qt_spinBox->setEnabled( enabled );
151 YWidget::setEnabled( enabled );
156 YQSlider::preferredWidth()
158 int hintWidth = _caption->isShown() ? _caption->sizeHint().width() : 0;
160 // Arbitrary value - there is no really good default
161 return max( 200, hintWidth );
166 YQSlider::preferredHeight()
168 return sizeHint().height();
173 YQSlider::setSize( int newWidth, int newHeight )
175 resize( newWidth, newHeight );
180 YQSlider::setLabel( const string & newLabel )
182 _caption->setText( newLabel );
183 YSlider::setLabel( newLabel );
188 YQSlider::setKeyboardFocus()
190 _qt_spinBox->setFocus();
196 #include "YQSlider.moc"