1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
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 : QVBox( (QWidget *) parent->widgetRep() )
44 , YSlider( parent, label, minValue, maxValue )
48 setSpacing( YQWidgetSpacing );
49 setMargin ( YQWidgetMargin );
51 _caption = new YQWidgetCaption( this, toUTF8( label ) );
52 YUI_CHECK_NEW( _caption );
54 _hbox = new QHBox( this );
55 YUI_CHECK_NEW( _hbox );
57 _hbox->setSpacing( YQWidgetSpacing );
61 _qt_spinBox = new QSpinBox( minValue, maxValue,
67 _caption->setAlignment( Qt::AlignRight );
70 _qt_slider = new QSlider( minValue, maxValue,
73 QSlider::Horizontal, _hbox );
74 YUI_CHECK_NEW( _qt_slider );
76 if ( ! reverseLayout )
78 _qt_spinBox = new QSpinBox( minValue, maxValue,
82 YUI_CHECK_NEW( _qt_spinBox );
84 _qt_spinBox->setValue( initialValue );
85 _caption->setBuddy( _qt_spinBox );
87 setValue( initialValue );
89 connect( _qt_spinBox, SIGNAL( valueChanged(int) ),
90 _qt_slider, SLOT ( setValue (int) ) );
92 connect( _qt_slider, SIGNAL( valueChanged(int) ),
93 _qt_spinBox, SLOT ( setValue (int) ) );
95 connect( _qt_spinBox, SIGNAL( valueChanged (int) ),
96 this, SLOT ( valueChangedSlot(int) ) );
100 YQSlider::~YQSlider()
109 return _qt_spinBox->value();
114 YQSlider::setValueInternal( int newValue )
116 YQSignalBlocker sigBlocker1( _qt_spinBox );
117 YQSignalBlocker sigBlocker2( _qt_slider );
118 _qt_slider->setValue ( newValue );
119 _qt_spinBox->setValue( newValue );
124 YQSlider::valueChangedSlot( int newValue )
127 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
129 emit valueChanged( newValue );
134 YQSlider::setEnabled( bool enabled )
136 _caption->setEnabled ( enabled );
137 _qt_slider->setEnabled ( enabled );
138 _qt_spinBox->setEnabled( enabled );
139 YWidget::setEnabled( enabled );
144 YQSlider::preferredWidth()
146 int hintWidth = _caption->isShown() ? _caption->sizeHint().width() : 0;
148 // Arbitrary value - there is no really good default
149 return max( 200, hintWidth );
154 YQSlider::preferredHeight()
156 return sizeHint().height();
161 YQSlider::setSize( int newWidth, int newHeight )
163 resize( newWidth, newHeight );
168 YQSlider::setLabel( const string & newLabel )
170 _caption->setText( newLabel );
171 YSlider::setLabel( newLabel );
176 YQSlider::setKeyboardFocus()
178 _qt_spinBox->setFocus();
184 #include "YQSlider.moc"