Stefano Verzegnassi has proposed merging lp:~verzegnassi-stefano/ubuntu-docviewer-app/lo-tileitem-class-code into lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-tiled-rendering.
Commit message: * Improved code consistency for TileItem class. * Removed the unnecessary painter->eraseRect() from the paint function of LOView Requested reviews: Ubuntu Document Viewer Developers (ubuntu-docviewer-dev) For more details, see: https://code.launchpad.net/~verzegnassi-stefano/ubuntu-docviewer-app/lo-tileitem-class-code/+merge/264550 * Improved code consistency for TileItem class. * Removed the unnecessary painter->eraseRect() from the paint function of LOView -- Your team Ubuntu Document Viewer Developers is requested to review the proposed merge of lp:~verzegnassi-stefano/ubuntu-docviewer-app/lo-tileitem-class-code into lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-tiled-rendering.
=== modified file 'po/com.ubuntu.docviewer.pot' --- po/com.ubuntu.docviewer.pot 2015-07-04 16:00:33 +0000 +++ po/com.ubuntu.docviewer.pot 2015-07-13 12:40:41 +0000 @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-07-04 17:57+0200\n" +"POT-Creation-Date: 2015-07-12 21:23+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <[email protected]>\n" @@ -33,7 +33,7 @@ msgstr "" #: ../src/app/docviewer-application.cpp:171 -#: /home/stefano/Progetti/docviewer/build-lo-tile-rendering-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:1 +#: /home/stefano/Progetti/docviewer/Libreoffice/build-lo-tiled-rendering-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:1 msgid "Document Viewer" msgstr "" @@ -414,6 +414,6 @@ msgid "Open" msgstr "" -#: /home/stefano/Progetti/docviewer/build-lo-tile-rendering-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:2 +#: /home/stefano/Progetti/docviewer/Libreoffice/build-lo-tiled-rendering-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:2 msgid "documents;viewer;pdf;reader;" msgstr "" === modified file 'src/plugin/libreofficetoolkit-qml-plugin/loview.cpp' --- src/plugin/libreofficetoolkit-qml-plugin/loview.cpp 2015-07-12 21:26:48 +0000 +++ src/plugin/libreofficetoolkit-qml-plugin/loview.cpp 2015-07-13 12:40:41 +0000 @@ -48,17 +48,17 @@ { // qDebug() << "Painting new tiles..."; - // Clean area outside the visible one - painter->eraseRect(QRect(0, 0, m_visibleArea.right(), m_visibleArea.top())); // TOP - painter->eraseRect(QRect(m_visibleArea.left(), m_visibleArea.bottom(), m_visibleArea.right(), this->height() - m_visibleArea.bottom())); // BOTTOM - painter->eraseRect(QRect(0, m_visibleArea.top(), m_visibleArea.left(), m_visibleArea.height())); // LEFT - painter->eraseRect(QRect(m_visibleArea.right(), m_visibleArea.top(), this->width() - m_visibleArea.right(), m_visibleArea.height())); // RIGHT - Q_FOREACH(TileItem* tile, m_tiles) { +<<<<<<< TREE // if (!tile->painted) { painter->drawImage(tile->area, tile->texture); // painter->drawRect(tile->area); // Uncomment to see tile borders. tile->painted = true; +======= + // if (!tile->painted) { + painter->drawImage(tile->area(), tile->texture()); + tile->setPainted(true); +>>>>>>> MERGE-SOURCE //} } } @@ -167,7 +167,7 @@ // Delete tiles that are outside the loading area auto b = m_tiles.begin(); while (b != m_tiles.end()) { - if (!loadingArea.intersects(b.value()->area)) { + if (!loadingArea.intersects(b.value()->area())) { qDebug() << "Removing tile indexed as" << b.key(); b.value()->releaseTexture(); b = m_tiles.erase(b); @@ -195,14 +195,16 @@ if (!m_tiles.contains(index)) { qDebug() << "Creating tile" << x << "x" << y; - TileItem* tile = new TileItem(tileRect, m_document); + + auto tile = new TileItem(tileRect, m_document); + tile->requestTexture(); // Append the tile in the map m_tiles.insert(index, tile); // Connect the tile to the QQuickPaintedItem's update() slot, so the tile is immediately painted. qDebug() << "Connecting tile" << x << "x" << y; - connect(tile, SIGNAL(textureUpdated()), this, SLOT(update())); + connect(tile, SIGNAL(textureChanged()), this, SLOT(update())); } else { // Just some debugging qDebug() << "tile" << x << "x" << y << "already exists"; === modified file 'src/plugin/libreofficetoolkit-qml-plugin/tileitem.cpp' --- src/plugin/libreofficetoolkit-qml-plugin/tileitem.cpp 2015-07-04 16:00:33 +0000 +++ src/plugin/libreofficetoolkit-qml-plugin/tileitem.cpp 2015-07-13 12:40:41 +0000 @@ -26,54 +26,137 @@ * TileItem class * ******************/ -TileItem::TileItem(QRect a, LODocument *doc) - : painted(false) -{ - area = a; - - RenderTask* task = new RenderTask(area, doc); +TileItem::TileItem(QRect area, LODocument *document) + : m_painted(false) + , m_document(nullptr) +{ + this->setArea(area); + this->setDocument(document); +} + +// Destructor +TileItem::~TileItem() +{ + this->releaseTexture(); +} + +QRect TileItem::area() const +{ + return m_area; +} + +void TileItem::setArea(QRect &area) +{ + if (m_area == area) + return; + + m_area = area; + Q_EMIT areaChanged(); +} + +QImage TileItem::texture() const +{ + return m_texture; +} + +bool TileItem::isPainted() const +{ + return m_painted; +} + +void TileItem::setPainted(bool isPainted) +{ + if (m_painted == isPainted) + return; + + m_painted = isPainted; + Q_EMIT isPaintedChanged(); +} + +LODocument* TileItem::document() const +{ + return m_document; +} + +void TileItem::setDocument(LODocument* document) +{ + if (m_document == document) + return; + + m_document = document; + Q_EMIT documentChanged(); +} + +void TileItem::requestTexture() +{ + auto task = new RenderTask(this->area(), this->document()); connect(task, SIGNAL(renderCompleted(QImage)), this, SLOT(updateTexture(QImage))); task->setAutoDelete(true); QThreadPool::globalInstance()->start(task); } -// Destructor -TileItem::~TileItem() -{ - this->releaseTexture(); -} - // Free memory used by the texture void TileItem::releaseTexture() { - if (texture.isNull()) + if (m_texture.isNull()) return; - texture = QImage(); + m_texture = QImage(); + Q_EMIT textureChanged(); } // This is a slot, connect to renderCompleted() signal from RenderTask class. void TileItem::updateTexture(QImage t) { - qDebug() << "Updating texture"; - texture = t; - Q_EMIT textureUpdated(); + m_texture = t; + Q_EMIT textureChanged(); } /* ****************** * RenderTask class * ********************/ -RenderTask::RenderTask(QRect area, LODocument *doc) -{ - m_document = doc; +RenderTask::RenderTask(QRect area, LODocument *document) +{ + this->setArea(area); + this->setDocument(document); +} + + +QRect RenderTask::area() const +{ + return m_area; +} + +void RenderTask::setArea(QRect &area) +{ + if (m_area == area) + return; + m_area = area; + Q_EMIT areaChanged(); +} + +LODocument* RenderTask::document() const +{ + return m_document; +} + +void RenderTask::setDocument(LODocument* document) +{ + if (m_document == document) + return; + + m_document = document; + Q_EMIT documentChanged(); } // Render the texture for this tile. void RenderTask::run() { - QImage render = m_document->paintTile(m_area.size(), m_area); + QImage render = this->document()->paintTile(this->area().size(), + this->area()); + Q_EMIT renderCompleted(render); } === modified file 'src/plugin/libreofficetoolkit-qml-plugin/tileitem.h' --- src/plugin/libreofficetoolkit-qml-plugin/tileitem.h 2015-07-04 16:00:33 +0000 +++ src/plugin/libreofficetoolkit-qml-plugin/tileitem.h 2015-07-13 12:40:41 +0000 @@ -29,22 +29,39 @@ Q_OBJECT public: - TileItem(QRect a, LODocument* doc); + TileItem(QRect area, LODocument* document); ~TileItem(); + QRect area() const; + void setArea(QRect &area); + + QImage texture() const; + + bool isPainted() const; + void setPainted(bool isPainted); + + LODocument* document() const; + void setDocument(LODocument* document); + +public Q_SLOTS: + void requestTexture(); void releaseTexture(); - QRect area; - QImage texture; - bool painted; - - LODocument* document; - Q_SIGNALS: - void textureUpdated(); + void areaChanged(); + void textureChanged(); + void isPaintedChanged(); + void documentChanged(); private Q_SLOTS: void updateTexture(QImage t); + +private: + QRect m_area; + QImage m_texture; + bool m_painted; + + LODocument* m_document; }; class RenderTask : public QObject, public QRunnable @@ -52,10 +69,19 @@ Q_OBJECT public: - RenderTask(QRect area, LODocument* doc); + RenderTask(QRect area, LODocument* document); + + QRect area() const; + void setArea(QRect &area); + + LODocument* document() const; + void setDocument(LODocument* document); + void run(); Q_SIGNALS: + void areaChanged(); + void documentChanged(); void renderCompleted(QImage t); private:
-- Mailing list: https://launchpad.net/~ubuntu-touch-coreapps-reviewers Post to : [email protected] Unsubscribe : https://launchpad.net/~ubuntu-touch-coreapps-reviewers More help : https://help.launchpad.net/ListHelp

