2015-06-28 14:22:35 +03:00
|
|
|
/*
|
2017-08-03 18:48:17 +03:00
|
|
|
* Copyright (C) 2015-2017 Jolla Ltd.
|
2015-06-28 14:22:35 +03:00
|
|
|
* Contact: Slava Monich <slava.monich@jolla.com>
|
|
|
|
*
|
|
|
|
* You may use this file under the terms of the BSD license as follows:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2016-10-08 19:57:54 +03:00
|
|
|
* * Neither the name of Jolla Ltd nor the names of its contributors
|
2015-06-28 14:22:35 +03:00
|
|
|
* may be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BOOKS_PAGE_WIDGET_H
|
|
|
|
#define BOOKS_PAGE_WIDGET_H
|
|
|
|
|
|
|
|
#include "BooksTypes.h"
|
|
|
|
#include "BooksTask.h"
|
|
|
|
#include "BooksTaskQueue.h"
|
|
|
|
#include "BooksSettings.h"
|
|
|
|
#include "BooksBookModel.h"
|
|
|
|
#include "BooksPos.h"
|
|
|
|
#include "BooksPaintContext.h"
|
|
|
|
#include "BooksLoadingProperty.h"
|
|
|
|
|
|
|
|
#include "ZLTextStyle.h"
|
|
|
|
|
|
|
|
#include <QQuickPaintedItem>
|
|
|
|
#include <QTimer>
|
2017-09-07 19:03:17 +03:00
|
|
|
#include <QList>
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
|
2017-09-07 19:03:17 +03:00
|
|
|
Q_PROPERTY(bool selecting READ selecting NOTIFY selectingChanged)
|
|
|
|
Q_PROPERTY(bool selectionEmpty READ selectionEmpty NOTIFY selectionEmptyChanged)
|
|
|
|
Q_PROPERTY(bool pressed READ pressed WRITE setPressed NOTIFY pressedChanged)
|
|
|
|
Q_PROPERTY(bool currentPage READ currentPage WRITE setCurrentPage NOTIFY currentPageChanged)
|
2015-06-28 14:22:35 +03:00
|
|
|
Q_PROPERTY(int page READ page WRITE setPage NOTIFY pageChanged)
|
|
|
|
Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
|
|
|
|
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(BooksBookModel* model READ model WRITE setModel NOTIFY modelChanged)
|
|
|
|
|
|
|
|
public:
|
|
|
|
class Data;
|
|
|
|
|
2017-09-07 19:03:17 +03:00
|
|
|
explicit BooksPageWidget(QQuickItem* aParent = NULL);
|
2015-06-28 14:22:35 +03:00
|
|
|
~BooksPageWidget();
|
|
|
|
|
|
|
|
bool loading() const;
|
2017-09-07 19:03:17 +03:00
|
|
|
bool selecting() const;
|
|
|
|
bool selectionEmpty() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
2017-09-07 19:03:17 +03:00
|
|
|
bool pressed() const;
|
|
|
|
void setPressed(bool aPressed);
|
|
|
|
|
|
|
|
bool currentPage() const;
|
|
|
|
void setCurrentPage(bool aCurrentPage);
|
|
|
|
|
|
|
|
int page() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
void setPage(int aPage);
|
|
|
|
|
2017-09-07 19:03:17 +03:00
|
|
|
BooksBookModel* model() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
void setModel(BooksBookModel* aModel);
|
|
|
|
|
2017-09-07 19:03:17 +03:00
|
|
|
int leftMargin() const;
|
|
|
|
int rightMargin() const;
|
|
|
|
int topMargin() const;
|
|
|
|
int bottomMargin() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
void setLeftMargin(int aMargin);
|
|
|
|
void setRightMargin(int aMargin);
|
|
|
|
void setTopMargin(int aMargin);
|
|
|
|
void setBottomMargin(int aMargin);
|
|
|
|
|
2017-09-07 19:03:17 +03:00
|
|
|
BooksMargins margins() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
2016-10-16 20:07:03 +03:00
|
|
|
Q_INVOKABLE void handlePress(int aX, int aY);
|
2017-09-07 19:03:17 +03:00
|
|
|
Q_INVOKABLE void handleLongPress(int aX, int aY);
|
|
|
|
Q_INVOKABLE void handlePositionChanged(int aX, int aY);
|
|
|
|
Q_INVOKABLE void clearSelection();
|
2016-10-08 14:56:14 +03:00
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
Q_SIGNALS:
|
|
|
|
void loadingChanged();
|
2017-09-07 19:03:17 +03:00
|
|
|
void pressedChanged();
|
|
|
|
void selectingChanged();
|
|
|
|
void selectionEmptyChanged();
|
|
|
|
void currentPageChanged();
|
2015-06-28 14:22:35 +03:00
|
|
|
void pageChanged();
|
|
|
|
void modelChanged();
|
|
|
|
void leftMarginChanged();
|
|
|
|
void rightMarginChanged();
|
|
|
|
void topMarginChanged();
|
|
|
|
void bottomMarginChanged();
|
2016-10-08 14:56:14 +03:00
|
|
|
void browserLinkPressed(QString url);
|
2016-11-02 16:33:26 +03:00
|
|
|
void imagePressed(QString imageId, QRect rect);
|
|
|
|
void activeTouch(int touchX, int touchY);
|
2016-10-16 20:07:03 +03:00
|
|
|
void jumpToPage(int page);
|
2016-11-02 16:33:26 +03:00
|
|
|
void showFootnote(int touchX, int touchY, QString text, QString imageId);
|
2017-08-03 18:48:17 +03:00
|
|
|
void pushPosition(BooksPos position);
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void onWidthChanged();
|
|
|
|
void onHeightChanged();
|
|
|
|
void onResizeTimeout();
|
|
|
|
void onBookModelChanged();
|
|
|
|
void onBookModelDestroyed();
|
|
|
|
void onBookModelPageMarksChanged();
|
|
|
|
void onBookModelLoadingChanged();
|
|
|
|
void onTextStyleChanged();
|
2015-07-11 01:35:13 +03:00
|
|
|
void onInvertColorsChanged();
|
2015-06-28 14:22:35 +03:00
|
|
|
void onResetTaskDone();
|
|
|
|
void onRenderTaskDone();
|
2017-09-07 19:03:17 +03:00
|
|
|
void onClearSelectionTaskDone();
|
|
|
|
void onStartSelectionTaskDone();
|
|
|
|
void onExtendSelectionTaskDone();
|
2016-10-16 20:07:03 +03:00
|
|
|
void onPressTaskDone();
|
2016-10-08 14:56:14 +03:00
|
|
|
void onLongPressTaskDone();
|
2016-11-02 16:33:26 +03:00
|
|
|
void onFootnoteTaskDone();
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
void paint(QPainter *painter);
|
|
|
|
void updateSize();
|
|
|
|
void resetView();
|
2017-09-07 19:03:17 +03:00
|
|
|
void releaseExtendSelectionTasks();
|
2015-06-28 14:22:35 +03:00
|
|
|
void scheduleRepaint();
|
|
|
|
void cancelRepaint();
|
2015-07-11 01:35:13 +03:00
|
|
|
bool invertColors() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
class ResetTask;
|
|
|
|
class RenderTask;
|
2016-10-16 20:07:03 +03:00
|
|
|
class PressTask;
|
2017-09-07 19:03:17 +03:00
|
|
|
class ClearSelectionTask;
|
|
|
|
class StartSelectionTask;
|
|
|
|
class ExtendSelectionTask;
|
2016-11-02 16:33:26 +03:00
|
|
|
class FootnoteTask;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
2016-10-16 23:36:13 +03:00
|
|
|
QSharedPointer<BooksSettings> iSettings;
|
2015-06-28 14:22:35 +03:00
|
|
|
shared_ptr<BooksTaskQueue> iTaskQueue;
|
|
|
|
shared_ptr<ZLTextStyle> iTextStyle;
|
|
|
|
BooksPos iPageMark;
|
|
|
|
QTimer* iResizeTimer;
|
|
|
|
BooksBookModel* iModel;
|
|
|
|
BooksMargins iMargins;
|
|
|
|
shared_ptr<Data> iData;
|
2016-11-02 16:33:26 +03:00
|
|
|
QImage iImage;
|
2015-06-28 14:22:35 +03:00
|
|
|
ResetTask* iResetTask;
|
|
|
|
RenderTask* iRenderTask;
|
2017-09-07 19:03:17 +03:00
|
|
|
ClearSelectionTask* iClearSelectionTask;
|
|
|
|
StartSelectionTask* iStartSelectionTask;
|
|
|
|
QList<ExtendSelectionTask*> iExtendSelectionTasks;
|
2016-10-16 20:07:03 +03:00
|
|
|
PressTask* iPressTask;
|
|
|
|
PressTask* iLongPressTask;
|
2016-11-02 16:33:26 +03:00
|
|
|
FootnoteTask* iFootnoteTask;
|
2015-06-28 14:22:35 +03:00
|
|
|
bool iEmpty;
|
2017-09-07 19:03:17 +03:00
|
|
|
bool iPressed;
|
|
|
|
bool iSelecting;
|
|
|
|
bool iSelectionEmpty;
|
|
|
|
bool iCurrentPage;
|
2015-06-28 14:22:35 +03:00
|
|
|
int iPage;
|
|
|
|
};
|
|
|
|
|
2017-09-07 19:03:17 +03:00
|
|
|
inline bool BooksPageWidget::pressed() const
|
|
|
|
{ return iPressed; }
|
|
|
|
inline bool BooksPageWidget::selecting() const
|
|
|
|
{ return iSelecting; }
|
|
|
|
inline bool BooksPageWidget::selectionEmpty() const
|
|
|
|
{ return iSelectionEmpty; }
|
|
|
|
inline bool BooksPageWidget::currentPage() const
|
|
|
|
{ return iCurrentPage; }
|
|
|
|
inline int BooksPageWidget::page() const
|
|
|
|
{ return iPage; }
|
|
|
|
inline BooksBookModel* BooksPageWidget::model() const
|
|
|
|
{ return iModel; }
|
|
|
|
inline int BooksPageWidget::leftMargin() const
|
|
|
|
{ return iMargins.iLeft; }
|
|
|
|
inline int BooksPageWidget::rightMargin() const
|
|
|
|
{ return iMargins.iRight; }
|
|
|
|
inline int BooksPageWidget::topMargin() const
|
|
|
|
{ return iMargins.iTop; }
|
|
|
|
inline int BooksPageWidget::bottomMargin() const
|
|
|
|
{ return iMargins.iBottom; }
|
|
|
|
inline BooksMargins BooksPageWidget::margins() const
|
|
|
|
{ return iMargins; }
|
2015-07-11 01:35:13 +03:00
|
|
|
inline bool BooksPageWidget::invertColors() const
|
|
|
|
{ return iSettings && iSettings->invertColors(); }
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
#endif // BOOKS_PAGE_WIDGET_H
|