Scribus
Open source desktop publishing at your fingertips
tablecell.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 
10 #ifndef TABLECELL_H
11 #define TABLECELL_H
12 
13 #include <QDebug>
14 #include <QExplicitlySharedDataPointer>
15 #include <QRectF>
16 #include <QSharedData>
17 #include <QString>
18 
19 #include "scribusapi.h"
20 
21 #include "commonstrings.h"
22 #include "pageitem_textframe.h"
23 #include "styles/cellstyle.h"
24 
25 class PageItem_Table;
26 class ScPainter;
27 
31 class TableCellData : public QSharedData
32 {
33 public:
36  isValid(false),
37  row(-1),
38  column(-1),
39  rowSpan(-1),
40  columnSpan(-1),
41  textFrame(0),
42  table(0) {}
44  TableCellData(const TableCellData& other) : QSharedData(other),
45  isValid(other.isValid),
46  row(other.row),
47  column(other.column),
48  rowSpan(other.rowSpan),
49  columnSpan(other.columnSpan),
50  textFrame(other.textFrame),
51  style(other.style),
52  table(other.table) {}
55  {
56  delete textFrame;
57  }
58 
59 public:
61  bool isValid;
63  int row;
65  int column;
67  int rowSpan;
70 
77 };
78 
97 class SCRIBUS_API TableCell
98 {
99 public:
106  TableCell() : d(new TableCellData) { setValid(false); }
107 
109  TableCell(const TableCell& other) : d(other.d) {}
110 
112  bool operator==(const TableCell& other) const { return other.d == d; }
113 
115  bool operator!=(const TableCell& other) const { return !(other == *this); }
116 
118  bool isValid() const { return d->isValid && d->table; }
119 
121  int row() const { return d->row; }
122 
124  int column() const { return d->column; }
125 
127  int rowSpan() const { return d->rowSpan; }
128 
130  int columnSpan() const { return d->columnSpan; }
131 
133  QRectF boundingRect() const;
134 
136  QRectF contentRect() const;
137 
139  void setFillColor(const QString& color) { d->style.setFillColor(color); }
140 
142  QString fillColor() const { return d->style.fillColor(); }
143 
145  void setFillShade(const double& shade) { d->style.setFillShade(shade); }
146 
148  double fillShade() const { return d->style.fillShade(); }
149 
151  void setLeftBorder(const TableBorder& border);
152 
154  TableBorder leftBorder() const { return d->style.leftBorder(); }
155 
157  void setRightBorder(const TableBorder& border);
158 
160  TableBorder rightBorder() const { return d->style.rightBorder(); }
161 
163  void setTopBorder(const TableBorder& border);
164 
166  TableBorder topBorder() const { return d->style.topBorder(); }
167 
169  void setBottomBorder(const TableBorder& border);
170 
172  TableBorder bottomBorder() const { return d->style.bottomBorder(); }
173 
175  void setLeftPadding(double padding);
176 
178  double leftPadding() const { return d->style.leftPadding(); }
179 
181  void setRightPadding(double padding);
182 
184  double rightPadding() const { return d->style.rightPadding(); }
185 
187  void setTopPadding(double padding);
188 
190  double topPadding() const { return d->style.topPadding(); }
191 
193  void setBottomPadding(double padding);
194 
196  double bottomPadding() const { return d->style.bottomPadding(); }
197 
199  void setStyle(const QString& style);
200 
201  void unsetDirectFormatting();
202 
204  QString style() const { return d->style.parent(); }
205 
207  void setText(const QString& text);
208 
210  PageItem_TextFrame* textFrame() const { return d->textFrame; }
211 
213  QString asString() const;
214 
215 private:
220  TableCell(int row, int column, PageItem_Table *table);
221 
223  void setRow(int row) { d->row = row; }
225  void setColumn(int column) { d->column = column; }
227  void setRowSpan(int rowSpan) { d->rowSpan = rowSpan; }
229  void setColumnSpan(int columnSpan) { d->columnSpan = columnSpan; }
231  void setValid(bool isValid) { d->isValid = isValid; }
233  void updateContent();
234 
236  void moveDown(int numRows) { d->row += numRows; }
238  void moveUp(int numRows) { d->row -= numRows; }
240  void moveRight(int numColumns) { d->column += numColumns; }
242  void moveLeft(int numColumns) { d->column -= numColumns; }
243 
245  double maxLeftBorderWidth() const;
247  double maxRightBorderWidth() const;
249  double maxTopBorderWidth() const;
251  double maxBottomBorderWidth() const;
252 
253 private:
254  friend class PageItem_Table;
255  QExplicitlySharedDataPointer<TableCellData> d;
256 };
257 Q_DECLARE_TYPEINFO(TableCell, Q_MOVABLE_TYPE);
258 
259 inline uint qHash(const TableCell& cell)
260 {
261  return (cell.row() << 16) ^ cell.column();
262 }
263 
264 QDebug operator<<(QDebug debug, const TableCell& cell);
265 
266 #endif // TABLECELL_H
double leftPadding() const
Returns the left padding of this cell.
Definition: tablecell.h:178
QString style() const
Returns the named cell style for this cell.
Definition: tablecell.h:204
TableCellData(const TableCellData &other)
Constructs data from data in other.
Definition: tablecell.h:44
int columnSpan() const
Returns the number of columns this cell spans.
Definition: tablecell.h:130
TableBorder topBorder() const
Returns the top border of this cell.
Definition: tablecell.h:166
bool operator==(const TableCell &other) const
Returns true if this cell is equal to other.
Definition: tablecell.h:112
PageItem_TextFrame * textFrame() const
Returns the text frame for this cell.
Definition: tablecell.h:210
bool operator!=(const TableCell &other) const
Returns true if this cell is not equal to other.
Definition: tablecell.h:115
void setFillColor(const QString &color)
Sets the fill color of this cell to color.
Definition: tablecell.h:139
CellStyle style
Style of the cell.
Definition: tablecell.h:74
TableCell()
Definition: tablecell.h:106
Definition: pageitem_textframe.h:45
Definition: tablecell.h:31
~TableCellData()
Destroys the cell data.
Definition: tablecell.h:54
bool isValid
Cell valid state.
Definition: tablecell.h:61
PageItem_Table * table
Table containing the cell.
Definition: tablecell.h:76
PageItem_TextFrame * textFrame
Text frame of the cell.
Definition: tablecell.h:72
double rightPadding() const
Returns the right padding of this cell.
Definition: tablecell.h:184
int rowSpan() const
Returns the number of rows this cell spans.
Definition: tablecell.h:127
double topPadding() const
Returns the top padding of this cell.
Definition: tablecell.h:190
int rowSpan
Number of rows the cell spans.
Definition: tablecell.h:67
int column
Column of the table the cell is in.
Definition: tablecell.h:65
Definition: tableborder.h:86
std::ostream & operator<<(std::ostream &out_file, const Geom::Matrix &m)
Definition: matrix.h:109
TableCell(const TableCell &other)
Construct a new table cell as a shallow copy of other.
Definition: tablecell.h:109
QString fillColor() const
Returns the fill color of this cell.
Definition: tablecell.h:142
int column() const
Returns the column in the table that contains this cell.
Definition: tablecell.h:124
Definition: cellstyle.h:32
int columnSpan
Number of columns the cell spans.
Definition: tablecell.h:69
Definition: scpainter.h:33
TableBorder rightBorder() const
Returns the right border of this cell.
Definition: tablecell.h:160
int row() const
Returns the row in the table that contains this cell.
Definition: tablecell.h:121
int row
Row of the table the cell is in.
Definition: tablecell.h:63
bool isValid() const
Returns true if this cell is valid.
Definition: tablecell.h:118
void setFillShade(const double &shade)
Sets the fill color of this cell to color.
Definition: tablecell.h:145
Definition: tablecell.h:97
TableBorder bottomBorder() const
Returns the bottom border of this cell.
Definition: tablecell.h:172
double fillShade() const
Returns the fill color of this cell.
Definition: tablecell.h:148
TableCellData()
Constructs data for an invalid cell.
Definition: tablecell.h:35
TableBorder leftBorder() const
Returns the left border of this cell.
Definition: tablecell.h:154
Definition: pageitem_table.h:49
double bottomPadding() const
Returns the bottom padding of this cell.
Definition: tablecell.h:196