[app] Housekeeping

This commit is contained in:
Slava Monich 2022-10-11 01:10:01 +03:00
parent 7de7fd1e3a
commit a4a868c1c8
2 changed files with 174 additions and 97 deletions

View file

@ -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 the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -53,14 +53,15 @@ static const QString IMAGE_URL("image://%1/%2");
// BooksPageWidget::Data // BooksPageWidget::Data
// ========================================================================== // ==========================================================================
class BooksPageWidget::Data { class BooksPageWidget::Data
{
public: public:
typedef shared_ptr<Data> Ptr; typedef shared_ptr<Data> Ptr;
Data(shared_ptr<ZLTextModel> aModel, int aWidth, int aHeight) : Data(shared_ptr<ZLTextModel> aModel, int aWidth, int aHeight) :
iModel(aModel), iPaintContext(aWidth, 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 width() const { return iPaintContext.width(); }
inline int height() const { return iPaintContext.height(); } inline int height() const { return iPaintContext.height(); }
@ -70,7 +71,10 @@ public:
BooksPaintContext iPaintContext; BooksPaintContext iPaintContext;
}; };
bool BooksPageWidget::Data::paint(QPainter* aPainter, BooksColorScheme aColors) bool
BooksPageWidget::Data::paint(
QPainter* aPainter,
BooksColorScheme aColors)
{ {
if (!iView.isNull()) { if (!iView.isNull()) {
iPaintContext.iColors = aColors; iPaintContext.iColors = aColors;
@ -86,14 +90,14 @@ bool BooksPageWidget::Data::paint(QPainter* aPainter, BooksColorScheme aColors)
// BooksPageWidget::ResetTask // BooksPageWidget::ResetTask
// ========================================================================== // ==========================================================================
class BooksPageWidget::ResetTask : public HarbourTask { class BooksPageWidget::ResetTask : public HarbourTask
{
public: public:
ResetTask(QThreadPool* aPool, shared_ptr<ZLTextModel> aModel, ResetTask(QThreadPool*, shared_ptr<ZLTextModel>, shared_ptr<ZLTextStyle>,
shared_ptr<ZLTextStyle> aTextStyle, int aWidth, int aHeight, int, int, const BooksMargins&, const BooksPos&);
const BooksMargins& aMargins, const BooksPos& aPosition);
~ResetTask(); ~ResetTask();
void performTask(); void performTask() Q_DECL_OVERRIDE;
public: public:
BooksPageWidget::Data* iData; BooksPageWidget::Data* iData;
@ -102,10 +106,15 @@ public:
BooksPos iPosition; BooksPos iPosition;
}; };
BooksPageWidget::ResetTask::ResetTask(QThreadPool* aPool, BooksPageWidget::ResetTask::ResetTask(
shared_ptr<ZLTextModel> aModel, shared_ptr<ZLTextStyle> aTextStyle, QThreadPool* aPool,
int aWidth, int aHeight, const BooksMargins& aMargins, shared_ptr<ZLTextModel> aModel,
const BooksPos& aPosition) : HarbourTask(aPool), shared_ptr<ZLTextStyle> aTextStyle,
int aWidth,
int aHeight,
const BooksMargins& aMargins,
const BooksPos& aPosition) :
HarbourTask(aPool),
iData(new BooksPageWidget::Data(aModel, aWidth, aHeight)), iData(new BooksPageWidget::Data(aModel, aWidth, aHeight)),
iTextStyle(aTextStyle), iTextStyle(aTextStyle),
iMargins(aMargins), iMargins(aMargins),
@ -118,7 +127,8 @@ BooksPageWidget::ResetTask::~ResetTask()
delete iData; delete iData;
} }
void BooksPageWidget::ResetTask::performTask() void
BooksPageWidget::ResetTask::performTask()
{ {
if (!isCanceled()) { if (!isCanceled()) {
BooksTextView* view = new BooksTextView(iData->iPaintContext, BooksTextView* view = new BooksTextView(iData->iPaintContext,
@ -141,13 +151,14 @@ void BooksPageWidget::ResetTask::performTask()
// BooksPageWidget::RenderTask // BooksPageWidget::RenderTask
// ========================================================================== // ==========================================================================
class BooksPageWidget::RenderTask : public HarbourTask { class BooksPageWidget::RenderTask : public HarbourTask
{
public: public:
RenderTask(QThreadPool* aPool, QThread* aTargetThread, Data::Ptr aData, RenderTask(QThreadPool* aPool, QThread* aTargetThread, Data::Ptr aData,
BooksColorScheme aColors) : HarbourTask(aPool, aTargetThread), BooksColorScheme aColors) : HarbourTask(aPool, aTargetThread),
iData(aData), iColors(aColors) {} iData(aData), iColors(aColors) {}
void performTask(); void performTask() Q_DECL_OVERRIDE;
public: public:
Data::Ptr iData; Data::Ptr iData;
@ -155,7 +166,8 @@ public:
QImage iImage; QImage iImage;
}; };
void BooksPageWidget::RenderTask::performTask() void
BooksPageWidget::RenderTask::performTask()
{ {
if (!iData.isNull() && !iData->iView.isNull()) { if (!iData.isNull() && !iData->iView.isNull()) {
const int width = iData->width(); const int width = iData->width();
@ -174,12 +186,13 @@ void BooksPageWidget::RenderTask::performTask()
// BooksPageWidget::ClearSelectionTask // BooksPageWidget::ClearSelectionTask
// ========================================================================== // ==========================================================================
class BooksPageWidget::ClearSelectionTask : public HarbourTask { class BooksPageWidget::ClearSelectionTask : public HarbourTask
{
public: public:
ClearSelectionTask(QThreadPool* aPool, Data::Ptr aData, BooksColorScheme aColors) : ClearSelectionTask(QThreadPool* aPool, Data::Ptr aData, BooksColorScheme aColors) :
HarbourTask(aPool), iData(aData), iColors(aColors), iImageUpdated(false) {} HarbourTask(aPool), iData(aData), iColors(aColors), iImageUpdated(false) {}
void performTask(); void performTask() Q_DECL_OVERRIDE;
public: public:
Data::Ptr iData; Data::Ptr iData;
@ -188,7 +201,8 @@ public:
bool iImageUpdated; bool iImageUpdated;
}; };
void BooksPageWidget::ClearSelectionTask::performTask() void
BooksPageWidget::ClearSelectionTask::performTask()
{ {
if (!iData.isNull() && !iData->iView.isNull()) { if (!iData.isNull() && !iData->iView.isNull()) {
iData->iView->endSelection(); iData->iView->endSelection();
@ -213,14 +227,14 @@ void BooksPageWidget::ClearSelectionTask::performTask()
// BooksPageWidget::StartSelectionTask // BooksPageWidget::StartSelectionTask
// ========================================================================== // ==========================================================================
class BooksPageWidget::StartSelectionTask : public HarbourTask { class BooksPageWidget::StartSelectionTask : public HarbourTask
{
public: public:
StartSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY, StartSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
BooksColorScheme aColors) : HarbourTask(aPool), BooksColorScheme aColors) : HarbourTask(aPool), iData(aData),
iData(aData), iX(aX), iY(aY), iColors(aColors), iX(aX), iY(aY), iColors(aColors), iSelectionEmpty(true) {}
iSelectionEmpty(true) {}
void performTask(); void performTask() Q_DECL_OVERRIDE;
public: public:
Data::Ptr iData; Data::Ptr iData;
@ -231,7 +245,8 @@ public:
bool iSelectionEmpty; bool iSelectionEmpty;
}; };
void BooksPageWidget::StartSelectionTask::performTask() void
BooksPageWidget::StartSelectionTask::performTask()
{ {
if (!iData.isNull() && !iData->iView.isNull()) { if (!iData.isNull() && !iData->iView.isNull()) {
const int width = iData->width(); const int width = iData->width();
@ -254,14 +269,15 @@ void BooksPageWidget::StartSelectionTask::performTask()
// BooksPageWidget::ExtendSelectionTask // BooksPageWidget::ExtendSelectionTask
// ========================================================================== // ==========================================================================
class BooksPageWidget::ExtendSelectionTask : public HarbourTask { class BooksPageWidget::ExtendSelectionTask : public HarbourTask
{
public: public:
ExtendSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY, ExtendSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
BooksColorScheme aColors) : HarbourTask(aPool), BooksColorScheme aColors) : HarbourTask(aPool), iData(aData),
iData(aData), iX(aX), iY(aY), iColors(aColors), iX(aX), iY(aY), iColors(aColors), iSelectionChanged(false),
iSelectionChanged(false), iSelectionEmpty(true) {} iSelectionEmpty(true) {}
void performTask(); void performTask() Q_DECL_OVERRIDE;
public: public:
Data::Ptr iData; Data::Ptr iData;
@ -273,7 +289,8 @@ public:
bool iSelectionEmpty; bool iSelectionEmpty;
}; };
void BooksPageWidget::ExtendSelectionTask::performTask() void
BooksPageWidget::ExtendSelectionTask::performTask()
{ {
if (!iData.isNull() && !iData->iView.isNull()) { if (!iData.isNull() && !iData->iView.isNull()) {
const int width = iData->width(); const int width = iData->width();
@ -296,7 +313,8 @@ void BooksPageWidget::ExtendSelectionTask::performTask()
// BooksPageWidget::FootnoteTask // BooksPageWidget::FootnoteTask
// ========================================================================== // ==========================================================================
class BooksPageWidget::FootnoteTask : public HarbourTask, ZLTextArea::Properties { class BooksPageWidget::FootnoteTask : public HarbourTask, ZLTextArea::Properties
{
public: public:
FootnoteTask(QThreadPool* aPool, int aX, int aY, int aMaxWidth, int aMaxHeight, FootnoteTask(QThreadPool* aPool, int aX, int aY, int aMaxWidth, int aMaxHeight,
QString aPath, QString aLinkText, QString aRef, QString aPath, QString aLinkText, QString aRef,
@ -308,12 +326,12 @@ public:
iRef(aRef), iLinkText(aLinkText), iPath(aPath) {} iRef(aRef), iLinkText(aLinkText), iPath(aPath) {}
~FootnoteTask(); ~FootnoteTask();
void performTask(); void performTask() Q_DECL_OVERRIDE;
// ZLTextArea::Properties // ZLTextArea::Properties
shared_ptr<ZLTextStyle> baseStyle() const; shared_ptr<ZLTextStyle> baseStyle() const Q_DECL_OVERRIDE;
ZLColor color(const std::string& aStyle) const; ZLColor color(const std::string&) const Q_DECL_OVERRIDE;
bool isSelectionEnabled() const; bool isSelectionEnabled() const Q_DECL_OVERRIDE;
public: public:
shared_ptr<ZLTextModel> iTextModel; shared_ptr<ZLTextModel> iTextModel;
@ -333,22 +351,27 @@ BooksPageWidget::FootnoteTask::~FootnoteTask()
{ {
} }
shared_ptr<ZLTextStyle> BooksPageWidget::FootnoteTask::baseStyle() const shared_ptr<ZLTextStyle>
BooksPageWidget::FootnoteTask::baseStyle() const
{ {
return iTextStyle; return iTextStyle;
} }
ZLColor BooksPageWidget::FootnoteTask::color(const std::string& aStyle) const ZLColor
BooksPageWidget::FootnoteTask::color(
const std::string& aStyle) const
{ {
return BooksPaintContext::realColor(aStyle, iColors); return BooksPaintContext::realColor(aStyle, iColors);
} }
bool BooksPageWidget::FootnoteTask::isSelectionEnabled() const bool
BooksPageWidget::FootnoteTask::isSelectionEnabled() const
{ {
return false; return false;
} }
void BooksPageWidget::FootnoteTask::performTask() void
BooksPageWidget::FootnoteTask::performTask()
{ {
if (!isCanceled()) { if (!isCanceled()) {
// Determine the size of the footnote canvas // Determine the size of the footnote canvas
@ -382,13 +405,14 @@ void BooksPageWidget::FootnoteTask::performTask()
// BooksPageWidget::PressTask // BooksPageWidget::PressTask
// ========================================================================== // ==========================================================================
class BooksPageWidget::PressTask : public HarbourTask { class BooksPageWidget::PressTask : public HarbourTask
{
public: public:
PressTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY) : PressTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY) :
HarbourTask(aPool), iData(aData), iX(aX), iY(aY), iKind(REGULAR) {} HarbourTask(aPool), iData(aData), iX(aX), iY(aY), iKind(REGULAR) {}
void performTask(); void performTask() Q_DECL_OVERRIDE;
QString getLinkText(ZLTextWordCursor& aCursor); QString getLinkText(ZLTextWordCursor&);
public: public:
Data::Ptr iData; Data::Ptr iData;
@ -403,7 +427,9 @@ public:
QImage iImage; QImage iImage;
}; };
QString BooksPageWidget::PressTask::getLinkText(ZLTextWordCursor& aCursor) QString
BooksPageWidget::PressTask::getLinkText(
ZLTextWordCursor& aCursor)
{ {
QString text; QString text;
while (!aCursor.isEndOfParagraph() && !isCanceled() && while (!aCursor.isEndOfParagraph() && !isCanceled() &&
@ -420,7 +446,8 @@ QString BooksPageWidget::PressTask::getLinkText(ZLTextWordCursor& aCursor)
return text; return text;
} }
void BooksPageWidget::PressTask::performTask() void
BooksPageWidget::PressTask::performTask()
{ {
if (!isCanceled()) { if (!isCanceled()) {
const BooksTextView& view = *iData->iView; const BooksTextView& view = *iData->iView;
@ -544,7 +571,8 @@ BooksPageWidget::~BooksPageWidget()
if (iFootnoteTask) iFootnoteTask->release(this); if (iFootnoteTask) iFootnoteTask->release(this);
} }
void BooksPageWidget::releaseExtendSelectionTasks() void
BooksPageWidget::releaseExtendSelectionTasks()
{ {
while (!iExtendSelectionTasks.isEmpty()) { while (!iExtendSelectionTasks.isEmpty()) {
const int i = iExtendSelectionTasks.count()-1; const int i = iExtendSelectionTasks.count()-1;
@ -553,7 +581,9 @@ void BooksPageWidget::releaseExtendSelectionTasks()
} }
} }
void BooksPageWidget::setPressed(bool aPressed) void
BooksPageWidget::setPressed(
bool aPressed)
{ {
if (iPressed != aPressed) { if (iPressed != aPressed) {
iPressed = aPressed; iPressed = aPressed;
@ -566,7 +596,9 @@ void BooksPageWidget::setPressed(bool aPressed)
} }
} }
void BooksPageWidget::setCurrentPage(bool aCurrentPage) void
BooksPageWidget::setCurrentPage(
bool aCurrentPage)
{ {
if (iCurrentPage != aCurrentPage) { if (iCurrentPage != aCurrentPage) {
iCurrentPage = aCurrentPage; iCurrentPage = aCurrentPage;
@ -576,7 +608,9 @@ void BooksPageWidget::setCurrentPage(bool aCurrentPage)
} }
} }
void BooksPageWidget::setModel(BooksBookModel* aModel) void
BooksPageWidget::setModel(
BooksBookModel* aModel)
{ {
if (iModel != aModel) { if (iModel != aModel) {
if (iModel) iModel->disconnect(this); if (iModel) iModel->disconnect(this);
@ -602,7 +636,8 @@ void BooksPageWidget::setModel(BooksBookModel* aModel)
} }
} }
void BooksPageWidget::onTextStyleChanged() void
BooksPageWidget::onTextStyleChanged()
{ {
HDEBUG(iPage); HDEBUG(iPage);
HASSERT(sender() == iModel); HASSERT(sender() == iModel);
@ -610,14 +645,16 @@ void BooksPageWidget::onTextStyleChanged()
resetView(); resetView();
} }
void BooksPageWidget::onColorsChanged() void
BooksPageWidget::onColorsChanged()
{ {
HDEBUG(iPage); HDEBUG(iPage);
HASSERT(sender() == iSettings); HASSERT(sender() == iSettings);
scheduleRepaint(); scheduleRepaint();
} }
void BooksPageWidget::onBookModelDestroyed() void
BooksPageWidget::onBookModelDestroyed()
{ {
HDEBUG("model destroyed"); HDEBUG("model destroyed");
HASSERT(iModel == sender()); HASSERT(iModel == sender());
@ -627,7 +664,9 @@ void BooksPageWidget::onBookModelDestroyed()
resetView(); resetView();
} }
void BooksPageWidget::setPage(int aPage) void
BooksPageWidget::setPage(
int aPage)
{ {
if (iPage != aPage) { if (iPage != aPage) {
BooksLoadingSignalBlocker block(this); BooksLoadingSignalBlocker block(this);
@ -637,7 +676,9 @@ void BooksPageWidget::setPage(int aPage)
} }
} }
void BooksPageWidget::setBookPos(const BooksPos& aBookPos) void
BooksPageWidget::setBookPos(
const BooksPos& aBookPos)
{ {
if (iBookPos != aBookPos) { if (iBookPos != aBookPos) {
iBookPos = aBookPos; iBookPos = aBookPos;
@ -647,7 +688,9 @@ void BooksPageWidget::setBookPos(const BooksPos& aBookPos)
} }
} }
void BooksPageWidget::setLeftMargin(int aMargin) void
BooksPageWidget::setLeftMargin(
int aMargin)
{ {
if (iMargins.iLeft != aMargin) { if (iMargins.iLeft != aMargin) {
iMargins.iLeft = aMargin; iMargins.iLeft = aMargin;
@ -657,7 +700,9 @@ void BooksPageWidget::setLeftMargin(int aMargin)
} }
} }
void BooksPageWidget::setRightMargin(int aMargin) void
BooksPageWidget::setRightMargin(
int aMargin)
{ {
if (iMargins.iRight != aMargin) { if (iMargins.iRight != aMargin) {
iMargins.iRight = aMargin; iMargins.iRight = aMargin;
@ -667,7 +712,9 @@ void BooksPageWidget::setRightMargin(int aMargin)
} }
} }
void BooksPageWidget::setTopMargin(int aMargin) void
BooksPageWidget::setTopMargin(
int aMargin)
{ {
if (iMargins.iTop != aMargin) { if (iMargins.iTop != aMargin) {
iMargins.iTop = aMargin; iMargins.iTop = aMargin;
@ -677,7 +724,9 @@ void BooksPageWidget::setTopMargin(int aMargin)
} }
} }
void BooksPageWidget::setBottomMargin(int aMargin) void
BooksPageWidget::setBottomMargin(
int aMargin)
{ {
if (iMargins.iBottom != aMargin) { if (iMargins.iBottom != aMargin) {
iMargins.iBottom = aMargin; iMargins.iBottom = aMargin;
@ -687,7 +736,9 @@ void BooksPageWidget::setBottomMargin(int aMargin)
} }
} }
void BooksPageWidget::paint(QPainter* aPainter) void
BooksPageWidget::paint(
QPainter* aPainter)
{ {
if (!iImage.isNull()) { if (!iImage.isNull()) {
HDEBUG("page" << iPage); HDEBUG("page" << iPage);
@ -707,12 +758,14 @@ void BooksPageWidget::paint(QPainter* aPainter)
} }
} }
bool BooksPageWidget::loading() const bool
BooksPageWidget::loading() const
{ {
return iPage >= 0 && iImage.isNull() && (iResetTask || iRenderTask); return iPage >= 0 && iImage.isNull() && (iResetTask || iRenderTask);
} }
void BooksPageWidget::resetView() void
BooksPageWidget::resetView()
{ {
BooksLoadingSignalBlocker block(this); BooksLoadingSignalBlocker block(this);
if (iResetTask) { if (iResetTask) {
@ -748,7 +801,8 @@ void BooksPageWidget::resetView()
} }
} }
void BooksPageWidget::cancelRepaint() void
BooksPageWidget::cancelRepaint()
{ {
BooksLoadingSignalBlocker block(this); BooksLoadingSignalBlocker block(this);
if (iRenderTask) { if (iRenderTask) {
@ -757,7 +811,8 @@ void BooksPageWidget::cancelRepaint()
} }
} }
void BooksPageWidget::scheduleRepaint() void
BooksPageWidget::scheduleRepaint()
{ {
BooksLoadingSignalBlocker block(this); BooksLoadingSignalBlocker block(this);
cancelRepaint(); cancelRepaint();
@ -773,7 +828,8 @@ void BooksPageWidget::scheduleRepaint()
} }
} }
void BooksPageWidget::onResetTaskDone() void
BooksPageWidget::onResetTaskDone()
{ {
BooksLoadingSignalBlocker block(this); BooksLoadingSignalBlocker block(this);
HASSERT(sender() == iResetTask); HASSERT(sender() == iResetTask);
@ -784,7 +840,8 @@ void BooksPageWidget::onResetTaskDone()
scheduleRepaint(); scheduleRepaint();
} }
void BooksPageWidget::onRenderTaskDone() void
BooksPageWidget::onRenderTaskDone()
{ {
BooksLoadingSignalBlocker block(this); BooksLoadingSignalBlocker block(this);
HASSERT(sender() == iRenderTask); HASSERT(sender() == iRenderTask);
@ -794,7 +851,8 @@ void BooksPageWidget::onRenderTaskDone()
update(); update();
} }
void BooksPageWidget::onPressTaskDone() void
BooksPageWidget::onPressTaskDone()
{ {
HASSERT(sender() == iPressTask); HASSERT(sender() == iPressTask);
HDEBUG(iPressTask->iKind); HDEBUG(iPressTask->iKind);
@ -809,7 +867,8 @@ void BooksPageWidget::onPressTaskDone()
task->release(this); task->release(this);
} }
void BooksPageWidget::onClearSelectionTaskDone() void
BooksPageWidget::onClearSelectionTaskDone()
{ {
HASSERT(sender() == iClearSelectionTask); HASSERT(sender() == iClearSelectionTask);
ClearSelectionTask* task = iClearSelectionTask; ClearSelectionTask* task = iClearSelectionTask;
@ -829,7 +888,8 @@ void BooksPageWidget::onClearSelectionTaskDone()
task->release(this); task->release(this);
} }
void BooksPageWidget::onStartSelectionTaskDone() void
BooksPageWidget::onStartSelectionTaskDone()
{ {
HASSERT(sender() == iStartSelectionTask); HASSERT(sender() == iStartSelectionTask);
StartSelectionTask* task = iStartSelectionTask; StartSelectionTask* task = iStartSelectionTask;
@ -859,7 +919,8 @@ void BooksPageWidget::onStartSelectionTaskDone()
task->release(this); task->release(this);
} }
void BooksPageWidget::onExtendSelectionTaskDone() void
BooksPageWidget::onExtendSelectionTaskDone()
{ {
ExtendSelectionTask* task = (ExtendSelectionTask*)sender(); ExtendSelectionTask* task = (ExtendSelectionTask*)sender();
HASSERT(iExtendSelectionTasks.contains(task)); HASSERT(iExtendSelectionTasks.contains(task));
@ -878,7 +939,8 @@ void BooksPageWidget::onExtendSelectionTaskDone()
task->release(this); task->release(this);
} }
void BooksPageWidget::onFootnoteTaskDone() void
BooksPageWidget::onFootnoteTaskDone()
{ {
HASSERT(sender() == iFootnoteTask); HASSERT(sender() == iFootnoteTask);
@ -901,7 +963,8 @@ void BooksPageWidget::onFootnoteTaskDone()
task->release(this); task->release(this);
} }
void BooksPageWidget::onLongPressTaskDone() void
BooksPageWidget::onLongPressTaskDone()
{ {
HASSERT(sender() == iLongPressTask); HASSERT(sender() == iLongPressTask);
HDEBUG(iLongPressTask->iKind); HDEBUG(iLongPressTask->iKind);
@ -975,14 +1038,16 @@ void BooksPageWidget::onLongPressTaskDone()
task->release(this); task->release(this);
} }
void BooksPageWidget::updateSize() void
BooksPageWidget::updateSize()
{ {
HDEBUG("page" << iPage << QSize(width(), height())); HDEBUG("page" << iPage << QSize(width(), height()));
iImage = QImage(); iImage = QImage();
resetView(); resetView();
} }
void BooksPageWidget::onWidthChanged() void
BooksPageWidget::onWidthChanged()
{ {
HVERBOSE((int)width()); HVERBOSE((int)width());
// Width change will probably be followed by height change // Width change will probably be followed by height change
@ -991,7 +1056,8 @@ void BooksPageWidget::onWidthChanged()
update(); update();
} }
void BooksPageWidget::onHeightChanged() void
BooksPageWidget::onHeightChanged()
{ {
HVERBOSE((int)height()); HVERBOSE((int)height());
if (iResizeTimer->isActive()) { if (iResizeTimer->isActive()) {
@ -1005,7 +1071,8 @@ void BooksPageWidget::onHeightChanged()
} }
} }
void BooksPageWidget::onResizeTimeout() void
BooksPageWidget::onResizeTimeout()
{ {
// This can only happen if only width or height has changed. Normally, // This can only happen if only width or height has changed. Normally,
// width change is followed by height change and view is reset from the // width change is followed by height change and view is reset from the
@ -1013,7 +1080,10 @@ void BooksPageWidget::onResizeTimeout()
updateSize(); updateSize();
} }
void BooksPageWidget::handleLongPress(int aX, int aY) void
BooksPageWidget::handleLongPress(
int aX,
int aY)
{ {
HDEBUG(aX << aY); HDEBUG(aX << aY);
if (!iResetTask && !iRenderTask && !iData.isNull()) { if (!iResetTask && !iRenderTask && !iData.isNull()) {
@ -1023,7 +1093,10 @@ void BooksPageWidget::handleLongPress(int aX, int aY)
} }
} }
void BooksPageWidget::handlePress(int aX, int aY) void
BooksPageWidget::handlePress(
int aX,
int aY)
{ {
HDEBUG(aX << aY); HDEBUG(aX << aY);
if (!iResetTask && !iRenderTask && !iData.isNull()) { if (!iResetTask && !iRenderTask && !iData.isNull()) {
@ -1033,7 +1106,10 @@ void BooksPageWidget::handlePress(int aX, int aY)
} }
} }
void BooksPageWidget::handlePositionChanged(int aX, int aY) void
BooksPageWidget::handlePositionChanged(
int aX,
int aY)
{ {
if (iSelecting && !iData.isNull()) { if (iSelecting && !iData.isNull()) {
HDEBUG(aX << aY); HDEBUG(aX << aY);
@ -1063,7 +1139,8 @@ void BooksPageWidget::handlePositionChanged(int aX, int aY)
} }
} }
void BooksPageWidget::clearSelection() void
BooksPageWidget::clearSelection()
{ {
if (!iData.isNull()) { if (!iData.isNull()) {
if (iClearSelectionTask) iClearSelectionTask->release(this); if (iClearSelectionTask) iClearSelectionTask->release(this);

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2015-2020 Jolla Ltd. * Copyright (C) 2015-2022 Jolla Ltd.
* Copyright (C) 2015-2020 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 the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
* *
@ -70,40 +70,40 @@ public:
explicit BooksPageWidget(QQuickItem* aParent = NULL); explicit BooksPageWidget(QQuickItem* aParent = NULL);
~BooksPageWidget(); ~BooksPageWidget();
bool loading() const; bool loading() const Q_DECL_OVERRIDE;
bool selecting() const; bool selecting() const;
bool selectionEmpty() const; bool selectionEmpty() const;
bool pressed() const; bool pressed() const;
void setPressed(bool aPressed); void setPressed(bool);
bool currentPage() const; bool currentPage() const;
void setCurrentPage(bool aCurrentPage); void setCurrentPage(bool);
int page() const; int page() const;
void setPage(int aPage); void setPage(int);
BooksBookModel* model() const; BooksBookModel* model() const;
void setModel(BooksBookModel* aModel); void setModel(BooksBookModel*);
const BooksPos& bookPos() const; const BooksPos& bookPos() const;
void setBookPos(const BooksPos& aBookPos); void setBookPos(const BooksPos&);
int leftMargin() const; int leftMargin() const;
int rightMargin() const; int rightMargin() const;
int topMargin() const; int topMargin() const;
int bottomMargin() const; int bottomMargin() const;
void setLeftMargin(int aMargin); void setLeftMargin(int);
void setRightMargin(int aMargin); void setRightMargin(int);
void setTopMargin(int aMargin); void setTopMargin(int);
void setBottomMargin(int aMargin); void setBottomMargin(int);
BooksMargins margins() const; BooksMargins margins() const;
Q_INVOKABLE void handlePress(int aX, int aY); Q_INVOKABLE void handlePress(int, int);
Q_INVOKABLE void handleLongPress(int aX, int aY); Q_INVOKABLE void handleLongPress(int, int);
Q_INVOKABLE void handlePositionChanged(int aX, int aY); Q_INVOKABLE void handlePositionChanged(int, int);
Q_INVOKABLE void clearSelection(); Q_INVOKABLE void clearSelection();
Q_SIGNALS: Q_SIGNALS:
@ -143,7 +143,7 @@ private Q_SLOTS:
void onFootnoteTaskDone(); void onFootnoteTaskDone();
private: private:
void paint(QPainter *painter) Q_DECL_OVERRIDE; void paint(QPainter*) Q_DECL_OVERRIDE;
void updateSize(); void updateSize();
void resetView(); void resetView();
void releaseExtendSelectionTasks(); void releaseExtendSelectionTasks();