@@ -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 the BSD license as follows:
*
@@ -48,19 +48,21 @@
#include <QPainter>
static const QString IMAGE_URL("image://%1/%2");
+static const int REPAINT_DELAY_MSEC = 250;
// ==========================================================================
// BooksPageWidget::Data
// ==========================================================================
-class BooksPageWidget::Data {
+class BooksPageWidget::Data
+{
public:
typedef shared_ptr<Data> Ptr;
Data(shared_ptr<ZLTextModel> aModel, int aWidth, int aHeight) :
iModel(aModel), iPaintContext(aWidth, aHeight) {}
- bool paint(QPainter* aPainter, BooksColorScheme aColors);
+ bool paint(QPainter*, BooksColorScheme);
inline int width() const { return iPaintContext.width(); }
inline int height() const { return iPaintContext.height(); }
@@ -70,7 +72,10 @@
BooksPaintContext iPaintContext;
};
-bool BooksPageWidget::Data::paint(QPainter* aPainter, BooksColorScheme aColors)
+bool
+BooksPageWidget::Data::paint(
+ QPainter* aPainter,
+ BooksColorScheme aColors)
{
if (!iView.isNull()) {
iPaintContext.iColors = aColors;
@@ -86,14 +91,14 @@
// BooksPageWidget::ResetTask
// ==========================================================================
-class BooksPageWidget::ResetTask : public HarbourTask {
+class BooksPageWidget::ResetTask : public HarbourTask
+{
public:
- ResetTask(QThreadPool* aPool, shared_ptr<ZLTextModel> aModel,
- shared_ptr<ZLTextStyle> aTextStyle, int aWidth, int aHeight,
- const BooksMargins& aMargins, const BooksPos& aPosition);
+ ResetTask(QThreadPool*, shared_ptr<ZLTextModel>, shared_ptr<ZLTextStyle>,
+ int, int, const BooksMargins&, const BooksPos&);
~ResetTask();
- void performTask();
+ void performTask() Q_DECL_OVERRIDE;
public:
BooksPageWidget::Data* iData;
@@ -102,10 +107,15 @@
BooksPos iPosition;
};
-BooksPageWidget::ResetTask::ResetTask(QThreadPool* aPool,
- shared_ptr<ZLTextModel> aModel, shared_ptr<ZLTextStyle> aTextStyle,
- int aWidth, int aHeight, const BooksMargins& aMargins,
- const BooksPos& aPosition) : HarbourTask(aPool),
+BooksPageWidget::ResetTask::ResetTask(
+ QThreadPool* aPool,
+ shared_ptr<ZLTextModel> aModel,
+ shared_ptr<ZLTextStyle> aTextStyle,
+ int aWidth,
+ int aHeight,
+ const BooksMargins& aMargins,
+ const BooksPos& aPosition) :
+ HarbourTask(aPool),
iData(new BooksPageWidget::Data(aModel, aWidth, aHeight)),
iTextStyle(aTextStyle),
iMargins(aMargins),
@@ -118,7 +128,8 @@
delete iData;
}
-void BooksPageWidget::ResetTask::performTask()
+void
+BooksPageWidget::ResetTask::performTask()
{
if (!isCanceled()) {
BooksTextView* view = new BooksTextView(iData->iPaintContext,
@@ -141,13 +152,14 @@
// BooksPageWidget::RenderTask
// ==========================================================================
-class BooksPageWidget::RenderTask : public HarbourTask {
+class BooksPageWidget::RenderTask : public HarbourTask
+{
public:
RenderTask(QThreadPool* aPool, QThread* aTargetThread, Data::Ptr aData,
BooksColorScheme aColors) : HarbourTask(aPool, aTargetThread),
iData(aData), iColors(aColors) {}
- void performTask();
+ void performTask() Q_DECL_OVERRIDE;
public:
Data::Ptr iData;
@@ -155,7 +167,8 @@
QImage iImage;
};
-void BooksPageWidget::RenderTask::performTask()
+void
+BooksPageWidget::RenderTask::performTask()
{
if (!iData.isNull() && !iData->iView.isNull()) {
const int width = iData->width();
@@ -174,12 +187,13 @@
// BooksPageWidget::ClearSelectionTask
// ==========================================================================
-class BooksPageWidget::ClearSelectionTask : public HarbourTask {
+class BooksPageWidget::ClearSelectionTask : public HarbourTask
+{
public:
ClearSelectionTask(QThreadPool* aPool, Data::Ptr aData, BooksColorScheme aColors) :
HarbourTask(aPool), iData(aData), iColors(aColors), iImageUpdated(false) {}
- void performTask();
+ void performTask() Q_DECL_OVERRIDE;
public:
Data::Ptr iData;
@@ -188,7 +202,8 @@
bool iImageUpdated;
};
-void BooksPageWidget::ClearSelectionTask::performTask()
+void
+BooksPageWidget::ClearSelectionTask::performTask()
{
if (!iData.isNull() && !iData->iView.isNull()) {
iData->iView->endSelection();
@@ -213,14 +228,14 @@
// BooksPageWidget::StartSelectionTask
// ==========================================================================
-class BooksPageWidget::StartSelectionTask : public HarbourTask {
+class BooksPageWidget::StartSelectionTask : public HarbourTask
+{
public:
StartSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
- BooksColorScheme aColors) : HarbourTask(aPool),
- iData(aData), iX(aX), iY(aY), iColors(aColors),
- iSelectionEmpty(true) {}
+ BooksColorScheme aColors) : HarbourTask(aPool), iData(aData),
+ iX(aX), iY(aY), iColors(aColors), iSelectionEmpty(true) {}
- void performTask();
+ void performTask() Q_DECL_OVERRIDE;
public:
Data::Ptr iData;
@@ -231,7 +246,8 @@
bool iSelectionEmpty;
};
-void BooksPageWidget::StartSelectionTask::performTask()
+void
+BooksPageWidget::StartSelectionTask::performTask()
{
if (!iData.isNull() && !iData->iView.isNull()) {
const int width = iData->width();
@@ -254,14 +270,15 @@
// BooksPageWidget::ExtendSelectionTask
// ==========================================================================
-class BooksPageWidget::ExtendSelectionTask : public HarbourTask {
+class BooksPageWidget::ExtendSelectionTask : public HarbourTask
+{
public:
ExtendSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
- BooksColorScheme aColors) : HarbourTask(aPool),
- iData(aData), iX(aX), iY(aY), iColors(aColors),
- iSelectionChanged(false), iSelectionEmpty(true) {}
+ BooksColorScheme aColors) : HarbourTask(aPool), iData(aData),
+ iX(aX), iY(aY), iColors(aColors), iSelectionChanged(false),
+ iSelectionEmpty(true) {}
- void performTask();
+ void performTask() Q_DECL_OVERRIDE;
public:
Data::Ptr iData;
@@ -273,7 +290,8 @@
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2015-2020 Jolla Ltd.
- * Copyright (C) 2015-2020 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 the BSD license as follows:
*
@@ -45,7 +45,7 @@
#include "ZLTextStyle.h"
#include <QQuickPaintedItem>
-#include <QTimer>
+#include <QBasicTimer>
#include <QList>
class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty
@@ -70,40 +70,40 @@
explicit BooksPageWidget(QQuickItem* aParent = NULL);
~BooksPageWidget();
- bool loading() const;
+ bool loading() const Q_DECL_OVERRIDE;
bool selecting() const;
bool selectionEmpty() const;
bool pressed() const;
- void setPressed(bool aPressed);
+ void setPressed(bool);
bool currentPage() const;
- void setCurrentPage(bool aCurrentPage);
+ void setCurrentPage(bool);
int page() const;
- void setPage(int aPage);
+ void setPage(int);
BooksBookModel* model() const;
- void setModel(BooksBookModel* aModel);
+ void setModel(BooksBookModel*);
const BooksPos& bookPos() const;
- void setBookPos(const BooksPos& aBookPos);
+ void setBookPos(const BooksPos&);
int leftMargin() const;
int rightMargin() const;
int topMargin() const;
int bottomMargin() const;
- void setLeftMargin(int aMargin);
- void setRightMargin(int aMargin);
- void setTopMargin(int aMargin);
- void setBottomMargin(int aMargin);
+ void setLeftMargin(int);
+ void setRightMargin(int);
+ void setTopMargin(int);
+ void setBottomMargin(int);
BooksMargins margins() const;
- Q_INVOKABLE void handlePress(int aX, int aY);
- Q_INVOKABLE void handleLongPress(int aX, int aY);
- Q_INVOKABLE void handlePositionChanged(int aX, int aY);
+ Q_INVOKABLE void handlePress(int, int);
+ Q_INVOKABLE void handleLongPress(int, int);
+ Q_INVOKABLE void handlePositionChanged(int, int);
Q_INVOKABLE void clearSelection();
Q_SIGNALS:
@@ -129,12 +129,12 @@
private Q_SLOTS:
void onWidthChanged();
void onHeightChanged();
- void onResizeTimeout();
void onBookModelDestroyed();
void onTextStyleChanged();
void onColorsChanged();
void onResetTaskDone();
void onRenderTaskDone();
+ void onRenderTaskDoneDelayUpdate();
void onClearSelectionTaskDone();
void onStartSelectionTaskDone();
void onExtendSelectionTaskDone();
@@ -142,13 +142,19 @@
void onLongPressTaskDone();
void onFootnoteTaskDone();
+protected:
+ void timerEvent(QTimerEvent*) Q_DECL_OVERRIDE;
+ void paint(QPainter*) Q_DECL_OVERRIDE;
+
private:
- void paint(QPainter *painter) Q_DECL_OVERRIDE;
void updateSize();
void resetView();
void releaseExtendSelectionTasks();
void scheduleRepaint();
+ void scheduleRepaintDelayUpdate();
void cancelRepaint();
+ void renderTaskDone();
+ void updateNow();
private:
class ResetTask;
@@ -163,7 +169,8 @@
shared_ptr<BooksTaskQueue> iTaskQueue;
shared_ptr<ZLTextStyle> iTextStyle;
BooksPos iBookPos;
- QTimer* iResizeTimer;
+ QBasicTimer iResizeTimer;
+ QBasicTimer iDelayUpdateTimer;
BooksBookModel* iModel;
BooksMargins iMargins;
shared_ptr<Data> iData;
|