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