digiKam
dsliderspinbox.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2014-11-30
7  * Description : Save space slider widget
8  *
9  * Copyright (C) 2014-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2010 by Justin Noel <justin at ics dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_DSLIDER_SPINBOX_H
26 #define DIGIKAM_DSLIDER_SPINBOX_H
27 
28 // Qt includes
29 
30 #include <QAbstractSpinBox>
31 #include <QStyleOptionSpinBox>
32 #include <QStyleOptionProgressBar>
33 
34 namespace Digikam
35 {
36 
37 class DAbstractSliderSpinBoxPrivate;
38 class DSliderSpinBoxPrivate;
39 class DDoubleSliderSpinBoxPrivate;
40 
41 class DAbstractSliderSpinBox : public QWidget
42 {
43  Q_OBJECT
44  Q_DISABLE_COPY(DAbstractSliderSpinBox)
45  Q_DECLARE_PRIVATE(DAbstractSliderSpinBox)
46 
47 protected:
48 
49  explicit DAbstractSliderSpinBox(QWidget* const parent, DAbstractSliderSpinBoxPrivate* const q);
50 
51 public:
52 
53  ~DAbstractSliderSpinBox() override;
54 
55  void showEdit();
56  void hideEdit();
57 
58  void setPrefix(const QString& prefix);
59  void setSuffix(const QString& suffix);
60 
61  void setExponentRatio(double dbl);
62 
68  void setBlockUpdateSignalOnDrag(bool block);
69 
70  QSize sizeHint() const override;
71  QSize minimumSizeHint() const override;
72  virtual QSize minimumSize() const;
73 
74  bool isDragging() const;
75 
76 protected:
77 
78  void paintEvent(QPaintEvent* e) override;
79  void mousePressEvent(QMouseEvent* e) override;
80  void mouseReleaseEvent(QMouseEvent* e) override;
81  void mouseMoveEvent(QMouseEvent* e) override;
82  void keyPressEvent(QKeyEvent* e) override;
83  void wheelEvent(QWheelEvent* e) override;
84  void focusInEvent(QFocusEvent* e) override;
85  bool eventFilter(QObject* recv, QEvent* e) override;
86 
87  QStyleOptionSpinBox spinBoxOptions() const;
88  QStyleOptionProgressBar progressBarOptions() const;
89 
90  QRect progressRect(const QStyleOptionSpinBox& spinBoxOptions) const;
91  QRect upButtonRect(const QStyleOptionSpinBox& spinBoxOptions) const;
92  QRect downButtonRect(const QStyleOptionSpinBox& spinBoxOptions) const;
93 
94  int valueForX(int x, Qt::KeyboardModifiers modifiers = Qt::NoModifier) const;
95 
96  virtual QString valueString() const = 0;
97 
102  virtual void setInternalValue(int value, bool blockUpdateSignal) = 0;
103 
104 protected Q_SLOTS:
105 
106  void contextMenuEvent(QContextMenuEvent* event) override;
107  void editLostFocus();
108 
109 protected:
110 
111  DAbstractSliderSpinBoxPrivate* const d_ptr;
112 
113  // -- QWidget interface --------------------------------------
114 
115 protected:
116 
117  void changeEvent(QEvent* e) override;
118  void paint(QPainter& painter);
119  void paintFusion(QPainter& painter);
120  void paintPlastique(QPainter& painter);
121  void paintBreeze(QPainter& painter);
122 
123 private:
124 
126 };
127 
128 // ---------------------------------------------------------------------------------
129 
131 {
132  Q_OBJECT
133  Q_DECLARE_PRIVATE(DSliderSpinBox)
134  Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
135  Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
136 
137 public:
138 
139  explicit DSliderSpinBox(QWidget* const parent = nullptr);
140  ~DSliderSpinBox() override;
141 
142  void setRange(int minimum, int maximum);
143 
144  int minimum() const;
145  void setMinimum(int minimum);
146  int maximum() const;
147  void setMaximum(int maximum);
148  int fastSliderStep() const;
149  void setFastSliderStep(int step);
150 
152  int value();
153 
154  void setSingleStep(int value);
155  void setPageStep(int value);
156 
157 public Q_SLOTS:
158 
160  void setValue(int value);
161 
162 protected:
163 
164  QString valueString() const override;
165  void setInternalValue(int value, bool blockUpdateSignal) override;
166 
167 Q_SIGNALS:
168 
169  void valueChanged(int value);
170 };
171 
172 // ---------------------------------------------------------------------------------
173 
175 {
176  Q_OBJECT
177  Q_DECLARE_PRIVATE(DDoubleSliderSpinBox)
178 
179 public:
180 
181  explicit DDoubleSliderSpinBox(QWidget* const parent = nullptr);
182  ~DDoubleSliderSpinBox() override;
183 
184  void setRange(double minimum, double maximum, int decimals = 0);
185 
186  double minimum() const;
187  void setMinimum(double minimum);
188  double maximum() const;
189  void setMaximum(double maximum);
190  double fastSliderStep() const;
191  void setFastSliderStep(double step);
192 
193  double value();
194  void setSingleStep(double value);
195 
196 public Q_SLOTS:
197 
198  void setValue(double value);
199 
200 protected:
201 
202  QString valueString() const override;
203  void setInternalValue(int value, bool blockUpdateSignal) override;
204 
205 Q_SIGNALS:
206 
207  void valueChanged(double value);
208 };
209 
210 } // namespace Digikam
211 
212 #endif // DIGIKAM_DSLIDER_SPINBOX_H
Definition: dsliderspinbox.h:42
virtual void setInternalValue(int value, bool blockUpdateSignal)=0
void contextMenuEvent(QContextMenuEvent *event) override
Definition: dsliderspinbox.cpp:920
void paint(QPainter &painter)
Definition: dsliderspinbox.cpp:212
void showEdit()
Definition: dsliderspinbox.cpp:150
QRect progressRect(const QStyleOptionSpinBox &spinBoxOptions) const
Definition: dsliderspinbox.cpp:801
virtual QSize minimumSize() const
Definition: dsliderspinbox.cpp:725
QStyleOptionProgressBar progressBarOptions() const
Definition: dsliderspinbox.cpp:773
void wheelEvent(QWheelEvent *e) override
Definition: dsliderspinbox.cpp:589
QRect downButtonRect(const QStyleOptionSpinBox &spinBoxOptions) const
Definition: dsliderspinbox.cpp:831
bool isDragging() const
Definition: dsliderspinbox.cpp:945
void hideEdit()
Definition: dsliderspinbox.cpp:175
void paintFusion(QPainter &painter)
Definition: dsliderspinbox.cpp:252
void setSuffix(const QString &suffix)
Definition: dsliderspinbox.cpp:901
void mouseReleaseEvent(QMouseEvent *e) override
Definition: dsliderspinbox.cpp:473
void mouseMoveEvent(QMouseEvent *e) override
Definition: dsliderspinbox.cpp:510
void paintEvent(QPaintEvent *e) override
Definition: dsliderspinbox.cpp:183
void changeEvent(QEvent *e) override
Definition: dsliderspinbox.cpp:951
void setPrefix(const QString &prefix)
Definition: dsliderspinbox.cpp:895
void mousePressEvent(QMouseEvent *e) override
Definition: dsliderspinbox.cpp:445
void keyPressEvent(QKeyEvent *e) override
Definition: dsliderspinbox.cpp:537
void paintBreeze(QPainter &painter)
Definition: dsliderspinbox.cpp:385
virtual QString valueString() const =0
DAbstractSliderSpinBox(QWidget *const parent, DAbstractSliderSpinBoxPrivate *const q)
Definition: dsliderspinbox.cpp:102
bool eventFilter(QObject *recv, QEvent *e) override
Definition: dsliderspinbox.cpp:616
int valueForX(int x, Qt::KeyboardModifiers modifiers=Qt::NoModifier) const
Definition: dsliderspinbox.cpp:837
void setExponentRatio(double dbl)
Definition: dsliderspinbox.cpp:907
QSize sizeHint() const override
Definition: dsliderspinbox.cpp:662
~DAbstractSliderSpinBox() override
Definition: dsliderspinbox.cpp:144
void editLostFocus()
Definition: dsliderspinbox.cpp:925
QRect upButtonRect(const QStyleOptionSpinBox &spinBoxOptions) const
Definition: dsliderspinbox.cpp:825
QSize minimumSizeHint() const override
Definition: dsliderspinbox.cpp:720
void paintPlastique(QPainter &painter)
Definition: dsliderspinbox.cpp:322
void focusInEvent(QFocusEvent *e) override
Definition: dsliderspinbox.cpp:606
void setBlockUpdateSignalOnDrag(bool block)
Definition: dsliderspinbox.cpp:914
QStyleOptionSpinBox spinBoxOptions() const
Definition: dsliderspinbox.cpp:730
DAbstractSliderSpinBoxPrivate *const d_ptr
Definition: dsliderspinbox.h:111
Definition: dsliderspinbox.h:175
double minimum() const
Definition: dsliderspinbox.cpp:1135
void setMinimum(double minimum)
Definition: dsliderspinbox.cpp:1142
void valueChanged(double value)
void setInternalValue(int value, bool blockUpdateSignal) override
Definition: dsliderspinbox.cpp:1204
void setRange(double minimum, double maximum, int decimals=0)
Definition: dsliderspinbox.cpp:1104
double fastSliderStep() const
Definition: dsliderspinbox.cpp:1161
QString valueString() const override
Definition: dsliderspinbox.cpp:1195
DDoubleSliderSpinBox(QWidget *const parent=nullptr)
Definition: dsliderspinbox.cpp:1095
double value()
Definition: dsliderspinbox.cpp:1174
double maximum() const
Definition: dsliderspinbox.cpp:1148
void setMaximum(double maximum)
Definition: dsliderspinbox.cpp:1155
void setSingleStep(double value)
Definition: dsliderspinbox.cpp:1189
void setValue(double value)
Definition: dsliderspinbox.cpp:1181
void setFastSliderStep(double step)
Definition: dsliderspinbox.cpp:1168
~DDoubleSliderSpinBox() override
Definition: dsliderspinbox.cpp:1100
Definition: dsliderspinbox.h:131
DSliderSpinBox(QWidget *const parent=nullptr)
Definition: dsliderspinbox.cpp:984
void setInternalValue(int value, bool blockUpdateSignal) override
Definition: dsliderspinbox.cpp:1077
int fastSliderStep() const
Definition: dsliderspinbox.cpp:1031
void valueChanged(int value)
int minimum
Definition: dsliderspinbox.h:134
void setMinimum(int minimum)
Definition: dsliderspinbox.cpp:1012
int value()
Get the value, don't use value()
Definition: dsliderspinbox.cpp:1044
void setMaximum(int maximum)
Definition: dsliderspinbox.cpp:1025
void setFastSliderStep(int step)
Definition: dsliderspinbox.cpp:1038
QString valueString() const override
Definition: dsliderspinbox.cpp:1057
void setRange(int minimum, int maximum)
Definition: dsliderspinbox.cpp:994
void setValue(int value)
Set the value, don't use setValue()
Definition: dsliderspinbox.cpp:1051
void setSingleStep(int value)
Definition: dsliderspinbox.cpp:1066
~DSliderSpinBox() override
Definition: dsliderspinbox.cpp:990
void setPageStep(int value)
Definition: dsliderspinbox.cpp:1072
int maximum
Definition: dsliderspinbox.h:135
QStringView prefix
Definition: itemviewutilities.cpp:593
QStringView suffix
Definition: itemviewutilities.cpp:594
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43