Change SwipeView to StackView and clean code.
This commit is contained in:
@@ -7,7 +7,6 @@ import Qt.labs.settings 1.0
|
||||
import "qrc:/qml/component"
|
||||
|
||||
Page {
|
||||
property var window
|
||||
property var controller
|
||||
|
||||
property alias homeserver: settings.server
|
||||
|
||||
@@ -4,7 +4,7 @@ import QtQuick.Layouts 1.3
|
||||
import QtQuick.Controls.Material 2.3
|
||||
|
||||
Item {
|
||||
property int index
|
||||
property Item page
|
||||
property alias contentItem: itemDelegate.contentItem
|
||||
signal clicked
|
||||
|
||||
@@ -14,13 +14,13 @@ Item {
|
||||
Layout.preferredHeight: width
|
||||
|
||||
Rectangle {
|
||||
width: swipeView.currentIndex === index ? parent.width : 0
|
||||
width: stackView.currentItem === page ? parent.width : 0
|
||||
height: parent.height
|
||||
anchors.bottom: itemDelegate.bottom
|
||||
color: Qt.lighter(Material.accent)
|
||||
|
||||
Behavior on width {
|
||||
PropertyAnimation { easing.type: Easing.InOutQuad; duration: 200 }
|
||||
PropertyAnimation { easing.type: Easing.InOutCubic; duration: 200 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,14 @@ Item {
|
||||
anchors.fill: parent
|
||||
|
||||
onClicked: {
|
||||
swipeView.currentIndex = index
|
||||
if(page != null) {
|
||||
if(stackView.depth === 1) {
|
||||
stackView.replace(page)
|
||||
} else {
|
||||
stackView.clear()
|
||||
stackView.push(page)
|
||||
}
|
||||
}
|
||||
buttonDelegate.clicked()
|
||||
}
|
||||
}
|
||||
|
||||
56
qml/main.qml
56
qml/main.qml
@@ -42,14 +42,17 @@ ApplicationWindow {
|
||||
spacing: 0
|
||||
|
||||
ButtonDelegate {
|
||||
index: 0
|
||||
|
||||
contentItem: ImageStatus {
|
||||
width: parent.width
|
||||
height: parent.width
|
||||
source: "qrc:/asset/img/avatar.png"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
page: Room {
|
||||
id: roomPage
|
||||
roomListModel: controller.roomListModel
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
@@ -58,8 +61,6 @@ ApplicationWindow {
|
||||
}
|
||||
|
||||
ButtonDelegate {
|
||||
index: 1
|
||||
|
||||
contentItem: Text {
|
||||
text: "\ue853"
|
||||
font.pointSize: 16
|
||||
@@ -68,24 +69,14 @@ ApplicationWindow {
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
page: Login {
|
||||
id: loginPage
|
||||
controller: controller
|
||||
}
|
||||
}
|
||||
|
||||
// ButtonDelegate {
|
||||
// index: 2
|
||||
|
||||
// contentItem: Text {
|
||||
// text: "\ue5d2"
|
||||
// font.pointSize: 16
|
||||
// font.family: materialFont.name
|
||||
// color: "white"
|
||||
// horizontalAlignment: Text.AlignHCenter
|
||||
// verticalAlignment: Text.AlignVCenter
|
||||
// }
|
||||
// }
|
||||
|
||||
ButtonDelegate {
|
||||
index: 2
|
||||
|
||||
contentItem: Text {
|
||||
text: "\ue8b8"
|
||||
font.pointSize: 16
|
||||
@@ -94,11 +85,13 @@ ApplicationWindow {
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
page: Setting {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ButtonDelegate {
|
||||
index: 3
|
||||
|
||||
contentItem: Text {
|
||||
text: "\ue879"
|
||||
font.pointSize: 16
|
||||
@@ -113,25 +106,10 @@ ApplicationWindow {
|
||||
}
|
||||
}
|
||||
|
||||
SwipeView {
|
||||
id: swipeView
|
||||
StackView {
|
||||
id: stackView
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: sideNav.width
|
||||
interactive: false
|
||||
orientation: Qt.Vertical
|
||||
|
||||
Room {
|
||||
roomListModel: controller.roomListModel
|
||||
}
|
||||
|
||||
Login {
|
||||
id: loginPage
|
||||
window: window
|
||||
controller: controller
|
||||
}
|
||||
|
||||
Setting {
|
||||
|
||||
}
|
||||
initialItem: roomPage
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user