[app] Use shared instance of BooksSettings
This commit is contained in:
parent
55b47f18f2
commit
caf858b581
15 changed files with 97 additions and 136 deletions
|
@ -44,7 +44,7 @@ SilicaFlickable {
|
|||
|
||||
property int _currentPage: bookListWatcher.currentIndex
|
||||
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: [
|
||||
{ pager: false, page: false, title: false, tools: false },
|
||||
{ pager: false, page: true, title: true, tools: false },
|
||||
|
@ -77,7 +77,7 @@ SilicaFlickable {
|
|||
Component {
|
||||
id: imageViewComponent
|
||||
BooksImageView {
|
||||
imageBackground: globalSettings.pageBackgroundColor
|
||||
imageBackground: Settings.pageBackgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,6 @@ SilicaFlickable {
|
|||
rightMargin: Theme.horizontalPageMargin
|
||||
topMargin: Theme.itemSizeSmall
|
||||
bottomMargin: Theme.itemSizeSmall
|
||||
settings: globalSettings
|
||||
onJumpToPage: bookView.jumpTo(index)
|
||||
onCurrentPageChanged: {
|
||||
if (linkMenu) linkMenu.hide()
|
||||
|
@ -163,7 +162,7 @@ SilicaFlickable {
|
|||
onJumpToPage: bookView.jumpTo(page)
|
||||
onPageClicked: {
|
||||
root.pageClicked(index)
|
||||
globalSettings.pageDetails = (globalSettings.pageDetails+ 1) % _visibilityStates.length
|
||||
Settings.pageDetails = (Settings.pageDetails+ 1) % _visibilityStates.length
|
||||
}
|
||||
onImagePressed: {
|
||||
if (_currentPage == index) {
|
||||
|
|
|
@ -7,14 +7,15 @@
|
|||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Jolla Ltd nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
* Neither the name of Jolla Ltd nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
|
@ -36,7 +37,7 @@ import harbour.books 1.0
|
|||
ApplicationWindow {
|
||||
id: window
|
||||
allowedOrientations: {
|
||||
switch (globalSettings.orientation) {
|
||||
switch (Settings.orientation) {
|
||||
default:
|
||||
case BooksSettings.OrientationAny: return Orientation.All
|
||||
case BooksSettings.OrientationPortrait: return Orientation.Portrait
|
||||
|
@ -50,7 +51,6 @@ ApplicationWindow {
|
|||
|
||||
property variant currentShelf: mainPage.currentShelf
|
||||
|
||||
BooksSettings { id: globalSettings }
|
||||
BooksHints { id: globalHints }
|
||||
SystemState { id: globalSystemState }
|
||||
|
||||
|
@ -58,7 +58,7 @@ ApplicationWindow {
|
|||
|
||||
cover: Component {
|
||||
BooksCoverPage {
|
||||
book: globalSettings.currentBook
|
||||
book: Settings.currentBook
|
||||
shelf: currentShelf
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2015 Jolla Ltd.
|
||||
Copyright (C) 2015-2016 Jolla Ltd.
|
||||
Contact: Slava Monich <slava.monich@jolla.com>
|
||||
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Jolla Ltd nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
* Neither the name of Jolla Ltd nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
|
@ -44,13 +45,13 @@ Page {
|
|||
property Item _bookView
|
||||
|
||||
function createBookViewIfNeeded() {
|
||||
if (globalSettings.currentBook && !_bookView) {
|
||||
if (Settings.currentBook && !_bookView) {
|
||||
_bookView = bookViewComponent.createObject(root)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: globalSettings
|
||||
target: Settings
|
||||
onCurrentBookChanged: createBookViewIfNeeded()
|
||||
}
|
||||
|
||||
|
@ -60,8 +61,8 @@ Page {
|
|||
anchors.fill: parent
|
||||
opacity: book ? 1 : 0
|
||||
visible: opacity > 0
|
||||
book: globalSettings.currentBook ? globalSettings.currentBook : null
|
||||
onCloseBook: globalSettings.currentBook = null
|
||||
book: Settings.currentBook ? Settings.currentBook : null
|
||||
onCloseBook: Settings.currentBook = null
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
}
|
||||
}
|
||||
|
@ -69,10 +70,10 @@ Page {
|
|||
BooksStorageView {
|
||||
id: storageView
|
||||
anchors.fill: parent
|
||||
opacity: globalSettings.currentBook ? 0 : 1
|
||||
opacity: Settings.currentBook ? 0 : 1
|
||||
visible: opacity > 0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
onOpenBook: globalSettings.currentBook = book
|
||||
onOpenBook: Settings.currentBook = book
|
||||
}
|
||||
|
||||
Component.onCompleted: createBookViewIfNeeded()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2015 Jolla Ltd.
|
||||
Copyright (C) 2015-2016 Jolla Ltd.
|
||||
Contact: Slava Monich <slava.monich@jolla.com>
|
||||
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Jolla Ltd nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
* Neither the name of Jolla Ltd nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
|
@ -57,7 +58,7 @@ Item {
|
|||
left: parent.left
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
onClicked: globalSettings.invertColors = !globalSettings.invertColors
|
||||
onClicked: Settings.invertColors = !Settings.invertColors
|
||||
|
||||
Image {
|
||||
id: dayModeImage
|
||||
|
@ -69,7 +70,7 @@ Item {
|
|||
}
|
||||
height: Math.ceil(parent.height/2)
|
||||
sourceSize.height: height
|
||||
opacity: globalSettings.invertColors ? 0.5 : 0
|
||||
opacity: Settings.invertColors ? 0.5 : 0
|
||||
visible: opacity > 0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
}
|
||||
|
@ -78,7 +79,7 @@ Item {
|
|||
source: "images/night-mode.svg"
|
||||
anchors.fill: dayModeImage
|
||||
sourceSize.height: height
|
||||
opacity: globalSettings.invertColors ? 0 : 0.25
|
||||
opacity: Settings.invertColors ? 0 : 0.25
|
||||
visible: opacity > 0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ Item {
|
|||
}
|
||||
height: Math.ceil(parent.height/2)
|
||||
sourceSize.height: height
|
||||
opacity: globalSettings.invertColors ? 1 : 0.5
|
||||
opacity: Settings.invertColors ? 1 : 0.5
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
}
|
||||
onClicked: pageTools.increaseFontSize()
|
||||
|
@ -128,7 +129,7 @@ Item {
|
|||
}
|
||||
height: Math.ceil(parent.height/2)
|
||||
sourceSize.height: height
|
||||
opacity: globalSettings.invertColors ? 1 : 0.5
|
||||
opacity: Settings.invertColors ? 1 : 0.5
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
}
|
||||
onClicked: pageTools.decreaseFontSize()
|
||||
|
|
|
@ -57,7 +57,6 @@ Item {
|
|||
PageWidget {
|
||||
id: widget
|
||||
anchors.fill: parent
|
||||
settings: globalSettings
|
||||
model: bookModel
|
||||
onBrowserLinkPressed: view.browserLinkPressed(url)
|
||||
onImagePressed: view.imagePressed(url, rect)
|
||||
|
@ -76,7 +75,7 @@ Item {
|
|||
}
|
||||
centerX: Math.floor(view.width/2) - anchors.leftMargin
|
||||
height: Theme.itemSizeExtraSmall
|
||||
color: globalSettings.primaryPageToolColor
|
||||
color: Settings.primaryPageToolColor
|
||||
opacity: titleVisible ? 1 : 0
|
||||
}
|
||||
|
||||
|
@ -91,7 +90,7 @@ Item {
|
|||
|
||||
Image {
|
||||
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
|
||||
opacity: 0
|
||||
readonly property int maxsize: Math.max(view.width, view.height)
|
||||
|
@ -146,7 +145,7 @@ Item {
|
|||
height: Theme.itemSizeExtraSmall
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
color: globalSettings.primaryPageToolColor
|
||||
color: Settings.primaryPageToolColor
|
||||
opacity: pageNumberVisible ? 1 : 0
|
||||
visible: opacity > 0
|
||||
Behavior on opacity { FadeAnimation {} }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2015 Jolla Ltd.
|
||||
Copyright (C) 2015-2016 Jolla Ltd.
|
||||
Contact: Slava Monich <slava.monich@jolla.com>
|
||||
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Jolla Ltd nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
* Neither the name of Jolla Ltd nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
|
@ -56,10 +57,10 @@ Item {
|
|||
minimumValue: 0
|
||||
valueText: ""
|
||||
label: ""
|
||||
primaryColor: globalSettings.primaryPageToolColor
|
||||
secondaryColor: globalSettings.primaryPageToolColor
|
||||
highlightColor: globalSettings.highlightPageToolColor
|
||||
secondaryHighlightColor: globalSettings.highlightPageToolColor
|
||||
primaryColor: Settings.primaryPageToolColor
|
||||
secondaryColor: Settings.primaryPageToolColor
|
||||
highlightColor: Settings.highlightPageToolColor
|
||||
secondaryHighlightColor: Settings.highlightPageToolColor
|
||||
onValueChanged: root.pageChanged(value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,13 +74,13 @@ Item {
|
|||
editMode: shelfView.editMode
|
||||
onRelativePathChanged: longStartTimer.restart()
|
||||
onPathChanged: {
|
||||
if (globalSettings.currentStorage === device && _completed) {
|
||||
globalSettings.currentFolder = path
|
||||
if (Settings.currentStorage === device && _completed) {
|
||||
Settings.currentFolder = path
|
||||
}
|
||||
}
|
||||
onDeviceChanged: {
|
||||
if (device === globalSettings.currentStorage) {
|
||||
relativePath = globalSettings.relativePath
|
||||
if (device === Settings.currentStorage) {
|
||||
relativePath = Settings.relativePath
|
||||
}
|
||||
}
|
||||
Component.onCompleted: _completed = true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2015 Jolla Ltd.
|
||||
Copyright (C) 2015-2016 Jolla Ltd.
|
||||
Contact: Slava Monich <slava.monich@jolla.com>
|
||||
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Jolla Ltd nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
* Neither the name of Jolla Ltd nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
|
@ -85,7 +86,7 @@ SilicaFlickable {
|
|||
|
||||
onCurrentShelfChanged: {
|
||||
if (storageList.completed && currentShelf) {
|
||||
globalSettings.currentFolder = currentShelf.path
|
||||
Settings.currentFolder = currentShelf.path
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,14 +188,14 @@ SilicaFlickable {
|
|||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
var index = model.deviceIndex(globalSettings.currentStorage)
|
||||
var index = model.deviceIndex(Settings.currentStorage)
|
||||
// positionViewAtIndex doesn't work here, update contentX directly
|
||||
if (index >= 0) {
|
||||
contentX = (width + spacing) * index
|
||||
} else {
|
||||
// Most likely, removable storage is gone
|
||||
console.log(globalSettings.currentFolder, "is gone")
|
||||
globalSettings.currentFolder = currentShelf ? currentShelf.path : ""
|
||||
console.log(Settings.currentFolder, "is gone")
|
||||
Settings.currentFolder = currentShelf ? currentShelf.path : ""
|
||||
}
|
||||
completed = true
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Jolla Ltd.
|
||||
* Copyright (C) 2015-2016 Jolla Ltd.
|
||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
||||
*
|
||||
* 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
|
||||
* the documentation and/or other materials provided with the
|
||||
* 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
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
|
@ -206,13 +206,14 @@ BooksBookModel::BooksBookModel(QObject* aParent) :
|
|||
iCurrentPage(-1),
|
||||
iProgress(0),
|
||||
iBook(NULL),
|
||||
iSettings(NULL),
|
||||
iTask(NULL),
|
||||
iData(NULL),
|
||||
iData2(NULL),
|
||||
iTaskQueue(BooksTaskQueue::defaultQueue()),
|
||||
iTextStyle(BooksTextStyle::defaults())
|
||||
iSettings(BooksSettings::sharedInstance()),
|
||||
iTaskQueue(BooksTaskQueue::defaultQueue())
|
||||
{
|
||||
iTextStyle = iSettings->textStyle(fontSizeAdjust());
|
||||
connect(iSettings.data(), SIGNAL(textStyleChanged()), SLOT(onTextStyleChanged()));
|
||||
HDEBUG("created");
|
||||
#if QT_VERSION < 0x050000
|
||||
setRoleNames(roleNames());
|
||||
|
@ -254,7 +255,6 @@ void BooksBookModel::setBook(BooksBook* aBook)
|
|||
iTitle = QString();
|
||||
HDEBUG("<none>");
|
||||
}
|
||||
updateTextStyle();
|
||||
startReset(ReasonLoading, true);
|
||||
if (oldTitle != iTitle) {
|
||||
Q_EMIT titleChanged();
|
||||
|
@ -270,34 +270,6 @@ bool BooksBookModel::loading() const
|
|||
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()
|
||||
{
|
||||
return iBook && iBook->setFontSizeAdjust(iBook->fontSizeAdjust()+1);
|
||||
|
|
|
@ -69,7 +69,6 @@ class BooksBookModel: public QAbstractListModel, private BooksLoadingProperty
|
|||
Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
|
||||
Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
|
||||
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)
|
||||
|
||||
public:
|
||||
|
@ -104,9 +103,6 @@ public:
|
|||
BooksBook* book() const { return iBook; }
|
||||
void setBook(BooksBook* aBook);
|
||||
|
||||
BooksSettings* settings() const { return iSettings; }
|
||||
void setSettings(BooksSettings* aModel);
|
||||
|
||||
int leftMargin() const { return iMargins.iLeft; }
|
||||
int rightMargin() const { return iMargins.iRight; }
|
||||
int topMargin() const { return iMargins.iTop; }
|
||||
|
@ -137,7 +133,6 @@ 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,7 +149,6 @@ Q_SIGNALS:
|
|||
void pageMarksChanged();
|
||||
void progressChanged();
|
||||
void currentPageChanged();
|
||||
void settingsChanged();
|
||||
void leftMarginChanged();
|
||||
void rightMarginChanged();
|
||||
void topMarginChanged();
|
||||
|
@ -175,10 +169,10 @@ private:
|
|||
BooksMargins iMargins;
|
||||
BooksBook* iBook;
|
||||
shared_ptr<Book> iBookRef;
|
||||
BooksSettings* iSettings;
|
||||
Task* iTask;
|
||||
Data* iData;
|
||||
Data* iData2;
|
||||
QSharedPointer<BooksSettings> iSettings;
|
||||
shared_ptr<BooksTaskQueue> iTaskQueue;
|
||||
shared_ptr<ZLTextStyle> iTextStyle;
|
||||
};
|
||||
|
|
|
@ -254,11 +254,11 @@ void BooksPageWidget::PressTask::performTask()
|
|||
|
||||
BooksPageWidget::BooksPageWidget(QQuickItem* aParent) :
|
||||
QQuickPaintedItem(aParent),
|
||||
iSettings(BooksSettings::sharedInstance()),
|
||||
iTaskQueue(BooksTaskQueue::defaultQueue()),
|
||||
iTextStyle(BooksTextStyle::defaults()),
|
||||
iResizeTimer(new QTimer(this)),
|
||||
iModel(NULL),
|
||||
iSettings(NULL),
|
||||
iResetTask(NULL),
|
||||
iRenderTask(NULL),
|
||||
iPressTask(NULL),
|
||||
|
@ -266,8 +266,13 @@ BooksPageWidget::BooksPageWidget(QQuickItem* aParent) :
|
|||
iEmpty(false),
|
||||
iPage(-1)
|
||||
{
|
||||
connect(iSettings.data(),
|
||||
SIGNAL(invertColorsChanged()),
|
||||
SLOT(onInvertColorsChanged()));
|
||||
setFillColor(qtColor(iSettings->invertColors() ?
|
||||
BooksTextView::INVERTED_BACKGROUND :
|
||||
BooksTextView::DEFAULT_BACKGROUND));
|
||||
setFlag(ItemHasContents, true);
|
||||
setFillColor(qtColor(BooksTextView::DEFAULT_BACKGROUND));
|
||||
iResizeTimer->setSingleShot(true);
|
||||
iResizeTimer->setInterval(0);
|
||||
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()
|
||||
{
|
||||
HDEBUG(iPage);
|
||||
|
|
|
@ -58,7 +58,6 @@ class BooksPageWidget: public QQuickPaintedItem, private BooksLoadingProperty
|
|||
Q_PROPERTY(int topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
|
||||
Q_PROPERTY(int bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
|
||||
Q_PROPERTY(BooksBookModel* model READ model WRITE setModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(BooksSettings* settings READ settings WRITE setSettings NOTIFY settingsChanged)
|
||||
|
||||
public:
|
||||
class Data;
|
||||
|
@ -74,9 +73,6 @@ public:
|
|||
BooksBookModel* model() const { return iModel; }
|
||||
void setModel(BooksBookModel* aModel);
|
||||
|
||||
BooksSettings* settings() const { return iSettings; }
|
||||
void setSettings(BooksSettings* aSettings);
|
||||
|
||||
int leftMargin() const { return iMargins.iLeft; }
|
||||
int rightMargin() const { return iMargins.iRight; }
|
||||
int topMargin() const { return iMargins.iTop; }
|
||||
|
@ -96,7 +92,6 @@ Q_SIGNALS:
|
|||
void loadingChanged();
|
||||
void pageChanged();
|
||||
void modelChanged();
|
||||
void settingsChanged();
|
||||
void leftMarginChanged();
|
||||
void rightMarginChanged();
|
||||
void topMarginChanged();
|
||||
|
@ -134,12 +129,12 @@ private:
|
|||
class RenderTask;
|
||||
class PressTask;
|
||||
|
||||
QSharedPointer<BooksSettings> iSettings;
|
||||
shared_ptr<BooksTaskQueue> iTaskQueue;
|
||||
shared_ptr<ZLTextStyle> iTextStyle;
|
||||
BooksPos iPageMark;
|
||||
QTimer* iResizeTimer;
|
||||
BooksBookModel* iModel;
|
||||
BooksSettings* iSettings;
|
||||
BooksMargins iMargins;
|
||||
shared_ptr<Data> iData;
|
||||
shared_ptr<QImage> iImage;
|
||||
|
|
|
@ -200,6 +200,13 @@ BooksSettings::TextStyle::allowHyphenations() const
|
|||
// BooksSettings
|
||||
// ==========================================================================
|
||||
|
||||
class BooksSettings::Private {
|
||||
public:
|
||||
static QWeakPointer<BooksSettings> sSharedInstance;
|
||||
};
|
||||
|
||||
QWeakPointer<BooksSettings> BooksSettings::Private::sSharedInstance;
|
||||
|
||||
BooksSettings::BooksSettings(QObject* aParent) :
|
||||
QObject(aParent),
|
||||
iFontSizeConf(new MGConfItem(DCONF_PATH KEY_FONT_SIZE, this)),
|
||||
|
@ -222,6 +229,19 @@ BooksSettings::BooksSettings(QObject* aParent) :
|
|||
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
|
||||
BooksSettings::increaseFontSize()
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "ZLTextStyle.h"
|
||||
#include <QColor>
|
||||
#include <QtQml>
|
||||
#include <QSharedPointer>
|
||||
|
||||
class MGConfItem;
|
||||
|
||||
|
@ -75,6 +76,8 @@ public:
|
|||
|
||||
explicit BooksSettings(QObject* aParent = NULL);
|
||||
|
||||
static QSharedPointer<BooksSettings> sharedInstance();
|
||||
|
||||
Q_INVOKABLE bool increaseFontSize();
|
||||
Q_INVOKABLE bool decreaseFontSize();
|
||||
|
||||
|
@ -128,6 +131,7 @@ private:
|
|||
int fontSize(int aFontSizeAdjust) const;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
MGConfItem* iFontSizeConf;
|
||||
MGConfItem* iPageDetailsConf;
|
||||
MGConfItem* iInvertColorsConf;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "BooksPaintContext.h"
|
||||
#include "BooksDialogManager.h"
|
||||
#include "BooksImageProvider.h"
|
||||
#include "BooksSettings.h"
|
||||
|
||||
#include "HarbourDebug.h"
|
||||
|
||||
|
@ -192,12 +193,14 @@ void ZLibrary::run(ZLApplication* aApp)
|
|||
|
||||
QQuickView* view = SailfishApp::createView();
|
||||
QQmlContext* root = view->rootContext();
|
||||
QSharedPointer<BooksSettings> settings = BooksSettings::sharedInstance();
|
||||
root->engine()->addImageProvider(BooksImageProvider::PROVIDER_ID,
|
||||
new BooksImageProvider(root));
|
||||
root->setContextProperty("PointsPerInch", booksPPI);
|
||||
root->setContextProperty("MaximumHintCount", 1);
|
||||
root->setContextProperty("BooksSettingsMenu",
|
||||
QVariant::fromValue(BOOKS_SETTINGS_MENU));
|
||||
root->setContextProperty("Settings", settings.data());
|
||||
|
||||
view->setTitle(qtTrId("harbour-books-app-name"));
|
||||
view->setSource(QUrl::fromLocalFile(qml));
|
||||
|
|
Loading…
Reference in a new issue