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

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Agata Cacko <cacko.azh@gmail.com>
0003  *  SPDX-FileCopyrightText: 2008, 2009, 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
0004  * 
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 #include "KisSprayShapeOptionWidget.h"
0009 
0010 #include <QButtonGroup>
0011 #include <QMetaProperty>
0012 #include <QMetaMethod>
0013 
0014 #include <KisImportExportManager.h>
0015 #include "kis_aspect_ratio_locker.h"
0016 
0017 #include <lager/constant.hpp>
0018 #include "ui_wdgsprayshapeoptions.h"
0019 #include "kis_signals_blocker.h"
0020 
0021 #include "KisSprayShapeOptionModel.h"
0022 
0023 
0024 namespace {
0025 class KisShapeOptionsWidget: public QWidget, public Ui::WdgSprayShapeOptions
0026 {
0027 public:
0028     KisShapeOptionsWidget(QWidget *parent = 0)
0029         : QWidget(parent) {
0030         setupUi(this);
0031         imageUrlRequester->setMimeTypeFilters(KisImportExportManager::supportedMimeTypes(KisImportExportManager::Import));
0032         
0033         //initialize slider values
0034         widthSpin->setRange(1, 1000, 0);
0035         widthSpin->setValue(6);
0036         widthSpin->setSuffix(i18n(" px"));
0037 
0038         heightSpin->setRange(1, 1000, 0);
0039         heightSpin->setValue(6);
0040         heightSpin->setSuffix(i18n(" px"));
0041     }
0042 };
0043 }
0044 
0045 struct KisSprayShapeOptionWidget::Private
0046 {
0047     Private(lager::cursor<KisSprayShapeOptionData> optionData, lager::cursor<int> diameter, lager::cursor<qreal> scale)
0048         : model(optionData, diameter, scale)
0049     {
0050     }
0051 
0052     KisSprayShapeOptionModel model;
0053     KisAspectRatioLocker *sizeRatioLocker;
0054     KisShapeOptionsWidget *widget;
0055 };
0056 
0057 KisSprayShapeOptionWidget::KisSprayShapeOptionWidget(lager::cursor<KisSprayShapeOptionData> optionData, lager::cursor<int> diameter, lager::cursor<qreal> scale)
0058     : KisPaintOpOption(i18n("Spray Shape"), KisPaintOpOption::GENERAL, optionData[&KisSprayShapeOptionData::enabled])
0059     , m_d(new Private(optionData, diameter, scale))
0060 {
0061     
0062     KisShapeOptionsWidget *widget = new KisShapeOptionsWidget();
0063     m_d->widget = widget;
0064     
0065     setObjectName("KisSprayShapeOptionWidget");
0066     
0067     m_checkable = true;
0068     
0069     using namespace KisWidgetConnectionUtils;
0070     
0071     m_d->sizeRatioLocker = new KisAspectRatioLocker(this);
0072     m_d->sizeRatioLocker->connectSpinBoxes(widget->widthSpin, widget->heightSpin, widget->aspectButton);
0073     
0074     connect(m_d->sizeRatioLocker, &KisAspectRatioLocker::sliderValueChanged, widget,
0075             [this, widget] () {
0076                 m_d->model.seteffectiveSize(QSize(widget->widthSpin->value(), widget->heightSpin->value()));
0077             });
0078     
0079     m_d->model.LAGER_QT(effectiveSize).bind([this, widget] (QSize value) {
0080         KisSignalsBlocker b(widget->widthSpin);
0081         KisSignalsBlocker b2(widget->heightSpin);
0082         
0083         widget->widthSpin->setValue(value.width());
0084         widget->heightSpin->setValue(value.height());
0085         
0086         m_d->sizeRatioLocker->updateAspect();
0087     });
0088     
0089     connectControl(widget->shapeBox, &m_d->model, "shape");
0090     
0091     connectControl(widget->proportionalBox, &m_d->model, "effectiveProportional");
0092 
0093     connectControl(widget->imageUrlRequester, &m_d->model, "imageUrl");
0094     
0095     m_d->widget->widthSpin->setSuffix(m_d->model.sizeSuffix());
0096     m_d->widget->heightSpin->setSuffix(m_d->model.sizeSuffix());
0097     
0098     connect(&m_d->model, &KisSprayShapeOptionModel::sizeSuffixChanged, m_d->widget->widthSpin, &KisDoubleSliderSpinBox::setSuffix);
0099     connect(&m_d->model, &KisSprayShapeOptionModel::sizeSuffixChanged, m_d->widget->heightSpin, &KisDoubleSliderSpinBox::setSuffix);
0100     
0101     m_d->model.optionData.bind(std::bind(&KisSprayShapeOptionWidget::emitSettingChanged, this));
0102     
0103     setConfigurationPage(widget);
0104 }
0105 
0106 KisSprayShapeOptionWidget::~KisSprayShapeOptionWidget()
0107 {
0108 }
0109 
0110 void KisSprayShapeOptionWidget::writeOptionSetting(KisPropertiesConfigurationSP setting) const
0111 {
0112     KisSprayShapeOptionData data = *m_d->model.optionData;
0113     data.write(setting.data());
0114 }
0115 
0116 void KisSprayShapeOptionWidget::readOptionSetting(const KisPropertiesConfigurationSP setting)
0117 {
0118     KisSprayShapeOptionData data = *m_d->model.optionData;
0119     data.read(setting.data());
0120     m_d->model.optionData.set(data);
0121 }