vdrawselection.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 "vdrawselection.h"
22#include "vcomposite.h"
23#include "vsegment.h"
24#include "vcolor.h"
25#include "vstroke.h"
26#include "vpainter.h"
27#include "vpath.h"
28
29void
31{
32 if(
33 composite.state() == VObject::deleted ||
34 composite.state() == VObject::hidden ||
35 composite.state() == VObject::hidden_locked )
36 {
37 return;
38 }
39
40
41 m_painter->save();
42 m_painter->setPen( TQt::SolidLine );
43
44 const bool editnodes = composite.state() == VObject::edit && m_nodeediting;
45
46 VSubpathListIterator itr( composite.paths() );
47
48 if(
49 composite.state() == VObject::selected ||
50 editnodes )
51 {
52 // paint fill:
53 m_painter->newPath();
54
55 if( editnodes )
56 m_painter->setRasterOp( TQt::XorROP );
57
58 m_painter->setPen( editnodes ? TQt::yellow : TQt::blue );
59 m_painter->setBrush( TQt::NoBrush );
60
61 for( itr.toFirst(); itr.current(); ++itr )
62 {
63 VSubpathIterator jtr( *( itr.current() ) );
64
65 for( ; jtr.current(); ++jtr )
66 {
67 jtr.current()->draw( m_painter );
68 }
69
70 m_painter->strokePath();
71 }
72 }
73
74 // Draw nodes and control lines.
75 if(
76 composite.state() == VObject::selected ||
77 editnodes )
78 {
79 itr.toFirst();
80 //++itr; // Skip "begin".
81
82 for( ; itr.current(); ++itr )
83 {
84 if( (*itr)->isEmpty() )
85 continue;
86 VSubpathIterator jtr( *( itr.current() ) );
87 //++jtr;
88
89 for( ; jtr.current(); ++jtr )
90 {
91 if( editnodes )
92 m_painter->setRasterOp( TQt::XorROP );
93
94 VColor color;
95 color.set( 0.5, 0.5, 1.0 );
96
97 VStroke stroke( color );
98 stroke.setLineWidth( 1.0 );
99
100 if( !editnodes )
101 {
102 m_painter->setPen( stroke );
103 m_painter->setPen( TQt::blue );
104 }
105 else
106 m_painter->setPen( TQt::yellow );
107
108 m_painter->setBrush( TQt::NoBrush );
109
110 if( ( editnodes || composite.state() == VObject::selected && m_nodeediting ) &&
111 jtr.current()->isCurve() )
112 {
113 VSegment* curr = jtr.current();
114 VSegment* next = curr->next();
115 VSegment* prev = curr->prev();
116
117 // Draw control lines.
118 if ( curr->pointIsSelected( curr->degree()-2 ) || curr->knotIsSelected()
119 || ( next && next->isCurve() && next->pointIsSelected( 0 ) && curr->isSmooth() ) )
120 {
121 m_painter->newPath();
122 m_painter->moveTo( curr->point( curr->degree()-2 ) );
123 m_painter->lineTo( curr->knot() );
124 m_painter->strokePath();
125 // Draw control node2:
126 m_painter->newPath();
127 m_painter->setBrush( editnodes ? TQt::yellow : TQt::blue );
128 m_painter->drawNode( curr->point( curr->degree()-2 ), m_nodeSize );
129 m_painter->strokePath();
130 }
131
132 if ( prev && ( ( prev->knotIsSelected() || curr->pointIsSelected( 0 ) )
133 || ( prev->isCurve() && prev->pointIsSelected( prev->degree()-2 ) && prev->isSmooth() ) ) )
134 {
135 m_painter->newPath();
136 m_painter->moveTo( prev->knot() );
137 m_painter->lineTo( curr->point( 0 ) );
138 m_painter->strokePath();
139 // Draw control node1:
140 m_painter->newPath();
141 m_painter->setBrush( editnodes ? TQt::yellow : TQt::blue );
142 m_painter->drawNode( curr->point( 0 ), m_nodeSize );
143 m_painter->strokePath();
144 }
145 }
146
147 // Draw knot.
148 m_painter->setPen( editnodes ? TQt::yellow : TQt::blue );
149
150 if( !m_nodeediting )
151 m_painter->setBrush( TQt::blue );
152 else if( jtr.current()->knotIsSelected() )
153 m_painter->setBrush( editnodes ? TQt::yellow : TQt::blue );
154 else
155 m_painter->setBrush( TQt::white );
156
157 m_painter->drawNode( jtr.current()->knot(), m_nodeSize );
158 }
159 }
160 }
161
162 // Draw center node.
163 if( composite.drawCenterNode() && composite.state() == VObject::selected && !m_nodeediting )
164 {
165 m_painter->setPen( TQt::NoPen );
166 m_painter->setBrush( TQt::blue.light() );
167 m_painter->drawNode( composite.boundingBox().center(), m_nodeSize );
168 }
169
170 m_painter->restore();
171
172 setSuccess();
173}
174
This class keeps track of color properties.
Definition vcolor.h:41
void set(float v1)
Sets the first color component.
Definition vcolor.h:91
virtual void visitVPath(VPath &composite)
Visit method for a VPath.
@ hidden_locked
hidden and locked (r/o)
Definition vobject.h:57
@ 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
@ hidden
hidden
Definition vobject.h:56
VState state() const
Get the state the object is in.
Definition vobject.h:154
A composite path consists of one or many subpaths.
Definition vcomposite.h:48
virtual const KoRect & boundingBox() const
Calculates the tightest bounding box around the object.
A class representing lines and beziers.
Definition vsegment.h:43
bool pointIsSelected(int i) const
Returns true if the point with index 0 <= i < degree() is selected.
Definition vsegment.h:173
bool knotIsSelected() const
Returns true if the knot is selected.
Definition vsegment.h:181
VSegment * next() const
Returns a pointer to the next not deleted segment, if stored in a VSubpath.
bool isSmooth(const VSegment &next) const
Calculates wether the tangent at the knot is exactly parallel to the tangent at p0 of the next segmen...
Definition vsegment.cpp:700
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.
Definition vsegment.h:77
const KoPoint & point(int i) const
Returns the segment's point with index 0 <= i < degree().
Definition vsegment.h:115
const KoPoint & knot() const
Returns the knot.
Definition vsegment.h:135
Manages stroke properties.
Definition vstroke.h:49
VSubpathIterator provides an iterator class for highlevel path access.
Definition vpath.h:180
void setSuccess(bool success=true)
Set the success property.
Definition vvisitor.h:142