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-16 20:07:03 +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_BOOK_MODEL_H
|
|
|
|
#define BOOKS_BOOK_MODEL_H
|
|
|
|
|
|
|
|
#include "BooksBook.h"
|
|
|
|
#include "BooksTask.h"
|
|
|
|
#include "BooksTaskQueue.h"
|
|
|
|
#include "BooksTextView.h"
|
|
|
|
#include "BooksSettings.h"
|
|
|
|
#include "BooksPos.h"
|
|
|
|
#include "BooksPaintContext.h"
|
|
|
|
#include "BooksLoadingProperty.h"
|
2017-08-03 18:48:17 +03:00
|
|
|
#include "BooksPageStack.h"
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
#include "ZLTextStyle.h"
|
|
|
|
#include "bookmodel/BookModel.h"
|
|
|
|
|
|
|
|
#include <QHash>
|
|
|
|
#include <QList>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QtQml>
|
|
|
|
#include <QQuickItem>
|
|
|
|
|
|
|
|
class BooksBookModel: public QAbstractListModel, private BooksLoadingProperty
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2015-08-24 13:23:24 +03:00
|
|
|
Q_ENUMS(ResetReason)
|
2015-06-28 14:22:35 +03:00
|
|
|
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
|
|
|
|
Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
|
|
|
|
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
|
|
|
|
Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
|
|
|
|
Q_PROPERTY(int pageCount READ pageCount NOTIFY pageCountChanged)
|
|
|
|
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)
|
2017-08-03 18:48:17 +03:00
|
|
|
Q_PROPERTY(BooksPageStack* pageStack READ pageStack CONSTANT)
|
2015-06-28 14:22:35 +03:00
|
|
|
Q_PROPERTY(BooksBook* book READ book WRITE setBook NOTIFY bookChanged)
|
2015-08-24 13:23:24 +03:00
|
|
|
Q_PROPERTY(ResetReason resetReason READ resetReason NOTIFY resetReasonChanged)
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
public:
|
2015-08-24 13:23:24 +03:00
|
|
|
// NOTE: These have to match the labels in BooksBookView.qml
|
|
|
|
enum ResetReason {
|
|
|
|
ReasonUnknown,
|
2015-11-03 01:33:58 +03:00
|
|
|
ReasonLoading,
|
2015-08-24 13:23:24 +03:00
|
|
|
ReasonIncreasingFontSize,
|
|
|
|
ReasonDecreasingFontSize
|
|
|
|
};
|
|
|
|
|
2015-12-13 14:46:53 +03:00
|
|
|
Q_INVOKABLE bool increaseFontSize();
|
|
|
|
Q_INVOKABLE bool decreaseFontSize();
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
explicit BooksBookModel(QObject* aParent = NULL);
|
|
|
|
~BooksBookModel();
|
|
|
|
|
|
|
|
bool loading() const;
|
|
|
|
int pageCount() const;
|
2017-08-03 18:48:17 +03:00
|
|
|
int progress() const;
|
|
|
|
QString title() const;
|
|
|
|
int width() const;
|
|
|
|
int height() const;
|
|
|
|
ResetReason resetReason() const;
|
|
|
|
BooksPageStack* pageStack() const;
|
|
|
|
|
|
|
|
QSize size() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
void setSize(QSize aSize);
|
|
|
|
|
2017-08-03 18:48:17 +03:00
|
|
|
BooksBook* book() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
void setBook(BooksBook* aBook);
|
|
|
|
|
2017-08-03 18:48: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);
|
|
|
|
|
|
|
|
BooksPos::List pageMarks() const;
|
|
|
|
BooksPos pageMark(int aPage) const;
|
2017-08-03 18:48:17 +03:00
|
|
|
BooksMargins margins() const;
|
|
|
|
shared_ptr<Book> bookRef() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
shared_ptr<BookModel> bookModel() const;
|
|
|
|
shared_ptr<ZLTextModel> bookTextModel() const;
|
|
|
|
shared_ptr<ZLTextModel> contentsModel() const;
|
2016-11-02 16:33:26 +03:00
|
|
|
shared_ptr<ZLTextModel> footnoteModel(const std::string& aId) const;
|
2017-08-03 18:48:17 +03:00
|
|
|
shared_ptr<ZLTextStyle> textStyle() const;
|
|
|
|
BooksPos linkPosition(const std::string& aLink) const;
|
2015-12-13 14:46:53 +03:00
|
|
|
int fontSizeAdjust() const;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
// QAbstractListModel
|
|
|
|
virtual QHash<int,QByteArray> roleNames() const;
|
|
|
|
virtual int rowCount(const QModelIndex& aParent) const;
|
|
|
|
virtual QVariant data(const QModelIndex& aIndex, int aRole) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateSize();
|
|
|
|
void updateModel(int aPrevPageCount);
|
2015-08-24 13:23:24 +03:00
|
|
|
void startReset(ResetReason aReason = ReasonUnknown, bool aFull = true);
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void onResetProgress(int aProgress);
|
|
|
|
void onResetDone();
|
|
|
|
void onTextStyleChanged();
|
2017-08-03 18:48:17 +03:00
|
|
|
void onPageStackChanged();
|
2015-06-28 14:22:35 +03:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void sizeChanged();
|
|
|
|
void bookChanged();
|
|
|
|
void bookModelChanged();
|
|
|
|
void titleChanged();
|
|
|
|
void loadingChanged();
|
|
|
|
void pageCountChanged();
|
|
|
|
void pageMarksChanged();
|
|
|
|
void progressChanged();
|
|
|
|
void leftMarginChanged();
|
|
|
|
void rightMarginChanged();
|
|
|
|
void topMarginChanged();
|
|
|
|
void bottomMarginChanged();
|
2015-08-24 13:23:24 +03:00
|
|
|
void resetReasonChanged();
|
2015-12-13 14:46:53 +03:00
|
|
|
bool textStyleChanged();
|
2015-06-28 14:22:35 +03:00
|
|
|
void jumpToPage(int index);
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Data;
|
2017-08-03 18:48:17 +03:00
|
|
|
class PagingTask;
|
2015-06-28 14:22:35 +03:00
|
|
|
|
2015-08-24 13:23:24 +03:00
|
|
|
ResetReason iResetReason;
|
2015-06-28 14:22:35 +03:00
|
|
|
int iProgress;
|
|
|
|
QSize iSize;
|
|
|
|
QString iTitle;
|
|
|
|
BooksMargins iMargins;
|
|
|
|
BooksBook* iBook;
|
|
|
|
shared_ptr<Book> iBookRef;
|
2017-08-03 18:48:17 +03:00
|
|
|
PagingTask* iPagingTask;
|
2015-06-28 14:22:35 +03:00
|
|
|
Data* iData;
|
|
|
|
Data* iData2;
|
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;
|
2017-08-03 18:48:17 +03:00
|
|
|
BooksPageStack* iPageStack;
|
2015-06-28 14:22:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
QML_DECLARE_TYPE(BooksBookModel)
|
|
|
|
|
2017-08-03 18:48:17 +03:00
|
|
|
inline int BooksBookModel::progress() const
|
|
|
|
{ return iProgress; }
|
|
|
|
inline QString BooksBookModel::title() const
|
|
|
|
{ return iTitle; }
|
|
|
|
inline int BooksBookModel::width() const
|
|
|
|
{ return iSize.width(); }
|
|
|
|
inline int BooksBookModel::height() const
|
|
|
|
{ return iSize.height(); }
|
|
|
|
inline BooksBookModel::ResetReason BooksBookModel::resetReason() const
|
|
|
|
{ return iResetReason; }
|
|
|
|
inline BooksPageStack* BooksBookModel::pageStack() const
|
|
|
|
{ return iPageStack; }
|
|
|
|
inline QSize BooksBookModel::size() const
|
|
|
|
{ return iSize; }
|
|
|
|
inline BooksBook* BooksBookModel::book() const
|
|
|
|
{ return iBook; }
|
|
|
|
inline int BooksBookModel::leftMargin() const
|
|
|
|
{ return iMargins.iLeft; }
|
|
|
|
inline int BooksBookModel::rightMargin() const
|
|
|
|
{ return iMargins.iRight; }
|
|
|
|
inline int BooksBookModel::topMargin() const
|
|
|
|
{ return iMargins.iTop; }
|
|
|
|
inline int BooksBookModel::bottomMargin() const
|
|
|
|
{ return iMargins.iBottom; }
|
|
|
|
inline BooksMargins BooksBookModel::margins() const
|
|
|
|
{ return iMargins; }
|
|
|
|
inline shared_ptr<Book> BooksBookModel::bookRef() const
|
|
|
|
{ return iBookRef; }
|
|
|
|
inline shared_ptr<ZLTextStyle> BooksBookModel::textStyle() const
|
|
|
|
{ return iTextStyle; }
|
|
|
|
|
2015-06-28 14:22:35 +03:00
|
|
|
#endif // BOOKS_BOOK_MODEL_H
|