Scribus
Open source desktop publishing at your fingertips
tableborder.h
1 /*
2 Copyright (C) 2011 Elvis Stansvik <elvstone@gmail.com>
3 
4 For general Scribus (>=1.3.2) copyright and licensing information please refer
5 to the COPYING file provided with the program. Following this notice may exist
6 a copyright and/or license notice that predates the release of Scribus 1.3.2
7 for which a new license (GPL+exception) is in place.
8 */
9 #ifndef TABLEBORDER_H
10 #define TABLEBORDER_H
11 
12 #include <QList>
13 #include <QPen>
14 #include <QString>
15 
16 #include "scribusapi.h"
17 
21 class SCRIBUS_API TableBorderLine
22 {
23 public:
26 
28  TableBorderLine(double width, Qt::PenStyle style, const QString& color, double shade);
29 
31  double width() const { return m_width; }
32 
34  void setWidth(double width) { m_width = width; }
35 
37  Qt::PenStyle style() const { return m_style; }
38 
40  void setStyle(Qt::PenStyle style) { m_style = style; }
41 
43  QString color() const { return m_color; }
44 
46  void setColor(const QString& color) { m_color = color; }
47 
49  double shade() const { return m_shade; }
50 
52  void setShade(double shade) { m_shade = shade; }
53 
55  QString asString() const;
56 
58  bool operator==(const TableBorderLine& other) const
59  {
60  return width() == other.width() && color() == other.color() && style() == other.style() && shade() == other.shade();
61  }
62 
64  bool operator!=(const TableBorderLine& other) const { return !(*this == other); }
65 
67  bool operator<(const TableBorderLine& other) const { return width() < other.width(); }
68 
69 private:
71  double m_width;
73  Qt::PenStyle m_style;
75  QString m_color;
77  double m_shade;
78 };
79 Q_DECLARE_TYPEINFO(TableBorderLine, Q_MOVABLE_TYPE);
80 
86 class SCRIBUS_API TableBorder
87 {
88 public:
91 
93  TableBorder(double width, Qt::PenStyle style, const QString& color, double shade);
94 
96  double width() const;
97 
99  QList<TableBorderLine> borderLines() const { return m_borderLines; }
100 
105  TableBorderLine borderLine(int index) const;
106 
108  void addBorderLine(const TableBorderLine& borderLine);
109 
114  void removeBorderLine(int index);
115 
120  void replaceBorderLine(int index, const TableBorderLine& borderLine);
121 
126  bool joinsWith(const TableBorder& other) const { return !isNull() && !other.isNull() && borderLines() == other.borderLines(); }
127 
129  bool isNull() const { return m_borderLines.size() == 0; }
130 
132  QString asString() const;
133 
134 private:
136  QList<TableBorderLine> m_borderLines;
137 };
138 
144 inline bool operator==(const TableBorder& lhs, const TableBorder& rhs)
145 {
146  return !lhs.isNull() && !rhs.isNull() && (lhs.borderLines() == rhs.borderLines());
147 }
148 
154 inline bool operator!=(const TableBorder& lhs, const TableBorder& rhs)
155 {
156  return !(lhs == rhs);
157 }
158 
159 #endif // TABLEBORDER_H
bool operator<(const TableBorderLine &other) const
Returns true if this table border line is thinner than other.
Definition: tableborder.h:67
void setShade(double shade)
Sets the shade of this table border line to shade.
Definition: tableborder.h:52
Definition: tableborder.h:21
Qt::PenStyle style() const
Returns the pen style of this table border line.
Definition: tableborder.h:37
bool operator!=(const TableBorderLine &other) const
Returns true if this table border line is not equal to other.
Definition: tableborder.h:64
bool isNull() const
Returns true if this border has no border lines.
Definition: tableborder.h:129
QList< TableBorderLine > borderLines() const
Returns the list of border lines for this border in the order they should be painted.
Definition: tableborder.h:99
Definition: tableborder.h:86
TableBorder()
Creates a new null table border. Null borders are used to indicate the absence of a border...
Definition: tableborder.h:90
void setColor(const QString &color)
Sets the color of this table border line to color.
Definition: tableborder.h:46
double width() const
Returns the width of this table border line.
Definition: tableborder.h:31
void setStyle(Qt::PenStyle style)
Sets the pen style of this table border line to style.
Definition: tableborder.h:40
bool operator==(const TableBorderLine &other) const
Returns true if this table border line is equal to other.
Definition: tableborder.h:58
double shade() const
Returns the shade of this table border line.
Definition: tableborder.h:49
void setWidth(double width)
Sets the width of this table border line to width.
Definition: tableborder.h:34
bool joinsWith(const TableBorder &other) const
Definition: tableborder.h:126
QString color() const
Returns the color of this table border line.
Definition: tableborder.h:43