Krita Source Code Documentation
Loading...
Searching...
No Matches
WGShadeLineEditor.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 "WGShadeLineEditor.h"
8#include "WGShadeSlider.h"
9
10#include "ui_WdgWGShadeLineEditor.h"
11
12#include <QCoreApplication>
13#include <QResizeEvent>
14
16 : QFrame(parent, Qt::Popup)
17 , m_model(new KisVisualColorModel)
18 , m_ui(new Ui_WGShadeLineEditor)
19 , m_previewLine(new WGShadeSlider(WGSelectorDisplayConfigSP(new WGSelectorDisplayConfig()), this, m_model))
20 , m_iconSlider(new WGShadeSlider(WGSelectorDisplayConfigSP(new WGSelectorDisplayConfig()), this, m_model))
21{
22 setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
23
24 m_model->slotSetColorSpace(KoColorSpaceRegistry::instance()->rgb8());
25 m_model->slotSetColor(KoColor(QColor(190, 50, 50), m_model->colorSpace()));
26
27 m_ui->setupUi(this);
28
29 m_previewLine->setObjectName(QString::fromUtf8("previewLine"));
30 m_previewLine->setFixedHeight(24);
31
32 m_ui->verticalLayout->addWidget(m_previewLine);
33
34 m_ui->verticalLayout->setSizeConstraint(QLayout::SetFixedSize);
37 // since this widget is not shown by Qt, a resize event needs to be sent manually
38 QResizeEvent event(QSize(128, 10), m_iconSlider->size());
39 m_iconSlider->resize(128, 10);
40 QCoreApplication::sendEvent(m_iconSlider, &event);
41 m_iconSlider->hide();
42 m_iconSlider->slotSetChannelValues(m_model->channelValues());
43 connect(m_ui->sbRangeHue, SIGNAL(valueChanged(double)), SLOT(slotValueChanged()));
44 connect(m_ui->sbRangeSaturation, SIGNAL(valueChanged(double)), SLOT(slotValueChanged()));
45 connect(m_ui->sbRangeValue, SIGNAL(valueChanged(double)), SLOT(slotValueChanged()));
46 connect(m_ui->sbOffsetHue, SIGNAL(valueChanged(double)), SLOT(slotValueChanged()));
47 connect(m_ui->sbOffsetSaturation, SIGNAL(valueChanged(double)), SLOT(slotValueChanged()));
48 connect(m_ui->sbOffsetValue, SIGNAL(valueChanged(double)), SLOT(slotValueChanged()));
49 connect(m_ui->sbPatchCount, SIGNAL(valueChanged(int)), SLOT(slotPatchCountChanged(int)));
50 connect(m_ui->rbSlider, SIGNAL(toggled(bool)), SLOT(slotSliderModeChanged(bool)));
51 // disable spinBox when slider mode set
52 connect(m_ui->rbColorPatches, SIGNAL(toggled(bool)), m_ui->sbPatchCount, SLOT(setEnabled(bool)));
53}
54
59
61{
63 cfg.gradient = QVector4D(m_ui->sbRangeHue->value(),
64 m_ui->sbRangeSaturation->value(),
65 m_ui->sbRangeValue->value(),
66 0);
67 cfg.offset = QVector4D(m_ui->sbOffsetHue->value(),
68 m_ui->sbOffsetSaturation->value(),
69 m_ui->sbOffsetValue->value(),
70 0);
71 cfg.patchCount = m_ui->rbSlider->isChecked() ? -1 : m_ui->sbPatchCount->value();
72 return cfg;
73}
74
76{
77 m_ui->sbRangeHue->setValue(cfg.gradient.x());
78 m_ui->sbRangeSaturation->setValue(cfg.gradient.y());
79 m_ui->sbRangeValue->setValue(cfg.gradient.z());
80 m_ui->sbOffsetHue->setValue(cfg.offset.x());
81 m_ui->sbOffsetSaturation->setValue(cfg.offset.y());
82 m_ui->sbOffsetValue->setValue(cfg.offset.z());
83 if (cfg.patchCount > 0) {
84 m_ui->rbColorPatches->setChecked(true);
85 m_ui->sbPatchCount->setValue(cfg.patchCount);
86 }
87 else {
88 m_ui->rbSlider->setChecked(true);
89 }
90 m_lineIndex = lineIndex;
91}
92
94{
97 return QIcon(QPixmap::fromImage(*m_iconSlider->background()));
98}
99
100void WGShadeLineEditor::hideEvent(QHideEvent *event)
101{
103 QWidget::hideEvent(event);
104}
105
111
116
118{
119 m_previewLine->setDisplayMode(enabled, m_ui->sbPatchCount->value());
120}
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisVisualColorModel class allows manipulating a KoColor using various color models.
void slotPatchCountChanged(int value)
WGShadeLineEditor(QWidget *parent=nullptr)
void sigEditorClosed(int lineIndex)
void slotSliderModeChanged(bool enabled)
WGShadeSlider * m_previewLine
KisVisualColorModelSP m_model
QIcon generateIcon(const WGConfig::ShadeLine &cfg)
void setConfiguration(const WGConfig::ShadeLine &cfg, int lineIndex)
void hideEvent(QHideEvent *event) override
WGShadeSlider * m_iconSlider
WGConfig::ShadeLine configuration() const
QScopedPointer< Ui_WGShadeLineEditor > m_ui
const QImage * background()
void setModel(KisVisualColorModelSP model)
void setDisplayMode(bool slider, int numPatches=-1)
void slotSetChannelValues(const QVector4D &values)
void setGradient(const QVector4D &range, const QVector4D &offset)
static KoColorSpaceRegistry * instance()
QVector4D offset
Definition WGConfig.h:88
QVector4D gradient
Definition WGConfig.h:87