From c90983070cb206566122ae3896ee20850762f762 Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 23 Aug 2015 14:47:25 +0300 Subject: [PATCH] [app] Moved font controls from pulley menu to toolbar Tool icon replaces double-click as the night/day mode switch. --- app/qml/BooksBookView.qml | 68 +++++--------- app/qml/BooksPageTools.qml | 133 +++++++++++++++++++++++++++ app/qml/BooksPageView.qml | 40 ++------ app/qml/BooksPager.qml | 11 +-- app/qml/BooksTitleLabel.qml | 80 ++++++++++++++++ app/qml/images/day-mode.svg | 94 +++++++++++++++++++ app/qml/images/font-larger.svg | 57 ++++++++++++ app/qml/images/font-smaller.svg | 57 ++++++++++++ app/qml/images/night-mode.svg | 74 +++++++++++++++ app/src/BooksSettings.cpp | 42 +++++++++ app/src/BooksSettings.h | 8 ++ app/src/ZLibrary.cpp | 3 - app/translations/harbour-books-fi.ts | 12 --- app/translations/harbour-books-ru.ts | 12 --- app/translations/harbour-books-sv.ts | 12 --- app/translations/harbour-books.ts | 12 --- 16 files changed, 582 insertions(+), 133 deletions(-) create mode 100644 app/qml/BooksPageTools.qml create mode 100644 app/qml/BooksTitleLabel.qml create mode 100644 app/qml/images/day-mode.svg create mode 100644 app/qml/images/font-larger.svg create mode 100644 app/qml/images/font-smaller.svg create mode 100644 app/qml/images/night-mode.svg diff --git a/app/qml/BooksBookView.qml b/app/qml/BooksBookView.qml index 0ebf09b..4de148a 100644 --- a/app/qml/BooksBookView.qml +++ b/app/qml/BooksBookView.qml @@ -51,27 +51,6 @@ SilicaFlickable { ] PullDownMenu { - MenuItem { - id: defaultFontMenuItem - //% "Use default fonts" - text: qsTrId("book-font-default") - enabled: globalSettings.fontSize != BooksSettings.DefaultFontSize - onClicked: globalSettings.fontSize = BooksSettings.DefaultFontSize - } - MenuItem { - id: smallerFontMenuItem - //% "Use smaller fonts" - text: qsTrId("book-font-smaller") - enabled: globalSettings.fontSize >= BooksSettings.MinFontSize - onClicked: globalSettings.fontSize -= 1 - } - MenuItem { - id: largerFontMenuItem - //% "Use larger fonts" - text: qsTrId("book-font-larger") - enabled: globalSettings.fontSize <= BooksSettings.MaxFontSize - onClicked: globalSettings.fontSize += 1 - } MenuItem { //% "Back to library" text: qsTrId("book-view-back") @@ -153,6 +132,8 @@ SilicaFlickable { rightMargin: bookModel.rightMargin topMargin: bookModel.topMargin bottomMargin: bookModel.bottomMargin + leftSpaceReserved: pageTools.visible ? pageTools.leftSpaceUsed : 0 + rightSpaceReserved: pageTools.visible ? pageTools.rightSpaceUsed: 0 titleVisible: _currentState.title pageNumberVisible: _currentState.page title: bookModel.title @@ -176,35 +157,34 @@ SilicaFlickable { } Behavior on opacity { FadeAnimation {} } - } -/* - BooksPageTools { - anchors { - top: parent.top - left: parent.left - right: parent.right + BooksPageTools { + id: pageTools + anchors { + top: parent.top + left: parent.left + right: parent.right + } leftMargin: bookModel.leftMargin rightMargin: bookModel.rightMargin + opacity: _currentState.tools ? 1 : 0 + visible: opacity > 0 && book && bookModel.pageCount && !_loading + Behavior on opacity { FadeAnimation {} } } - opacity: _currentState.tools ? 1 : 0 - visible: opacity > 0 - Behavior on opacity { FadeAnimation {} } - } -*/ - BooksPager { - id: pager - anchors { - bottom: parent.bottom - bottomMargin: (Theme.itemSizeExtraSmall + 2*(bookModel.bottomMargin - height))/4 + BooksPager { + id: pager + anchors { + bottom: parent.bottom + bottomMargin: (Theme.itemSizeExtraSmall + 2*(bookModel.bottomMargin - height))/4 + } + pageCount: bookModel.pageCount + width: parent.width + opacity: (_currentState.pager && book && bookModel.pageCount) ? 0.75 : 0 + visible: opacity > 0 + onPageChanged: bookView.jumpTo(page) + Behavior on opacity { FadeAnimation {} } } - pageCount: bookModel.pageCount - width: parent.width - opacity: _currentState.pager ? 1 : 0 - visible: opacity > 0 && book && bookModel.pageCount && !_loading - onPageChanged: bookView.jumpTo(page) - Behavior on opacity { FadeAnimation {} } } BusyIndicator { diff --git a/app/qml/BooksPageTools.qml b/app/qml/BooksPageTools.qml new file mode 100644 index 0000000..50cb0ba --- /dev/null +++ b/app/qml/BooksPageTools.qml @@ -0,0 +1,133 @@ +/* + Copyright (C) 2015 Jolla Ltd. + Contact: Slava Monich + + You may use this file under the terms of BSD license as follows: + + 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. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. +*/ + +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import harbour.books 1.0 + +Item { + id: pageTools + height: Theme.itemSizeExtraSmall + property real leftMargin: Theme.horizontalPageMargin + property real rightMargin: Theme.horizontalPageMargin + property real spacing: Theme.paddingLarge + property real leftSpaceUsed: dayNightModeSwitch.x + dayNightModeSwitch.width + property real rightSpaceUsed: width - decreaseFontSizeButton.x + + property real _spacingBy2: Math.ceil(spacing/2) + + // Left side + + MouseArea { + id: dayNightModeSwitch + height: parent.height + width: leftMargin + dayModeImage.width + spacing + anchors { + left: parent.left + verticalCenter: parent.verticalCenter + } + onClicked: globalSettings.invertColors = !globalSettings.invertColors + + Image { + id: dayModeImage + source: "images/day-mode.svg" + anchors { + left: parent.left + leftMargin: pageTools.leftMargin + verticalCenter: parent.verticalCenter + } + height: Math.ceil(parent.height/2) + sourceSize.height: height + opacity: globalSettings.invertColors ? 0.5 : 0 + visible: opacity > 0 + Behavior on opacity { FadeAnimation {} } + } + + Image { + source: "images/night-mode.svg" + anchors.fill: dayModeImage + sourceSize.height: height + opacity: globalSettings.invertColors ? 0 : 0.25 + visible: opacity > 0 + Behavior on opacity { FadeAnimation {} } + } + } + + // Right side + + MouseArea { + id: increaseFontSizeButton + width: leftMargin + increaseFontSizeButtonImage.width + _spacingBy2 + height: parent.height + anchors { + right: parent.right + verticalCenter: parent.verticalCenter + } + Image { + id: increaseFontSizeButtonImage + source: "images/font-larger.svg" + anchors { + left: parent.left + leftMargin: _spacingBy2 + verticalCenter: parent.verticalCenter + } + height: Math.ceil(parent.height/2) + sourceSize.height: height + opacity: globalSettings.invertColors ? 1 : 0.5 + Behavior on opacity { FadeAnimation {} } + } + onClicked: globalSettings.increaseFontSize() + } + + MouseArea { + id: decreaseFontSizeButton + width: decreaseFontSizeButtonImage.width + spacing + _spacingBy2 + height: parent.height + anchors { + right: increaseFontSizeButton.left + verticalCenter: parent.verticalCenter + } + Image { + id: decreaseFontSizeButtonImage + source: "images/font-smaller.svg" + anchors { + right: parent.right + rightMargin: _spacingBy2 + verticalCenter: parent.verticalCenter + } + height: Math.ceil(parent.height/2) + sourceSize.height: height + opacity: globalSettings.invertColors ? 1 : 0.5 + Behavior on opacity { FadeAnimation {} } + } + onClicked: globalSettings.decreaseFontSize() + } +} diff --git a/app/qml/BooksPageView.qml b/app/qml/BooksPageView.qml index 5a33782..3fad3ee 100644 --- a/app/qml/BooksPageView.qml +++ b/app/qml/BooksPageView.qml @@ -43,9 +43,10 @@ Item { property alias topMargin: widget.topMargin property alias bottomMargin: widget.bottomMargin property alias title: titleLabel.text + property real leftSpaceReserved + property real rightSpaceReserved property bool titleVisible property bool pageNumberVisible - property color extraInfoColor: "#808080" signal pageClicked() @@ -56,24 +57,19 @@ Item { model: bookModel } - Label { + BooksTitleLabel { id: titleLabel anchors { top: parent.top left: parent.left right: parent.right - leftMargin: Theme.paddingLarge - rightMargin: Theme.paddingLarge + leftMargin: Math.max(view.leftMargin, leftSpaceReserved) + rightMargin: Math.max(view.rightMargin, rightSpaceReserved) } + centerX: Math.floor(view.width/2) - anchors.leftMargin height: Theme.itemSizeExtraSmall - font.pixelSize: Theme.fontSizeSmall - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - color: extraInfoColor - elide: Text.ElideRight + color: globalSettings.primaryPageToolColor opacity: titleVisible ? 1 : 0 - visible: opacity > 0 - Behavior on opacity { FadeAnimation {} } } BusyIndicator { @@ -94,32 +90,14 @@ Item { height: Theme.itemSizeExtraSmall font.pixelSize: Theme.fontSizeSmall verticalAlignment: Text.AlignVCenter - color: extraInfoColor + color: globalSettings.primaryPageToolColor opacity: pageNumberVisible ? 1 : 0 visible: opacity > 0 Behavior on opacity { FadeAnimation {} } } - // For some reason this MouseArea receives clicks but not double-click - // events. It was easier to reimplement double-click functionality than - // to figure out what's wrong with double clicks. MouseArea { anchors.fill: parent - onClicked: { - if (!clickTimer.running) { - // If there're no more clicks within DoubleClickInterval - // then it's a single click - clickTimer.start() - } else { - // Otherwise it's a double click - clickTimer.stop() - globalSettings.invertColors = !globalSettings.invertColors - } - } - Timer { - id: clickTimer - interval: DoubleClickInterval - onTriggered: view.pageClicked() - } + onClicked: view.pageClicked() } } diff --git a/app/qml/BooksPager.qml b/app/qml/BooksPager.qml index 2ef8c55..b57e60c 100644 --- a/app/qml/BooksPager.qml +++ b/app/qml/BooksPager.qml @@ -56,13 +56,10 @@ Item { minimumValue: 0 valueText: "" label: "" - //highlightColor: primaryColor - //secondaryHighlightColor: secondaryColor - //highlightColor: "#000000" - //secondaryHighlightColor: "#808080" - //primaryColor: "#808080" - primaryColor: highlightColor - secondaryColor: secondaryHighlightColor + primaryColor: globalSettings.primaryPageToolColor + secondaryColor: globalSettings.primaryPageToolColor + highlightColor: globalSettings.highlightPageToolColor + secondaryHighlightColor: globalSettings.highlightPageToolColor onValueChanged: root.pageChanged(value) } } diff --git a/app/qml/BooksTitleLabel.qml b/app/qml/BooksTitleLabel.qml new file mode 100644 index 0000000..57daf8d --- /dev/null +++ b/app/qml/BooksTitleLabel.qml @@ -0,0 +1,80 @@ +/* + Copyright (C) 2015 Jolla Ltd. + Contact: Slava Monich + + You may use this file under the terms of BSD license as follows: + + 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. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + THE POSSIBILITY OF SUCH DAMAGE. +*/ + +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Item { + id: title + property real centerX: Math.floor(width/2) + property alias text: label.text + property alias color: label.color + + visible: opacity > 0 + Behavior on opacity { FadeAnimation {} } + + Component.onCompleted: updateLayout() + + onWidthChanged: updateLayout() + onHeightChanged: updateLayout() + onCenterXChanged: updateLayout() + onTextChanged: updateLayout() + + function updateLayout() { + if (centerX > 0 && centerX < width) { + var left = Math.ceil(centerX) + var right = Math.floor(width - centerX) + var preferredWidth = Math.floor(Math.min(left, right))*2 + label.anchors.leftMargin = 0 + label.anchors.rightMargin = 0 + if (label.paintedWidth <= preferredWidth) { + if (left < right) { + label.anchors.leftMargin = 0 + label.anchors.rightMargin = right - left + } else { + label.anchors.leftMargin = left - right + label.anchors.rightMargin = 0 + } + } + } + } + + Label { + id: label + anchors.fill: parent + smooth: true + height: Theme.itemSizeExtraSmall + font.pixelSize: Theme.fontSizeSmall + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } +} diff --git a/app/qml/images/day-mode.svg b/app/qml/images/day-mode.svg new file mode 100644 index 0000000..0559dec --- /dev/null +++ b/app/qml/images/day-mode.svg @@ -0,0 +1,94 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/app/qml/images/font-larger.svg b/app/qml/images/font-larger.svg new file mode 100644 index 0000000..2e2aff6 --- /dev/null +++ b/app/qml/images/font-larger.svg @@ -0,0 +1,57 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/app/qml/images/font-smaller.svg b/app/qml/images/font-smaller.svg new file mode 100644 index 0000000..a7e21a0 --- /dev/null +++ b/app/qml/images/font-smaller.svg @@ -0,0 +1,57 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/app/qml/images/night-mode.svg b/app/qml/images/night-mode.svg new file mode 100644 index 0000000..c39b90d --- /dev/null +++ b/app/qml/images/night-mode.svg @@ -0,0 +1,74 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/app/src/BooksSettings.cpp b/app/src/BooksSettings.cpp index 76b1006..daa49f7 100644 --- a/app/src/BooksSettings.cpp +++ b/app/src/BooksSettings.cpp @@ -53,6 +53,10 @@ #define DEFAULT_CURRENT_FOLDER QString() #define DEFAULT_INVERT_COLORS false +#define PAGETOOL_COLOR QColor(128,128,128) // any bg +#define NORMAL_PAGETOOL_HIGHLIGHT_COLOR QColor(64,64,64) // on white +#define INVERTED_PAGETOOL_HIGHLIGHT_COLOR QColor(192,192,192) // on black + // ========================================================================== // BooksSettings::TextStyle // ========================================================================== @@ -212,6 +216,30 @@ BooksSettings::BooksSettings(QObject* aParent) : connect(iCurrentBookPath, SIGNAL(valueChanged()), SLOT(onCurrentBookPathChanged())); } +bool +BooksSettings::increaseFontSize() +{ + int size = fontSize(); + if (size < MaxFontSize) { + setFontSize(size+1); + return true; + } else { + return false; + } +} + +bool +BooksSettings::decreaseFontSize() +{ + int size = fontSize(); + if (size > MinFontSize) { + setFontSize(size-1); + return true; + } else { + return false; + } +} + int BooksSettings::fontSize() const { @@ -362,3 +390,17 @@ BooksSettings::onCurrentBookPathChanged() Q_EMIT currentBookChanged(); } } + +QColor +BooksSettings::primaryPageToolColor() const +{ + return PAGETOOL_COLOR; +} + +QColor +BooksSettings::highlightPageToolColor() const +{ + return invertColors() ? + INVERTED_PAGETOOL_HIGHLIGHT_COLOR : + NORMAL_PAGETOOL_HIGHLIGHT_COLOR; +} diff --git a/app/src/BooksSettings.h b/app/src/BooksSettings.h index 7c067dd..7ab0c6d 100644 --- a/app/src/BooksSettings.h +++ b/app/src/BooksSettings.h @@ -36,6 +36,7 @@ #include "BooksTypes.h" #include "ZLTextStyle.h" +#include #include class MGConfItem; @@ -50,6 +51,8 @@ class BooksSettings : public QObject Q_PROPERTY(QObject* currentBook READ currentBook WRITE setCurrentBook NOTIFY currentBookChanged) Q_PROPERTY(QString currentFolder READ currentFolder WRITE setCurrentFolder NOTIFY currentFolderChanged) Q_PROPERTY(QString currentStorage READ currentStorage NOTIFY currentStorageChanged) + Q_PROPERTY(QColor primaryPageToolColor READ primaryPageToolColor CONSTANT) + Q_PROPERTY(QColor highlightPageToolColor READ highlightPageToolColor NOTIFY invertColorsChanged) class TextStyle; public: @@ -61,6 +64,9 @@ public: explicit BooksSettings(QObject* aParent = NULL); + Q_INVOKABLE bool increaseFontSize(); + Q_INVOKABLE bool decreaseFontSize(); + int fontSize() const; void setFontSize(int aValue); @@ -79,6 +85,8 @@ public: void setCurrentFolder(QString aValue); QString currentStorage() const { return iCurrentStorageDevice; } + QColor primaryPageToolColor() const; + QColor highlightPageToolColor() const; signals: void fontSizeChanged(); diff --git a/app/src/ZLibrary.cpp b/app/src/ZLibrary.cpp index 4576166..4c8e9b5 100644 --- a/app/src/ZLibrary.cpp +++ b/app/src/ZLibrary.cpp @@ -51,7 +51,6 @@ #include #include -#include #include #include @@ -170,8 +169,6 @@ void ZLibrary::run(ZLApplication* aApp) QQmlContext* root = view->rootContext(); root->setContextProperty("PointsPerInch", BOOKS_PPI); root->setContextProperty("MaximumHintCount", 1); - root->setContextProperty("DoubleClickInterval", - qApp->styleHints()->mouseDoubleClickInterval()); view->setSource(QUrl::fromLocalFile(qml)); view->show(); diff --git a/app/translations/harbour-books-fi.ts b/app/translations/harbour-books-fi.ts index 44e2e46..05526fc 100644 --- a/app/translations/harbour-books-fi.ts +++ b/app/translations/harbour-books-fi.ts @@ -3,18 +3,6 @@ - - Use default fonts - Oletuskirjasimet - - - Use smaller fonts - Pienemmät kirjasimet - - - Use larger fonts - Suuremmat kirjasimet - Back to library Takaisin kirjalistaan diff --git a/app/translations/harbour-books-ru.ts b/app/translations/harbour-books-ru.ts index 1c95112..1420047 100644 --- a/app/translations/harbour-books-ru.ts +++ b/app/translations/harbour-books-ru.ts @@ -3,18 +3,6 @@ - - Use default fonts - Шрифты по умолчанию - - - Use smaller fonts - Шрифты поменьше - - - Use larger fonts - Шрифты побольше - Back to library Вернуться в библиотеку diff --git a/app/translations/harbour-books-sv.ts b/app/translations/harbour-books-sv.ts index c595742..046c24a 100644 --- a/app/translations/harbour-books-sv.ts +++ b/app/translations/harbour-books-sv.ts @@ -3,18 +3,6 @@ - - Use default fonts - Standardteckensnitt - - - Use smaller fonts - Mindre teckensnitt - - - Use larger fonts - Större teckensnitt - Back to library Tillbaka till biblioteket diff --git a/app/translations/harbour-books.ts b/app/translations/harbour-books.ts index c043350..fa5ff14 100644 --- a/app/translations/harbour-books.ts +++ b/app/translations/harbour-books.ts @@ -3,18 +3,6 @@ - - Use default fonts - Use default fonts - - - Use smaller fonts - Use smaller fonts - - - Use larger fonts - Use larger fonts - Back to library Back to library