KReport

KReportScriptLabel.cpp
1 /* This file is part of the KDE project
2  * Copyright (C) 2007-2008 by Adam Pigg ([email protected])
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 
18 #include "KReportScriptLabel.h"
19 
20 #include <QSizeF>
21 #include <QPointF>
22 
23 namespace Scripting
24 {
25 Label::Label(KReportItemLabel *l)
26 {
27  m_label = l;
28 }
29 
30 
31 Label::~Label()
32 {
33 }
34 
35 QString Label::caption() const
36 {
37  return m_label->text();
38 }
39 
40 void Label::setCaption(const QString& c)
41 {
42  m_label->setText(c);
43 }
44 
45 int Label::horizontalAlignment() const
46 {
47  const QString a = m_label->m_horizontalAlignment->value().toString().toLower();
48 
49  if (a == QLatin1String("left")) {
50  return -1;
51  }
52  if (a == QLatin1String("center")) {
53  return 0;
54  }
55  if (a == QLatin1String("right")) {
56  return 1;
57  }
58  return -1;
59 }
60 void Label::setHorizonalAlignment(int a)
61 {
62  switch (a) {
63  case -1:
64  m_label->m_horizontalAlignment->setValue(QLatin1String("left"));
65  break;
66  case 0:
67  m_label->m_horizontalAlignment->setValue(QLatin1String("center"));
68  break;
69  case 1:
70  m_label->m_horizontalAlignment->setValue(QLatin1String("right"));
71  break;
72  default:
73  m_label->m_horizontalAlignment->setValue(QLatin1String("left"));
74  break;
75  }
76 }
77 
78 int Label::verticalAlignment() const
79 {
80  const QString a = m_label->m_horizontalAlignment->value().toString().toLower();
81 
82  if (a == QLatin1String("top")) {
83  return -1;
84  }
85  if (a == QLatin1String("middle")) {
86  return 0;
87  }
88  if (a == QLatin1String("bottom")) {
89  return 1;
90  }
91  return -1;
92 }
93 void Label::setVerticalAlignment(int a)
94 {
95  switch (a) {
96  case -1:
97  m_label->m_verticalAlignment->setValue(QLatin1String("top"));
98  break;
99  case 0:
100  m_label->m_verticalAlignment->setValue(QLatin1String("middle"));
101  break;
102  case 1:
103  m_label->m_verticalAlignment->setValue(QLatin1String("bottom"));
104  break;
105  default:
106  m_label->m_verticalAlignment->setValue(QLatin1String("middle"));
107  break;
108  }
109 }
110 
111 QColor Label::backgroundColor() const
112 {
113  return m_label->m_backgroundColor->value().value<QColor>();
114 }
115 void Label::setBackgroundColor(const QColor& c)
116 {
117  m_label->m_backgroundColor->setValue(c);
118 }
119 
120 QColor Label::foregroundColor() const
121 {
122  return m_label->m_foregroundColor->value().value<QColor>();
123 }
124 void Label::setForegroundColor(const QColor& c)
125 {
126  m_label->m_foregroundColor->setValue(c);
127 }
128 
129 int Label::backgroundOpacity() const
130 {
131  return m_label->m_backgroundOpacity->value().toInt();
132 }
133 void Label::setBackgroundOpacity(int o)
134 {
135  m_label->m_backgroundOpacity->setValue(o);
136 }
137 
138 QColor Label::lineColor() const
139 {
140  return m_label->m_lineColor->value().value<QColor>();
141 }
142 void Label::setLineColor(const QColor& c)
143 {
144  m_label->m_lineColor->setValue(c);
145 }
146 
147 int Label::lineWeight() const
148 {
149  return m_label->m_lineWeight->value().toInt();
150 }
151 void Label::setLineWeight(int w)
152 {
153  m_label->m_lineWeight->setValue(w);
154 }
155 
156 int Label::lineStyle() const
157 {
158  return m_label->m_lineStyle->value().toInt();
159 }
160 void Label::setLineStyle(int s)
161 {
162  if (s < 0 || s > 5) {
163  s = 1;
164  }
165  m_label->m_lineStyle->setValue(s);
166 }
167 
168 QPointF Label::position() const
169 {
170  return m_label->position();
171 }
172 void Label::setPosition(const QPointF &p)
173 {
174  m_label->setPosition(p);
175 }
176 
177 QSizeF Label::size() const
178 {
179  return m_label->size();
180 }
181 void Label::setSize(const QSizeF &s)
182 {
183  m_label->setSize(s);
184 }
185 }
186 
int value() const const
QString toLower() const const
Field item script interface.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:17:37 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.