filters

kspread/excel/sidewinder/format.cpp
1/* Swinder - Portable library for spreadsheet
2 Copyright (C) 2003-2006 Ariya Hidayat <ariya@kde.org>
3 Copyright (C) 2006 Marijn Kruisselbrink <m.kruisselbrink@student.tue.nl>
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 "format.h"
22
23#include "ustring.h"
24
25
26using namespace Swinder;
27
28class FormatFont::Private
29{
30public:
31 bool null : 1 ;
32 bool bold : 1;
33 bool italic : 1;
34 bool underline : 1;
35 bool strikeout : 1;
36 bool subscript : 1;
37 bool superscript : 1;
38 UString fontFamily;
39 double fontSize;
40 Color color;
41
42 static UString defaultFont;
43};
44
45UString FormatFont::Private::defaultFont("Arial");
46
48{
49 d = new FormatFont::Private();
50 d->null = true;
51 d->fontFamily = Private::defaultFont;
52 d->fontSize = 11;
53 d->bold = false;
54 d->italic = false;
55 d->underline = false;
56 d->strikeout = false;
57 d->subscript = false;
58 d->superscript = false;
59}
60
62{
63 delete d;
64}
65
67{
68 d = new FormatFont::Private();
69 assign( f );
70}
71
73{
74 return assign( f );
75}
76
78{
79 d->null = f.isNull();
80 d->fontFamily = f.fontFamily();
81 d->fontSize = f.fontSize();
82 d->color = f.color();
83 d->bold = f.bold();
84 d->italic = f.italic();
85 d->underline = f.underline();
86 d->strikeout = f.strikeout();
87 d->subscript = f.subscript();
88 d->superscript = f.superscript();
89
90 return *this;
91}
92
94{
95 return d->null;
96}
97
99{
100 return d->fontFamily;
101}
102
104{
105 d->fontFamily = fontFamily;
106 d->null = false;
107}
108
110{
111 return d->fontSize;
112}
113
114void FormatFont::setFontSize( double fs )
115{
116 d->fontSize = fs;
117 d->null = false;
118}
119
121{
122 return d->color;
123}
124
126{
127 d->color = c;
128 d->null = false;
129}
130
132{
133 return d->bold;
134}
135
137{
138 d->bold = b;
139 d->null = false;
140}
141
143{
144 return d->italic;
145}
146
148{
149 d->italic = b;
150 d->null = false;
151}
152
154{
155 return d->underline;
156}
157
159{
160 d->underline = b;
161 d->null = false;
162}
163
165{
166 return d->strikeout;
167}
168
170{
171 d->strikeout = s;
172 d->null = false;
173}
174
176{
177 return d->subscript;
178}
179
181{
182 d->subscript = s;
183 d->null = false;
184
185 // mutually exclusive
186 if( d->subscript && d->superscript )
187 d->superscript = false;
188}
189
191{
192 return d->superscript;
193}
194
196{
197 d->superscript = s;
198 d->null = false;
199
200 // mutually exclusive
201 if( d->superscript && d->subscript )
202 d->subscript = false;
203}
204
205bool FormatFont::operator==(const FormatFont& font) const
206{
207 return
208 d->bold == font.d->bold &&
209 d->italic == font.d->italic &&
210 d->underline == font.d->underline &&
211 d->strikeout == font.d->strikeout &&
212 d->subscript == font.d->subscript &&
213 d->superscript == font.d->superscript &&
214 d->fontFamily == font.d->fontFamily &&
215 d->fontSize == font.d->fontSize &&
216 d->color == font.d->color;
217}
218
219bool FormatFont::operator!=(const FormatFont& font) const
220{
221 return
222 d->bold != font.d->bold ||
223 d->italic != font.d->italic ||
224 d->underline != font.d->underline ||
225 d->strikeout != font.d->strikeout ||
226 d->subscript != font.d->subscript ||
227 d->superscript != font.d->superscript ||
228 d->fontFamily != font.d->fontFamily ||
229 d->fontSize != font.d->fontSize ||
230 d->color != font.d->color;
231}
232
233class FormatAlignment::Private
234{
235public:
236 bool null;
237 unsigned alignX;
238 unsigned alignY;
239 bool wrap;
240 unsigned indentLevel;
241 unsigned rotationAngle;
242};
243
245{
246 d = new FormatAlignment::Private;
247 d->null = true;
248 d->alignX = Format::Left;
249 d->alignY = Format::Middle;
250 d->wrap = false;
251 d->indentLevel = 0;
252 d->rotationAngle = 0;
253}
254
255// destructor
257{
258 delete d;
259}
260
261// copy constructor
263{
264 d = new FormatAlignment::Private;
265 assign( align );
266}
267
268// assignment operator
270{
271 return assign( align );
272}
273
274// assign from another alignment
276{
277 d->null = align.isNull();
278 d->alignX = align.alignX();
279 d->alignY = align.alignY();
280 d->wrap = align.wrap();
281 d->indentLevel = align.indentLevel();
282 d->rotationAngle = align.rotationAngle();
283 return *this;
284}
285
287{
288 return d->null;
289}
290
292{
293 return d->alignX;
294}
295
296void FormatAlignment::setAlignX( unsigned xa )
297{
298 d->alignX = xa;
299 d->null = false;
300}
301
303{
304 return d->alignY;
305}
306
307void FormatAlignment::setAlignY( unsigned ya )
308{
309 d->alignY = ya;
310 d->null = false;
311}
312
314{
315 return d->wrap;
316}
317
319{
320 d->wrap = w;
321 d->null = false;
322}
323
325{
326 return d->indentLevel;
327}
328
330{
331 d->indentLevel = i;
332 d->null = false;
333}
334
336{
337 return d->rotationAngle;
338}
339
341{
342 d->rotationAngle = r;
343 d->null = false;
344}
345
347{
348 return
349 d->alignX == font.d->alignX &&
350 d->alignY == font.d->alignY &&
351 d->wrap == font.d->wrap &&
352 d->indentLevel == font.d->indentLevel &&
353 d->rotationAngle == font.d->rotationAngle;
354}
355
357{
358 return
359 d->alignX != font.d->alignX ||
360 d->alignY != font.d->alignY ||
361 d->wrap != font.d->wrap ||
362 d->indentLevel != font.d->indentLevel ||
363 d->rotationAngle != font.d->rotationAngle;
364}
365
366class FormatBackground::Private
367{
368public:
369 bool null;
370 unsigned pattern;
371 Color background;
372 Color foreground;
373};
374
375// constructor
377{
378 d = new FormatBackground::Private();
379 d->null = true;
380}
381
382// destructor
384{
385 delete d;
386}
387
388// copy constructor
390{
391 d = new FormatBackground::Private;
392 assign( background );
393}
394
395// assignment operator
397{
398 return assign( background );
399}
400
401// assign from another alignment
403{
404 d->null = background.isNull();
405 d->pattern = background.pattern();
406 d->background = background.backgroundColor();
407 d->foreground = background.foregroundColor();
408 return *this;
409}
410
412{
413 return d->null;
414}
415
417{
418 return d->pattern;
419}
420
422{
423 d->pattern = pattern;
424 d->null = false;
425}
426
428{
429 return d->background;
430}
431
433{
434 d->background = color;
435 d->null = false;
436}
437
439{
440 return d->foreground;
441}
442
444{
445 d->foreground = color;
446 d->null = false;
447}
448
450{
451 return
452 d->pattern == font.d->pattern &&
453 d->background == font.d->background &&
454 d->foreground == font.d->foreground;
455}
456
458{
459 return
460 d->pattern != font.d->pattern ||
461 d->background != font.d->background ||
462 d->foreground != font.d->foreground;
463}
464
465class FormatBorders::Private
466{
467public:
468 bool null;
469 Pen leftBorder;
470 Pen rightBorder;
471 Pen topBorder;
472 Pen bottomBorder;
473};
474
475// constructor
477{
478 d = new FormatBorders::Private;
479 d->null = true;
480}
481
482// destructor
484{
485 delete d;
486}
487
488// copy constructor
490{
491 d = new FormatBorders::Private;
492 assign( border );
493}
494
495// assignment operator
497{
498 return assign( border );
499}
500
501// assign from another alignment
503{
504 d->null = border.isNull();
505 d->leftBorder = border.leftBorder();
506 d->rightBorder = border.rightBorder();
507 d->topBorder = border.topBorder();
508 d->bottomBorder = border.bottomBorder();
509 return *this;
510}
511
513{
514 return d->null;
515}
516
518{
519 return d->leftBorder;
520}
521
522void FormatBorders::setLeftBorder( const Pen& pen )
523{
524 d->leftBorder = pen;
525 d->null = false;
526}
527
529{
530 return d->rightBorder;
531}
532
533void FormatBorders::setRightBorder( const Pen& pen )
534{
535 d->rightBorder = pen;
536 d->null = false;
537}
538
539const Pen& FormatBorders::topBorder() const
540{
541 return d->topBorder;
542}
543
544void FormatBorders::setTopBorder( const Pen& pen )
545{
546 d->topBorder = pen;
547 d->null = false;
548}
549
551{
552 return d->bottomBorder;
553}
554
555void FormatBorders::setBottomBorder( const Pen& pen )
556{
557 d->bottomBorder = pen;
558 d->null = false;
559}
560
562{
563 return
564 d->leftBorder == font.d->leftBorder &&
565 d->rightBorder == font.d->rightBorder &&
566 d->topBorder == font.d->topBorder &&
567 d->bottomBorder == font.d->bottomBorder;
568}
569
571{
572 return
573 d->leftBorder != font.d->leftBorder ||
574 d->rightBorder != font.d->rightBorder ||
575 d->topBorder != font.d->topBorder ||
576 d->bottomBorder != font.d->bottomBorder;
577}
578
579// helper class for Format class
580class Format::Private
581{
582public:
583 FormatFont font;
584 FormatAlignment alignment;
585 FormatBorders borders;
586 FormatBackground background;
587 UString valueFormat;
588};
589
590// create an empty format
592{
593 d = new Format::Private;
594 d->valueFormat = "General";
595}
596
597// destructor
599{
600 delete d;
601}
602
603// copy constructor
605{
606 d = new Format::Private;
607 assign( f );
608}
609
610// assignment operator
612{
613 return assign( f );
614}
615
616// assign from another format
618{
619 d->font = f.font();
620 d->alignment = f.alignment();
621 d->borders = f.borders();
622 d->valueFormat = f.valueFormat();
623 d->background = f.background();
624 return *this;
625}
626
627bool Format::isNull() const
628{
629 return d->font.isNull() && d->alignment.isNull() && d->borders.isNull();
630}
631
633{
634 return d->font;
635}
636
638{
639 d->font = font;
640}
641
643{
644 return d->alignment;
645}
646
648{
649 d->alignment = alignment;
650}
651
653{
654 return d->borders;
655}
656
658{
659 d->borders = borders;
660}
661
663{
664 return d->background;
665}
666
668{
669 d->background = background;
670}
671
673{
674 return d->valueFormat;
675}
676
678{
679 d->valueFormat = valueFormat;
680}
681
682// merge f into current format
684{
685 if( !f.alignment().isNull() )
686 alignment() = f.alignment();
687 if( !f.font().isNull() )
688 font() = f.font();
689 if( !f.borders().isNull() )
690 borders() = f.borders();
691 if( f.valueFormat().isEmpty() || f.valueFormat() == "General" )
693 if (!f.background().isNull() )
694 background() = f.background();
695
696 return *this;
697}
698
699bool Format::operator==(const Format& format) const
700{
701 return
702 d->font == format.d->font &&
703 d->alignment == format.d->alignment &&
704 d->borders == format.d->borders &&
705 d->background == format.d->background &&
706 d->valueFormat == format.d->valueFormat;
707}
708
709bool Format::operator!=(const Format& format) const
710{
711 return
712 d->font != format.d->font ||
713 d->alignment != format.d->alignment ||
714 d->borders != format.d->borders ||
715 d->background != format.d->background ||
716 d->valueFormat != format.d->valueFormat;
717}
Provides color based on RGB values.
Defines alignment information for cell format.
~FormatAlignment()
Destroys the alignment information.
unsigned indentLevel() const
Returns the indentation level.
bool operator==(const FormatAlignment &f) const
Returns true if this alignment is equal to f; otherwise returns false.
bool operator!=(const FormatAlignment &f) const
Returns true if this alignment is not equal to f; otherwise returns false.
FormatAlignment & operator=(const FormatAlignment &)
Assigns from another alignment information.
void setIndentLevel(unsigned i)
Sets the indentation level.
bool wrap() const
Returns true if the text should be wrapped at right border.
unsigned alignY() const
Returns horizontal alignment.
void setAlignX(unsigned xa)
Sets the horizontal alignment.
void setWrap(bool w)
Sets whether the text should be wrapped at right border.
FormatAlignment()
Creates a default alignment information.
unsigned rotationAngle() const
Returns the text rotation angle.
bool isNull() const
Returns true if it is a default alignment information.
unsigned alignX() const
Returns horizontal alignment.
void setAlignY(unsigned xa)
Sets the horizontal alignment.
void setRotationAngle(unsigned r)
Sets the text rotation angle.
FormatAlignment & assign(const FormatAlignment &)
Assigns from another alignment information.
Defines background information for cell.
~FormatBackground()
Destroys the background information.
bool operator==(const FormatBackground &f) const
Returns true if this background is equal to f; otherwise returns false.
unsigned pattern() const
Returns pattern for this background.
void setForegroundColor(const Color &)
Sets the foreground color.
bool isNull() const
Returns true if it is a default background information.
FormatBackground()
Creates a default background information.
void setBackgroundColor(const Color &)
Set the background color.
bool operator!=(const FormatBackground &f) const
Returns true if this background is not equal to f; otherwise returns false.
FormatBackground & operator=(const FormatBackground &)
Assigns from another background information.
void setPattern(unsigned)
Set the pattern for this background.
Color foregroundColor() const
Returns the foreground color of the background area.
FormatBackground & assign(const FormatBackground &)
Assigns from another background information.
Color backgroundColor() const
Returns the background color of the background area.
Defines borders information for cell.
const Pen & leftBorder() const
Returns pen style, width and color for left border.
void setRightBorder(const Pen &pen)
Sets pen style, width and color for right border.
void setTopBorder(const Pen &pen)
Sets pen style, width and color for top border.
void setLeftBorder(const Pen &pen)
Sets pen style, width and color for left border.
~FormatBorders()
Destroys the border information.
bool operator==(const FormatBorders &f) const
Returns true if this background is equal to f; otherwise returns false.
void setBottomBorder(const Pen &pen)
Sets pen style, width and color for bottom border.
bool operator!=(const FormatBorders &f) const
Returns true if this background is not equal to f; otherwise returns false.
FormatBorders & assign(const FormatBorders &)
Assigns from another border information.
const Pen & rightBorder() const
Returns pen style, width and color for right border.
bool isNull() const
Returns true if it is a default border information.
FormatBorders & operator=(const FormatBorders &)
Assigns from another border information.
const Pen & topBorder() const
Returns pen style, width and color for top border.
const Pen & bottomBorder() const
Returns pen style, width and color for bottom border.
FormatBorders()
Creates a default border information.
Defines font information for cell format.
bool italic() const
Returns true if italic has been set.
bool strikeout() const
Returns true if strikeout has been set.
bool operator==(const FormatFont &f) const
Returns true if this font is equal to f; otherwise returns false.
bool isNull() const
Returns true if it is a default font information.
FormatFont & operator=(const FormatFont &)
Assigns from another font information.
FormatFont()
Creates a default font information.
void setColor(const Color &color)
Sets the color of the font.
bool subscript() const
Returns true if subscript has been set.
void setFontFamily(const UString &fontFamily)
Sets a new family for the font information.
void setStrikeout(bool s)
If s is true, strikeout is set on; otherwise strikeout is set off.
bool superscript() const
Returns true if superscript has been set.
void setFontSize(double fs)
Sets the size of font (in points).
~FormatFont()
Destroys the font information.
void setSuperscript(bool s)
If s is true, superscript is set on; otherwise superscript is set off.
bool operator!=(const FormatFont &f) const
Returns true if this font is not equal to f; otherwise returns false.
void setSubscript(bool s)
If s is true, subscript is set on; otherwise subscript is set off.
void setBold(bool b)
If b is true, bold is set on; otherwise bold is set off.
double fontSize() const
Returns the size of font (in points).
const UString & fontFamily() const
Returns the name of font family, e.g "Helvetica".
FormatFont & assign(const FormatFont &)
Assigns from another font information.
Color color() const
Returns the color of the font.
bool underline() const
Returns true if underline has been set.
void setUnderline(bool u)
If u is true, underline is set on; otherwise underline is set off.
void setItalic(bool i)
If i is true, italic is set on; otherwise italic is set off.
bool bold() const
Returns true if bold has been set.
void setBackground(const FormatBackground &)
Sets new background information for this format.
bool operator!=(const Format &f) const
Returns true if this format is not equal to f; otherwise returns false.
Format & operator=(const Format &f)
Assigns from another format.
void setFont(const FormatFont &font)
Sets new font information for this format.
FormatFont & font() const
Returns a constant reference to the formatting information of this format.
const UString & valueFormat() const
Returns the formatting string to display the value of this format.
bool isNull() const
Returns true if it is a default format information.
void setValueFormat(const UString &valueFormat)
Sets the new formatting string to display the value of this format.
Format()
Creates a default format.
void setAlignment(const FormatAlignment &alignment)
Sets new alignment information for this format.
void setBorders(const FormatBorders &border)
Sets new borders information for this format.
FormatAlignment & alignment() const
Returns a constant reference to the alignment information of this format.
Format & apply(const Format &f)
Applies another format to this format.
FormatBorders & borders() const
Returns a reference to the borders information of this format.
FormatBackground & background() const
Returns a reference to the background information of this format.
Format & assign(const Format &f)
Assigns from another value.
bool operator==(const Format &f) const
Returns true if this format is equal to f; otherwise returns false.