karbon

vzoomtool.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002, The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library 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 GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18
19*/
20
21#include <tqcursor.h>
22#include <tqevent.h>
23
24#include <tdelocale.h>
25
26#include "vzoomtool.h"
27#include <karbon_part.h>
28#include <karbon_part.h>
29#include <karbon_view.h>
30#include <karbon_view.h>
31#include <render/vpainter.h>
32#include <render/vpainterfactory.h>
33#include <core/vcursor.h>
34
35VZoomTool::VZoomTool(KarbonView *view ): VTool( view, "tool_zoom_plugin" )
36{
37 m_plusCursor = new TQCursor( VCursor::createCursor( VCursor::ZoomPlus ) );
38
39 registerTool( this );
40}
41
42VZoomTool::~VZoomTool()
43{
44 delete m_plusCursor;
45}
46
47TQString
49{
50 TQString s = i18n( "<qt><b>Zoom tool:</b><br>" );
51 s += i18n( "<i>Click and drag</i> to zoom into a rectangular area.<br>" );
52 s += i18n( "<i>Right click</i> to zoom out of canvas.<br>" );
53 s += i18n( "<i>Pressing +/- keys</i><br>to zoom into/out of canvas." );
54 return s;
55}
56
57void
59{
61 view()->setCursor( *m_plusCursor );
62}
63
64TQString
66{
67 return i18n( "Zoom Tool" );
68}
69
70void
72{
73}
74
75void
76VZoomTool::draw()
77{
78 VPainter *painter = view()->painterFactory()->editpainter();
79 painter->setRasterOp( TQt::NotROP );
80
81 if( isDragging() )
82 {
83 painter->setPen( TQt::DotLine );
84 painter->newPath();
85 painter->moveTo( KoPoint( first().x(), first().y() ) );
86 painter->lineTo( KoPoint( m_current.x(), first().y() ) );
87 painter->lineTo( KoPoint( m_current.x(), m_current.y() ) );
88 painter->lineTo( KoPoint( first().x(), m_current.y() ) );
89 painter->lineTo( KoPoint( first().x(), first().y() ) );
90 painter->strokePath();
91 }
92}
93
94void
96{
97 m_current = first();
98
99 recalc();
100
101 draw();
102}
103
104void
106{
107 view()->setZoomAt( view()->zoom() * 0.75, last() );
108}
109
110void
112{
113 view()->setZoomAt( view()->zoom() * 1.5, last() );
114}
115
116void
118{
119 draw();
120
121 recalc();
122
123 draw();
124}
125
126void
128{
129 KoRect rect( first().x(), first().y(), last().x() - first().x(), last().y() - first().y() );
130 rect = rect.normalize();
131 view()->setViewportRect( rect );
132}
133
134bool
135VZoomTool::keyReleased( TQt::Key key )
136{
137 double zoomChange = 0;
138 if( key == TQt::Key_Minus )
139 zoomChange = 0.75;
140 else if( key == TQt::Key_Plus )
141 zoomChange = 1.50;
142
143 if( zoomChange != 0 )
144 {
145 view()->setZoomAt( view()->zoom() * zoomChange );
146 return true;
147 }
148 return false;
149}
150
151void
152VZoomTool::recalc()
153{
154 m_current = last();
155}
156
157void
158VZoomTool::setup( TDEActionCollection *collection )
159{
160 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
161
162 if( m_action == 0 )
163 {
164 m_action = new TDERadioAction( i18n( "Zoom Tool" ), "14_zoom", TQt::SHIFT+TQt::Key_H, this, TQ_SLOT( activate() ), collection, name() );
165 m_action->setToolTip( i18n( "Zoom" ) );
166 m_action->setExclusiveGroup( "misc" );
167 //m_ownAction = true;
168 }
169}
170
@ ZoomPlus
zoom in cursor
Definition vcursor.h:39
static TQCursor createCursor(CursorType type)
Creates a predefined cursor of the specified type.
Definition vcursor.cpp:75
The base class for all karbon tools.
Definition vtool.h:52
virtual void mouseDragRelease()
Mouse button release.
Definition vtool.h:220
virtual void mouseButtonPress()
Left mouse button press.
Definition vtool.h:185
const KoPoint & last() const
The last mouse coordinate.
Definition vtool.h:285
const KoPoint & first() const
Most tools need to know the first mouse coordinate.
Definition vtool.h:280
virtual void rightMouseButtonRelease()
Right mouse button release.
Definition vtool.h:200
virtual void mouseButtonRelease()
Left mouse button release.
Definition vtool.h:195
TDERadioAction * action() const
Returns the tool's associated action object.
Definition vtool.h:151
virtual TQString statusText()
The tool status text.
Definition vtool.h:108
virtual void deactivate()
Deactivates the tool.
Definition vtool.h:83
virtual void activate()
Called during the tool activation.
Definition vtool.cpp:252
TDERadioAction * m_action
The tool's action object.
Definition vtool.h:309
bool isDragging() const
Returns the current dagging state.
Definition vtool.h:173
virtual TQString contextHelp()
The context help of the tool.
Definition vtool.h:98
virtual void mouseDrag()
Mouse drag.
Definition vtool.h:215
KarbonView * view() const
Returns the connected karbon part.
Definition vtool.cpp:66