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