Chatterino
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ColorPickerDialog.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "util/LayoutCreator.hpp"
4 #include "widgets/BasePopup.hpp"
7 
8 #include <pajlada/signals/signal.hpp>
9 
10 #include <array>
11 
12 #include <QLabel>
13 
14 namespace chatterino {
15 
24 {
25 public:
32  ColorPickerDialog(const QColor &initial, QWidget *parent);
33 
35 
45  QColor selectedColor() const;
46 
47  pajlada::Signals::Signal<QColor> closed;
48 
49 protected:
50  void closeEvent(QCloseEvent *);
51  void themeChangedEvent();
52 
53 private:
54  struct {
55  struct {
56  QLabel *label;
57  std::vector<ColorButton *> colors;
58  } recent;
59 
60  struct {
61  QLabel *label;
62  std::vector<ColorButton *> colors;
63  } def;
64 
65  struct {
66  QLabel *label;
68  } selected;
69 
70  struct {
73 
74  std::array<QLabel *, 4> spinBoxLabels;
75  std::array<QColSpinBox *, 4> spinBoxes;
76 
77  QLabel *htmlLabel;
78  QLineEdit *htmlEdit;
79  } picker;
80  } ui_;
81 
82  enum SpinBox : size_t { RED = 0, GREEN = 1, BLUE = 2, ALPHA = 3, END };
83 
84  static const size_t MAX_RECENT_COLORS = 10;
85  static const size_t RECENT_COLORS_PER_ROW = 5;
86  static const size_t DEFAULT_COLORS_PER_ROW = 5;
87 
88  QColor color_;
89  bool dialogConfirmed_;
90  QRegularExpressionValidator *htmlColorValidator_{};
91 
100  void selectColor(const QColor &color, bool fromColorPicker);
101 
103  void ok();
104 
105  // Helper methods for initializing UI elements
106  void initRecentColors(LayoutCreator<QWidget> &creator);
107  void initDefaultColors(LayoutCreator<QWidget> &creator);
108  void initColorPicker(LayoutCreator<QWidget> &creator);
109  void initSpinBoxes(LayoutCreator<QWidget> &creator);
110  void initHtmlColor(LayoutCreator<QWidget> &creator);
111 
112  void addShortcuts() override;
113 };
114 } // namespace chatterino
~ColorPickerDialog()
Definition: ColorPickerDialog.cpp:113
pajlada::Signals::Signal< QColor > closed
Definition: ColorPickerDialog.hpp:47
ColorButton * color
Definition: ColorPickerDialog.hpp:67
Definition: QColorPicker.hpp:54
Definition: QColorPicker.hpp:89
Definition: Application.cpp:48
struct chatterino::ColorPickerDialog::@28::@31 selected
Definition: BasePopup.hpp:10
QLabel * htmlLabel
Definition: ColorPickerDialog.hpp:77
std::array< QLabel *, 4 > spinBoxLabels
Definition: ColorPickerDialog.hpp:74
QColorLuminancePicker * luminancePicker
Definition: ColorPickerDialog.hpp:72
ColorPickerDialog(const QColor &initial, QWidget *parent)
Create a new color picker dialog that selects the initial color.
Definition: ColorPickerDialog.cpp:11
Definition: ColorButton.hpp:7
void closeEvent(QCloseEvent *)
Definition: ColorPickerDialog.cpp:133
void themeChangedEvent()
Definition: ColorPickerDialog.cpp:138
struct chatterino::ColorPickerDialog::@28::@29 recent
QLabel * label
Definition: ColorPickerDialog.hpp:56
QLineEdit * htmlEdit
Definition: ColorPickerDialog.hpp:78
QColorPicker * colorPicker
Definition: ColorPickerDialog.hpp:71
A custom color picker dialog.
Definition: ColorPickerDialog.hpp:23
Definition: LayoutCreator.hpp:14
std::array< QColSpinBox *, 4 > spinBoxes
Definition: ColorPickerDialog.hpp:75
std::vector< ColorButton * > colors
Definition: ColorPickerDialog.hpp:57
struct chatterino::ColorPickerDialog::@28::@30 def
struct chatterino::ColorPickerDialog::@28::@32 picker
QColor selectedColor() const
Return the final color selected by the user.
Definition: ColorPickerDialog.cpp:122