Unify look of scrolling setting page

* Add frame on desktop
* Remove frame on mobile
* Use actions.main when needed on mobile
* Don't push a new setting page on mobile
This commit is contained in:
Carl Schwan
2021-06-17 12:57:58 +02:00
parent 6487ea7414
commit d7345ee4e6
6 changed files with 267 additions and 148 deletions

View File

@@ -11,49 +11,91 @@ import org.kde.kirigami 2.15 as Kirigami
import org.kde.neochat 1.0 import org.kde.neochat 1.0
import NeoChat.Dialog 1.0 import NeoChat.Dialog 1.0
Kirigami.ScrollablePage { Kirigami.Page {
title: i18n("Accounts") title: i18n("Accounts")
ListView { leftPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
model: AccountListModel { } topPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
delegate: Kirigami.SwipeListItem { bottomPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
leftPadding: 0 rightPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
rightPadding: 0
action: Kirigami.Action {
onTriggered: Controller.activeConnection = model.connection
}
Kirigami.BasicListItem {
anchors.top: parent.top
anchors.bottom: parent.bottom
text: model.user.displayName actions.main: Kirigami.Action {
subtitle: model.user.id text: i18n("Add an account")
icon: model.user.avatarMediaId ? ("image://mxc/" + model.user.avatarMediaId) : "im-user" icon.name: "list-add-user"
onTriggered: pageStack.layers.push("qrc:/imports/NeoChat/Page/WelcomePage.qml")
visible: !pageSettingStack.wideMode
}
onClicked: { ColumnLayout {
Controller.activeConnection = model.connection anchors.fill: parent
pageStack.layers.pop()
} Connections {
} target: pageSettingStack
actions: [ onWideModeChanged: scroll.background.visible = pageSettingStack.wideMode
Kirigami.Action { }
text: i18n("Edit this account")
iconName: "document-edit" Controls.ScrollView {
onTriggered: { id: scroll
userEditSheet.connection = model.connection Component.onCompleted: background.visible = pageSettingStack.wideMode
userEditSheet.open()
Layout.fillWidth: true
Layout.fillHeight: true
ListView {
clip: true
model: AccountListModel { }
delegate: Kirigami.SwipeListItem {
leftPadding: 0
rightPadding: 0
action: Kirigami.Action {
onTriggered: Controller.activeConnection = model.connection
} }
}, Kirigami.BasicListItem {
Kirigami.Action { anchors.top: parent.top
text: i18n("Logout") anchors.bottom: parent.bottom
iconName: "im-kick-user"
onTriggered: { text: model.user.displayName
Controller.logout(model.connection, true) subtitle: model.user.id
if(Controller.accountCount === 1) icon: model.user.avatarMediaId ? ("image://mxc/" + model.user.avatarMediaId) : "im-user"
onClicked: {
Controller.activeConnection = model.connection
pageStack.layers.pop() pageStack.layers.pop()
}
} }
actions: [
Kirigami.Action {
text: i18n("Edit this account")
iconName: "document-edit"
onTriggered: {
userEditSheet.connection = model.connection
userEditSheet.open()
}
},
Kirigami.Action {
text: i18n("Logout")
iconName: "im-kick-user"
onTriggered: {
Controller.logout(model.connection, true)
if(Controller.accountCount === 1)
pageStack.layers.pop()
}
}
]
} }
] }
}
RowLayout {
Item {
Layout.fillWidth: true
}
Controls.Button {
visible: pageSettingStack.wideMode
text: i18n("Add an account")
icon.name: "list-add-user"
onClicked: pageStack.layers.push("qrc:/imports/NeoChat/Page/WelcomePage.qml")
}
} }
} }
@@ -73,12 +115,6 @@ Kirigami.ScrollablePage {
} }
} }
actions.main: Kirigami.Action {
text: i18n("Add an account")
iconName: "list-add-user"
onTriggered: pageStack.layers.push("qrc:/imports/NeoChat/Page/WelcomePage.qml")
}
Component { Component {
id: openFileDialog id: openFileDialog

View File

@@ -9,43 +9,74 @@ import org.kde.kirigami 2.15 as Kirigami
import org.kde.neochat 1.0 import org.kde.neochat 1.0
Kirigami.ScrollablePage { Kirigami.Page {
title: i18n("Devices") title: i18n("Devices")
ListView { leftPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
model: DevicesModel { topPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
id: devices bottomPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
} rightPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
delegate: Kirigami.SwipeListItem {
leftPadding: 0
rightPadding: 0
Kirigami.BasicListItem {
anchors.top: parent.top
anchors.bottom: parent.bottom
text: model.displayName ColumnLayout {
subtitle: model.id anchors.fill: parent
icon: "network-connect"
} Connections {
actions: [ target: pageSettingStack
Kirigami.Action { onWideModeChanged: scroll.background.visible = pageSettingStack.wideMode
text: i18n("Edit device name") }
iconName: "document-edit"
onTriggered: { Controls.ScrollView {
renameSheet.index = model.index id: scroll
renameSheet.name = model.displayName Component.onCompleted: background.visible = pageSettingStack.wideMode
renameSheet.open() Layout.fillWidth: true
} Layout.fillHeight: true
}, ListView {
Kirigami.Action { clip: true
text: i18n("Logout device") model: DevicesModel {
iconName: "edit-delete-remove" id: devices
onTriggered: { }
passwordSheet.index = index
passwordSheet.open() Kirigami.PlaceholderMessage {
visible: parent.model.count === 0 // We can assume 0 means loading since there is at least one device
anchors.centerIn: parent
text: i18n("Loading")
Controls.BusyIndicator {
running: parent.visible
} }
} }
]
delegate: Kirigami.SwipeListItem {
leftPadding: 0
rightPadding: 0
Kirigami.BasicListItem {
anchors.top: parent.top
anchors.bottom: parent.bottom
text: model.displayName
subtitle: model.id
icon: "network-connect"
}
actions: [
Kirigami.Action {
text: i18n("Edit device name")
iconName: "document-edit"
onTriggered: {
renameSheet.index = model.index
renameSheet.name = model.displayName
renameSheet.open()
}
},
Kirigami.Action {
text: i18n("Logout device")
iconName: "edit-delete-remove"
onTriggered: {
passwordSheet.index = index
passwordSheet.open()
}
}
]
}
}
} }
} }

View File

@@ -17,6 +17,8 @@ import NeoChat.Menu 1.0
Kirigami.ScrollablePage { Kirigami.ScrollablePage {
id: page id: page
title: i18n("Rooms")
property var enteredRoom property var enteredRoom
property bool collapsedMode: Config.roomListPageWidth === applicationWindow().collapsedPageWidth && applicationWindow().shouldUseSidebars property bool collapsedMode: Config.roomListPageWidth === applicationWindow().collapsedPageWidth && applicationWindow().shouldUseSidebars

View File

@@ -36,7 +36,9 @@ Kirigami.ScrollablePage {
topPadding: 0 topPadding: 0
Kirigami.Theme.colorSet: Kirigami.Theme.View Kirigami.Theme.colorSet: Kirigami.Theme.View
ListView { ListView {
Component.onCompleted: actions[0].trigger(); Component.onCompleted: if (pageSettingStack.wideMode) {
actions[0].trigger();
}
property list<Kirigami.Action> actions: [ property list<Kirigami.Action> actions: [
Kirigami.Action { Kirigami.Action {
text: i18n("General") text: i18n("General")
@@ -58,6 +60,11 @@ Kirigami.ScrollablePage {
icon.name: "preferences-desktop-emoticons" icon.name: "preferences-desktop-emoticons"
onTriggered: pageSettingStack.push("qrc:/imports/NeoChat/Settings/Emoticons.qml") onTriggered: pageSettingStack.push("qrc:/imports/NeoChat/Settings/Emoticons.qml")
}, },
Kirigami.Action {
text: i18n("Devices")
iconName: "network-connect"
onTriggered: pageSettingStack.push("qrc:/imports/NeoChat/Page/DevicesPage.qml")
},
Kirigami.Action { Kirigami.Action {
text: i18n("About NeoChat") text: i18n("About NeoChat")
icon.name: "help-about" icon.name: "help-about"

View File

@@ -13,7 +13,92 @@ import NeoChat.Settings 1.0
import NeoChat.Component 1.0 as Components import NeoChat.Component 1.0 as Components
import NeoChat.Dialog 1.0 import NeoChat.Dialog 1.0
Kirigami.ScrollablePage { Kirigami.Page {
leftPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
topPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
bottomPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
rightPadding: pageSettingStack.wideMode ? Kirigami.Units.gridUnit : 0
ColumnLayout {
id: column
anchors.fill: parent
Connections {
target: pageSettingStack
onWideModeChanged: scroll.background.visible = pageSettingStack.wideMode
}
QQC2.ScrollView {
id: scroll
Component.onCompleted: background.visible = pageSettingStack.wideMode
Layout.fillWidth: true
Layout.fillHeight: true
ListView {
clip: true
model: CustomEmojiModel {
id: emojiModel
connection: Controller.activeConnection
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
text: i18n("No custom inline stickers found")
visible: parent.model.count === 0
}
delegate: Kirigami.BasicListItem {
id: del
required property string name
required property url imageURL
text: name
reserveSpaceForSubtitle: true
leading: Image {
width: height
sourceSize.width: width
sourceSize.height: height
source: imageURL
Rectangle {
anchors.fill: parent
visible: parent.status === Image.Loading
radius: height/2
gradient: Components.ShimmerGradient { }
}
}
trailing: QQC2.ToolButton {
width: height
icon.name: "delete"
onClicked: emojiModel.removeEmoji(del.name)
}
}
}
}
Loader {
active: pageSettingStack.wideMode
sourceComponent: addEmojiComponent
Layout.fillWidth: true
}
}
footer: QQC2.ToolBar {
id: toolbar
width: parent.width
visible: !pageSettingStack.wideMode
height: visible ? implicitHeight : 0
contentItem: Loader {
active: !pageSettingStack.wideMode
sourceComponent: addEmojiComponent
}
}
Component { Component {
id: openFileDialog id: openFileDialog
@@ -22,83 +107,47 @@ Kirigami.ScrollablePage {
} }
} }
ListView { property Component addEmojiComponent: RowLayout {
header: QQC2.ToolBar { Item {
width: parent.width Layout.fillWidth: Qt.application.layoutDirection == Qt.LeftToRight
contentItem: RowLayout { }
Item {
Layout.fillWidth: Qt.application.layoutDirection == Qt.LeftToRight
}
QQC2.TextField {
id: emojiField
placeholderText: i18n("new_emoji_name_here")
validator: RegularExpressionValidator { QQC2.TextField {
regularExpression: /[a-zA-Z_0-9]*/ id: emojiField
} placeholderText: i18n("new_emoji_name_here")
}
QQC2.Button {
text: i18n("Add Emoji...")
enabled: emojiField.text != "" validator: RegularExpressionValidator {
property var fileDialog: null regularExpression: /[a-zA-Z_0-9]*/
onClicked: {
if (this.fileDialog != null) {
return;
}
this.fileDialog = openFileDialog.createObject(QQC2.Overlay.overlay)
this.fileDialog.chosen.connect((url) => {
emojiModel.addEmoji(emojiField.text, url)
this.fileDialog = null
})
this.fileDialog.onRejected.connect(() => {
rej()
this.fileDialog = null
})
this.fileDialog.open()
}
}
Item {
Layout.fillWidth: Qt.application.layoutDirection == Qt.RightToLeft
}
} }
} }
model: CustomEmojiModel {
id: emojiModel
connection: Controller.activeConnection QQC2.Button {
} text: i18n("Add Emoji...")
delegate: Kirigami.BasicListItem {
id: del
required property string name enabled: emojiField.text != ""
required property url imageURL property var fileDialog: null
text: name onClicked: {
reserveSpaceForSubtitle: true if (this.fileDialog != null) {
return;
leading: Image {
width: height
sourceSize.width: width
sourceSize.height: height
source: imageURL
Rectangle {
anchors.fill: parent
visible: parent.status === Image.Loading
radius: height/2
gradient: Components.ShimmerGradient { }
} }
}
trailing: QQC2.ToolButton { this.fileDialog = openFileDialog.createObject(QQC2.Overlay.overlay)
width: height
icon.name: "delete" this.fileDialog.chosen.connect((url) => {
onClicked: emojiModel.removeEmoji(del.name) emojiModel.addEmoji(emojiField.text, url)
this.fileDialog = null
})
this.fileDialog.onRejected.connect(() => {
rej()
this.fileDialog = null
})
this.fileDialog.open()
} }
} }
Item {
Layout.fillWidth: Qt.application.layoutDirection == Qt.RightToLeft
}
} }
} }

View File

@@ -258,12 +258,6 @@ Kirigami.ApplicationWindow {
shortcut: StandardKey.New shortcut: StandardKey.New
enabled: pageStack.layers.currentItem.title !== i18n("Start a Chat") && Controller.accountCount > 0 enabled: pageStack.layers.currentItem.title !== i18n("Start a Chat") && Controller.accountCount > 0
}, },
Kirigami.Action {
text: i18n("Devices")
iconName: "network-connect"
onTriggered: pushReplaceLayer("qrc:/imports/NeoChat/Page/DevicesPage.qml")
enabled: pageStack.layers.currentItem.title !== i18n("Devices") && Controller.accountCount > 0
},
Kirigami.Action { Kirigami.Action {
text: i18n("Settings") text: i18n("Settings")
icon.name: "settings-configure" icon.name: "settings-configure"