ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #03545
[Merge] lp:~verzegnassi-stefano/ubuntu-docviewer-app/lo-use-timer-update-view into lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-tiled-rendering
Stefano Verzegnassi has proposed merging lp:~verzegnassi-stefano/ubuntu-docviewer-app/lo-use-timer-update-view into lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-tiled-rendering.
Commit message:
[LOK-plugin] Use a QTimer to avoid multiple updates when contentX/contentY change
Requested reviews:
Ubuntu Document Viewer Developers (ubuntu-docviewer-dev)
For more details, see:
https://code.launchpad.net/~verzegnassi-stefano/ubuntu-docviewer-app/lo-use-timer-update-view/+merge/264687
[LOK-plugin] Use a QTimer to avoid multiple updates when contentX/contentY change.
This avoids multiple calls of the updateVisibleRect() function, so that the Flickable can scroll smooth without the main thread being busy.
*** NOTES:
The interval of the timer is arbitrary, and we may need to change it as we'll have all the things in the right place (i.e. cache buffer and low-res page placeholder).
At the moment it is just set to 20ms, which seems to provide a good balance between the speed of Flickable's scrolling and the frequency of the updates of the view.
--
Your team Ubuntu Document Viewer Developers is requested to review the proposed merge of lp:~verzegnassi-stefano/ubuntu-docviewer-app/lo-use-timer-update-view into lp:~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-tiled-rendering.
=== 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-14 09:28:29 +0000
@@ -21,6 +21,7 @@
#include <QPainter>
#include <QImage>
+#include <QTimer>
#include <QtCore/qmath.h>
// TODO: Use a QQuickItem and implement painting through
@@ -34,26 +35,21 @@
, m_document(nullptr)
, m_zoomFactor(1.0)
, m_visibleArea(0, 0, 0, 0)
+ , m_updateTimer(nullptr)
{
- Q_UNUSED(parent)
+ Q_UNUSED(parent)
+ m_updateTimer = new QTimer();
- // Connections for updating the canvas size.
connect(this, SIGNAL(documentChanged()), this, SLOT(updateViewSize()));
connect(this, SIGNAL(zoomFactorChanged()), this, SLOT(updateViewSize()));
-
connect(this, SIGNAL(parentFlickableChanged()), this, SLOT(updateVisibleRect()));
+ connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateVisibleRect()));
}
void LOView::paint(QPainter *painter)
{
// 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) {
// if (!tile->painted) {
painter->drawImage(tile->area, tile->texture);
@@ -83,8 +79,8 @@
connect(m_parentFlickable, SIGNAL(widthChanged()), this, SLOT(updateVisibleRect()));
connect(m_parentFlickable, SIGNAL(heightChanged()), this, SLOT(updateVisibleRect()));
- connect(m_parentFlickable, SIGNAL(contentXChanged()), this, SLOT(updateVisibleRect()));
- connect(m_parentFlickable, SIGNAL(contentYChanged()), this, SLOT(updateVisibleRect()));
+ connect(m_parentFlickable, SIGNAL(contentXChanged()), this, SLOT(queueVisibleRectUpdate()));
+ connect(m_parentFlickable, SIGNAL(contentYChanged()), this, SLOT(queueVisibleRectUpdate()));
Q_EMIT parentFlickableChanged();
}
@@ -212,9 +208,12 @@
// TODO: Generate tiles in the cacheBuffer area
// (currently called loadingArea).
+}
- // Request a new paint.
- this->update();
+void LOView::queueVisibleRectUpdate()
+{
+ if (!m_updateTimer->isActive())
+ m_updateTimer->start(20);
}
LOView::~LOView()
=== modified file 'src/plugin/libreofficetoolkit-qml-plugin/loview.h'
--- src/plugin/libreofficetoolkit-qml-plugin/loview.h 2015-07-04 16:00:33 +0000
+++ src/plugin/libreofficetoolkit-qml-plugin/loview.h 2015-07-14 09:28:29 +0000
@@ -24,6 +24,7 @@
class LODocument;
class TileItem;
+class QTimer;
class LOView : public QQuickPaintedItem
{
@@ -60,6 +61,7 @@
private Q_SLOTS:
void updateViewSize();
void updateVisibleRect();
+ void queueVisibleRectUpdate();
private:
QQuickItem* m_parentFlickable;
@@ -68,6 +70,8 @@
qreal m_zoomFactor;
QRect m_visibleArea;
+ QTimer* m_updateTimer;
+
// TODO: Should we move tiles management in another class (e.g. TileBuffer)?
QMap<int, TileItem*> m_tiles;
};
Follow ups