From ed9bf8098a9a02c5b5ed393637635f24851a15a1 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 30 Oct 2022 00:34:09 +0300 Subject: [PATCH] [app] Synced page image with the background Delay the update of the background color until the page image has been rendered. --- app/qml/BooksPageView.qml | 6 +++--- app/src/BooksPageWidget.cpp | 42 ++++++++++--------------------------- app/src/BooksPageWidget.h | 10 +++++++-- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/app/qml/BooksPageView.qml b/app/qml/BooksPageView.qml index f24aaff..671545a 100644 --- a/app/qml/BooksPageView.qml +++ b/app/qml/BooksPageView.qml @@ -1,6 +1,6 @@ /* - Copyright (C) 2015-2021 Jolla Ltd. - Copyright (C) 2015-2021 Slava Monich + Copyright (C) 2015-2022 Jolla Ltd. + Copyright (C) 2015-2022 Slava Monich You may use this file under the terms of BSD license as follows: @@ -40,7 +40,7 @@ import "Books.js" as Books Rectangle { id: view - color: Settings.pageBackgroundColor + color: widget.backgroundColor property alias page: widget.page property alias bookPos: widget.bookPos diff --git a/app/src/BooksPageWidget.cpp b/app/src/BooksPageWidget.cpp index 19becab..143e1ed 100644 --- a/app/src/BooksPageWidget.cpp +++ b/app/src/BooksPageWidget.cpp @@ -48,7 +48,6 @@ #include static const QString IMAGE_URL("image://%1/%2"); -static const int REPAINT_DELAY_MSEC = 250; // ========================================================================== // BooksPageWidget::Data @@ -534,6 +533,7 @@ BooksPageWidget::BooksPageWidget(QQuickItem* aParent) : iSettings(BooksSettings::sharedInstance()), iTaskQueue(BooksTaskQueue::defaultQueue()), iTextStyle(BooksTextStyle::defaults()), + iBackgroundColor(iSettings->pageBackgroundColor()), iModel(NULL), iResetTask(NULL), iRenderTask(NULL), @@ -647,7 +647,7 @@ BooksPageWidget::onColorsChanged() { HDEBUG(iPage); HASSERT(sender() == iSettings); - scheduleRepaintDelayUpdate(); + scheduleRepaint(); } void @@ -824,22 +824,6 @@ BooksPageWidget::scheduleRepaint() } } -void -BooksPageWidget::scheduleRepaintDelayUpdate() -{ - BooksLoadingSignalBlocker block(this); - cancelRepaint(); - if (width() > 0 && height() > 0) { - if (!iData.isNull() && !iData->iView.isNull()) { - (iRenderTask = new RenderTask(iTaskQueue->pool(), thread(), - iData, iSettings->colorScheme()))->submit(this, - SLOT(onRenderTaskDoneDelayUpdate())); - } else if (!iDelayUpdateTimer.isActive()) { - iDelayUpdateTimer.start(REPAINT_DELAY_MSEC, this); - } - } -} - void BooksPageWidget::updateNow() { @@ -862,10 +846,16 @@ BooksPageWidget::onResetTaskDone() void BooksPageWidget::renderTaskDone() { - HASSERT(sender() == iRenderTask); - iImage = iRenderTask->iImage; - iRenderTask->release(this); + RenderTask* task = iRenderTask; + HASSERT(sender() == task); iRenderTask = NULL; + iImage = task->iImage; + const QColor bg(task->iColors.background()); + if (iBackgroundColor != bg) { + iBackgroundColor = bg; + Q_EMIT backgroundColorChanged(); + } + task->release(this); } void @@ -876,16 +866,6 @@ BooksPageWidget::onRenderTaskDone() updateNow(); } -void -BooksPageWidget::onRenderTaskDoneDelayUpdate() -{ - BooksLoadingSignalBlocker block(this); - renderTaskDone(); - if (!iDelayUpdateTimer.isActive()) { - iDelayUpdateTimer.start(REPAINT_DELAY_MSEC, this); - } -} - void BooksPageWidget::timerEvent( QTimerEvent* aEvent) diff --git a/app/src/BooksPageWidget.h b/app/src/BooksPageWidget.h index 5f2ccf2..6d78d80 100644 --- a/app/src/BooksPageWidget.h +++ b/app/src/BooksPageWidget.h @@ -46,6 +46,7 @@ #include #include +#include #include class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty @@ -61,6 +62,7 @@ class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty Q_PROPERTY(int rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) + Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY backgroundColorChanged) Q_PROPERTY(BooksBookModel* model READ model WRITE setModel NOTIFY modelChanged) Q_PROPERTY(BooksPos bookPos READ bookPos WRITE setBookPos NOTIFY bookPosChanged) @@ -83,6 +85,8 @@ public: int page() const; void setPage(int); + QColor backgroundColor() const; + BooksBookModel* model() const; void setModel(BooksBookModel*); @@ -119,6 +123,7 @@ Q_SIGNALS: void rightMarginChanged(); void topMarginChanged(); void bottomMarginChanged(); + void backgroundColorChanged(); void browserLinkPressed(QString url); void imagePressed(QString imageId, QRect rect); void activeTouch(int touchX, int touchY); @@ -134,7 +139,6 @@ private Q_SLOTS: void onColorsChanged(); void onResetTaskDone(); void onRenderTaskDone(); - void onRenderTaskDoneDelayUpdate(); void onClearSelectionTaskDone(); void onStartSelectionTaskDone(); void onExtendSelectionTaskDone(); @@ -151,7 +155,6 @@ private: void resetView(); void releaseExtendSelectionTasks(); void scheduleRepaint(); - void scheduleRepaintDelayUpdate(); void cancelRepaint(); void renderTaskDone(); void updateNow(); @@ -169,6 +172,7 @@ private: shared_ptr iTaskQueue; shared_ptr iTextStyle; BooksPos iBookPos; + QColor iBackgroundColor; QBasicTimer iResizeTimer; QBasicTimer iDelayUpdateTimer; BooksBookModel* iModel; @@ -203,6 +207,8 @@ inline int BooksPageWidget::page() const { return iPage; } inline const BooksPos& BooksPageWidget::bookPos() const { return iBookPos; } +inline QColor BooksPageWidget::backgroundColor() const + { return iBackgroundColor; } inline BooksBookModel* BooksPageWidget::model() const { return iModel; } inline int BooksPageWidget::leftMargin() const