KReport

KReportItemWeb.cpp
1/* This file is part of the KDE project
2 Copyright Shreya Pandit <shreya@shreyapandit.com>
3 Copyright 2011 Adam Pigg <adam@piggz.co.uk>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KReportItemWeb.h"
22#include "KReportUtils.h"
23#include "KReportRenderObjects.h"
24
25#include <KPropertyListData>
26#include <KPropertySet>
27
28#include <QGraphicsRectItem>
29#include <QUrl>
30#include <QWebPage>
31#include <QWebFrame>
32#include <QPainter>
33
34#include "kreportplugin_debug.h"
35
36KReportItemWeb::KReportItemWeb()
37 : m_rendering(false), m_targetPage(nullptr), m_targetSection(nullptr)
38{
39 createProperties();
40 m_webPage = new QWebPage();
41 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
42}
43
44KReportItemWeb::KReportItemWeb(const QDomNode &element)
45 : KReportItemWeb()
46{
47 QDomElement e = element.toElement();
48
49 setItemDataSource(e.attribute(QLatin1String("report:item-data-source")));
50 nameProperty()->setValue(KReportUtils::readNameAttribute(e));
51 setZ(e.attribute(QLatin1String("report:z-index")).toDouble());
52 parseReportRect(e);
53 QDomNodeList nl = element.childNodes();
54 QString n;
55 QDomNode node;
56 for (int i = 0; i < nl.count(); i++) {
57 node = nl.item(i);
58 n = node.nodeName();
59 }
60}
61
62void KReportItemWeb::createProperties()
63{
64 createDataSourceProperty();
65}
66
67KReportItemWeb::~KReportItemWeb()
68{
69}
70
71QString KReportItemWeb::typeName() const
72{
73 return QLatin1String("web");
74}
75
76void KReportItemWeb::loadFinished(bool)
77{
78 //kreportpluginDebug() << m_rendering;
79 if (m_rendering) {
80 OROPicture * pic = new OROPicture();
81 m_webPage->setViewportSize(sceneSize(size()).toSize());
82 m_webPage->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
83 m_webPage->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
84
85 QPainter p(pic->picture());
86
87 m_webPage->mainFrame()->render(&p);
88
90 QSizeF siz = sceneSize(size());
91
92 pos += m_targetOffset;
93
94 pic->setPosition(pos);
95 pic->setSize(siz);
96 if (m_targetPage) m_targetPage->insertPrimitive(pic);
97
98 OROPicture *p2 = dynamic_cast<OROPicture*>(pic->clone());
99 if (p2) {
100 p2->setPosition(scenePosition(position()));
101 if (m_targetSection) {
102 m_targetSection->addPrimitive(p2);
103 }
104 }
105
106 m_rendering = false;
107 emit(finishedRendering());
108 }
109}
110
111int KReportItemWeb::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
112 const QVariant &data, KReportScriptHandler *script)
113{
114 Q_UNUSED(script);
115
116 m_rendering = true;
117
118 //kreportpluginDebug() << data;
119
120 m_targetPage = page;
121 m_targetSection = section;
122 m_targetOffset = offset;
123
124 QUrl url = QUrl::fromUserInput(data.toString());
125 if (url.isValid()) {
126 m_webPage->mainFrame()->load(url);
127 } else {
128 m_webPage->mainFrame()->setHtml(data.toString());
129 }
130
131 return 0; //Item doesn't stretch the section height
132}
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
QPointF position() const
Return the position in points.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
QSizeF size() const
Return the size in points.
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Defines a picture. A picture is different to an image, in that it is drawn using commands.
Represents a single a single row in a document and may contain zero or more OROPrimitives.
QString attribute(const QString &name, const QString &defValue) const const
QDomNodeList childNodes() const const
QString nodeName() const const
QDomElement toElement() const const
int count() const const
QDomNode item(int index) const const
Horizontal
ScrollBarAlwaysOff
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options)
bool isValid() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.