karbon

vsheartool.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 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#include <math.h>
21
22#include <tqcursor.h>
23#include <tqlabel.h>
24
25#include <tdelocale.h>
26#include <KoRect.h>
27
28#include <karbon_part.h>
29#include <karbon_view.h>
30#include <render/vpainter.h>
31#include <render/vpainterfactory.h>
32#include <vselection.h>
33#include "vsheartool.h"
34#include <commands/vtransformcmd.h>
35
36VShearTool::VShearTool( KarbonView *view ) : VTool( view, "sheartool" )
37{
38 setName( "tool_shear" );
39 m_objects.setAutoDelete( true );
40 registerTool( this );
41}
42
43VShearTool::~VShearTool()
44{
45}
46
47void
48VShearTool::activate()
49{
50 view()->setCursor( TQCursor( TQt::arrowCursor ) );
51 view()->part()->document().selection()->showHandle( true );
52 view()->part()->document().selection()->setState( VObject::selected );
54}
55
56TQString
57VShearTool::statusText()
58{
59 return i18n( "Shear" );
60}
61
62void
64{
65 VPainter* painter = view()->painterFactory()->editpainter();
66 painter->setRasterOp( TQt::NotROP );
67
68 VObjectListIterator itr = m_objects;
69 for( ; itr.current(); ++itr )
70 itr.current()->draw( painter, &itr.current()->boundingBox() );
71}
72
73void
74VShearTool::setCursor() const
75{
76 if( isDragging() ) return;
77 switch( view()->part()->document().selection()->handleNode( last() ) )
78 {
79 case node_lt:
80 case node_rb:
81 view()->setCursor( TQCursor( TQt::SizeFDiagCursor ) );
82 break;
83 case node_rt:
84 case node_lb:
85 view()->setCursor( TQCursor( TQt::SizeBDiagCursor ) );
86 break;
87 case node_lm:
88 case node_rm:
89 view()->setCursor( TQCursor( TQt::SizeHorCursor ) );
90 break;
91 case node_mt:
92 case node_mb:
93 view()->setCursor( TQCursor( TQt::SizeVerCursor ) );
94 break;
95 default:
96 view()->setCursor( TQCursor( TQt::arrowCursor ) );
97 }
98}
99
100void
101VShearTool::mouseButtonPress()
102{
103 view()->painterFactory()->painter()->end();
104 m_activeNode = view()->part()->document().selection()->handleNode( first() );
105 recalc();
106
107 // Draw new object:
108 draw();
109}
110
111void
112VShearTool::mouseDrag( )
113{
114 // Erase old object:
115 draw();
116
117 recalc();
118
119 // Draw new object:
120 draw();
121}
122
123
124void
125VShearTool::mouseDragRelease()
126{
127 view()->part()->addCommand(
128 new VShearCmd( &view()->part()->document(), m_center, m_s1, m_s2, altPressed() ),
129 true );
130}
131
132void
133VShearTool::cancel()
134{
135 // Erase old object:
136 if ( isDragging() )
137 {
138 draw();
139 view()->repaintAll( view()->part()->document().selection()->boundingBox() );
140 }
141}
142
143void
144VShearTool::recalc()
145{
146 KoRect rect = view()->part()->document().selection()->boundingBox();
147
148 if( m_activeNode == node_lt )
149 {
150 }
151 else if( m_activeNode == node_mt )
152 {
153 m_s1 = 0;
154 m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) );
155 }
156 else if( m_activeNode == node_rt )
157 {
158 }
159 else if( m_activeNode == node_rm)
160 {
161 m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) );
162 m_s2 = 0;
163 }
164 else if( m_activeNode == node_rb )
165 {
166 }
167 else if( m_activeNode == node_mb )
168 {
169 m_s1 = 0;
170 m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) );
171 }
172 else if( m_activeNode == node_lb )
173 {
174 }
175 else if( m_activeNode == node_lm )
176 {
177 m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) );
178 m_s2 = 0;
179 }
180
181 // Get center:
182 m_center = view()->part()->document().selection()->boundingBox().center();
183
184 VShearCmd cmd( 0L, m_center, m_s1, m_s2 );
185
186 // Copy selected objects and transform:
187 m_objects.clear();
188 VObject* copy;
189
190 VObjectListIterator itr = view()->part()->document().selection()->objects();
191 for ( ; itr.current() ; ++itr )
192 {
193 if( itr.current()->state() != VObject::deleted )
194 {
195 copy = itr.current()->clone();
196
197 cmd.visit( *copy );
198
199 copy->setState( VObject::edit );
200
201 m_objects.append( copy );
202 }
203 }
204}
205
206void
207VShearTool::setup( TDEActionCollection *collection )
208{
209 m_action = static_cast<TDERadioAction *>(collection -> action( name() ) );
210
211 if( m_action == 0 )
212 {
213 m_action = new TDERadioAction( i18n( "Shear Tool" ), "14_shear", TQt::SHIFT+TQt::Key_H, this, TQ_SLOT( activate() ), collection, name() );
214 m_action->setToolTip( i18n( "Shear" ) );
215 m_action->setExclusiveGroup( "manipulation" );
216 //m_ownAction = true;
217 }
218}
219
VSelection * selection() const
Returns a pointer to the selection.
Definition vdocument.h:238
The base class for all karbon objects.
Definition vobject.h:50
virtual VObject * clone() const =0
Create an exact copy of this object.
virtual void setState(const VState state)
Sets the state to a specified new state.
Definition vobject.h:163
@ selected
visible, active and can be manipulated by tools
Definition vobject.h:61
@ deleted
deleted, nearly dead
Definition vobject.h:58
@ edit
visible, active and is currently manipulated by a tool
Definition vobject.h:62
VDocument * document() const
Return document the object belongs to.
Definition vobject.cpp:216
const VObjectList & objects() const
Read only access to the selected objects.
Definition vselection.h:136
The base class for all karbon tools.
Definition vtool.h:52
virtual void draw(VPainter *painter)
Draws the actual tool state.
Definition vtool.h:158
virtual void activate()
Called during the tool activation.
Definition vtool.cpp:252