chalk

kis_tool_dummy.cpp
1/*
2 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
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 <tqwidget.h>
20#include <tqstring.h>
21#include <tdeaction.h>
22#include <tqlabel.h>
23
24#include <tdeaction.h>
25#include <tdelocale.h>
26
27#include "kis_canvas_controller.h"
28#include "kis_canvas_subject.h"
29#include "kis_cursor.h"
30#include "kis_tool_dummy.h"
31#include "kis_button_press_event.h"
32#include "kis_button_release_event.h"
33#include "kis_move_event.h"
34
35KisToolDummy::KisToolDummy()
36 : super(i18n("No Active Tool"))
37{
38 setName("tool_dummy");
39 m_subject = 0;
40 m_dragging = false;
41 m_optionWidget = 0;
42 setCursor(TQCursor::forbiddenCursor);
43}
44
45KisToolDummy::~KisToolDummy()
46{
47}
48
50{
51 m_subject = subject;
52 super::update(m_subject);
53}
54
55void KisToolDummy::buttonPress(KisButtonPressEvent *e)
56{
57 if (m_subject && !m_dragging && e->button() == TQt::LeftButton) {
58 KisCanvasController *controller = m_subject->canvasController();
59
60 m_origScrollX = controller->horzValue();
61 m_origScrollY = controller->vertValue();
62 m_dragPos = controller->windowToView(e->pos());
63 m_dragging = true;
64 }
65}
66
67void KisToolDummy::move(KisMoveEvent *e)
68{
69 if (m_subject && m_dragging) {
70 KisCanvasController *controller = m_subject->canvasController();
71
72 KisPoint currPos = controller->windowToView(e->pos());
73 KisPoint delta = currPos - m_dragPos;
74 controller->scrollTo(m_origScrollX - delta.floorX(), m_origScrollY - delta.floorY());
75 }
76}
77
78void KisToolDummy::buttonRelease(KisButtonReleaseEvent *e)
79{
80 if (m_subject && m_dragging && e->button() == TQt::LeftButton) {
81 m_dragging = false;
82 }
83}
84
85void KisToolDummy::setup(TDEActionCollection *collection)
86{
87 m_action = static_cast<TDERadioAction *>(collection->action(name()));
88
89 if (m_action == 0) {
90 m_action = new TDERadioAction(i18n("&Dummy"), "tool_dummy", TQt::SHIFT+TQt::Key_H, this, TQ_SLOT(activate()), collection, name());
91 m_action->setExclusiveGroup("tools");
92 m_ownAction = true;
93 }
94}
95
96
97TQWidget* KisToolDummy::createOptionWidget(TQWidget* parent)
98{
99 m_optionWidget = new TQLabel(i18n("Layer is locked or invisible."), parent);
100 m_optionWidget->setCaption(i18n("No Active Tool"));
101 m_optionWidget->setAlignment(TQt::AlignCenter);
102 return m_optionWidget;
103}
104
105TQWidget* KisToolDummy::optionWidget()
106{
107 return m_optionWidget;
108}
109
110
111#include "kis_tool_dummy.moc"
Interface for classes that implement a canvas; i.e., a widget where KisImages are painted onto.
virtual TQ_INT32 vertValue() const =0
virtual TQPoint windowToView(const TQPoint &pt)=0
Conversion functions from image coordinates to view coordinates.
virtual void scrollTo(TQ_INT32 x, TQ_INT32 y)=0
Sets the horizontal and vertical scrollbars to the specified values.
virtual TQ_INT32 horzValue() const =0
KisCanvasSubject is part of the Observer pattern.
virtual KisCanvasController * canvasController() const =0
virtual void update(KisCanvasSubject *subject)
Implement this function to query the KisCanvasSubject implementation about state that may be interest...