File indexing completed on 2024-05-26 04:27:30

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_uniform_paintop_property.h"
0008 
0009 #include <QVariant>
0010 #include "kis_debug.h"
0011 #include "kis_paintop_settings.h"
0012 
0013 struct KisUniformPaintOpProperty::Private
0014 {
0015     Private(Type _type, SubType _subType, const KoID &_id, KisPaintOpSettingsSP _settings)
0016         : type(_type)
0017         , subType(_subType)
0018         , id(_id)
0019         , settings(_settings)
0020         , isReadingValue(false)
0021         , isWritingValue(false)
0022     {
0023     }
0024 
0025     Type type;
0026     SubType subType;
0027     KoID id;
0028 
0029     QVariant value;
0030 
0031     KisPaintOpSettingsSP settings;
0032     bool isReadingValue;
0033     bool isWritingValue;
0034 };
0035 
0036 KisUniformPaintOpProperty::KisUniformPaintOpProperty(Type type, SubType subType, const KoID &id, KisPaintOpSettingsRestrictedSP settings, QObject *parent)
0037     : QObject(parent)
0038     , m_d(new Private(type, subType, id, settings))
0039 {
0040 }
0041 
0042 KisUniformPaintOpProperty::KisUniformPaintOpProperty(Type type, const KoID &id, KisPaintOpSettingsRestrictedSP settings, QObject *parent)
0043     : QObject(parent)
0044     , m_d(new Private(type, SubType_None, id, settings))
0045 {
0046 }
0047 
0048 KisUniformPaintOpProperty::KisUniformPaintOpProperty(const KoID &id, KisPaintOpSettingsRestrictedSP settings, QObject *parent)
0049     : QObject(parent)
0050     , m_d(new Private(Bool, SubType_None, id, settings))
0051 {
0052 }
0053 
0054 KisUniformPaintOpProperty::~KisUniformPaintOpProperty()
0055 {
0056 }
0057 
0058 QString KisUniformPaintOpProperty::id() const
0059 {
0060     return m_d->id.id();
0061 }
0062 
0063 QString KisUniformPaintOpProperty::name() const
0064 {
0065     return m_d->id.name();
0066 }
0067 
0068 KisUniformPaintOpProperty::Type KisUniformPaintOpProperty::type() const
0069 {
0070     return m_d->type;
0071 }
0072 
0073 KisUniformPaintOpProperty::SubType KisUniformPaintOpProperty::subType() const
0074 {
0075     return m_d->subType;
0076 }
0077 
0078 QVariant KisUniformPaintOpProperty::value() const
0079 {
0080     return m_d->value;
0081 }
0082 
0083 QWidget *KisUniformPaintOpProperty::createPropertyWidget()
0084 {
0085     return nullptr;
0086 }
0087 
0088 void KisUniformPaintOpProperty::setValue(const QVariant &value)
0089 {
0090     if (m_d->value == value) return;
0091     m_d->value = value;
0092 
0093     emit valueChanged(value);
0094 
0095     if (!m_d->isReadingValue) {
0096         m_d->isWritingValue = true;
0097         writeValueImpl();
0098         m_d->isWritingValue = false;
0099     }
0100 }
0101 
0102 void KisUniformPaintOpProperty::requestReadValue()
0103 {
0104     if (m_d->isWritingValue) return;
0105 
0106     m_d->isReadingValue = true;
0107     readValueImpl();
0108     m_d->isReadingValue = false;
0109 }
0110 
0111 KisPaintOpSettingsSP KisUniformPaintOpProperty::settings() const
0112 {
0113     // correct conversion weak-to-strong shared pointer
0114     return m_d->settings ? m_d->settings : KisPaintOpSettingsSP();
0115 }
0116 
0117 bool KisUniformPaintOpProperty::isVisible() const
0118 {
0119     return true;
0120 }
0121 
0122 void KisUniformPaintOpProperty::readValueImpl()
0123 {
0124 }
0125 
0126 void KisUniformPaintOpProperty::writeValueImpl()
0127 {
0128 }
0129 
0130 #include "kis_callback_based_paintop_property_impl.h"
0131 
0132 template class KRITAIMAGE_EXPORT_INSTANCE
0133     KisCallbackBasedPaintopProperty<KisUniformPaintOpProperty>;