An abstract base class for slider widgets. More...
#include <qwt_abstract_slider.h>
Classes | |
class | PrivateData |
Public Types | |
enum | ScrollMode { ScrNone, ScrMouse, ScrTimer, ScrDirect, ScrPage } |
Public Slots | |
virtual void | setValue (double val) |
Move the slider to a specified value. | |
virtual void | fitValue (double val) |
Set the slider's value to the nearest integer multiple of the step size. | |
virtual void | incValue (int steps) |
Increment the value by a specified number of steps. | |
virtual void | setReadOnly (bool) |
Signals | |
void | valueChanged (double value) |
Notify a change of value. | |
void | sliderPressed () |
void | sliderReleased () |
void | sliderMoved (double value) |
Public Member Functions | |
QwtAbstractSlider (Qt::Orientation, QWidget *parent=NULL) | |
Constructor. | |
virtual | ~QwtAbstractSlider () |
Destructor. | |
void | setUpdateTime (int t) |
Specify the update interval for automatic scrolling. | |
void | stopMoving () |
Stop updating if automatic scrolling is active. | |
void | setTracking (bool enable) |
Enables or disables tracking. | |
virtual void | setMass (double val) |
Set the slider's mass for flywheel effect. | |
virtual double | mass () const |
virtual void | setOrientation (Orientation o) |
Orientation | orientation () const |
bool | isReadOnly () const |
bool | isValid () const |
void | setValid (bool valid) |
Protected Member Functions | |
virtual void | setPosition (const QPoint &) |
virtual void | valueChange () |
virtual void | timerEvent (QTimerEvent *e) |
virtual void | mousePressEvent (QMouseEvent *e) |
virtual void | mouseReleaseEvent (QMouseEvent *e) |
virtual void | mouseMoveEvent (QMouseEvent *e) |
virtual void | keyPressEvent (QKeyEvent *e) |
virtual void | wheelEvent (QWheelEvent *e) |
virtual double | getValue (const QPoint &p)=0 |
Determine the value corresponding to a specified poind. | |
virtual void | getScrollMode (const QPoint &p, int &scrollMode, int &direction)=0 |
Determine what to do when the user presses a mouse button. | |
void | setMouseOffset (double) |
double | mouseOffset () const |
int | scrollMode () const |
Properties | |
bool | readOnly |
bool | valid |
double | mass |
Orientation | orientation |
An abstract base class for slider widgets.
QwtAbstractSlider is a base class for slider widgets. It handles mouse events and updates the slider's value accordingly. Derived classes only have to implement the getValue() and getScrollMode() members, and should react to a valueChange(), which normally requires repainting.
Definition at line 28 of file qwt_abstract_slider.h.
QwtAbstractSlider::QwtAbstractSlider | ( | Qt::Orientation | orientation, |
QWidget * | parent = NULL |
||
) | [explicit] |
Constructor.
orientation | Orientation |
parent | Parent widget |
Definition at line 54 of file qwt_abstract_slider.cpp.
References orientation(), and QwtAbstractSlider::PrivateData::orientation.
: QWidget(parent, NULL) { d_data = new QwtAbstractSlider::PrivateData; d_data->orientation = orientation; #if QT_VERSION >= 0x040000 using namespace Qt; #endif setFocusPolicy(TabFocus); }
QwtAbstractSlider::~QwtAbstractSlider | ( | ) | [virtual] |
Destructor.
Definition at line 68 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::tmrID.
void QwtAbstractSlider::fitValue | ( | double | value ) | [virtual, slot] |
Set the slider's value to the nearest integer multiple of the step size.
value | Value |
Reimplemented from QwtDoubleRange.
Definition at line 556 of file qwt_abstract_slider.cpp.
References ScrMouse, QwtAbstractSlider::PrivateData::scrollMode, and stopMoving().
Referenced by mouseReleaseEvent(), setPosition(), and timerEvent().
{ if (d_data->scrollMode == ScrMouse) stopMoving(); QwtDoubleRange::fitValue(value); }
virtual void QwtAbstractSlider::getScrollMode | ( | const QPoint & | p, |
int & | scrollMode, | ||
int & | direction | ||
) | [protected, pure virtual] |
Determine what to do when the user presses a mouse button.
This function is abstract and has to be implemented by derived classes. It is called on a mousePress event. The derived class can determine what should happen next in dependence of the position where the mouse was pressed by returning scrolling mode and direction. QwtAbstractSlider knows the following modes:
p | point where the mouse was pressed |
scrollMode | The scrolling mode |
direction | direction: 1, 0, or -1. |
Implemented in QwtDial, QwtSlider, and QwtWheel.
Referenced by mousePressEvent(), and wheelEvent().
virtual double QwtAbstractSlider::getValue | ( | const QPoint & | p ) | [protected, pure virtual] |
Determine the value corresponding to a specified poind.
This is an abstract virtual function which is called when the user presses or releases a mouse button or moves the mouse. It has to be implemented by the derived class.
p | point |
Implemented in QwtDial, QwtSlider, and QwtWheel.
Referenced by mousePressEvent(), and setPosition().
void QwtAbstractSlider::incValue | ( | int | steps ) | [virtual, slot] |
Increment the value by a specified number of steps.
steps | number of steps |
Reimplemented from QwtDoubleRange.
Definition at line 568 of file qwt_abstract_slider.cpp.
References ScrMouse, QwtAbstractSlider::PrivateData::scrollMode, and stopMoving().
Referenced by QwtDial::keyPressEvent(), and keyPressEvent().
{ if (d_data->scrollMode == ScrMouse) stopMoving(); QwtDoubleRange::incValue(steps); }
bool QwtAbstractSlider::isReadOnly | ( | ) | const |
In read only mode the slider can't be controlled by mouse or keyboard.
Definition at line 98 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::readOnly.
Referenced by QwtDial::drawFocusIndicator(), QwtDial::keyPressEvent(), QwtCompass::keyPressEvent(), keyPressEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and wheelEvent().
{ return d_data->readOnly; }
bool QwtAbstractSlider::isValid | ( | ) | const [inline] |
Reimplemented from QwtDoubleRange.
Definition at line 74 of file qwt_abstract_slider.h.
Referenced by QwtDial::drawContents(), QwtKnob::drawKnob(), QwtAnalogClock::drawNeedle(), QwtCompass::drawScaleContents(), QwtSlider::drawSlider(), QwtDial::keyPressEvent(), keyPressEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and wheelEvent().
void QwtAbstractSlider::keyPressEvent | ( | QKeyEvent * | e ) | [protected, virtual] |
Handles key events
e | Key event |
Reimplemented in QwtCompass, and QwtDial.
Definition at line 377 of file qwt_abstract_slider.cpp.
References incValue(), isReadOnly(), isValid(), mitk::Key_Down, mitk::Key_Left, mitk::Key_Right, mitk::Key_Up, orientation(), QwtDoubleRange::prevValue(), sliderMoved(), and QwtDoubleRange::value().
{ if ( isReadOnly() ) { e->ignore(); return; } if ( !isValid() ) return; int increment = 0; switch ( e->key() ) { case Qt::Key_Down: if ( orientation() == Qt::Vertical ) increment = -1; break; case Qt::Key_Up: if ( orientation() == Qt::Vertical ) increment = 1; break; case Qt::Key_Left: if ( orientation() == Qt::Horizontal ) increment = -1; break; case Qt::Key_Right: if ( orientation() == Qt::Horizontal ) increment = 1; break; default:; e->ignore(); } if ( increment != 0 ) { QwtDoubleRange::incValue(increment); if (value() != prevValue()) emit sliderMoved(value()); } }
virtual double QwtAbstractSlider::mass | ( | ) | const [virtual] |
Reimplemented in QwtWheel.
void QwtAbstractSlider::mouseMoveEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Mouse Move Event handler
e | Mouse event |
Definition at line 311 of file qwt_abstract_slider.cpp.
References QwtDoubleRange::exactPrevValue(), QwtDoubleRange::exactValue(), isReadOnly(), isValid(), QwtAbstractSlider::PrivateData::mass, QwtDoubleRange::prevValue(), ScrMouse, QwtAbstractSlider::PrivateData::scrollMode, setPosition(), sliderMoved(), QwtAbstractSlider::PrivateData::speed, QwtAbstractSlider::PrivateData::time, and QwtDoubleRange::value().
{ if ( isReadOnly() ) { e->ignore(); return; } if ( !isValid() ) return; if (d_data->scrollMode == ScrMouse ) { setPosition(e->pos()); if (d_data->mass > 0.0) { double ms = double(d_data->time.elapsed()); if (ms < 1.0) ms = 1.0; d_data->speed = (exactValue() - exactPrevValue()) / ms; d_data->time.start(); } if (value() != prevValue()) emit sliderMoved(value()); } }
double QwtAbstractSlider::mouseOffset | ( | ) | const [protected] |
Definition at line 580 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::mouseOffset.
Referenced by QwtDial::getValue().
{ return d_data->mouseOffset; }
void QwtAbstractSlider::mousePressEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Mouse press event handler
e | Mouse event |
Definition at line 150 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::direction, getScrollMode(), getValue(), isReadOnly(), isValid(), QwtAbstractSlider::PrivateData::mouseOffset, qwtMax, ScrMouse, QwtAbstractSlider::PrivateData::scrollMode, ScrPage, ScrTimer, sliderPressed(), QwtAbstractSlider::PrivateData::speed, stopMoving(), QwtAbstractSlider::PrivateData::time, QwtAbstractSlider::PrivateData::timerTick, QwtAbstractSlider::PrivateData::tmrID, QwtAbstractSlider::PrivateData::updTime, and QwtDoubleRange::value().
{ if ( isReadOnly() ) { e->ignore(); return; } if ( !isValid() ) return; const QPoint &p = e->pos(); d_data->timerTick = 0; getScrollMode(p, d_data->scrollMode, d_data->direction); stopMoving(); switch(d_data->scrollMode) { case ScrPage: case ScrTimer: d_data->mouseOffset = 0; d_data->tmrID = startTimer(qwtMax(250, 2 * d_data->updTime)); break; case ScrMouse: d_data->time.start(); d_data->speed = 0; d_data->mouseOffset = getValue(p) - value(); emit sliderPressed(); break; default: d_data->mouseOffset = 0; d_data->direction = 0; break; } }
void QwtAbstractSlider::mouseReleaseEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Mouse Release Event handler
e | Mouse event |
Definition at line 202 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::direction, fitValue(), QwtDoubleRange::incPages(), isReadOnly(), isValid(), QwtAbstractSlider::PrivateData::mass, QwtAbstractSlider::PrivateData::mouseOffset, ScrDirect, ScrMouse, ScrNone, QwtAbstractSlider::PrivateData::scrollMode, ScrPage, ScrTimer, setPosition(), sliderReleased(), QwtAbstractSlider::PrivateData::speed, QwtDoubleRange::step(), stopMoving(), QwtAbstractSlider::PrivateData::time, QwtAbstractSlider::PrivateData::timerTick, QwtAbstractSlider::PrivateData::tmrID, QwtAbstractSlider::PrivateData::updTime, and QwtDoubleRange::value().
{ if ( isReadOnly() ) { e->ignore(); return; } if ( !isValid() ) return; const double inc = step(); switch(d_data->scrollMode) { case ScrMouse: { setPosition(e->pos()); d_data->direction = 0; d_data->mouseOffset = 0; if (d_data->mass > 0.0) { const int ms = d_data->time.elapsed(); if ((fabs(d_data->speed) > 0.0) && (ms < 50)) d_data->tmrID = startTimer(d_data->updTime); } else { d_data->scrollMode = ScrNone; buttonReleased(); } emit sliderReleased(); break; } case ScrDirect: { setPosition(e->pos()); d_data->direction = 0; d_data->mouseOffset = 0; d_data->scrollMode = ScrNone; buttonReleased(); break; } case ScrPage: { stopMoving(); if (!d_data->timerTick) QwtDoubleRange::incPages(d_data->direction); d_data->timerTick = 0; buttonReleased(); d_data->scrollMode = ScrNone; break; } case ScrTimer: { stopMoving(); if (!d_data->timerTick) QwtDoubleRange::fitValue(value() + double(d_data->direction) * inc); d_data->timerTick = 0; buttonReleased(); d_data->scrollMode = ScrNone; break; } default: { d_data->scrollMode = ScrNone; buttonReleased(); } } }
Orientation QwtAbstractSlider::orientation | ( | ) | const |
Referenced by QwtSlider::drawSlider(), QwtSlider::drawThumb(), QwtWheel::drawWheel(), QwtWheel::drawWheelBackground(), QwtSlider::getScrollMode(), QwtWheel::getValue(), QwtSlider::getValue(), keyPressEvent(), QwtSlider::layoutSlider(), QwtWheel::minimumSizeHint(), QwtSlider::minimumSizeHint(), QwtAbstractSlider(), QwtWheel::setOrientation(), and QwtSlider::setOrientation().
int QwtAbstractSlider::scrollMode | ( | ) | const [protected] |
Definition at line 585 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::scrollMode.
Referenced by QwtDial::getValue().
{ return d_data->scrollMode; }
void QwtAbstractSlider::setMass | ( | double | val ) | [virtual] |
Set the slider's mass for flywheel effect.
If the slider's mass is greater then 0, it will continue to move after the mouse button has been released. Its speed decreases with time at a rate depending on the slider's mass. A large mass means that it will continue to move for a long time.
Derived widgets may overload this function to make it public.
val | New mass in kg |
Reimplemented in QwtWheel.
Definition at line 513 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::mass.
void QwtAbstractSlider::setMouseOffset | ( | double | offset ) | [protected] |
Definition at line 575 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::mouseOffset.
Referenced by QwtDial::getValue().
{ d_data->mouseOffset = offset; }
virtual void QwtAbstractSlider::setOrientation | ( | Orientation | o ) | [virtual] |
void QwtAbstractSlider::setPosition | ( | const QPoint & | p ) | [protected, virtual] |
Move the slider to a specified point, adjust the value and emit signals if necessary.
Definition at line 282 of file qwt_abstract_slider.cpp.
References fitValue(), getValue(), and QwtAbstractSlider::PrivateData::mouseOffset.
Referenced by mouseMoveEvent(), and mouseReleaseEvent().
{ QwtDoubleRange::fitValue(getValue(p) - d_data->mouseOffset); }
void QwtAbstractSlider::setReadOnly | ( | bool | readOnly ) | [virtual, slot] |
En/Disable read only mode
In read only mode the slider can't be controlled by mouse or keyboard.
readOnly | Enables in case of true |
Definition at line 85 of file qwt_abstract_slider.cpp.
References readOnly, and QwtAbstractSlider::PrivateData::readOnly.
void QwtAbstractSlider::setTracking | ( | bool | enable ) |
Enables or disables tracking.
If tracking is enabled, the slider emits a valueChanged() signal whenever its value changes (the default behaviour). If tracking is disabled, the value changed() signal will only be emitted if:
Tracking is enabled by default.
enable | true (enable) or false (disable) tracking. |
Definition at line 302 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::tracking.
{ d_data->tracking = enable; }
void QwtAbstractSlider::setUpdateTime | ( | int | t ) |
Specify the update interval for automatic scrolling.
t | update interval in milliseconds |
Definition at line 138 of file qwt_abstract_slider.cpp.
References QuadProgPP::t(), and QwtAbstractSlider::PrivateData::updTime.
void QwtAbstractSlider::setValid | ( | bool | valid ) | [inline] |
valid | true/false |
Reimplemented from QwtDoubleRange.
Definition at line 80 of file qwt_abstract_slider.h.
References QwtDoubleRange::isValid().
Referenced by QwtAnalogClock::setTime().
void QwtAbstractSlider::setValue | ( | double | val ) | [virtual, slot] |
Move the slider to a specified value.
This function can be used to move the slider to a value which is not an integer multiple of the step size.
val | new value |
Reimplemented from QwtDoubleRange.
Definition at line 541 of file qwt_abstract_slider.cpp.
References ScrMouse, QwtAbstractSlider::PrivateData::scrollMode, and stopMoving().
Referenced by QwtDial::keyPressEvent(), QwtCompass::keyPressEvent(), and QwtAnalogClock::setTime().
{ if (d_data->scrollMode == ScrMouse) stopMoving(); QwtDoubleRange::setValue(val); }
void QwtAbstractSlider::sliderMoved | ( | double | value ) | [signal] |
This signal is emitted when the user moves the slider with the mouse.
value | new value |
Referenced by QwtDial::keyPressEvent(), keyPressEvent(), mouseMoveEvent(), and wheelEvent().
void QwtAbstractSlider::sliderPressed | ( | ) | [signal] |
This signal is emitted when the user presses the movable part of the slider (start ScrMouse Mode).
Referenced by mousePressEvent().
void QwtAbstractSlider::sliderReleased | ( | ) | [signal] |
This signal is emitted when the user releases the movable part of the slider.
Referenced by mouseReleaseEvent().
void QwtAbstractSlider::stopMoving | ( | ) |
Stop updating if automatic scrolling is active.
Definition at line 124 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::tmrID.
Referenced by fitValue(), incValue(), mousePressEvent(), mouseReleaseEvent(), setValue(), and timerEvent().
void QwtAbstractSlider::timerEvent | ( | QTimerEvent * | e ) | [protected, virtual] |
Qt timer event
e | Timer event |
Definition at line 423 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::direction, QwtDoubleRange::exactValue(), QuadProgPP::exp(), fitValue(), QwtDoubleRange::incPages(), QwtAbstractSlider::PrivateData::mass, ScrMouse, QwtAbstractSlider::PrivateData::scrollMode, ScrPage, ScrTimer, QwtAbstractSlider::PrivateData::speed, QwtDoubleRange::step(), stopMoving(), QwtAbstractSlider::PrivateData::timerTick, QwtAbstractSlider::PrivateData::tmrID, QwtAbstractSlider::PrivateData::updTime, and QwtDoubleRange::value().
{ const double inc = step(); switch (d_data->scrollMode) { case ScrMouse: { if (d_data->mass > 0.0) { d_data->speed *= exp( - double(d_data->updTime) * 0.001 / d_data->mass ); const double newval = exactValue() + d_data->speed * double(d_data->updTime); QwtDoubleRange::fitValue(newval); // stop if d_data->speed < one step per second if (fabs(d_data->speed) < 0.001 * fabs(step())) { d_data->speed = 0; stopMoving(); buttonReleased(); } } else stopMoving(); break; } case ScrPage: { QwtDoubleRange::incPages(d_data->direction); if (!d_data->timerTick) { killTimer(d_data->tmrID); d_data->tmrID = startTimer(d_data->updTime); } break; } case ScrTimer: { QwtDoubleRange::fitValue(value() + double(d_data->direction) * inc); if (!d_data->timerTick) { killTimer(d_data->tmrID); d_data->tmrID = startTimer(d_data->updTime); } break; } default: { stopMoving(); break; } } d_data->timerTick = 1; }
void QwtAbstractSlider::valueChange | ( | ) | [protected, virtual] |
Notify change of value
This function can be reimplemented by derived classes in order to keep track of changes, i.e. repaint the widget. The default implementation emits a valueChanged() signal if tracking is enabled.
Reimplemented from QwtDoubleRange.
Reimplemented in QwtDial, QwtSlider, and QwtWheel.
Definition at line 490 of file qwt_abstract_slider.cpp.
References QwtAbstractSlider::PrivateData::tracking, QwtDoubleRange::value(), and valueChanged().
{ if (d_data->tracking) emit valueChanged(value()); }
void QwtAbstractSlider::valueChanged | ( | double | value ) | [signal] |
Notify a change of value.
In the default setting (tracking enabled), this signal will be emitted every time the value changes ( see setTracking() ).
value | new value |
Referenced by valueChange().
void QwtAbstractSlider::wheelEvent | ( | QWheelEvent * | e ) | [protected, virtual] |
Wheel Event handler
e | Whell event |
Definition at line 342 of file qwt_abstract_slider.cpp.
References getScrollMode(), QwtDoubleRange::incPages(), isReadOnly(), isValid(), QwtDoubleRange::prevValue(), ScrNone, sliderMoved(), QwtDoubleRange::value(), and WHEEL_DELTA.
{ if ( isReadOnly() ) { e->ignore(); return; } if ( !isValid() ) return; int mode = ScrNone, direction = 0; // Give derived classes a chance to say ScrNone getScrollMode(e->pos(), mode, direction); if ( mode != ScrNone ) { const int inc = e->delta() / WHEEL_DELTA; QwtDoubleRange::incPages(inc); if (value() != prevValue()) emit sliderMoved(value()); } }
double QwtAbstractSlider::mass [read, write] |
Reimplemented in QwtWheel.
Definition at line 20 of file qwt_abstract_slider.h.
Qt::Orientation QwtAbstractSlider::orientation [read, write] |
bool QwtAbstractSlider::readOnly [read, write] |
Definition at line 18 of file qwt_abstract_slider.h.
Referenced by setReadOnly().
bool QwtAbstractSlider::valid [read, write] |
Definition at line 19 of file qwt_abstract_slider.h.