2
* kis_tool_polyline.cc -- part of Krita
4
* Copyright (c) 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
#include <knuminput.h>
35
#include "kis_painter.h"
36
#include "kis_canvas_subject.h"
37
#include "kis_canvas_controller.h"
38
#include "kis_button_press_event.h"
39
#include "kis_button_release_event.h"
40
#include "kis_move_event.h"
41
#include "kis_paintop_registry.h"
42
#include "kis_canvas.h"
43
#include "kis_canvas_painter.h"
44
#include "kis_cursor.h"
46
#include "kis_tool_polyline.h"
48
KisToolPolyline::KisToolPolyline()
49
: super(i18n ("Polyline")),
53
setName("tool_polyline");
54
setCursor(KisCursor::load("tool_polyline_cursor.png", 6, 6));
57
KisToolPolyline::~KisToolPolyline()
61
void KisToolPolyline::update (KisCanvasSubject *subject)
63
super::update (subject);
65
m_currentImage = m_subject->currentImg ();
68
void KisToolPolyline::buttonPress(KisButtonPressEvent *event)
71
if (event->button() == LeftButton && event->state() != Qt::ShiftButton ) {
75
if (m_points.isEmpty())
77
m_dragStart = event->pos();
78
m_dragEnd = event->pos();
79
m_points.append(m_dragStart);
81
m_dragStart = m_dragEnd;
82
m_dragEnd = event->pos();
85
} else if (event->button() == LeftButton && event->state() == Qt::ShiftButton ) {
91
void KisToolPolyline::deactivate()
98
void KisToolPolyline::finish()
100
// erase old lines on canvas
104
KisPaintDeviceSP device = m_currentImage->activeDevice ();
107
KisPainter painter (device);
108
if (m_currentImage->undo()) painter.beginTransaction (i18n ("Polyline"));
110
painter.setPaintColor(m_subject->fgColor());
111
painter.setBrush(m_subject->currentBrush());
112
painter.setOpacity(m_opacity);
113
painter.setCompositeOp(m_compositeOp);
114
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter);
115
painter.setPaintOp(op); // Painter takes ownership
118
KisPointVector::iterator it;
119
for( it = m_points.begin(); it != m_points.end(); ++it )
121
if( it == m_points.begin() )
126
painter.paintLine(start, PRESSURE_DEFAULT, 0, 0, end, PRESSURE_DEFAULT, 0, 0);
132
device->setDirty( painter.dirtyRect() );
135
if (m_currentImage->undo()) {
136
m_currentImage->undoAdapter()->addCommand(painter.endTransaction());
140
void KisToolPolyline::move(KisMoveEvent *event)
143
// erase old lines on canvas
145
// get current mouse position
146
m_dragEnd = event->pos();
147
// draw new lines on canvas
152
void KisToolPolyline::buttonRelease(KisButtonReleaseEvent *event)
154
if (!m_subject || !m_currentImage)
157
if (m_dragging && event->button() == LeftButton) {
159
m_points.append (m_dragEnd);
162
if (m_dragging && event->button() == RightButton) {
168
void KisToolPolyline::doubleClick(KisDoubleClickEvent *)
174
void KisToolPolyline::paint(KisCanvasPainter& gc)
179
void KisToolPolyline::paint(KisCanvasPainter& gc, const QRect&)
184
void KisToolPolyline::draw()
187
KisCanvasController *controller = m_subject->canvasController();
188
KisCanvas *canvas = controller->kiscanvas();
189
KisCanvasPainter gc(canvas);
195
void KisToolPolyline::draw(KisCanvasPainter& gc)
197
if (!m_subject || !m_currentImage)
200
QPen pen(Qt::white, 0, Qt::SolidLine);
203
gc.setRasterOp(Qt::XorROP);
205
KisCanvasController *controller = m_subject->canvasController();
211
startPos = controller->windowToView(m_dragStart.floorQPoint());
212
endPos = controller->windowToView(m_dragEnd.floorQPoint());
213
gc.drawLine(startPos, endPos);
215
for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) {
217
if (it == m_points.begin())
223
startPos = controller->windowToView(start.floorQPoint());
224
endPos = controller->windowToView(end.floorQPoint());
226
gc.drawLine(startPos, endPos);
234
void KisToolPolyline::setup(KActionCollection *collection)
236
m_action = static_cast<KRadioAction *>(collection->action(name()));
239
KShortcut shortcut(Qt::Key_Plus);
240
shortcut.append(KShortcut(Qt::Key_F9));
241
m_action = new KRadioAction(i18n("&Polyline"),
248
Q_CHECK_PTR(m_action);
250
m_action->setToolTip(i18n("Draw a polyline. Shift-mouseclick ends the polyline."));
251
m_action->setExclusiveGroup("tools");
256
QString KisToolPolyline::quickHelp() const
258
return i18n("Press shift-mouseclick to end the polyline.");
261
#include "kis_tool_polyline.moc"