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