karbon
vstrokecmd.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <klocale.h>
00022
00023 #include "vselection.h"
00024 #include "vstroke.h"
00025 #include "vgradient.h"
00026 #include "vstrokecmd.h"
00027 #include "vdocument.h"
00028
00029 VStrokeCmd::VStrokeCmd( VDocument *doc, const VStroke *stroke, const QString& icon )
00030 : VCommand( doc, i18n( "Stroke Objects" ), icon ), m_stroke( *stroke )
00031 {
00032 m_selection = document()->selection()->clone();
00033 m_state = Stroke;
00034
00035 if( m_selection->objects().count() == 1 )
00036 setName( i18n( "Stroke Object" ) );
00037 }
00038
00039 VStrokeCmd::VStrokeCmd( VDocument *doc, VGradient *gradient )
00040 : VCommand( doc, i18n( "Stroke Objects" ), "14_gradient" )
00041 {
00042 m_selection = document()->selection()->clone();
00043 m_state = Gradient;
00044 m_stroke.gradient() = *gradient;
00045
00046 if( m_selection->objects().count() == 1 )
00047 setName( i18n( "Stroke Object" ) );
00048 }
00049
00050 VStrokeCmd::VStrokeCmd( VDocument *doc, VPattern *pattern )
00051 : VCommand( doc, i18n( "Stroke Objects" ), "14_pattern" )
00052 {
00053 m_selection = document()->selection()->clone();
00054 m_state = Pattern;
00055 m_stroke.pattern() = *pattern;
00056
00057 if( m_selection->objects().count() == 1 )
00058 setName( i18n( "Stroke Object" ) );
00059 }
00060
00061 VStrokeCmd::VStrokeCmd( VDocument *doc, double width )
00062 : VCommand( doc, i18n( "Stroke Width" ), "linewidth" )
00063 {
00064 m_selection = document()->selection()->clone();
00065 m_state = LineWidth;
00066 m_stroke.setLineWidth( width );
00067 }
00068
00069 VStrokeCmd::VStrokeCmd( VDocument *doc, const VColor &color )
00070 : VCommand( doc, i18n( "Stroke Color" ), "linewidth" )
00071 {
00072 m_selection = document()->selection()->clone();
00073 m_state = Color;
00074 m_stroke.setColor( color );
00075 }
00076
00077 VStrokeCmd::VStrokeCmd( VDocument *doc, const QValueList<float>& array )
00078 : VCommand( doc, i18n( "Dash Pattern" ), "linewidth" )
00079 {
00080 m_selection = document()->selection()->clone();
00081 m_state = Dash;
00082 m_stroke.dashPattern().setArray( array );
00083 }
00084
00085 VStrokeCmd::~VStrokeCmd()
00086 {
00087 delete( m_selection );
00088 }
00089
00090 void
00091 VStrokeCmd::changeStroke( const VColor &color )
00092 {
00093 m_state = Color;
00094 m_stroke.setColor( color );
00095
00096 VObjectListIterator itr( m_selection->objects() );
00097 for ( ; itr.current() ; ++itr )
00098 {
00099
00100
00101
00102 m_oldstrokes.push_back( *itr.current()->stroke() );
00103
00104 VStroke stroke( *itr.current()->stroke() );
00105 stroke.setParent( itr.current() );
00106
00107 stroke.setColor( m_stroke.color() );
00108 stroke.setType( VStroke::solid );
00109
00110 itr.current()->setStroke( stroke );
00111 }
00112
00113 setSuccess( true );
00114 }
00115
00116 void
00117 VStrokeCmd::execute()
00118 {
00119 VObjectListIterator itr( m_selection->objects() );
00120 for ( ; itr.current() ; ++itr )
00121 {
00122
00123
00124
00125 m_oldstrokes.push_back( *itr.current()->stroke() );
00126
00127 VStroke stroke( *itr.current()->stroke() );
00128 stroke.setParent( itr.current() );
00129 if( m_state == LineWidth )
00130 stroke.setLineWidth( m_stroke.lineWidth() );
00131 else if( m_state == Color )
00132 {
00133 stroke.setColor( m_stroke.color() );
00134 stroke.setType( VStroke::solid );
00135 }
00136 else if( m_state == Gradient )
00137 {
00138 stroke.gradient() = m_stroke.gradient();
00139 stroke.setType( VStroke::grad );
00140 }
00141 else if( m_state == Pattern )
00142 {
00143 stroke.pattern() = m_stroke.pattern();
00144 stroke.setType( VStroke::patt );
00145 }
00146 else if( m_state == Stroke )
00147 {
00148 stroke.setLineCap( m_stroke.lineCap() );
00149 stroke.setLineJoin( m_stroke.lineJoin() );
00150 stroke.setLineWidth( m_stroke.lineWidth() );
00151 if( m_stroke.type() == VStroke::none )
00152 {
00153 stroke.setType( VStroke::none );
00154 }
00155 else if( m_stroke.type() == VStroke::solid )
00156 {
00157 stroke.setColor( m_stroke.color() );
00158 stroke.setType( VStroke::solid );
00159 }
00160 else if( m_stroke.type() == VStroke::grad )
00161 {
00162 stroke.gradient() = m_stroke.gradient();
00163 stroke.setType( VStroke::grad );
00164 }
00165 else if( m_stroke.type() == VStroke::patt )
00166 {
00167 stroke.pattern() = m_stroke.pattern();
00168 stroke.setType( VStroke::patt );
00169 }
00170 }
00171 else if( m_state == Dash )
00172 {
00173 stroke.dashPattern() = m_stroke.dashPattern();
00174 }
00175 itr.current()->setStroke( stroke );
00176 }
00177
00178 setSuccess( true );
00179 }
00180
00181 void
00182 VStrokeCmd::unexecute()
00183 {
00184 VObjectListIterator itr( m_selection->objects() );
00185 int i = 0;
00186 for ( ; itr.current() ; ++itr )
00187 {
00188 itr.current()->setStroke( m_oldstrokes[ i++ ] );
00189 }
00190
00191 setSuccess( false );
00192 }
00193
|