]> git.sesse.net Git - kdenlive/blob - src/dragvalue.h
drag value:
[kdenlive] / src / dragvalue.h
1 /***************************************************************************
2  *   Copyright (C) 2011 by Till Theato (root@ttill.de)                     *
3  *   This file is part of Kdenlive (www.kdenlive.org).                     *
4  *                                                                         *
5  *   Kdenlive is free software: you can redistribute it and/or modify      *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation, either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   Kdenlive is distributed in the hope that it will be useful,           *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with Kdenlive.  If not, see <http://www.gnu.org/licenses/>.     *
17  ***************************************************************************/
18
19 #ifndef DRAGVALUE_H_
20 #define DRAGVALUE_H_
21
22 #include <QWidget>
23
24 class QValidator;
25 class QToolButton;
26 class QLineEdit;
27 class QAction;
28 class QMenu;
29
30 /**
31  * @brief A widget for modifing numbers by dragging, using the mouse wheel or entering them with the keyboard.
32  */
33
34 class DragValue : public QWidget
35 {
36     Q_OBJECT
37
38 public:
39     DragValue(QWidget* parent = 0);
40     virtual ~DragValue();
41
42     /** @brief Returns the precision = number of decimals */
43     int precision() const;
44     /** @brief Returns the maximum value */
45     qreal minimum() const;
46     /** @brief Returns the minimum value */
47     qreal maximum() const;
48
49     /** @brief Sets the precision (number of decimals) to @param precision. */
50     void setPrecision(int precision);
51     /** @brief Sets the minimum value. */
52     void setMinimum(qreal min);
53     /** @brief Sets the maximum value. */
54     void setMaximum(qreal max);
55     /** @brief Sets minimum and maximum value. */
56     void setRange(qreal min, qreal max);
57     /** @brief Sets the size of a step (when dragging or using the mouse wheel). */
58     void setStep(qreal step);
59
60     /** @brief Returns the current value */
61     qreal value() const;
62     
63 public slots:
64     /** @brief Sets the value (forced to be in the valid range) and emits valueChanged. */
65     void setValue(qreal value, bool final = true);
66
67 signals:
68     void valueChanged(qreal value, bool final);
69
70
71
72
73     /*
74      * Private
75      */
76
77 protected:
78     virtual void mousePressEvent(QMouseEvent *e);
79     virtual void mouseMoveEvent(QMouseEvent *e);
80     virtual void mouseReleaseEvent(QMouseEvent *e);
81     /** @brief Forwards tab focus to lineedit since it is disabled. */
82     virtual void focusInEvent(QFocusEvent *e);
83     //virtual void keyPressEvent(QKeyEvent *e);
84     virtual void wheelEvent(QWheelEvent *e);
85
86 private slots:
87     void slotValueInc();
88     void slotValueDec();
89     void slotEditingFinished();
90
91     void slotSetNonlinearScale(bool nonlinear);
92     void slotSetDirectUpdate(bool directUpdate);
93     void slotShowContextMenu(const QPoint &pos);
94
95 private:
96     qreal m_maximum;
97     qreal m_minimum;
98     int m_precision;
99     qreal m_step;
100     QLineEdit *m_edit;
101     QPoint m_dragStartPosition;
102     QPoint m_dragLastPosition;
103     bool m_dragMode;
104
105     QMenu *m_menu;
106     QAction *m_nonlinearScale;
107     QAction *m_directUpdate;
108
109     /** @brief Sets the maximum width of the widget so that there is enough space for the widest possible value. */
110     void updateMaxWidth();
111 };
112
113 #endif