| 1 |
/** =========================================================== |
| 2 |
* @file |
| 3 |
* |
| 4 |
* This file is a part of digiKam project |
| 5 |
* <a href="https://www.digikam.org">https://www.digikam.org</a> |
| 6 |
* |
| 7 |
* @date 2014-11-30 |
| 8 |
* @brief Save space slider widget |
| 9 |
* |
| 10 |
* @author Copyright (C) 2014 by Gilles Caulier |
| 11 |
* <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a> |
| 12 |
* @author Copyright (C) 2010 by Justin Noel |
| 13 |
* <a href="mailto:justin at ics dot com">justin at ics dot com</a> |
| 14 |
* |
| 15 |
* This program is free software; you can redistribute it |
| 16 |
* and/or modify it under the terms of the GNU General |
| 17 |
* Public License as published by the Free Software Foundation; |
| 18 |
* either version 2, or (at your option) |
| 19 |
* any later version. |
| 20 |
* |
| 21 |
* This program is distributed in the hope that it will be useful, |
| 22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
* GNU General Public License for more details. |
| 25 |
* |
| 26 |
* ============================================================ */ |
| 27 |
|
| 28 |
#ifndef RSLIDERSPINBOX_H |
| 29 |
#define RSLIDERSPINBOX_H |
| 30 |
|
| 31 |
// Qt includes |
| 32 |
|
| 33 |
#include <QWidget> |
| 34 |
#include <QString> |
| 35 |
#include <QRect> |
| 36 |
#include <QStyleOptionSpinBox> |
| 37 |
#include <QStyleOptionProgressBar> |
| 38 |
|
| 39 |
namespace KDcrawIface |
| 40 |
{ |
| 41 |
|
| 42 |
class RAbstractSliderSpinBoxPrivate; |
| 43 |
class RSliderSpinBoxPrivate; |
| 44 |
class RDoubleSliderSpinBoxPrivate; |
| 45 |
|
| 46 |
/** |
| 47 |
* TODO: when inactive, also show the progress bar part as inactive! |
| 48 |
*/ |
| 49 |
class RAbstractSliderSpinBox : public QWidget |
| 50 |
{ |
| 51 |
Q_OBJECT |
| 52 |
Q_DISABLE_COPY(RAbstractSliderSpinBox) |
| 53 |
Q_DECLARE_PRIVATE(RAbstractSliderSpinBox) |
| 54 |
|
| 55 |
protected: |
| 56 |
|
| 57 |
explicit RAbstractSliderSpinBox(QWidget* const parent, RAbstractSliderSpinBoxPrivate* const q); |
| 58 |
|
| 59 |
public: |
| 60 |
|
| 61 |
~RAbstractSliderSpinBox() override; |
| 62 |
|
| 63 |
void showEdit(); |
| 64 |
void hideEdit(); |
| 65 |
|
| 66 |
void setSuffix(const QString& suffix); |
| 67 |
|
| 68 |
void setExponentRatio(double dbl); |
| 69 |
|
| 70 |
protected: |
| 71 |
|
| 72 |
void paintEvent(QPaintEvent* e) override; |
| 73 |
void mousePressEvent(QMouseEvent* e) override; |
| 74 |
void mouseReleaseEvent(QMouseEvent* e) override; |
| 75 |
void mouseMoveEvent(QMouseEvent* e) override; |
| 76 |
void keyPressEvent(QKeyEvent* e) override; |
| 77 |
void wheelEvent(QWheelEvent *) override; |
| 78 |
bool eventFilter(QObject* recv, QEvent* e) override; |
| 79 |
|
| 80 |
QSize sizeHint() const override; |
| 81 |
QSize minimumSizeHint() const override; |
| 82 |
|
| 83 |
QStyleOptionSpinBox spinBoxOptions() const; |
| 84 |
QStyleOptionProgressBar progressBarOptions() const; |
| 85 |
|
| 86 |
QRect editRect(const QStyleOptionSpinBox& spinBoxOptions) const; |
| 87 |
QRect progressRect(const QStyleOptionProgressBar& progressBarOptions) const; |
| 88 |
QRect upButtonRect(const QStyleOptionSpinBox& spinBoxOptions) const; |
| 89 |
QRect downButtonRect(const QStyleOptionSpinBox& spinBoxOptions) const; |
| 90 |
|
| 91 |
int valueForX(int x, Qt::KeyboardModifiers modifiers = Qt::NoModifier) const; |
| 92 |
|
| 93 |
virtual QString valueString() const = 0; |
| 94 |
virtual void setInternalValue(int value) = 0; |
| 95 |
|
| 96 |
protected Q_SLOTS: |
| 97 |
|
| 98 |
void contextMenuEvent(QContextMenuEvent* event) override; |
| 99 |
void editLostFocus(); |
| 100 |
|
| 101 |
protected: |
| 102 |
|
| 103 |
RAbstractSliderSpinBoxPrivate* const d_ptr; |
| 104 |
}; |
| 105 |
|
| 106 |
// --------------------------------------------------------------------------------- |
| 107 |
|
| 108 |
class RSliderSpinBox : public RAbstractSliderSpinBox |
| 109 |
{ |
| 110 |
Q_OBJECT |
| 111 |
Q_DECLARE_PRIVATE(RSliderSpinBox) |
| 112 |
Q_PROPERTY( int minimum READ minimum WRITE setMinimum ) |
| 113 |
Q_PROPERTY( int maximum READ maximum WRITE setMaximum ) |
| 114 |
|
| 115 |
public: |
| 116 |
|
| 117 |
RSliderSpinBox(QWidget* const parent = 0); |
| 118 |
~RSliderSpinBox() override; |
| 119 |
|
| 120 |
void setRange(int minimum, int maximum); |
| 121 |
|
| 122 |
int minimum() const; |
| 123 |
void setMinimum(int minimum); |
| 124 |
int maximum() const; |
| 125 |
void setMaximum(int maximum); |
| 126 |
int fastSliderStep() const; |
| 127 |
void setFastSliderStep(int step); |
| 128 |
|
| 129 |
int value() const; |
| 130 |
void setValue(int value); |
| 131 |
|
| 132 |
void setSingleStep(int value); |
| 133 |
void setPageStep(int value); |
| 134 |
|
| 135 |
Q_SIGNALS: |
| 136 |
|
| 137 |
void valueChanged(int value); |
| 138 |
|
| 139 |
protected: |
| 140 |
|
| 141 |
QString valueString() const override; |
| 142 |
void setInternalValue(int value) override; |
| 143 |
}; |
| 144 |
|
| 145 |
// --------------------------------------------------------------------------------- |
| 146 |
|
| 147 |
class RDoubleSliderSpinBox : public RAbstractSliderSpinBox |
| 148 |
{ |
| 149 |
Q_OBJECT |
| 150 |
Q_DECLARE_PRIVATE(RDoubleSliderSpinBox) |
| 151 |
|
| 152 |
public: |
| 153 |
|
| 154 |
RDoubleSliderSpinBox(QWidget* const parent = 0); |
| 155 |
~RDoubleSliderSpinBox() override; |
| 156 |
|
| 157 |
void setRange(double minimum, double maximum, int decimals = 0); |
| 158 |
|
| 159 |
double minimum() const; |
| 160 |
void setMinimum(double minimum); |
| 161 |
double maximum() const; |
| 162 |
void setMaximum(double maximum); |
| 163 |
double fastSliderStep() const; |
| 164 |
void setFastSliderStep(double step); |
| 165 |
|
| 166 |
double value() const; |
| 167 |
void setValue(double value); |
| 168 |
|
| 169 |
void setSingleStep(double value); |
| 170 |
|
| 171 |
Q_SIGNALS: |
| 172 |
|
| 173 |
void valueChanged(double value); |
| 174 |
|
| 175 |
protected: |
| 176 |
|
| 177 |
QString valueString() const override; |
| 178 |
void setInternalValue(int val) override; |
| 179 |
}; |
| 180 |
|
| 181 |
} // namespace KDcrawIface |
| 182 |
|
| 183 |
#endif // RSLIDERSPINBOX_H |