KReport

KReportLabelPlugin.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2010 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 Library 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  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "KReportLabelPlugin.h"
21 #include "KReportItemLabel.h"
22 #include "KReportDesignerItemLabel.h"
23 #include "KReportDesigner.h"
24 #include "KReportPluginMetaData.h"
25 #include "KReportLabelElement.h"
26 #include "KReportLineStyle.h"
27 #include "KReportUtils.h"
28 
29 #ifdef KREPORT_SCRIPTING
30 #include "KReportScriptLabel.h"
31 #endif
32 
33 #include <QDomElement>
34 
35 K_PLUGIN_CLASS_WITH_JSON(KReportLabelPlugin, "label.json")
36 
37 KReportLabelPlugin::KReportLabelPlugin(QObject *parent, const QVariantList &args)
38  : KReportPluginInterface(parent, args)
39 {
40 }
41 
42 KReportLabelPlugin::~KReportLabelPlugin()
43 {
44 
45 }
46 
47 QObject* KReportLabelPlugin::createRendererInstance(const QDomNode &elem)
48 {
49  return new KReportItemLabel(elem);
50 }
51 
52 QObject* KReportLabelPlugin::createDesignerInstance(KReportDesigner* designer, QGraphicsScene* scene, const QPointF &pos)
53 {
54  return new KReportDesignerItemLabel(designer, scene, pos);
55 }
56 
57 QObject* KReportLabelPlugin::createDesignerInstance(const QDomNode & element, KReportDesigner *designer, QGraphicsScene * scene)
58 {
59  return new KReportDesignerItemLabel(element, designer, scene);
60 }
61 
62 KReportElement KReportLabelPlugin::createElement()
63 {
64  return KReportLabelElement();
65 }
66 
67 bool KReportLabelPlugin::loadElement(KReportElement *el, const QDomElement &dom, KReportDesignReadingStatus *status)
68 {
69  if (!KReportPluginInterface::loadElement(el, dom, status)) {
70  return false;
71  }
73  label.setText(KReportUtils::attr(dom, QLatin1String("report:caption"), QString()));
74  QString s = KReportUtils::attr(dom, QLatin1String("report:horizontal-align"), QString());
75  Qt::Alignment alignment = KReportUtils::horizontalAlignment(
76  s, label.alignment() & Qt::AlignHorizontal_Mask);
77  s = KReportUtils::attr(dom, QLatin1String("report:vertical-align"), QString());
78  alignment |= KReportUtils::verticalAlignment(s, label.alignment() & Qt::AlignVertical_Mask);
79  label.setAlignment(alignment);
80 
81  const QDomElement textStyleDom = dom.firstChildElement(QLatin1String("report:text-style"));
82  QFont font(label.font());
83  KReportUtils::readFontAttributes(textStyleDom, &font);
84  label.setFont(font);
85 
86  const QDomElement lineStyleDom
87  = dom.firstChildElement(QLatin1String("report:line-style"));
88  KReportLineStyle borderStyle(label.borderStyle());
89  s = KReportUtils::attr(lineStyleDom, QLatin1String("report:line-style"), QString());
90  borderStyle.setPenStyle(KReportUtils::penStyle(s, borderStyle.penStyle()));
91  borderStyle.setColor(KReportUtils::attr(
92  lineStyleDom, QLatin1String("report:line-color"), borderStyle.color()));
93  // border-line-width could be better name but it's too late...
94  borderStyle.setWeight(KReportUtils::attr(
95  lineStyleDom, QLatin1String("report:line-weight"), borderStyle.weight()));
96  label.setBorderStyle(borderStyle);
97  return true;
98 }
99 
100 #ifdef KREPORT_SCRIPTING
101 QObject* KReportLabelPlugin::createScriptInstance(KReportItemBase *item)
102 {
103  KReportItemLabel *label = dynamic_cast<KReportItemLabel*>(item);
104  if (label) {
105  return new Scripting::Label(label);
106  }
107  return nullptr;
108 }
109 #endif
110 
111 #include "KReportLabelPlugin.moc"
Base class for items that are drawn syncronously.
typedef Alignment
The KReportLineStyle class represents line style.
The KReportDesignReadStatus represents status of reading a report design in .kreport format.
Definition: KReportDesign.h:35
Q_SCRIPTABLE CaptureState status()
QDomElement firstChildElement(const QString &tagName) const const
QString label(StandardShortcut id)
The KReportLabelElement class represents a label element of a report design.
The KReportElement class represents a functional visual element of a report design.
The ReportDesigner is the main widget for designing a report.
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
An interface for plugins delivering KReport elements.
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.