-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpalette-editor.cpp
64 lines (51 loc) · 1.72 KB
/
palette-editor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "palette-editor.h"
#include <QColorDialog>
#include <QSizePolicy>
PaletteEditor::PaletteEditor(SignalWrapper<Palette> &palette)
: palette(palette)
{
setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
setLayout(&grid_layout);
grid_layout.setSpacing(0);
grid_layout.setContentsMargins(0, 0, 0, 0);
for (int line = 0; line < Palette::TOTAL_LINES; ++line)
{
for (int index = 0; index < Palette::COLOURS_PER_LINE; ++index)
{
ColourButton &button = buttons[line][index];
connect(&button, &ColourButton::clicked, this,
[this, line, index]()
{
ColourButton &button = *static_cast<ColourButton*>(sender());
const QColor selected_colour = QColorDialog::getColor(button.colour(), this, "Select Colour");
if (selected_colour.isValid())
{
button.setColour(selected_colour);
this->palette.modify(
[line, index, &selected_colour](Palette &palette)
{
palette.lines[line].colours[index] = selected_colour;
}
);
}
}
);
button.setColour(palette->lines[line].colours[index].toQColor224());
button.setFixedSize(13, 13);
grid_layout.addWidget(&button, index, line);
}
}
connect(&palette, &SignalWrapper<Palette>::modified, this,
[this]()
{
for (int line = 0; line < Palette::TOTAL_LINES; ++line)
for (int index = 0; index < Palette::COLOURS_PER_LINE; ++index)
buttons[line][index].setColour(this->palette->lines[line].colours[index].toQColor224());
update();
}
);
}
void PaletteEditor::setButtonColour(const int palette_line, const int palette_index, const QColor &colour)
{
buttons[palette_line][palette_index].setColour(colour);
}