summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/tools/tool_polygon
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/plugins/tools/tool_polygon
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/plugins/tools/tool_polygon')
-rw-r--r--chalk/plugins/tools/tool_polygon/Makefile.am36
-rw-r--r--chalk/plugins/tools/tool_polygon/chalktoolpolygon.desktop52
-rw-r--r--chalk/plugins/tools/tool_polygon/kis_tool_polygon.cc252
-rw-r--r--chalk/plugins/tools/tool_polygon/kis_tool_polygon.h102
-rw-r--r--chalk/plugins/tools/tool_polygon/tool_polygon.cc62
-rw-r--r--chalk/plugins/tools/tool_polygon/tool_polygon.h39
-rw-r--r--chalk/plugins/tools/tool_polygon/tool_polygon.pngbin0 -> 773 bytes
-rw-r--r--chalk/plugins/tools/tool_polygon/tool_polygon_cursor.pngbin0 -> 402 bytes
8 files changed, 543 insertions, 0 deletions
diff --git a/chalk/plugins/tools/tool_polygon/Makefile.am b/chalk/plugins/tools/tool_polygon/Makefile.am
new file mode 100644
index 00000000..66f4d403
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/Makefile.am
@@ -0,0 +1,36 @@
+kde_services_DATA = chalktoolpolygon.desktop
+
+# all_includes must remain last!
+INCLUDES = -I$(srcdir)/../../../sdk \
+ -I$(srcdir)/../../../core \
+ -I$(srcdir)/../../../chalkcolor/ \
+ -I$(srcdir)/../../../ui \
+ -I$/../../../ui \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+chalktoolpolygon_la_SOURCES = \
+ tool_polygon.cc \
+ kis_tool_polygon.cc
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = chalktoolpolygon.la
+
+noinst_HEADERS = \
+ tool_polygon.h \
+ kis_tool_polygon.h
+
+chalktoolpolygon_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_QT) -lkdecore -lkdeui -lkjs -lkdefx -lkio -lkparts -L../../../../chalk/chalkcolor/.libs -lchalkcolor -L../../../../chalk/core/.libs -lchalkimage \
+ -L../../../../chalk/ui/.libs -lchalkui
+chalktoolpolygon_la_LIBADD = ../../../libchalkcommon.la
+
+chalktoolpolygon_la_METASOURCES = AUTO
+
+KDE_OPTIONS = nofinal
+
+chalkpics_DATA = \
+ tool_polygon_cursor.png \
+ tool_polygon.png
+
+chalkpicsdir = $(kde_datadir)/chalk/pics
+
diff --git a/chalk/plugins/tools/tool_polygon/chalktoolpolygon.desktop b/chalk/plugins/tools/tool_polygon/chalktoolpolygon.desktop
new file mode 100644
index 00000000..2b981e8f
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/chalktoolpolygon.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=Chalk/Tool
+Type=Service
+X-KDE-Library=chalktoolpolygon
+X-Chalk-Version=2
diff --git a/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cc b/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cc
new file mode 100644
index 00000000..dba84042
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cc
@@ -0,0 +1,252 @@
+/*
+ * kis_tool_polygon.cc -- part of Chalk
+ *
+ * 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 <tqpainter.h>
+#include <tqspinbox.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() == Qt::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() == Qt::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() == Qt::LeftButton) {
+ m_dragging = false;
+ m_points.append (m_dragEnd);
+ }
+
+ if (m_dragging && event->button() == Qt::RightButton) {
+
+ }
+}
+
+void KisToolPolygon::paint(KisCanvasPainter& gc)
+{
+ draw(gc);
+}
+
+void KisToolPolygon::paint(KisCanvasPainter& gc, const TQRect&)
+{
+ 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;
+
+ TQPen pen(TQt::white, 0, TQt::SolidLine);
+
+ gc.setPen(pen);
+ gc.setRasterOp(TQt::XorROP);
+
+ KisCanvasController *controller = m_subject->canvasController();
+ KisPoint start, end;
+ TQPoint startPos;
+ TQPoint endPos;
+
+ if (m_dragging) {
+ startPos = controller->windowToView(m_dragStart.floorTQPoint());
+ endPos = controller->windowToView(m_dragEnd.floorTQPoint());
+ 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.floorTQPoint());
+ endPos = controller->windowToView(end.floorTQPoint());
+
+ 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(TQt::Key_Plus);
+ shortcut.append(KShortcut(TQt::Key_F9));
+ m_action = new KRadioAction(i18n("&Polygon"),
+ "tool_polygon",
+ shortcut,
+ this,
+ TQT_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(TQKeyEvent *e)
+{
+ if (e->key()==TQt::Key_Escape) {
+ // erase old lines on canvas
+ draw();
+ m_dragging = false;
+ m_points.clear();
+ }
+}
+
+
+#include "kis_tool_polygon.moc"
diff --git a/chalk/plugins/tools/tool_polygon/kis_tool_polygon.h b/chalk/plugins/tools/tool_polygon/kis_tool_polygon.h
new file mode 100644
index 00000000..9be3f324
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/kis_tool_polygon.h
@@ -0,0 +1,102 @@
+/*
+ * kis_tool_polygon.h - part of Chalk
+ *
+ * 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_POLYGON_H_
+#define KIS_TOOL_POLYGON_H_
+
+#include <tqvaluevector.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
+ TQ_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 TQ_UINT32 priority() { return 4; }
+ virtual void buttonPress(KisButtonPressEvent *event);
+ virtual void move(KisMoveEvent *event);
+ virtual void buttonRelease(KisButtonReleaseEvent *event);
+ virtual TQString 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 TQRect& rc);
+ void draw(KisCanvasPainter& gc);
+ void draw();
+ void finish();
+ virtual void keyPress(TQKeyEvent *e);
+protected:
+ KisPoint m_dragStart;
+ KisPoint m_dragEnd;
+
+ bool m_dragging;
+ KisImageSP m_currentImage;
+private:
+ typedef TQValueVector<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/chalk/plugins/tools/tool_polygon/tool_polygon.cc b/chalk/plugins/tools/tool_polygon/tool_polygon.cc
new file mode 100644
index 00000000..3dbd15d6
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/tool_polygon.cc
@@ -0,0 +1,62 @@
+/*
+ * tool_polygon.cc -- Part of Chalk
+ *
+ * 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 <tqpoint.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( chalktoolpolygon, ToolPolygonFactory( "chalk" ) )
+
+
+ToolPolygon::ToolPolygon(TQObject *tqparent, const char *name, const TQStringList &)
+ : KParts::Plugin(tqparent, name)
+{
+ setInstance(ToolPolygonFactory::instance());
+
+ if ( tqparent->inherits("KisToolRegistry") )
+ {
+ KisToolRegistry * r = dynamic_cast<KisToolRegistry*>( tqparent );
+ r->add(new KisToolPolygonFactory());
+ }
+
+}
+
+ToolPolygon::~ToolPolygon()
+{
+}
+
+//#include "tool_polygon.moc"
diff --git a/chalk/plugins/tools/tool_polygon/tool_polygon.h b/chalk/plugins/tools/tool_polygon/tool_polygon.h
new file mode 100644
index 00000000..ec816736
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/tool_polygon.h
@@ -0,0 +1,39 @@
+/*
+ * 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_POLYGON_H_
+#define TOOL_POLYGON_H_
+
+#include <kparts/plugin.h>
+
+/**
+ * A module that provides a polygon tool.
+ */
+class ToolPolygon : public KParts::Plugin
+{
+ Q_OBJECT
+ TQ_OBJECT
+
+public:
+
+ ToolPolygon(TQObject *tqparent, const char *name, const TQStringList &);
+ virtual ~ToolPolygon();
+
+};
+
+#endif // TOOL_POLYGON_H_
diff --git a/chalk/plugins/tools/tool_polygon/tool_polygon.png b/chalk/plugins/tools/tool_polygon/tool_polygon.png
new file mode 100644
index 00000000..654083c6
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/tool_polygon.png
Binary files differ
diff --git a/chalk/plugins/tools/tool_polygon/tool_polygon_cursor.png b/chalk/plugins/tools/tool_polygon/tool_polygon_cursor.png
new file mode 100644
index 00000000..bca4bffd
--- /dev/null
+++ b/chalk/plugins/tools/tool_polygon/tool_polygon_cursor.png
Binary files differ