Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSpinboxHSXSelector.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Mathias Wein <lynx.mw+kde@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QFormLayout>
10#include <QLabel>
11#include <QList>
12#include <QSignalBlocker>
14
16{
17 QList <QLabel*> labels;
18 QList <KisDoubleParseSpinBox*> spinBoxes;
19 QFormLayout *layout {0};
21};
22
24 : QWidget(parent)
25 , m_d(new Private)
26{
27 m_d->layout = new QFormLayout(this);
28 for (int i = 0; i < 3; i++){
29 m_d->labels.push_back(new QLabel(this));
30 m_d->spinBoxes.push_back(new KisDoubleParseSpinBox(this));
31 m_d->layout->addRow(m_d->labels[i], m_d->spinBoxes[i]);
32 connect(m_d->spinBoxes.back(), SIGNAL(valueChanged(double)), this, SLOT(slotSpinBoxChanged()));
33 }
34 m_d->labels[0]->setText(i18n("Hue:"));
35 m_d->labels[1]->setText(i18n("Saturation:"));
36 m_d->labels[2]->setText("<x>:");
37 m_d->spinBoxes[0]->setMaximum(360.0);
38 m_d->spinBoxes[1]->setMaximum(100.0);
39 m_d->spinBoxes[2]->setMaximum(100.0);
40 m_d->spinBoxes[0]->setSuffix(" °");
41 m_d->spinBoxes[1]->setSuffix(" %");
42 m_d->spinBoxes[2]->setSuffix(" %");
43}
44
48
50{
51 if (m_d->selectorModel) {
52 m_d->selectorModel->disconnect(this);
53 disconnect(m_d->selectorModel.data());
54 }
55 m_d->selectorModel = model;
56 if (model) {
57 connect(model.data(), SIGNAL(sigColorModelChanged()), this, SLOT(slotColorModelChanged()));
59 if (model->isHSXModel()) {
60 slotChannelValuesChanged(model->channelValues());
61 }
62 }
63}
64
66{
67 if (!m_d->selectorModel) {
68 return;
69 }
70
71 if (m_d->selectorModel->isHSXModel()) {
72 switch (m_d->selectorModel->colorModel()) {
74 m_d->labels[2]->setText(i18n("Value:"));
75 break;
77 m_d->labels[2]->setText(i18n("Lightness:"));
78 break;
80 m_d->labels[2]->setText(i18n("Intensity:"));
81 break;
83 m_d->labels[2]->setText(i18n("Luma:"));
84 break;
85 default:
86 break;
87 }
88 connect(m_d->selectorModel.data(), SIGNAL(sigChannelValuesChanged(QVector4D,quint32)),
89 this, SLOT(slotChannelValuesChanged(QVector4D)), Qt::UniqueConnection);
90 connect(this, SIGNAL(sigChannelValuesChanged(QVector4D)),
91 m_d->selectorModel.data(), SLOT(slotSetChannelValues(QVector4D)), Qt::UniqueConnection);
92 } else {
93 m_d->selectorModel->disconnect(SIGNAL(sigChannelValuesChanged(QVector4D,quint32)), this);
94 disconnect(SIGNAL(sigChannelValuesChanged(QVector4D)));
95 }
96}
97
99{
100 const QSignalBlocker s1(m_d->spinBoxes[0]), s2(m_d->spinBoxes[1]), s3(m_d->spinBoxes[2]);
101 m_d->spinBoxes[0]->setValue(values[0] * 360.0);
102 m_d->spinBoxes[1]->setValue(values[1] * 100.0);
103 m_d->spinBoxes[2]->setValue(values[2] * 100.0);
104}
105
107{
108 QVector4D hsx(m_d->spinBoxes[0]->value() / 360.0,
109 m_d->spinBoxes[1]->value() / 100.0,
110 m_d->spinBoxes[2]->value() / 100.0,
111 0);
112 Q_EMIT sigChannelValuesChanged(hsx);
113}
QPointF s3
QPointF s1
QPointF s2
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions.
const QScopedPointer< Private > m_d
void slotChannelValuesChanged(const QVector4D &values)
void sigChannelValuesChanged(const QVector4D &values)
void setModel(KisVisualColorModelSP model)
connect signals and slots with given selector model to synchronize value and color model changes.
KisSpinboxHSXSelector(QWidget *parent=nullptr)
QList< KisDoubleParseSpinBox * > spinBoxes