File indexing completed on 2024-05-12 16:02:12

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 2007 C. Boemann <cbo@boemann.dk>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KOSLIDERCOMBO_H_
0008 #define KOSLIDERCOMBO_H_
0009 
0010 #include <QComboBox>
0011 
0012 #include "kritawidgets_export.h"
0013 
0014 /**
0015  * @short A widget for qreal values with a popup slider
0016  *
0017  * KoSliderCombo combines a numerical input and a dropdown slider in a way that takes up as
0018  * little screen space as possible.
0019  * 
0020  * It allows the user to either enter a floating point value or quickly set the value using a slider
0021  * 
0022  * One signal is emitted when the value changes. The signal is even emitted when the slider
0023  * is moving. The second argument of the signal however tells you if the value is final or not. A
0024  * final value is produced by entering a value numerically or by releasing the slider.
0025  * 
0026  * The input of the numerical line edit is constrained to numbers and decimal signs.
0027  */
0028 class KRITAWIDGETS_EXPORT KoSliderCombo : public QComboBox
0029 {
0030 
0031     Q_OBJECT
0032 
0033 public:
0034 
0035     /**
0036      * Constructor for the widget, where value is set to 0
0037      *
0038      * @param parent parent QWidget
0039      */
0040     explicit KoSliderCombo(QWidget *parent=0);
0041 
0042     /**
0043      * Destructor
0044      */
0045     ~KoSliderCombo() override;
0046 
0047     /**
0048      * The precision of values given as the number of digits after the period.
0049      * default is 2
0050      */
0051     qreal decimals() const;
0052 
0053     /**
0054      * The minimum value that can be entered.
0055      * default is 0
0056      */
0057     qreal minimum() const;
0058 
0059     /**
0060      * The maximum value that can be entered.
0061      * default is 100
0062      */
0063     qreal maximum() const;
0064 
0065     /**
0066      * Sets the precision of the entered values.
0067      * @param number the number of digits after the period
0068      */
0069 
0070     void setDecimals(int number);
0071 
0072     /**
0073      * Sets the minimum value that can be entered.
0074      * @param min the minimum value
0075      */
0076     void setMinimum(qreal min);
0077 
0078     /**
0079      * Sets the maximum value that can be entered.
0080      * @param max the maximum value
0081      */
0082     void setMaximum(qreal max);
0083 
0084      /**
0085      * The value shown.
0086      */
0087     qreal value() const;
0088 
0089     QSize minimumSizeHint() const override; ///< reimplemented from QComboBox
0090     QSize sizeHint() const override; ///< reimplemented from QComboBox
0091 
0092 public Q_SLOTS:
0093 
0094      /**
0095      * Sets the value.
0096      * The value actually set is forced to be within the legal range: minimum <= value <= maximum
0097      * @param value the new value
0098      */
0099     void setValue(qreal value);
0100 
0101 Q_SIGNALS:
0102 
0103     /**
0104      * Emitted every time the value changes (by calling setValue() or
0105      * by user interaction).
0106      * @param value the new value
0107      * @param final if the value is final ie not produced during sliding (on slider release it's final)
0108      */
0109     void valueChanged(qreal value, bool final);
0110 
0111 protected:
0112     void paintEvent(QPaintEvent *) override; ///< reimplemented from QComboBox
0113     void hideEvent(QHideEvent *) override; ///< reimplemented from QComboBox
0114     void changeEvent(QEvent *e) override; ///< reimplemented from QComboBox
0115     void mousePressEvent(QMouseEvent *e) override; ///< reimplemented from QComboBox
0116     void keyPressEvent(QKeyEvent *e) override; ///< reimplemented from QComboBox
0117     void wheelEvent(QWheelEvent *e) override; ///< reimplemented from QComboBox
0118 
0119 private:
0120     Q_PRIVATE_SLOT(d, void sliderValueChanged(int value))
0121     Q_PRIVATE_SLOT(d, void sliderReleased())
0122     Q_PRIVATE_SLOT(d, void lineEditFinished())
0123 
0124     class KoSliderComboPrivate;
0125     KoSliderComboPrivate * const d;
0126 };
0127 
0128 #endif