Changeset View
Changeset View
Standalone View
Standalone View
src/items/text/KReportItemText.cpp
Show All 33 Lines | |||||
34 | 34 | | |||
35 | KReportItemText::KReportItemText(const QDomNode & element) : m_bottomPadding(0.0) | 35 | KReportItemText::KReportItemText(const QDomNode & element) : m_bottomPadding(0.0) | ||
36 | { | 36 | { | ||
37 | QDomNodeList nl = element.childNodes(); | 37 | QDomNodeList nl = element.childNodes(); | ||
38 | QString n; | 38 | QString n; | ||
39 | QDomNode node; | 39 | QDomNode node; | ||
40 | 40 | | |||
41 | createProperties(); | 41 | createProperties(); | ||
42 | m_name->setValue(element.toElement().attribute(QLatin1String("report:name"))); | 42 | nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); | ||
43 | m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); | 43 | m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); | ||
44 | m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); | 44 | m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); | ||
45 | Z = element.toElement().attribute(QLatin1String("report:z-index")).toDouble(); | 45 | setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); | ||
46 | m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); | 46 | m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); | ||
47 | m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); | 47 | m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); | ||
48 | m_bottomPadding = element.toElement().attribute(QLatin1String("report:bottom-padding")).toDouble(); | 48 | m_bottomPadding = element.toElement().attribute(QLatin1String("report:bottom-padding")).toDouble(); | ||
49 | 49 | | |||
50 | parseReportRect(element.toElement(), &m_pos, &m_size); | 50 | parseReportRect(element.toElement()); | ||
51 | 51 | | |||
52 | for (int i = 0; i < nl.count(); i++) { | 52 | for (int i = 0; i < nl.count(); i++) { | ||
53 | node = nl.item(i); | 53 | node = nl.item(i); | ||
54 | n = node.nodeName(); | 54 | n = node.nodeName(); | ||
55 | 55 | | |||
56 | if (n == QLatin1String("report:text-style")) { | 56 | if (n == QLatin1String("report:text-style")) { | ||
57 | KRTextStyleData ts; | 57 | KRTextStyleData ts; | ||
58 | if (parseReportTextStyleData(node.toElement(), &ts)) { | 58 | if (parseReportTextStyleData(node.toElement(), &ts)) { | ||
Show All 14 Lines | 72 | } else { | |||
73 | kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; | 73 | kreportpluginWarning() << "while parsing field element encountered unknow element: " << n; | ||
74 | } | 74 | } | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | KReportItemText::~KReportItemText() | 79 | KReportItemText::~KReportItemText() | ||
80 | { | 80 | { | ||
81 | delete m_set; | | |||
82 | } | 81 | } | ||
83 | 82 | | |||
84 | Qt::Alignment KReportItemText::textFlags() const | 83 | Qt::Alignment KReportItemText::textFlags() const | ||
85 | { | 84 | { | ||
86 | Qt::Alignment align; | 85 | Qt::Alignment align; | ||
87 | QString t; | 86 | QString t; | ||
88 | t = m_horizontalAlignment->value().toString(); | 87 | t = m_horizontalAlignment->value().toString(); | ||
89 | if (t == QLatin1String("center")) | 88 | if (t == QLatin1String("center")) | ||
Show All 11 Lines | |||||
101 | else | 100 | else | ||
102 | align |= Qt::AlignTop; | 101 | align |= Qt::AlignTop; | ||
103 | 102 | | |||
104 | return align; | 103 | return align; | ||
105 | } | 104 | } | ||
106 | 105 | | |||
107 | void KReportItemText::createProperties() | 106 | void KReportItemText::createProperties() | ||
108 | { | 107 | { | ||
109 | m_set = new KPropertySet; | | |||
110 | | ||||
111 | //connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) ); | 108 | //connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) ); | ||
112 | 109 | | |||
113 | QStringList keys, strings; | 110 | QStringList keys, strings; | ||
114 | 111 | | |||
115 | //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" ); | 112 | //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" ); | ||
116 | m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); | 113 | m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); | ||
117 | 114 | | |||
118 | m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); | 115 | m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); | ||
Show All 16 Lines | |||||
135 | m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); | 132 | m_lineWeight = new KProperty("line-weight", 1, tr("Line Weight")); | ||
136 | m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); | 133 | m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); | ||
137 | m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); | 134 | m_lineStyle = new KProperty("line-style", QPen(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); | ||
138 | m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); | 135 | m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); | ||
139 | m_backgroundOpacity->setOption("max", 100); | 136 | m_backgroundOpacity->setOption("max", 100); | ||
140 | m_backgroundOpacity->setOption("min", 0); | 137 | m_backgroundOpacity->setOption("min", 0); | ||
141 | m_backgroundOpacity->setOption("unit", QLatin1String("%")); | 138 | m_backgroundOpacity->setOption("unit", QLatin1String("%")); | ||
142 | 139 | | |||
143 | addDefaultProperties(); | 140 | propertySet()->addProperty(m_controlSource); | ||
144 | m_set->addProperty(m_controlSource); | 141 | propertySet()->addProperty(m_itemValue); | ||
145 | m_set->addProperty(m_itemValue); | 142 | propertySet()->addProperty(m_horizontalAlignment); | ||
146 | m_set->addProperty(m_horizontalAlignment); | 143 | propertySet()->addProperty(m_verticalAlignment); | ||
147 | m_set->addProperty(m_verticalAlignment); | 144 | propertySet()->addProperty(m_font); | ||
148 | m_set->addProperty(m_font); | 145 | propertySet()->addProperty(m_backgroundColor); | ||
149 | m_set->addProperty(m_backgroundColor); | 146 | propertySet()->addProperty(m_foregroundColor); | ||
150 | m_set->addProperty(m_foregroundColor); | 147 | propertySet()->addProperty(m_backgroundOpacity); | ||
151 | m_set->addProperty(m_backgroundOpacity); | 148 | propertySet()->addProperty(m_lineWeight); | ||
152 | m_set->addProperty(m_lineWeight); | 149 | propertySet()->addProperty(m_lineColor); | ||
153 | m_set->addProperty(m_lineColor); | 150 | propertySet()->addProperty(m_lineStyle); | ||
154 | m_set->addProperty(m_lineStyle); | | |||
155 | 151 | | |||
156 | } | 152 | } | ||
157 | 153 | | |||
158 | QString KReportItemText::itemDataSource() const | 154 | QString KReportItemText::itemDataSource() const | ||
159 | { | 155 | { | ||
160 | return m_controlSource->value().toString(); | 156 | return m_controlSource->value().toString(); | ||
161 | } | 157 | } | ||
162 | 158 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 207 | if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string | |||
212 | qstrValue = cs.mid(1); | 208 | qstrValue = cs.mid(1); | ||
213 | } else { | 209 | } else { | ||
214 | qstrValue = data.toString(); | 210 | qstrValue = data.toString(); | ||
215 | } | 211 | } | ||
216 | } else { | 212 | } else { | ||
217 | qstrValue = m_itemValue->value().toString(); | 213 | qstrValue = m_itemValue->value().toString(); | ||
218 | } | 214 | } | ||
219 | 215 | | |||
220 | QPointF pos = m_pos.toScene(); | 216 | QPointF pos = scenePosition(position()); | ||
221 | QSizeF size = m_size.toScene(); | 217 | QSizeF siz = sceneSize(size()); | ||
222 | pos += offset; | 218 | pos += offset; | ||
223 | 219 | | |||
224 | QRectF trf(pos, size); | 220 | QRectF trf(pos, siz); | ||
225 | qreal intStretch = trf.top() - offset.y(); | 221 | qreal intStretch = trf.top() - offset.y(); | ||
226 | 222 | | |||
227 | if (qstrValue.length()) { | 223 | if (qstrValue.length()) { | ||
228 | QRectF rect = trf; | 224 | QRectF rect = trf; | ||
229 | 225 | | |||
230 | int pos = 0; | 226 | int pos = 0; | ||
231 | QChar separator; | 227 | QChar separator; | ||
232 | QRegExp re(QLatin1String("\\s")); | 228 | QRegExp re(QLatin1String("\\s")); | ||
233 | QPrinter prnt(QPrinter::HighResolution); | 229 | QPrinter prnt(QPrinter::HighResolution); | ||
234 | QFontMetrics fm(font(), &prnt); | 230 | QFontMetrics fm(font(), &prnt); | ||
235 | 231 | | |||
236 | // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; | 232 | // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; | ||
237 | int intRectWidth = (int)((m_size.toPoint().width() / 72) * prnt.resolution()); | 233 | int intRectWidth = (int)((size().width() / 72) * prnt.resolution()); | ||
238 | int intLineCounter = 0; | 234 | int intLineCounter = 0; | ||
239 | qreal intBaseTop = trf.top(); | 235 | qreal intBaseTop = trf.top(); | ||
240 | qreal intRectHeight = trf.height(); | 236 | qreal intRectHeight = trf.height(); | ||
241 | 237 | | |||
242 | while (qstrValue.length()) { | 238 | while (qstrValue.length()) { | ||
243 | int idx = re.indexIn(qstrValue, pos); | 239 | int idx = re.indexIn(qstrValue, pos); | ||
244 | if (idx == -1) { | 240 | if (idx == -1) { | ||
245 | idx = qstrValue.length(); | 241 | idx = qstrValue.length(); | ||
Show All 23 Lines | 248 | if (separator == QLatin1Char('\n')) { | |||
269 | tb->setLineStyle(lineStyle()); | 265 | tb->setLineStyle(lineStyle()); | ||
270 | 266 | | |||
271 | if (page) { | 267 | if (page) { | ||
272 | page->addPrimitive(tb); | 268 | page->addPrimitive(tb); | ||
273 | } | 269 | } | ||
274 | 270 | | |||
275 | if (section) { | 271 | if (section) { | ||
276 | OROTextBox *tb2 = dynamic_cast<OROTextBox*>(tb->clone()); | 272 | OROTextBox *tb2 = dynamic_cast<OROTextBox*>(tb->clone()); | ||
277 | tb2->setPosition(m_pos.toPoint()); | 273 | tb2->setPosition(scenePosition(position())); | ||
278 | section->addPrimitive(tb2); | 274 | section->addPrimitive(tb2); | ||
279 | } | 275 | } | ||
280 | 276 | | |||
281 | if (!page) { | 277 | if (!page) { | ||
282 | delete tb; | 278 | delete tb; | ||
283 | } | 279 | } | ||
284 | 280 | | |||
285 | intStretch += intRectHeight; | 281 | intStretch += intRectHeight; | ||
Show All 34 Lines |