29#include <karbon_part.h>
30#include <karbon_view.h>
32#include <render/vpainter.h>
33#include <render/vpainterfactory.h>
34#include <visitors/vselectnodes.h>
35#include <commands/vtransformcmd.h>
36#include <visitors/vdrawselection.h>
37#include <core/vselection.h>
38#include <core/vcursor.h>
39#include "vselectnodestool.h"
40#include <vtransformnodes.h>
41#include <commands/vdeletenodescmd.h>
42#include <widgets/vcanvas.h>
46VSelectNodesTool::VSelectNodesTool( KarbonView* view )
47 :
VTool( view,
"tool_select_nodes" ), m_state( normal ), m_select( true )
52VSelectNodesTool::~VSelectNodesTool()
57VSelectNodesTool::activate()
62 view()->part()->document().selection()->showHandle(
false );
63 view()->part()->document().selection()->setSelectObjects(
false );
65 view()->part()->document().selection()->selectNodes(
false );
66 view()->repaintAll( view()->part()->document().selection()->boundingBox() );
72VSelectNodesTool::statusText()
74 if( m_state == normal )
75 return i18n(
"Editing Nodes" );
77 return TQString(
"" );
83 VPainter *painter = view()->painterFactory()->editpainter();
84 painter->setZoomFactor( view()->zoom() );
85 painter->setRasterOp( TQt::NotROP );
87 if( m_state == dragging )
89 painter->setPen( TQt::DotLine );
91 painter->moveTo( KoPoint( m_first.x(), m_first.y() ) );
92 painter->lineTo( KoPoint( m_current.x(), m_first.y() ) );
93 painter->lineTo( KoPoint( m_current.x(), m_current.y() ) );
94 painter->lineTo( KoPoint( m_first.x(), m_current.y() ) );
95 painter->lineTo( KoPoint( m_first.x(), m_first.y() ) );
96 painter->strokePath();
100 VDrawSelection op( m_objects, painter,
true, VSelection::handleSize() );
101 VObjectListIterator itr = m_objects;
102 for( ; itr.current(); ++itr )
103 op.visit( *( itr.current() ) );
108VSelectNodesTool::setCursor()
const
110 if( m_state >= moving )
116 KoRect selrect = calcSelRect( last() );
118 TQPtrList<VSegment> segments = view()->part()->document().selection()->getSegments( selrect );
119 if( segments.count() > 0 )
122 for(
int i = 0; i < seg->
degree(); ++i )
134VSelectNodesTool::mouseButtonPress()
136 m_first = m_current = first();
143 view()->part()->document().selection()->setState(
VObject::edit );
144 view()->repaintAll( view()->part()->document().selection()->boundingBox() );
149 KoRect selrect = calcSelRect( m_current );
152 TQPtrList<VSegment> segments = selection->
getSegments( selrect );
153 if( segments.count() > 0 )
161 if( segments.count() == 1 && ! selrect.contains( seg->
knot() ) && ! seg->
knotIsSelected()
164 if( selrect.contains( seg->
point( 1 ) ) )
166 m_state = movingbezier1;
170 else if( selrect.contains( seg->
point( 0 ) ) )
172 m_state = movingbezier2;
179 for(
VSegment *seg = segments.first(); seg; seg = segments.
next() )
181 for(
int i = 0; i < seg->
degree(); ++i )
189 if( m_state == moving )
194 double minDist = -1.0;
196 for(
VSegment *seg = segments.first(); seg; seg = segments.
next() )
198 for(
int i = 0; i < seg->
degree(); ++i )
200 if( selrect.contains( seg->
point( i ) ) )
202 KoPoint vDist = seg->
point( i ) - m_current;
203 double dist = vDist.x()*vDist.x() + vDist.y()*vDist.y();
204 if( minDist < 0.0 || dist < minDist )
206 m_first = seg->
point( i );
221VSelectNodesTool::rightMouseButtonPress()
223 m_first = m_current = first();
230 view()->part()->document().selection()->setState(
VObject::edit );
231 view()->repaintAll( view()->part()->document().selection()->boundingBox() );
238VSelectNodesTool::keyReleased( TQt::Key key )
247 uint handleSize = selection->handleSize();
249 selection->setHandleSize( ++handleSize );
250 else if( handleSize > 1 )
251 selection->setHandleSize( --handleSize );
254 case TQt::Key_Delete:
255 if( selection->
objects().count() > 0 )
256 view()->part()->addCommand(
new VDeleteNodeCmd( &view()->part()->document() ),
true );
258 default:
return false;
268VSelectNodesTool::mouseButtonRelease()
275 KoRect selrect = calcSelRect( last() );
278 selection->
append( selrect.normalize(),
false,
false );
280 selection->
append( selrect.normalize(),
false,
true );
282 view()->selectionChanged();
283 view()->part()->repaintAllViews();
288VSelectNodesTool::rightMouseButtonRelease()
295 KoRect selrect = calcSelRect( last() );
297 selection->
take( selrect.normalize(),
false,
false );
299 view()->selectionChanged();
300 view()->part()->repaintAllViews();
305VSelectNodesTool::mouseDrag()
315VSelectNodesTool::mouseDragRelease()
317 if( m_state >= moving )
321 TQPtrList<VSegment> segments;
322 KoPoint _last = view()->canvasWidget()->snapToGrid( last() );
323 if( m_state == movingbezier1 || m_state == movingbezier2 )
325 KoRect selrect = calcSelRect( m_first );
326 segments = view()->part()->document().selection()->getSegments( selrect );
327 cmd =
new VTranslateBezierCmd( &view()->part()->document(), segments.at( 0 ),
328 tqRound( ( _last.x() - m_first.x() ) ),
329 tqRound( ( _last.y() - m_first.y() ) ),
330 m_state == movingbezier2 );
334 cmd =
new VTranslatePointCmd(
335 &view()->part()->document(),
336 tqRound( ( _last.x() - m_first.x() ) ),
337 tqRound( ( _last.y() - m_first.y() ) ) );
339 view()->part()->addCommand( cmd,
true );
344 KoPoint fp = m_first;
347 if ( (fabs(lp.x() - fp.x()) + fabs(lp.y()-fp.y())) < 3.0 )
350 fp = last() - KoPoint(8.0, 8.0);
351 lp = last() + KoPoint(8.0, 8.0);
359 view()->part()->document().selection()->append();
360 view()->part()->document().selection()->append(
361 KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(),
366 view()->part()->document().selection()->take(
367 KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(),
370 view()->selectionChanged();
371 view()->part()->repaintAllViews();
377VSelectNodesTool::cancel()
384 view()->repaintAll( view()->part()->document().selection()->boundingBox() );
389VSelectNodesTool::recalc()
391 if( m_state == dragging )
395 else if( m_state == moving || m_state == movingbezier1 || m_state == movingbezier2 )
397 KoPoint _last = view()->canvasWidget()->snapToGrid( last() );
398 double distx = _last.x() - m_first.x();
399 double disty = _last.y() - m_first.y();
402 mat.translate( distx, disty );
408 VTransformNodes op( mat );
410 VObjectListIterator itr = view()->part()->document().selection()->objects();
411 for ( ; itr.current() ; ++itr )
415 copy = itr.current()->
clone();
418 m_objects.append( copy );
425VSelectNodesTool::setup( TDEActionCollection *collection )
427 m_action =
static_cast<TDERadioAction *
>(collection -> action( name() ) );
431 m_action =
new TDERadioAction( i18n(
"Select Nodes Tool" ),
"14_selectnodes", TQt::SHIFT+TQt::Key_H,
this, TQ_SLOT( activate() ), collection, name() );
432 m_action->setToolTip( i18n(
"Select Nodes" ) );
433 m_action->setExclusiveGroup(
"select" );
439VSelectNodesTool::calcSelRect(
const KoPoint &pos )
const
441 double tolerance = view()->part()->document().selection()->handleSize() / view()->zoom();
442 return KoRect( pos.x() - tolerance, pos.y() - tolerance, 2 * tolerance + 1.0, 2 * tolerance + 1.0 );
The base class for all karbon commands.
static TQCursor needleMoveArrow()
needle arrow with four way arrow
static TQCursor needleArrow()
needle arraow cursor
VSelection * selection() const
Returns a pointer to the selection.
Helper class to draw the outline of a composite path, including (?) optionally its bezier helper line...
The base class for all karbon objects.
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.
@ selected
visible, active and can be manipulated by tools
@ deleted
deleted, nearly dead
@ edit
visible, active and is currently manipulated by a tool
VDocument * document() const
Return document the object belongs to.
A class representing lines and beziers.
bool pointIsSelected(int i) const
Returns true if the point with index 0 <= i < degree() is selected.
bool knotIsSelected() const
Returns true if the knot is selected.
VSegment * next() const
Returns a pointer to the next not deleted segment, if stored in a VSubpath.
void selectPoint(int i, bool select=true)
Selects the point with index 0 <= i < degree().
VSegment * prev() const
Returns a pointer to the previous not deleted segment, if stored in a VSubpath.
unsigned short degree() const
Returns the segment's degree, which is identical to the number of nodes.
const KoPoint & point(int i) const
Returns the segment's point with index 0 <= i < degree().
const KoPoint & knot() const
Returns the knot.
VSelection manages a set of selected vobjects.
const VObjectList & objects() const
Read only access to the selected objects.
void append()
Adds all objects to the selection.
TQPtrList< VSegment > getSegments(const KoRect &rect)
Returns a list of segments that have at least one control point inside the specified rect.
virtual const KoRect & boundingBox() const
Calculates the tightest bounding box around the object.
void take(VObject &object)
Removes the reference to the object, not the object itself.