KReport

KReportScriptText.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17#include "KReportScriptText.h"
18
19#include <QFile>
20#include <QTextStream>
21#include <QSizeF>
22#include <QPointF>
23
24#include "kreportplugin_debug.h"
25
26namespace Scripting
27{
28
29Text::Text(KReportItemText* t)
30{
31 m_text = t;
32}
33
34
35Text::~Text()
36{
37}
38
40{
41 return m_text->itemDataSource();
42}
43
45{
46 m_text->setItemDataSource(s);
47}
48
50{
51 const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
52
53 if (a == QLatin1String("left")) {
54 return -1;
55 }
56 if (a == QLatin1String("center")) {
57 return 0;
58 }
59 if (a == QLatin1String("right")) {
60 return 1;
61 }
62 return -1;
63}
65{
66 switch (a) {
67 case -1:
68 m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
69 break;
70 case 0:
71 m_text->m_horizontalAlignment->setValue(QLatin1String("center"));
72 break;
73 case 1:
74 m_text->m_horizontalAlignment->setValue(QLatin1String("right"));
75 break;
76 default:
77 m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
78 break;
79 }
80}
81
83{
84 const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
85
86 if (a == QLatin1String("top")) {
87 return -1;
88 }
89 if (a == QLatin1String("middle")) {
90 return 0;
91 }
92 if (a == QLatin1String("bottom")) {
93 return 1;
94 }
95 return -1;
96}
98{
99 switch (a) {
100 case -1:
101 m_text->m_verticalAlignment->setValue(QLatin1String("top"));
102 break;
103 case 0:
104 m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
105 break;
106 case 1:
107 m_text->m_verticalAlignment->setValue(QLatin1String("bottom"));
108 break;
109 default:
110 m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
111 break;
112 }
113}
114
116{
117 return m_text->m_backgroundColor->value().value<QColor>();
118}
120{
121 m_text->m_backgroundColor->setValue(QColor(c));
122}
123
125{
126 return m_text->m_foregroundColor->value().value<QColor>();
127}
129{
130 m_text->m_foregroundColor->setValue(QColor(c));
131}
132
134{
135 return m_text->m_backgroundOpacity->value().toInt();
136}
138{
139 m_text->m_backgroundOpacity->setValue(o);
140}
141
143{
144 return m_text->m_lineColor->value().value<QColor>();
145}
147{
148 m_text->m_lineColor->setValue(QColor(c));
149}
150
152{
153 return m_text->m_lineWeight->value().toInt();
154}
156{
157 m_text->m_lineWeight->setValue(w);
158}
159
161{
162 return m_text->m_lineStyle->value().toInt();
163}
165{
166 if (s < 0 || s > 5) {
167 s = 1;
168 }
169 m_text->m_lineStyle->setValue(s);
170}
171
173{
174 return m_text->position();
175}
177{
178 m_text->setPosition(p);
179}
180
182{
183 return m_text->size();
184}
185void Text::setSize(const QSizeF& s)
186{
187 m_text->setSize(s);
188}
189
190bool Text::loadFromFile(const QString &fileName)
191{
192 QFile file(fileName);
193 //kreportpluginDebug() << "Loading from" << fn;
195 kreportpluginWarning() << "Failed to load value for text element from file" << fileName;
196 return false;
197 }
198 QTextStream in(&file);
199 QString data = in.readAll();
200 /*
201 while (!in.atEnd()) {
202 QString line = in.readLine();
203 process_line(line);
204 }*/
205 m_text->m_itemValue->setValue(data);
206 return true;
207}
208
209}
int backgroundOpacity() const
int horizontalAlignment() const
void setLineWeight(int)
Sets the border line weight (thickness) of the text-item.
QColor foregroundColor() const
void setBackgroundColor(const QColor &)
Set the background color of the text-item to the given color.
QString source() const
void setVerticalAlignment(int)
Sets the vertical alignment Valid values for aligmnt are top: -1, middle: 0, bottom: 1.
void setPosition(const QPointF &)
Sets the position of the text-item to the given point coordinates.
void setHorizonalAlignment(int)
Sets the horizontal alignment Valid values for alignment are left: -1, center: 0, right; 1.
void setSource(const QString &s)
Sets the data source for the text element.
void setBackgroundOpacity(int)
Sets the background opacity of the text-item Valid values are in the range 0-100.
void setLineStyle(int)
Sets the border line style of the text-item to the given style in the range 0-5.
void setLineColor(const QColor &)
Sets the border line color of the text-item to the given color.
QColor lineColor() const
bool loadFromFile(const QString &fileName)
Load the contents for the text item from the given file.
QColor backgroundColor() const
int verticalAlignment() const
void setSize(const QSizeF &)
Sets the size of the text-item to the given size in points.
void setForegroundColor(const QColor &)
Sets the foreground (text) color of the text-item to the given color.
QPointF position() const
Field item script interface.
int value() const const
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
QString toLower() const const
QString readAll()
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:54:26 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.