~ubuntu-branches/debian/sid/calligraplan/sid

« back to all changes in this revision

Viewing changes to src/libs/ui/reports/items/text/PlanReportScriptText.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2018-02-01 18:20:19 UTC
  • Revision ID: package-import@ubuntu.com-20180201182019-1qo7qaim5wejm5k9
Tags: upstream-3.1.0
ImportĀ upstreamĀ versionĀ 3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
#include "PlanReportScriptText.h"
 
19
 
 
20
#include <QFile>
 
21
#include <QTextStream>
 
22
 
 
23
namespace Scripting
 
24
{
 
25
 
 
26
Text::Text(PlanReportItemText* t)
 
27
{
 
28
    m_text = t;
 
29
}
 
30
 
 
31
 
 
32
Text::~Text()
 
33
{
 
34
}
 
35
 
 
36
QString Text::source() const
 
37
{
 
38
    return m_text->itemDataSource();
 
39
}
 
40
 
 
41
void Text::setSource(const QString& s)
 
42
{
 
43
    m_text->m_controlSource->setValue(s);
 
44
}
 
45
 
 
46
int Text::horizontalAlignment() const
 
47
{
 
48
    const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
 
49
 
 
50
    if (a == QLatin1String("left")) {
 
51
        return -1;
 
52
    }
 
53
    if (a == QLatin1String("center")) {
 
54
        return 0;
 
55
    }
 
56
    if (a == QLatin1String("right")) {
 
57
        return 1;
 
58
    }
 
59
    return -1;
 
60
}
 
61
void Text::setHorizonalAlignment(int a)
 
62
{
 
63
    switch (a) {
 
64
    case -1:
 
65
        m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
 
66
        break;
 
67
    case 0:
 
68
        m_text->m_horizontalAlignment->setValue(QLatin1String("center"));
 
69
        break;
 
70
    case 1:
 
71
        m_text->m_horizontalAlignment->setValue(QLatin1String("right"));
 
72
        break;
 
73
    default:
 
74
        m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
 
75
        break;
 
76
    }
 
77
}
 
78
 
 
79
int Text::verticalAlignment() const
 
80
{
 
81
    const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
 
82
 
 
83
    if (a == QLatin1String("top")) {
 
84
        return -1;
 
85
    }
 
86
    if (a == QLatin1String("middle")) {
 
87
        return 0;
 
88
    }
 
89
    if (a == QLatin1String("bottom")) {
 
90
        return 1;
 
91
    }
 
92
    return -1;
 
93
}
 
94
void Text::setVerticalAlignment(int a)
 
95
{
 
96
    switch (a) {
 
97
    case -1:
 
98
        m_text->m_verticalAlignment->setValue(QLatin1String("top"));
 
99
        break;
 
100
    case 0:
 
101
        m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
 
102
        break;
 
103
    case 1:
 
104
        m_text->m_verticalAlignment->setValue(QLatin1String("bottom"));
 
105
        break;
 
106
    default:
 
107
        m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
 
108
        break;
 
109
    }
 
110
}
 
111
 
 
112
QColor Text::backgroundColor() const
 
113
{
 
114
    return m_text->m_backgroundColor->value().value<QColor>();
 
115
}
 
116
void Text::setBackgroundColor(const QColor& c)
 
117
{
 
118
    m_text->m_backgroundColor->setValue(QColor(c));
 
119
}
 
120
 
 
121
QColor Text::foregroundColor() const
 
122
{
 
123
    return m_text->m_foregroundColor->value().value<QColor>();
 
124
}
 
125
void Text::setForegroundColor(const QColor& c)
 
126
{
 
127
    m_text->m_foregroundColor->setValue(QColor(c));
 
128
}
 
129
 
 
130
int Text::backgroundOpacity() const
 
131
{
 
132
    return m_text->m_backgroundOpacity->value().toInt();
 
133
}
 
134
void Text::setBackgroundOpacity(int o)
 
135
{
 
136
    m_text->m_backgroundOpacity->setValue(o);
 
137
}
 
138
 
 
139
QColor Text::lineColor() const
 
140
{
 
141
    return m_text->m_lineColor->value().value<QColor>();
 
142
}
 
143
void Text::setLineColor(const QColor& c)
 
144
{
 
145
    m_text->m_lineColor->setValue(QColor(c));
 
146
}
 
147
 
 
148
int Text::lineWeight() const
 
149
{
 
150
    return m_text->m_lineWeight->value().toInt();
 
151
}
 
152
void Text::setLineWeight(int w)
 
153
{
 
154
    m_text->m_lineWeight->setValue(w);
 
155
}
 
156
 
 
157
int Text::lineStyle() const
 
158
{
 
159
    return m_text->m_lineStyle->value().toInt();
 
160
}
 
161
void Text::setLineStyle(int s)
 
162
{
 
163
    if (s < 0 || s > 5) {
 
164
        s = 1;
 
165
    }
 
166
    m_text->m_lineStyle->setValue(s);
 
167
}
 
168
 
 
169
QPointF Text::position() const
 
170
{
 
171
    return m_text->m_pos.toPoint();
 
172
}
 
173
void Text::setPosition(const QPointF& p)
 
174
{
 
175
    m_text->m_pos.setPointPos(p);
 
176
}
 
177
 
 
178
QSizeF Text::size() const
 
179
{
 
180
    return m_text->m_size.toPoint();
 
181
}
 
182
void Text::setSize(const QSizeF& s)
 
183
{
 
184
    m_text->m_size.setPointSize(s);
 
185
}
 
186
 
 
187
void Text::loadFromFile(const QString &fn)
 
188
{
 
189
    QFile file(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));
 
193
        return;
 
194
    }
 
195
    QTextStream in(&file);
 
196
    QString data = in.readAll();
 
197
    /*
 
198
    while (!in.atEnd()) {
 
199
      QString line = in.readLine();
 
200
      process_line(line);
 
201
    }*/
 
202
    m_text->m_controlSource->setValue(QVariant(QLatin1String("$") + data));
 
203
}
 
204
 
 
205
}