1 /** 2 * \file gradient_slider.hpp 3 * 4 * \author Mattia Basaglia 5 * 6 * \copyright Copyright (C) 2013-2020 Mattia Basaglia 7 * \copyright Copyright (C) 2014 Calle Laakkonen 8 * \copyright Copyright (C) 2017 caryoscelus 9 * 10 * This program is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation, either version 3 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 22 * 23 */ 24 #ifndef GRADIENT_SLIDER_HPP 25 #define GRADIENT_SLIDER_HPP 26 27 #include "colorwidgets_global.hpp" 28 29 #include <QSlider> 30 #include <QGradient> 31 32 namespace color_widgets { 33 34 /** 35 * \brief A slider that moves on top of a gradient 36 */ 37 class QCP_EXPORT GradientSlider : public QSlider 38 { 39 Q_OBJECT 40 Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged) 41 Q_PROPERTY(QGradientStops colors READ colors WRITE setColors DESIGNABLE false) 42 Q_PROPERTY(QColor firstColor READ firstColor WRITE setFirstColor STORED false) 43 Q_PROPERTY(QColor lastColor READ lastColor WRITE setLastColor STORED false) 44 Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient) 45 46 public: 47 explicit GradientSlider(QWidget *parent = 0); 48 explicit GradientSlider(Qt::Orientation orientation, QWidget *parent = 0); 49 ~GradientSlider(); 50 51 /// Get the background, it's visible for transparent gradient stops 52 QBrush background() const; 53 /// Set the background, it's visible for transparent gradient stops 54 void setBackground(const QBrush &bg); 55 56 /// Get the colors that make up the gradient 57 QGradientStops colors() const; 58 /// Set the colors that make up the gradient 59 void setColors(const QGradientStops &colors); 60 61 /// Get the gradient 62 QLinearGradient gradient() const; 63 /// Set the gradient 64 void setGradient(const QLinearGradient &gradient); 65 66 /** 67 * Overload: create an evenly distributed gradient of the given colors 68 */ 69 void setColors(const QVector<QColor> &colors); 70 71 /** 72 * \brief Set the first color of the gradient 73 * 74 * If the gradient is currently empty it will create a stop with the given color 75 */ 76 void setFirstColor(const QColor &c); 77 78 /** 79 * \brief Set the last color of the gradient 80 * 81 * If the gradient is has less than two colors, 82 * it will create a stop with the given color 83 */ 84 void setLastColor(const QColor &c); 85 86 /** 87 * \brief Get the first color 88 * 89 * \returns QColor() con empty gradient 90 */ 91 QColor firstColor() const; 92 93 /** 94 * \brief Get the last color 95 * 96 * \returns QColor() con empty gradient 97 */ 98 QColor lastColor() const; 99 100 Q_SIGNALS: 101 void backgroundChanged(const QBrush&); 102 103 protected: 104 void paintEvent(QPaintEvent *ev) override; 105 106 void mousePressEvent(QMouseEvent *ev) override; 107 void mouseMoveEvent(QMouseEvent *ev) override; 108 void mouseReleaseEvent(QMouseEvent *ev) override; 109 110 private: 111 class Private; 112 Private * const p; 113 }; 114 115 } // namespace color_widgets 116 117 #endif // GRADIENT_SLIDER_HPP 118