[app] Use shared instance of BooksSettings

This commit is contained in:
Slava Monich 2016-10-16 23:36:13 +03:00
parent 55b47f18f2
commit caf858b581
15 changed files with 97 additions and 136 deletions

View file

@ -44,7 +44,7 @@ SilicaFlickable {
property int _currentPage: bookListWatcher.currentIndex property int _currentPage: bookListWatcher.currentIndex
property bool _loading: minLoadingDelay.running || bookModel.loading property bool _loading: minLoadingDelay.running || bookModel.loading
property var _currentState: _visibilityStates[globalSettings.pageDetails % _visibilityStates.length] property var _currentState: _visibilityStates[Settings.pageDetails % _visibilityStates.length]
readonly property var _visibilityStates: [ readonly property var _visibilityStates: [
{ pager: false, page: false, title: false, tools: false }, { pager: false, page: false, title: false, tools: false },
{ pager: false, page: true, title: true, tools: false }, { pager: false, page: true, title: true, tools: false },
@ -77,7 +77,7 @@ SilicaFlickable {
Component { Component {
id: imageViewComponent id: imageViewComponent
BooksImageView { BooksImageView {
imageBackground: globalSettings.pageBackgroundColor imageBackground: Settings.pageBackgroundColor
} }
} }
@ -114,7 +114,6 @@ SilicaFlickable {
rightMargin: Theme.horizontalPageMargin rightMargin: Theme.horizontalPageMargin
topMargin: Theme.itemSizeSmall topMargin: Theme.itemSizeSmall
bottomMargin: Theme.itemSizeSmall bottomMargin: Theme.itemSizeSmall
settings: globalSettings
onJumpToPage: bookView.jumpTo(index) onJumpToPage: bookView.jumpTo(index)
onCurrentPageChanged: { onCurrentPageChanged: {
if (linkMenu) linkMenu.hide() if (linkMenu) linkMenu.hide()
@ -163,7 +162,7 @@ SilicaFlickable {
onJumpToPage: bookView.jumpTo(page) onJumpToPage: bookView.jumpTo(page)
onPageClicked: { onPageClicked: {
root.pageClicked(index) root.pageClicked(index)
globalSettings.pageDetails = (globalSettings.pageDetails+ 1) % _visibilityStates.length Settings.pageDetails = (Settings.pageDetails+ 1) % _visibilityStates.length
} }
onImagePressed: { onImagePressed: {
if (_currentPage == index) { if (_currentPage == index) {

View file

@ -7,14 +7,15 @@
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Jolla Ltd nor the * Neither the name of Jolla Ltd nor the names of its contributors may
names of its contributors may be used to endorse or promote products be used to endorse or promote products derived from this software
derived from this software without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -36,7 +37,7 @@ import harbour.books 1.0
ApplicationWindow { ApplicationWindow {
id: window id: window
allowedOrientations: { allowedOrientations: {
switch (globalSettings.orientation) { switch (Settings.orientation) {
default: default:
case BooksSettings.OrientationAny: return Orientation.All case BooksSettings.OrientationAny: return Orientation.All
case BooksSettings.OrientationPortrait: return Orientation.Portrait case BooksSettings.OrientationPortrait: return Orientation.Portrait
@ -50,7 +51,6 @@ ApplicationWindow {
property variant currentShelf: mainPage.currentShelf property variant currentShelf: mainPage.currentShelf
BooksSettings { id: globalSettings }
BooksHints { id: globalHints } BooksHints { id: globalHints }
SystemState { id: globalSystemState } SystemState { id: globalSystemState }
@ -58,7 +58,7 @@ ApplicationWindow {
cover: Component { cover: Component {
BooksCoverPage { BooksCoverPage {
book: globalSettings.currentBook book: Settings.currentBook
shelf: currentShelf shelf: currentShelf
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2015 Jolla Ltd. Copyright (C) 2015-2016 Jolla Ltd.
Contact: Slava Monich <slava.monich@jolla.com> Contact: Slava Monich <slava.monich@jolla.com>
You may use this file under the terms of BSD license as follows: You may use this file under the terms of BSD license as follows:
@ -7,14 +7,15 @@
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Jolla Ltd nor the * Neither the name of Jolla Ltd nor the names of its contributors may
names of its contributors may be used to endorse or promote products be used to endorse or promote products derived from this software
derived from this software without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -44,13 +45,13 @@ Page {
property Item _bookView property Item _bookView
function createBookViewIfNeeded() { function createBookViewIfNeeded() {
if (globalSettings.currentBook && !_bookView) { if (Settings.currentBook && !_bookView) {
_bookView = bookViewComponent.createObject(root) _bookView = bookViewComponent.createObject(root)
} }
} }
Connections { Connections {
target: globalSettings target: Settings
onCurrentBookChanged: createBookViewIfNeeded() onCurrentBookChanged: createBookViewIfNeeded()
} }
@ -60,8 +61,8 @@ Page {
anchors.fill: parent anchors.fill: parent
opacity: book ? 1 : 0 opacity: book ? 1 : 0
visible: opacity > 0 visible: opacity > 0
book: globalSettings.currentBook ? globalSettings.currentBook : null book: Settings.currentBook ? Settings.currentBook : null
onCloseBook: globalSettings.currentBook = null onCloseBook: Settings.currentBook = null
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
} }
@ -69,10 +70,10 @@ Page {
BooksStorageView { BooksStorageView {
id: storageView id: storageView
anchors.fill: parent anchors.fill: parent
opacity: globalSettings.currentBook ? 0 : 1 opacity: Settings.currentBook ? 0 : 1
visible: opacity > 0 visible: opacity > 0
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
onOpenBook: globalSettings.currentBook = book onOpenBook: Settings.currentBook = book
} }
Component.onCompleted: createBookViewIfNeeded() Component.onCompleted: createBookViewIfNeeded()

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2015 Jolla Ltd. Copyright (C) 2015-2016 Jolla Ltd.
Contact: Slava Monich <slava.monich@jolla.com> Contact: Slava Monich <slava.monich@jolla.com>
You may use this file under the terms of BSD license as follows: You may use this file under the terms of BSD license as follows:
@ -7,14 +7,15 @@
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Jolla Ltd nor the * Neither the name of Jolla Ltd nor the names of its contributors may
names of its contributors may be used to endorse or promote products be used to endorse or promote products derived from this software
derived from this software without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -57,7 +58,7 @@ Item {
left: parent.left left: parent.left
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
onClicked: globalSettings.invertColors = !globalSettings.invertColors onClicked: Settings.invertColors = !Settings.invertColors
Image { Image {
id: dayModeImage id: dayModeImage
@ -69,7 +70,7 @@ Item {
} }
height: Math.ceil(parent.height/2) height: Math.ceil(parent.height/2)
sourceSize.height: height sourceSize.height: height
opacity: globalSettings.invertColors ? 0.5 : 0 opacity: Settings.invertColors ? 0.5 : 0
visible: opacity > 0 visible: opacity > 0
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
@ -78,7 +79,7 @@ Item {
source: "images/night-mode.svg" source: "images/night-mode.svg"
anchors.fill: dayModeImage anchors.fill: dayModeImage
sourceSize.height: height sourceSize.height: height
opacity: globalSettings.invertColors ? 0 : 0.25 opacity: Settings.invertColors ? 0 : 0.25
visible: opacity > 0 visible: opacity > 0
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
@ -104,7 +105,7 @@ Item {
} }
height: Math.ceil(parent.height/2) height: Math.ceil(parent.height/2)
sourceSize.height: height sourceSize.height: height
opacity: globalSettings.invertColors ? 1 : 0.5 opacity: Settings.invertColors ? 1 : 0.5
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
onClicked: pageTools.increaseFontSize() onClicked: pageTools.increaseFontSize()
@ -128,7 +129,7 @@ Item {
} }
height: Math.ceil(parent.height/2) height: Math.ceil(parent.height/2)
sourceSize.height: height sourceSize.height: height
opacity: globalSettings.invertColors ? 1 : 0.5 opacity: Settings.invertColors ? 1 : 0.5
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }
} }
onClicked: pageTools.decreaseFontSize() onClicked: pageTools.decreaseFontSize()

View file

@ -57,7 +57,6 @@ Item {
PageWidget { PageWidget {
id: widget id: widget
anchors.fill: parent anchors.fill: parent
settings: globalSettings
model: bookModel model: bookModel
onBrowserLinkPressed: view.browserLinkPressed(url) onBrowserLinkPressed: view.browserLinkPressed(url)
onImagePressed: view.imagePressed(url, rect) onImagePressed: view.imagePressed(url, rect)
@ -76,7 +75,7 @@ Item {
} }
centerX: Math.floor(view.width/2) - anchors.leftMargin centerX: Math.floor(view.width/2) - anchors.leftMargin
height: Theme.itemSizeExtraSmall height: Theme.itemSizeExtraSmall
color: globalSettings.primaryPageToolColor color: Settings.primaryPageToolColor
opacity: titleVisible ? 1 : 0 opacity: titleVisible ? 1 : 0
} }
@ -91,7 +90,7 @@ Item {
Image { Image {
id: pressImage id: pressImage
source: globalSettings.invertColors ? "images/press-invert.svg" : "images/press.svg" source: Settings.invertColors ? "images/press-invert.svg" : "images/press.svg"
visible: opacity > 0 visible: opacity > 0
opacity: 0 opacity: 0
readonly property int maxsize: Math.max(view.width, view.height) readonly property int maxsize: Math.max(view.width, view.height)
@ -146,7 +145,7 @@ Item {
height: Theme.itemSizeExtraSmall height: Theme.itemSizeExtraSmall
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
color: globalSettings.primaryPageToolColor color: Settings.primaryPageToolColor
opacity: pageNumberVisible ? 1 : 0 opacity: pageNumberVisible ? 1 : 0
visible: opacity > 0 visible: opacity > 0
Behavior on opacity { FadeAnimation {} } Behavior on opacity { FadeAnimation {} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2015 Jolla Ltd. Copyright (C) 2015-2016 Jolla Ltd.
Contact: Slava Monich <slava.monich@jolla.com> Contact: Slava Monich <slava.monich@jolla.com>
You may use this file under the terms of BSD license as follows: You may use this file under the terms of BSD license as follows:
@ -7,14 +7,15 @@
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Jolla Ltd nor the * Neither the name of Jolla Ltd nor the names of its contributors may
names of its contributors may be used to endorse or promote products be used to endorse or promote products derived from this software
derived from this software without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -56,10 +57,10 @@ Item {
minimumValue: 0 minimumValue: 0
valueText: "" valueText: ""
label: "" label: ""
primaryColor: globalSettings.primaryPageToolColor primaryColor: Settings.primaryPageToolColor
secondaryColor: globalSettings.primaryPageToolColor secondaryColor: Settings.primaryPageToolColor
highlightColor: globalSettings.highlightPageToolColor highlightColor: Settings.highlightPageToolColor
secondaryHighlightColor: globalSettings.highlightPageToolColor secondaryHighlightColor: Settings.highlightPageToolColor
onValueChanged: root.pageChanged(value) onValueChanged: root.pageChanged(value)
} }
} }

View file

@ -74,13 +74,13 @@ Item {
editMode: shelfView.editMode editMode: shelfView.editMode
onRelativePathChanged: longStartTimer.restart() onRelativePathChanged: longStartTimer.restart()
onPathChanged: { onPathChanged: {
if (globalSettings.currentStorage === device && _completed) { if (Settings.currentStorage === device && _completed) {
globalSettings.currentFolder = path Settings.currentFolder = path
} }
} }
onDeviceChanged: { onDeviceChanged: {
if (device === globalSettings.currentStorage) { if (device === Settings.currentStorage) {
relativePath = globalSettings.relativePath relativePath = Settings.relativePath
} }
} }
Component.onCompleted: _completed = true Component.onCompleted: _completed = true

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2015 Jolla Ltd. Copyright (C) 2015-2016 Jolla Ltd.
Contact: Slava Monich <slava.monich@jolla.com> Contact: Slava Monich <slava.monich@jolla.com>
You may use this file under the terms of BSD license as follows: You may use this file under the terms of BSD license as follows:
@ -7,14 +7,15 @@
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Jolla Ltd nor the * Neither the name of Jolla Ltd nor the names of its contributors may
names of its contributors may be used to endorse or promote products be used to endorse or promote products derived from this software
derived from this software without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@ -85,7 +86,7 @@ SilicaFlickable {
onCurrentShelfChanged: { onCurrentShelfChanged: {
if (storageList.completed && currentShelf) { if (storageList.completed && currentShelf) {
globalSettings.currentFolder = currentShelf.path Settings.currentFolder = currentShelf.path
} }
} }
@ -187,14 +188,14 @@ SilicaFlickable {
} }
Component.onCompleted: { Component.onCompleted: {
var index = model.deviceIndex(globalSettings.currentStorage) var index = model.deviceIndex(Settings.currentStorage)
// positionViewAtIndex doesn't work here, update contentX directly // positionViewAtIndex doesn't work here, update contentX directly
if (index >= 0) { if (index >= 0) {
contentX = (width + spacing) * index contentX = (width + spacing) * index
} else { } else {
// Most likely, removable storage is gone // Most likely, removable storage is gone
console.log(globalSettings.currentFolder, "is gone") console.log(Settings.currentFolder, "is gone")
globalSettings.currentFolder = currentShelf ? currentShelf.path : "" Settings.currentFolder = currentShelf ? currentShelf.path : ""
} }
completed = true completed = true
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015 Jolla Ltd. * Copyright (C) 2015-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com> * Contact: Slava Monich <slava.monich@jolla.com>
* *
* You may use this file under the terms of the BSD license as follows: * You may use this file under the terms of the BSD license as follows:
@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors * * Neither the name of Jolla Ltd nor the names of its contributors
* may be used to endorse or promote products derived from this * may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
@ -206,13 +206,14 @@ BooksBookModel::BooksBookModel(QObject* aParent) :
iCurrentPage(-1), iCurrentPage(-1),
iProgress(0), iProgress(0),
iBook(NULL), iBook(NULL),
iSettings(NULL),
iTask(NULL), iTask(NULL),
iData(NULL), iData(NULL),
iData2(NULL), iData2(NULL),
iTaskQueue(BooksTaskQueue::defaultQueue()), iSettings(BooksSettings::sharedInstance()),
iTextStyle(BooksTextStyle::defaults()) iTaskQueue(BooksTaskQueue::defaultQueue())
{ {
iTextStyle = iSettings->textStyle(fontSizeAdjust());
connect(iSettings.data(), SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged()));
HDEBUG("created"); HDEBUG("created");
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
setRoleNames(roleNames()); setRoleNames(roleNames());
@ -254,7 +255,6 @@ 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();
@ -270,34 +270,6 @@ bool BooksBookModel::loading() const
return (iTask != NULL); return (iTask != NULL);
} }
void BooksBookModel::setSettings(BooksSettings* aSettings)
{
if (iSettings != aSettings) {
shared_ptr<ZLTextStyle> oldTextStyle(iTextStyle);
if (iSettings) iSettings->disconnect(this);
iSettings = aSettings;
if (iSettings) {
connect(iSettings, SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged()));
}
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() bool BooksBookModel::increaseFontSize()
{ {
return iBook && iBook->setFontSizeAdjust(iBook->fontSizeAdjust()+1); return iBook && iBook->setFontSizeAdjust(iBook->fontSizeAdjust()+1);

View file

@ -69,7 +69,6 @@ class BooksBookModel: public QAbstractListModel, private BooksLoadingProperty
Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
Q_PROPERTY(BooksBook* book READ book WRITE setBook NOTIFY bookChanged) Q_PROPERTY(BooksBook* book READ book WRITE setBook NOTIFY bookChanged)
Q_PROPERTY(BooksSettings* settings READ settings WRITE setSettings NOTIFY settingsChanged)
Q_PROPERTY(ResetReason resetReason READ resetReason NOTIFY resetReasonChanged) Q_PROPERTY(ResetReason resetReason READ resetReason NOTIFY resetReasonChanged)
public: public:
@ -104,9 +103,6 @@ public:
BooksBook* book() const { return iBook; } BooksBook* book() const { return iBook; }
void setBook(BooksBook* aBook); void setBook(BooksBook* aBook);
BooksSettings* settings() const { return iSettings; }
void setSettings(BooksSettings* aModel);
int leftMargin() const { return iMargins.iLeft; } int leftMargin() const { return iMargins.iLeft; }
int rightMargin() const { return iMargins.iRight; } int rightMargin() const { return iMargins.iRight; }
int topMargin() const { return iMargins.iTop; } int topMargin() const { return iMargins.iTop; }
@ -137,7 +133,6 @@ 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,7 +149,6 @@ Q_SIGNALS:
void pageMarksChanged(); void pageMarksChanged();
void progressChanged(); void progressChanged();
void currentPageChanged(); void currentPageChanged();
void settingsChanged();
void leftMarginChanged(); void leftMarginChanged();
void rightMarginChanged(); void rightMarginChanged();
void topMarginChanged(); void topMarginChanged();
@ -175,10 +169,10 @@ private:
BooksMargins iMargins; BooksMargins iMargins;
BooksBook* iBook; BooksBook* iBook;
shared_ptr<Book> iBookRef; shared_ptr<Book> iBookRef;
BooksSettings* iSettings;
Task* iTask; Task* iTask;
Data* iData; Data* iData;
Data* iData2; Data* iData2;
QSharedPointer<BooksSettings> iSettings;
shared_ptr<BooksTaskQueue> iTaskQueue; shared_ptr<BooksTaskQueue> iTaskQueue;
shared_ptr<ZLTextStyle> iTextStyle; shared_ptr<ZLTextStyle> iTextStyle;
}; };

View file

@ -254,11 +254,11 @@ void BooksPageWidget::PressTask::performTask()
BooksPageWidget::BooksPageWidget(QQuickItem* aParent) : BooksPageWidget::BooksPageWidget(QQuickItem* aParent) :
QQuickPaintedItem(aParent), QQuickPaintedItem(aParent),
iSettings(BooksSettings::sharedInstance()),
iTaskQueue(BooksTaskQueue::defaultQueue()), iTaskQueue(BooksTaskQueue::defaultQueue()),
iTextStyle(BooksTextStyle::defaults()), iTextStyle(BooksTextStyle::defaults()),
iResizeTimer(new QTimer(this)), iResizeTimer(new QTimer(this)),
iModel(NULL), iModel(NULL),
iSettings(NULL),
iResetTask(NULL), iResetTask(NULL),
iRenderTask(NULL), iRenderTask(NULL),
iPressTask(NULL), iPressTask(NULL),
@ -266,8 +266,13 @@ BooksPageWidget::BooksPageWidget(QQuickItem* aParent) :
iEmpty(false), iEmpty(false),
iPage(-1) iPage(-1)
{ {
connect(iSettings.data(),
SIGNAL(invertColorsChanged()),
SLOT(onInvertColorsChanged()));
setFillColor(qtColor(iSettings->invertColors() ?
BooksTextView::INVERTED_BACKGROUND :
BooksTextView::DEFAULT_BACKGROUND));
setFlag(ItemHasContents, true); setFlag(ItemHasContents, true);
setFillColor(qtColor(BooksTextView::DEFAULT_BACKGROUND));
iResizeTimer->setSingleShot(true); iResizeTimer->setSingleShot(true);
iResizeTimer->setInterval(0); iResizeTimer->setInterval(0);
connect(iResizeTimer, SIGNAL(timeout()), SLOT(onResizeTimeout())); connect(iResizeTimer, SIGNAL(timeout()), SLOT(onResizeTimeout()));
@ -318,40 +323,6 @@ void BooksPageWidget::setModel(BooksBookModel* aModel)
} }
} }
void BooksPageWidget::setSettings(BooksSettings* aSettings)
{
if (iSettings != aSettings) {
const bool colorsWereInverted = invertColors();
shared_ptr<ZLTextStyle> oldTextStyle(iTextStyle);
if (iSettings) iSettings->disconnect(this);
iSettings = aSettings;
if (iSettings) {
connect(iSettings,
SIGNAL(invertColorsChanged()),
SLOT(onInvertColorsChanged()));
} else {
iTextStyle = BooksTextStyle::defaults();
}
const bool colorsAreInverted = invertColors();
if (colorsWereInverted != colorsAreInverted) {
setFillColor(qtColor(colorsAreInverted ?
BooksTextView::INVERTED_BACKGROUND :
BooksTextView::DEFAULT_BACKGROUND));
}
if (!BooksTextStyle::equalLayout(oldTextStyle, iTextStyle)) {
resetView();
} else if (colorsWereInverted != colorsAreInverted) {
if (!iData.isNull() && !iData->iView.isNull()) {
iData->iView->setInvertColors(colorsAreInverted);
scheduleRepaint();
} else {
update();
}
}
Q_EMIT settingsChanged();
}
}
void BooksPageWidget::onTextStyleChanged() void BooksPageWidget::onTextStyleChanged()
{ {
HDEBUG(iPage); HDEBUG(iPage);

View file

@ -58,7 +58,6 @@ class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty
Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
Q_PROPERTY(BooksBookModel* model READ model WRITE setModel NOTIFY modelChanged) Q_PROPERTY(BooksBookModel* model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(BooksSettings* settings READ settings WRITE setSettings NOTIFY settingsChanged)
public: public:
class Data; class Data;
@ -74,9 +73,6 @@ public:
BooksBookModel* model() const { return iModel; } BooksBookModel* model() const { return iModel; }
void setModel(BooksBookModel* aModel); void setModel(BooksBookModel* aModel);
BooksSettings* settings() const { return iSettings; }
void setSettings(BooksSettings* aSettings);
int leftMargin() const { return iMargins.iLeft; } int leftMargin() const { return iMargins.iLeft; }
int rightMargin() const { return iMargins.iRight; } int rightMargin() const { return iMargins.iRight; }
int topMargin() const { return iMargins.iTop; } int topMargin() const { return iMargins.iTop; }
@ -96,7 +92,6 @@ Q_SIGNALS:
void loadingChanged(); void loadingChanged();
void pageChanged(); void pageChanged();
void modelChanged(); void modelChanged();
void settingsChanged();
void leftMarginChanged(); void leftMarginChanged();
void rightMarginChanged(); void rightMarginChanged();
void topMarginChanged(); void topMarginChanged();
@ -134,12 +129,12 @@ private:
class RenderTask; class RenderTask;
class PressTask; class PressTask;
QSharedPointer<BooksSettings> iSettings;
shared_ptr<BooksTaskQueue> iTaskQueue; shared_ptr<BooksTaskQueue> iTaskQueue;
shared_ptr<ZLTextStyle> iTextStyle; shared_ptr<ZLTextStyle> iTextStyle;
BooksPos iPageMark; BooksPos iPageMark;
QTimer* iResizeTimer; QTimer* iResizeTimer;
BooksBookModel* iModel; BooksBookModel* iModel;
BooksSettings* iSettings;
BooksMargins iMargins; BooksMargins iMargins;
shared_ptr<Data> iData; shared_ptr<Data> iData;
shared_ptr<QImage> iImage; shared_ptr<QImage> iImage;

View file

@ -200,6 +200,13 @@ BooksSettings::TextStyle::allowHyphenations() const
// BooksSettings // BooksSettings
// ========================================================================== // ==========================================================================
class BooksSettings::Private {
public:
static QWeakPointer<BooksSettings> sSharedInstance;
};
QWeakPointer<BooksSettings> BooksSettings::Private::sSharedInstance;
BooksSettings::BooksSettings(QObject* aParent) : BooksSettings::BooksSettings(QObject* aParent) :
QObject(aParent), QObject(aParent),
iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)), iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
@ -222,6 +229,19 @@ BooksSettings::BooksSettings(QObject* aParent) :
connect(iOrientationConf, SIGNAL(valueChanged()), SIGNAL(orientationChanged())); connect(iOrientationConf, SIGNAL(valueChanged()), SIGNAL(orientationChanged()));
} }
QSharedPointer<BooksSettings>
BooksSettings::sharedInstance()
{
QSharedPointer<BooksSettings> instance = Private::sSharedInstance;
if (instance.isNull()) {
// QObject::deleteLater protects against trouble in case if the
// recipient of the signal drops the last shared reference.
instance = QSharedPointer<BooksSettings>(new BooksSettings, &QObject::deleteLater);
Private::sSharedInstance = instance;
}
return instance;
}
bool bool
BooksSettings::increaseFontSize() BooksSettings::increaseFontSize()
{ {

View file

@ -38,6 +38,7 @@
#include "ZLTextStyle.h" #include "ZLTextStyle.h"
#include <QColor> #include <QColor>
#include <QtQml> #include <QtQml>
#include <QSharedPointer>
class MGConfItem; class MGConfItem;
@ -75,6 +76,8 @@ public:
explicit BooksSettings(QObject* aParent = NULL); explicit BooksSettings(QObject* aParent = NULL);
static QSharedPointer<BooksSettings> sharedInstance();
Q_INVOKABLE bool increaseFontSize(); Q_INVOKABLE bool increaseFontSize();
Q_INVOKABLE bool decreaseFontSize(); Q_INVOKABLE bool decreaseFontSize();
@ -128,6 +131,7 @@ private:
int fontSize(int aFontSizeAdjust) const; int fontSize(int aFontSizeAdjust) const;
private: private:
class Private;
MGConfItem* iFontSizeConf; MGConfItem* iFontSizeConf;
MGConfItem* iPageDetailsConf; MGConfItem* iPageDetailsConf;
MGConfItem* iInvertColorsConf; MGConfItem* iInvertColorsConf;

View file

@ -36,6 +36,7 @@
#include "BooksPaintContext.h" #include "BooksPaintContext.h"
#include "BooksDialogManager.h" #include "BooksDialogManager.h"
#include "BooksImageProvider.h" #include "BooksImageProvider.h"
#include "BooksSettings.h"
#include "HarbourDebug.h" #include "HarbourDebug.h"
@ -192,12 +193,14 @@ void ZLibrary::run(ZLApplication* aApp)
QQuickView* view = SailfishApp::createView(); QQuickView* view = SailfishApp::createView();
QQmlContext* root = view->rootContext(); QQmlContext* root = view->rootContext();
QSharedPointer<BooksSettings> settings = BooksSettings::sharedInstance();
root->engine()->addImageProvider(BooksImageProvider::PROVIDER_ID, root->engine()->addImageProvider(BooksImageProvider::PROVIDER_ID,
new BooksImageProvider(root)); new BooksImageProvider(root));
root->setContextProperty("PointsPerInch", booksPPI); root->setContextProperty("PointsPerInch", booksPPI);
root->setContextProperty("MaximumHintCount", 1); root->setContextProperty("MaximumHintCount", 1);
root->setContextProperty("BooksSettingsMenu", root->setContextProperty("BooksSettingsMenu",
QVariant::fromValue(BOOKS_SETTINGS_MENU)); QVariant::fromValue(BOOKS_SETTINGS_MENU));
root->setContextProperty("Settings", settings.data());
view->setTitle(qtTrId("harbour-books-app-name")); view->setTitle(qtTrId("harbour-books-app-name"));
view->setSource(QUrl::fromLocalFile(qml)); view->setSource(QUrl::fromLocalFile(qml));