File indexing completed on 2024-05-19 04:44:33
0001 /* This file is part of the KDE project 0002 Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk) 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KReportLabelPlugin.h" 0021 #include "KReportItemLabel.h" 0022 #include "KReportDesignerItemLabel.h" 0023 #include "KReportDesigner.h" 0024 #include "KReportPluginMetaData.h" 0025 #include "KReportLabelElement.h" 0026 #include "KReportLineStyle.h" 0027 #include "KReportUtils.h" 0028 0029 #ifdef KREPORT_SCRIPTING 0030 #include "KReportScriptLabel.h" 0031 #endif 0032 0033 #include <QDomElement> 0034 0035 K_PLUGIN_CLASS_WITH_JSON(KReportLabelPlugin, "label.json") 0036 0037 KReportLabelPlugin::KReportLabelPlugin(QObject *parent, const QVariantList &args) 0038 : KReportPluginInterface(parent, args) 0039 { 0040 } 0041 0042 KReportLabelPlugin::~KReportLabelPlugin() 0043 { 0044 0045 } 0046 0047 QObject* KReportLabelPlugin::createRendererInstance(const QDomNode &elem) 0048 { 0049 return new KReportItemLabel(elem); 0050 } 0051 0052 QObject* KReportLabelPlugin::createDesignerInstance(KReportDesigner* designer, QGraphicsScene* scene, const QPointF &pos) 0053 { 0054 return new KReportDesignerItemLabel(designer, scene, pos); 0055 } 0056 0057 QObject* KReportLabelPlugin::createDesignerInstance(const QDomNode & element, KReportDesigner *designer, QGraphicsScene * scene) 0058 { 0059 return new KReportDesignerItemLabel(element, designer, scene); 0060 } 0061 0062 KReportElement KReportLabelPlugin::createElement() 0063 { 0064 return KReportLabelElement(); 0065 } 0066 0067 bool KReportLabelPlugin::loadElement(KReportElement *el, const QDomElement &dom, KReportDesignReadingStatus *status) 0068 { 0069 if (!KReportPluginInterface::loadElement(el, dom, status)) { 0070 return false; 0071 } 0072 KReportLabelElement label(*el); 0073 label.setText(KReportUtils::attr(dom, QLatin1String("report:caption"), QString())); 0074 QString s = KReportUtils::attr(dom, QLatin1String("report:horizontal-align"), QString()); 0075 Qt::Alignment alignment = KReportUtils::horizontalAlignment( 0076 s, label.alignment() & Qt::AlignHorizontal_Mask); 0077 s = KReportUtils::attr(dom, QLatin1String("report:vertical-align"), QString()); 0078 alignment |= KReportUtils::verticalAlignment(s, label.alignment() & Qt::AlignVertical_Mask); 0079 label.setAlignment(alignment); 0080 0081 const QDomElement textStyleDom = dom.firstChildElement(QLatin1String("report:text-style")); 0082 QFont font(label.font()); 0083 KReportUtils::readFontAttributes(textStyleDom, &font); 0084 label.setFont(font); 0085 0086 const QDomElement lineStyleDom 0087 = dom.firstChildElement(QLatin1String("report:line-style")); 0088 KReportLineStyle borderStyle(label.borderStyle()); 0089 s = KReportUtils::attr(lineStyleDom, QLatin1String("report:line-style"), QString()); 0090 borderStyle.setPenStyle(KReportUtils::penStyle(s, borderStyle.penStyle())); 0091 borderStyle.setColor(KReportUtils::attr( 0092 lineStyleDom, QLatin1String("report:line-color"), borderStyle.color())); 0093 // border-line-width could be better name but it's too late... 0094 borderStyle.setWeight(KReportUtils::attr( 0095 lineStyleDom, QLatin1String("report:line-weight"), borderStyle.weight())); 0096 label.setBorderStyle(borderStyle); 0097 return true; 0098 } 0099 0100 #ifdef KREPORT_SCRIPTING 0101 QObject* KReportLabelPlugin::createScriptInstance(KReportItemBase *item) 0102 { 0103 KReportItemLabel *label = dynamic_cast<KReportItemLabel*>(item); 0104 if (label) { 0105 return new Scripting::Label(label); 0106 } 0107 return nullptr; 0108 } 0109 #endif 0110 0111 #include "KReportLabelPlugin.moc"