]> git.sesse.net Git - kdenlive/blob - src/timecodedisplay.h
Add widget for easier timecode display
[kdenlive] / src / timecodedisplay.h
1 /* This file is part of the KDE project
2    Copyright (c) 2010 Jean-Baptiste Mardelle <jb@kdenlive.org>
3
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version.
8
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19
20 #ifndef TIMECODEDISPLAY_H_
21 #define TIMECODEDISPLAY_H_
22
23 #include "ui_timecodedisplay_ui.h"
24 #include "timecode.h"
25
26 #include <KRestrictedLine>
27
28
29 /**
30  * @short A widget for qreal values with a popup slider
31  *
32  * TimecodeDisplay combines a numerical input and a dropdown slider in a way that takes up as
33  * little screen space as possible.
34  *
35  * It allows the user to either enter a floating point value or quickly set the value using a slider
36  *
37  * One signal is emitted when the value changes. The signal is even emitted when the slider
38  * is moving. The second argument of the signal however tells you if the value is final or not. A
39  * final value is produced by entering a value numerically or by releasing the slider.
40  *
41  * The input of the numerical line edit is constrained to numbers and decimal signs.
42  */
43 class TimecodeDisplay : public QWidget, public Ui::TimecodeDisplay_UI
44 {
45
46     Q_OBJECT
47
48 public:
49
50     /**
51      * Constructor for the widget, where value is set to 0
52      *
53      * @param parent parent QWidget
54      */
55     TimecodeDisplay(Timecode t, QWidget *parent = 0);
56
57     /**
58      * Destructor
59      */
60     virtual ~TimecodeDisplay();
61
62     /**
63      * The minimum value that can be entered.
64      * default is 0
65      */
66     int minimum() const;
67
68     /**
69      * The maximum value that can be entered.
70      * default is 100
71      */
72     int maximum() const;
73
74     /**
75      * Sets the minimum value that can be entered.
76      * @param min the minimum value
77      */
78     void setMinimum(int min);
79
80     /**
81      * Sets the maximum value that can be entered.
82      * @param max the maximum value
83      */
84     void setMaximum(int max);
85
86     /**
87     * The value shown.
88     */
89     int value() const;
90
91     //virtual QSize minimumSizeHint() const; ///< reimplemented from QComboBox
92     //virtual QSize sizeHint() const; ///< reimplemented from QComboBox
93
94 private:
95     /** timecode for widget */
96     Timecode m_timecode;
97     /** Should we display the timecode in frames or in format hh:mm:ss:ff */
98     bool m_frametimecode;
99     int m_minimum;
100     int m_maximum;
101
102 public slots:
103
104     /**
105     * Sets the value.
106     * The value actually set is forced to be within the legal range: minimum <= value <= maximum
107     * @param value the new value
108     */
109     void setValue(int value);
110     void setValue(const QString &value);
111     void slotPrepareTimeCodeFormat(Timecode t);
112
113 private slots:
114     void slotValueUp();
115     void slotValueDown();
116
117 signals:
118
119     /**
120      * Emitted every time the value changes (by calling setValue() or
121      * by user interaction).
122      * @param value the new value
123      * @param final if the value is final ie not produced during sliding (on slider release it's final)
124      */
125     void valueChanged(int value, bool final);
126     void editingFinished();
127
128 protected:
129     virtual void keyPressEvent(QKeyEvent *e);
130     virtual void wheelEvent(QWheelEvent *e);
131
132 };
133
134 #endif