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" 42 const std::string & label,
48 : QFrame( (QWidget *) parent->widgetRep() )
49 , YSlider( parent, label, minValue, maxValue )
53 QVBoxLayout* toplayout =
new QVBoxLayout(
this );
54 setLayout( toplayout );
56 toplayout->setSpacing( YQWidgetSpacing );
57 toplayout->setMargin ( YQWidgetMargin );
60 YUI_CHECK_NEW( _caption );
61 toplayout->addWidget( _caption );
63 _hbox =
new QFrame(
this );
64 YUI_CHECK_NEW( _hbox );
65 toplayout->addWidget( _hbox );
67 QHBoxLayout *layout =
new QHBoxLayout( _hbox );
68 _hbox->setLayout( layout );
70 layout->setMargin ( YQWidgetMargin );
71 layout->setSpacing( YQWidgetSpacing );
75 _qt_spinBox =
new QSpinBox( _hbox );
76 _qt_spinBox->setMinimum(minValue);
77 _qt_spinBox->setMaximum(maxValue);
78 _qt_spinBox->setSingleStep(1);
79 layout->addWidget( _qt_spinBox );
83 _caption->setAlignment( Qt::AlignRight );
86 _qt_slider =
new QSlider( Qt::Horizontal, _hbox );
87 _qt_slider->setMinimum(minValue);
88 _qt_slider->setMaximum(maxValue);
89 _qt_slider->setPageStep(1);
90 YUI_CHECK_NEW( _qt_slider );
91 layout->addWidget( _qt_slider );
93 if ( ! reverseLayout )
95 _qt_spinBox =
new QSpinBox( _hbox );
96 _qt_spinBox->setMinimum(minValue);
97 _qt_spinBox->setMaximum(maxValue);
98 _qt_spinBox->setSingleStep(1);
100 layout->addWidget( _qt_spinBox );
102 YUI_CHECK_NEW( _qt_spinBox );
104 _qt_spinBox->setValue( initialValue );
105 _caption->setBuddy( _qt_spinBox );
107 setValue( initialValue );
109 connect( _qt_spinBox,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
110 _qt_slider, &pclass(_qt_slider)::setValue );
113 _qt_spinBox, &pclass(_qt_spinBox)::setValue );
115 connect( _qt_spinBox,
static_cast<void (QSpinBox::*)(
int)
>(&QSpinBox::valueChanged),
129 return _qt_spinBox->value();
138 _qt_slider->setValue ( newValue );
139 _qt_spinBox->setValue( newValue );
156 _caption->setEnabled ( enabled );
157 _qt_slider->setEnabled ( enabled );
158 _qt_spinBox->setEnabled( enabled );
159 YWidget::setEnabled( enabled );
166 int hintWidth = !_caption->isHidden() ? _caption->sizeHint().width() : 0;
169 return std::max( 200, hintWidth );
176 return sizeHint().height();
183 resize( newWidth, newHeight );
191 YSlider::setLabel( newLabel );
198 _qt_spinBox->setFocus();
204 #include "YQSlider.moc" Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
virtual ~YQSlider()
Destructor.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
void valueChangedSlot(int newValue)
Slot for "value changed".
virtual int preferredWidth()
Preferred width of the widget.
virtual int preferredHeight()
Preferred height of the widget.
YQSlider(YWidget *parent, const std::string &label, int minValue, int maxValue, int initialValue, bool reverseLayout=false)
Constructor.
virtual int value()
Get the current value (the number entered by the user or set from the outside) of this slider...
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
void valueChanged(int newValue)
Emitted when the value changes (regardless of the notify flag).
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
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 setEnabled(bool enabled)
Set enabled/disabled state.
static YQUI * ui()
Access the global Qt-UI.