karbon

vstrokecmd.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, The Karbon Developers
3 Copyright (C) 2002, The Karbon Developers
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tdelocale.h>
22
23#include "vselection.h"
24#include "vstroke.h"
25#include "vgradient.h"
26#include "vstrokecmd.h"
27#include "vdocument.h"
28
29VStrokeCmd::VStrokeCmd( VDocument *doc, const VStroke *stroke, const TQString& icon )
30 : VCommand( doc, i18n( "Stroke Objects" ), icon ), m_stroke( *stroke )
31{
32 m_selection = document()->selection()->clone();
33 m_state = Stroke;
34
35 if( m_selection->objects().count() == 1 )
36 setName( i18n( "Stroke Object" ) );
37}
38
39VStrokeCmd::VStrokeCmd( VDocument *doc, VGradient *gradient )
40 : VCommand( doc, i18n( "Stroke Objects" ), "14_gradient" )
41{
42 m_selection = document()->selection()->clone();
43 m_state = Gradient;
44 m_stroke.gradient() = *gradient;
45
46 if( m_selection->objects().count() == 1 )
47 setName( i18n( "Stroke Object" ) );
48}
49
50VStrokeCmd::VStrokeCmd( VDocument *doc, VPattern *pattern )
51 : VCommand( doc, i18n( "Stroke Objects" ), "14_pattern" )
52{
53 m_selection = document()->selection()->clone();
54 m_state = Pattern;
55 m_stroke.pattern() = *pattern;
56
57 if( m_selection->objects().count() == 1 )
58 setName( i18n( "Stroke Object" ) );
59}
60
61VStrokeCmd::VStrokeCmd( VDocument *doc, double width )
62 : VCommand( doc, i18n( "Stroke Width" ), "linewidth" )
63{
64 m_selection = document()->selection()->clone();
65 m_state = LineWidth;
66 m_stroke.setLineWidth( width );
67}
68
69VStrokeCmd::VStrokeCmd( VDocument *doc, const VColor &color )
70 : VCommand( doc, i18n( "Stroke Color" ), "linewidth" )
71{
72 m_selection = document()->selection()->clone();
73 m_state = Color;
74 m_stroke.setColor( color );
75}
76
77VStrokeCmd::VStrokeCmd( VDocument *doc, const TQValueList<float>& array )
78 : VCommand( doc, i18n( "Dash Pattern" ), "linewidth" )
79{
80 m_selection = document()->selection()->clone();
81 m_state = Dash;
82 m_stroke.dashPattern().setArray( array );
83}
84
85VStrokeCmd::~VStrokeCmd()
86{
87 delete( m_selection );
88}
89
90void
91VStrokeCmd::changeStroke( const VColor &color )
92{
93 m_state = Color;
94 m_stroke.setColor( color );
95
96 VObjectListIterator itr( m_selection->objects() );
97 for ( ; itr.current() ; ++itr )
98 {
99 //if( m_opacity == -1 )
100 // m_color.setOpacity( itr.current()->stroke()->color().opacity() );
101
102 m_oldstrokes.push_back( *itr.current()->stroke() );
103
104 VStroke stroke( *itr.current()->stroke() );
105 stroke.setParent( itr.current() );
106
107 stroke.setColor( m_stroke.color() );
108 stroke.setType( VStroke::solid );
109
110 itr.current()->setStroke( stroke );
111 }
112
113 setSuccess( true );
114}
115
116void
118{
119 VObjectListIterator itr( m_selection->objects() );
120 for ( ; itr.current() ; ++itr )
121 {
122 //if( m_opacity == -1 )
123 // m_color.setOpacity( itr.current()->stroke()->color().opacity() );
124
125 m_oldstrokes.push_back( *itr.current()->stroke() );
126
127 VStroke stroke( *itr.current()->stroke() );
128 stroke.setParent( itr.current() );
129 if( m_state == LineWidth )
130 stroke.setLineWidth( m_stroke.lineWidth() );
131 else if( m_state == Color )
132 {
133 stroke.setColor( m_stroke.color() );
134 stroke.setType( VStroke::solid );
135 }
136 else if( m_state == Gradient )
137 {
138 stroke.gradient() = m_stroke.gradient();
139 stroke.setType( VStroke::grad );
140 }
141 else if( m_state == Pattern )
142 {
143 stroke.pattern() = m_stroke.pattern();
144 stroke.setType( VStroke::patt );
145 }
146 else if( m_state == Stroke )
147 {
148 stroke.setLineCap( m_stroke.lineCap() );
149 stroke.setLineJoin( m_stroke.lineJoin() );
150 stroke.setLineWidth( m_stroke.lineWidth() );
151 if( m_stroke.type() == VStroke::none )
152 {
153 stroke.setType( VStroke::none );
154 }
155 else if( m_stroke.type() == VStroke::solid )
156 {
157 stroke.setColor( m_stroke.color() );
158 stroke.setType( VStroke::solid );
159 }
160 else if( m_stroke.type() == VStroke::grad )
161 {
162 stroke.gradient() = m_stroke.gradient();
163 stroke.setType( VStroke::grad );
164 }
165 else if( m_stroke.type() == VStroke::patt )
166 {
167 stroke.pattern() = m_stroke.pattern();
168 stroke.setType( VStroke::patt );
169 }
170 }
171 else if( m_state == Dash )
172 {
173 stroke.dashPattern() = m_stroke.dashPattern();
174 }
175 itr.current()->setStroke( stroke );
176 }
177
178 setSuccess( true );
179}
180
181void
183{
184 VObjectListIterator itr( m_selection->objects() );
185 int i = 0;
186 for ( ; itr.current() ; ++itr )
187 {
188 itr.current()->setStroke( m_oldstrokes[ i++ ] );
189 }
190
191 setSuccess( false );
192}
193
This class keeps track of color properties.
Definition vcolor.h:41
The base class for all karbon commands.
Definition vcommand.h:42
virtual void unexecute()
Unexecutes the command.
Definition vcommand.h:75
virtual void execute()=0
Executes the command.
All non-visual, static doc info is in here.
Definition vdocument.h:53
Manages stroke properties.
Definition vstroke.h:49
@ patt
gradient as stroke
Definition vstroke.h:56
@ grad
solid stroke
Definition vstroke.h:55
@ solid
no stroke at all
Definition vstroke.h:54
void setSuccess(bool success=true)
Set the success property.
Definition vvisitor.h:142