gradient_slider.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include "colorwidgets_global.hpp"
  27. #include <QSlider>
  28. #include <QGradient>
  29. namespace color_widgets {
  30. /**
  31. * \brief A slider that moves on top of a gradient
  32. */
  33. class QCP_EXPORT GradientSlider : public QSlider
  34. {
  35. Q_OBJECT
  36. Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged)
  37. Q_PROPERTY(QGradientStops colors READ colors WRITE setColors DESIGNABLE false)
  38. Q_PROPERTY(QColor firstColor READ firstColor WRITE setFirstColor STORED false)
  39. Q_PROPERTY(QColor lastColor READ lastColor WRITE setLastColor STORED false)
  40. Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
  41. public:
  42. explicit GradientSlider(QWidget *parent = 0);
  43. explicit GradientSlider(Qt::Orientation orientation, QWidget *parent = 0);
  44. ~GradientSlider();
  45. /// Get the background, it's visible for transparent gradient stops
  46. QBrush background() const;
  47. /// Set the background, it's visible for transparent gradient stops
  48. void setBackground(const QBrush &bg);
  49. /// Get the colors that make up the gradient
  50. QGradientStops colors() const;
  51. /// Set the colors that make up the gradient
  52. void setColors(const QGradientStops &colors);
  53. /// Get the gradient
  54. QLinearGradient gradient() const;
  55. /// Set the gradient
  56. void setGradient(const QLinearGradient &gradient);
  57. /**
  58. * Overload: create an evenly distributed gradient of the given colors
  59. */
  60. void setColors(const QVector<QColor> &colors);
  61. /**
  62. * \brief Set the first color of the gradient
  63. *
  64. * If the gradient is currently empty it will create a stop with the given color
  65. */
  66. void setFirstColor(const QColor &c);
  67. /**
  68. * \brief Set the last color of the gradient
  69. *
  70. * If the gradient is has less than two colors,
  71. * it will create a stop with the given color
  72. */
  73. void setLastColor(const QColor &c);
  74. /**
  75. * \brief Get the first color
  76. *
  77. * \returns QColor() con empty gradient
  78. */
  79. QColor firstColor() const;
  80. /**
  81. * \brief Get the last color
  82. *
  83. * \returns QColor() con empty gradient
  84. */
  85. QColor lastColor() const;
  86. Q_SIGNALS:
  87. void backgroundChanged(const QBrush&);
  88. protected:
  89. void paintEvent(QPaintEvent *ev) override;
  90. void mousePressEvent(QMouseEvent *ev) override;
  91. void mouseMoveEvent(QMouseEvent *ev) override;
  92. void mouseReleaseEvent(QMouseEvent *ev) override;
  93. private:
  94. class Private;
  95. Private * const p;
  96. };
  97. } // namespace color_widgets
  98. #endif // GRADIENT_SLIDER_HPP