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 #include <algorithm>
11 #include <functional>
12
13 #include <QList>
14 #include <QString>
15 #include <QStringList>
16 #include <QtAlgorithms>
17
18 #include "commonstrings.h"
19
20 #include "tableborder.h"
21
22 /*
23 * TableBorderLine definitions.
24 */
25
26 TableBorderLine::TableBorderLine() = default;
27
TableBorderLine(double width,Qt::PenStyle style,const QString & color,double shade)28 TableBorderLine::TableBorderLine(double width, Qt::PenStyle style, const QString& color, double shade)
29 {
30 m_width = width;
31 m_style = style;
32 m_color = color;
33 m_shade = shade;
34 }
35
asString() const36 QString TableBorderLine::asString() const
37 {
38 return QString("(%1,%2,%3,%4)").arg(width()).arg(style()).arg(color()).arg(shade());
39 }
40
41 /*
42 * TableBorder definitions.
43 */
44
TableBorder(double width,Qt::PenStyle style,const QString & color,double shade)45 TableBorder::TableBorder(double width, Qt::PenStyle style, const QString& color, double shade)
46 {
47 addBorderLine(TableBorderLine(width, style, color, shade));
48 }
49
width() const50 double TableBorder::width() const
51 {
52 return isNull() ? 0.0 : m_borderLines.first().width();
53 }
54
borderLine(int index) const55 TableBorderLine TableBorder::borderLine(int index) const
56 {
57 if (index < 0 || index >= m_borderLines.size())
58 return TableBorderLine();
59
60 return m_borderLines.at(index);
61 }
62
addBorderLine(const TableBorderLine & borderLine)63 void TableBorder::addBorderLine(const TableBorderLine& borderLine)
64 {
65 m_borderLines.append(borderLine);
66 std::stable_sort(m_borderLines.begin(), m_borderLines.end(), std::greater<TableBorderLine>());
67 }
68
removeBorderLine(int index)69 void TableBorder::removeBorderLine(int index)
70 {
71 if (index < 0 || index >= m_borderLines.size())
72 return;
73
74 m_borderLines.removeAt(index);
75 }
76
replaceBorderLine(int index,const TableBorderLine & borderLine)77 void TableBorder::replaceBorderLine(int index, const TableBorderLine& borderLine)
78 {
79 if (index < 0 || index >= m_borderLines.size())
80 return;
81
82 m_borderLines.replace(index, borderLine);
83 std::stable_sort(m_borderLines.begin(), m_borderLines.end(), std::greater<TableBorderLine>());
84 }
85
asString() const86 QString TableBorder::asString() const
87 {
88 QStringList lines;
89 for (const TableBorderLine& line : m_borderLines)
90 lines << line.asString();
91 return QString("TableBorder(%1)").arg(lines.join(","));
92 }
93