1
0

GradientWidget.h 1.4 KB

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