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