summaryrefslogtreecommitdiffstats
path: root/krita/plugins/tools/tool_polygon
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /krita/plugins/tools/tool_polygon
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krita/plugins/tools/tool_polygon')
-rw-r--r--krita/plugins/tools/tool_polygon/Makefile.am35
-rw-r--r--krita/plugins/tools/tool_polygon/kis_tool_polygon.cc252
-rw-r--r--krita/plugins/tools/tool_polygon/kis_tool_polygon.h101
-rw-r--r--krita/plugins/tools/tool_polygon/kritatoolpolygon.desktop52
-rw-r--r--krita/plugins/tools/tool_polygon/tool_polygon.cc62
-rw-r--r--krita/plugins/tools/tool_polygon/tool_polygon.h38
-rw-r--r--krita/plugins/tools/tool_polygon/tool_polygon.pngbin0 -> 772 bytes
-rw-r--r--krita/plugins/tools/tool_polygon/tool_polygon_cursor.pngbin0 -> 401 bytes
8 files changed, 540 insertions, 0 deletions
diff --git a/krita/plugins/tools/tool_polygon/Makefile.am b/krita/plugins/tools/tool_polygon/Makefile.am
new file mode 100644
index 00000000..dec22b37
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/Makefile.am
@@ -0,0 +1,35 @@
+kde_services_DATA = kritatoolpolygon.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)
+
+kritatoolpolygon_la_SOURCES = \
+ tool_polygon.cc \
+ kis_tool_polygon.cc
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = kritatoolpolygon.la
+
+noinst_HEADERS = \
+ tool_polygon.h \
+ kis_tool_polygon.h
+
+kritatoolpolygon_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kritatoolpolygon_la_LIBADD = ../../../libkritacommon.la
+
+kritatoolpolygon_la_METASOURCES = AUTO
+
+KDE_OPTIONS = nofinal
+
+kritapics_DATA = \
+ tool_polygon_cursor.png \
+ tool_polygon.png
+
+kritapicsdir = $(kde_datadir)/krita/pics
+
diff --git a/krita/plugins/tools/tool_polygon/kis_tool_polygon.cc b/krita/plugins/tools/tool_polygon/kis_tool_polygon.cc
new file mode 100644
index 00000000..9589e19f
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/kis_tool_polygon.cc
@@ -0,0 +1,252 @@
+/*
+ * kis_tool_polygon.cc -- part of Krita
+ *
+ * Copyright (c) 2004 Michael Thaler <[email protected]>
+ *
+ * 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_polygon.h"
+
+KisToolPolygon::KisToolPolygon()
+ : super(i18n ("Polygon")),
+ m_dragging (false),
+ m_currentImage (0)
+{
+ setName("tool_polygon");
+ setCursor(KisCursor::load("tool_polygon_cursor.png", 6, 6));
+}
+
+KisToolPolygon::~KisToolPolygon()
+{
+}
+
+void KisToolPolygon::update (KisCanvasSubject *subject)
+{
+ super::update (subject);
+ if (m_subject)
+ m_currentImage = m_subject->currentImg ();
+}
+
+void KisToolPolygon::buttonPress(KisButtonPressEvent *event)
+{
+ if (m_currentImage) {
+ if (event->button() == LeftButton && event->state() != 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() == ShiftButton) {
+ finish();
+ }
+ }
+}
+
+void KisToolPolygon::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 ("Polygon"));
+
+ painter.setPaintColor(m_subject->fgColor());
+ painter.setBackgroundColor(m_subject->bgColor());
+ painter.setFillStyle(fillStyle());
+ painter.setBrush(m_subject->currentBrush());
+ painter.setPattern(m_subject->currentPattern());
+ 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
+
+ painter.paintPolygon(m_points);
+
+ m_points.clear();
+
+ device->setDirty( painter.dirtyRect() );
+ notifyModified();
+
+ if (m_currentImage->undo()) {
+ m_currentImage->undoAdapter()->addCommand(painter.endTransaction());
+ }
+}
+
+void KisToolPolygon::doubleClick( KisDoubleClickEvent * )
+{
+ finish();
+}
+
+void KisToolPolygon::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 KisToolPolygon::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 KisToolPolygon::paint(KisCanvasPainter& gc)
+{
+ draw(gc);
+}
+
+void KisToolPolygon::paint(KisCanvasPainter& gc, const QRect&)
+{
+ draw(gc);
+}
+
+void KisToolPolygon::draw()
+{
+ if (m_subject) {
+ KisCanvasController *controller = m_subject->canvasController();
+ KisCanvas *canvas = controller->kiscanvas();
+ KisCanvasPainter gc(canvas);
+
+ draw(gc);
+ }
+}
+
+void KisToolPolygon::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 KisToolPolygon::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("&Polygon"),
+ "tool_polygon",
+ shortcut,
+ this,
+ SLOT(activate()),
+ collection,
+ name());
+ Q_CHECK_PTR(m_action);
+
+ m_action->setToolTip(i18n("Draw a polygon. Shift-mouseclick ends the polygon."));
+ m_action->setExclusiveGroup("tools");
+ m_ownAction = true;
+ }
+}
+
+void KisToolPolygon::keyPress(QKeyEvent *e)
+{
+ if (e->key()==Qt::Key_Escape) {
+ // erase old lines on canvas
+ draw();
+ m_dragging = false;
+ m_points.clear();
+ }
+}
+
+
+#include "kis_tool_polygon.moc"
diff --git a/krita/plugins/tools/tool_polygon/kis_tool_polygon.h b/krita/plugins/tools/tool_polygon/kis_tool_polygon.h
new file mode 100644
index 00000000..7ca24914
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/kis_tool_polygon.h
@@ -0,0 +1,101 @@
+/*
+ * kis_tool_polygon.h - part of Krita
+ *
+ * Copyright (c) 2004 Michael Thaler <michael [email protected]>
+ *
+ * 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_POLYGON_H_
+#define KIS_TOOL_POLYGON_H_
+
+#include <qvaluevector.h>
+
+#include "kis_tool_shape.h"
+
+class KisCanvas;
+class KisDoc;
+class KisPainter;
+class KisView;
+class KisRect;
+
+class KisToolPolygon : public KisToolShape {
+
+ typedef KisToolShape super;
+ Q_OBJECT
+
+public:
+ KisToolPolygon();
+ virtual ~KisToolPolygon();
+
+ //
+ // 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 4; }
+ virtual void buttonPress(KisButtonPressEvent *event);
+ virtual void move(KisMoveEvent *event);
+ virtual void buttonRelease(KisButtonReleaseEvent *event);
+ virtual QString quickHelp() const {
+ return i18n("Shift-click will end the polygon.");
+ }
+ virtual void doubleClick(KisDoubleClickEvent * event);
+
+protected:
+ virtual void paint(KisCanvasPainter& gc);
+ virtual void paint(KisCanvasPainter& gc, const QRect& rc);
+ void draw(KisCanvasPainter& gc);
+ void draw();
+ void finish();
+ virtual void keyPress(QKeyEvent *e);
+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 KisToolPolygonFactory : public KisToolFactory {
+ typedef KisToolFactory super;
+public:
+ KisToolPolygonFactory() : super() {};
+ virtual ~KisToolPolygonFactory(){};
+
+ virtual KisTool * createTool(KActionCollection * ac) {
+ KisTool * t = new KisToolPolygon();
+ Q_CHECK_PTR(t);
+ t->setup(ac);
+ return t;
+ }
+ virtual KisID id() { return KisID("polygon", i18n("Polygon Tool")); }
+};
+
+
+#endif //__KIS_TOOL_POLYGON_H__
diff --git a/krita/plugins/tools/tool_polygon/kritatoolpolygon.desktop b/krita/plugins/tools/tool_polygon/kritatoolpolygon.desktop
new file mode 100644
index 00000000..08d8b162
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/kritatoolpolygon.desktop
@@ -0,0 +1,52 @@
+[Desktop Entry]
+Name=Polygon Tool
+Name[bg]=Инструмент многоъгълник
+Name[br]=Ostilh liestueg
+Name[ca]=Eina de polígon
+Name[cy]=Erfyn Polygon
+Name[da]=Polygonværktøj
+Name[de]=Vieleck-Werkzeug
+Name[el]=Εργαλείο πολυγώνου
+Name[eo]=Poligon-ilo
+Name[es]=Herramienta Polígono
+Name[et]=Hulknurga tööriist
+Name[eu]=Poligonoa tresna
+Name[fa]=ابزار چندضلعی
+Name[fi]=Monikulmiotyökalu
+Name[fr]=Outil polygone
+Name[fy]=Meardere-hoek-ark
+Name[ga]=Uirlis Pholagáin
+Name[gl]=Ferramenta de Polígonos
+Name[he]=כלי מצולע
+Name[hu]=Sokszög eszköz
+Name[is]=Marghyrnitól
+Name[it]=Strumento poligono
+Name[ja]=多角形ツール
+Name[km]=ឧបករណ៍​រាង​ពហុកោណ
+Name[lt]=Daugiakampio įrankis
+Name[lv]=Poligonu rīks
+Name[ms]=Alat Poligon
+Name[nb]=Verktøy for mangekanter
+Name[nds]=Veeleck-Warktüüch
+Name[ne]=बहुभुज उपकरण
+Name[nl]=Veelhoeksgereedschap
+Name[nn]=Verktøy for mangekant
+Name[pl]=Narzędzie do rysowania wielokątów
+Name[pt]=Ferramenta de Polígonos
+Name[pt_BR]=Ferramenta Polígono
+Name[ru]=Многоугольник
+Name[se]=Moanáčiegareaidu
+Name[sk]=Mnohouholník
+Name[sl]=Orodje za poligon
+Name[sr]=Алат за полигоне
+Name[sr@Latn]=Alat za poligone
+Name[sv]=Polygonverktyg
+Name[uk]=Засіб багатокутника
+Name[uz]=Pligon vositasi
+Name[uz@cyrillic]=Плигон воситаси
+Name[zh_CN]=多边形工具
+Name[zh_TW]=多邊形工具
+ServiceTypes=Krita/Tool
+Type=Service
+X-KDE-Library=kritatoolpolygon
+X-Krita-Version=2
diff --git a/krita/plugins/tools/tool_polygon/tool_polygon.cc b/krita/plugins/tools/tool_polygon/tool_polygon.cc
new file mode 100644
index 00000000..a1fec49c
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/tool_polygon.cc
@@ -0,0 +1,62 @@
+/*
+ * tool_polygon.cc -- Part of Krita
+ *
+ * Copyright (c) 2004 Michael Thaler <[email protected]>
+ *
+ * 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 "tool_polygon.h"
+#include "tool_polygon.moc"
+#include "kis_tool_polygon.h"
+
+
+typedef KGenericFactory<ToolPolygon> ToolPolygonFactory;
+K_EXPORT_COMPONENT_FACTORY( kritatoolpolygon, ToolPolygonFactory( "krita" ) )
+
+
+ToolPolygon::ToolPolygon(QObject *parent, const char *name, const QStringList &)
+ : KParts::Plugin(parent, name)
+{
+ setInstance(ToolPolygonFactory::instance());
+
+ if ( parent->inherits("KisToolRegistry") )
+ {
+ KisToolRegistry * r = dynamic_cast<KisToolRegistry*>( parent );
+ r->add(new KisToolPolygonFactory());
+ }
+
+}
+
+ToolPolygon::~ToolPolygon()
+{
+}
+
+//#include "tool_polygon.moc"
diff --git a/krita/plugins/tools/tool_polygon/tool_polygon.h b/krita/plugins/tools/tool_polygon/tool_polygon.h
new file mode 100644
index 00000000..6249d935
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/tool_polygon.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2004 Michael Thaler <[email protected]>
+ *
+ * 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_POLYGON_H_
+#define TOOL_POLYGON_H_
+
+#include <kparts/plugin.h>
+
+/**
+ * A module that provides a polygon tool.
+ */
+class ToolPolygon : public KParts::Plugin
+{
+ Q_OBJECT
+
+public:
+
+ ToolPolygon(QObject *parent, const char *name, const QStringList &);
+ virtual ~ToolPolygon();
+
+};
+
+#endif // TOOL_POLYGON_H_
diff --git a/krita/plugins/tools/tool_polygon/tool_polygon.png b/krita/plugins/tools/tool_polygon/tool_polygon.png
new file mode 100644
index 00000000..0f1627d9
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/tool_polygon.png
Binary files differ
diff --git a/krita/plugins/tools/tool_polygon/tool_polygon_cursor.png b/krita/plugins/tools/tool_polygon/tool_polygon_cursor.png
new file mode 100644
index 00000000..4d312ade
--- /dev/null
+++ b/krita/plugins/tools/tool_polygon/tool_polygon_cursor.png
Binary files differ