Commit 089cadb3 authored by Boudewijn Rempt's avatar Boudewijn Rempt

KisPaintOpFactory: implement composite op whitelist

Some paintops can make good use of composite ops that are normally not
user visible, such as copy. Following discussion on irc with Sven and
Lukas, create a whitelist for those.

svn path=/trunk/koffice/; revision=1177105
parent 813bed69
......@@ -19,10 +19,16 @@
#include <KoColorSpace.h>
KisPaintOpFactory::KisPaintOpFactory()
KisPaintOpFactory::KisPaintOpFactory(const QStringList & whiteListedCompositeOps)
: m_whiteListedCompositeOps(whiteListedCompositeOps)
{
}
QStringList KisPaintOpFactory::whiteListedCompositeOps() const
{
return m_whiteListedCompositeOps;
}
bool KisPaintOpFactory::userVisible(const KoColorSpace * cs)
{
return cs && cs->id() != "WET";
......
......@@ -23,6 +23,7 @@
#include "krita_export.h"
#include <QObject>
#include <QString>
#include <QStringList>
class KoColorSpace;
class KisPainter;
......@@ -42,7 +43,7 @@ class KRITAIMAGE_EXPORT KisPaintOpFactory : public QObject
public:
KisPaintOpFactory();
KisPaintOpFactory(const QStringList & whiteListedCompositeOps = QStringList());
virtual ~KisPaintOpFactory() {}
/**
......@@ -54,6 +55,12 @@ public:
virtual QString id() const = 0;
virtual QString name() const = 0;
/**
* List of usually hidden compositeops that are useful for this paintop.
*/
QStringList whiteListedCompositeOps() const;
/**
* The filename of the pixmap we can use to represent this paintop in the ui.
*/
......@@ -75,7 +82,8 @@ public:
* create a widget that can display paintop settings
*/
virtual KisPaintOpSettingsWidget* createSettingsWidget(QWidget* parent) = 0;
private:
QStringList m_whiteListedCompositeOps;
};
#endif
......@@ -26,6 +26,8 @@
#include <kis_debug.h>
#include <kpluginfactory.h>
#include <KoCompositeOp.h>
#include "kis_simple_paintop_factory.h"
#include "kis_brushop.h"
#include "kis_brushop_settings_widget.h"
......@@ -48,7 +50,9 @@ DefaultPaintOpsPlugin::DefaultPaintOpsPlugin(QObject *parent, const QVariantList
KisPaintOpRegistry *r = KisPaintOpRegistry::instance();
r->add(new KisSimplePaintOpFactory<KisBrushOp, KisBrushBasedPaintOpSettings, KisBrushOpSettingsWidget>("paintbrush", i18n("Pixel Brush"), "krita-paintbrush.png"));
r->add(new KisDuplicateOpFactory);
r->add(new KisSimplePaintOpFactory<KisSmudgeOp, KisBrushBasedPaintOpSettings, KisSmudgeOpSettingsWidget>("smudge", i18n("Smudge Brush"), "krita-smudgebrush.png","smudge-finger"));
QStringList whiteList;
whiteList << COMPOSITE_COPY;
r->add(new KisSimplePaintOpFactory<KisSmudgeOp, KisBrushBasedPaintOpSettings, KisSmudgeOpSettingsWidget>("smudge", i18n("Smudge Brush"), "krita-smudgebrush.png","smudge-finger", whiteList));
}
DefaultPaintOpsPlugin::~DefaultPaintOpsPlugin()
......
......@@ -23,12 +23,14 @@
#include <kis_image.h>
#include <KoInputDevice.h>
#include <KoCompositeOp.h>
#include "kis_deform_paintop_settings_widget.h"
#include "kis_deform_paintop_settings.h"
#include "kis_deform_paintop.h"
KisDeformPaintOpFactory::KisDeformPaintOpFactory()
: KisPaintOpFactory(QStringList(COMPOSITE_COPY))
{
}
......
......@@ -37,21 +37,21 @@
#include "kis_brush.h"
KisHairyPaintOp::KisHairyPaintOp(const
KisBrushBasedPaintOpSettings *settings, KisPainter * painter, KisImageWSP image)
KisHairyPaintOp::KisHairyPaintOp(const KisBrushBasedPaintOpSettings *settings, KisPainter * painter, KisImageWSP image)
: KisPaintOp(painter)
, m_settings(settings)
, newStrokeFlag(true)
{
Q_UNUSED(image)
Q_ASSERT(settings);
if (!settings->node()) {
m_dev = 0;
} else {
m_dev = settings->node()->paintDevice();
}
}
KisBrushOption brushOption;
brushOption.readOptionSetting(settings);
KisBrushSP brush = brushOption.brush();
......@@ -61,13 +61,13 @@ KisHairyPaintOp::KisHairyPaintOp(const
} else {
brush->mask(dab, painter->paintColor(), 1.0, 1.0, 0.0);
}
m_brush.fromDabWithDensity(dab, settings->getDouble(HAIRY_BRISTLE_DENSITY) * 0.01);
m_brush.setInkColor(painter->paintColor());
loadSettings(settings);
m_brush.setProperties( &m_properties );
m_rotationOption.readOptionSetting(settings);
m_opacityOption.readOptionSetting(settings);
m_sizeOption.readOptionSetting(settings);
......@@ -80,7 +80,7 @@ void KisHairyPaintOp::loadSettings(const KisBrushBasedPaintOpSettings* settings)
{
m_properties.inkAmount = settings->getInt(HAIRY_INK_AMOUNT);
//TODO: wait for the transfer function with variable size
m_properties.inkDepletionCurve = settings->getCubicCurve(HAIRY_INK_DEPLETION_CURVE).floatTransfer(m_properties.inkAmount);
m_properties.inkDepletionEnabled = settings->getBool(HAIRY_INK_DEPLETION_ENABLED);
......@@ -124,14 +124,14 @@ KisDistanceInformation KisHairyPaintOp::paintLine(const KisPaintInformation &pi1
} else {
m_dab->clear();
}
qreal scale = KisPaintOp::scaleForPressure(m_sizeOption.apply(pi2));
qreal rotation = m_rotationOption.apply(pi2);
quint8 origOpacity = m_opacityOption.apply(painter(), pi2);
setCurrentScale(scale);
setCurrentRotation(rotation);
m_brush.paintLine(m_dab, m_dev, pi1, pi2, scale * m_properties.scaleFactor, rotation);
//QRect rc = m_dab->exactBounds();
......@@ -142,6 +142,6 @@ KisDistanceInformation KisHairyPaintOp::paintLine(const KisPaintInformation &pi1
KisVector2D end = toKisVector2D(pi2.pos());
KisVector2D start = toKisVector2D(pi1.pos());
KisVector2D dragVec = end - start;
return KisDistanceInformation(0, dragVec.norm());
}
......@@ -30,8 +30,10 @@ template <class Op, class OpSettings, class OpSettingsWidget> class KisSimplePai
public:
KisSimplePaintOpFactory(const QString& id, const QString& name,
const QString& pixmap, const QString& model = QString())
: m_id(id)
const QString& pixmap, const QString& model = QString(),
const QStringList& whiteListedCompositeOps = QStringList())
: KisPaintOpFactory(whiteListedCompositeOps)
, m_id(id)
, m_name(name)
, m_pixmap(pixmap)
, m_model(model)
......@@ -41,7 +43,7 @@ public:
virtual ~KisSimplePaintOpFactory()
{
}
KisPaintOp * createOp(const KisPaintOpSettingsSP settings, KisPainter * painter, KisImageWSP image = 0)
{
const OpSettings *opSettings = dynamic_cast<const OpSettings *>(settings.data());
......@@ -64,7 +66,7 @@ public:
{
return new OpSettingsWidget(parent);
}
QString id() const {
return m_id;
}
......@@ -76,7 +78,7 @@ public:
QString pixmap() {
return m_pixmap;
}
private:
QString m_id;
QString m_name;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment