]> git.sesse.net Git - kdenlive/blob - src/dragvalue.h
Make class constructors with required args explicit [krazy 45/46] by Mikko Rapeli
[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 #include <kselectaction.h>
24 #include <QSpinBox>
25 #include <QDoubleSpinBox>
26 #include <QLabel>
27 #include <QProgressBar>
28
29 class QValidator;
30 class QToolButton;
31 class QLineEdit;
32 class QAction;
33 class QMenu;
34 class KSelectAction;
35
36
37 class CustomLabel : public QProgressBar
38 {
39     Q_OBJECT
40 public:
41     explicit CustomLabel(const QString &label, bool showSlider = true, int range = 1000, QWidget *parent = 0);
42     void setProgressValue(double value);
43     void setStep(double step);
44     
45 protected:
46     //virtual void mouseDoubleClickEvent(QMouseEvent * event);
47     virtual void mousePressEvent(QMouseEvent * event);
48     virtual void mouseReleaseEvent(QMouseEvent *event);
49     virtual void mouseMoveEvent(QMouseEvent *event);
50     //virtual void paintEvent(QPaintEvent *event);
51     virtual void wheelEvent(QWheelEvent * event);
52     virtual void focusInEvent(QFocusEvent *e);
53     virtual void focusOutEvent(QFocusEvent *e);
54
55 private:
56     QPoint m_dragStartPosition;
57     QPoint m_dragLastPosition;
58     bool m_dragMode;
59     bool m_showSlider;
60     double m_step;
61     void slotValueInc(double factor = 1);
62     void slotValueDec(double factor = 1);
63     void setNewValue(double, bool);
64     
65 signals:
66     void valueChanged(double, bool);
67     void setInTimeline();
68     void resetValue();
69 };
70
71 /**
72  * @brief A widget for modifing numbers by dragging, using the mouse wheel or entering them with the keyboard.
73  */
74
75 class DragValue : public QWidget
76 {
77     Q_OBJECT
78
79 public:
80     /**
81     * @brief Default constructor.
82     * @param label The label that will be displayed in the progress bar
83     * @param defaultValue The default value
84     * @param decimals The number of decimals for the parameter. 0 means it is an integer
85     * @param min The minimum value
86     * @param max The maximum value
87     * @param id Used to identify this widget. If this parameter is set, "Show in Timeline" will be available in context menu.
88     * @param suffix The suffix that will be displayed in the spinbox (for example '%')
89     * @param showSlider If disabled, user can still drag on the label but no progress bar is shown
90     */    
91     DragValue(const QString &label, double defaultValue, int decimals, double min = 0, double max = 100, int id = -1, const QString suffix = QString(), bool showSlider = true, QWidget* parent = 0);
92     virtual ~DragValue();
93
94     /** @brief Returns the precision = number of decimals */
95     int precision() const;
96     /** @brief Returns the maximum value */
97     qreal minimum() const;
98     /** @brief Returns the minimum value */
99     qreal maximum() const;
100
101     /** @brief Sets the precision (number of decimals) to @param precision. */
102     void setPrecision(int precision);
103     /** @brief Sets the minimum value. */
104     void setMinimum(qreal min);
105     /** @brief Sets the maximum value. */
106     void setMaximum(qreal max);
107     /** @brief Sets minimum and maximum value. */
108     void setRange(qreal min, qreal max);
109     /** @brief Sets the size of a step (when dragging or using the mouse wheel). */
110     void setStep(qreal step);
111
112     /** @brief Returns the current value */
113     qreal value() const;
114     /** @brief Change the "inTimeline" property to paint the intimeline widget differently. */
115     void setInTimelineProperty(bool intimeline);
116     /** @brief Returns minimum size for QSpinBox, used to set all spinboxes to the same width. */
117     int spinSize();
118     /** @brief Sets the minimum size for QSpinBox, used to set all spinboxes to the same width. */
119     void setSpinSize(int width);
120     
121 public slots:
122     /** @brief Sets the value (forced to be in the valid range) and emits valueChanged. */
123     void setValue(double value, bool final = true);
124     void setValueFromProgress(double value, bool final);
125     /** @brief Resets to default value */
126     void slotReset();
127
128 signals:
129     void valueChanged(double value, bool final = true);
130     void inTimeline(int);
131
132
133
134     /*
135      * Private
136      */
137
138 protected:
139     /*virtual void mousePressEvent(QMouseEvent *e);
140     virtual void mouseMoveEvent(QMouseEvent *e);
141     virtual void mouseReleaseEvent(QMouseEvent *e);*/
142     /** @brief Forwards tab focus to lineedit since it is disabled. */
143     virtual void focusInEvent(QFocusEvent *e);
144     virtual void focusOutEvent(QFocusEvent *e);
145     //virtual void keyPressEvent(QKeyEvent *e);
146     //virtual void wheelEvent(QWheelEvent *e);
147     //virtual void paintEvent( QPaintEvent * event );
148
149 private slots:
150
151     void slotEditingFinished();
152
153     void slotSetScaleMode(int mode);
154     void slotSetDirectUpdate(bool directUpdate);
155     void slotShowContextMenu(const QPoint &pos);
156     void slotSetValue(int value);
157     void slotSetValue(double value);
158     void slotSetInTimeline();
159
160 private:
161     double m_maximum;
162     double m_minimum;
163     int m_decimals;
164     double m_default;
165     int m_id;
166     QSpinBox *m_intEdit;
167     QDoubleSpinBox *m_doubleEdit;
168
169     QMenu *m_menu;
170     KSelectAction *m_scale;
171     QAction *m_directUpdate;
172     CustomLabel *m_label;
173 };
174
175 #endif