color_2d_slider.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * \file
  3. *
  4. * \author Mattia Basaglia
  5. *
  6. * \copyright Copyright (C) 2013-2020 Mattia Basaglia
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef COLOR_WIDGETS_COLOR_2D_SLIDER_HPP
  23. #define COLOR_WIDGETS_COLOR_2D_SLIDER_HPP
  24. #include "colorwidgets_global.hpp"
  25. #include <QWidget>
  26. namespace color_widgets {
  27. /**
  28. * \brief A 2D slider that edits 2 color components
  29. */
  30. class QCP_EXPORT Color2DSlider : public QWidget
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged DESIGNABLE true STORED false )
  34. Q_PROPERTY(qreal hue READ hue WRITE setHue DESIGNABLE false )
  35. Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation DESIGNABLE false )
  36. Q_PROPERTY(qreal value READ value WRITE setValue DESIGNABLE false )
  37. /**
  38. * \brief Which color component is used on the x axis
  39. */
  40. Q_PROPERTY(Component componentX READ componentX WRITE setComponentX NOTIFY componentXChanged)
  41. /**
  42. * \brief Which color component is used on the y axis
  43. */
  44. Q_PROPERTY(Component componentY READ componentY WRITE setComponentY NOTIFY componentYChanged)
  45. public:
  46. enum Component {
  47. Hue, Saturation, Value
  48. };
  49. Q_ENUMS(Component)
  50. explicit Color2DSlider(QWidget *parent = nullptr);
  51. ~Color2DSlider();
  52. /// Get current color
  53. QColor color() const;
  54. QSize sizeHint() const Q_DECL_OVERRIDE;
  55. /// Get current hue in the range [0-1]
  56. qreal hue() const;
  57. /// Get current saturation in the range [0-1]
  58. qreal saturation() const;
  59. /// Get current value in the range [0-1]
  60. qreal value() const;
  61. Component componentX() const;
  62. Component componentY() const;
  63. public Q_SLOTS:
  64. /// Set current color
  65. void setColor(const QColor& c);
  66. /**
  67. * @param h Hue [0-1]
  68. */
  69. void setHue(qreal h);
  70. /**
  71. * @param s Saturation [0-1]
  72. */
  73. void setSaturation(qreal s);
  74. /**
  75. * @param v Value [0-1]
  76. */
  77. void setValue(qreal v);
  78. void setComponentX(Component componentX);
  79. void setComponentY(Component componentY);
  80. Q_SIGNALS:
  81. /**
  82. * Emitted when the user selects a color or setColor is called
  83. */
  84. void colorChanged(QColor);
  85. /**
  86. * Emitted when the user selects a color
  87. */
  88. void colorSelected(QColor);
  89. void componentXChanged(Component componentX);
  90. void componentYChanged(Component componentY);
  91. protected:
  92. void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
  93. void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
  94. void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
  95. void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
  96. void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
  97. private:
  98. class Private;
  99. Private * const p;
  100. };
  101. } // namespace color_widgets
  102. #endif // COLOR_WIDGETS_COLOR_2D_SLIDER_HPP