Rejig navigation

This change streamlines the navigation across the pages to be in line
with the stackview organization. The top bar becomes a static element
with the title and a button that either opens the preferences or shows
the back arrow.

This makes it a bit more efficient, since we load the title bar only
one, and there are no strange animations in the title. The stackview
gets the role of content container, the "chrome" around it is laid out
in main.qml.

Most of the churn in this patch comes from moving large blocks of code
between files with different indentation levels.

Signed-off-by: Sebastian Kügler <sebas@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Sebastian Kügler 2015-11-07 03:08:05 +01:00 committed by Dirk Hohndel
parent 0e26afbf0a
commit 2b70b76133
3 changed files with 84 additions and 125 deletions

View file

@ -38,10 +38,6 @@ Item {
width: parent.width width: parent.width
spacing: 8 spacing: 8
TopBar {
}
Button { Button {
text: "Hide Dive Profile" text: "Hide Dive Profile"
onClicked: { onClicked: {

View file

@ -8,33 +8,52 @@ import QtQuick.Window 2.2
import org.subsurfacedivelog.mobile 1.0 import org.subsurfacedivelog.mobile 1.0
Rectangle { Rectangle {
id: topBar id: topPart
property bool goBack: (stackView.depth > 1)
color: theme.accentColor color: theme.accentColor
Layout.minimumHeight: units.gridUnit * 2 + units.smallSpacing * 2
Layout.fillWidth: true Layout.fillWidth: true
Layout.margins: 0 Layout.margins: 0
Layout.minimumHeight: prefsButton.height + units.smallSpacing * 2
RowLayout { RowLayout {
anchors.bottom: topBar.bottom anchors.bottom: topPart.bottom
anchors.bottomMargin: units.smallSpacing anchors.bottomMargin: units.smallSpacing
anchors.left: topBar.left anchors.left: topPart.left
anchors.leftMargin: units.smallSpacing anchors.leftMargin: units.smallSpacing
anchors.right: topBar.right anchors.right: topPart.right
anchors.rightMargin: units.smallSpacing anchors.rightMargin: units.smallSpacing
Button { Image {
id: backButton source: "qrc:/qml/subsurface-mobile-icon.png"
Layout.maximumHeight: prefsButton.height Layout.maximumWidth: units.gridUnit * 2
Layout.minimumHeight: prefsButton.height
Layout.preferredWidth: units.gridUnit * 2 Layout.preferredWidth: units.gridUnit * 2
text: "\u2190" Layout.preferredHeight: units.gridUnit * 2
}
Text {
text: qsTr("Subsurface")
font.pointSize: units.fontMetrics.font.pointSize * 2
Layout.fillWidth: false
color: theme.accentTextColor
}
Item {
Layout.fillWidth: true
}
Button {
id: prefsButton
// Display back arrow or menu button
text: topPart.goBack ? "\u2190" : "\u22ee"
anchors.right: parent.right
Layout.preferredWidth: units.gridUnit * 2
Layout.preferredHeight: parent.height
style: ButtonStyle { style: ButtonStyle {
background: Rectangle { background: Rectangle {
color: theme.accentColor
implicitWidth: units.gridUnit * 2 implicitWidth: units.gridUnit * 2
color: theme.accentColor
} }
label: Text { label: Text {
id: txt id: txt
color: theme.accentTextColor color: theme.accentTextColor
font.pointSize: 18 font.pointSize: units.fontMetrics.font.pointSize * 2
font.bold: true font.bold: true
text: control.text text: control.text
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
@ -42,26 +61,14 @@ Rectangle {
} }
} }
onClicked: { onClicked: {
if (stackView.currentItem.objectName == "DiveDetails") if (topPart.goBack) {
{ stackView.pop()
manager.commitChanges( } else {
dive_id, prefsMenu.popup()
suit,
buddy,
divemaster,
notes
)
} }
stackView.pop();
} }
} }
Text {
text: qsTr("Subsurface mobile")
font.pointSize: 18
color: theme.accentTextColor
anchors.left: backButton.right
anchors.leftMargin: units.smallSpacing
//horizontalAlignment: Text.AlignHCenter
}
} }
} }

View file

@ -17,6 +17,9 @@ ApplicationWindow {
Theme.Units { Theme.Units {
id: units id: units
property int titlePointSize: fontMetrics.font.pointSize * 1.5
} }
Theme.Theme { Theme.Theme {
@ -81,105 +84,58 @@ ApplicationWindow {
} }
} }
StackView { ColumnLayout {
id: stackView
anchors.fill: parent anchors.fill: parent
focus: true
Keys.onReleased: if (event.key == Qt.Key_Back && stackView.depth > 1) {
stackView.pop()
event.accepted = true;
}
initialItem: Item {
width: parent.width
height: parent.height
ColumnLayout { TopBar {
id: awLayout
anchors.fill: parent }
spacing: units.gridUnit / 2
Rectangle { StackView {
id: topPart id: stackView
color: theme.accentColor Layout.preferredWidth: parent.width
Layout.minimumHeight: units.gridUnit * 2 + units.smallSpacing * 2 Layout.fillHeight: true
Layout.fillWidth: true focus: true
Layout.margins: 0 Keys.onReleased: if (event.key == Qt.Key_Back && stackView.depth > 1) {
RowLayout { stackView.pop()
anchors.bottom: topPart.bottom event.accepted = true;
anchors.bottomMargin: units.smallSpacing }
anchors.left: topPart.left initialItem: Item {
anchors.leftMargin: units.smallSpacing width: parent.width
anchors.right: topPart.right height: parent.height
anchors.rightMargin: units.smallSpacing
Image { ColumnLayout {
source: "qrc:/qml/subsurface-mobile-icon.png" id: awLayout
Layout.maximumWidth: units.gridUnit * 2 anchors.fill: parent
Layout.preferredWidth: units.gridUnit * 2 spacing: units.gridUnit / 2
Layout.preferredHeight: units.gridUnit * 2
Rectangle {
id: detailsPage
Layout.fillHeight: true
Layout.fillWidth: true
DiveList {
anchors.fill: detailsPage
id: diveDetails
color: theme.backgroundColor
} }
}
Rectangle {
id: messageArea
height: childrenRect.height
Layout.fillWidth: true
Text { Text {
text: qsTr("Subsurface mobile") id: message
font.pointSize: 18 color: theme.textColor
Layout.fillWidth: false text: ""
color: theme.accentTextColor styleColor: theme.textColor
font.pointSize: 10
} }
Item {
Layout.fillWidth: true
}
Button {
id: prefsButton
text: "\u22ee"
anchors.right: parent.right
Layout.preferredWidth: units.gridUnit * 2
Layout.preferredHeight: units.gridUnit * 2
style: ButtonStyle {
background: Rectangle {
implicitWidth: units.gridUnit * 2
color: theme.accentColor
}
label: Text {
id: txt
color: theme.accentTextColor
font.pointSize: 18
font.bold: true
text: control.text
horizontalAlignment: Text.AlignHCenter
}
}
onClicked: {
prefsMenu.popup()
}
}
} }
} }
Rectangle {
id: detailsPage
Layout.fillHeight: true
Layout.fillWidth: true
DiveList {
anchors.fill: detailsPage
id: diveDetails
color: theme.backgroundColor
}
}
Rectangle {
id: messageArea
height: childrenRect.height
Layout.fillWidth: true
Text {
id: message
color: theme.textColor
text: ""
styleColor: theme.textColor
font.pointSize: 10
}
}
} }
} }
} }