130 lines
4.5 KiB
C++
130 lines
4.5 KiB
C++
#ifndef APPSTATE_H
|
|
#define APPSTATE_H
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QUrl>
|
|
#include <QVariantMap>
|
|
#include <QVariantList>
|
|
|
|
class AppState : public QObject {
|
|
Q_OBJECT
|
|
Q_PROPERTY(QString lastFilePath READ lastFilePath WRITE setLastFilePath NOTIFY lastFilePathChanged)
|
|
Q_PROPERTY(int lastChapter READ lastChapter WRITE setLastChapter NOTIFY lastChapterChanged)
|
|
Q_PROPERTY(qreal lastScrollPosition READ lastScrollPosition WRITE setLastScrollPosition NOTIFY lastScrollPositionChanged)
|
|
Q_PROPERTY(int lastScrollIndex READ lastScrollIndex WRITE setLastScrollIndex NOTIFY lastScrollIndexChanged)
|
|
Q_PROPERTY(qreal lastScrollOffset READ lastScrollOffset WRITE setLastScrollOffset NOTIFY lastScrollOffsetChanged)
|
|
Q_PROPERTY(int horizontalMargin READ horizontalMargin WRITE setHorizontalMargin NOTIFY horizontalMarginChanged)
|
|
Q_PROPERTY(int verticalMargin READ verticalMargin WRITE setVerticalMargin NOTIFY verticalMarginChanged)
|
|
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
|
Q_PROPERTY(qreal lineSpacing READ lineSpacing WRITE setLineSpacing NOTIFY lineSpacingChanged)
|
|
Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
|
|
Q_PROPERTY(int windowHeight READ windowHeight WRITE setWindowHeight NOTIFY windowHeightChanged)
|
|
Q_PROPERTY(int windowX READ windowX WRITE setWindowX NOTIFY windowXChanged)
|
|
Q_PROPERTY(int windowY READ windowY WRITE setWindowY NOTIFY windowYChanged)
|
|
Q_PROPERTY(QVariantList libraryBooks READ libraryBooks NOTIFY libraryBooksChanged)
|
|
Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged)
|
|
Q_PROPERTY(bool sidebarOpen READ sidebarOpen WRITE setSidebarOpen NOTIFY sidebarOpenChanged)
|
|
|
|
public:
|
|
explicit AppState(QObject *parent = nullptr);
|
|
|
|
QString lastFilePath() const;
|
|
void setLastFilePath(const QString &path);
|
|
|
|
int lastChapter() const;
|
|
void setLastChapter(int chapter);
|
|
|
|
qreal lastScrollPosition() const;
|
|
void setLastScrollPosition(qreal position);
|
|
|
|
int lastScrollIndex() const;
|
|
void setLastScrollIndex(int index);
|
|
|
|
qreal lastScrollOffset() const;
|
|
void setLastScrollOffset(qreal offset);
|
|
|
|
int horizontalMargin() const;
|
|
void setHorizontalMargin(int margin);
|
|
|
|
int verticalMargin() const;
|
|
void setVerticalMargin(int margin);
|
|
|
|
int fontSize() const;
|
|
void setFontSize(int size);
|
|
|
|
qreal lineSpacing() const;
|
|
void setLineSpacing(qreal spacing);
|
|
|
|
int windowWidth() const;
|
|
void setWindowWidth(int width);
|
|
|
|
int windowHeight() const;
|
|
void setWindowHeight(int height);
|
|
|
|
int windowX() const;
|
|
void setWindowX(int x);
|
|
|
|
int windowY() const;
|
|
void setWindowY(int y);
|
|
|
|
Q_INVOKABLE QUrl lastFileUrl() const;
|
|
|
|
Q_INVOKABLE void saveBookPosition(const QString &filePath, int chapter, int scrollIndex, qreal scrollOffset);
|
|
Q_INVOKABLE QVariantMap loadBookPosition(const QString &filePath) const;
|
|
|
|
QString lastPage() const;
|
|
void setLastPage(const QString &page);
|
|
|
|
bool sidebarOpen() const;
|
|
void setSidebarOpen(bool open);
|
|
|
|
Q_INVOKABLE void addOrUpdateLibraryBook(const QString &filePath, const QString &title, const QString &author, double progress);
|
|
Q_INVOKABLE void removeLibraryBook(const QString &filePath);
|
|
Q_INVOKABLE QVariantList libraryBooks() const;
|
|
|
|
Q_INVOKABLE void save();
|
|
Q_INVOKABLE void restore();
|
|
|
|
signals:
|
|
void lastFilePathChanged();
|
|
void lastChapterChanged();
|
|
void lastScrollPositionChanged();
|
|
void lastScrollIndexChanged();
|
|
void lastScrollOffsetChanged();
|
|
void horizontalMarginChanged();
|
|
void verticalMarginChanged();
|
|
void fontSizeChanged();
|
|
void lineSpacingChanged();
|
|
void stateRestored();
|
|
void windowWidthChanged();
|
|
void windowHeightChanged();
|
|
void windowXChanged();
|
|
void windowYChanged();
|
|
void libraryBooksChanged();
|
|
void lastPageChanged();
|
|
void sidebarOpenChanged();
|
|
|
|
private:
|
|
void loadLibraryBooks();
|
|
void saveLibraryBooks();
|
|
QString m_lastFilePath;
|
|
int m_lastChapter = 0;
|
|
qreal m_lastScrollPosition = 0.0;
|
|
int m_lastScrollIndex = 0;
|
|
qreal m_lastScrollOffset = 0.0;
|
|
int m_horizontalMargin = 32;
|
|
int m_verticalMargin = 8;
|
|
int m_fontSize = 16;
|
|
qreal m_lineSpacing = 1.6;
|
|
int m_windowWidth = 1024;
|
|
int m_windowHeight = 768;
|
|
int m_windowX = -1;
|
|
int m_windowY = -1;
|
|
QVariantList m_libraryBooks;
|
|
QString m_lastPage = QStringLiteral("starter");
|
|
bool m_sidebarOpen = false;
|
|
};
|
|
|
|
#endif // APPSTATE_H
|