File indexing completed on 2024-12-22 04:16:04

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #include "KisSmudgeLengthOptionWidget.h"
0007 
0008 #include <KisLager.h>
0009 
0010 #include <QWidget>
0011 #include <QComboBox>
0012 #include <QCheckBox>
0013 #include <QFormLayout>
0014 #include <QLabel>
0015 #include <QVBoxLayout>
0016 
0017 #include <KisSmudgeLengthOptionModel.h>
0018 #include <KisWidgetConnectionUtils.h>
0019 
0020 
0021 struct KisSmudgeLengthOptionWidget::Private
0022 {
0023     Private(lager::cursor<KisSmudgeLengthOptionData> optionData,
0024             lager::reader<bool> _isBrushPierced,
0025             lager::reader<bool> forceNewEngine)
0026         : model(optionData.zoom(
0027                     kislager::lenses::to_base<KisSmudgeLengthOptionMixIn>),
0028                 forceNewEngine
0029                 )
0030         , isBrushPierced(_isBrushPierced)
0031     {
0032     }
0033 
0034     KisSmudgeLengthOptionModel model;
0035     lager::reader<bool> isBrushPierced;
0036     QComboBox *cmbSmudgeMode {nullptr};
0037 };
0038 
0039 KisSmudgeLengthOptionWidget::KisSmudgeLengthOptionWidget(lager::cursor<KisSmudgeLengthOptionData> optionData,
0040                                                          lager::reader<bool> isBrushPierced,
0041                                                          lager::reader<bool> forceNewEngine)
0042     : KisCurveOptionWidget(optionData.zoom(kislager::lenses::to_base<KisCurveOptionDataCommon>), KisPaintOpOption::GENERAL)
0043     , m_d(new Private(optionData, isBrushPierced, forceNewEngine))
0044 {
0045     using namespace KisWidgetConnectionUtils;
0046 
0047     setObjectName("KisSmudgeOptionWidget");
0048 
0049     QWidget *page = new QWidget();
0050 
0051     m_d->cmbSmudgeMode = new QComboBox(page);
0052     m_d->cmbSmudgeMode->addItem(i18n("Smearing"), KisSmudgeLengthOptionData::SMEARING_MODE);
0053     m_d->cmbSmudgeMode->addItem("dulling-placeholder" , KisSmudgeLengthOptionData::DULLING_MODE);
0054 
0055     QCheckBox *chkSmearAlpha = new QCheckBox(page);
0056     QCheckBox *chkUseNewEngine = new QCheckBox(page);
0057 
0058     QFormLayout *formLayout = new QFormLayout();
0059     formLayout->addRow(i18n("Smudge mode:"), m_d->cmbSmudgeMode);
0060     formLayout->addRow(i18n("Smear alpha:"), chkSmearAlpha);
0061     formLayout->addRow(i18n("Use new smudge algorithm:"), chkUseNewEngine);
0062     formLayout->addRow(new QLabel(i18n("(required for Color Image, Lightness Map, and Gradient Map brushes)")));
0063 
0064     QVBoxLayout *pageLayout = new QVBoxLayout(page);
0065     pageLayout->setMargin(0);
0066 
0067     pageLayout->addLayout(formLayout);
0068     pageLayout->addWidget(configurationPage());
0069 
0070     setConfigurationPage(page);
0071 
0072     connectControl(m_d->cmbSmudgeMode, &m_d->model, "mode");
0073     connectControl(chkSmearAlpha, &m_d->model, "smearAlpha");
0074     connectControlState(chkUseNewEngine, &m_d->model, "useNewEngineState", "useNewEngine");
0075 
0076     m_d->isBrushPierced.bind(std::bind(&KisSmudgeLengthOptionWidget::updateBrushPierced, this, std::placeholders::_1));
0077     m_d->model.optionData.bind(std::bind(&KisSmudgeLengthOptionWidget::emitSettingChanged, this));
0078 }
0079 
0080 KisSmudgeLengthOptionWidget::~KisSmudgeLengthOptionWidget()
0081 {
0082 
0083 }
0084 
0085 void KisSmudgeLengthOptionWidget::writeOptionSetting(KisPropertiesConfigurationSP setting) const
0086 {
0087     KisCurveOptionWidget::writeOptionSetting(setting);
0088     m_d->model.backedOptionData().write(setting.data());
0089 }
0090 
0091 void KisSmudgeLengthOptionWidget::readOptionSetting(const KisPropertiesConfigurationSP setting)
0092 {
0093     KisSmudgeLengthOptionMixIn data = *m_d->model.optionData;
0094     data.read(setting.data());
0095     m_d->model.optionData.set(data);
0096 
0097     KisCurveOptionWidget::readOptionSetting(setting);
0098 }
0099 
0100 lager::reader<bool> KisSmudgeLengthOptionWidget::useNewEngine() const
0101 {
0102     return m_d->model.LAGER_QT(useNewEngineState)[&CheckBoxState::value];
0103 }
0104 
0105 void KisSmudgeLengthOptionWidget::updateBrushPierced(bool pierced)
0106 {
0107     QString dullingText = i18n("Dulling");
0108     QString toolTip;
0109 
0110     if (pierced) {
0111         dullingText += i18n(" (caution, pierced brush!)");
0112         toolTip = i18nc("@info:tooltip", "This brush has transparent pixels in its center. \"Dulling\" mode may give unstable results. Consider using \"Smearing\" mode instead.");
0113     }
0114 
0115     m_d->cmbSmudgeMode->setItemText(1, dullingText);
0116     m_d->cmbSmudgeMode->setToolTip(toolTip);
0117 }