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.

563 lines
14KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2005 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef KSPREAD_MANIPULATOR
  17. #define KSPREAD_MANIPULATOR
  18. #include <tqrect.h>
  19. #include <tqstring.h>
  20. #include <tqvaluelist.h>
  21. #include <kcommand.h>
  22. #include <tdelocale.h>
  23. #include <koffice_export.h>
  24. #include "kspread_format.h"
  25. #include "kspread_undo.h"
  26. #include "region.h"
  27. namespace KSpread
  28. {
  29. class Cell;
  30. class ColumnFormat;
  31. class RowFormat;
  32. class Sheet;
  33. // struct layoutCell {
  34. // int row;
  35. // int col;
  36. // Format *l;
  37. // };
  38. //
  39. // struct layoutColumn {
  40. // int col;
  41. // ColumnFormat *l;
  42. // };
  43. //
  44. // struct layoutRow {
  45. // int row;
  46. // RowFormat *l;
  47. // };
  48. /**
  49. * Manipulator
  50. */
  51. class Manipulator : public Region, public KCommand
  52. {
  53. public:
  54. Manipulator();
  55. virtual ~Manipulator();
  56. Sheet* sheet() const { return m_sheet; }
  57. void setSheet(Sheet* sheet) { m_sheet = sheet; }
  58. bool creation() { return m_creation; }
  59. void setCreation(bool creation) { m_creation = creation; }
  60. /** Is this a formatting manipulator ? If so, execute will call
  61. process(Format*) for each complete row/column, instead of going
  62. cell-by-cell. True by default. */
  63. bool format() { return m_format; };
  64. void setFormat (bool f) { m_format = f; };
  65. virtual void execute();
  66. virtual void unexecute();
  67. virtual void setArgument(const TQString& /*arg*/, const TQString& /*val*/) {};
  68. virtual void setReverse(bool reverse) { m_reverse = reverse; }
  69. void setRegisterUndo(bool registerUndo) { m_register = registerUndo; }
  70. virtual void setName (const TQString &n) { m_name = n; }
  71. virtual TQString name() const { return m_name; };
  72. protected:
  73. virtual bool process(Element*);
  74. virtual bool process(Cell*) { return true; }
  75. virtual bool process(Format*) { return true; }
  76. virtual bool preProcessing() { return true; }
  77. virtual bool postProcessing() { return true; }
  78. Sheet* m_sheet;
  79. TQString m_name;
  80. bool m_creation : 1;
  81. bool m_reverse : 1;
  82. bool m_firstrun : 1;
  83. bool m_format : 1;
  84. bool m_register : 1;
  85. private:
  86. };
  87. /**
  88. * FormatManipulator
  89. */
  90. class FormatManipulator : public Manipulator
  91. {
  92. public:
  93. FormatManipulator();
  94. virtual ~FormatManipulator();
  95. void setProperty(Format::Properties property) { m_properties |= property; }
  96. bool isEmpty() { return m_properties == 0; }
  97. // SetSelectionFontWorker
  98. // SetSelectionSizeWorker
  99. void setFontFamily(const TQString& font) { m_properties |= Format::PFont; m_font = font; }
  100. void setFontSize(int size) { m_properties |= Format::PFont; m_size = size; }
  101. void setFontBold(uint bold) { m_properties |= Format::PFont; m_bold = bold; }
  102. void setFontItalic(uint italic) { m_properties |= Format::PFont; m_italic = italic; }
  103. void setFontStrike(uint strike) { m_properties |= Format::PFont; m_strike = strike; }
  104. void setFontUnderline(uint underline) { m_properties |= Format::PFont; m_underline = underline; }
  105. // SetSelectionAngleWorker
  106. void setAngle(int angle) { m_properties |= Format::PAngle; m_angle = angle; }
  107. // SetSelectionTextColorWorker
  108. void setTextColor(const TQColor& textColor) { m_properties |= Format::PTextPen; m_textColor = textColor; }
  109. // SetSelectionBgColorWorker
  110. void setBackgroundColor(const TQColor& bgColor) { m_properties |= Format::PBackgroundColor; m_backgroundColor = bgColor; }
  111. // SetSelectionBorderAllWorker
  112. void setTopBorderPen(const TQPen& pen) { m_properties |= Format::PTopBorder; m_topBorderPen = pen; }
  113. void setBottomBorderPen(const TQPen& pen) { m_properties |= Format::PBottomBorder; m_bottomBorderPen = pen; }
  114. void setLeftBorderPen(const TQPen& pen) { m_properties |= Format::PLeftBorder; m_leftBorderPen = pen; }
  115. void setRightBorderPen(const TQPen& pen) { m_properties |= Format::PRightBorder; m_rightBorderPen = pen; }
  116. void setHorizontalPen(const TQPen& pen) { m_properties |= Format::PTopBorder | Format::PBottomBorder; m_horizontalPen = pen; }
  117. void setVerticalPen(const TQPen& pen) { m_properties |= Format::PLeftBorder | Format::PRightBorder; m_verticalPen = pen; }
  118. void setFallDiagonalPen(const TQPen& pen) { m_properties |= Format::PFallDiagonal; m_fallDiagonalPen = pen; }
  119. void setGoUpDiagonalPen(const TQPen& pen) { m_properties |= Format::PGoUpDiagonal; m_goUpDiagonalPen = pen; }
  120. // SetSelectionAlignWorker
  121. void setHorizontalAlignment(Format::Align align) { m_properties |= Format::PAlign; m_horAlign = align; }
  122. // SetSelectionAlignWorker
  123. void setVerticalAlignment(Format::AlignY align) { m_properties |= Format::PAlignY; m_verAlign = align; }
  124. void setBackgroundBrush(const TQBrush& brush) { m_properties |= Format::PBackgroundBrush; m_backgroundBrush = brush; }
  125. void setIndent(double indent) { m_properties |= Format::PIndent; m_indent = indent; }
  126. void setMultiRow(bool multiRow) { m_properties |= Format::PMultiRow; m_multiRow = multiRow; }
  127. void setVerticalText(bool verticalText) { m_properties |= Format::PVerticalText; m_verticalText = verticalText; }
  128. void setDontPrintText(bool dontPrintText) { m_properties |= Format::PDontPrintText; m_dontPrintText = dontPrintText; }
  129. void setNotProtected(bool notProtected) { m_properties |= Format::PNotProtected; m_notProtected = notProtected; }
  130. void setHideAll(bool hideAll) { m_properties |= Format::PHideAll; m_hideAll = hideAll; }
  131. void setHideFormula(bool hideFormula) { m_properties |= Format::PHideFormula; m_hideFormula = hideFormula; }
  132. void setComment(const TQString& comment) { m_properties |= Format::PComment; m_comment = comment; }
  133. void setPrefix(const TQString& prefix) { m_properties |= Format::PPrefix; m_prefix = prefix; }
  134. void setPostfix(const TQString& postfix) { m_properties |= Format::PPostfix; m_postfix = postfix; }
  135. void setPrecision(int precision) { m_properties |= Format::PPrecision; m_precision = precision; }
  136. void setFloatFormat(Format::FloatFormat floatFormat) { m_properties |= Format::PFloatFormat; m_floatFormat = floatFormat; }
  137. void setFloatColor(Format::FloatColor floatColor) { m_properties |= Format::PFloatColor; m_floatColor = floatColor; }
  138. void setFormatType(FormatType formatType) { m_properties |= Format::PFormatType; m_formatType = formatType; }
  139. void setCurrency(int type, const TQString& symbol) { m_currencyType = type; m_currencySymbol = symbol; }
  140. protected:
  141. virtual TQString name() const { return i18n("Format Change"); }
  142. virtual bool preProcessing();
  143. virtual bool process(Element*);
  144. void copyFormat(TQValueList<layoutCell> &list,
  145. TQValueList<layoutColumn> &listCol,
  146. TQValueList<layoutRow> &listRow);
  147. bool testCondition(RowFormat*);
  148. void doWork(Format*, bool isTop, bool isBottom, bool isLeft, bool isRight);
  149. void prepareCell(Cell*);
  150. private:
  151. TQ_UINT32 m_properties;
  152. // TODO Stefan: find a more elegant way to store the format
  153. TQValueList<layoutCell> m_lstFormats;
  154. TQValueList<layoutCell> m_lstRedoFormats;
  155. TQValueList<layoutColumn> m_lstColFormats;
  156. TQValueList<layoutColumn> m_lstRedoColFormats;
  157. TQValueList<layoutRow> m_lstRowFormats;
  158. TQValueList<layoutRow> m_lstRedoRowFormats;
  159. // SetSelectionFontWorker
  160. // SetSelectionSizeWorker
  161. TQString m_font;
  162. int m_size;
  163. signed char m_bold;
  164. signed char m_italic;
  165. signed char m_strike;
  166. signed char m_underline;
  167. // SetSelectionAngleWorker
  168. int m_angle;
  169. int m_precision;
  170. int m_currencyType;
  171. double m_indent;
  172. bool m_multiRow;
  173. bool m_verticalText;
  174. bool m_dontPrintText;
  175. bool m_notProtected;
  176. bool m_hideAll;
  177. bool m_hideFormula;
  178. // SetSelectionTextColorWorker
  179. TQColor m_textColor;
  180. // SetSelectionBgColorWorker
  181. TQColor m_backgroundColor;
  182. // SetSelectionBorderAllWorker
  183. TQPen m_topBorderPen;
  184. TQPen m_bottomBorderPen;
  185. TQPen m_leftBorderPen;
  186. TQPen m_rightBorderPen;
  187. TQPen m_horizontalPen;
  188. TQPen m_verticalPen;
  189. TQPen m_fallDiagonalPen;
  190. TQPen m_goUpDiagonalPen;
  191. TQBrush m_backgroundBrush;
  192. TQString m_comment;
  193. TQString m_prefix;
  194. TQString m_postfix;
  195. TQString m_currencySymbol;
  196. // SetSelectionAlignWorker
  197. Format::Align m_horAlign;
  198. // SetSelectionAlignWorker
  199. Format::AlignY m_verAlign;
  200. Format::FloatFormat m_floatFormat;
  201. Format::FloatColor m_floatColor;
  202. FormatType m_formatType;
  203. };
  204. /**
  205. * ResizeColumnManipulator
  206. */
  207. class ResizeColumnManipulator : public Manipulator
  208. {
  209. public:
  210. ResizeColumnManipulator();
  211. ~ResizeColumnManipulator();
  212. void setSize(double size) { m_newSize = size; }
  213. void setOldSize(double size) { m_oldSize = size; }
  214. protected:
  215. virtual bool process(Element*);
  216. virtual TQString name() const { return i18n("Resize Column"); }
  217. private:
  218. double m_newSize;
  219. double m_oldSize;
  220. };
  221. /**
  222. * ResizeRowManipulator
  223. */
  224. class ResizeRowManipulator : public Manipulator
  225. {
  226. public:
  227. ResizeRowManipulator();
  228. ~ResizeRowManipulator();
  229. void setSize(double size) { m_newSize = size; }
  230. void setOldSize(double size) { m_oldSize = size; }
  231. protected:
  232. virtual bool process(Element*);
  233. virtual TQString name() const { return i18n("Resize Row"); }
  234. private:
  235. double m_newSize;
  236. double m_oldSize;
  237. };
  238. /**
  239. * BorderManipulator
  240. */
  241. class BorderManipulator : public FormatManipulator
  242. {
  243. public:
  244. BorderManipulator() {}
  245. ~BorderManipulator() {}
  246. protected:
  247. virtual TQString name() const { return i18n("Change Border"); }
  248. private:
  249. };
  250. /**
  251. * class BackgroundColorManipulator
  252. */
  253. class BackgroundColorManipulator : public FormatManipulator
  254. {
  255. public:
  256. BackgroundColorManipulator() {}
  257. ~BackgroundColorManipulator() {}
  258. protected:
  259. virtual TQString name() const { return i18n("Change Background Color"); }
  260. private:
  261. };
  262. /**
  263. * class FontColorManipulator
  264. */
  265. class FontColorManipulator : public FormatManipulator
  266. {
  267. public:
  268. FontColorManipulator() {}
  269. ~FontColorManipulator() {}
  270. protected:
  271. virtual TQString name() const { return i18n("Change Text Color"); }
  272. private:
  273. };
  274. /**
  275. * class FontManipulator
  276. */
  277. class FontManipulator : public FormatManipulator
  278. {
  279. public:
  280. FontManipulator() {}
  281. ~FontManipulator() {}
  282. protected:
  283. virtual TQString name() const { return i18n("Change Font"); }
  284. private:
  285. };
  286. /**
  287. * class AngleManipulator
  288. */
  289. class AngleManipulator : public FormatManipulator
  290. {
  291. public:
  292. AngleManipulator() {}
  293. ~AngleManipulator() {}
  294. protected:
  295. virtual TQString name() const { return i18n("Change Angle"); }
  296. private:
  297. };
  298. /**
  299. * class HorAlignManipulator
  300. */
  301. class HorAlignManipulator : public FormatManipulator
  302. {
  303. public:
  304. HorAlignManipulator() {}
  305. ~HorAlignManipulator() {}
  306. protected:
  307. virtual TQString name() const { return i18n("Change Horizontal Alignment"); }
  308. private:
  309. };
  310. /**
  311. * class VerAlignManipulator
  312. */
  313. class VerAlignManipulator : public FormatManipulator
  314. {
  315. public:
  316. VerAlignManipulator() {}
  317. ~VerAlignManipulator() {}
  318. protected:
  319. virtual TQString name() const { return i18n("Change Vertical Alignment"); }
  320. private:
  321. };
  322. /**
  323. * MergeManipulator
  324. */
  325. class MergeManipulator : public Manipulator
  326. {
  327. public:
  328. MergeManipulator();
  329. virtual ~MergeManipulator();
  330. virtual bool preProcessing();
  331. virtual void setReverse(bool reverse) { m_merge = !reverse; }
  332. void setHorizontalMerge(bool state) { m_mergeHorizontal = state; }
  333. void setVerticalMerge(bool state) { m_mergeVertical = state; }
  334. protected:
  335. virtual bool process(Element*);
  336. virtual bool postProcessing();
  337. virtual TQString name() const;
  338. bool m_merge;
  339. private:
  340. bool m_mergeHorizontal : 1;
  341. bool m_mergeVertical : 1;
  342. Manipulator* m_unmerger; // to restore old merging
  343. };
  344. /**
  345. * DilationManipulator
  346. */
  347. class DilationManipulator : public Manipulator
  348. {
  349. public:
  350. DilationManipulator();
  351. virtual ~DilationManipulator();
  352. virtual void execute();
  353. virtual void unexecute();
  354. protected:
  355. virtual TQString name() const { return i18n("Dilate Region"); }
  356. private:
  357. };
  358. /**
  359. * AdjustColumnRowManipulator
  360. */
  361. class AdjustColumnRowManipulator : public Manipulator
  362. {
  363. public:
  364. AdjustColumnRowManipulator();
  365. virtual ~AdjustColumnRowManipulator();
  366. virtual bool process(Element*);
  367. virtual bool preProcessing();
  368. void setAdjustColumn(bool state) { m_adjustColumn = state; }
  369. void setAdjustRow(bool state) { m_adjustRow = state; }
  370. protected:
  371. virtual TQString name() const;
  372. double adjustColumnHelper( Cell * c, int _col, int _row );
  373. double adjustRowHelper( Cell * c, int _col, int _row );
  374. private:
  375. bool m_adjustColumn : 1;
  376. bool m_adjustRow : 1;
  377. TQMap<int, double> m_newWidths;
  378. TQMap<int, double> m_oldWidths;
  379. TQMap<int, double> m_newHeights;
  380. TQMap<int, double> m_oldHeights;
  381. };
  382. /**
  383. * HideShowManipulator
  384. */
  385. class HideShowManipulator : public Manipulator
  386. {
  387. public:
  388. HideShowManipulator();
  389. virtual ~HideShowManipulator();
  390. virtual bool process(Element*);
  391. virtual bool preProcessing();
  392. virtual bool postProcessing();
  393. void setManipulateColumns(bool state) { m_manipulateColumns = state; }
  394. void setManipulateRows(bool state) { m_manipulateRows = state; }
  395. protected:
  396. virtual TQString name() const;
  397. private:
  398. bool m_manipulateColumns : 1;
  399. bool m_manipulateRows : 1;
  400. };
  401. /**
  402. * InsertDeleteManipulator
  403. */
  404. class InsertDeleteManipulator : public Manipulator
  405. {
  406. public:
  407. InsertDeleteManipulator();
  408. ~InsertDeleteManipulator();
  409. protected:
  410. private:
  411. bool m_manipulateColumns : 1;
  412. bool m_manipulateRows : 1;
  413. };
  414. /**
  415. * ManipulatorManager
  416. */
  417. class ManipulatorManager
  418. {
  419. public:
  420. static ManipulatorManager* self();
  421. ~ManipulatorManager();
  422. Manipulator* create(const TQString&);
  423. private:
  424. ManipulatorManager();
  425. static ManipulatorManager* m_self;
  426. };
  427. } // namespace KSpread
  428. #endif // KSPREAD_MANIPULATOR