[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] plugins/reporting/web: Initial implementation of the
From:       Jaroslaw Staniek <staniek () kde ! org>
Date:       2011-09-30 22:30:28
Message-ID: 20110930223028.96A1BA60C9 () git ! kde ! org
[Download RAW message or body]

Git commit a83f505530864fea6687b892476a3d025f179882 by Jaroslaw Staniek, on behalf of \
Adam Pigg. Committed on 29/09/2011 at 19:41.
Pushed by staniek into branch 'master'.

Initial implementation of the async item interface for the web item.  Also implements \
loading and saving, and painting of a simple box where the item is in the designer.  \
Needs improvement.

M  +13   -1    plugins/reporting/web/KoReportDesignerItemWeb.cpp
M  +44   -28   plugins/reporting/web/KoReportItemWeb.cpp
M  +9    -4    plugins/reporting/web/KoReportItemWeb.h

http://commits.kde.org/calligra/a83f505530864fea6687b892476a3d025f179882

diff --git a/plugins/reporting/web/KoReportDesignerItemWeb.cpp \
b/plugins/reporting/web/KoReportDesignerItemWeb.cpp index 3a24529..e29a70c 100644
--- a/plugins/reporting/web/KoReportDesignerItemWeb.cpp
+++ b/plugins/reporting/web/KoReportDesignerItemWeb.cpp
@@ -57,6 +57,10 @@ KoReportDesignerItemWeb::KoReportDesignerItemWeb(KoReportDesigner \
*rw, QGraphics  init(scene);
     m_size.setSceneSize(QSizeF(100, 100));
     m_pos.setScenePos(pos);
+    
+    setSceneRect(m_pos.toScene(), m_size.toScene());
+    
+    kDebug() << m_size.toScene() << m_pos.toScene();
     m_name->setValue(m_reportDesigner->suggestEntityName("web"));
 }
 
@@ -90,7 +94,14 @@ void KoReportDesignerItemWeb::paint(QPainter *painter, const \
KoViewConverter &co  //    qreal cz = target.width() / size().width();
 //    m_webPage->mainFrame()->setZoomFactor(m_zoom * cz);
 //    m_webPage->mainFrame()->setScrollPosition(m_scrollPosition.toPoint());
+    m_webPage->mainFrame()->load(QUrl("http://www.google.com"));
     m_webPage->mainFrame()->render(painter);
+    
+    kDebug() << QGraphicsRectItem::rect();
+    
+    painter->drawRect(QGraphicsRectItem::rect());
+    
+    drawHandles(painter);
 }
 
 void KoReportDesignerItemWeb::buildXML(QDomDocument &doc, QDomElement &parent)
@@ -99,10 +110,11 @@ void KoReportDesignerItemWeb::buildXML(QDomDocument &doc, \
QDomElement &parent)  QDomElement entity = doc.createElement("report:web");
 
     // properties
-    addPropertyAsAttribute(&entity, url);
+    //addPropertyAsAttribute(&entity, url);
     addPropertyAsAttribute(&entity, m_controlSource);
     entity.setAttribute("report:z-index", zValue());
     buildXMLRect(doc, entity, &m_pos, &m_size);
+    parent.appendChild(entity);
 }
 
 void KoReportDesignerItemWeb::slotPropertyChanged(KoProperty::Set &s, \
                KoProperty::Property &p)
diff --git a/plugins/reporting/web/KoReportItemWeb.cpp \
b/plugins/reporting/web/KoReportItemWeb.cpp index e055008..69dcc98 100644
--- a/plugins/reporting/web/KoReportItemWeb.cpp
+++ b/plugins/reporting/web/KoReportItemWeb.cpp
@@ -37,7 +37,7 @@
 #include <QtGui/QWidget>
 #include <QtGui/QApplication>
 
-KoReportItemWeb::KoReportItemWeb(): m_loaded(false)
+KoReportItemWeb::KoReportItemWeb(): m_rendering(false)
 {
     createProperties();
     init();
@@ -65,12 +65,7 @@ KoReportItemWeb::KoReportItemWeb(QDomNode &element)
 void KoReportItemWeb::init()
 {
     m_webPage = new QWebPage();
-    connect(m_webPage, SIGNAL(loadFinished(bool)),
-            this, SLOT(loadFinished(bool)));
-    //connect(m_webPage, SIGNAL(loadFinished(bool)),
-    //        this, \
                SLOT(render(OROPage*,OROSection*,QPointF,QVariant,KRScriptHandler)));
-    //setUrl("http://www.kde.org");
-    m_webImage = new QImage(m_size.toScene().toSize(), QImage::Format_ARGB32);
+    connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
 }
 
 void KoReportItemWeb::createProperties()
@@ -102,35 +97,56 @@ void KoReportItemWeb::setUrl(const QString &url)
 }
 
 void KoReportItemWeb::loadFinished(bool)
-{
-    m_loaded = true;
+{       
+    kDebug () << m_rendering;
+    if (m_rendering) {
+        OROPicture * pic = new OROPicture();
+        m_webPage->setViewportSize(m_webPage->mainFrame()->contentsSize());
+            
+        QPainter p(pic->picture());
+        
+        m_webPage->mainFrame()->render(&p);
+        
+        QPointF pos = m_pos.toScene();
+        QSizeF size = m_size.toScene();
+        
+        pos += m_targetOffset;
+        
+        pic->setPosition(pos);
+        pic->setSize(size);
+        if (m_targetPage) m_targetPage->addPrimitive(pic);
+        
+        OROPicture *p2 = dynamic_cast<OROPicture*>(pic->clone());
+        p2->setPosition(m_pos.toPoint());
+        if (m_targetSection) m_targetSection->addPrimitive(p2);
+    
+        m_rendering = false;
+        emit(finishedRendering());
+    }
 }
 
 int KoReportItemWeb::render(OROPage *page, OROSection *section,  QPointF offset,
                             QVariant data, KRScriptHandler *script)
 {
-    Q_UNUSED(section);
-    Q_UNUSED(data);
     Q_UNUSED(script);
-
-    QPainter painter(m_webImage);
-    m_webPage->mainFrame()->render(&painter);
-    painter.end();
-    OROImage *id = new OROImage();
-    id->setImage(*m_webImage);
-    id->setScaled(false);
-    id->setPosition(m_pos.toScene() + offset);
-    id->setSize(m_size.toScene());
-    if (page) {
-        page->addPrimitive(id);
-    }
-
-
-    if (!page) {
-        delete id;
-    }
+ 
+    m_rendering = true;
+    
+    kDebug() << data;
+    
+    m_targetPage = page;
+    m_targetSection = section;
+    m_targetOffset = offset;
+    
+    m_webPage->mainFrame()->load(QUrl(data.toString()));
 
     return 0; //Item doesnt stretch the section height
 }
 
+QString KoReportItemWeb::itemDataSource() const
+{
+    return m_controlSource->value().toString();
+}
+
+
 #include "KoReportItemWeb.moc"
diff --git a/plugins/reporting/web/KoReportItemWeb.h \
b/plugins/reporting/web/KoReportItemWeb.h index 879a8ce..dc160ed 100644
--- a/plugins/reporting/web/KoReportItemWeb.h
+++ b/plugins/reporting/web/KoReportItemWeb.h
@@ -20,7 +20,7 @@
 #ifndef KOREPORTITEMWEB_H
 #define KOREPORTITEMWEB_H
 
-#include <KoReportItemBase.h>
+#include <KoReportASyncItemBase.h>
 #include "krpos.h"
 #include "krsize.h"
 #include "KoReportData.h"
@@ -52,7 +52,7 @@ class Web;
 /**
  @author Shreya Pandit
 */
-class KoReportItemWeb : public KoReportItemBase
+class KoReportItemWeb : public KoReportASyncItemBase
 {
     Q_OBJECT
 public:
@@ -63,7 +63,8 @@ public:
 
     virtual int render(OROPage *page, OROSection *section,  QPointF offset,
                        QVariant data, KRScriptHandler *script);
-    using KoReportItemBase::render;
+   
+    virtual QString itemDataSource() const;
 
 public slots:
     void setUrl(const QString &url);
@@ -73,7 +74,11 @@ private slots:
     void loadFinished(bool);
 private:
     void init();
-    bool m_loaded;
+    bool m_rendering;
+    
+    OROPage *m_targetPage;
+    OROSection *m_targetSection;
+    QPointF m_targetOffset;
 
 protected:
     KoProperty::Property *url;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic