Commit f4c6bff6 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Paintops back in their box; if unsermake hadn't stranded me, I'd have made

sure you can select any paintop with any paint tool tonight. As it stands,
that's for tomorrow.

svn path=/trunk/koffice/; revision=427800
parent ff6638c9
......@@ -29,6 +29,7 @@ class KisCanvasControllerInterface;
class KisCanvasObserver;
class KisGradient;
class KisPattern;
class KisPaintOpFactory;
class KisToolControllerInterface;
class KisUndoAdapter;
class KisProgressDisplayInterface;
......@@ -50,25 +51,43 @@ public:
public:
virtual void attach(KisCanvasObserver *observer) = 0;
virtual void detach(KisCanvasObserver *observer) = 0;
virtual void notify() = 0;
virtual KisImageSP currentImg() const = 0;
virtual KisColor bgColor() const = 0;
virtual void setBGColor(const KisColor& c) = 0;
virtual KisColor fgColor() const = 0;
virtual void setFGColor(const KisColor& c) = 0;
virtual KisBrush *currentBrush() const = 0;
virtual KisPattern *currentPattern() const = 0;
virtual KisGradient *currentGradient() const = 0;
virtual KisID currentPaintop() const = 0;
virtual double zoomFactor() const = 0;
virtual KisUndoAdapter *undoAdapter() const = 0;
virtual KisCanvasControllerInterface *canvasController() const = 0;
virtual KisToolControllerInterface *toolController() const = 0;
virtual KoDocument *document() const = 0;
virtual KisProgressDisplayInterface *progressDisplay() const = 0;
virtual KisSelectionManager * selectionManager() = 0;
virtual KisFilterRegistry * filterRegistry() const = 0;
virtual KisFilterSP filterGet(const KisID& id) = 0;
virtual KisIDList filterList() = 0;
virtual QCursor setCanvasCursor(const QCursor &) = 0;
private:
KisCanvasSubject(const KisCanvasSubject&);
......
......@@ -101,6 +101,7 @@
#include "kis_profile.h"
#include "kis_transaction.h"
#include "kis_layerbox.h"
#include "kis_paintop_box.h"
#include "kis_color.h"
// Dialog boxes
......@@ -188,7 +189,7 @@ KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const ch
m_brush = 0;
m_pattern = 0;
m_gradient = 0;
m_currentGuide = 0;
m_progress = 0;
......@@ -209,6 +210,7 @@ KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const ch
dcopObject();
createLayerBox();
createPaintopBox();
connect(m_doc, SIGNAL(imageListUpdated()), SLOT(docImageListUpdate()));
connect(m_doc, SIGNAL(layersUpdated(KisImageSP)), SLOT(layersUpdated(KisImageSP)));
......@@ -264,6 +266,13 @@ void KisView::createLayerBox()
}
void KisView::createPaintopBox()
{
m_paintopBox = new KisPaintopBox(this, "paintopbox");
m_paintopBox->setCaption(i18n("Brushes and stuff"));
paletteManager()->addWidget(actionCollection(), m_paintopBox, "paintopbox", krita::PAINTBOX, INT_MIN, PALETTE_TOOLBOX);
}
DCOPObject* KisView::dcopObject()
{
......@@ -1522,6 +1531,18 @@ void KisView::gradientActivated(KisResource *gradient)
}
}
void KisView::paintopActivated(const KisID & paintop)
{
kdDebug() << "paintop activated: " << paintop.name() << "\n";
if (paintop.id().isNull() || paintop.id().isEmpty()) {
return;
}
m_paintop = paintop;
emit paintopChanged(m_paintop);
notify();
}
void KisView::setBGColor(const KisColor& c)
{
emit bgColorChanged(c);
......@@ -2650,6 +2671,11 @@ KisGradient *KisView::currentGradient() const
return m_gradient;
}
KisID KisView::currentPaintop() const
{
return m_paintop;
}
double KisView::zoomFactor() const
{
return zoom();
......
......@@ -79,6 +79,7 @@ class KisToolRegistry;
class KisFilterRegistry;
class KisCompositeOp;
class KisLayerBox;
class KisPaintopBox;
class KRITA_EXPORT KisView
: public KoView,
......@@ -153,7 +154,8 @@ signals:
void brushChanged(KisBrush * brush);
void gradientChanged(KisGradient * gradient);
void patternChanged(KisPattern * pattern);
void paintopChanged(KisID paintop);
void currentLayerChanged(int layer);
void cursorPosition(Q_INT32 xpos, Q_INT32 ypos);
......@@ -207,17 +209,25 @@ private:
virtual void attach(KisCanvasObserver *observer);
virtual void detach(KisCanvasObserver *observer);
virtual void notify();
virtual KisColor bgColor() const;
virtual void setBGColor(const KisColor& c);
virtual KisColor fgColor() const;
virtual void setFGColor(const KisColor& c);
virtual KisBrush *currentBrush() const;
virtual KisPattern *currentPattern() const;
virtual KisGradient *currentGradient() const;
virtual KisID currentPaintop() const;
virtual double zoomFactor() const;
virtual KisUndoAdapter *undoAdapter() const;
virtual KisCanvasControllerInterface *canvasController() const;
virtual KisToolControllerInterface *toolController() const;
virtual KoDocument *document() const;
// Sets the specified cursor; returns the previous cursor
virtual QCursor setCanvasCursor(const QCursor & cursor);
......@@ -268,6 +278,7 @@ private:
void layerUpdateGUI(bool enable);
void createLayerBox();
void createPaintopBox();
void paintView(const KisRect& rc);
......@@ -317,16 +328,24 @@ public slots:
void mergeLayer();
void mergeLinkedLayers();
void saveLayerAsImage();
void currentImageUpdated(KisImageSP img);
void brushActivated(KisResource *brush);
void patternActivated(KisResource *pattern);
void gradientActivated(KisResource *gradient);
void paintopActivated(const KisID & paintop);
void scrollH(int value);
void scrollV(int value);
void slotInsertImageAsLayer();
void imgUpdated(KisImageSP img, const QRect& rc);
void imgUpdated(KisImageSP img);
void profileChanged(KisProfileSP profile);
void slotZoomIn();
void slotZoomOut();
void slotImageSizeChanged(KisImageSP img, Q_INT32 w, Q_INT32 h);
......@@ -412,6 +431,7 @@ private:
KisLabelProgress *m_progress;
KisLayerBox *m_layerBox;
KisPaintopBox *m_paintopBox;
// Current colours, brushes, patterns etc.
......@@ -422,6 +442,8 @@ private:
KisPattern *m_pattern;
KisGradient *m_gradient;
KisID m_paintop;
enumInputDevice m_inputDevice;
InputDeviceToolMap m_inputDeviceToolMap;
InputDeviceToolSetMap m_inputDeviceToolSetMap;
......
......@@ -21,6 +21,6 @@ kritawsplugin_la_LIBADD = ../../libkritacommon.la $(LIB_KOPAINTER) $(LIB_KOFFIC
kritawsplugin_la_METASOURCES = AUTO
SUBDIRS=filter
SUBDIRS=filter brushop
* Add paintopbox to toolbox
* Make all paint tools use the paintop from the paintop box
* Add paintop properties palette
* Add continuously running filters
* Add filler objects that can fill a given area computationally
* Add extensible properties for paint devices (to control things like drying)
* Add default fill hook dependent on colorspace
kde_services_DATA = kritawsbrushpaintop.desktop
# all_includes must remain last!
INCLUDES = -I$(srcdir)/../../..//core \
-I$(srcdir)/../../..//core/color_strategy/ \
-I$(srcdir)/../../..//core/resources/ \
-I$(srcdir)/../../..//core/tiles \
-I$(srcdir)/../../..//core/tool \
-I$(srcdir)/../../..//core/paintop \
-I$(srcdir)/../../..//ui \
-I$(srcdir)/../../..//ui/dialogs \
-I$(srcdir)/../../..//ui/widgets \
-I../../..//ui/dialogs \
$(KOFFICE_INCLUDES) $(KOPAINTER_INCLUDES) -I$(srcdir)/../../..//core/strategy/ $(all_includes)
kritawsbrushpaintop_la_SOURCES = \
wsbrushpaintop_plugin.cc \
kis_wsbrushop.cc
noinst_HEADERS= \
wsbrushpaintop_plugin.h \
kis_wsbrushop.h
kde_module_LTLIBRARIES = kritawsbrushpaintop.la
kritawsbrushpaintop_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
kritawsbrushpaintop_la_LIBADD = ../../..//libkritacommon.la $(LIB_KOPAINTER) $(LIB_KOFFICECORE)
kritawsbrushpaintop_la_METASOURCES = AUTO
Template for plugin paintops. Paint tools use the paintop to determine how
to deposit their paint on the canvas, exactly.
/*
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <qrect.h>
#include <kdebug.h>
#include "kis_brush.h"
#include "kis_global.h"
#include "kis_paint_device.h"
#include "kis_painter.h"
#include "kis_types.h"
#include "kis_paintop.h"
#include "kis_wsbrushop.h"
KisPaintOp * KisWSBrushOpFactory::createOp(KisPainter * painter)
{
KisPaintOp * op = new KisWSBrushOp(painter);
Q_CHECK_PTR(op);
return op;
}
KisWSBrushOp::KisWSBrushOp(KisPainter * painter)
: super(painter)
{
}
KisWSBrushOp::~KisWSBrushOp()
{
}
void KisWSBrushOp::paintAt(const KisPoint &pos,
const double pressure,
const double /*xTilt*/,
const double /*yTilt*/)
{
// Painting should be implemented according to the following algorithm:
// retrieve brush
// if brush == mask
// retrieve mask
// else if brush == image
// retrieve image
// subsample (mask | image) for position -- pos should be double!
// apply filters to mask (colour | gradient | pattern | etc.
// composite filtered mask into temporary layer
// composite temporary layer into target layer
// @see: doc/brush.txt
if (!m_painter -> device()) return;
KisBrush *brush = m_painter -> brush();
Q_ASSERT(brush);
if (!brush) return;
KisPaintDeviceSP device = m_painter -> device();
KisPoint hotSpot = brush -> hotSpot(pressure);
KisPoint pt = pos - hotSpot;
// Split the coordinates into integer plus fractional parts. The integer
// is where the dab will be positioned and the fractional part determines
// the sub-pixel positioning.
Q_INT32 x;
double xFraction;
Q_INT32 y;
double yFraction;
splitCoordinate(pt.x(), &x, &xFraction);
splitCoordinate(pt.y(), &y, &yFraction);
KisLayerSP dab = 0;
if (brush -> brushType() == IMAGE || brush -> brushType() == PIPE_IMAGE) {
dab = brush -> image(device -> colorStrategy(), pressure, xFraction, yFraction);
}
else {
KisAlphaMaskSP mask = brush -> mask(pressure, xFraction, yFraction);
dab = computeDab(mask);
}
m_painter -> setPressure(pressure);
QRect dabRect = QRect(0, 0, brush -> maskWidth(pressure), brush -> maskHeight(pressure));
QRect dstRect = QRect(x, y, dabRect.width(), dabRect.height());
KisImage * image = device -> image();
if (image != 0) {
dstRect &= image -> bounds();
}
if (dstRect.isNull() || dstRect.isEmpty() || !dstRect.isValid()) return;
Q_INT32 sx = dstRect.x() - x;
Q_INT32 sy = dstRect.y() - y;
Q_INT32 sw = dstRect.width();
Q_INT32 sh = dstRect.height();
m_painter -> bltSelection(dstRect.x(), dstRect.y(), m_painter -> compositeOp(), dab.data(), m_painter -> opacity(), sx, sy, sw, sh);
m_painter -> addDirtyRect(dstRect);
}
/*
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef KIS_WSBRUSHOP_H_
#define KIS_WSBRUSHOP_H_
#include "kis_paintop.h"
#include "kis_types.h"
class KisPoint;
class KisPainter;
class KisWSBrushOpFactory : public KisPaintOpFactory {
public:
KisWSBrushOpFactory() {}
virtual ~KisWSBrushOpFactory() {}
virtual KisPaintOp * createOp(KisPainter * painter);
virtual KisID id() { return KisID("wsbrush", i18n("Wet & sticky paintbrush")); }
};
class KisWSBrushOp : public KisPaintOp {
typedef KisPaintOp super;
public:
KisWSBrushOp(KisPainter * painter);
virtual ~KisWSBrushOp();
void paintAt(const KisPoint &pos,
const double pressure,
const double /*xTilt*/,
const double /*yTilt*/);
};
#endif // KIS_WSBRUSHOP_H_
[Desktop Entry]
Encoding=UTF-8
Name=Wet & Sticky paintbrush paintop
Comment=Wet & Sticky paintbrush
ServiceTypes=Krita/CoreModule
Type=Service
X-KDE-Library=kritawsbrushpaintop
/*
* wsbrushpaintop_plugin.cc -- Part of Krita
*
* Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org)
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <vector>
#include <qpoint.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kinstance.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <ktempfile.h>
#include <kdebug.h>
#include <kgenericfactory.h>
#include <kis_factory.h>
#include <kis_doc.h>
#include <kis_image.h>
#include <kis_layer.h>
#include <kis_global.h>
#include <kis_types.h>
#include <kis_view.h>
#include <kis_paintop_registry.h>
#include "kis_wsbrushop.h"
#include "wsbrushpaintop_plugin.h"
typedef KGenericFactory<WSBrushPaintOpPlugin> WSBrushPaintOpPluginFactory;
K_EXPORT_COMPONENT_FACTORY( kritawsbrushpaintop, WSBrushPaintOpPluginFactory( "kritacore" ) )
WSBrushPaintOpPlugin::WSBrushPaintOpPlugin(QObject *parent, const char *name, const QStringList &)
: KParts::Plugin(parent, name)
{
setInstance(WSBrushPaintOpPluginFactory::instance());
kdDebug() << "WSBrushPaintOpPlugin. Class: "
<< className()
<< ", Parent: "
<< parent -> className()
<< "\n";
// This is not a gui plugin; only load it when the doc is created.
if ( parent->inherits("KisFactory") )
{
KisPaintOpRegistry::instance() -> add ( new KisWSBrushOpFactory );
}
}
WSBrushPaintOpPlugin::~WSBrushPaintOpPlugin()
{
}
#include "wsbrushpaintop_plugin.moc"
/*
* Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org)
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef WSBRUSH_PAINTOP_PLUGIN_H_
#define WSBRUSH_PAINTOP_PLUGIN_H_
#include <kparts/plugin.h>
#include "kis_types.h"
class KisView;
/**
* A plugin wrapper that adds the paintop factories to the paintop registry.
*/
class WSBrushPaintOpPlugin : public KParts::Plugin
{
Q_OBJECT
public:
WSBrushPaintOpPlugin(QObject *parent, const char *name, const QStringList &);
virtual ~WSBrushPaintOpPlugin();
private:
KisView* m_view;
};
#endif // WSBRUSH_PAINTOP_PLUGIN_H_
......@@ -35,6 +35,7 @@ libkisui_la_SOURCES = \
kis_previewdialog.cc \
kis_selection_options.cc \
kis_guide.cc \
kis_paintop_box.cc \
wdgmatrix.ui \
kis_previewwidgetbase.ui \
wdgselectionoptions.ui \
......@@ -67,6 +68,7 @@ noinst_HEADERS = kis_dlg_preferences.h \
kis_double_widget.h \
kis_dlg_apply_profile.h \
kis_guide.h \
kis_paintop_box.h \
wdgmatrix.h \
kis_previewwidgetbase.h \
kis_previewdialog.h \
......
/*
* kis_paintop_box.cc - part of KImageShop/Krayon/Krita
*
* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <qwidget.h>
#include <qstring.h>
#include <qvaluelist.h>
#include <kis_id.h>
#include <kis_paintop_registry.h>
#include <kis_view.h>
#include "kis_paintop_box.h"
KisPaintopBox::KisPaintopBox (KisView * parent, const char * name, WFlags f)
: super (parent, name, f),
m_view(parent)
{
m_paintops = new QValueList<KisID>();
connect(this, SIGNAL(selected(const KisID &)), m_view, SLOT(paintopActivated(const KisID &)));
connect(this, SIGNAL(selected(int)), this, SLOT(slotItemselected(int)));
// XXX: Let's see... Are all paintops loaded and ready?
KisIDList keys = KisPaintOpRegistry::instance()->listKeys();
for ( KisIDList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
addItem(*it);
}
}
KisPaintopBox::~KisPaintopBox()
{
delete m_paintops;
}
void KisPaintopBox::addItem(const KisID & paintop, const QString & /*category*/)
{
m_paintops->append(paintop);
insertItem(paintop.name());
}
void KisPaintopBox::slotItemSelected(int index)
{
KisID id = *m_paintops->at(index);
emit selected(id);
}
#include "kis_paintop_box.moc"
/*
* kis_paintop_box.h - part of KImageShop/Krayon/Krita
*
* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef KIS_PAINTOP_BOX_H_
#define KIS_PAINTOP_BOX_H_
#include <qlistbox.h>
#include <qvaluelist.h>
#include <kis_view.h>
class KisID;
class QString;
/**
* This widget presents all paintops that a user can paint with.
* Paintops represent real-world tools or the well-known Shoup
* computer equivalents that do nothing but change color.
*
* XXX: When we have a lot of paintops, replace the listbox
* with a table, and for every category a combobox.
*
* XXX: instead of text, use pretty pictures.
*/
class KisPaintopBox : public QListBox {
Q_OBJECT
typedef QListBox super;
public:
KisPaintopBox (KisView * parent, const char * name = 0, WFlags f = 0);
~KisPaintopBox();
public slots:
void addItem(const KisID & paintop, const QString & category = "");
signals:
void selected(const KisID & id);
private slots:
void slotItemSelected(int index);
private:
KisView * m_view;
QValueList<KisID> * m_paintops;
};
#endif //KIS_PAINTOP_BOX_H_
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