kspread

manipulator.h
1/* This file is part of the KDE project
2 Copyright (C) 2005 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
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.
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#ifndef KSPREAD_MANIPULATOR
22#define KSPREAD_MANIPULATOR
23
24#include <tqrect.h>
25#include <tqstring.h>
26#include <tqvaluelist.h>
27
28#include <kcommand.h>
29#include <tdelocale.h>
30
31#include <koffice_export.h>
32
33#include "kspread_format.h"
34#include "kspread_undo.h"
35#include "region.h"
36
37namespace KSpread
38{
39class Cell;
40class ColumnFormat;
41class RowFormat;
42class Sheet;
43
44
45// struct layoutCell {
46// int row;
47// int col;
48// Format *l;
49// };
50//
51// struct layoutColumn {
52// int col;
53// ColumnFormat *l;
54// };
55//
56// struct layoutRow {
57// int row;
58// RowFormat *l;
59// };
60
61
62
66class Manipulator : public Region, public KCommand
67{
68public:
70 virtual ~Manipulator();
71
72 Sheet* sheet() const { return m_sheet; }
73 void setSheet(Sheet* sheet) { m_sheet = sheet; }
74
75 bool creation() { return m_creation; }
76 void setCreation(bool creation) { m_creation = creation; }
77
81 bool format() { return m_format; };
82 void setFormat (bool f) { m_format = f; };
83
84 virtual void execute();
85 virtual void unexecute();
86
87 virtual void setArgument(const TQString& /*arg*/, const TQString& /*val*/) {};
88
89 virtual void setReverse(bool reverse) { m_reverse = reverse; }
90 void setRegisterUndo(bool registerUndo) { m_register = registerUndo; }
91
92 virtual void setName (const TQString &n) { m_name = n; }
93 virtual TQString name() const { return m_name; };
94
95protected:
96 virtual bool process(Element*);
97 virtual bool process(Cell*) { return true; }
98 virtual bool process(Format*) { return true; }
99
100 virtual bool preProcessing() { return true; }
101 virtual bool postProcessing() { return true; }
102
103
104 Sheet* m_sheet;
105 TQString m_name;
106 bool m_creation : 1;
107 bool m_reverse : 1;
108 bool m_firstrun : 1;
109 bool m_format : 1;
110 bool m_register : 1;
111private:
112};
113
114
115
120{
121public:
123 virtual ~FormatManipulator();
124
125 void setProperty(Format::Properties property) { m_properties |= property; }
126 bool isEmpty() { return m_properties == 0; }
127
128 // SetSelectionFontWorker
129 // SetSelectionSizeWorker
130 void setFontFamily(const TQString& font) { m_properties |= Format::PFont; m_font = font; }
131 void setFontSize(int size) { m_properties |= Format::PFont; m_size = size; }
132 void setFontBold(uint bold) { m_properties |= Format::PFont; m_bold = bold; }
133 void setFontItalic(uint italic) { m_properties |= Format::PFont; m_italic = italic; }
134 void setFontStrike(uint strike) { m_properties |= Format::PFont; m_strike = strike; }
135 void setFontUnderline(uint underline) { m_properties |= Format::PFont; m_underline = underline; }
136 // SetSelectionAngleWorker
137 void setAngle(int angle) { m_properties |= Format::PAngle; m_angle = angle; }
138 // SetSelectionTextColorWorker
139 void setTextColor(const TQColor& textColor) { m_properties |= Format::PTextPen; m_textColor = textColor; }
140 // SetSelectionBgColorWorker
141 void setBackgroundColor(const TQColor& bgColor) { m_properties |= Format::PBackgroundColor; m_backgroundColor = bgColor; }
142 // SetSelectionBorderAllWorker
143 void setTopBorderPen(const TQPen& pen) { m_properties |= Format::PTopBorder; m_topBorderPen = pen; }
144 void setBottomBorderPen(const TQPen& pen) { m_properties |= Format::PBottomBorder; m_bottomBorderPen = pen; }
145 void setLeftBorderPen(const TQPen& pen) { m_properties |= Format::PLeftBorder; m_leftBorderPen = pen; }
146 void setRightBorderPen(const TQPen& pen) { m_properties |= Format::PRightBorder; m_rightBorderPen = pen; }
147 void setHorizontalPen(const TQPen& pen) { m_properties |= Format::PTopBorder | Format::PBottomBorder; m_horizontalPen = pen; }
148 void setVerticalPen(const TQPen& pen) { m_properties |= Format::PLeftBorder | Format::PRightBorder; m_verticalPen = pen; }
149 void setFallDiagonalPen(const TQPen& pen) { m_properties |= Format::PFallDiagonal; m_fallDiagonalPen = pen; }
150 void setGoUpDiagonalPen(const TQPen& pen) { m_properties |= Format::PGoUpDiagonal; m_goUpDiagonalPen = pen; }
151 // SetSelectionAlignWorker
152 void setHorizontalAlignment(Format::Align align) { m_properties |= Format::PAlign; m_horAlign = align; }
153 // SetSelectionAlignWorker
154 void setVerticalAlignment(Format::AlignY align) { m_properties |= Format::PAlignY; m_verAlign = align; }
155
156 void setBackgroundBrush(const TQBrush& brush) { m_properties |= Format::PBackgroundBrush; m_backgroundBrush = brush; }
157 void setIndent(double indent) { m_properties |= Format::PIndent; m_indent = indent; }
158 void setMultiRow(bool multiRow) { m_properties |= Format::PMultiRow; m_multiRow = multiRow; }
159 void setVerticalText(bool verticalText) { m_properties |= Format::PVerticalText; m_verticalText = verticalText; }
160 void setDontPrintText(bool dontPrintText) { m_properties |= Format::PDontPrintText; m_dontPrintText = dontPrintText; }
161 void setNotProtected(bool notProtected) { m_properties |= Format::PNotProtected; m_notProtected = notProtected; }
162 void setHideAll(bool hideAll) { m_properties |= Format::PHideAll; m_hideAll = hideAll; }
163 void setHideFormula(bool hideFormula) { m_properties |= Format::PHideFormula; m_hideFormula = hideFormula; }
164 void setComment(const TQString& comment) { m_properties |= Format::PComment; m_comment = comment; }
165 void setPrefix(const TQString& prefix) { m_properties |= Format::PPrefix; m_prefix = prefix; }
166 void setPostfix(const TQString& postfix) { m_properties |= Format::PPostfix; m_postfix = postfix; }
167 void setPrecision(int precision) { m_properties |= Format::PPrecision; m_precision = precision; }
168 void setFloatFormat(Format::FloatFormat floatFormat) { m_properties |= Format::PFloatFormat; m_floatFormat = floatFormat; }
169 void setFloatColor(Format::FloatColor floatColor) { m_properties |= Format::PFloatColor; m_floatColor = floatColor; }
170 void setFormatType(FormatType formatType) { m_properties |= Format::PFormatType; m_formatType = formatType; }
171 void setCurrency(int type, const TQString& symbol) { m_currencyType = type; m_currencySymbol = symbol; }
172
173protected:
174 virtual TQString name() const { return i18n("Format Change"); }
175
176 virtual bool preProcessing();
177 virtual bool process(Element*);
178
179 void copyFormat(TQValueList<layoutCell> &list,
180 TQValueList<layoutColumn> &listCol,
181 TQValueList<layoutRow> &listRow);
182 bool testCondition(RowFormat*);
183 void doWork(Format*, bool isTop, bool isBottom, bool isLeft, bool isRight);
184 void prepareCell(Cell*);
185
186private:
187 TQ_UINT32 m_properties;
188
189 // TODO Stefan: find a more elegant way to store the format
190 TQValueList<layoutCell> m_lstFormats;
191 TQValueList<layoutCell> m_lstRedoFormats;
192 TQValueList<layoutColumn> m_lstColFormats;
193 TQValueList<layoutColumn> m_lstRedoColFormats;
194 TQValueList<layoutRow> m_lstRowFormats;
195 TQValueList<layoutRow> m_lstRedoRowFormats;
196
197 // SetSelectionFontWorker
198 // SetSelectionSizeWorker
199 TQString m_font;
200 int m_size;
201 signed char m_bold;
202 signed char m_italic;
203 signed char m_strike;
204 signed char m_underline;
205 // SetSelectionAngleWorker
206 int m_angle;
207 int m_precision;
208 int m_currencyType;
209 double m_indent;
210 bool m_multiRow;
211 bool m_verticalText;
212 bool m_dontPrintText;
213 bool m_notProtected;
214 bool m_hideAll;
215 bool m_hideFormula;
216
217 // SetSelectionTextColorWorker
218 TQColor m_textColor;
219 // SetSelectionBgColorWorker
220 TQColor m_backgroundColor;
221 // SetSelectionBorderAllWorker
222 TQPen m_topBorderPen;
223 TQPen m_bottomBorderPen;
224 TQPen m_leftBorderPen;
225 TQPen m_rightBorderPen;
226 TQPen m_horizontalPen;
227 TQPen m_verticalPen;
228 TQPen m_fallDiagonalPen;
229 TQPen m_goUpDiagonalPen;
230
231 TQBrush m_backgroundBrush;
232 TQString m_comment;
233 TQString m_prefix;
234 TQString m_postfix;
235 TQString m_currencySymbol;
236
237 // SetSelectionAlignWorker
238 Format::Align m_horAlign;
239 // SetSelectionAlignWorker
240 Format::AlignY m_verAlign;
241 Format::FloatFormat m_floatFormat;
242 Format::FloatColor m_floatColor;
243 FormatType m_formatType;
244};
245
246
247
252{
253public:
256
257 void setSize(double size) { m_newSize = size; }
258 void setOldSize(double size) { m_oldSize = size; }
259
260protected:
261 virtual bool process(Element*);
262
263 virtual TQString name() const { return i18n("Resize Column"); }
264
265private:
266 double m_newSize;
267 double m_oldSize;
268};
269
270
271
276{
277public:
280
281 void setSize(double size) { m_newSize = size; }
282 void setOldSize(double size) { m_oldSize = size; }
283
284protected:
285 virtual bool process(Element*);
286
287 virtual TQString name() const { return i18n("Resize Row"); }
288
289private:
290 double m_newSize;
291 double m_oldSize;
292};
293
294
295
300{
301public:
304
305protected:
306 virtual TQString name() const { return i18n("Change Border"); }
307
308private:
309};
310
311
312
317{
318public:
321
322protected:
323 virtual TQString name() const { return i18n("Change Background Color"); }
324
325private:
326};
327
328
329
334{
335public:
338
339protected:
340 virtual TQString name() const { return i18n("Change Text Color"); }
341
342private:
343};
344
345
346
351{
352public:
353 FontManipulator() {}
355
356protected:
357 virtual TQString name() const { return i18n("Change Font"); }
358
359private:
360};
361
362
363
368{
369 public:
372
373 protected:
374 virtual TQString name() const { return i18n("Change Angle"); }
375
376 private:
377};
378
379
380
385{
386 public:
389
390 protected:
391 virtual TQString name() const { return i18n("Change Horizontal Alignment"); }
392
393 private:
394};
395
396
397
402{
403 public:
406
407 protected:
408 virtual TQString name() const { return i18n("Change Vertical Alignment"); }
409
410 private:
411};
412
413
414
415
420{
421public:
423 virtual ~MergeManipulator();
424
425 virtual bool preProcessing();
426
427 virtual void setReverse(bool reverse) { m_merge = !reverse; }
428 void setHorizontalMerge(bool state) { m_mergeHorizontal = state; }
429 void setVerticalMerge(bool state) { m_mergeVertical = state; }
430
431protected:
432 virtual bool process(Element*);
433
434 virtual bool postProcessing();
435
436 virtual TQString name() const;
437
438 bool m_merge;
439private:
440 bool m_mergeHorizontal : 1;
441 bool m_mergeVertical : 1;
442 Manipulator* m_unmerger; // to restore old merging
443};
444
445
446
451{
452public:
454 virtual ~DilationManipulator();
455
456 virtual void execute();
457 virtual void unexecute();
458
459protected:
460 virtual TQString name() const { return i18n("Dilate Region"); }
461
462private:
463};
464
465
466
471{
472public:
475
476 virtual bool process(Element*);
477 virtual bool preProcessing();
478
479 void setAdjustColumn(bool state) { m_adjustColumn = state; }
480 void setAdjustRow(bool state) { m_adjustRow = state; }
481
482protected:
483 virtual TQString name() const;
484
485 double adjustColumnHelper( Cell * c, int _col, int _row );
486 double adjustRowHelper( Cell * c, int _col, int _row );
487
488private:
489 bool m_adjustColumn : 1;
490 bool m_adjustRow : 1;
491 TQMap<int, double> m_newWidths;
492 TQMap<int, double> m_oldWidths;
493 TQMap<int, double> m_newHeights;
494 TQMap<int, double> m_oldHeights;
495};
496
497
498
503{
504public:
506 virtual ~HideShowManipulator();
507
508 virtual bool process(Element*);
509 virtual bool preProcessing();
510 virtual bool postProcessing();
511
512 void setManipulateColumns(bool state) { m_manipulateColumns = state; }
513 void setManipulateRows(bool state) { m_manipulateRows = state; }
514
515protected:
516 virtual TQString name() const;
517
518private:
519 bool m_manipulateColumns : 1;
520 bool m_manipulateRows : 1;
521};
522
523
524
529{
530public:
533
534protected:
535
536private:
537 bool m_manipulateColumns : 1;
538 bool m_manipulateRows : 1;
539};
540
541
542
543
544
549{
550 public:
551 static ManipulatorManager* self();
553 Manipulator* create(const TQString&);
554
555 private:
557 static ManipulatorManager* m_self;
558};
559
560} // namespace KSpread
561
562#endif // KSPREAD_MANIPULATOR
AdjustColumnRowManipulator.
class AngleManipulator
class BackgroundColorManipulator
BorderManipulator.
For every cell in the spread sheet there is a Cell object.
DilationManipulator.
class FontColorManipulator
class FontManipulator
FormatManipulator.
HideShowManipulator.
class HorAlignManipulator
InsertDeleteManipulator.
ManipulatorManager.
bool format()
Is this a formatting manipulator ? If so, execute will call process(Format*) for each complete row/co...
Definition manipulator.h:81
MergeManipulator.
Base class for region elements, which can be points or ranges.
Definition region.h:325
The one for all class for points and ranges.
Definition region.h:44
ResizeColumnManipulator.
ResizeRowManipulator.
class VerAlignManipulator
The KSpread namespace.
Definition commands.h:39