| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2020 Mathias Wein <[email protected]> |
| 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 |
|
| 15 |
WGShadeLineEditor::WGShadeLineEditor(QWidget *parent) |
| 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); |
| 35 |
m_previewLine->setModel(m_model); |
| 36 |
m_previewLine->slotSetChannelValues(m_model->channelValues()); |
| 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 |
|
| 55 |
WGShadeLineEditor::~WGShadeLineEditor() |
| 56 |
{ |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
WGConfig::ShadeLine WGShadeLineEditor::configuration() const |
| 61 |
{ |
| 62 |
WGConfig::ShadeLine cfg; |
| 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 |
|
| 75 |
void WGShadeLineEditor::setConfiguration(const WGConfig::ShadeLine &cfg, int lineIndex) |
| 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 |
|
| 93 |
QIcon WGShadeLineEditor::generateIcon(const WGConfig::ShadeLine &cfg) |
| 94 |
{ |
| 95 |
m_iconSlider->setGradient(cfg.gradient, cfg.offset); |
| 96 |
m_iconSlider->setDisplayMode(cfg.patchCount < 0, cfg.patchCount); |
| 97 |
return QIcon(QPixmap::fromImage(*m_iconSlider->background())); |
| 98 |
} |
| 99 |
|
| 100 |
void WGShadeLineEditor::hideEvent(QHideEvent *event) |
| 101 |
{ |
| 102 |
Q_EMIT sigEditorClosed(m_lineIndex); |
| 103 |
QWidget::hideEvent(event); |
| 104 |
} |
| 105 |
|
| 106 |
void WGShadeLineEditor::slotValueChanged() |
| 107 |
{ |
| 108 |
WGConfig::ShadeLine cfg = configuration(); |
| 109 |
m_previewLine->setGradient(cfg.gradient, cfg.offset); |
| 110 |
} |
| 111 |
|
| 112 |
void WGShadeLineEditor::slotPatchCountChanged(int value) |
| 113 |
{ |
| 114 |
m_previewLine->setDisplayMode(false, value); |
| 115 |
} |
| 116 |
|
| 117 |
void WGShadeLineEditor::slotSliderModeChanged(bool enabled) |
| 118 |
{ |
| 119 |
m_previewLine->setDisplayMode(enabled, m_ui->sbPatchCount->value()); |
| 120 |
} |