]> git.sesse.net Git - kdenlive/blob - src/KoSliderCombo.h
Re-use KOffice widget in the titler to gain space (spin box with popup slider)
[kdenlive] / src / KoSliderCombo.h
1 /* This file is part of the KDE project
2    Copyright (c) 2007 Casper Boemann <cbr@boemann.dk>
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 KOSLIDERCOMBO_H_
21 #define KOSLIDERCOMBO_H_
22
23 #include <QComboBox>
24
25 #include "kowidgets_export.h"
26
27 /**
28  * @short A widget for qreal values with a popup slider
29  *
30  * KoSliderCombo combines a numerical input and a dropdown slider in a way that takes up as
31  * little screen space as possible.
32  * 
33  * It allows the user to either enter a floating point value or quickly set the value using a slider
34  * 
35  * One signal is emitted when the value changes. The signal is even emitted when the slider
36  * is moving. The second argument of the signal however tells you if the value is final or not. A
37  * final value is produced by entering a value numerically or by releasing the slider.
38  * 
39  * The input of the numerical line edit is constrained to numbers and decimal signs.
40  */
41 class KOWIDGETS_EXPORT KoSliderCombo : public QComboBox
42 {
43
44     Q_OBJECT
45
46 public:
47
48     /**
49      * Constructor for the widget, where value is set to 0
50      *
51      * @param parent parent QWidget
52      */
53     KoSliderCombo(QWidget *parent=0);
54
55     /**
56      * Destructor
57      */
58     virtual ~KoSliderCombo();
59
60     /**
61      * The precision of values given as the number of digits after the period.
62      * default is 2
63      */
64     qreal decimals() const;
65
66     /**
67      * The minimum value that can be entered.
68      * default is 0
69      */
70     qreal minimum() const;
71
72     /**
73      * The maximum value that can be entered.
74      * default is 100
75      */
76     qreal maximum() const;
77
78     /**
79      * Sets the precision of the entered values.
80      * @param number the number of digits after the period
81      */
82
83     void setDecimals(int number);
84
85     /**
86      * Sets the minimum value that can be entered.
87      * @param min the minimum value
88      */
89     void setMinimum(qreal min);
90
91     /**
92      * Sets the maximum value that can be entered.
93      * @param max the maximum value
94      */
95     void setMaximum(qreal max);
96
97      /**
98      * The value shown.
99      */
100     qreal value() const;
101
102     virtual QSize minimumSizeHint() const; ///< reimplemented from QComboBox
103     virtual QSize sizeHint() const; ///< reimplemented from QComboBox
104
105 public slots:
106
107      /**
108      * Sets the value.
109      * The value actually set is forced to be within the legal range: minimum <= value <= maximum
110      * @param value the new value
111      */
112     void setValue(qreal value);
113
114 signals:
115
116     /**
117      * Emitted every time the value changes (by calling setValue() or
118      * by user interaction).
119      * @param value the new value
120      * @param final if the value is final ie not produced during sliding (on slider release it's final)
121      */
122     void valueChanged(qreal value, bool final);
123
124 protected:
125     virtual void paintEvent(QPaintEvent *); ///< reimplemented from QComboBox
126     virtual void hideEvent(QHideEvent *); ///< reimplemented from QComboBox
127     virtual void changeEvent(QEvent *e); ///< reimplemented from QComboBox
128     virtual void mousePressEvent(QMouseEvent *e); ///< reimplemented from QComboBox
129     virtual void keyPressEvent(QKeyEvent *e); ///< reimplemented from QComboBox
130     virtual void wheelEvent(QWheelEvent *e); ///< reimplemented from QComboBox
131
132 private:
133     Q_PRIVATE_SLOT(d, void sliderValueChanged(int value))
134     Q_PRIVATE_SLOT(d, void sliderReleased())
135     Q_PRIVATE_SLOT(d, void lineEditFinished())
136
137     class KoSliderComboPrivate;
138     KoSliderComboPrivate * const d;
139 };
140
141 #endif