krita

kis_part_layer_handler.cc

00001 /*
00002  *  Copyright (c) 2006 Bart Coppens <kde@bartcoppens.be>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_canvas.h"
00020 #include <fixx11h.h> // kis_canvas.h does X11 stuff
00021 
00022 #include <qpainter.h>
00023 #include <qcursor.h>
00024 
00025 #include "kis_cursor.h"
00026 #include "kis_canvas_painter.h"
00027 #include "kis_move_event.h"
00028 #include "kis_button_press_event.h"
00029 #include "kis_button_release_event.h"
00030 #include "kis_group_layer.h"
00031 #include "kis_part_layer_handler.h"
00032 
00033 KisPartLayerHandler::KisPartLayerHandler(KisView* view, const KoDocumentEntry& entry,
00034                                          KisGroupLayerSP parent, KisLayerSP above)
00035     : m_parent(parent), m_above(above), m_view(view), m_entry(entry) {
00036     m_started = false;
00037     view->getCanvasController()->setCanvasCursor( KisCursor::selectCursor() );
00038 }
00039 
00040 void KisPartLayerHandler::done() {
00041     emit handlerDone(); // We will get deleted by the view
00042 }
00043 
00044 void KisPartLayerHandler::gotMoveEvent(KisMoveEvent* event) {
00045     if (!m_started) {
00046         emit sigGotMoveEvent(event);
00047         return;
00048     }
00049 
00050     KisCanvasPainter painter(m_view->getCanvasController()->kiscanvas());
00051     painter.setRasterOp( NotROP );
00052 
00053     // erase old lines
00054     QRect r(m_start, m_end);
00055     r = r.normalize();
00056     if (!r.isEmpty())
00057         painter.drawRect(r);
00058 
00059     m_end = event->pos().roundQPoint();
00060     r = QRect(m_start, m_end).normalize();
00061 
00062     painter.drawRect(r);
00063     painter.end();
00064 }
00065 
00066 void KisPartLayerHandler::gotButtonPressEvent(KisButtonPressEvent* event) {
00067     m_start = event->pos().roundQPoint();
00068     m_end = m_start;
00069     m_started = true;
00070 }
00071 
00072 void KisPartLayerHandler::gotButtonReleaseEvent(KisButtonReleaseEvent* event) {
00073     if (!m_started) {
00074         done();
00075         return;
00076     }
00077 
00078     m_end = event->pos().roundQPoint();
00079 
00080     QRect r(m_start, m_end);
00081 
00082     m_view->insertPart(r.normalize(), m_entry, m_parent, m_above);
00083     // We will get deleted by the view through the above
00084 }
00085 
00086 void KisPartLayerHandler::gotKeyPressEvent(QKeyEvent* event) {
00087     if (event->key() == Key_Escape) {
00088         done();
00089     } else {
00090         emit sigGotKeyPressEvent(event);
00091     }
00092 }
00093 
00094 #include "kis_part_layer_handler.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys