ColorDialog.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef COLORDIALOG_H
  2. #define COLORDIALOG_H
  3. #include <QLabel>
  4. #include <QWidget>
  5. #include "Widgets/Slider.h"
  6. #include "Widgets/LineEdit.h"
  7. #include "MaskDialogBase.h"
  8. class HuePanel;
  9. class ScrollArea;
  10. class PrimaryPushButton;
  11. class BrightnessSlider : public Slider
  12. {
  13. Q_OBJECT
  14. public:
  15. explicit BrightnessSlider(const QColor &color, QWidget *parent = nullptr);
  16. void setColor(const QColor &color);
  17. signals:
  18. void colorChanged(const QColor &);
  19. private slots:
  20. void onValueChanged(int value);
  21. private:
  22. QColor m_color;
  23. };
  24. class ColorCard : public QWidget
  25. {
  26. Q_OBJECT
  27. public:
  28. explicit ColorCard(const QColor &color, QWidget *parent = nullptr);
  29. void setColor(const QColor &color);
  30. // QWidget interface
  31. protected:
  32. virtual void paintEvent(QPaintEvent *event) override;
  33. private:
  34. QColor m_color;
  35. };
  36. class ColorLineEdit : public LineEdit
  37. {
  38. Q_OBJECT
  39. public:
  40. explicit ColorLineEdit(const QString &value, QWidget *parent = nullptr);
  41. private slots:
  42. void onTextEdited(const QString &text);
  43. signals:
  44. void valueChanged(const QString &);
  45. };
  46. class HexColorLineEdit : public ColorLineEdit
  47. {
  48. Q_OBJECT
  49. public:
  50. explicit HexColorLineEdit(const QColor &color, QWidget *parent = nullptr);
  51. void setColor(const QColor &color);
  52. QLabel *prefixLabel;
  53. };
  54. class ColorDialog : public MaskDialogBase
  55. {
  56. Q_OBJECT
  57. public:
  58. explicit ColorDialog(const QColor &color, const QString &title, QWidget *parent = nullptr);
  59. void setColor(const QColor &color, bool movePicker = true);
  60. void updateStyle();
  61. signals:
  62. void colorChanged(const QColor &);
  63. private:
  64. void initWidget();
  65. void setQss();
  66. void initLayout();
  67. void connectSignalToSlot();
  68. private slots:
  69. void onYesButtonClicked();
  70. void onHueChanged(const QColor &color);
  71. void onBrightnessChanged(const QColor &color);
  72. void onRedChanged(const QString &value);
  73. void onGreenChanged(const QString &value);
  74. void onBlueChanged(const QString &value);
  75. void onHexColorChanged(const QString &value);
  76. private:
  77. QColor m_oldColor;
  78. QColor m_color;
  79. ScrollArea *m_scrollArea;
  80. QWidget *m_scrollWidget;
  81. QFrame *m_buttonGroup;
  82. PrimaryPushButton *m_yesButton;
  83. QPushButton *m_cancelButton;
  84. QLabel *m_titleLabel;
  85. HuePanel *m_huePanel;
  86. ColorCard *m_newColorCard;
  87. ColorCard *m_oldColorCard;
  88. BrightnessSlider *m_brightSlider;
  89. QLabel *m_editLabel;
  90. QLabel *m_redLabel;
  91. QLabel *m_greenLabel;
  92. QLabel *m_blueLabel;
  93. HexColorLineEdit *m_hexLineEdit;
  94. ColorLineEdit *m_redLineEdit;
  95. ColorLineEdit *m_greenLineEdit;
  96. ColorLineEdit *m_blueLineEdit;
  97. QVBoxLayout *m_vBoxLayout;
  98. };
  99. #endif // COLORDIALOG_H