chalk

kis_part_layer_handler.cpp
1/*
2 * Copyright (c) 2006 Bart Coppens <kde@bartcoppens.be>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "kis_canvas.h"
20#include <fixx11h.h> // kis_canvas.h does X11 stuff
21
22#include <tqpainter.h>
23#include <tqcursor.h>
24
25#include "kis_cursor.h"
26#include "kis_canvas_painter.h"
27#include "kis_move_event.h"
28#include "kis_button_press_event.h"
29#include "kis_button_release_event.h"
30#include "kis_group_layer.h"
31#include "kis_part_layer_handler.h"
32
33KisPartLayerHandler::KisPartLayerHandler(KisView* view, const KoDocumentEntry& entry,
34 KisGroupLayerSP parent, KisLayerSP above)
35 : m_parent(parent), m_above(above), m_view(view), m_entry(entry) {
36 m_started = false;
37 view->getCanvasController()->setCanvasCursor( KisCursor::selectCursor() );
38}
39
40void KisPartLayerHandler::done() {
41 emit handlerDone(); // We will get deleted by the view
42}
43
44void KisPartLayerHandler::gotMoveEvent(KisMoveEvent* event) {
45 if (!m_started) {
46 emit sigGotMoveEvent(event);
47 return;
48 }
49
50 KisCanvasPainter painter(m_view->getCanvasController()->kiscanvas());
51 painter.setRasterOp( NotROP );
52
53 // erase old lines
54 TQRect r(m_start, m_end);
55 r = r.normalize();
56 if (!r.isEmpty())
57 painter.drawRect(r);
58
59 m_end = event->pos().roundTQPoint();
60 r = TQRect(m_start, m_end).normalize();
61
62 painter.drawRect(r);
63 painter.end();
64}
65
66void KisPartLayerHandler::gotButtonPressEvent(KisButtonPressEvent* event) {
67 m_start = event->pos().roundTQPoint();
68 m_end = m_start;
69 m_started = true;
70}
71
72void KisPartLayerHandler::gotButtonReleaseEvent(KisButtonReleaseEvent* event) {
73 if (!m_started) {
74 done();
75 return;
76 }
77
78 m_end = event->pos().roundTQPoint();
79
80 TQRect r(m_start, m_end);
81
82 m_view->insertPart(r.normalize(), m_entry, m_parent, m_above);
83 // We will get deleted by the view through the above
84}
85
86void KisPartLayerHandler::gotKeyPressEvent(TQKeyEvent* event) {
87 if (event->key() == Key_Escape) {
88 done();
89 } else {
90 emit sigGotKeyPressEvent(event);
91 }
92}
93
94#include "kis_part_layer_handler.moc"