[app] Implemented per-book font size
The global font size setting still exists, per-book value is the adjustment relative to the default value.
This commit is contained in:
parent
7ab1b72343
commit
58d0927e82
10 changed files with 191 additions and 72 deletions
|
@ -172,6 +172,8 @@ SilicaFlickable {
|
||||||
opacity: _currentState.tools ? 1 : 0
|
opacity: _currentState.tools ? 1 : 0
|
||||||
visible: opacity > 0 && book && bookModel.pageCount && !_loading
|
visible: opacity > 0 && book && bookModel.pageCount && !_loading
|
||||||
Behavior on opacity { FadeAnimation {} }
|
Behavior on opacity { FadeAnimation {} }
|
||||||
|
onIncreaseFontSize: bookModel.increaseFontSize()
|
||||||
|
onDecreaseFontSize: bookModel.decreaseFontSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
BooksPager {
|
BooksPager {
|
||||||
|
|
|
@ -42,6 +42,9 @@ Item {
|
||||||
property real leftSpaceUsed: dayNightModeSwitch.x + dayNightModeSwitch.width
|
property real leftSpaceUsed: dayNightModeSwitch.x + dayNightModeSwitch.width
|
||||||
property real rightSpaceUsed: width - decreaseFontSizeButton.x
|
property real rightSpaceUsed: width - decreaseFontSizeButton.x
|
||||||
|
|
||||||
|
signal increaseFontSize();
|
||||||
|
signal decreaseFontSize();
|
||||||
|
|
||||||
property real _spacingBy2: Math.ceil(spacing/2)
|
property real _spacingBy2: Math.ceil(spacing/2)
|
||||||
|
|
||||||
// Left side
|
// Left side
|
||||||
|
@ -104,7 +107,7 @@ Item {
|
||||||
opacity: globalSettings.invertColors ? 1 : 0.5
|
opacity: globalSettings.invertColors ? 1 : 0.5
|
||||||
Behavior on opacity { FadeAnimation {} }
|
Behavior on opacity { FadeAnimation {} }
|
||||||
}
|
}
|
||||||
onClicked: globalSettings.increaseFontSize()
|
onClicked: pageTools.increaseFontSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
@ -128,6 +131,6 @@ Item {
|
||||||
opacity: globalSettings.invertColors ? 1 : 0.5
|
opacity: globalSettings.invertColors ? 1 : 0.5
|
||||||
Behavior on opacity { FadeAnimation {} }
|
Behavior on opacity { FadeAnimation {} }
|
||||||
}
|
}
|
||||||
onClicked: globalSettings.decreaseFontSize()
|
onClicked: pageTools.decreaseFontSize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "BooksTextView.h"
|
#include "BooksTextView.h"
|
||||||
#include "BooksTextStyle.h"
|
#include "BooksTextStyle.h"
|
||||||
#include "BooksPaintContext.h"
|
#include "BooksPaintContext.h"
|
||||||
|
#include "BooksSettings.h"
|
||||||
#include "BooksUtil.h"
|
#include "BooksUtil.h"
|
||||||
|
|
||||||
#include "HarbourJson.h"
|
#include "HarbourJson.h"
|
||||||
|
@ -57,8 +58,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#define BOOK_STATE_POSITION "position"
|
#define BOOK_STATE_FONT_SIZE_ADJUST "fontSizeAdjust"
|
||||||
#define BOOK_COVER_SUFFIX ".cover."
|
#define BOOK_STATE_POSITION "position"
|
||||||
|
#define BOOK_COVER_SUFFIX ".cover."
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// BooksBook::CoverContext
|
// BooksBook::CoverContext
|
||||||
|
@ -327,6 +329,7 @@ BooksBook::BooksBook(const BooksStorage& aStorage, QString aRelativePath,
|
||||||
QVariantMap state;
|
QVariantMap state;
|
||||||
if (HarbourJson::load(iStateFilePath, state)) {
|
if (HarbourJson::load(iStateFilePath, state)) {
|
||||||
iLastPos = BooksPos::fromVariant(state.value(BOOK_STATE_POSITION));
|
iLastPos = BooksPos::fromVariant(state.value(BOOK_STATE_POSITION));
|
||||||
|
iFontSizeAdjust = state.value(BOOK_STATE_FONT_SIZE_ADJUST).toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Refcounted BooksBook objects are managed by C++ code
|
// Refcounted BooksBook objects are managed by C++ code
|
||||||
|
@ -335,6 +338,7 @@ BooksBook::BooksBook(const BooksStorage& aStorage, QString aRelativePath,
|
||||||
|
|
||||||
void BooksBook::init()
|
void BooksBook::init()
|
||||||
{
|
{
|
||||||
|
iFontSizeAdjust = 0;
|
||||||
iCoverTask = NULL;
|
iCoverTask = NULL;
|
||||||
iCoverTasksDone = false;
|
iCoverTasksDone = false;
|
||||||
iCopyingOut = false;
|
iCopyingOut = false;
|
||||||
|
@ -398,19 +402,41 @@ bool BooksBook::accessible() const
|
||||||
return !iCopyingOut;
|
return !iCopyingOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BooksBook::setFontSizeAdjust(int aFontSizeAdjust)
|
||||||
|
{
|
||||||
|
if (aFontSizeAdjust > BooksSettings::FontSizeSteps) {
|
||||||
|
aFontSizeAdjust = BooksSettings::FontSizeSteps;
|
||||||
|
} else if (aFontSizeAdjust < -BooksSettings::FontSizeSteps) {
|
||||||
|
aFontSizeAdjust = -BooksSettings::FontSizeSteps;
|
||||||
|
}
|
||||||
|
if (iFontSizeAdjust != aFontSizeAdjust) {
|
||||||
|
iFontSizeAdjust = aFontSizeAdjust;
|
||||||
|
requestSave();
|
||||||
|
Q_EMIT fontSizeAdjustChanged();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BooksBook::setLastPos(const BooksPos& aPos)
|
void BooksBook::setLastPos(const BooksPos& aPos)
|
||||||
{
|
{
|
||||||
if (iLastPos != aPos) {
|
if (iLastPos != aPos) {
|
||||||
iLastPos = aPos;
|
iLastPos = aPos;
|
||||||
// We only need save timer if we have the state file
|
requestSave();
|
||||||
if (!iSaveTimer && iStorage.isValid()) {
|
|
||||||
iSaveTimer = new BooksSaveTimer(this);
|
|
||||||
connect(iSaveTimer, SIGNAL(save()), SLOT(saveState()));
|
|
||||||
}
|
|
||||||
if (iSaveTimer) iSaveTimer->requestSave();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BooksBook::requestSave()
|
||||||
|
{
|
||||||
|
// We only need save timer if we have the state file
|
||||||
|
if (!iSaveTimer && iStorage.isValid()) {
|
||||||
|
iSaveTimer = new BooksSaveTimer(this);
|
||||||
|
connect(iSaveTimer, SIGNAL(save()), SLOT(saveState()));
|
||||||
|
}
|
||||||
|
if (iSaveTimer) iSaveTimer->requestSave();
|
||||||
|
}
|
||||||
|
|
||||||
void BooksBook::setCopyingOut(bool aValue)
|
void BooksBook::setCopyingOut(bool aValue)
|
||||||
{
|
{
|
||||||
if (iCopyingOut != aValue) {
|
if (iCopyingOut != aValue) {
|
||||||
|
@ -511,6 +537,7 @@ void BooksBook::saveState()
|
||||||
QVariantMap state;
|
QVariantMap state;
|
||||||
HarbourJson::load(iStateFilePath, state);
|
HarbourJson::load(iStateFilePath, state);
|
||||||
state.insert(BOOK_STATE_POSITION, iLastPos.toVariant());
|
state.insert(BOOK_STATE_POSITION, iLastPos.toVariant());
|
||||||
|
state.insert(BOOK_STATE_FONT_SIZE_ADJUST, iFontSizeAdjust);
|
||||||
if (HarbourJson::save(iStateFilePath, state)) {
|
if (HarbourJson::save(iStateFilePath, state)) {
|
||||||
HDEBUG("wrote" << iStateFilePath);
|
HDEBUG("wrote" << iStateFilePath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ class BooksBook : public QObject, public BooksItem
|
||||||
Q_PROPERTY(bool accessible READ accessible NOTIFY accessibleChanged)
|
Q_PROPERTY(bool accessible READ accessible NOTIFY accessibleChanged)
|
||||||
Q_PROPERTY(bool loadingCover READ loadingCover NOTIFY loadingCoverChanged)
|
Q_PROPERTY(bool loadingCover READ loadingCover NOTIFY loadingCoverChanged)
|
||||||
Q_PROPERTY(bool copyingOut READ copyingOut NOTIFY copyingOutChanged)
|
Q_PROPERTY(bool copyingOut READ copyingOut NOTIFY copyingOutChanged)
|
||||||
|
Q_PROPERTY(bool fontSizeAdjust READ fontSizeAdjust WRITE setFontSizeAdjust NOTIFY fontSizeAdjustChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BooksBook(QObject* aParent = NULL);
|
explicit BooksBook(QObject* aParent = NULL);
|
||||||
|
@ -75,6 +76,8 @@ public:
|
||||||
|
|
||||||
QString title() const { return iTitle; }
|
QString title() const { return iTitle; }
|
||||||
QString authors() const { return iAuthors; }
|
QString authors() const { return iAuthors; }
|
||||||
|
int fontSizeAdjust() const { return iFontSizeAdjust; }
|
||||||
|
bool setFontSizeAdjust(int aFontSizeAdjust);
|
||||||
BooksPos lastPos() const { return iLastPos; }
|
BooksPos lastPos() const { return iLastPos; }
|
||||||
void setLastPos(const BooksPos& aPos);
|
void setLastPos(const BooksPos& aPos);
|
||||||
shared_ptr<Book> bookRef() const { return iBook; }
|
shared_ptr<Book> bookRef() const { return iBook; }
|
||||||
|
@ -107,6 +110,7 @@ Q_SIGNALS:
|
||||||
void loadingCoverChanged();
|
void loadingCoverChanged();
|
||||||
void accessibleChanged();
|
void accessibleChanged();
|
||||||
void copyingOutChanged();
|
void copyingOutChanged();
|
||||||
|
void fontSizeAdjustChanged();
|
||||||
void movedAway();
|
void movedAway();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
@ -118,11 +122,13 @@ private:
|
||||||
void init();
|
void init();
|
||||||
bool coverTaskDone();
|
bool coverTaskDone();
|
||||||
bool makeLink(QString aDestPath);
|
bool makeLink(QString aDestPath);
|
||||||
|
void requestSave();
|
||||||
QString cachedImagePath() const;
|
QString cachedImagePath() const;
|
||||||
static bool isCanceled(CopyOperation* aOperation);
|
static bool isCanceled(CopyOperation* aOperation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAtomicInt iRef;
|
QAtomicInt iRef;
|
||||||
|
int iFontSizeAdjust;
|
||||||
BooksPos iLastPos;
|
BooksPos iLastPos;
|
||||||
BooksStorage iStorage;
|
BooksStorage iStorage;
|
||||||
shared_ptr<Book> iBook;
|
shared_ptr<Book> iBook;
|
||||||
|
|
|
@ -222,6 +222,11 @@ BooksBookModel::BooksBookModel(QObject* aParent) :
|
||||||
BooksBookModel::~BooksBookModel()
|
BooksBookModel::~BooksBookModel()
|
||||||
{
|
{
|
||||||
if (iTask) iTask->release(this);
|
if (iTask) iTask->release(this);
|
||||||
|
if (iBook) {
|
||||||
|
iBook->disconnect(this);
|
||||||
|
iBook->release();
|
||||||
|
iBook = NULL;
|
||||||
|
}
|
||||||
delete iData;
|
delete iData;
|
||||||
delete iData2;
|
delete iData2;
|
||||||
HDEBUG("destroyed");
|
HDEBUG("destroyed");
|
||||||
|
@ -233,11 +238,15 @@ void BooksBookModel::setBook(BooksBook* aBook)
|
||||||
shared_ptr<Book> newBook;
|
shared_ptr<Book> newBook;
|
||||||
if (iBook != aBook) {
|
if (iBook != aBook) {
|
||||||
const QString oldTitle(iTitle);
|
const QString oldTitle(iTitle);
|
||||||
if (iBook) iBook->release();
|
if (iBook) {
|
||||||
|
iBook->disconnect(this);
|
||||||
|
iBook->release();
|
||||||
|
}
|
||||||
if (aBook) {
|
if (aBook) {
|
||||||
(iBook = aBook)->retain();
|
(iBook = aBook)->retain();
|
||||||
iBookRef = newBook;
|
iBookRef = newBook;
|
||||||
iTitle = iBook->title();
|
iTitle = iBook->title();
|
||||||
|
connect(iBook, SIGNAL(fontSizeAdjustChanged()), SLOT(onTextStyleChanged()));
|
||||||
HDEBUG(iTitle);
|
HDEBUG(iTitle);
|
||||||
} else {
|
} else {
|
||||||
iBook = NULL;
|
iBook = NULL;
|
||||||
|
@ -245,10 +254,12 @@ void BooksBookModel::setBook(BooksBook* aBook)
|
||||||
iTitle = QString();
|
iTitle = QString();
|
||||||
HDEBUG("<none>");
|
HDEBUG("<none>");
|
||||||
}
|
}
|
||||||
|
updateTextStyle();
|
||||||
startReset(ReasonLoading, true);
|
startReset(ReasonLoading, true);
|
||||||
if (oldTitle != iTitle) {
|
if (oldTitle != iTitle) {
|
||||||
Q_EMIT titleChanged();
|
Q_EMIT titleChanged();
|
||||||
}
|
}
|
||||||
|
Q_EMIT textStyleChanged();
|
||||||
Q_EMIT bookModelChanged();
|
Q_EMIT bookModelChanged();
|
||||||
Q_EMIT bookChanged();
|
Q_EMIT bookChanged();
|
||||||
}
|
}
|
||||||
|
@ -266,18 +277,37 @@ void BooksBookModel::setSettings(BooksSettings* aSettings)
|
||||||
if (iSettings) iSettings->disconnect(this);
|
if (iSettings) iSettings->disconnect(this);
|
||||||
iSettings = aSettings;
|
iSettings = aSettings;
|
||||||
if (iSettings) {
|
if (iSettings) {
|
||||||
iTextStyle = iSettings->textStyle();
|
|
||||||
connect(iSettings, SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged()));
|
connect(iSettings, SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged()));
|
||||||
} else {
|
|
||||||
iTextStyle = BooksTextStyle::defaults();
|
|
||||||
}
|
}
|
||||||
if (!BooksTextStyle::equalLayout(oldTextStyle, iTextStyle)) {
|
if (updateTextStyle()) {
|
||||||
startReset();
|
startReset();
|
||||||
}
|
}
|
||||||
|
Q_EMIT textStyleChanged();
|
||||||
Q_EMIT settingsChanged();
|
Q_EMIT settingsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BooksBookModel::updateTextStyle()
|
||||||
|
{
|
||||||
|
shared_ptr<ZLTextStyle> oldTextStyle(iTextStyle);
|
||||||
|
if (iSettings) {
|
||||||
|
iTextStyle = iSettings->textStyle(fontSizeAdjust());
|
||||||
|
} else {
|
||||||
|
iTextStyle = BooksTextStyle::defaults();
|
||||||
|
}
|
||||||
|
return !BooksTextStyle::equalLayout(oldTextStyle, iTextStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BooksBookModel::increaseFontSize()
|
||||||
|
{
|
||||||
|
return iBook && iBook->setFontSizeAdjust(iBook->fontSizeAdjust()+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BooksBookModel::decreaseFontSize()
|
||||||
|
{
|
||||||
|
return iBook && iBook->setFontSizeAdjust(iBook->fontSizeAdjust()-1);
|
||||||
|
}
|
||||||
|
|
||||||
void BooksBookModel::setCurrentPage(int aPage)
|
void BooksBookModel::setCurrentPage(int aPage)
|
||||||
{
|
{
|
||||||
if (iCurrentPage != aPage) {
|
if (iCurrentPage != aPage) {
|
||||||
|
@ -304,6 +334,11 @@ BooksPos::List BooksBookModel::pageMarks() const
|
||||||
return iData ? iData->iPageMarks : BooksPos::List();
|
return iData ? iData->iPageMarks : BooksPos::List();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BooksBookModel::fontSizeAdjust() const
|
||||||
|
{
|
||||||
|
return iBook ? iBook->fontSizeAdjust() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
BooksPos BooksBookModel::pageMark(int aPage) const
|
BooksPos BooksBookModel::pageMark(int aPage) const
|
||||||
{
|
{
|
||||||
if (aPage >= 0 && iData) {
|
if (aPage >= 0 && iData) {
|
||||||
|
@ -445,7 +480,7 @@ void BooksBookModel::setSize(QSize aSize)
|
||||||
void BooksBookModel::onTextStyleChanged()
|
void BooksBookModel::onTextStyleChanged()
|
||||||
{
|
{
|
||||||
HDEBUG(iTitle);
|
HDEBUG(iTitle);
|
||||||
shared_ptr<ZLTextStyle> newStyle = iSettings->textStyle();
|
shared_ptr<ZLTextStyle> newStyle = iSettings->textStyle(fontSizeAdjust());
|
||||||
const int newFontSize = newStyle->fontSize();
|
const int newFontSize = newStyle->fontSize();
|
||||||
const int oldFontSize = iTextStyle->fontSize();
|
const int oldFontSize = iTextStyle->fontSize();
|
||||||
const ResetReason reason =
|
const ResetReason reason =
|
||||||
|
@ -454,6 +489,7 @@ void BooksBookModel::onTextStyleChanged()
|
||||||
ReasonUnknown;
|
ReasonUnknown;
|
||||||
iTextStyle = newStyle;
|
iTextStyle = newStyle;
|
||||||
startReset(reason);
|
startReset(reason);
|
||||||
|
Q_EMIT textStyleChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BooksBookModel::startReset(ResetReason aResetReason, bool aFullReset)
|
void BooksBookModel::startReset(ResetReason aResetReason, bool aFullReset)
|
||||||
|
|
|
@ -81,6 +81,9 @@ public:
|
||||||
ReasonDecreasingFontSize
|
ReasonDecreasingFontSize
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_INVOKABLE bool increaseFontSize();
|
||||||
|
Q_INVOKABLE bool decreaseFontSize();
|
||||||
|
|
||||||
explicit BooksBookModel(QObject* aParent = NULL);
|
explicit BooksBookModel(QObject* aParent = NULL);
|
||||||
~BooksBookModel();
|
~BooksBookModel();
|
||||||
|
|
||||||
|
@ -122,6 +125,7 @@ public:
|
||||||
shared_ptr<ZLTextModel> bookTextModel() const;
|
shared_ptr<ZLTextModel> bookTextModel() const;
|
||||||
shared_ptr<ZLTextModel> contentsModel() const;
|
shared_ptr<ZLTextModel> contentsModel() const;
|
||||||
shared_ptr<ZLTextStyle> textStyle() const { return iTextStyle; }
|
shared_ptr<ZLTextStyle> textStyle() const { return iTextStyle; }
|
||||||
|
int fontSizeAdjust() const;
|
||||||
|
|
||||||
// QAbstractListModel
|
// QAbstractListModel
|
||||||
virtual QHash<int,QByteArray> roleNames() const;
|
virtual QHash<int,QByteArray> roleNames() const;
|
||||||
|
@ -132,6 +136,7 @@ private:
|
||||||
void updateSize();
|
void updateSize();
|
||||||
void updateModel(int aPrevPageCount);
|
void updateModel(int aPrevPageCount);
|
||||||
void startReset(ResetReason aReason = ReasonUnknown, bool aFull = true);
|
void startReset(ResetReason aReason = ReasonUnknown, bool aFull = true);
|
||||||
|
bool updateTextStyle();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onResetProgress(int aProgress);
|
void onResetProgress(int aProgress);
|
||||||
|
@ -154,6 +159,7 @@ Q_SIGNALS:
|
||||||
void topMarginChanged();
|
void topMarginChanged();
|
||||||
void bottomMarginChanged();
|
void bottomMarginChanged();
|
||||||
void resetReasonChanged();
|
void resetReasonChanged();
|
||||||
|
bool textStyleChanged();
|
||||||
void jumpToPage(int index);
|
void jumpToPage(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -187,10 +187,7 @@ BooksPageWidget::~BooksPageWidget()
|
||||||
void BooksPageWidget::setModel(BooksBookModel* aModel)
|
void BooksPageWidget::setModel(BooksBookModel* aModel)
|
||||||
{
|
{
|
||||||
if (iModel != aModel) {
|
if (iModel != aModel) {
|
||||||
if (iModel) {
|
if (iModel) iModel->disconnect(this);
|
||||||
iModel->disconnect(this);
|
|
||||||
iModel = NULL;
|
|
||||||
}
|
|
||||||
iModel = aModel;
|
iModel = aModel;
|
||||||
if (iModel) {
|
if (iModel) {
|
||||||
#if HARBOUR_DEBUG
|
#if HARBOUR_DEBUG
|
||||||
|
@ -200,6 +197,7 @@ void BooksPageWidget::setModel(BooksBookModel* aModel)
|
||||||
HDEBUG(iModel->title());
|
HDEBUG(iModel->title());
|
||||||
}
|
}
|
||||||
#endif // HARBOUR_DEBUG
|
#endif // HARBOUR_DEBUG
|
||||||
|
iTextStyle = iModel->textStyle();
|
||||||
iPageMark = iModel->pageMark(iPage);
|
iPageMark = iModel->pageMark(iPage);
|
||||||
connect(iModel, SIGNAL(bookModelChanged()),
|
connect(iModel, SIGNAL(bookModelChanged()),
|
||||||
SLOT(onBookModelChanged()));
|
SLOT(onBookModelChanged()));
|
||||||
|
@ -209,8 +207,11 @@ void BooksPageWidget::setModel(BooksBookModel* aModel)
|
||||||
SLOT(onBookModelPageMarksChanged()));
|
SLOT(onBookModelPageMarksChanged()));
|
||||||
connect(iModel, SIGNAL(loadingChanged()),
|
connect(iModel, SIGNAL(loadingChanged()),
|
||||||
SLOT(onBookModelLoadingChanged()));
|
SLOT(onBookModelLoadingChanged()));
|
||||||
|
connect(iModel, SIGNAL(textStyleChanged()),
|
||||||
|
SLOT(onTextStyleChanged()));
|
||||||
} else {
|
} else {
|
||||||
iPageMark.invalidate();
|
iPageMark.invalidate();
|
||||||
|
iTextStyle = BooksTextStyle::defaults();
|
||||||
}
|
}
|
||||||
resetView();
|
resetView();
|
||||||
Q_EMIT modelChanged();
|
Q_EMIT modelChanged();
|
||||||
|
@ -225,10 +226,6 @@ void BooksPageWidget::setSettings(BooksSettings* aSettings)
|
||||||
if (iSettings) iSettings->disconnect(this);
|
if (iSettings) iSettings->disconnect(this);
|
||||||
iSettings = aSettings;
|
iSettings = aSettings;
|
||||||
if (iSettings) {
|
if (iSettings) {
|
||||||
iTextStyle = iSettings->textStyle();
|
|
||||||
connect(iSettings,
|
|
||||||
SIGNAL(textStyleChanged()),
|
|
||||||
SLOT(onTextStyleChanged()));
|
|
||||||
connect(iSettings,
|
connect(iSettings,
|
||||||
SIGNAL(invertColorsChanged()),
|
SIGNAL(invertColorsChanged()),
|
||||||
SLOT(onInvertColorsChanged()));
|
SLOT(onInvertColorsChanged()));
|
||||||
|
@ -258,8 +255,8 @@ void BooksPageWidget::setSettings(BooksSettings* aSettings)
|
||||||
void BooksPageWidget::onTextStyleChanged()
|
void BooksPageWidget::onTextStyleChanged()
|
||||||
{
|
{
|
||||||
HDEBUG(iPage);
|
HDEBUG(iPage);
|
||||||
HASSERT(sender() == iSettings);
|
HASSERT(sender() == iModel);
|
||||||
iTextStyle = iSettings->textStyle();
|
iTextStyle = iModel->textStyle();
|
||||||
resetView();
|
resetView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,6 @@ public:
|
||||||
void setBottomMargin(int aMargin);
|
void setBottomMargin(int aMargin);
|
||||||
|
|
||||||
BooksMargins margins() const { return iMargins; }
|
BooksMargins margins() const { return iMargins; }
|
||||||
shared_ptr<ZLTextStyle> textStyle() const { return iTextStyle; }
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void loadingChanged();
|
void loadingChanged();
|
||||||
|
|
|
@ -199,29 +199,28 @@ BooksSettings::TextStyle::allowHyphenations() const
|
||||||
|
|
||||||
BooksSettings::BooksSettings(QObject* aParent) :
|
BooksSettings::BooksSettings(QObject* aParent) :
|
||||||
QObject(aParent),
|
QObject(aParent),
|
||||||
iFontSize(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
|
iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
|
||||||
iPageDetails(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)),
|
iPageDetailsConf(new MGConfItem(DCONF_PATH KEY_PAGE_DETAILS, this)),
|
||||||
iInvertColors(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
|
iInvertColorsConf(new MGConfItem(DCONF_PATH KEY_INVERT_COLORS, this)),
|
||||||
iCurrentFolder(new MGConfItem(DCONF_PATH KEY_CURRENT_FOLDER, this)),
|
iCurrentFolderConf(new MGConfItem(DCONF_PATH KEY_CURRENT_FOLDER, this)),
|
||||||
iCurrentBookPath(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
|
iCurrentBookPathConf(new MGConfItem(DCONF_PATH KEY_CURRENT_BOOK, this)),
|
||||||
iCurrentBook(NULL)
|
iCurrentBook(NULL),
|
||||||
|
iFontSize(currentFontSize())
|
||||||
{
|
{
|
||||||
iTextStyle = new TextStyle(fontSize());
|
|
||||||
updateCurrentBook();
|
updateCurrentBook();
|
||||||
updateCurrentStorage();
|
updateCurrentStorage();
|
||||||
connect(iFontSize, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged()));
|
connect(iFontSizeConf, SIGNAL(valueChanged()), SLOT(onFontSizeValueChanged()));
|
||||||
connect(iPageDetails, SIGNAL(valueChanged()), SIGNAL(pageDetailsChanged()));
|
connect(iPageDetailsConf, SIGNAL(valueChanged()), SIGNAL(pageDetailsChanged()));
|
||||||
connect(iInvertColors, SIGNAL(valueChanged()), SIGNAL(invertColorsChanged()));
|
connect(iInvertColorsConf, SIGNAL(valueChanged()), SIGNAL(invertColorsChanged()));
|
||||||
connect(iCurrentFolder, SIGNAL(valueChanged()), SLOT(onCurrentFolderChanged()));
|
connect(iCurrentFolderConf, SIGNAL(valueChanged()), SLOT(onCurrentFolderChanged()));
|
||||||
connect(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
|
connect(iCurrentBookPathConf, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BooksSettings::increaseFontSize()
|
BooksSettings::increaseFontSize()
|
||||||
{
|
{
|
||||||
int size = fontSize();
|
if (iFontSize < MaxFontSize) {
|
||||||
if (size < MaxFontSize) {
|
setFontSize(iFontSize+1);
|
||||||
setFontSize(size+1);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -231,9 +230,8 @@ BooksSettings::increaseFontSize()
|
||||||
bool
|
bool
|
||||||
BooksSettings::decreaseFontSize()
|
BooksSettings::decreaseFontSize()
|
||||||
{
|
{
|
||||||
int size = fontSize();
|
if (iFontSize > MinFontSize) {
|
||||||
if (size > MinFontSize) {
|
setFontSize(iFontSize-1);
|
||||||
setFontSize(size-1);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -241,9 +239,30 @@ BooksSettings::decreaseFontSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BooksSettings::fontSize() const
|
BooksSettings::currentFontSize() const
|
||||||
{
|
{
|
||||||
return iFontSize->value(DEFAULT_FONT_SIZE).toInt();
|
const int fontSize = iFontSizeConf->value(DEFAULT_FONT_SIZE).toInt();
|
||||||
|
if (fontSize < MinFontSize) {
|
||||||
|
return MinFontSize;
|
||||||
|
} else if (fontSize > MaxFontSize) {
|
||||||
|
return MaxFontSize;
|
||||||
|
} else {
|
||||||
|
return fontSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
BooksSettings::fontSize(
|
||||||
|
int aFontSizeAdjust) const
|
||||||
|
{
|
||||||
|
const int fontSize = iFontSize + aFontSizeAdjust;
|
||||||
|
if (fontSize < MinFontSize) {
|
||||||
|
return MinFontSize;
|
||||||
|
} else if (fontSize > MaxFontSize) {
|
||||||
|
return MaxFontSize;
|
||||||
|
} else {
|
||||||
|
return fontSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -251,23 +270,42 @@ BooksSettings::setFontSize(
|
||||||
int aValue)
|
int aValue)
|
||||||
{
|
{
|
||||||
HDEBUG(aValue);
|
HDEBUG(aValue);
|
||||||
iFontSize->set(aValue);
|
iFontSizeConf->set(aValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BooksSettings::onFontSizeValueChanged()
|
BooksSettings::onFontSizeValueChanged()
|
||||||
{
|
{
|
||||||
const int newSize = fontSize();
|
const int newSize = currentFontSize();
|
||||||
HDEBUG(newSize);
|
HDEBUG(newSize);
|
||||||
iTextStyle = new TextStyle(newSize);
|
if (iFontSize != newSize) {
|
||||||
Q_EMIT fontSizeChanged();
|
iFontSize = newSize;
|
||||||
Q_EMIT textStyleChanged();
|
for (int i=0; i<=FontSizeSteps; i++) {
|
||||||
|
iTextStyle[i].reset();
|
||||||
|
}
|
||||||
|
Q_EMIT fontSizeChanged();
|
||||||
|
Q_EMIT textStyleChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<ZLTextStyle>
|
||||||
|
BooksSettings::textStyle(
|
||||||
|
int aFontSizeAdjust) const
|
||||||
|
{
|
||||||
|
const int size = fontSize(aFontSizeAdjust);
|
||||||
|
const int i = size - MinFontSize;
|
||||||
|
shared_ptr<ZLTextStyle> style = iTextStyle[i];
|
||||||
|
if (style.isNull()) {
|
||||||
|
style = new TextStyle(size);
|
||||||
|
iTextStyle[i] = style;
|
||||||
|
}
|
||||||
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BooksSettings::pageDetails() const
|
BooksSettings::pageDetails() const
|
||||||
{
|
{
|
||||||
return iPageDetails->value(DEFAULT_PAGE_DETAILS).toInt();
|
return iPageDetailsConf->value(DEFAULT_PAGE_DETAILS).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -275,13 +313,13 @@ BooksSettings::setPageDetails(
|
||||||
int aValue)
|
int aValue)
|
||||||
{
|
{
|
||||||
HDEBUG(aValue);
|
HDEBUG(aValue);
|
||||||
iPageDetails->set(aValue);
|
iPageDetailsConf->set(aValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BooksSettings::invertColors() const
|
BooksSettings::invertColors() const
|
||||||
{
|
{
|
||||||
return iInvertColors->value(DEFAULT_INVERT_COLORS).toBool();
|
return iInvertColorsConf->value(DEFAULT_INVERT_COLORS).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -289,13 +327,13 @@ BooksSettings::setInvertColors(
|
||||||
bool aValue)
|
bool aValue)
|
||||||
{
|
{
|
||||||
HDEBUG(aValue);
|
HDEBUG(aValue);
|
||||||
iInvertColors->set(aValue);
|
iInvertColorsConf->set(aValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
BooksSettings::currentFolder() const
|
BooksSettings::currentFolder() const
|
||||||
{
|
{
|
||||||
return iCurrentFolder->value(DEFAULT_CURRENT_FOLDER).toString();
|
return iCurrentFolderConf->value(DEFAULT_CURRENT_FOLDER).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -303,7 +341,7 @@ BooksSettings::setCurrentFolder(
|
||||||
QString aValue)
|
QString aValue)
|
||||||
{
|
{
|
||||||
HDEBUG(aValue);
|
HDEBUG(aValue);
|
||||||
iCurrentFolder->set(aValue);
|
iCurrentFolderConf->set(aValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -334,7 +372,8 @@ BooksSettings::currentBook() const
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BooksSettings::setCurrentBook(QObject* aBook)
|
BooksSettings::setCurrentBook(
|
||||||
|
QObject* aBook)
|
||||||
{
|
{
|
||||||
BooksBook* book = qobject_cast<BooksBook*>(aBook);
|
BooksBook* book = qobject_cast<BooksBook*>(aBook);
|
||||||
if (iCurrentBook != book) {
|
if (iCurrentBook != book) {
|
||||||
|
@ -342,10 +381,10 @@ BooksSettings::setCurrentBook(QObject* aBook)
|
||||||
if (book) {
|
if (book) {
|
||||||
HDEBUG(book->path());
|
HDEBUG(book->path());
|
||||||
(iCurrentBook = book)->retain();
|
(iCurrentBook = book)->retain();
|
||||||
iCurrentBookPath->set(book->path());
|
iCurrentBookPathConf->set(book->path());
|
||||||
} else {
|
} else {
|
||||||
iCurrentBook = NULL;
|
iCurrentBook = NULL;
|
||||||
iCurrentBookPath->set(QString());
|
iCurrentBookPathConf->set(QString());
|
||||||
}
|
}
|
||||||
Q_EMIT currentBookChanged();
|
Q_EMIT currentBookChanged();
|
||||||
}
|
}
|
||||||
|
@ -354,7 +393,7 @@ BooksSettings::setCurrentBook(QObject* aBook)
|
||||||
bool
|
bool
|
||||||
BooksSettings::updateCurrentBook()
|
BooksSettings::updateCurrentBook()
|
||||||
{
|
{
|
||||||
QString path = iCurrentBookPath->value(DEFAULT_CURRENT_BOOK).toString();
|
QString path = iCurrentBookPathConf->value(DEFAULT_CURRENT_BOOK).toString();
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
if (iCurrentBook) {
|
if (iCurrentBook) {
|
||||||
iCurrentBook->release();
|
iCurrentBook->release();
|
||||||
|
|
|
@ -59,7 +59,8 @@ public:
|
||||||
enum FontSize {
|
enum FontSize {
|
||||||
MinFontSize = -5,
|
MinFontSize = -5,
|
||||||
DefaultFontSize = 0,
|
DefaultFontSize = 0,
|
||||||
MaxFontSize = 10
|
MaxFontSize = 10,
|
||||||
|
FontSizeSteps = MaxFontSize - MinFontSize
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit BooksSettings(QObject* aParent = NULL);
|
explicit BooksSettings(QObject* aParent = NULL);
|
||||||
|
@ -67,13 +68,13 @@ public:
|
||||||
Q_INVOKABLE bool increaseFontSize();
|
Q_INVOKABLE bool increaseFontSize();
|
||||||
Q_INVOKABLE bool decreaseFontSize();
|
Q_INVOKABLE bool decreaseFontSize();
|
||||||
|
|
||||||
int fontSize() const;
|
int fontSize() const { return iFontSize; }
|
||||||
void setFontSize(int aValue);
|
void setFontSize(int aValue);
|
||||||
|
|
||||||
int pageDetails() const;
|
int pageDetails() const;
|
||||||
void setPageDetails(int aValue);
|
void setPageDetails(int aValue);
|
||||||
|
|
||||||
shared_ptr<ZLTextStyle> textStyle() const { return iTextStyle; }
|
shared_ptr<ZLTextStyle> textStyle(int aFontSizeAdjust) const;
|
||||||
|
|
||||||
bool invertColors() const;
|
bool invertColors() const;
|
||||||
void setInvertColors(bool aValue);
|
void setInvertColors(bool aValue);
|
||||||
|
@ -88,7 +89,7 @@ public:
|
||||||
QColor primaryPageToolColor() const;
|
QColor primaryPageToolColor() const;
|
||||||
QColor highlightPageToolColor() const;
|
QColor highlightPageToolColor() const;
|
||||||
|
|
||||||
signals:
|
Q_SIGNALS:
|
||||||
void fontSizeChanged();
|
void fontSizeChanged();
|
||||||
void textStyleChanged();
|
void textStyleChanged();
|
||||||
void pageDetailsChanged();
|
void pageDetailsChanged();
|
||||||
|
@ -106,16 +107,19 @@ private:
|
||||||
void updateRenderType();
|
void updateRenderType();
|
||||||
bool updateCurrentBook();
|
bool updateCurrentBook();
|
||||||
bool updateCurrentStorage();
|
bool updateCurrentStorage();
|
||||||
|
int currentFontSize() const;
|
||||||
|
int fontSize(int aFontSizeAdjust) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MGConfItem* iFontSize;
|
MGConfItem* iFontSizeConf;
|
||||||
MGConfItem* iPageDetails;
|
MGConfItem* iPageDetailsConf;
|
||||||
MGConfItem* iInvertColors;
|
MGConfItem* iInvertColorsConf;
|
||||||
MGConfItem* iCurrentFolder;
|
MGConfItem* iCurrentFolderConf;
|
||||||
MGConfItem* iCurrentBookPath;
|
MGConfItem* iCurrentBookPathConf;
|
||||||
shared_ptr<ZLTextStyle> iTextStyle;
|
mutable shared_ptr<ZLTextStyle> iTextStyle[FontSizeSteps+1];
|
||||||
BooksBook* iCurrentBook;
|
BooksBook* iCurrentBook;
|
||||||
QString iCurrentStorageDevice;
|
QString iCurrentStorageDevice;
|
||||||
|
int iFontSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
QML_DECLARE_TYPE(BooksSettings)
|
QML_DECLARE_TYPE(BooksSettings)
|
||||||
|
|
Loading…
Reference in a new issue