Subversion Repositories Scribus

Rev

Rev 24342 | Details | Compare with Previous | Last modification | View Log | RSS feed

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