[app] Synced page image with the background
Delay the update of the background color until the page image has been rendered.
This commit is contained in:
parent
34eff94867
commit
ed9bf8098a
3 changed files with 22 additions and 36 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Copyright (C) 2015-2021 Jolla Ltd.
|
||||
Copyright (C) 2015-2021 Slava Monich <slava.monich@jolla.com>
|
||||
Copyright (C) 2015-2022 Jolla Ltd.
|
||||
Copyright (C) 2015-2022 Slava Monich <slava.monich@jolla.com>
|
||||
|
||||
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
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include <QPainter>
|
||||
|
||||
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)
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
|
||||
#include <QQuickPaintedItem>
|
||||
#include <QBasicTimer>
|
||||
#include <QColor>
|
||||
#include <QList>
|
||||
|
||||
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<BooksTaskQueue> iTaskQueue;
|
||||
shared_ptr<ZLTextStyle> 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
|
||||
|
|
Loading…
Reference in a new issue