1
0

GradientWidget.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef GRADIENTWIDGET_H
  2. #define GRADIENTWIDGET_H
  3. #include <QWidget>
  4. #include <QLinearGradient>
  5. #include <QVector>
  6. #include <QPair>
  7. class GradientWidget :
  8. public QWidget
  9. {
  10. Q_OBJECT
  11. QVector<QPair<float, QColor>> points;
  12. bool dragging;
  13. int selectedHandle;
  14. float selectOffsetY;
  15. int mouseOver;
  16. int handleWidth = 40;
  17. int handleHeight = 24;
  18. public:
  19. explicit GradientWidget(QWidget *parent = nullptr);
  20. const QVector<QPair<float, QColor>>& getGradient(void) const;
  21. void setGradient(QVector<QPair<float, QColor>>);
  22. QColor colorAtY(float y);
  23. void paintEvent(QPaintEvent* e) override;
  24. void mousePressEvent(QMouseEvent* e) override;
  25. void mouseReleaseEvent(QMouseEvent* e) override;
  26. void mouseMoveEvent(QMouseEvent* e) override;
  27. void mouseDoubleClickEvent(QMouseEvent* e) override;
  28. QSize minimumSizeHint(void) const override;
  29. QSize sizeHint(void) const override;
  30. protected:
  31. /// \brief the area in which the gradient is displayed
  32. QRect getGradientRect(void) const;
  33. /// \brief the area in which the handle with index
  34. /// \c index is displayed
  35. QRect getHandleRect(int index) const;
  36. /// \brief the area in which the handles can move around
  37. QRect getHandleArea(void) const;
  38. int handleAtPos(QPoint pos) const;
  39. float handleYToGradVal(float y) const;
  40. float gradValToHandleY(float v) const;
  41. signals:
  42. };
  43. #endif // GRADIENTWIDGET_H