filters

kspread/excel/sidewinder/format.h
1/* Sidewinder - 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#ifndef SWINDER_FORMAT_H
22#define SWINDER_FORMAT_H
23
24#include "ustring.h"
25#include <cstdio> // for sscanf
26
27namespace Swinder
28{
29
37class Color
38{
39public:
40
41 unsigned red, green, blue;
42
46 Color(){ red = green = blue = 0; };
47
51 Color( const Color& c )
52 { red = c.red; green = c.green; blue = c.blue; }
53
57 Color( unsigned r, unsigned g, unsigned b )
58 { red = r; green = g; blue = b; }
59
63 Color( const char* c )
64 { std::sscanf(c, "#%2x%2x%2x", &red, &green, &blue); }
65
66 friend inline bool operator==(const Color&, const Color&);
67 friend inline bool operator!=(const Color&, const Color&);
68};
69
73inline bool operator==(const Color& c1, const Color& c2)
74{ return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue; }
75
79inline bool operator!=(const Color& c1, const Color& c2)
80{ return c1.red != c2.red || c1.green != c2.green || c1.blue != c2.blue; }
81
82class Pen
83{
84public:
85
86 unsigned style;
87
88 unsigned width;
89
90 Color color;
91
92 enum {
93 NoLine, // no line at all
94 SolidLine, // a simple solid line
95 DashLine, // dashes separated by a few pixels
96 DotLine, // dots separated by a few pixels
97 DashDotLine, // alternate dots and dashes
98 DashDotDotLine // one dash, two dots, one dash, two dots
99 };
100
101 Pen(): style( SolidLine ), width( 0 ){}
102
103 friend inline bool operator==(const Pen&, const Pen&);
104 friend inline bool operator!=(const Pen&, const Pen&);
105};
106
110inline bool operator==(const Pen& p1, const Pen& p2)
111{ return p1.style == p2.style && p1.width == p1.width && p1.color == p2.color; }
112
116inline bool operator!=(const Pen& p1, const Pen& p2)
117{ return p1.style != p2.style || p1.width != p1.width || p1.color != p2.color; }
118
119
127
129{
130public:
131
135 FormatFont();
136
140 ~FormatFont();
141
145 FormatFont( const FormatFont& );
146
151
155 FormatFont& assign( const FormatFont& );
156
160 bool isNull() const;
161
165 const UString& fontFamily() const;
166
170 void setFontFamily( const UString& fontFamily );
171
175 double fontSize() const;
176
180 void setFontSize( double fs );
181
185 Color color() const;
186
190 void setColor( const Color& color );
191
195 bool bold() const;
196
200 void setBold( bool b );
201
205 bool italic() const;
206
210 void setItalic( bool i );
211
215 bool underline() const;
216
220 void setUnderline( bool u );
221
225 bool strikeout() const;
226
230 void setStrikeout( bool s );
231
235 bool subscript() const;
236
240 void setSubscript( bool s );
241
245 bool superscript() const;
246
250 void setSuperscript( bool s );
251
255 bool operator==(const FormatFont& f) const;
256
260 bool operator!=(const FormatFont& f) const;
261
262private:
263 class Private;
264 Private *d;
265};
266
267
275
277{
278public:
279
284
289
294
299
304
308 bool isNull() const;
309
316 unsigned alignX() const;
317
323 void setAlignX( unsigned xa );
324
331 unsigned alignY() const;
332
338 void setAlignY( unsigned xa );
339
345 bool wrap() const;
346
352 void setWrap( bool w );
353
359 unsigned indentLevel() const;
360
366 void setIndentLevel( unsigned i );
367
373 unsigned rotationAngle() const;
374
380 void setRotationAngle( unsigned r );
381
385 bool operator==(const FormatAlignment& f) const;
386
390 bool operator!=(const FormatAlignment& f) const;
391
392private:
393 class Private;
394 Private *d;
395};
396
402{
403public:
408
413
418
423
428
432 bool isNull() const;
433
434 enum {
435 SolidPattern,
436 Dense1Pattern,
437 Dense2Pattern,
438 Dense3Pattern,
439 Dense4Pattern,
440 Dense5Pattern,
441 Dense6Pattern,
442 Dense7Pattern,
443 HorPattern, // Horizonatal lines
444 VerPattern, // Vertical lines
445 CrossPattern, // Horizontal and vertical lines
446 BDiagPattern, // Left-bottom to right-top diagonal lines
447 FDiagPattern, // Left-top to right-bottom diagonal lines
448 DiagCrossPattern, // Crossing diagonal lines
449 EmptyPattern
450 };
451
457 unsigned pattern() const;
458
464 void setPattern( unsigned );
465
471 Color backgroundColor() const;
472
478 void setBackgroundColor( const Color& );
479
485 Color foregroundColor() const;
486
492 void setForegroundColor( const Color& );
493
497 bool operator==(const FormatBackground& f) const;
498
502 bool operator!=(const FormatBackground& f) const;
503
504private:
505 class Private;
506 Private *d;
507};
508
513
515{
516public:
517
522
527
532
537
542
546 bool isNull() const;
547
553 const Pen& leftBorder() const;
554
560 void setLeftBorder( const Pen& pen );
561
567 const Pen& rightBorder() const;
568
574 void setRightBorder( const Pen& pen );
575
581 const Pen& topBorder() const;
582
588 void setTopBorder( const Pen& pen );
589
595 const Pen& bottomBorder() const;
596
602 void setBottomBorder( const Pen& pen );
603
607 bool operator==(const FormatBorders& f) const;
608
612 bool operator!=(const FormatBorders& f) const;
613
614private:
615 class Private;
616 Private *d;
617};
618
639
640
642{
643public:
644
648 Format();
649
653 ~Format();
654
658 Format( const Format& f );
659
663 Format& operator= ( const Format& f );
664
668 Format& assign( const Format& f );
669
673 bool isNull() const;
674
678 FormatFont& font() const;
679
683 void setFont( const FormatFont& font );
684
688 FormatAlignment& alignment() const;
689
694
698 FormatBorders& borders() const;
699
703 void setBorders( const FormatBorders& border );
704
709
713 void setBackground( const FormatBackground& );
714
718 const UString& valueFormat() const;
719
723 void setValueFormat( const UString& valueFormat );
724
725 enum { Left, Center, Right };
726
727 enum { Top, Middle, Bottom };
728
741 Format& apply( const Format& f );
742
746 bool operator==(const Format& f) const;
747
751 bool operator!=(const Format& f) const;
752
753private:
754 class Private;
755 Private* d; // can't never be 0
756};
757
758}
759
760#endif // SWINDER_FORMAT_H
761
This class describe a pen which is used to draw borders.
Definition pen.h:39
Provides color based on RGB values.
Color(const char *c)
Creates a color based on given red, green and blue values, encoded as RRGGBB in a string.
Color(const Color &c)
Creates a copy of another color.
Color(unsigned r, unsigned g, unsigned b)
Creates a color based on given red, green and blue values.
Color()
Constructs a default color with the RGB value (0, 0, 0), i.e black.
friend bool operator==(const Color &, const Color &)
Returns true if c1 is equal to c2; otherwise returns false.
friend bool operator!=(const Color &, const Color &)
Returns true if c1 is not equal to c2; otherwise returns false.
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.