krita

kis_tool_dummy.cc

00001 /*
00002  *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
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 <qwidget.h>
00020 #include <qstring.h>
00021 #include <kaction.h>
00022 #include <qlabel.h>
00023 
00024 #include <kaction.h>
00025 #include <klocale.h>
00026 
00027 #include "kis_canvas_controller.h"
00028 #include "kis_canvas_subject.h"
00029 #include "kis_cursor.h"
00030 #include "kis_tool_dummy.h"
00031 #include "kis_button_press_event.h"
00032 #include "kis_button_release_event.h"
00033 #include "kis_move_event.h"
00034 
00035 KisToolDummy::KisToolDummy()
00036     : super(i18n("No Active Tool"))
00037 {
00038     setName("tool_dummy");
00039     m_subject = 0;
00040     m_dragging = false;
00041     m_optionWidget = 0;
00042     setCursor(QCursor::forbiddenCursor);
00043 }
00044 
00045 KisToolDummy::~KisToolDummy()
00046 {
00047 }
00048 
00049 void KisToolDummy::update(KisCanvasSubject *subject)
00050 {
00051     m_subject = subject;
00052     super::update(m_subject);
00053 }
00054 
00055 void KisToolDummy::buttonPress(KisButtonPressEvent *e)
00056 {
00057     if (m_subject && !m_dragging && e->button() == Qt::LeftButton) {
00058         KisCanvasController *controller = m_subject->canvasController();
00059 
00060         m_origScrollX = controller->horzValue();
00061         m_origScrollY = controller->vertValue();
00062         m_dragPos = controller->windowToView(e->pos());
00063         m_dragging = true;
00064     }
00065 }
00066 
00067 void KisToolDummy::move(KisMoveEvent *e)
00068 {
00069     if (m_subject && m_dragging) {
00070         KisCanvasController *controller = m_subject->canvasController();
00071 
00072         KisPoint currPos = controller->windowToView(e->pos());
00073         KisPoint delta = currPos - m_dragPos;
00074         controller->scrollTo(m_origScrollX - delta.floorX(), m_origScrollY - delta.floorY());
00075     }
00076 }
00077 
00078 void KisToolDummy::buttonRelease(KisButtonReleaseEvent *e)
00079 {
00080     if (m_subject && m_dragging && e->button() == Qt::LeftButton) {
00081         m_dragging = false;
00082     }
00083 }
00084 
00085 void KisToolDummy::setup(KActionCollection *collection)
00086 {
00087     m_action = static_cast<KRadioAction *>(collection->action(name()));
00088 
00089     if (m_action == 0) {
00090         m_action = new KRadioAction(i18n("&Dummy"), "tool_dummy", Qt::SHIFT+Qt::Key_H, this, SLOT(activate()), collection, name());
00091         m_action->setExclusiveGroup("tools");
00092         m_ownAction = true;
00093     }
00094 }
00095 
00096 
00097 QWidget* KisToolDummy::createOptionWidget(QWidget* parent)
00098 {
00099     m_optionWidget = new QLabel(i18n("Layer is locked or invisible."), parent);
00100     m_optionWidget->setCaption(i18n("No Active Tool"));
00101     m_optionWidget->setAlignment(Qt::AlignCenter);
00102     return m_optionWidget;
00103 }
00104 
00105 QWidget* KisToolDummy::optionWidget()
00106 {
00107     return m_optionWidget;
00108 }
00109 
00110 
00111 #include "kis_tool_dummy.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys