Hide history controls if there's no history

Also, long-press on the history arrow clears the history
This commit is contained in:
Slava Monich 2017-08-03 21:24:03 +03:00
parent 9ac726c523
commit bd403f44c9

View file

@ -40,6 +40,9 @@ Item {
property var stack property var stack
property int pageCount property int pageCount
readonly property bool haveHistory: stack && stack.count > 1
readonly property bool canGoBack: haveHistory && stack.currentIndex > 0
readonly property bool canGoForward: haveHistory && (stack.currentIndex < (stack.count - 1))
property real leftMargin: Theme.horizontalPageMargin property real leftMargin: Theme.horizontalPageMargin
property real rightMargin: Theme.horizontalPageMargin property real rightMargin: Theme.horizontalPageMargin
property alias currentPage: slider.value property alias currentPage: slider.value
@ -47,6 +50,25 @@ Item {
signal pageChanged(var page) signal pageChanged(var page)
states: [
State {
name: "history"
when: haveHistory
PropertyChanges {
target: slider
x: navigateBack.x + navigateBack.width
}
},
State {
name: "default"
when: !haveHistory
PropertyChanges {
target: slider
x: 0
}
}
]
MouseArea { MouseArea {
id: navigateBackArea id: navigateBackArea
property bool down: pressed && containsMouse property bool down: pressed && containsMouse
@ -57,12 +79,15 @@ Item {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
onClicked: stack.back() onClicked: stack.back()
onPressAndHold: stack.clear()
} }
IconButton { IconButton {
id: navigateBack id: navigateBack
icon.source: "image://theme/icon-m-left?" + Settings.primaryPageToolColor icon.source: "image://theme/icon-m-left?" + Settings.primaryPageToolColor
opacity: canGoBack ? 1 : 0
visible: opacity > 0
Behavior on opacity { FadeAnimation {} }
down: navigateBackArea.down || (pressed && containsMouse) down: navigateBackArea.down || (pressed && containsMouse)
anchors { anchors {
left: parent.left left: parent.left
@ -70,15 +95,15 @@ Item {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
onClicked: stack.back() onClicked: stack.back()
onPressAndHold: stack.clear()
} }
BooksPageSlider { BooksPageSlider {
id: slider id: slider
anchors { anchors {
left: navigateBack.right
right: navigateForwardArea.left
bottom: parent.bottom bottom: parent.bottom
} }
width: parent.width - 2*x
stepSize: 1 stepSize: 1
minimumValue: 0 minimumValue: 0
maximumValue: pageCount > 0 ? pageCount - 1 : 0 maximumValue: pageCount > 0 ? pageCount - 1 : 0
@ -91,6 +116,7 @@ Item {
highlightColor: Settings.highlightPageToolColor highlightColor: Settings.highlightPageToolColor
secondaryHighlightColor: Settings.highlightPageToolColor secondaryHighlightColor: Settings.highlightPageToolColor
onSliderValueChanged: root.pageChanged(value) onSliderValueChanged: root.pageChanged(value)
Behavior on x { SmoothedAnimation { duration: 250 } }
} }
MouseArea { MouseArea {
@ -103,17 +129,22 @@ Item {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
onClicked: stack.forward() onClicked: stack.forward()
onPressAndHold: stack.clear()
} }
IconButton { IconButton {
id: navigateForward id: navigateForward
icon.source: "image://theme/icon-m-right?" + Settings.primaryPageToolColor icon.source: "image://theme/icon-m-right?" + Settings.primaryPageToolColor
down: navigateForwardArea.down || (pressed && containsMouse) down: navigateForwardArea.down || (pressed && containsMouse)
opacity: canGoForward ? 1 : 0
visible: opacity > 0
Behavior on opacity { FadeAnimation {} }
anchors { anchors {
right: parent.right right: parent.right
rightMargin: root.rightMargin rightMargin: root.rightMargin
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
onClicked: stack.forward() onClicked: stack.forward()
onPressAndHold: stack.clear()
} }
} }