From b74d57291c9bce570bc1c024f4548d632faa12ee Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Sun, 1 Nov 2020 19:03:59 +0200 Subject: [PATCH] [app] Reduced number of flickables That makes scrolling easier. It appears that nested flickables with the same flicking direction are having hard time fighting for mouse events. --- app/qml/BooksBookView.qml | 17 +++++----- app/qml/BooksMainPage.qml | 61 ++++++++++++++++++++++++++---------- app/qml/BooksStorageView.qml | 14 +++++++-- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/app/qml/BooksBookView.qml b/app/qml/BooksBookView.qml index c0cfe23..d4785e0 100644 --- a/app/qml/BooksBookView.qml +++ b/app/qml/BooksBookView.qml @@ -42,7 +42,7 @@ import harbour.books 1.0 import "harbour" -SilicaFlickable { +Item { id: root property variant book @@ -63,12 +63,10 @@ SilicaFlickable { { pager: true, page: true, title: true, tools: true } ] - interactive: !selecting && !scrollAnimation.running && - (!linkMenu || !linkMenu.visible) && - (!imageView || !imageView.visible) && - (!footnoteView || !footnoteView.visible) - + property alias viewInteractive: bookView.interactive + property alias pullDownMenu: menu property bool pageActive + readonly property bool viewActive: pageActive && Qt.application.active && book readonly property bool haveVolumeUpAction: Settings.volumeUpAction !== BooksSettings.ActionNone readonly property bool haveVolumeDownAction: Settings.volumeDownAction !== BooksSettings.ActionNone @@ -134,6 +132,8 @@ SilicaFlickable { } PullDownMenu { + id: menu + MenuItem { //: Pulley menu item //% "Settings" @@ -201,7 +201,10 @@ SilicaFlickable { spacing: Theme.paddingMedium opacity: loading ? 0 : 1 visible: opacity > 0 - interactive: root.interactive + interactive: !selecting && !scrollAnimation.running && + (!linkMenu || !linkMenu.visible) && + (!imageView || !imageView.visible) && + (!footnoteView || !footnoteView.visible) readonly property real maxContentX: Math.max(0, contentWidth - width) readonly property int currentPage: stackModel.currentPage diff --git a/app/qml/BooksMainPage.qml b/app/qml/BooksMainPage.qml index 1b6cedc..06cb593 100644 --- a/app/qml/BooksMainPage.qml +++ b/app/qml/BooksMainPage.qml @@ -42,12 +42,28 @@ Page { property variant currentShelf: storageView.currentShelf readonly property bool pageActive: status === PageStatus.Active + readonly property Item currentView: Settings.currentBook ? bookView : storageView + property Item bookView - property Item _bookView + Component.onCompleted: createBookViewIfNeeded() + + onCurrentViewChanged: setPullDownMenu(currentView ? currentView.pullDownMenu : null) function createBookViewIfNeeded() { - if (Settings.currentBook && !_bookView) { - _bookView = bookViewComponent.createObject(root) + if (Settings.currentBook && !bookView) { + bookView = bookViewComponent.createObject(flickable.contentItem) + } + } + + function setPullDownMenu(menu) { + if (flickable.pullDownMenu !== menu) { + if (flickable.pullDownMenu) { + flickable.pullDownMenu.visible = false + } + if (menu) { + menu.visible = true + } + flickable.pullDownMenu = menu } } @@ -56,11 +72,36 @@ Page { onCurrentBookChanged: createBookViewIfNeeded() } + Connections { + target: currentView + onPullDownMenuChanged: setPullDownMenu(currentView.pullDownMenu) + } + + SilicaFlickable { + id: flickable + + anchors.fill: parent + flickableDirection: Flickable.VerticalFlick + interactive: currentView && currentView.viewInteractive + pullDownMenu: currentView ? currentView.pullDownMenu : null + + BooksStorageView { + id: storageView + anchors.fill: parent + pageActive: root.pageActive + opacity: Settings.currentBook ? 0 : 1 + visible: opacity > 0 + Behavior on opacity { FadeAnimation {} } + onOpenBook: Settings.currentBook = book + } + } + Component { id: bookViewComponent + BooksBookView { anchors.fill: parent - opacity: book ? 1 : 0 + opacity: Settings.currentBook ? 1 : 0 visible: opacity > 0 orientation: root.orientation pageActive: root.pageActive @@ -69,16 +110,4 @@ Page { Behavior on opacity { FadeAnimation {} } } } - - BooksStorageView { - id: storageView - anchors.fill: parent - pageActive: root.pageActive - opacity: Settings.currentBook ? 0 : 1 - visible: opacity > 0 - Behavior on opacity { FadeAnimation {} } - onOpenBook: Settings.currentBook = book - } - - Component.onCompleted: createBookViewIfNeeded() } diff --git a/app/qml/BooksStorageView.qml b/app/qml/BooksStorageView.qml index 3e60b38..fe12f92 100644 --- a/app/qml/BooksStorageView.qml +++ b/app/qml/BooksStorageView.qml @@ -35,11 +35,11 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 import harbour.books 1.0 -SilicaFlickable { +Item { id: storageView - interactive: !dragInProgress - + property alias viewInteractive: storageList.interactive + property alias pullDownMenu: menu property bool pageActive property bool editMode: false @@ -94,6 +94,8 @@ SilicaFlickable { } PullDownMenu { + id: menu + MenuItem { //: Pulley menu item //% "Settings" @@ -137,6 +139,7 @@ SilicaFlickable { Component { id: importComponent + BooksImport { destination: currentShelf ? currentShelf.path : "" onAccepted: { @@ -155,6 +158,7 @@ SilicaFlickable { BookStorage { id: storageModel + // Show the contents of SD-card and let use know that he can switch // between the internal memory and the removable storage by swiping // the list horizontally @@ -168,12 +172,14 @@ SilicaFlickable { ListWatcher { id: storageListWatcher + listView: storageList onSizeChanged: _cellWidth = calculateCellWidth() } SilicaListView { id: storageList + anchors.fill: parent model: storageModel flickDeceleration: maximumFlickVelocity @@ -286,6 +292,7 @@ SilicaFlickable { BooksShelfItem { id: dragItem + visible: false width: storageView._cellWidth height: storageView._cellHeight @@ -303,6 +310,7 @@ SilicaFlickable { NumberAnimation { id: dragScrollAnimation + target: storageList property: "contentX" duration: 500