summaryrefslogtreecommitdiffstats
path: root/krita/plugins/tools/tool_polyline
diff options
context:
space:
mode:
Diffstat (limited to 'krita/plugins/tools/tool_polyline')
-rw-r--r--krita/plugins/tools/tool_polyline/Makefile.am35
-rw-r--r--krita/plugins/tools/tool_polyline/kis_tool_polyline.cc271
-rw-r--r--krita/plugins/tools/tool_polyline/kis_tool_polyline.h108
-rw-r--r--krita/plugins/tools/tool_polyline/kritatoolpolyline.desktop49
-rw-r--r--krita/plugins/tools/tool_polyline/polyline.pngbin0 -> 586 bytes
-rw-r--r--krita/plugins/tools/tool_polyline/tool_polyline.cc64
-rw-r--r--krita/plugins/tools/tool_polyline/tool_polyline.h42
-rw-r--r--krita/plugins/tools/tool_polyline/tool_polyline_cursor.pngbin0 -> 396 bytes
8 files changed, 569 insertions, 0 deletions
diff --git a/krita/plugins/tools/tool_polyline/Makefile.am b/krita/plugins/tools/tool_polyline/Makefile.am
new file mode 100644
index 000000000..298119b5f
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/Makefile.am
@@ -0,0 +1,35 @@
+kde_services_DATA = kritatoolpolyline.desktop
+
+# all_includes must remain last!
+INCLUDES = -I$(srcdir)/../../../sdk \
+ -I$(srcdir)/../../../core \
+ -I$(srcdir)/../../../kritacolor/ \
+ -I$(srcdir)/../../../ui \
+ -I$/../../../ui \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+kritatoolpolyline_la_SOURCES = \
+ tool_polyline.cc \
+ kis_tool_polyline.cc
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = kritatoolpolyline.la
+
+noinst_HEADERS = \
+ tool_polyline.h \
+ kis_tool_polyline.h
+
+kritatoolpolyline_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kritatoolpolyline_la_LIBADD = ../../../libkritacommon.la
+
+kritatoolpolyline_la_METASOURCES = AUTO
+
+KDE_OPTIONS = nofinal
+
+kritapics_DATA = \
+ tool_polyline_cursor.png \
+ polyline.png
+
+kritapicsdir = $(kde_datadir)/krita/pics
+
diff --git a/krita/plugins/tools/tool_polyline/kis_tool_polyline.cc b/krita/plugins/tools/tool_polyline/kis_tool_polyline.cc
new file mode 100644
index 000000000..2f7a8e59e
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/kis_tool_polyline.cc
@@ -0,0 +1,271 @@
+/*
+ * kis_tool_polyline.cc -- part of Krita
+ *
+ * Copyright (c) 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
+ *
+ * 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.
+ */
+
+
+#include <math.h>
+
+#include <qpainter.h>
+#include <qspinbox.h>
+
+#include <kaction.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <knuminput.h>
+
+#include "kis_doc.h"
+#include "kis_view.h"
+#include "kis_painter.h"
+#include "kis_canvas_subject.h"
+#include "kis_canvas_controller.h"
+#include "kis_button_press_event.h"
+#include "kis_button_release_event.h"
+#include "kis_move_event.h"
+#include "kis_paintop_registry.h"
+#include "kis_canvas.h"
+#include "kis_canvas_painter.h"
+#include "kis_cursor.h"
+
+#include "kis_tool_polyline.h"
+
+KisToolPolyline::KisToolPolyline()
+ : super(i18n ("Polyline")),
+ m_dragging (false),
+ m_currentImage (0)
+{
+ setName("tool_polyline");
+ setCursor(KisCursor::load("tool_polyline_cursor.png", 6, 6));
+}
+
+KisToolPolyline::~KisToolPolyline()
+{
+}
+
+void KisToolPolyline::update (KisCanvasSubject *subject)
+{
+ super::update (subject);
+ if (m_subject)
+ m_currentImage = m_subject->currentImg ();
+}
+
+void KisToolPolyline::buttonPress(KisButtonPressEvent *event)
+{
+ if (m_currentImage) {
+ if (event->button() == LeftButton && event->state() != Qt::ShiftButton ) {
+
+ m_dragging = true;
+
+ if (m_points.isEmpty())
+ {
+ m_dragStart = event->pos();
+ m_dragEnd = event->pos();
+ m_points.append(m_dragStart);
+ } else {
+ m_dragStart = m_dragEnd;
+ m_dragEnd = event->pos();
+ draw();
+ }
+ } else if (event->button() == LeftButton && event->state() == Qt::ShiftButton ) {
+ finish();
+ }
+ }
+}
+
+void KisToolPolyline::deactivate()
+{
+ draw();
+ m_points.clear();
+ m_dragging = false;
+}
+
+void KisToolPolyline::finish()
+{
+ // erase old lines on canvas
+ draw();
+ m_dragging = false;
+
+ KisPaintDeviceSP device = m_currentImage->activeDevice ();
+ if (!device) return;
+
+ KisPainter painter (device);
+ if (m_currentImage->undo()) painter.beginTransaction (i18n ("Polyline"));
+
+ painter.setPaintColor(m_subject->fgColor());
+ painter.setBrush(m_subject->currentBrush());
+ painter.setOpacity(m_opacity);
+ painter.setCompositeOp(m_compositeOp);
+ KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter);
+ painter.setPaintOp(op); // Painter takes ownership
+
+ KisPoint start,end;
+ KisPointVector::iterator it;
+ for( it = m_points.begin(); it != m_points.end(); ++it )
+ {
+ if( it == m_points.begin() )
+ {
+ start = (*it);
+ } else {
+ end = (*it);
+ painter.paintLine(start, PRESSURE_DEFAULT, 0, 0, end, PRESSURE_DEFAULT, 0, 0);
+ start = end;
+ }
+ }
+ m_points.clear();
+
+ device->setDirty( painter.dirtyRect() );
+ notifyModified();
+
+ if (m_currentImage->undo()) {
+ m_currentImage->undoAdapter()->addCommand(painter.endTransaction());
+ }
+
+}
+void KisToolPolyline::move(KisMoveEvent *event)
+{
+ if (m_dragging) {
+ // erase old lines on canvas
+ draw();
+ // get current mouse position
+ m_dragEnd = event->pos();
+ // draw new lines on canvas
+ draw();
+ }
+}
+
+void KisToolPolyline::buttonRelease(KisButtonReleaseEvent *event)
+{
+ if (!m_subject || !m_currentImage)
+ return;
+
+ if (m_dragging && event->button() == LeftButton) {
+ m_dragging = false;
+ m_points.append (m_dragEnd);
+ }
+
+ if (m_dragging && event->button() == RightButton) {
+
+ }
+}
+
+
+void KisToolPolyline::doubleClick(KisDoubleClickEvent *)
+{
+ finish();
+}
+
+
+void KisToolPolyline::paint(KisCanvasPainter& gc)
+{
+ draw(gc);
+}
+
+void KisToolPolyline::paint(KisCanvasPainter& gc, const QRect&)
+{
+ draw(gc);
+}
+
+void KisToolPolyline::draw()
+{
+ if (m_subject) {
+ KisCanvasController *controller = m_subject->canvasController();
+ KisCanvas *canvas = controller->kiscanvas();
+ KisCanvasPainter gc(canvas);
+
+ draw(gc);
+ }
+}
+
+void KisToolPolyline::draw(KisCanvasPainter& gc)
+{
+ if (!m_subject || !m_currentImage)
+ return;
+
+ QPen pen(Qt::white, 0, Qt::SolidLine);
+
+ gc.setPen(pen);
+ gc.setRasterOp(Qt::XorROP);
+
+ KisCanvasController *controller = m_subject->canvasController();
+ KisPoint start, end;
+ QPoint startPos;
+ QPoint endPos;
+
+ if (m_dragging) {
+ startPos = controller->windowToView(m_dragStart.floorQPoint());
+ endPos = controller->windowToView(m_dragEnd.floorQPoint());
+ gc.drawLine(startPos, endPos);
+ } else {
+ for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) {
+
+ if (it == m_points.begin())
+ {
+ start = (*it);
+ } else {
+ end = (*it);
+
+ startPos = controller->windowToView(start.floorQPoint());
+ endPos = controller->windowToView(end.floorQPoint());
+
+ gc.drawLine(startPos, endPos);
+
+ start = end;
+ }
+ }
+ }
+}
+
+void KisToolPolyline::setup(KActionCollection *collection)
+{
+ m_action = static_cast<KRadioAction *>(collection->action(name()));
+
+ if (m_action == 0) {
+ KShortcut shortcut(Qt::Key_Plus);
+ shortcut.append(KShortcut(Qt::Key_F9));
+ m_action = new KRadioAction(i18n("&Polyline"),
+ "polyline",
+ shortcut,
+ this,
+ SLOT(activate()),
+ collection,
+ name());
+ Q_CHECK_PTR(m_action);
+
+ m_action->setToolTip(i18n("Draw a polyline. Shift-mouseclick ends the polyline."));
+ m_action->setExclusiveGroup("tools");
+ m_ownAction = true;
+ }
+}
+
+QString KisToolPolyline::quickHelp() const
+{
+ return i18n("Press shift-mouseclick to end the polyline.");
+}
+
+void KisToolPolyline::keyPress(QKeyEvent *e)
+{
+ if (e->key()==Qt::Key_Escape) {
+ // erase old lines on canvas
+ draw();
+ m_dragging = false;
+ m_points.clear();
+ }
+}
+
+#include "kis_tool_polyline.moc"
diff --git a/krita/plugins/tools/tool_polyline/kis_tool_polyline.h b/krita/plugins/tools/tool_polyline/kis_tool_polyline.h
new file mode 100644
index 000000000..5dfff695a
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/kis_tool_polyline.h
@@ -0,0 +1,108 @@
+/*
+ * kis_tool_polyline.h - part of Krita
+ *
+ * Copyright (c) 2004 Michael Thaler <michael Thaler@physik.tu-muenchen.de>
+ *
+ * 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_TOOL_POLYLINE_H_
+#define KIS_TOOL_POLYLINE_H_
+
+#include <qvaluevector.h>
+#include <qstring.h>
+
+#include "kis_tool_paint.h"
+#include "kis_point.h"
+
+class KisCanvas;
+class KisDoc;
+class KisPainter;
+class KisView;
+class KisRect;
+
+
+class KisToolPolyline : public KisToolPaint {
+
+ typedef KisToolPaint super;
+ Q_OBJECT
+
+public:
+ KisToolPolyline();
+ virtual ~KisToolPolyline();
+
+ //
+ // KisCanvasObserver interface
+ //
+
+ virtual void update (KisCanvasSubject *subject);
+
+ //
+ // KisToolPaint interface
+ //
+
+ virtual void setup(KActionCollection *collection);
+ virtual enumToolType toolType() { return TOOL_SHAPE; }
+ virtual Q_UINT32 priority() { return 5; }
+
+ virtual void buttonPress(KisButtonPressEvent *event);
+ virtual void doubleClick(KisDoubleClickEvent *e);
+ virtual void move(KisMoveEvent *event);
+ virtual void buttonRelease(KisButtonReleaseEvent *event);
+ virtual QString quickHelp() const;
+ void finish();
+ virtual void keyPress(QKeyEvent *e);
+
+public slots:
+
+ void deactivate();
+
+protected:
+ virtual void paint(KisCanvasPainter& gc);
+ virtual void paint(KisCanvasPainter& gc, const QRect& rc);
+ void draw(KisCanvasPainter& gc);
+ void draw();
+
+protected:
+ KisPoint m_dragStart;
+ KisPoint m_dragEnd;
+
+ bool m_dragging;
+ KisImageSP m_currentImage;
+private:
+ typedef QValueVector<KisPoint> KisPointVector;
+ KisPointVector m_points;
+};
+
+
+#include "kis_tool_factory.h"
+
+class KisToolPolylineFactory : public KisToolFactory {
+ typedef KisToolFactory super;
+public:
+ KisToolPolylineFactory() : super() {};
+ virtual ~KisToolPolylineFactory(){};
+
+ virtual KisTool * createTool(KActionCollection * ac) {
+ KisTool * t = new KisToolPolyline();
+ Q_CHECK_PTR(t);
+ t->setup(ac);
+ return t;
+ }
+ virtual KisID id() { return KisID("polyline", i18n("Polyline Tool")); }
+};
+
+
+#endif //__KIS_TOOL_POLYLINE_H__
diff --git a/krita/plugins/tools/tool_polyline/kritatoolpolyline.desktop b/krita/plugins/tools/tool_polyline/kritatoolpolyline.desktop
new file mode 100644
index 000000000..fc0db01c3
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/kritatoolpolyline.desktop
@@ -0,0 +1,49 @@
+[Desktop Entry]
+Name=Polyline Tool
+Name[bg]=Инструмент съставна линия
+Name[br]=Ostilh lieslinenn
+Name[ca]=Eina de polilínia
+Name[cy]=Erfyn Polylinell
+Name[da]=Flerlinjeværktøj
+Name[de]=Linienketten-Werkzeug
+Name[el]=Εργαλείο συνεχούς γραμμής
+Name[eo]=Plurlinio-ilo
+Name[es]=Herramienta Polilínea
+Name[et]=Kompleksjoone tööriist
+Name[eu]=Polilerroa tresna
+Name[fa]=ابزار چندخطی
+Name[fr]=Outil lignes multiples
+Name[fy]=Brútsen-streek-ark
+Name[ga]=Uirlis Il-líne
+Name[gl]=Ferramenta de Liñas Poligonais
+Name[he]=כלי קו שבור
+Name[hu]=Sokszögvonal eszköz
+Name[is]=Fjöllínutól
+Name[it]=Strumento polilinea
+Name[ja]=ポリラインツール
+Name[km]=ឧបករណ៍​ពហុបន្ទាត់
+Name[ms]=Alat Poligaris
+Name[nb]=Verktøy for flerstrekslinje
+Name[nds]=Lienenkeden-Warktüüch (Polygon-Tog)
+Name[ne]=बहुरेखा उपकरण
+Name[nl]=Gebroken-lijngereedschap
+Name[nn]=Verktøy for fleirstrekslinje
+Name[pl]=Narzędzie do rysowania łamanej
+Name[pt]=Ferramenta de Linhas Poligonais
+Name[pt_BR]=Ferramenta Poli-linha
+Name[ru]=Ломаная
+Name[se]=Moanálinnjáreaidu
+Name[sk]=Lomená čiara
+Name[sl]=Orodje za lomljeno črto
+Name[sr]=Алат за полилиније
+Name[sr@Latn]=Alat za polilinije
+Name[sv]=Flerlinjesverktyg
+Name[uk]=Засіб ламаної лінії
+Name[uz]=Koʻpburchak asbobi
+Name[uz@cyrillic]=Кўпбурчак асбоби
+Name[zh_CN]=折线工具
+Name[zh_TW]=任意線工具
+ServiceTypes=Krita/Tool
+Type=Service
+X-KDE-Library=kritatoolpolyline
+X-Krita-Version=2
diff --git a/krita/plugins/tools/tool_polyline/polyline.png b/krita/plugins/tools/tool_polyline/polyline.png
new file mode 100644
index 000000000..d30680da8
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/polyline.png
Binary files differ
diff --git a/krita/plugins/tools/tool_polyline/tool_polyline.cc b/krita/plugins/tools/tool_polyline/tool_polyline.cc
new file mode 100644
index 000000000..ae1fdda56
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/tool_polyline.cc
@@ -0,0 +1,64 @@
+/*
+ * tool_polyline.cc -- Part of Krita
+ *
+ * Copyright (c) 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
+ *
+ * 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.
+ */
+#include <stdlib.h>
+#include <vector>
+
+#include <qpoint.h>
+
+#include <klocale.h>
+#include <kiconloader.h>
+#include <kinstance.h>
+#include <kmessagebox.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+#include <kgenericfactory.h>
+
+#include <kis_global.h>
+#include <kis_types.h>
+#include <kis_tool_registry.h>
+#include <kis_view.h>
+
+#include "tool_polyline.h"
+#include "kis_tool_polyline.h"
+
+
+typedef KGenericFactory<ToolPolyline> ToolPolylineFactory;
+K_EXPORT_COMPONENT_FACTORY( kritatoolpolyline, ToolPolylineFactory( "krita" ) )
+
+
+ToolPolyline::ToolPolyline(QObject *parent, const char *name, const QStringList &)
+ : KParts::Plugin(parent, name)
+{
+ setInstance(ToolPolylineFactory::instance());
+
+ if ( parent->inherits("KisToolRegistry") )
+ {
+ KisToolRegistry * r = dynamic_cast<KisToolRegistry*>(parent);
+
+ r->add(new KisToolPolylineFactory());
+ }
+
+}
+
+ToolPolyline::~ToolPolyline()
+{
+}
+
+#include "tool_polyline.moc"
diff --git a/krita/plugins/tools/tool_polyline/tool_polyline.h b/krita/plugins/tools/tool_polyline/tool_polyline.h
new file mode 100644
index 000000000..14987487d
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/tool_polyline.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
+ *
+ * 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 TOOL_POLYLINE_H_
+#define TOOL_POLYLINE_H_
+
+#include <kparts/plugin.h>
+
+class KisView;
+
+/**
+ * A module that provides a polyline tool.
+ */
+class ToolPolyline : public KParts::Plugin
+{
+ Q_OBJECT
+public:
+ ToolPolyline(QObject *parent, const char *name, const QStringList &);
+ virtual ~ToolPolyline();
+
+private:
+
+ KisView * m_view;
+
+};
+
+#endif // TOOL_POLYLINE_H_
diff --git a/krita/plugins/tools/tool_polyline/tool_polyline_cursor.png b/krita/plugins/tools/tool_polyline/tool_polyline_cursor.png
new file mode 100644
index 000000000..54606bcec
--- /dev/null
+++ b/krita/plugins/tools/tool_polyline/tool_polyline_cursor.png
Binary files differ