File indexing completed on 2024-05-12 04:43:21
0001 /* This file is part of the KDE project 0002 Copyright Shreya Pandit <shreya@shreyapandit.com> 0003 Copyright 2011 Adam Pigg <adam@piggz.co.uk> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "KReportDesignerItemWeb.h" 0022 #include <KReportDesignerItemBase.h> 0023 #include <KReportDesigner.h> 0024 0025 #include <KProperty> 0026 #include <KPropertySet> 0027 0028 #include <QGraphicsScene> 0029 #include <QGraphicsSceneMouseEvent> 0030 #include <QDomDocument> 0031 #include <QPainter> 0032 #include "kreportplugin_debug.h" 0033 0034 void KReportDesignerItemWeb::init(QGraphicsScene *scene) 0035 { 0036 if (scene) 0037 scene->addItem(this); 0038 0039 connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); 0040 0041 setZValue(z()); 0042 } 0043 0044 KReportDesignerItemWeb::KReportDesignerItemWeb(KReportDesigner *rw, QGraphicsScene *scene, 0045 const QPointF &pos) : KReportDesignerItemRectBase(rw, this) 0046 { 0047 Q_UNUSED(pos); 0048 init(scene); 0049 setSceneRect(properRect(*rw, KREPORT_ITEM_RECT_DEFAULT_WIDTH, KREPORT_ITEM_RECT_DEFAULT_WIDTH)); 0050 nameProperty()->setValue(designer()->suggestEntityName(typeName())); 0051 } 0052 0053 KReportDesignerItemWeb::KReportDesignerItemWeb(const QDomNode &element, KReportDesigner *rw, 0054 QGraphicsScene *scene) 0055 : KReportItemWeb(element), KReportDesignerItemRectBase(rw, this) 0056 { 0057 init(scene); 0058 setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); 0059 } 0060 0061 KReportDesignerItemWeb *KReportDesignerItemWeb::clone() 0062 { 0063 QDomDocument d; 0064 QDomElement e = d.createElement(QLatin1String("clone")); 0065 QDomNode n; 0066 buildXML(&d, &e); 0067 n = e.firstChild(); 0068 return new KReportDesignerItemWeb(n, designer(), nullptr); 0069 } 0070 0071 KReportDesignerItemWeb::~KReportDesignerItemWeb() //done,compared 0072 { 0073 // do we need to clean anything up? 0074 } 0075 0076 void KReportDesignerItemWeb::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) 0077 { 0078 Q_UNUSED(option); 0079 Q_UNUSED(widget); 0080 0081 painter->drawRect(QGraphicsRectItem::rect()); 0082 painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("web-view"))); 0083 0084 painter->setBackgroundMode(Qt::TransparentMode); 0085 0086 drawHandles(painter); 0087 } 0088 0089 void KReportDesignerItemWeb::buildXML(QDomDocument *doc, QDomElement *parent) 0090 { 0091 Q_UNUSED(doc); 0092 Q_UNUSED(parent); 0093 QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); 0094 0095 // properties 0096 addPropertyAsAttribute(&entity, dataSourceProperty()); 0097 addPropertyAsAttribute(&entity, nameProperty()); 0098 entity.setAttribute(QLatin1String("report:z-index"), zValue()); 0099 buildXMLRect(doc, &entity, this); 0100 parent->appendChild(entity); 0101 } 0102 0103 void KReportDesignerItemWeb::slotPropertyChanged(KPropertySet &s, KProperty &p) 0104 { 0105 if (p.name() == "name") { 0106 if (!designer()->isEntityNameUnique(p.value().toString(), this)) { 0107 p.setValue(oldName()); 0108 } 0109 else { 0110 setOldName(p.value().toString()); 0111 } 0112 } 0113 0114 KReportDesignerItemRectBase::propertyChanged(s, p); 0115 if (designer()) { 0116 designer()->setModified(true); 0117 } 0118 }