Commit 56b882d9 authored by Bart Coppens's avatar Bart Coppens

Add a system that can, if needed, automatically perform actions on a paint...

Add a system that can, if needed, automatically perform actions on a paint device at creation time. This is used so that if the user creates a new layer with the Wet colorstrategy it will automatically get a texture assigned to it.
This removes the need for seperate initialization by the user.

svn path=/trunk/koffice/; revision=480123
parent 09636cf9
......@@ -25,29 +25,20 @@
#include "kis_texture_painter.h"
#include "kis_texture_filter.h"
TextureFilter::TextureFilter(KisView* view)
: m_view(view) {
}
void TextureFilter::slotActivated() {
if (!m_view -> getCanvasSubject()->currentImg())
return;
if (!m_view -> getCanvasSubject()->currentImg() -> activeDevice())
return;
KisPaintDeviceImplSP device = m_view -> getCanvasSubject()->currentImg() -> activeDevice();
void WetPaintDevAction::act(KisPaintDeviceImplSP device, Q_INT32 w, Q_INT32 h) const {
KisColorSpace * cs = device -> colorSpace();
if (cs -> id() != KisID("WET","")) {
kdDebug(DBG_AREA_CMS) << "You set this kind of texture on non-wet layers!.\n";
return;
} else {
kdDebug(DBG_AREA_CMS) << "Wet Paint Action activated!\n";
}
// XXX if params of the painter get configurable, make them here configurable as well?
KisTexturePainter painter(device);
painter.createTexture(0, 0, m_view -> getCanvasSubject()->currentImg() -> width(), m_view -> getCanvasSubject()->currentImg() -> height());
painter.createTexture(0, 0, w, h);
painter.end();
m_view -> getCanvasSubject()->currentImg() -> notify();
}
#include "kis_texture_filter.moc"
......@@ -21,24 +21,18 @@
#ifndef _TEXTURE_FILTER_H
#define _TEXTURE_FILTER_H
#include <qobject.h>
#include <qtimer.h>
#include <kactionclasses.h>
#include <qstring.h>
#include <klocale.h>
#include <kis_paint_device_action.h>
class KisView;
class TextureFilter : public QObject
{
Q_OBJECT
/// Initializes a wet paint device with a texture
class WetPaintDevAction : public KisPaintDeviceAction {
public:
TextureFilter(KisView* view);
virtual ~TextureFilter() {}
private slots:
void slotActivated();
virtual ~WetPaintDevAction() {}
private:
KisView * m_view;
virtual void act(KisPaintDeviceImplSP device, Q_INT32 w = 0, Q_INT32 h = 0) const;
virtual QString name() const { return i18n("Wet Texture"); }
virtual QString description() const { return i18n("Add a texture to the wet canvas"); }
};
#endif // _TEXTURE_FILTER_H
......@@ -100,6 +100,9 @@ WetPlugin::WetPlugin(QObject *parent, const char *name, const QStringList &)
// Dry filter
KisFilterRegistry::instance() -> add( new WetPhysicsFilter() );
// Texture Action:
f -> addPaintDeviceAction(colorSpaceWet, new WetPaintDevAction);
//(void) new KAction(i18n("Dry the paint (25 times)"), 0, 0, kfi, SLOT(slotActivated()), actionCollection(), "wetphysics");
}
else if (parent -> inherits("KisView"))
......@@ -112,10 +115,6 @@ WetPlugin::WetPlugin(QObject *parent, const char *name, const QStringList &)
WetnessVisualisationFilter * wf = new WetnessVisualisationFilter(m_view);
wf -> setAction(new KToggleAction(i18n("Wetness Visualisation"), 0, 0, wf,
SLOT(slotActivated()), actionCollection(), "wetnessvisualisation"));
// Texture filter
(void) new KAction(i18n("Initialize Texture"), 0, 0, new TextureFilter(m_view),
SLOT(slotActivated()), actionCollection(), "texturefilter");
// Create the wet palette
KisWetPaletteWidget * w = new KisWetPaletteWidget(m_view);
......
......@@ -4,11 +4,5 @@
<Menu name="View"><text>&amp;View</text>
<Action name="wetnessvisualisation"/>
</Menu>
<Menu name="Layer"><text>La&amp;yer</text>
<Menu name="watercolors"><text>&amp;Watercolors</text>
<Action name="texturefilter"/>
</Menu>
</Menu>
</MenuBar>
</kpartgui>
/*
* Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_PAINTDEV_ACTION_H_
#define KIS_PAINTDEV_ACTION_H_
#include "kis_paint_device_impl.h"
class QString;
/**
* Defines an action to do with a paint device. It can be force used by the gui on creation
* of a layer, for example. Or just appear in a list of actions to do.
*/
class KisPaintDeviceAction {
public:
virtual ~KisPaintDeviceAction() {}
/**
* Do something with the paint device. This can be anything, like, for example, popping
* up a dialog to choose a texture. The width and height are added because these may
* be needed in some cases.
*/
virtual void act(KisPaintDeviceImplSP paintDev, Q_INT32 w = 0, Q_INT32 h = 0) const = 0;
/// The name of the action, to be displayed in the GUI
virtual QString name() const = 0;
/// A description of the action, to be displayed in the GUI
virtual QString description() const = 0;
};
#endif // KIS_PAINTDEV_ACTION_H_
......@@ -120,6 +120,16 @@ void KisColorSpaceFactoryRegistry::addProfile(KisProfile *p)
}
}
void KisColorSpaceFactoryRegistry::addPaintDeviceAction(KisColorSpace* cs,
KisPaintDeviceAction* action) {
m_paintDevActionMap[cs -> id()].append(action);
}
QValueVector<KisPaintDeviceAction *>
KisColorSpaceFactoryRegistry::paintDeviceActionsFor(KisColorSpace* cs) {
return m_paintDevActionMap[cs -> id()];
}
KisColorSpace * KisColorSpaceFactoryRegistry::getColorSpace(const KisID & csID, const QString & pName)
{
QString profileName = pName;
......
......@@ -24,12 +24,14 @@
#include "kis_colorspace.h"
class QStringList;
class KisPaintDeviceAction;
/**
* This class contains:
* - a registry of singleton color strategies.
* - a registry of icc profiles
* - a registry of default pixel operations
* - a registry of actions that can be performed when a layer with a colorstrategy is made
*/
class KisColorSpaceFactoryRegistry : public QObject, public KisGenericRegistry<KisColorSpaceFactory *> {
......@@ -93,6 +95,16 @@ public:
*/
KisColorSpace * getRGB8();
/**
* add a KisConstructPaintDeviceAction to the registry for a colorspace
*/
void addPaintDeviceAction(KisColorSpace* cs, KisPaintDeviceAction* action);
/**
* Get a list of KisConstructPaintDeviceAction for a colorspace
*/
QValueVector<KisPaintDeviceAction *> paintDeviceActionsFor(KisColorSpace* cs);
private:
KisColorSpaceFactoryRegistry();
KisColorSpaceFactoryRegistry(const KisColorSpaceFactoryRegistry&);
......@@ -102,6 +114,8 @@ private:
QMap<QString, KisProfile * > m_profileMap;
QMap<QString, KisColorSpace * > m_csMap;
typedef QValueVector<KisPaintDeviceAction *> PaintActionVector;
QMap<KisID, PaintActionVector> m_paintDevActionMap;
KisColorSpace *m_xyzCs;
KisColorSpace *m_alphaCs;
};
......
......@@ -75,6 +75,7 @@
#include "kis_id.h"
#include "kis_part_layer.h"
#include "kis_doc_iface.h"
#include "kis_paint_device_action.h"
static const char *CURRENT_DTD_VERSION = "1.3";
......@@ -882,6 +883,12 @@ bool KisDoc::slotNewImage()
painter.begin(layer.data());
painter.fillRect(0, 0, dlg.imgWidth(), dlg.imgHeight(), KisColor(c, opacity, cs), opacity);
painter.end();
QValueVector<KisPaintDeviceAction *> actions = KisMetaRegistry::instance() ->
csRegistry() -> paintDeviceActionsFor(cs);
for (uint i = 0; i < actions.count(); i++)
actions.at(i) -> act(layer.data(), img -> width(), img -> height());
img -> setBackgroundColor(KisColor(c, opacity, cs));
img -> add(layer, -1);
img -> notify();
......
......@@ -116,6 +116,7 @@
#include "kis_label_progress.h"
#include "kis_opengl_image_context.h"
#include "kis_background.h"
#include "kis_paint_device_action.h"
#include <kis_resourceserver.h>
#include <kis_resource_mediator.h>
......@@ -2108,8 +2109,17 @@ void KisView::layerAdd()
NewLayerDialog dlg(img->colorSpace()->id(), img->nextLayerName(), this);
if (dlg.exec() == QDialog::Accepted) {
KisLayerSP layer = img->layerAdd(dlg.layerName(), dlg.compositeOp(), dlg.opacity(), KisMetaRegistry::instance()->csRegistry()->getColorSpace(dlg.colorSpaceID(),""));
KisColorSpace* cs = KisMetaRegistry::instance() -> csRegistry() ->
getColorSpace(dlg.colorSpaceID(),"");
KisLayerSP layer = img->layerAdd(dlg.layerName(), dlg.compositeOp(),
dlg.opacity(), cs);
if (layer) {
QValueVector<KisPaintDeviceAction *> actions = KisMetaRegistry::instance() ->
csRegistry() -> paintDeviceActionsFor(cs);
for (uint i = 0; i < actions.count(); i++)
actions.at(i) -> act(layer.data(), img -> width(), img -> height());
m_layerBox->slotSetCurrentItem(img -> index(layer));
resizeEvent(0);
updateCanvas(0, 0, img -> width(), img -> height());
......
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