qwt_abstract_slider.h 5.45 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_ABSTRACT_SLIDER_H
#define QWT_ABSTRACT_SLIDER_H

#include <qwidget.h>
#include "qwt_global.h"
#include "qwt_double_range.h"

/*!
  \brief 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
23
  only have to implement the getValue() and
pixhawk's avatar
pixhawk committed
24
  getScrollMode() members, and should react to a
25
  valueChange(), which normally requires repainting.
pixhawk's avatar
pixhawk committed
26 27 28 29
*/

class QWT_EXPORT QwtAbstractSlider : public QWidget, public QwtDoubleRange
{
30
    Q_OBJECT
pixhawk's avatar
pixhawk committed
31 32 33 34 35
    Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
    Q_PROPERTY( bool valid READ isValid WRITE setValid )
    Q_PROPERTY( double mass READ mass WRITE setMass )
#ifndef Q_MOC_RUN // Qt3 moc
#define QWT_PROPERTY Q_PROPERTY
36 37
    Q_PROPERTY( Orientation orientation
                READ orientation WRITE setOrientation )
pixhawk's avatar
pixhawk committed
38 39
#else // Qt4 moc
// MOC_SKIP_BEGIN
40 41
    Q_PROPERTY( Qt::Orientation orientation
                READ orientation WRITE setOrientation )
pixhawk's avatar
pixhawk committed
42 43 44 45
// MOC_SKIP_END
#endif

public:
46
    /*!
pixhawk's avatar
pixhawk committed
47 48 49
      Scroll mode
      \sa getScrollMode()
     */
50 51 52 53 54 55
    enum ScrollMode {
        ScrNone,
        ScrMouse,
        ScrTimer,
        ScrDirect,
        ScrPage
pixhawk's avatar
pixhawk committed
56
    };
57

pixhawk's avatar
pixhawk committed
58 59 60 61 62 63
    explicit QwtAbstractSlider(Qt::Orientation, QWidget *parent = NULL);
    virtual ~QwtAbstractSlider();

    void setUpdateTime(int t);
    void stopMoving();
    void setTracking(bool enable);
64

pixhawk's avatar
pixhawk committed
65 66 67 68 69 70 71 72 73 74 75 76 77
    virtual void setMass(double val);
    virtual double mass() const;

#if QT_VERSION >= 0x040000
    virtual void setOrientation(Qt::Orientation o);
    Qt::Orientation orientation() const;
#else
    virtual void setOrientation(Orientation o);
    Orientation orientation() const;
#endif

    bool isReadOnly() const;

78
    /*
pixhawk's avatar
pixhawk committed
79 80 81 82
        Wrappers for QwtDblRange::isValid/QwtDblRange::setValid made
        to be available as Q_PROPERTY in the designer.
    */

83
    /*!
pixhawk's avatar
pixhawk committed
84 85
      \sa QwtDblRange::isValid
    */
86 87 88
    bool isValid() const {
        return QwtDoubleRange::isValid();
    }
pixhawk's avatar
pixhawk committed
89

90
    /*!
pixhawk's avatar
pixhawk committed
91 92
      \sa QwtDblRange::isValid
    */
93 94 95
    void setValid(bool valid) {
        QwtDoubleRange::setValid(valid);
    }
pixhawk's avatar
pixhawk committed
96 97 98 99 100 101

public slots:
    virtual void setValue(double val);
    virtual void fitValue(double val);
    virtual void incValue(int steps);

102
    virtual void setReadOnly(bool);
pixhawk's avatar
pixhawk committed
103 104 105 106 107 108

signals:

    /*!
      \brief Notify a change of value.

109 110 111
      In the default setting
      (tracking enabled), this signal will be emitted every
      time the value changes ( see setTracking() ).
pixhawk's avatar
pixhawk committed
112 113 114 115 116
      \param value new value
    */
    void valueChanged(double value);

    /*!
117
      This signal is emitted when the user presses the
pixhawk's avatar
pixhawk committed
118 119 120 121 122
      movable part of the slider (start ScrMouse Mode).
    */
    void sliderPressed();

    /*!
123
      This signal is emitted when the user releases the
pixhawk's avatar
pixhawk committed
124 125 126 127 128 129 130 131 132 133
      movable part of the slider.
    */

    void sliderReleased();
    /*!
      This signal is emitted when the user moves the
      slider with the mouse.
      \param value new value
    */
    void sliderMoved(double value);
134

pixhawk's avatar
pixhawk committed
135 136 137 138 139 140 141 142 143 144 145
protected:
    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);

146 147
    /*!
      \brief Determine the value corresponding to a specified poind
pixhawk's avatar
pixhawk committed
148

149 150 151 152 153
      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.
      \param p point
    */
pixhawk's avatar
pixhawk committed
154
    virtual double getValue(const QPoint & p) = 0;
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    /*!
      \brief 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:<dl>
      <dt>QwtAbstractSlider::ScrNone
      <dd>Scrolling switched off. Don't change the value.
      <dt>QwtAbstractSlider::ScrMouse
      <dd>Change the value while the user keeps the
          button pressed and moves the mouse.
      <dt>QwtAbstractSlider::ScrTimer
      <dd>Automatic scrolling. Increment the value
          in the specified direction as long as
      the user keeps the button pressed.
      <dt>QwtAbstractSlider::ScrPage
      <dd>Automatic scrolling. Same as ScrTimer, but
          increment by page size.</dl>

      \param p point where the mouse was pressed
      \retval scrollMode The scrolling mode
      \retval direction  direction: 1, 0, or -1.
    */
pixhawk's avatar
pixhawk committed
180
    virtual void getScrollMode( const QPoint &p,
181
                                int &scrollMode, int &direction) = 0;
pixhawk's avatar
pixhawk committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195

    void setMouseOffset(double);
    double mouseOffset() const;

    int scrollMode() const;

private:
    void buttonReleased();

    class PrivateData;
    PrivateData *d_data;
};

#endif