Krita Source Code Documentation
Loading...
Searching...
No Matches
kiswdgindexcolors.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Manuel Riecke <spell1337@gmail.com>
3 *
4 * SPDX-License-Identifier: ICS
5 */
6
8
9#include "kiswdgindexcolors.h"
11#include "ui_kiswdgindexcolors.h"
13
15
16#include <kis_color_button.h>
17
18KisWdgIndexColors::KisWdgIndexColors(QWidget* parent, Qt::WindowFlags f, int delay): KisConfigWidget(parent, f, delay)
19{
20 ui = new Ui::KisWdgIndexColors;
21 ui->setupUi(this);
22
23 connect(ui->diagCheck, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
24 connect(ui->inbetweenSpinBox, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
25 connect(ui->alphaStepsSpinBox, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
26
27 connect(ui->colorLimit, SIGNAL(valueChanged(int)), SLOT(slotColorLimitChanged(int)));
28 connect(ui->colorLimit, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
29
30 connect(ui->colorLimitCheck, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));
31
32 connect(ui->luminanceSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
33 connect(ui->aSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
34 connect(ui->bSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged()));
35}
36
38{
39 ui->colorLimit->setSuffix(i18ncp("suffix for a spinbox",
40 " color", " colors", value));
41}
42
43void KisWdgIndexColors::setup(QStringList shadesLabels, int ramps)
44{
45 int rows = shadesLabels.length();
46 int columns = ramps;
47
48 m_colorSelectors.resize(rows);
49 m_stepSpinners.resize(rows-1);
50 // Labels for the shades
51 for(int row = 0; row < rows; ++row)
52 {
53 QLabel* l = new QLabel(shadesLabels[row], ui->colorsBox);
54 ui->layoutColors->addWidget(l, row+1, 0);
55 m_colorSelectors[row].resize(columns);
56 }
57 // Labels for the ramps
58 /*for(int col = 0; col < columns; ++col)
59 {
60 QLabel* l = new QLabel(rampsLabels[col], ui->colorsBox);
61 l->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
62 ui->layoutColors->addWidget(l, 0, col+1);
63 }*/
64 // Step selectors for the shade gradients
65 for(int row = 0; row < (rows-1); ++row)
66 {
67 QLabel* l0 = new QLabel(shadesLabels[row+1]);
68 QLabel* l1 = new QLabel(QString::fromUtf8("↔"));
69 QLabel* l2 = new QLabel(shadesLabels[row]);
70
71 QSpinBox* s = new KisIntParseSpinBox();
72 s->setMinimum(0);
73 s->setMaximum(32);
74 s->setValue(2);
75
76 connect(s, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
77 m_stepSpinners[row] = s;
78
79 ui->layoutRowSteps->addWidget(l0, row, 0);
80 ui->layoutRowSteps->addWidget(l1, row, 1);
81 ui->layoutRowSteps->addWidget(l2, row, 2);
82 ui->layoutRowSteps->addWidget(s, row, 3);
83 }
84 // Color selectors
85 for(int y = 0; y < rows; ++y)
86 for(int x = 0; x < columns; ++x)
87 {
89 QCheckBox* c = new QCheckBox;
90 c->setChecked(false);
91 b->setEnabled(false);
92 b->setMaximumWidth(50);
93 c->setMaximumWidth(21); // Ugh. I hope this won't be causing any issues. Trying to get rid of the unnecessary spacing after it.
94
95 connect(c, SIGNAL(toggled(bool)), b, SLOT(setEnabled(bool)));
96 connect(c, SIGNAL(toggled(bool)), this, SIGNAL(sigConfigurationItemChanged()));
97 connect(b, SIGNAL(changed(KoColor)), this, SIGNAL(sigConfigurationItemChanged()));
98
99 QHBoxLayout* cell = new QHBoxLayout();
100 cell->setSpacing(0);
101 cell->setContentsMargins(0, 0, 0, 0);
102 cell->addWidget(c);
103 cell->addWidget(b);
104 ui->layoutColors->addLayout(cell, 1+y, 1+x);
105
106 m_colorSelectors[y][x].button = b;
107 m_colorSelectors[y][x].checkbox = c;
108 }
109}
110
111
113{
115
117
118 for(int y = 0; y < 4; ++y)
119 for(int x = 0; x < 4; ++x)
120 {
121 palCfg.colors[y][x] = m_colorSelectors[y][x].button->color().toQColor();
122 palCfg.colorsEnabled[y][x] = m_colorSelectors[y][x].button->isEnabled();
123 }
124
125 for(int y = 0; y < 3; ++y)
126 palCfg.gradientSteps[y] = m_stepSpinners[y]->value();
127
128 palCfg.diagonalGradients = ui->diagCheck->isChecked();
129 palCfg.inbetweenRampSteps = ui->inbetweenSpinBox->value();
130
131 IndexColorPalette pal = palCfg.generate();
132 ui->colorCount->setText(QString::number(pal.numColors()));
133
134 config->setProperty("paletteGen", palCfg.toByteArray());
135
136 config->setProperty("LFactor", ui->luminanceSlider->value() / 100.f);
137 config->setProperty("aFactor", ui->aSlider->value() / 100.f);
138 config->setProperty("bFactor", ui->bSlider->value() / 100.f);
139
140 config->setProperty("reduceColorsEnabled", ui->colorLimitCheck->isChecked());
141 config->setProperty("colorLimit", ui->colorLimit->value());
142
143 config->setProperty("alphaSteps", ui->alphaStepsSpinBox->value());
144 return config;
145}
146
148{
150 palCfg.fromByteArray(config->getProperty("paletteGen").toByteArray());
151
152 ui->luminanceSlider->setValue(config->getFloat("LFactor")*100);
153 ui->aSlider->setValue(config->getFloat("aFactor")*100);
154 ui->bSlider->setValue(config->getFloat("bFactor")*100);
155 ui->alphaStepsSpinBox->setValue(config->getInt("alphaSteps"));
156 ui->colorLimitCheck->setChecked(config->getBool("reduceColorsEnabled"));
157 ui->colorLimit->setEnabled(config->getBool("reduceColorsEnabled"));
158 ui->colorLimit->setValue(config->getInt("colorLimit"));
159 ui->diagCheck->setChecked(palCfg.diagonalGradients);
160 ui->inbetweenSpinBox->setValue(palCfg.inbetweenRampSteps);
161
162 for(int y = 0; y < 4; ++y)
163 for(int x = 0; x < 4; ++x)
164 {
165 m_colorSelectors[y][x].checkbox->setChecked(palCfg.colorsEnabled[y][x]);
166 m_colorSelectors[y][x].button->setEnabled(palCfg.colorsEnabled[y][x]);
167 KoColor c;
168 c.fromQColor(palCfg.colors[y][x]);
169 m_colorSelectors[y][x].button->setColor(c);
170 }
171
172 for(int y = 0; y < 3; ++y)
173 m_stepSpinners[y]->setValue(palCfg.gradientSteps[y]);
174
175 IndexColorPalette pal = palCfg.generate();
176 ui->colorCount->setText(QString::number(pal.numColors()));
177}
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
A pushbutton to display or allow user selection of a color.
void sigConfigurationItemChanged()
static KisResourcesInterfaceSP instance()
The KisIntParseSpinBox class is a cleverer SpinBox, able to parse arithmetic expressions.
void slotColorLimitChanged(int value)
void setConfiguration(const KisPropertiesConfigurationSP config) override
KisPropertiesConfigurationSP configuration() const override
QVector< QVector< ColorWidgets > > m_colorSelectors
KisWdgIndexColors(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags(), int delay=500)
void setup(QStringList shadesLabels, int ramps)
QVector< QSpinBox * > m_stepSpinners
Ui::KisWdgIndexColors * ui
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
void fromByteArray(const QByteArray &str)