harbour-books/app/src/BooksPageWidget.h

153 lines
5.1 KiB
C
Raw Normal View History

2015-06-28 14:22:35 +03:00
/*
2016-10-08 19:57:54 +03:00
* Copyright (C) 2015-2016 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>
class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty
{
Q_OBJECT
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
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)
Q_PROPERTY(BooksSettings* settings READ settings WRITE setSettings NOTIFY settingsChanged)
public:
class Data;
BooksPageWidget(QQuickItem* aParent = NULL);
~BooksPageWidget();
bool loading() const;
int page() const { return iPage; }
void setPage(int aPage);
BooksBookModel* model() const { return iModel; }
void setModel(BooksBookModel* aModel);
BooksSettings* settings() const { return iSettings; }
void setSettings(BooksSettings* aSettings);
int leftMargin() const { return iMargins.iLeft; }
int rightMargin() const { return iMargins.iRight; }
int topMargin() const { return iMargins.iTop; }
int bottomMargin() const { return iMargins.iBottom; }
void setLeftMargin(int aMargin);
void setRightMargin(int aMargin);
void setTopMargin(int aMargin);
void setBottomMargin(int aMargin);
BooksMargins margins() const { return iMargins; }
2016-10-08 14:56:14 +03:00
Q_INVOKABLE void handleLongPress(int aX, int aY);
2015-06-28 14:22:35 +03:00
Q_SIGNALS:
void loadingChanged();
void pageChanged();
void modelChanged();
void settingsChanged();
void leftMarginChanged();
void rightMarginChanged();
void topMarginChanged();
void bottomMarginChanged();
2016-10-08 14:56:14 +03:00
void browserLinkPressed(QString url);
2016-10-08 19:57:54 +03:00
void imagePressed(QString url, QRect rect);
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();
2016-10-08 14:56:14 +03:00
void onLongPressTaskDone();
2015-06-28 14:22:35 +03:00
private:
void paint(QPainter *painter);
void updateSize();
void resetView();
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-08 14:56:14 +03:00
class LongPressTask;
2015-06-28 14:22:35 +03:00
shared_ptr<BooksTaskQueue> iTaskQueue;
shared_ptr<ZLTextStyle> iTextStyle;
BooksPos iPageMark;
QTimer* iResizeTimer;
BooksBookModel* iModel;
BooksSettings* iSettings;
BooksMargins iMargins;
shared_ptr<Data> iData;
shared_ptr<QImage> iImage;
ResetTask* iResetTask;
RenderTask* iRenderTask;
2016-10-08 14:56:14 +03:00
LongPressTask* iLongPressTask;
2015-06-28 14:22:35 +03:00
bool iEmpty;
int iPage;
};
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