[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-2022 Jolla Ltd.
|
||||||
Copyright (C) 2015-2021 Slava Monich <slava.monich@jolla.com>
|
Copyright (C) 2015-2022 Slava Monich <slava.monich@jolla.com>
|
||||||
|
|
||||||
You may use this file under the terms of BSD license as follows:
|
You may use this file under the terms of BSD license as follows:
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import "Books.js" as Books
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: view
|
id: view
|
||||||
|
|
||||||
color: Settings.pageBackgroundColor
|
color: widget.backgroundColor
|
||||||
|
|
||||||
property alias page: widget.page
|
property alias page: widget.page
|
||||||
property alias bookPos: widget.bookPos
|
property alias bookPos: widget.bookPos
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
static const QString IMAGE_URL("image://%1/%2");
|
static const QString IMAGE_URL("image://%1/%2");
|
||||||
static const int REPAINT_DELAY_MSEC = 250;
|
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// BooksPageWidget::Data
|
// BooksPageWidget::Data
|
||||||
|
@ -534,6 +533,7 @@ BooksPageWidget::BooksPageWidget(QQuickItem* aParent) :
|
||||||
iSettings(BooksSettings::sharedInstance()),
|
iSettings(BooksSettings::sharedInstance()),
|
||||||
iTaskQueue(BooksTaskQueue::defaultQueue()),
|
iTaskQueue(BooksTaskQueue::defaultQueue()),
|
||||||
iTextStyle(BooksTextStyle::defaults()),
|
iTextStyle(BooksTextStyle::defaults()),
|
||||||
|
iBackgroundColor(iSettings->pageBackgroundColor()),
|
||||||
iModel(NULL),
|
iModel(NULL),
|
||||||
iResetTask(NULL),
|
iResetTask(NULL),
|
||||||
iRenderTask(NULL),
|
iRenderTask(NULL),
|
||||||
|
@ -647,7 +647,7 @@ BooksPageWidget::onColorsChanged()
|
||||||
{
|
{
|
||||||
HDEBUG(iPage);
|
HDEBUG(iPage);
|
||||||
HASSERT(sender() == iSettings);
|
HASSERT(sender() == iSettings);
|
||||||
scheduleRepaintDelayUpdate();
|
scheduleRepaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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
|
void
|
||||||
BooksPageWidget::updateNow()
|
BooksPageWidget::updateNow()
|
||||||
{
|
{
|
||||||
|
@ -862,10 +846,16 @@ BooksPageWidget::onResetTaskDone()
|
||||||
void
|
void
|
||||||
BooksPageWidget::renderTaskDone()
|
BooksPageWidget::renderTaskDone()
|
||||||
{
|
{
|
||||||
HASSERT(sender() == iRenderTask);
|
RenderTask* task = iRenderTask;
|
||||||
iImage = iRenderTask->iImage;
|
HASSERT(sender() == task);
|
||||||
iRenderTask->release(this);
|
|
||||||
iRenderTask = NULL;
|
iRenderTask = NULL;
|
||||||
|
iImage = task->iImage;
|
||||||
|
const QColor bg(task->iColors.background());
|
||||||
|
if (iBackgroundColor != bg) {
|
||||||
|
iBackgroundColor = bg;
|
||||||
|
Q_EMIT backgroundColorChanged();
|
||||||
|
}
|
||||||
|
task->release(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -876,16 +866,6 @@ BooksPageWidget::onRenderTaskDone()
|
||||||
updateNow();
|
updateNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
BooksPageWidget::onRenderTaskDoneDelayUpdate()
|
|
||||||
{
|
|
||||||
BooksLoadingSignalBlocker block(this);
|
|
||||||
renderTaskDone();
|
|
||||||
if (!iDelayUpdateTimer.isActive()) {
|
|
||||||
iDelayUpdateTimer.start(REPAINT_DELAY_MSEC, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BooksPageWidget::timerEvent(
|
BooksPageWidget::timerEvent(
|
||||||
QTimerEvent* aEvent)
|
QTimerEvent* aEvent)
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
#include <QQuickPaintedItem>
|
||||||
#include <QBasicTimer>
|
#include <QBasicTimer>
|
||||||
|
#include <QColor>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty
|
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 rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
|
||||||
Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
|
Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
|
||||||
Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
|
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(BooksBookModel* model READ model WRITE setModel NOTIFY modelChanged)
|
||||||
Q_PROPERTY(BooksPos bookPos READ bookPos WRITE setBookPos NOTIFY bookPosChanged)
|
Q_PROPERTY(BooksPos bookPos READ bookPos WRITE setBookPos NOTIFY bookPosChanged)
|
||||||
|
|
||||||
|
@ -83,6 +85,8 @@ public:
|
||||||
int page() const;
|
int page() const;
|
||||||
void setPage(int);
|
void setPage(int);
|
||||||
|
|
||||||
|
QColor backgroundColor() const;
|
||||||
|
|
||||||
BooksBookModel* model() const;
|
BooksBookModel* model() const;
|
||||||
void setModel(BooksBookModel*);
|
void setModel(BooksBookModel*);
|
||||||
|
|
||||||
|
@ -119,6 +123,7 @@ Q_SIGNALS:
|
||||||
void rightMarginChanged();
|
void rightMarginChanged();
|
||||||
void topMarginChanged();
|
void topMarginChanged();
|
||||||
void bottomMarginChanged();
|
void bottomMarginChanged();
|
||||||
|
void backgroundColorChanged();
|
||||||
void browserLinkPressed(QString url);
|
void browserLinkPressed(QString url);
|
||||||
void imagePressed(QString imageId, QRect rect);
|
void imagePressed(QString imageId, QRect rect);
|
||||||
void activeTouch(int touchX, int touchY);
|
void activeTouch(int touchX, int touchY);
|
||||||
|
@ -134,7 +139,6 @@ private Q_SLOTS:
|
||||||
void onColorsChanged();
|
void onColorsChanged();
|
||||||
void onResetTaskDone();
|
void onResetTaskDone();
|
||||||
void onRenderTaskDone();
|
void onRenderTaskDone();
|
||||||
void onRenderTaskDoneDelayUpdate();
|
|
||||||
void onClearSelectionTaskDone();
|
void onClearSelectionTaskDone();
|
||||||
void onStartSelectionTaskDone();
|
void onStartSelectionTaskDone();
|
||||||
void onExtendSelectionTaskDone();
|
void onExtendSelectionTaskDone();
|
||||||
|
@ -151,7 +155,6 @@ private:
|
||||||
void resetView();
|
void resetView();
|
||||||
void releaseExtendSelectionTasks();
|
void releaseExtendSelectionTasks();
|
||||||
void scheduleRepaint();
|
void scheduleRepaint();
|
||||||
void scheduleRepaintDelayUpdate();
|
|
||||||
void cancelRepaint();
|
void cancelRepaint();
|
||||||
void renderTaskDone();
|
void renderTaskDone();
|
||||||
void updateNow();
|
void updateNow();
|
||||||
|
@ -169,6 +172,7 @@ private:
|
||||||
shared_ptr<BooksTaskQueue> iTaskQueue;
|
shared_ptr<BooksTaskQueue> iTaskQueue;
|
||||||
shared_ptr<ZLTextStyle> iTextStyle;
|
shared_ptr<ZLTextStyle> iTextStyle;
|
||||||
BooksPos iBookPos;
|
BooksPos iBookPos;
|
||||||
|
QColor iBackgroundColor;
|
||||||
QBasicTimer iResizeTimer;
|
QBasicTimer iResizeTimer;
|
||||||
QBasicTimer iDelayUpdateTimer;
|
QBasicTimer iDelayUpdateTimer;
|
||||||
BooksBookModel* iModel;
|
BooksBookModel* iModel;
|
||||||
|
@ -203,6 +207,8 @@ inline int BooksPageWidget::page() const
|
||||||
{ return iPage; }
|
{ return iPage; }
|
||||||
inline const BooksPos& BooksPageWidget::bookPos() const
|
inline const BooksPos& BooksPageWidget::bookPos() const
|
||||||
{ return iBookPos; }
|
{ return iBookPos; }
|
||||||
|
inline QColor BooksPageWidget::backgroundColor() const
|
||||||
|
{ return iBackgroundColor; }
|
||||||
inline BooksBookModel* BooksPageWidget::model() const
|
inline BooksBookModel* BooksPageWidget::model() const
|
||||||
{ return iModel; }
|
{ return iModel; }
|
||||||
inline int BooksPageWidget::leftMargin() const
|
inline int BooksPageWidget::leftMargin() const
|
||||||
|
|
Loading…
Reference in a new issue