Krita Source Code Documentation
Loading...
Searching...
No Matches
WGShadeSelector.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-3.0-or-later
5 */
6
7#include "WGShadeSelector.h"
8
9#include "WGConfig.h"
10#include "WGShadeSlider.h"
11
12#include <QVBoxLayout>
13#include <QMouseEvent>
14
16 : WGSelectorWidgetBase(displayConfig, parent)
17 , m_model(colorModel)
18{
19 QVBoxLayout* l = new QVBoxLayout(this);
20 l->setSpacing(1);
21 l->setContentsMargins(0, 0, 0, 0);
22 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
23
25}
26
28{
29 if (m_model) {
30 m_model->disconnect(this);
31 disconnect(m_model.data());
32 }
33 m_model = colorModel;
34 for (WGShadeSlider *slider : std::as_const(m_sliders)) {
35 slider->setModel(m_model);
36 }
38 if (m_model->colorModel() != KisVisualColorModel::None) {
39 slotChannelValuesChanged(m_model->channelValues());
40 }
41}
42
44{
47 QVector<WGConfig::ShadeLine> config = cfg.shadeSelectorLines();
48
49 while (config.size() > m_sliders.size()) {
51 m_sliders.append(line);
52 layout()->addWidget(m_sliders.last());
53 connect(line, SIGNAL(sigChannelValuesChanged(QVector4D)), SLOT(slotSliderValuesChanged(QVector4D)));
54 connect(line, SIGNAL(sigInteraction(bool)), SLOT(slotSliderInteraction(bool)));
55 }
56 while (config.size() < m_sliders.size()) {
57 layout()->removeWidget(m_sliders.last());
58 delete m_sliders.takeLast();
59 }
60
61 for (int i=0; i < config.size(); i++) {
62 m_sliders[i]->setGradient(config[i].gradient, config[i].offset);
63 m_sliders[i]->setDisplayMode(config[i].patchCount < 0, config[i].patchCount);
64 m_sliders[i]->setFixedHeight(m_lineHeight);
65 }
69
70 if (m_model->colorModel() != KisVisualColorModel::None) {
71 slotReset();
72 slotChannelValuesChanged(m_model->channelValues());
73 }
74}
75
76void WGShadeSelector::mousePressEvent(QMouseEvent *event)
77{
78 if (m_resetOnRightClick && event->button() == Qt::RightButton) {
79 for (WGShadeSlider* slider : std::as_const(m_sliders)) {
80 slider->slotSetChannelValues(m_model->channelValues());
81 }
82 }
83}
84
86{
87 connect(m_model.data(), SIGNAL(sigColorModelChanged()), SLOT(slotReset()));
88 connect(m_model.data(), SIGNAL(sigColorSpaceChanged()), SLOT(slotReset()));
89 connect(m_model.data(), SIGNAL(sigChannelValuesChanged(QVector4D,quint32)),
90 SLOT(slotChannelValuesChanged(QVector4D)));
91 connect(this, SIGNAL(sigChannelValuesChanged(QVector4D)),
92 m_model.data(), SLOT(slotSetChannelValues(QVector4D)));
93}
94
95void WGShadeSelector::slotChannelValuesChanged(const QVector4D &values)
96{
98 for (WGShadeSlider* slider : std::as_const(m_sliders)) {
99 slider->slotSetChannelValues(values);
100 }
101 m_initialized = true;
102 }
103}
104
105void WGShadeSelector::slotSliderValuesChanged(const QVector4D &values)
106{
107 m_allowUpdates = false;
108 Q_EMIT sigChannelValuesChanged(values);
109 m_allowUpdates = true;
110}
111
113{
114 if (active) {
115 const WGShadeSlider* activeLine = qobject_cast<WGShadeSlider*>(sender());
116 for (WGShadeSlider* slider : std::as_const(m_sliders)) {
117 if (slider != activeLine) {
118 slider->resetHandle();
119 }
120 }
121 Q_EMIT sigColorInteraction(active);
122 if (activeLine) {
123 // the line may have different channel values at any position than the last used one
124 m_allowUpdates = false;
125 Q_EMIT sigChannelValuesChanged(activeLine->channelValues());
126 m_allowUpdates = true;
127 }
128 }
129 else {
130 // reset slider base values if configured for automatic reset
132 for (WGShadeSlider* slider : std::as_const(m_sliders)) {
133 slider->slotSetChannelValues(m_model->channelValues());
134 }
135 }
136 Q_EMIT sigColorInteraction(active);
137 }
138}
139
141{
142 m_initialized = false;
143}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void sigChannelValuesChanged(const QVector4D &values)
WGSelectorDisplayConfigSP displayConfiguration() const
void sigColorInteraction(bool active)
void slotSliderValuesChanged(const QVector4D &values)
WGShadeSelector(WGSelectorDisplayConfigSP displayConfig, KisVisualColorModelSP colorModel, QWidget *parent=nullptr)
void slotSliderInteraction(bool active)
void slotChannelValuesChanged(const QVector4D &values)
KisVisualColorModelSP m_model
void setModel(KisVisualColorModelSP colorModel) override
void mousePressEvent(QMouseEvent *event) override
void updateSettings() override
QVector< WGShadeSlider * > m_sliders
QVector4D channelValues() const
const NumericSetting< int > shadeSelectorLineHeight
Definition WGConfig.cpp:247
class WGConfig Accessor
const GenericSetting< bool > shadeSelectorUpdateOnExternalChanges
Definition WGConfig.cpp:248
const GenericSetting< bool > shadeSelectorUpdateOnInteractionEnd
Definition WGConfig.cpp:249
const GenericSetting< bool > shadeSelectorUpdateOnRightClick
Definition WGConfig.cpp:250