KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
5.0KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2001, The Karbon Developers
  3. Copyright (C) 2002, The Karbon Developers
  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. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. * Boston, MA 02110-1301, USA.
  16. */
  17. #include <tdelocale.h>
  18. #include "vselection.h"
  19. #include "vstroke.h"
  20. #include "vgradient.h"
  21. #include "vstrokecmd.h"
  22. #include "vdocument.h"
  23. VStrokeCmd::VStrokeCmd( VDocument *doc, const VStroke *stroke, const TQString& icon )
  24. : VCommand( doc, i18n( "Stroke Objects" ), icon ), m_stroke( *stroke )
  25. {
  26. m_selection = document()->selection()->clone();
  27. m_state = Stroke;
  28. if( m_selection->objects().count() == 1 )
  29. setName( i18n( "Stroke Object" ) );
  30. }
  31. VStrokeCmd::VStrokeCmd( VDocument *doc, VGradient *gradient )
  32. : VCommand( doc, i18n( "Stroke Objects" ), "14_gradient" )
  33. {
  34. m_selection = document()->selection()->clone();
  35. m_state = Gradient;
  36. m_stroke.gradient() = *gradient;
  37. if( m_selection->objects().count() == 1 )
  38. setName( i18n( "Stroke Object" ) );
  39. }
  40. VStrokeCmd::VStrokeCmd( VDocument *doc, VPattern *pattern )
  41. : VCommand( doc, i18n( "Stroke Objects" ), "14_pattern" )
  42. {
  43. m_selection = document()->selection()->clone();
  44. m_state = Pattern;
  45. m_stroke.pattern() = *pattern;
  46. if( m_selection->objects().count() == 1 )
  47. setName( i18n( "Stroke Object" ) );
  48. }
  49. VStrokeCmd::VStrokeCmd( VDocument *doc, double width )
  50. : VCommand( doc, i18n( "Stroke Width" ), "linewidth" )
  51. {
  52. m_selection = document()->selection()->clone();
  53. m_state = LineWidth;
  54. m_stroke.setLineWidth( width );
  55. }
  56. VStrokeCmd::VStrokeCmd( VDocument *doc, const VColor &color )
  57. : VCommand( doc, i18n( "Stroke Color" ), "linewidth" )
  58. {
  59. m_selection = document()->selection()->clone();
  60. m_state = Color;
  61. m_stroke.setColor( color );
  62. }
  63. VStrokeCmd::VStrokeCmd( VDocument *doc, const TQValueList<float>& array )
  64. : VCommand( doc, i18n( "Dash Pattern" ), "linewidth" )
  65. {
  66. m_selection = document()->selection()->clone();
  67. m_state = Dash;
  68. m_stroke.dashPattern().setArray( array );
  69. }
  70. VStrokeCmd::~VStrokeCmd()
  71. {
  72. delete( m_selection );
  73. }
  74. void
  75. VStrokeCmd::changeStroke( const VColor &color )
  76. {
  77. m_state = Color;
  78. m_stroke.setColor( color );
  79. VObjectListIterator itr( m_selection->objects() );
  80. for ( ; itr.current() ; ++itr )
  81. {
  82. //if( m_opacity == -1 )
  83. // m_color.setOpacity( itr.current()->stroke()->color().opacity() );
  84. m_oldstrokes.push_back( *itr.current()->stroke() );
  85. VStroke stroke( *itr.current()->stroke() );
  86. stroke.setParent( itr.current() );
  87. stroke.setColor( m_stroke.color() );
  88. stroke.setType( VStroke::solid );
  89. itr.current()->setStroke( stroke );
  90. }
  91. setSuccess( true );
  92. }
  93. void
  94. VStrokeCmd::execute()
  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. m_oldstrokes.push_back( *itr.current()->stroke() );
  102. VStroke stroke( *itr.current()->stroke() );
  103. stroke.setParent( itr.current() );
  104. if( m_state == LineWidth )
  105. stroke.setLineWidth( m_stroke.lineWidth() );
  106. else if( m_state == Color )
  107. {
  108. stroke.setColor( m_stroke.color() );
  109. stroke.setType( VStroke::solid );
  110. }
  111. else if( m_state == Gradient )
  112. {
  113. stroke.gradient() = m_stroke.gradient();
  114. stroke.setType( VStroke::grad );
  115. }
  116. else if( m_state == Pattern )
  117. {
  118. stroke.pattern() = m_stroke.pattern();
  119. stroke.setType( VStroke::patt );
  120. }
  121. else if( m_state == Stroke )
  122. {
  123. stroke.setLineCap( m_stroke.lineCap() );
  124. stroke.setLineJoin( m_stroke.lineJoin() );
  125. stroke.setLineWidth( m_stroke.lineWidth() );
  126. if( m_stroke.type() == VStroke::none )
  127. {
  128. stroke.setType( VStroke::none );
  129. }
  130. else if( m_stroke.type() == VStroke::solid )
  131. {
  132. stroke.setColor( m_stroke.color() );
  133. stroke.setType( VStroke::solid );
  134. }
  135. else if( m_stroke.type() == VStroke::grad )
  136. {
  137. stroke.gradient() = m_stroke.gradient();
  138. stroke.setType( VStroke::grad );
  139. }
  140. else if( m_stroke.type() == VStroke::patt )
  141. {
  142. stroke.pattern() = m_stroke.pattern();
  143. stroke.setType( VStroke::patt );
  144. }
  145. }
  146. else if( m_state == Dash )
  147. {
  148. stroke.dashPattern() = m_stroke.dashPattern();
  149. }
  150. itr.current()->setStroke( stroke );
  151. }
  152. setSuccess( true );
  153. }
  154. void
  155. VStrokeCmd::unexecute()
  156. {
  157. VObjectListIterator itr( m_selection->objects() );
  158. int i = 0;
  159. for ( ; itr.current() ; ++itr )
  160. {
  161. itr.current()->setStroke( m_oldstrokes[ i++ ] );
  162. }
  163. setSuccess( false );
  164. }