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 TABLEUTILS_H
10 #define TABLEUTILS_H
11 
12 #include "scribusapi.h"
13 #include "tableborder.h"
14 
15 class QPointF;
16 class TableCell;
17 class PageItem_Table;
18 
19 /**
20  * Table utility functions.
21  */
22 namespace TableUtils
23 {
24 
25 /**
26  * Resolves the collapsed borders between six cells in a 3x2 area.
27  *
28  * Given the six cells @a topLeftCell, @a topCell, @a topRightCell, @a bottomLeftCell,
29  * @a bottomCell and @a bottomRightCell in the following picture
30  *
31  * <pre>
32  *  +--------------------------+--------------------------+--------------------------+
33  *  |                          |                          |                          |
34  *  |                          |                          |                          |
35  *  |        topLeftCell   topLeft        topCell      topRight   topRightCell       |
36  *  |                          |                          |                          |
37  *  |                          |                          |                          |
38  *  +----------left------------+--------- center ---------+----------right-----------+
39  *  |                          |                          |                          |
40  *  |                          |                          |                          |
41  *  |     bottomLeftCell   bottomLeft   bottomCell   bottomRight  bottomRightCell    |
42  *  |                          |                          |                          |
43  *  |                          |                          |                          |
44  *  +--------------------------+--------------------------+--------------------------+
45  * </pre>
46  *
47  * the function will return the collapsed borders @a topLeft, @a left, @a bottomLeft,
48  * @a center, @a topRight, @a right and @a bottomRight. If two adjacent cells are invalid,
49  * the returned collapsed border between them is null. If only one of two adjacent cells is
50  * valid, the returned collapsed border will be the border of the valid cell collapsed with
51  * the appropriate table border instead. If two "adjacent" cells are actually the same
52  * cell, the returned collapsed border between them is null.
53  *
54  * If both @a topCell and @a bottomCell are invalid, the function will print a
55  * warning message and return immediately, leaving @a topLeft, @a top, @a bottomLeft,
56  * @a center, @a topRight, @a right and @a bottomRight unchanged.
57  *
58  * @a topLeft, @a left , @a bottomLeft, @a center, @a topRight, @a right and
59  * @a bottomRight must point to existing borders.
60  */
61 void SCRIBUS_API resolveBordersHorizontal(const TableCell& topLeftCell, const TableCell& topCell,
62 	const TableCell& topRightCell, const TableCell& bottomLeftCell, const TableCell& bottomCell,
63 	const TableCell& bottomRightCell, TableBorder* topLeft, TableBorder* left, TableBorder* bottomLeft,
64 	TableBorder* center, TableBorder* topRight, TableBorder* right, TableBorder* bottomRight, PageItem_Table* table);
65 
66 /**
67  * Resolves the collapsed borders between six cells in a 2x3 area.
68  *
69  * Given the six cells @a topLeftCell, @a topRightCell, @a leftCell, @a rightCell,
70  * @a bottomLeftCell and @a bottomRightCell in the following picture
71  *
72  * <pre>
73  *  +----------------------+----------------------+
74  *  |                      |                      |
75  *  |                      |                      |
76  *  |    topLeftCell      top     topRightCell    |
77  *  |                      |                      |
78  *  |                      |                      |
79  *  +--------topLeft-------+-------topRight-------+
80  *  |                      |                      |
81  *  |                      |                      |
82  *  |      leftCell     center     rightCell      |
83  *  |                      |                      |
84  *  |                      |                      |
85  *  +-------bottomLeft-----+------bottomRight-----+
86  *  |                      |                      |
87  *  |                      |                      |
88  *  |  bottomLeftCell   bottom   bottomRightCell  |
89  *  |                      |                      |
90  *  |                      |                      |
91  *  +----------------------+----------------------+
92  * </pre>
93  *
94  * the function will return the collapsed borders @a topLeft, @a top, @a topRight,
95  * @a center, @a bottomLeft, @a bottom and @a bottomRight. If two adjacent cells are
96  * invalid, the returned collapsed border between them is null. If only one of two adjacent
97  * cells is valid, the returned collapsed border will be the border of the valid cell
98  * collapsed with the appropriate table border instead. If two "adjacent" cells are
99  * actually the same cell, the returned collapsed border between them is null.
100  *
101  * If both @a leftCell and @a rightCell are invalid, the function will print a
102  * warning message and return immediately, leaving @a topLeft, @a top, @a topRight,
103  * @a center, @a bottomLeft, @a bottom and @a bottomRight unchanged.
104  *
105  * @a topLeft, @a top, @a topRight, @a center, @a bottomLeft, @a bottom and
106  * @a bottomRight must point to existing borders.
107  */
108 void SCRIBUS_API resolveBordersVertical(const TableCell& topLeftCell, const TableCell& topRightCell,
109 	const TableCell& leftCell, const TableCell& rightCell, const TableCell& bottomLeftCell,
110 	const TableCell& bottomRightCell, TableBorder* topLeft, TableBorder* top, TableBorder* topRight,
111 	TableBorder* center, TableBorder* bottomLeft, TableBorder* bottom, TableBorder* bottomRight, PageItem_Table* table);
112 
113 /**
114  * Collapses @a firstBorder with @a secondBorder and returns the collapsed border.
115  *
116  * Rules in order of priority:
117  *
118  * 1) If both borders are null borders, a null border is returned.
119  * 2) If one of the two borders is null, the non-null border is returned.
120  * 3) If one of the two borders is wider than the other, the wider border is returned.
121  * 4) If @a firstBorder has more border lines than @a secondBorder, @a firstBorder is returned,
122  *    else, @a secondBorder is returned.
123  */
124 TableBorder SCRIBUS_API collapseBorders(const TableBorder& firstBorder, const TableBorder& secondBorder);
125 
126 /**
127  * Joins the vertical border @a border with neighboring borders.
128  *
129  * Adjustments are made to the passed @a start and @a end points and offset factors for the
130  * individual border lines are returned in @a startOffsetFactors and @a endOffsetFactors.
131  *
132  * If any of @a topLeft, @a top, @a topRight, @a bottomLeft, @a bottom or @a bottomRight
133  * is null (isNull() returning <code>true</code>), then it is assumed that there is no border
134  * coming in from that direction.
135  *
136  * Which neighboring borders the arguments refer to is illustrated by:
137  *
138  * <pre>
139  *                 top
140  *                  |
141  *       topLeft--(start)--topRight
142  *                  |
143  *                border
144  *                  |
145  *    bottomLeft--(end)--bottomRight
146  *                  |
147  *                bottom
148  * </pre>
149  *
150  * @param border the border that should be joined.
151  * @param topLeft horizontal border meeting the start point of the border from the left.
152  * @param top vertical border meeting the start point of the border from above.
153  * @param topRight horizontal border meeting the start point of the border from the right.
154  * @param bottomLeft horizontal border meeting the end point of the border from the left.
155  * @param bottom vertical border meeting the end point of the border from above.
156  * @param bottomRight horizontal border meeting the end point of the border from the right.
157  * @param start start point of @a border, assumed to be above @a end.
158  * @param end end point of @a border, assumed to be below @a start.
159  * @param startOffsetFactors start offset factors for the individual border lines. The start
160  * 		point of each border line of the border should be adjusted by its
161  * 		own width multiplied by these factors.
162  * @param endOffsetFactors end offset factors for the individual border lines. The end
163  * 		point of each border line of the border should be adjusted by its
164  * 		own width multiplied by these factors.
165  */
166 void SCRIBUS_API joinVertical(const TableBorder& border, const TableBorder& topLeft, const TableBorder& top,
167 				  const TableBorder& topRight, const TableBorder& bottomLeft, const TableBorder& bottom,
168 				  const TableBorder& bottomRight, QPointF* start, QPointF* end, QPointF* startOffsetFactors,
169 				  QPointF* endOffsetFactors);
170 
171 /**
172  * Joins the horizontal border @a border with neighboring borders.
173  *
174  * Adjustments are made to the passed @a start and @a end points and offset factors for the
175  * individual border lines are returned in @a startOffsetFactors and @a endOffsetFactors.
176  *
177  * If any of @a topLeft, @a left, @a bottomLeft, @a topRight, @a right or @a bottomRight
178  * is null (isNull() returning <code>true</code>), then it is assumed that there is no border
179  * coming in from that direction.
180  *
181  * Which neighboring borders the arguments refer to is illustrated by:
182  *
183  * <pre>
184  *          topLeft              topRight
185  *             |                     |
186  *   left--(m_start)---m_border---(m_end)--right
187  *             |                     |
188  *         bottomLeft           bottomRight
189  * </pre>
190  *
191  * @param topLeft vertical border meeting the start point of the border from the top.
192  * @param left horizontal border meeting the start point of @a border from the left.
193  * @param bottomLeft vertical border meeting the start point of the border from the bottom.
194  * @param topRight vertical border meeting the end point of the border from the top.
195  * @param right horizontal border meeting the end point of the border from the right.
196  * @param bottomRight vertical border meeting the end point of the border from the bottom.
197  * @param start start point of @a border, assumed to be above @a end.
198  * @param end end point of @a border, assumed to be below @a start.
199  * @param startOffsetFactors start offset factors for the individual border lines. The start
200  * 		point of each border line of the border should be adjusted by its
201  * 		own width multiplied by these factors.
202  * @param endOffsetFactors end offset factors for the individual border lines. The end
203  * 		point of each border line of the border should be adjusted by its
204  * 		own width multiplied by these factors.
205  */
206 void SCRIBUS_API joinHorizontal(const TableBorder& border, const TableBorder& topLeft, const TableBorder& left,
207 				  const TableBorder& bottomLeft, const TableBorder& topRight, const TableBorder& right,
208 				  const TableBorder& bottomRight, QPointF* start, QPointF* end, QPointF* startOffsetFactors,
209 				  QPointF* endOffsetFactors);
210 
211 } // namespace TableUtils
212 
213 #endif // TABLEUTILS_H
214