1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
22 #include <QVBoxLayout>
24 #define y2log_component "qt-ui"
25 #include <ycp/y2log.h>
31 #include "YQSignalBlocker.h"
32 #include "YQWidgetCaption.h"
35 YQSlider::YQSlider( YWidget * parent,
42 : QFrame( (QWidget *) parent->widgetRep() )
43 , YSlider( parent, label, minValue, maxValue )
47 QVBoxLayout* layout = new QVBoxLayout( this );
50 layout->setSpacing( YQWidgetSpacing );
51 layout->setMargin ( YQWidgetMargin );
53 _caption = new YQWidgetCaption( this, label );
54 YUI_CHECK_NEW( _caption );
55 layout->addWidget( _caption );
57 _hbox = new QFrame( this );
58 YUI_CHECK_NEW( _hbox );
59 layout->addWidget( _hbox );
61 layout = new QVBoxLayout( _hbox );
62 _hbox->setLayout( layout );
64 layout->setMargin ( YQWidgetMargin );
65 layout->setSpacing( YQWidgetSpacing );
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 );
77 _caption->setAlignment( Qt::AlignRight );
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 );
87 if ( ! reverseLayout )
89 _qt_spinBox = new QSpinBox( _hbox );
90 _qt_spinBox->setMinimum(minValue);
91 _qt_spinBox->setMaximum(maxValue);
92 _qt_spinBox->setSingleStep(1);
94 layout->addWidget( _qt_spinBox );
96 YUI_CHECK_NEW( _qt_spinBox );
98 _qt_spinBox->setValue( initialValue );
99 _caption->setBuddy( _qt_spinBox );
101 setValue( initialValue );
103 connect( _qt_spinBox, SIGNAL( valueChanged(int) ),
104 _qt_slider, SLOT ( setValue (int) ) );
106 connect( _qt_slider, SIGNAL( valueChanged(int) ),
107 _qt_spinBox, SLOT ( setValue (int) ) );
109 connect( _qt_spinBox, SIGNAL( valueChanged (int) ),
110 this, SLOT ( valueChangedSlot(int) ) );
114 YQSlider::~YQSlider()
123 return _qt_spinBox->value();
128 YQSlider::setValueInternal( int newValue )
130 YQSignalBlocker sigBlocker1( _qt_spinBox );
131 YQSignalBlocker sigBlocker2( _qt_slider );
132 _qt_slider->setValue ( newValue );
133 _qt_spinBox->setValue( newValue );
138 YQSlider::valueChangedSlot( int newValue )
141 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
143 emit valueChanged( newValue );
148 YQSlider::setEnabled( bool enabled )
150 _caption->setEnabled ( enabled );
151 _qt_slider->setEnabled ( enabled );
152 _qt_spinBox->setEnabled( enabled );
153 YWidget::setEnabled( enabled );
158 YQSlider::preferredWidth()
160 int hintWidth = !_caption->isHidden() ? _caption->sizeHint().width() : 0;
162 // Arbitrary value - there is no really good default
163 return max( 200, hintWidth );
168 YQSlider::preferredHeight()
170 return sizeHint().height();
175 YQSlider::setSize( int newWidth, int newHeight )
177 resize( newWidth, newHeight );
182 YQSlider::setLabel( const string & newLabel )
184 _caption->setText( newLabel );
185 YSlider::setLabel( newLabel );
190 YQSlider::setKeyboardFocus()
192 _qt_spinBox->setFocus();
198 #include "YQSlider.moc"