~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.1.1/src/qwt_abstract_slider.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2008-05-26 10:26:31 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526102631-bp95mfccnrb957nx
Tags: 5.1.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 
2
 * Qwt Widget Library
 
3
 * Copyright (C) 1997   Josef Wilgen
 
4
 * Copyright (C) 2002   Uwe Rathmann
 
5
 * 
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the Qwt License, Version 1.0
 
8
 *****************************************************************************/
 
9
 
 
10
#ifndef QWT_ABSTRACT_SLIDER_H
 
11
#define QWT_ABSTRACT_SLIDER_H
 
12
 
 
13
#include <qwidget.h>
 
14
#include "qwt_global.h"
 
15
#include "qwt_double_range.h"
 
16
 
 
17
/*!
 
18
  \brief An abstract base class for slider widgets
 
19
 
 
20
  QwtAbstractSlider is a base class for
 
21
  slider widgets. It handles mouse events
 
22
  and updates the slider's value accordingly. Derived classes
 
23
  only have to implement the getValue() and 
 
24
  getScrollMode() members, and should react to a
 
25
  valueChange(), which normally requires repainting. 
 
26
*/
 
27
 
 
28
class QWT_EXPORT QwtAbstractSlider : public QWidget, public QwtDoubleRange
 
29
{
 
30
    Q_OBJECT 
 
31
    Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
 
32
    Q_PROPERTY( bool valid READ isValid WRITE setValid )
 
33
    Q_PROPERTY( double mass READ mass WRITE setMass )
 
34
#ifndef Q_MOC_RUN // Qt3 moc
 
35
#define QWT_PROPERTY Q_PROPERTY
 
36
    Q_PROPERTY( Orientation orientation 
 
37
        READ orientation WRITE setOrientation )
 
38
#else // Qt4 moc
 
39
// MOC_SKIP_BEGIN
 
40
    Q_PROPERTY( Qt::Orientation orientation 
 
41
        READ orientation WRITE setOrientation )
 
42
// MOC_SKIP_END
 
43
#endif
 
44
 
 
45
public:
 
46
    /*! 
 
47
      Scroll mode
 
48
      \sa getScrollMode()
 
49
     */
 
50
    enum ScrollMode 
 
51
    { 
 
52
        ScrNone, 
 
53
        ScrMouse, 
 
54
        ScrTimer, 
 
55
        ScrDirect, 
 
56
        ScrPage 
 
57
    };
 
58
    
 
59
    explicit QwtAbstractSlider(Qt::Orientation, QWidget *parent = NULL);
 
60
    virtual ~QwtAbstractSlider();
 
61
 
 
62
    void setUpdateTime(int t);
 
63
    void stopMoving();
 
64
    void setTracking(bool enable);
 
65
    
 
66
    virtual void setMass(double val);
 
67
    virtual double mass() const;
 
68
 
 
69
#if QT_VERSION >= 0x040000
 
70
    virtual void setOrientation(Qt::Orientation o);
 
71
    Qt::Orientation orientation() const;
 
72
#else
 
73
    virtual void setOrientation(Orientation o);
 
74
    Orientation orientation() const;
 
75
#endif
 
76
 
 
77
    bool isReadOnly() const;
 
78
 
 
79
    /* 
 
80
        Wrappers for QwtDblRange::isValid/QwtDblRange::setValid made
 
81
        to be available as Q_PROPERTY in the designer.
 
82
    */
 
83
 
 
84
    /*! 
 
85
      \sa QwtDblRange::isValid
 
86
    */
 
87
    bool isValid() const { return QwtDoubleRange::isValid(); }
 
88
 
 
89
    /*! 
 
90
      \sa QwtDblRange::isValid
 
91
    */
 
92
    void setValid(bool valid) { QwtDoubleRange::setValid(valid); }
 
93
 
 
94
public slots:
 
95
    virtual void setValue(double val);
 
96
    virtual void fitValue(double val);
 
97
    virtual void incValue(int steps);
 
98
 
 
99
    virtual void setReadOnly(bool); 
 
100
 
 
101
signals:
 
102
 
 
103
    /*!
 
104
      \brief Notify a change of value.
 
105
 
 
106
      In the default setting 
 
107
      (tracking enabled), this signal will be emitted every 
 
108
      time the value changes ( see setTracking() ). 
 
109
      \param value new value
 
110
    */
 
111
    void valueChanged(double value);
 
112
 
 
113
    /*!
 
114
      This signal is emitted when the user presses the 
 
115
      movable part of the slider (start ScrMouse Mode).
 
116
    */
 
117
    void sliderPressed();
 
118
 
 
119
    /*!
 
120
      This signal is emitted when the user releases the 
 
121
      movable part of the slider.
 
122
    */
 
123
 
 
124
    void sliderReleased();
 
125
    /*!
 
126
      This signal is emitted when the user moves the
 
127
      slider with the mouse.
 
128
      \param value new value
 
129
    */
 
130
    void sliderMoved(double value);
 
131
    
 
132
protected:
 
133
    virtual void setPosition(const QPoint &);
 
134
    virtual void valueChange();
 
135
 
 
136
    virtual void timerEvent(QTimerEvent *e);
 
137
    virtual void mousePressEvent(QMouseEvent *e);
 
138
    virtual void mouseReleaseEvent(QMouseEvent *e);
 
139
    virtual void mouseMoveEvent(QMouseEvent *e);
 
140
    virtual void keyPressEvent(QKeyEvent *e);
 
141
    virtual void wheelEvent(QWheelEvent *e);
 
142
 
 
143
  /*!
 
144
    \brief Determine the value corresponding to a specified poind
 
145
 
 
146
    This is an abstract virtual function which is called when
 
147
    the user presses or releases a mouse button or moves the
 
148
    mouse. It has to be implemented by the derived class.
 
149
    \param p point 
 
150
  */
 
151
    virtual double getValue(const QPoint & p) = 0;
 
152
  /*!
 
153
    \brief Determine what to do when the user presses a mouse button.
 
154
 
 
155
    This function is abstract and has to be implemented by derived classes.
 
156
    It is called on a mousePress event. The derived class can determine
 
157
    what should happen next in dependence of the position where the mouse
 
158
    was pressed by returning scrolling mode and direction. QwtAbstractSlider
 
159
    knows the following modes:<dl>
 
160
    <dt>QwtAbstractSlider::ScrNone
 
161
    <dd>Scrolling switched off. Don't change the value.
 
162
    <dt>QwtAbstractSlider::ScrMouse
 
163
    <dd>Change the value while the user keeps the
 
164
        button pressed and moves the mouse.
 
165
    <dt>QwtAbstractSlider::ScrTimer
 
166
    <dd>Automatic scrolling. Increment the value
 
167
        in the specified direction as long as
 
168
    the user keeps the button pressed.
 
169
    <dt>QwtAbstractSlider::ScrPage
 
170
    <dd>Automatic scrolling. Same as ScrTimer, but
 
171
        increment by page size.</dl>
 
172
 
 
173
    \param p point where the mouse was pressed
 
174
    \retval scrollMode The scrolling mode
 
175
    \retval direction  direction: 1, 0, or -1.
 
176
  */
 
177
    virtual void getScrollMode( const QPoint &p,
 
178
                  int &scrollMode, int &direction) = 0;
 
179
 
 
180
    void setMouseOffset(double);
 
181
    double mouseOffset() const;
 
182
 
 
183
    int scrollMode() const;
 
184
 
 
185
private:
 
186
    void buttonReleased();
 
187
 
 
188
    class PrivateData;
 
189
    PrivateData *d_data;
 
190
};
 
191
 
 
192
#endif