1
/* This file is part of the KDE project
2
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
3
* Copyright (C) 2016 by Dag Andersen <danders@get2net.dk>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
#include "PlanReportScriptText.h"
21
#include <QTextStream>
26
Text::Text(PlanReportItemText* t)
36
QString Text::source() const
38
return m_text->itemDataSource();
41
void Text::setSource(const QString& s)
43
m_text->m_controlSource->setValue(s);
46
int Text::horizontalAlignment() const
48
const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
50
if (a == QLatin1String("left")) {
53
if (a == QLatin1String("center")) {
56
if (a == QLatin1String("right")) {
61
void Text::setHorizonalAlignment(int a)
65
m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
68
m_text->m_horizontalAlignment->setValue(QLatin1String("center"));
71
m_text->m_horizontalAlignment->setValue(QLatin1String("right"));
74
m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
79
int Text::verticalAlignment() const
81
const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
83
if (a == QLatin1String("top")) {
86
if (a == QLatin1String("middle")) {
89
if (a == QLatin1String("bottom")) {
94
void Text::setVerticalAlignment(int a)
98
m_text->m_verticalAlignment->setValue(QLatin1String("top"));
101
m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
104
m_text->m_verticalAlignment->setValue(QLatin1String("bottom"));
107
m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
112
QColor Text::backgroundColor() const
114
return m_text->m_backgroundColor->value().value<QColor>();
116
void Text::setBackgroundColor(const QColor& c)
118
m_text->m_backgroundColor->setValue(QColor(c));
121
QColor Text::foregroundColor() const
123
return m_text->m_foregroundColor->value().value<QColor>();
125
void Text::setForegroundColor(const QColor& c)
127
m_text->m_foregroundColor->setValue(QColor(c));
130
int Text::backgroundOpacity() const
132
return m_text->m_backgroundOpacity->value().toInt();
134
void Text::setBackgroundOpacity(int o)
136
m_text->m_backgroundOpacity->setValue(o);
139
QColor Text::lineColor() const
141
return m_text->m_lineColor->value().value<QColor>();
143
void Text::setLineColor(const QColor& c)
145
m_text->m_lineColor->setValue(QColor(c));
148
int Text::lineWeight() const
150
return m_text->m_lineWeight->value().toInt();
152
void Text::setLineWeight(int w)
154
m_text->m_lineWeight->setValue(w);
157
int Text::lineStyle() const
159
return m_text->m_lineStyle->value().toInt();
161
void Text::setLineStyle(int s)
163
if (s < 0 || s > 5) {
166
m_text->m_lineStyle->setValue(s);
169
QPointF Text::position() const
171
return m_text->m_pos.toPoint();
173
void Text::setPosition(const QPointF& p)
175
m_text->m_pos.setPointPos(p);
178
QSizeF Text::size() const
180
return m_text->m_size.toPoint();
182
void Text::setSize(const QSizeF& s)
184
m_text->m_size.setPointSize(s);
187
void Text::loadFromFile(const QString &fn)
190
//kreportpluginDebug() << "Loading from" << fn;
191
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
192
m_text->m_controlSource->setValue(tr("$Unable to read %1").arg(fn));
195
QTextStream in(&file);
196
QString data = in.readAll();
198
while (!in.atEnd()) {
199
QString line = in.readLine();
202
m_text->m_controlSource->setValue(QVariant(QLatin1String("$") + data));