28 #include <QVBoxLayout>
30 #define YUILogComponent "qt-ui"
31 #include <yui/YUILog.h>
35 #include <yui/YEvent.h>
37 #include "YQSignalBlocker.h"
38 #include "YQWidgetCaption.h"
50 : QFrame( (QWidget *) parent->widgetRep() )
51 , YSlider( parent, label, minValue, maxValue )
55 QVBoxLayout* toplayout =
new QVBoxLayout(
this );
56 setLayout( toplayout );
58 toplayout->setSpacing( YQWidgetSpacing );
59 toplayout->setMargin ( YQWidgetMargin );
62 YUI_CHECK_NEW( _caption );
63 toplayout->addWidget( _caption );
65 _hbox =
new QFrame(
this );
66 YUI_CHECK_NEW( _hbox );
67 toplayout->addWidget( _hbox );
69 QHBoxLayout *layout =
new QHBoxLayout( _hbox );
70 _hbox->setLayout( layout );
72 layout->setMargin ( YQWidgetMargin );
73 layout->setSpacing( YQWidgetSpacing );
77 _qt_spinBox =
new QSpinBox( _hbox );
78 _qt_spinBox->setMinimum(minValue);
79 _qt_spinBox->setMaximum(maxValue);
80 _qt_spinBox->setSingleStep(1);
81 layout->addWidget( _qt_spinBox );
85 _caption->setAlignment( Qt::AlignRight );
88 _qt_slider =
new QSlider( Qt::Horizontal, _hbox );
89 _qt_slider->setMinimum(minValue);
90 _qt_slider->setMaximum(maxValue);
91 _qt_slider->setPageStep(1);
92 YUI_CHECK_NEW( _qt_slider );
93 layout->addWidget( _qt_slider );
95 if ( ! reverseLayout )
97 _qt_spinBox =
new QSpinBox( _hbox );
98 _qt_spinBox->setMinimum(minValue);
99 _qt_spinBox->setMaximum(maxValue);
100 _qt_spinBox->setSingleStep(1);
102 layout->addWidget( _qt_spinBox );
104 YUI_CHECK_NEW( _qt_spinBox );
106 _qt_spinBox->setValue( initialValue );
107 _caption->setBuddy( _qt_spinBox );
109 setValue( initialValue );
111 connect( _qt_spinBox,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
112 _qt_slider, &pclass(_qt_slider)::setValue );
115 _qt_spinBox, &pclass(_qt_spinBox)::setValue );
117 connect( _qt_spinBox,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
131 return _qt_spinBox->value();
140 _qt_slider->setValue ( newValue );
141 _qt_spinBox->setValue( newValue );
158 _caption->setEnabled ( enabled );
159 _qt_slider->setEnabled ( enabled );
160 _qt_spinBox->setEnabled( enabled );
161 YWidget::setEnabled( enabled );
168 int hintWidth = !_caption->isHidden() ? _caption->sizeHint().width() : 0;
171 return std::max( 200, hintWidth );
178 return sizeHint().height();
185 resize( newWidth, newHeight );
193 YSlider::setLabel( newLabel );
200 _qt_spinBox->setFocus();
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
virtual void setValueInternal(int val)
Set the current value (the number entered by the user or set from the outside) of this slider.
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual int preferredWidth()
Preferred width of the widget.
YQSlider(YWidget *parent, const std::string &label, int minValue, int maxValue, int initialValue, bool reverseLayout=false)
Constructor.
virtual int preferredHeight()
Preferred height of the widget.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual ~YQSlider()
Destructor.
void valueChanged(int newValue)
Emitted when the value changes (regardless of the notify flag).
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual int value()
Get the current value (the number entered by the user or set from the outside) of this slider.
void valueChangedSlot(int newValue)
Slot for "value changed".
static YQUI * ui()
Access the global Qt-UI.
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...