summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/tools/tool_perspectivegrid
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_perspectivegrid
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_perspectivegrid')
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/Makefile.am35
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/chalktoolperspectivegrid.desktop35
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cc499
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.h111
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cc62
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.h43
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.pngbin0 -> 738 bytes
-rw-r--r--chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.svg87
8 files changed, 872 insertions, 0 deletions
diff --git a/chalk/plugins/tools/tool_perspectivegrid/Makefile.am b/chalk/plugins/tools/tool_perspectivegrid/Makefile.am
new file mode 100644
index 00000000..b3b0f74f
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/Makefile.am
@@ -0,0 +1,35 @@
+kde_services_DATA = chalktoolperspectivegrid.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)
+
+chalktoolperspectivegrid_la_SOURCES = \
+ tool_perspectivegrid.cc \
+ kis_tool_perspectivegrid.cc
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = chalktoolperspectivegrid.la
+
+noinst_HEADERS = \
+ tool_perspectivegrid.h \
+ kis_tool_perspectivegrid.h
+
+chalktoolperspectivegrid_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
+chalktoolperspectivegrid_la_LIBADD = ../../../libchalkcommon.la
+
+METASOURCES = AUTO
+
+KDE_OPTIONS = nofinal
+
+chalkpics_DATA = \
+ tool_perspectivegrid.png
+
+chalkpicsdir = $(kde_datadir)/chalk/pics
+
diff --git a/chalk/plugins/tools/tool_perspectivegrid/chalktoolperspectivegrid.desktop b/chalk/plugins/tools/tool_perspectivegrid/chalktoolperspectivegrid.desktop
new file mode 100644
index 00000000..70001614
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/chalktoolperspectivegrid.desktop
@@ -0,0 +1,35 @@
+[Desktop Entry]
+Name=Perspective Grid Tool
+Name[bg]=Инструмент мрежа
+Name[ca]=Eina de graella de perspectiva
+Name[da]=Perspektivgitterværktøj
+Name[de]=Perspektive-Raster-Werkzeug
+Name[el]=Εργαλείο προοπτικού πλέγματος
+Name[eo]=Perspektivkrado-ilo
+Name[es]=Herramienta Cuadrícula de perspectiva
+Name[et]=Perspektiivvõrgu tööriist
+Name[fa]=ابزار توری بُعدنما
+Name[fy]=Perspeksjeraster-ark
+Name[hu]=Perspektívarács
+Name[it]=Strumento di reticolo prospettico
+Name[ja]=遠近法グリッドツール
+Name[km]=ឧបករណ៍​ក្រឡា​ចត្រង្គ​យថាទស្សន៍
+Name[nb]=Perspektivnett-verktøy
+Name[nds]=Kiekwinkelgadder-Warktüüch
+Name[ne]=दृश्यात्मक ग्रीड उपकरण
+Name[nl]=Perspectiefraster-gereedschap
+Name[pl]=Narzędzie siatki perspektywy
+Name[pt]=Ferramenta de Grelha em Perspectiva
+Name[pt_BR]=Ferramenta de Grade em Perspectiva
+Name[ru]=Перспектива
+Name[sk]=Perspektívna mriežka
+Name[sl]=Orodja Mreža za perspektivo
+Name[sr]=Алат за мрежу у перспективи
+Name[sr@Latn]=Alat za mrežu u perspektivi
+Name[sv]=Perspektivrutnätsverktyg
+Name[uk]=Засіб ґратки перспективи
+Name[zh_TW]=透視格工具
+ServiceTypes=Chalk/Tool
+Type=Service
+X-KDE-Library=chalktoolperspectivegrid
+X-Chalk-Version=2
diff --git a/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cc b/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cc
new file mode 100644
index 00000000..3a21e72e
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cc
@@ -0,0 +1,499 @@
+/*
+ * kis_tool_perspectivegrid.cc - part of Chalk
+ *
+ * Copyright (c) 2006 Cyrille Berger <[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 <kis_tool_perspectivegrid.h>
+
+#include <tqapplication.h>
+#include <tqpainter.h>
+#include <tqregion.h>
+#include <tqwidget.h>
+#include <tqlayout.h>
+
+#include <kaction.h>
+#include <kdebug.h>
+#include <kcommand.h>
+#include <klocale.h>
+
+#include <kis_button_press_event.h>
+#include <kis_button_release_event.h>
+#include <kis_canvas_controller.h>
+#include <kis_canvas_painter.h>
+#include <kis_canvas_subject.h>
+#include <kis_cursor.h>
+#include <kis_image.h>
+#include <kis_move_event.h>
+#include <kis_perspective_grid_manager.h>
+#include <kis_selected_transaction.h>
+#include <kis_painter.h>
+#include <kis_paintop_registry.h>
+#include <kis_vec.h>
+
+#include <kis_canvas.h>
+
+KisToolPerspectiveGrid::KisToolPerspectiveGrid()
+ : super(i18n("Perspective Grid")), m_handleSize(13), m_handleHalfSize(6)
+
+{
+ setName("tool_perspectivegrid");
+
+ m_subject = 0;
+ m_dragging = false;
+}
+
+KisToolPerspectiveGrid::~KisToolPerspectiveGrid()
+{
+}
+
+void KisToolPerspectiveGrid::activate()
+{
+ m_subject->perspectiveGridManager()->startEdition();
+ if( ! m_subject->currentImg()->perspectiveGrid()->hasSubGrids() )
+ {
+ m_mode = MODE_CREATION;
+ m_points.clear();
+ } else {
+ m_mode = MODE_EDITING;
+ drawGrid();
+ }
+ super::activate();
+}
+
+void KisToolPerspectiveGrid::deactivate()
+{
+ m_subject->perspectiveGridManager()->stopEdition();
+ m_subject->perspectiveGridManager()->setGridVisible( true);
+ if( m_mode == MODE_CREATION )
+ {
+ drawGridCreation();
+ m_points.clear();
+ m_dragging = false;
+ } else {
+ drawGrid();
+ }
+}
+
+
+void KisToolPerspectiveGrid::update (KisCanvasSubject *subject)
+{
+ m_subject = subject;
+ super::update(m_subject);
+}
+
+bool KisToolPerspectiveGrid::mouseNear(const TQPoint& mousep, const TQPoint point)
+{
+ return (TQRect( (point.x() - m_handleHalfSize), (point.y() - m_handleHalfSize), m_handleSize, m_handleSize).tqcontains(mousep) );
+}
+
+void KisToolPerspectiveGrid::buttonPress(KisButtonPressEvent *event)
+{
+ KisPerspectiveGrid* pGrid = m_subject->currentImg()->perspectiveGrid();
+ if(!pGrid->hasSubGrids() && m_mode != MODE_CREATION)
+ { // it's possible that the perspectiv grid was cleared
+ m_mode = MODE_CREATION;
+ m_points.clear();
+ }
+ if( m_mode == MODE_CREATION && event->button() == Qt::LeftButton)
+ {
+ 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();
+ drawGridCreation();
+ }
+ } else if(m_mode == MODE_EDITING && event->button() == Qt::LeftButton){
+ // Look for the handle which was pressed
+ if (!m_subject)
+ return;
+ KisCanvasController *controller = m_subject->canvasController();
+ Q_ASSERT(controller);
+ TQPoint mousep = controller->windowToView( event->pos().roundTQPoint() );
+
+ for( TQValueList<KisSubPerspectiveGrid*>::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it)
+ {
+ KisSubPerspectiveGrid* grid = *it;
+ if( mouseNear( mousep, controller->windowToView(grid->topLeft()->roundTQPoint() ) ) )
+ {
+ kdDebug() << " PRESS TOPLEFT HANDLE " << endl;
+ m_mode = MODE_DRAGING_NODE;
+ m_selectedNode1 = grid->topLeft();
+ break;
+ }
+ else if( mouseNear( mousep, controller->windowToView(grid->topRight()->roundTQPoint() ) ) )
+ {
+ kdDebug() << " PRESS TOPRIGHT HANDLE " << endl;
+ m_mode = MODE_DRAGING_NODE;
+ m_selectedNode1 = grid->topRight();
+ break;
+ }
+ else if( mouseNear( mousep, controller->windowToView(grid->bottomLeft()->roundTQPoint() ) ) )
+ {
+ kdDebug() << " PRESS BOTTOMLEFT HANDLE " << endl;
+ m_mode = MODE_DRAGING_NODE;
+ m_selectedNode1 = grid->bottomLeft();
+ break;
+ }
+ else if( mouseNear( mousep, controller->windowToView(grid->bottomRight()->roundTQPoint() ) ) )
+ {
+ kdDebug() << " PRESS BOTTOMRIGHT HANDLE " << endl;
+ m_mode = MODE_DRAGING_NODE;
+ m_selectedNode1 = grid->bottomRight();
+ break;
+ }
+ else if( !grid->leftGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topLeft() + *grid->bottomLeft() )*0.5) ).roundTQPoint() ) )
+ {
+ kdDebug() << " PRESS LEFT HANDLE " << endl;
+ m_mode = MODE_DRAGING_TRANSLATING_TWONODES;
+ drawGrid();
+ m_selectedNode1 = new KisPerspectiveGridNode( *grid->topLeft() );
+ m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomLeft() );
+ KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( m_selectedNode1, grid->topLeft() , grid->bottomLeft(), m_selectedNode2);
+ m_dragEnd = event->pos();
+ newsubgrid->setRightGrid( grid);
+ grid->setLeftGrid( newsubgrid);
+ pGrid->addNewSubGrid( newsubgrid);
+ drawGrid();
+ break;
+ }
+ else if( !grid->rightGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topRight() + *grid->bottomRight() )*0.5) ).roundTQPoint() ) )
+ {
+ kdDebug() << " PRESS RIGHT HANDLE " << endl;
+ m_mode = MODE_DRAGING_TRANSLATING_TWONODES;
+ drawGrid();
+ m_selectedNode1 = new KisPerspectiveGridNode( *grid->topRight() );
+ m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomRight() );
+ KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( grid->topRight(), m_selectedNode1, m_selectedNode2, grid->bottomRight());
+ m_dragEnd = event->pos();
+ newsubgrid->setLeftGrid( grid);
+ grid->setRightGrid( newsubgrid);
+ pGrid->addNewSubGrid( newsubgrid);
+ drawGrid();
+ break;
+ }
+ else if( !grid->topGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topLeft() + *grid->topRight() )*0.5) ).roundTQPoint() ) )
+ {
+ kdDebug() << " PRESS TOP HANDLE " << endl;
+ m_mode = MODE_DRAGING_TRANSLATING_TWONODES;
+ drawGrid();
+ m_selectedNode1 = new KisPerspectiveGridNode( *grid->topLeft() );
+ m_selectedNode2 = new KisPerspectiveGridNode( *grid->topRight() );
+ KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( m_selectedNode1, m_selectedNode2, grid->topRight(), grid->topLeft() );
+ m_dragEnd = event->pos();
+ newsubgrid->setBottomGrid( grid);
+ grid->setTopGrid( newsubgrid);
+ pGrid->addNewSubGrid( newsubgrid);
+ drawGrid();
+ break;
+ }
+ else if( !grid->bottomGrid() && mouseNear( mousep, controller->windowToView( ((*grid->bottomLeft() + *grid->bottomRight() )*0.5) ).roundTQPoint() ) )
+ {
+ kdDebug() << " PRESS BOTTOM HANDLE " << endl;
+ m_mode = MODE_DRAGING_TRANSLATING_TWONODES;
+ drawGrid();
+ m_selectedNode1 = new KisPerspectiveGridNode( *grid->bottomLeft() );
+ m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomRight() );
+ KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( grid->bottomLeft(), grid->bottomRight(), m_selectedNode2, m_selectedNode1);
+ m_dragEnd = event->pos();
+ newsubgrid->setTopGrid( grid);
+ grid->setBottomGrid( newsubgrid);
+ pGrid->addNewSubGrid( newsubgrid);
+ drawGrid();
+ break;
+ }
+ }
+ }
+}
+
+
+void KisToolPerspectiveGrid::move(KisMoveEvent *event)
+{
+ if( m_mode == MODE_CREATION )
+ {
+ if (m_dragging) {
+ // erase old lines on canvas
+ drawGridCreation();
+ // get current mouse position
+ m_dragEnd = event->pos();
+ // draw new lines on canvas
+ drawGridCreation();
+ }
+ } else {
+ if( m_mode == MODE_DRAGING_NODE)
+ {
+ drawGrid();
+ m_selectedNode1->setX( event->pos().x() );
+ m_selectedNode1->setY( event->pos().y() );
+ drawGrid();
+ }
+ if( m_mode == MODE_DRAGING_TRANSLATING_TWONODES)
+ {
+ drawGrid();
+ KisPoint translate = event->pos() - m_dragEnd;
+ m_dragEnd = event->pos();
+ *m_selectedNode1 += translate;;
+ *m_selectedNode2 += translate;;
+ drawGrid();
+ }
+ }
+}
+
+void KisToolPerspectiveGrid::buttonRelease(KisButtonReleaseEvent *event)
+{
+ if (!m_subject)
+ return;
+
+ if( m_mode == MODE_CREATION )
+ {
+ if (m_dragging && event->button() == Qt::LeftButton) {
+ m_dragging = false;
+ m_points.append (m_dragEnd);
+ if( m_points.size() == 4)
+ { // wow we have a grid, isn't that cool ?
+ drawGridCreation(); // Clean
+ m_subject->currentImg()->perspectiveGrid()->addNewSubGrid( new KisSubPerspectiveGrid( new KisPerspectiveGridNode(m_points[0]), new KisPerspectiveGridNode(m_points[1]), new KisPerspectiveGridNode(m_points[2]), new KisPerspectiveGridNode(m_points[3]) ) );
+ drawGrid();
+ m_mode = MODE_EDITING;
+ }
+ }
+ } else {
+ m_mode = MODE_EDITING;
+ m_selectedNode1 = 0;
+ m_selectedNode2 = 0;
+ }
+
+/* if (m_dragging && event->button() == RightButton) {
+
+ }*/
+}
+
+void KisToolPerspectiveGrid::paint(KisCanvasPainter& gc)
+{
+ if( m_mode == MODE_CREATION )
+ {
+ drawGridCreation(gc);
+ } else {
+ drawGrid(gc);
+ }
+}
+
+void KisToolPerspectiveGrid::paint(KisCanvasPainter& gc, const TQRect&)
+{
+ if( m_mode == MODE_CREATION )
+ {
+ drawGridCreation(gc);
+ } else {
+ drawGrid(gc);
+ }
+}
+
+void KisToolPerspectiveGrid::drawGridCreation()
+{
+ if (m_subject) {
+ KisCanvasController *controller = m_subject->canvasController();
+ KisCanvas *canvas = controller->kiscanvas();
+ KisCanvasPainter gc(canvas);
+
+ drawGridCreation(gc);
+ }
+}
+
+
+void KisToolPerspectiveGrid::drawGridCreation(KisCanvasPainter& gc)
+{
+ if (!m_subject)
+ return;
+
+ TQPen pen(TQt::white);
+
+ 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 KisToolPerspectiveGrid::drawSmallRectangle(KisCanvasPainter& gc, TQPoint p)
+{
+ gc.drawRect( p.x() - m_handleHalfSize - 1, p.y() - m_handleHalfSize - 1, m_handleSize, m_handleSize);
+}
+
+void KisToolPerspectiveGrid::drawGrid(KisCanvasPainter& gc)
+{
+
+ if (!m_subject)
+ return;
+
+ KisCanvasController *controller = m_subject->canvasController();
+
+ TQPen pen(TQt::white);
+ TQPoint startPos;
+ TQPoint endPos;
+
+ gc.setPen(pen);
+ gc.setRasterOp(TQt::XorROP);
+ KisPerspectiveGrid* pGrid = m_subject->currentImg()->perspectiveGrid();
+
+ for( TQValueList<KisSubPerspectiveGrid*>::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it)
+ {
+ KisSubPerspectiveGrid* grid = *it;
+ int index = grid->index();
+ bool drawLeft = !(grid->leftGrid() && (index > grid->leftGrid()->index() ) );
+ bool drawRight = !(grid->rightGrid() && (index > grid->rightGrid()->index() ) );
+ bool drawTop = !(grid->topGrid() && (index > grid->topGrid()->index() ) );
+ bool drawBottom = !(grid->bottomGrid() && (index > grid->bottomGrid()->index() ) );
+ if(drawTop) {
+ startPos = controller->windowToView(grid->topLeft()->roundTQPoint());
+ endPos = controller->windowToView(grid->topRight()->roundTQPoint());
+ gc.drawLine( startPos, endPos );
+ if( !grid->topGrid() )
+ {
+ drawSmallRectangle(gc, (endPos + startPos) / 2);
+ }
+ if(drawLeft) {
+ drawSmallRectangle(gc, startPos);
+ }
+ if(drawRight) {
+ drawSmallRectangle(gc, endPos);
+ }
+ }
+ if(drawRight) {
+ startPos = controller->windowToView(grid->topRight()->roundTQPoint());
+ endPos = controller->windowToView(grid->bottomRight()->roundTQPoint());
+ gc.drawLine( startPos, endPos );
+ if( !grid->rightGrid() )
+ {
+ drawSmallRectangle(gc, (endPos + startPos) / 2);
+ }
+ }
+ if(drawBottom) {
+ startPos = controller->windowToView(grid->bottomRight()->roundTQPoint());
+ endPos = controller->windowToView(grid->bottomLeft()->roundTQPoint());
+ gc.drawLine( startPos, endPos );
+ if( !grid->bottomGrid() )
+ {
+ drawSmallRectangle(gc, (endPos + startPos) / 2);
+ }
+ if(drawLeft) {
+ drawSmallRectangle(gc, endPos);
+ }
+ if(drawRight) {
+ drawSmallRectangle(gc, startPos);
+ }
+ }
+ if(drawLeft) {
+ startPos = controller->windowToView(grid->bottomLeft()->roundTQPoint());
+ endPos = controller->windowToView(grid->topLeft()->roundTQPoint());
+ gc.drawLine( startPos, endPos );
+ if( !grid->leftGrid() )
+ {
+ drawSmallRectangle(gc, (endPos + startPos) / 2);
+ }
+ }
+ KisPoint tbVpf = grid->topBottomVanishingPoint();
+ if( fabs(tbVpf.x()) < 30000000. && fabs(tbVpf.y()) < 30000000.)
+ {
+ TQPoint tbVp = controller->windowToView(tbVpf.roundTQPoint());
+ gc.drawLine( tbVp.x() - m_handleHalfSize, tbVp.y() - m_handleHalfSize, tbVp.x() + m_handleHalfSize, tbVp.y() + m_handleHalfSize);
+ gc.drawLine( tbVp.x() - m_handleHalfSize, tbVp.y() + m_handleHalfSize, tbVp.x() + m_handleHalfSize, tbVp.y() - m_handleHalfSize);
+ }
+ KisPoint lrVpf = grid->leftRightVanishingPoint();
+ if( fabs(lrVpf.x()) < 30000000. && fabs(lrVpf.y()) < 30000000.)
+ { // Don't display it, if it is too far, or you get funny results
+ TQPoint lrVp = controller->windowToView(lrVpf.roundTQPoint());
+ gc.drawLine( lrVp.x() - m_handleHalfSize, lrVp.y() - m_handleHalfSize, lrVp.x() + m_handleHalfSize, lrVp.y() + m_handleHalfSize);
+ gc.drawLine( lrVp.x() - m_handleHalfSize, lrVp.y() + m_handleHalfSize, lrVp.x() + m_handleHalfSize, lrVp.y() - m_handleHalfSize);
+ }
+ }
+}
+
+void KisToolPerspectiveGrid::drawGrid()
+{
+ if (m_subject) {
+ KisCanvasController *controller = m_subject->canvasController();
+ KisCanvas *canvas = controller->kiscanvas();
+ KisCanvasPainter gc(canvas);
+
+ drawGrid(gc);
+ }
+
+}
+
+
+void KisToolPerspectiveGrid::setup(KActionCollection *collection)
+{
+ m_action = static_cast<KRadioAction *>(collection->action(name()));
+
+ if (m_action == 0) {
+ m_action = new KRadioAction(i18n("&Perspective Grid"),
+ "tool_perspectivegrid" ,
+ 0,
+ this,
+ TQT_SLOT(activate()),
+ collection,
+ name());
+ Q_CHECK_PTR(m_action);
+ m_action->setExclusiveGroup("tools");
+ m_action->setToolTip(i18n("Edit the perspective grid"));
+ m_ownAction = true;
+ }
+}
+
+
+// TQWidget* KisToolPerspectiveGrid::createOptionWidget(TQWidget* tqparent)
+// {
+// return 0;
+// }
+//
+// TQWidget* KisToolPerspectiveGrid::optionWidget()
+// {
+// return 0;
+// }
+
+
+#include "kis_tool_perspectivegrid.moc"
diff --git a/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.h b/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.h
new file mode 100644
index 00000000..69f6407a
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.h
@@ -0,0 +1,111 @@
+/*
+ * kis_tool_perspectivegrid.h - part of Chalk
+ *
+ * Copyright (c) 2006 Cyrille Berger <[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_PERSPECTIVE_GRID_H_
+#define _KIS_TOOL_PERSPECTIVE_GRID_H_
+
+#include <kis_perspective_grid.h>
+#include <kis_point.h>
+#include <kis_tool_non_paint.h>
+#include <kis_tool_factory.h>
+
+class KisToolPerspectiveGrid : public KisToolNonPaint {
+ Q_OBJECT
+ TQ_OBJECT
+ enum PerspectiveGridEditionMode {
+ MODE_CREATION, // This is the mode when there is not yet a perspective grid
+ MODE_EDITING, // This is the mode when the grid has been created, and we are waiting for the user to click on a control box
+ MODE_DRAGING_NODE, // In this mode one node is translated
+ MODE_DRAGING_TRANSLATING_TWONODES // This mode is used when creating a new sub perspective grid
+ };
+ typedef KisToolNonPaint super;
+public:
+ KisToolPerspectiveGrid();
+ virtual ~KisToolPerspectiveGrid();
+ //
+ // KisCanvasObserver interface
+ //
+
+ virtual void update (KisCanvasSubject *subject);
+
+ //
+ // KisToolPaint interface
+ //
+
+ virtual void setup(KActionCollection *collection);
+ virtual TQ_UINT32 priority() { return 3; }
+ virtual enumToolType toolType() { return TOOL_VIEW; }
+ virtual void buttonPress(KisButtonPressEvent *event);
+ virtual void move(KisMoveEvent *event);
+ virtual void buttonRelease(KisButtonReleaseEvent *event);
+
+// TQWidget* createOptionWidget(TQWidget* tqparent);
+// virtual TQWidget* optionWidget();
+
+public slots:
+ virtual void activate();
+ void deactivate();
+
+protected:
+ virtual void paint(KisCanvasPainter& gc);
+ virtual void paint(KisCanvasPainter& gc, const TQRect& rc);
+ void drawGridCreation(KisCanvasPainter& gc);
+ void drawGridCreation();
+ void drawGrid(KisCanvasPainter& gc);
+ void drawGrid();
+
+private:
+ void drawSmallRectangle(KisCanvasPainter& gc, TQPoint p);
+ bool mouseNear(const TQPoint& mousep, const TQPoint point);
+
+protected:
+ KisPoint m_dragStart;
+ KisPoint m_dragEnd;
+
+ bool m_dragging;
+private:
+ typedef TQValueVector<KisPoint> KisPointVector;
+ KisCanvasSubject *m_subject;
+ KisPointVector m_points;
+ PerspectiveGridEditionMode m_mode;
+ TQ_INT32 m_handleSize, m_handleHalfSize;
+ KisPerspectiveGridNodeSP m_selectedNode1, m_selectedNode2;
+
+};
+
+
+class KisToolPerspectiveGridFactory : public KisToolFactory {
+ typedef KisToolFactory super;
+public:
+ KisToolPerspectiveGridFactory() : super() {};
+ virtual ~KisToolPerspectiveGridFactory(){};
+
+ virtual KisTool * createTool(KActionCollection * ac) {
+ KisTool * t = new KisToolPerspectiveGrid();
+ Q_CHECK_PTR(t);
+ t->setup(ac);
+ return t;
+ }
+ virtual KisID id() { return KisID("perspectivegridtool", i18n("Perspective Grid Tool")); }
+};
+
+
+#endif
+
diff --git a/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cc b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cc
new file mode 100644
index 00000000..69158e21
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cc
@@ -0,0 +1,62 @@
+/*
+ * tool_perspectivegrid.cc -- Part of Chalk
+ *
+ * Copyright (c) 2006 Cyrille Berger <[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 <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_perspectivegrid.h"
+#include "kis_tool_perspectivegrid.h"
+
+
+typedef KGenericFactory<ToolPerspectiveGrid> ToolPerspectiveGridFactory;
+K_EXPORT_COMPONENT_FACTORY( chalktoolperspectivegrid, ToolPerspectiveGridFactory( "chalk" ) )
+
+
+ToolPerspectiveGrid::ToolPerspectiveGrid(TQObject *tqparent, const char *name, const TQStringList &)
+ : KParts::Plugin(tqparent, name)
+{
+ setInstance(ToolPerspectiveGridFactory::instance());
+
+ if ( tqparent->inherits("KisToolRegistry") )
+ {
+ KisToolRegistry * r = dynamic_cast<KisToolRegistry*>(tqparent);
+ r->add(new KisToolPerspectiveGridFactory());
+ }
+
+}
+
+ToolPerspectiveGrid::~ToolPerspectiveGrid()
+{
+}
+
+#include "tool_perspectivegrid.moc"
diff --git a/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.h b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.h
new file mode 100644
index 00000000..aed4a60c
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <[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_PERSPECTIVE_GRID_H_
+#define TOOL_PERSPECTIVE_GRID_H_
+
+#include <kparts/plugin.h>
+
+class KisView;
+
+/**
+ * A module that provides a tool for editing the perspective grid.
+ */
+class ToolPerspectiveGrid : public KParts::Plugin
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ ToolPerspectiveGrid(TQObject *tqparent, const char *name, const TQStringList &);
+ virtual ~ToolPerspectiveGrid();
+
+private:
+
+ KisView * m_view;
+
+};
+
+#endif // TOOL_PERSPECTIVE_GRID_H_
diff --git a/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.png b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.png
new file mode 100644
index 00000000..ac4efbfa
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.png
Binary files differ
diff --git a/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.svg b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.svg
new file mode 100644
index 00000000..3dd79413
--- /dev/null
+++ b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.svg
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://web.resource.org/cc/"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="22"
+ height="22"
+ id="svg2"
+ sodipodi:version="0.32"
+ inkscape:version="0.43"
+ version="1.0"
+ sodipodi:docbase="/home/cyrille/koffice-1.6/chalk/plugins/tools/tool_perspectivegrid"
+ sodipodi:docname="tool_perspectivegrid.svg"
+ inkscape:export-filename="/home/cyrille/koffice-1.6/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="9.8597476"
+ inkscape:cx="12.855376"
+ inkscape:cy="7.6671075"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ inkscape:window-width="749"
+ inkscape:window-height="540"
+ inkscape:window-x="424"
+ inkscape:window-y="433" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1">
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#909090;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 4.8682788,20.580085 C 6.5924609,1.3098151 6.7953058,1.5126601 6.7953058,1.5126601 L 6.7953058,1.5126601 L 6.7953058,1.5126601"
+ id="path2183" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#909090;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 11.359317,18.551636 C 10.446515,2.3240399 10.446515,2.3240399 10.446515,2.3240399 L 10.446515,2.3240399 L 10.446515,2.3240399"
+ id="path2185" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#909090;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 17.444666,17.131721 C 13.894879,3.1354197 13.894879,3.1354197 13.894879,3.1354197"
+ id="path2187" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#909090;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 2.7384068,4.7581793 C 17.647511,6.5837838 17.546088,6.5837838 17.546088,6.5837838"
+ id="path2191" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#909090;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 2.0284495,10.742105 C 18.256045,9.7278805 18.86458,9.1193456 18.86458,9.1193456"
+ id="path2193"
+ sodipodi:nodetypes="cc" />
+ <path
+ style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:#909090;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 1.0142247,17.131721 C 20.08165,12.56771 20.08165,12.364865 20.08165,12.364865"
+ id="path2195"
+ sodipodi:nodetypes="cc" />
+ <path
+ style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 3.1440967,0.59985768 L 16.531864,3.6425319 L 21.70441,15.813228 L 0.50711235,21.594309 L 3.1440967,0.59985768 z "
+ id="rect1307"
+ sodipodi:nodetypes="ccccc" />
+ </g>
+</svg>