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