Refactor room list in multiple sub components
Also modernize the codebase where possible (e.g use required properties, reorder properties, fix warnings, don't use Action when not needed) Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This commit is contained in:
45
src/qml/Page/RoomList/AccountMenu.qml
Normal file
45
src/qml/Page/RoomList/AccountMenu.qml
Normal file
@@ -0,0 +1,45 @@
|
||||
// SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.19 as Kirigami
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
import '../Dialog' as Dialog
|
||||
|
||||
QQC2.Menu {
|
||||
id: root
|
||||
margins: Kirigami.Units.smallSpacing
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Edit this account")
|
||||
icon.name: "document-edit"
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/AccountEditorPage.qml", {
|
||||
connection: Controller.activeConnection
|
||||
}, {
|
||||
title: i18n("Account editor")
|
||||
});
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Notification settings")
|
||||
icon.name: "notifications"
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {defaultPage: "notifications"}, { title: i18n("Configure")})
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Devices")
|
||||
icon.name: "computer-symbolic"
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {defaultPage: "devices"}, { title: i18n("Configure")})
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Logout")
|
||||
icon.name: "list-remove-user"
|
||||
onTriggered: confirmLogoutDialog.open()
|
||||
}
|
||||
|
||||
Dialog.ConfirmLogoutDialog {
|
||||
id: confirmLogoutDialog
|
||||
}
|
||||
}
|
||||
53
src/qml/Page/RoomList/CollapsedRoomDelegate.qml
Normal file
53
src/qml/Page/RoomList/CollapsedRoomDelegate.qml
Normal file
@@ -0,0 +1,53 @@
|
||||
// SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQml.Models 2.15
|
||||
|
||||
import org.kde.kirigami 2.15 as Kirigami
|
||||
import org.kde.kitemmodels 1.0
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
import './' as RoomList
|
||||
|
||||
QQC2.ItemDelegate {
|
||||
id: root
|
||||
|
||||
required property var currentRoom
|
||||
required property bool categoryVisible
|
||||
required property string filterText
|
||||
required property string avatar
|
||||
required property string name
|
||||
|
||||
topPadding: Kirigami.Units.largeSpacing
|
||||
leftPadding: Kirigami.Units.largeSpacing
|
||||
rightPadding: Kirigami.Units.largeSpacing
|
||||
bottomPadding: Kirigami.Units.largeSpacing
|
||||
|
||||
width: ListView.view.width
|
||||
height: visible ? ListView.view.width : 0
|
||||
|
||||
visible: root.categoryVisible || filterText.length > 0 || Config.mergeRoomList
|
||||
|
||||
contentItem: Kirigami.Avatar {
|
||||
source: root.avatar ? `image://mxc/${root.avatar}` : ""
|
||||
name: root.name || i18n("No Name")
|
||||
|
||||
sourceSize {
|
||||
width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
||||
height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: RoomManager.enterRoom(root.currentRoom)
|
||||
|
||||
Keys.onEnterPressed: RoomManager.enterRoom(root.currentRoom)
|
||||
Keys.onReturnPressed: RoomManager.enterRoom(root.currentRoom)
|
||||
|
||||
QQC2.ToolTip.visible: text.length > 0 && hovered
|
||||
QQC2.ToolTip.text: root.name ?? ""
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
}
|
||||
232
src/qml/Page/RoomList/ContextMenu.qml
Normal file
232
src/qml/Page/RoomList/ContextMenu.qml
Normal file
@@ -0,0 +1,232 @@
|
||||
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
|
||||
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.19 as Kirigami
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
/**
|
||||
* Context menu when clicking on a room in the room list
|
||||
*/
|
||||
Loader {
|
||||
id: root
|
||||
property var room
|
||||
signal closed()
|
||||
|
||||
Component {
|
||||
id: regularMenu
|
||||
QQC2.Menu {
|
||||
QQC2.MenuItem {
|
||||
id: newWindow
|
||||
text: i18n("Open in New Window")
|
||||
icon.name: "window-new"
|
||||
onTriggered: RoomManager.openWindow(room);
|
||||
visible: !Kirigami.Settings.isMobile
|
||||
}
|
||||
|
||||
QQC2.MenuSeparator {
|
||||
visible: newWindow.visible
|
||||
}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: room.isFavourite ? i18n("Remove from Favourites") : i18n("Add to Favourites")
|
||||
icon.name: room.isFavourite ? "bookmark-remove" : "bookmark-new"
|
||||
onTriggered: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", 1.0)
|
||||
}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: room.isLowPriority ? i18n("Reprioritize") : i18n("Deprioritize")
|
||||
icon.name: room.isLowPriority ? "arrow-up" : "arrow-down"
|
||||
onTriggered: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", 1.0)
|
||||
}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Mark as Read")
|
||||
icon.name: "checkmark"
|
||||
onTriggered: room.markAllMessagesAsRead()
|
||||
}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: room.isDirectChat() ? i18nc("@action:inmenu", "Copy user's Matrix ID to Clipboard") : i18nc("@action:inmenu", "Copy Address to Clipboard")
|
||||
icon.name: "edit-copy"
|
||||
onTriggered: if (room.isDirectChat()) {
|
||||
Clipboard.saveText(room.directChatRemoteUser.id)
|
||||
} else if (room.canonicalAlias.length === 0) {
|
||||
Clipboard.saveText(room.id)
|
||||
} else {
|
||||
Clipboard.saveText(room.canonicalAlias)
|
||||
}
|
||||
}
|
||||
|
||||
QQC2.Menu {
|
||||
title: i18n("Notification State")
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Follow Global Setting")
|
||||
icon.name: "globe"
|
||||
checkable: true
|
||||
autoExclusive: true
|
||||
checked: room.pushNotificationState === PushNotificationState.Default
|
||||
enabled: room.pushNotificationState != PushNotificationState.Unknown
|
||||
onTriggered: {
|
||||
room.pushNotificationState = PushNotificationState.Default
|
||||
}
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("As in 'notify for all messages'","All")
|
||||
icon.name: "notifications"
|
||||
checkable: true
|
||||
autoExclusive: true
|
||||
checked: room.pushNotificationState === PushNotificationState.All
|
||||
enabled: room.pushNotificationState != PushNotificationState.Unknown
|
||||
onTriggered: {
|
||||
room.pushNotificationState = PushNotificationState.All
|
||||
}
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("As in 'notify when the user is mentioned or the message contains a set keyword'","@Mentions and Keywords")
|
||||
icon.name: "im-user"
|
||||
checkable: true
|
||||
autoExclusive: true
|
||||
checked: room.pushNotificationState === PushNotificationState.MentionKeyword
|
||||
enabled: room.pushNotificationState != PushNotificationState.Unknown
|
||||
onTriggered: {
|
||||
room.pushNotificationState = PushNotificationState.MentionKeyword
|
||||
}
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("As in 'do not notify for any messages'","Off")
|
||||
icon.name: "notifications-disabled"
|
||||
checkable: true
|
||||
autoExclusive: true
|
||||
checked: room.pushNotificationState === PushNotificationState.Mute
|
||||
enabled: room.pushNotificationState != PushNotificationState.Unknown
|
||||
onTriggered: {
|
||||
room.pushNotificationState = PushNotificationState.Mute
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Room Settings")
|
||||
icon.name: "configure"
|
||||
onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Room Settings") })
|
||||
}
|
||||
|
||||
QQC2.MenuSeparator {}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Leave Room")
|
||||
icon.name: "go-previous"
|
||||
onTriggered: RoomManager.leaveRoom(room)
|
||||
}
|
||||
|
||||
onClosed: {
|
||||
root.closed()
|
||||
destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: mobileMenu
|
||||
|
||||
Kirigami.OverlayDrawer {
|
||||
id: drawer
|
||||
height: popupContent.implicitHeight
|
||||
edge: Qt.BottomEdge
|
||||
padding: 0
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
bottomPadding: 0
|
||||
topPadding: 0
|
||||
|
||||
parent: applicationWindow().overlay
|
||||
|
||||
ColumnLayout {
|
||||
id: popupContent
|
||||
width: parent.width
|
||||
spacing: 0
|
||||
RowLayout {
|
||||
id: headerLayout
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: Kirigami.Units.largeSpacing
|
||||
spacing: Kirigami.Units.largeSpacing
|
||||
Kirigami.Avatar {
|
||||
id: avatar
|
||||
source: room.avatarMediaId ? ("image://mxc/" + room.avatarMediaId) : ""
|
||||
name: room.displayName
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 3
|
||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
|
||||
Layout.alignment: Qt.AlignTop
|
||||
}
|
||||
Kirigami.Heading {
|
||||
level: 5
|
||||
Layout.fillWidth: true
|
||||
text: room.displayName
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
QQC2.ToolButton {
|
||||
checked: room.isFavourite
|
||||
checkable: true
|
||||
icon.name: 'favorite'
|
||||
Accessible.name: room.isFavourite ? i18n("Remove from Favourites") : i18n("Add to Favourites")
|
||||
onClicked: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", 1.0)
|
||||
}
|
||||
|
||||
QQC2.ToolButton {
|
||||
icon.name: 'settings-configure'
|
||||
onClicked: {
|
||||
QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Room Settings") })
|
||||
drawer.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kirigami.BasicListItem {
|
||||
text: room.isLowPriority ? i18n("Reprioritize") : i18n("Deprioritize")
|
||||
icon: room.isLowPriority ? "arrow-up" : "arrow-down"
|
||||
onClicked: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", 1.0)
|
||||
implicitHeight: visible ? Kirigami.Units.gridUnit * 3 : 0
|
||||
}
|
||||
|
||||
Kirigami.BasicListItem {
|
||||
text: i18n("Mark as Read")
|
||||
icon: "checkmark"
|
||||
onClicked: room.markAllMessagesAsRead()
|
||||
implicitHeight: visible ? Kirigami.Units.gridUnit * 3 : 0
|
||||
}
|
||||
Kirigami.BasicListItem {
|
||||
text: i18n("Leave Room")
|
||||
icon: "go-previous"
|
||||
onClicked: {
|
||||
RoomManager.leaveRoom(room)
|
||||
drawer.close()
|
||||
}
|
||||
implicitHeight: visible ? Kirigami.Units.gridUnit * 3 : 0
|
||||
}
|
||||
}
|
||||
onClosed: root.closed()
|
||||
}
|
||||
}
|
||||
|
||||
asynchronous: true
|
||||
sourceComponent: Kirigami.Settings.isMobile ? mobileMenu : regularMenu
|
||||
|
||||
function open() {
|
||||
active = true;
|
||||
}
|
||||
|
||||
onStatusChanged: if (status == Loader.Ready) {
|
||||
if (Kirigami.Settings.isMobile) {
|
||||
item.open();
|
||||
} else {
|
||||
item.popup();
|
||||
}
|
||||
}
|
||||
}
|
||||
129
src/qml/Page/RoomList/ExploreComponent.qml
Normal file
129
src/qml/Page/RoomList/ExploreComponent.qml
Normal file
@@ -0,0 +1,129 @@
|
||||
// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.15 as Kirigami
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
QQC2.ToolBar {
|
||||
id: root
|
||||
|
||||
property var desiredWidth
|
||||
property bool collapsed: false
|
||||
|
||||
property Kirigami.Action exploreAction: Kirigami.Action {
|
||||
text: i18n("Explore rooms")
|
||||
icon.name: "compass"
|
||||
onTriggered: {
|
||||
applicationWindow().pushReplaceLayer("qrc:/JoinRoomPage.qml", {connection: Controller.activeConnection})
|
||||
}
|
||||
}
|
||||
property Kirigami.Action chatAction: Kirigami.Action {
|
||||
text: i18n("Start a Chat")
|
||||
icon.name: "irc-join-channel"
|
||||
onTriggered: applicationWindow().pushReplaceLayer("qrc:/StartChatPage.qml", {connection: Controller.activeConnection})
|
||||
}
|
||||
property Kirigami.Action roomAction: Kirigami.Action {
|
||||
text: i18n("Create a Room")
|
||||
icon.name: "irc-join-channel"
|
||||
onTriggered: {
|
||||
let dialog = createRoomDialog.createObject(root.overlay);
|
||||
dialog.open();
|
||||
}
|
||||
shortcut: StandardKey.New
|
||||
}
|
||||
|
||||
padding: 0
|
||||
|
||||
RowLayout {
|
||||
id: row
|
||||
Kirigami.SearchField {
|
||||
Layout.topMargin: Kirigami.Units.smallSpacing
|
||||
Layout.bottomMargin: Kirigami.Units.smallSpacing
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredWidth: root.desiredWidth ? root.desiredWidth - menuButton.width - row.spacing : -1
|
||||
visible: !root.collapsed
|
||||
onTextChanged: sortFilterRoomListModel.filterText = text
|
||||
KeyNavigation.tab: listView
|
||||
}
|
||||
QQC2.ToolButton {
|
||||
id: menuButton
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
checkable: true
|
||||
action: Kirigami.Action {
|
||||
text: i18n("Create rooms and chats")
|
||||
icon.name: "irc-join-channel"
|
||||
onTriggered: {
|
||||
if (Kirigami.isMobile) {
|
||||
let menu = mobileMenu.createObject();
|
||||
menu.open();
|
||||
} else {
|
||||
let menu = desktopMenu.createObject(menuButton, {y: menuButton.height});
|
||||
menu.closed.connect(menuButton.toggle)
|
||||
menu.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
QQC2.ToolTip {
|
||||
text: parent.text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: desktopMenu
|
||||
QQC2.Menu {
|
||||
QQC2.MenuItem {
|
||||
action: exploreAction
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
action: chatAction
|
||||
}
|
||||
QQC2.MenuItem {
|
||||
action: roomAction
|
||||
}
|
||||
}
|
||||
}
|
||||
Component {
|
||||
id: mobileMenu
|
||||
|
||||
Kirigami.OverlayDrawer {
|
||||
id: menuRoot
|
||||
edge: Qt.BottomEdge
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
bottomPadding: 0
|
||||
topPadding: 0
|
||||
|
||||
parent: applicationWindow().overlay
|
||||
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
spacing: 0
|
||||
|
||||
Kirigami.ListSectionHeader {
|
||||
label: i18n("Create rooms and chats")
|
||||
}
|
||||
Kirigami.BasicListItem {
|
||||
implicitHeight: Kirigami.Units.gridUnit * 3
|
||||
action: exploreAction
|
||||
onClicked: menuRoot.close()
|
||||
}
|
||||
Kirigami.BasicListItem {
|
||||
implicitHeight: Kirigami.Units.gridUnit * 3
|
||||
action: chatAction
|
||||
onClicked: menuRoot.close()
|
||||
}
|
||||
Kirigami.BasicListItem {
|
||||
implicitHeight: Kirigami.Units.gridUnit * 3
|
||||
action: roomAction
|
||||
onClicked: menuRoot.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
301
src/qml/Page/RoomList/Page.qml
Normal file
301
src/qml/Page/RoomList/Page.qml
Normal file
@@ -0,0 +1,301 @@
|
||||
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
|
||||
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQml.Models 2.15
|
||||
|
||||
import org.kde.kirigami 2.15 as Kirigami
|
||||
import org.kde.kitemmodels 1.0
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
import './' as RoomList
|
||||
|
||||
Kirigami.ScrollablePage {
|
||||
id: root
|
||||
|
||||
/**
|
||||
* @brief The current width of the room list.
|
||||
*
|
||||
* @note Other objects can access the value but the private function makes sure
|
||||
* that only the internal members can modify it.
|
||||
*/
|
||||
readonly property int currentWidth: _private.currentWidth
|
||||
|
||||
readonly property RoomListModel roomListModel: RoomListModel {
|
||||
connection: Controller.activeConnection
|
||||
}
|
||||
|
||||
readonly property bool collapsed: Config.collapsed
|
||||
|
||||
property var enteredRoom: null
|
||||
|
||||
onCollapsedChanged: if (collapsed) {
|
||||
sortFilterRoomListModel.filterText = "";
|
||||
}
|
||||
|
||||
header: ColumnLayout {
|
||||
visible: !root.collapsed
|
||||
spacing: 0
|
||||
|
||||
RoomList.SpaceListView {
|
||||
roomListModel: root.roomListModel
|
||||
}
|
||||
|
||||
Kirigami.Separator {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Component {
|
||||
id: spaceListContextMenu
|
||||
SpaceListContextMenu {}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: RoomManager
|
||||
function onCurrentRoomChanged() {
|
||||
itemSelection.setCurrentIndex(roomListModel.index(roomListModel.indexForRoom(RoomManager.currentRoom), 0), ItemSelectionModel.SelectCurrent)
|
||||
}
|
||||
}
|
||||
|
||||
function goToNextRoomFiltered(condition) {
|
||||
let index = listView.currentIndex;
|
||||
while (index++ !== listView.count - 1) {
|
||||
if (condition(listView.itemAtIndex(index))) {
|
||||
listView.currentIndex = index;
|
||||
listView.currentItem.action.trigger();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function goToPreviousRoomFiltered(condition) {
|
||||
let index = listView.currentIndex;
|
||||
while (index-- !== 0) {
|
||||
if (condition(listView.itemAtIndex(index))) {
|
||||
listView.currentIndex = index;
|
||||
listView.currentItem.action.trigger();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function goToNextRoom() {
|
||||
goToNextRoomFiltered((item) => item.visible);
|
||||
}
|
||||
|
||||
function goToPreviousRoom() {
|
||||
goToPreviousRoomFiltered((item) => item.visible);
|
||||
}
|
||||
|
||||
function goToNextUnreadRoom() {
|
||||
goToNextRoomFiltered((item) => (item.visible && item.hasUnread));
|
||||
}
|
||||
|
||||
function goToPreviousUnreadRoom() {
|
||||
goToPreviousRoomFiltered((item) => (item.visible && item.hasUnread));
|
||||
}
|
||||
|
||||
titleDelegate: ExploreComponent {
|
||||
Layout.fillWidth: true
|
||||
desiredWidth: root.width - Kirigami.Units.largeSpacing
|
||||
collapsed: root.collapsed
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
|
||||
activeFocusOnTab: true
|
||||
clip: AccountRegistry.count > 1
|
||||
|
||||
header: QQC2.ItemDelegate {
|
||||
width: visible ? ListView.view.width : 0
|
||||
height: visible ? Kirigami.Units.gridUnit * 2 : 0
|
||||
|
||||
visible: root.collapsed
|
||||
|
||||
topPadding: Kirigami.Units.largeSpacing
|
||||
leftPadding: Kirigami.Units.largeSpacing
|
||||
rightPadding: Kirigami.Units.largeSpacing
|
||||
bottomPadding: Kirigami.Units.largeSpacing
|
||||
|
||||
onClicked: quickView.item.open();
|
||||
|
||||
Kirigami.Icon {
|
||||
anchors.centerIn: parent
|
||||
width: Kirigami.Units.iconSizes.smallMedium
|
||||
height: Kirigami.Units.iconSizes.smallMedium
|
||||
source: "search"
|
||||
}
|
||||
|
||||
Kirigami.Separator {
|
||||
width: parent.width
|
||||
anchors.bottom: parent.bottom
|
||||
}
|
||||
}
|
||||
|
||||
Layout.fillWidth: true
|
||||
|
||||
Kirigami.PlaceholderMessage {
|
||||
anchors.centerIn: parent
|
||||
width: parent.width - (Kirigami.Units.largeSpacing * 4)
|
||||
visible: listView.count == 0
|
||||
text: sortFilterRoomListModel.filterText.length > 0 ? i18n("No rooms found") : i18n("Join some rooms to get started")
|
||||
helpfulAction: Kirigami.Action {
|
||||
icon.name: sortFilterRoomListModel.filterText.length > 0 ? "search" : "list-add"
|
||||
text: sortFilterRoomListModel.filterText.length > 0 ? i18n("Search in room directory") : i18n("Explore rooms")
|
||||
onTriggered: pageStack.layers.push("qrc:/JoinRoomPage.qml", {
|
||||
connection: Controller.activeConnection,
|
||||
keyword: sortFilterRoomListModel.filterText
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ItemSelectionModel {
|
||||
id: itemSelection
|
||||
model: root.roomListModel
|
||||
onCurrentChanged: listView.currentIndex = sortFilterRoomListModel.mapFromSource(current).row
|
||||
}
|
||||
|
||||
model: SortFilterRoomListModel {
|
||||
id: sortFilterRoomListModel
|
||||
|
||||
sourceModel: root.roomListModel
|
||||
roomSortOrder: Config.mergeRoomList ? SortFilterRoomListModel.LastActivity : SortFilterRoomListModel.Categories
|
||||
onLayoutChanged: {
|
||||
listView.currentIndex = sortFilterRoomListModel.mapFromSource(itemSelection.currentIndex).row
|
||||
}
|
||||
}
|
||||
|
||||
section.property: sortFilterRoomListModel.filterText.length === 0 && !Config.mergeRoomList ? "category" : null
|
||||
section.delegate: root.collapsed ? foldButton : sectionHeader
|
||||
|
||||
Component {
|
||||
id: sectionHeader
|
||||
Kirigami.ListSectionHeader {
|
||||
height: implicitHeight
|
||||
label: roomListModel.categoryName(section)
|
||||
action: Kirigami.Action {
|
||||
onTriggered: roomListModel.setCategoryVisible(section, !roomListModel.categoryVisible(section))
|
||||
}
|
||||
contentItem.children: QQC2.ToolButton {
|
||||
icon {
|
||||
name: roomListModel.categoryVisible(section) ? "go-up" : "go-down"
|
||||
width: Kirigami.Units.iconSizes.small
|
||||
height: Kirigami.Units.iconSizes.small
|
||||
}
|
||||
|
||||
onClicked: roomListModel.setCategoryVisible(section, !roomListModel.categoryVisible(section))
|
||||
}
|
||||
}
|
||||
}
|
||||
Component {
|
||||
id: foldButton
|
||||
Item {
|
||||
width: ListView.view.width
|
||||
height: visible ? width : 0
|
||||
QQC2.ToolButton {
|
||||
id: button
|
||||
anchors.centerIn: parent
|
||||
|
||||
icon {
|
||||
name: hovered ? (roomListModel.categoryVisible(section) ? "go-up" : "go-down") : roomListModel.categoryIconName(section)
|
||||
width: Kirigami.Units.iconSizes.smallMedium
|
||||
height: Kirigami.Units.iconSizes.smallMedium
|
||||
}
|
||||
|
||||
onClicked: roomListModel.setCategoryVisible(section, !roomListModel.categoryVisible(section))
|
||||
|
||||
QQC2.ToolTip.text: roomListModel.categoryName(section)
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reuseItems: true
|
||||
currentIndex: -1 // we don't want any room highlighted by default
|
||||
|
||||
delegate: root.collapsed ? collapsedModeListComponent : normalModeListComponent
|
||||
|
||||
Component {
|
||||
id: collapsedModeListComponent
|
||||
|
||||
RoomList.CollapsedRoomDelegate {
|
||||
filterText: sortFilterRoomListModel.filterText
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: normalModeListComponent
|
||||
|
||||
RoomList.RoomDelegate {
|
||||
filterText: sortFilterRoomListModel.filterText
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
footer: UserInfo {
|
||||
width: parent.width
|
||||
visible: !root.collapsed
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
parent: applicationWindow().overlay.parent
|
||||
|
||||
x: root.currentWidth - width / 2
|
||||
width: Kirigami.Units.smallSpacing * 2
|
||||
z: root.z + 1
|
||||
enabled: RoomManager.hasOpenRoom && applicationWindow().width >= Kirigami.Units.gridUnit * 35
|
||||
visible: enabled
|
||||
cursorShape: Qt.SplitHCursor
|
||||
|
||||
property int _lastX
|
||||
|
||||
onPressed: mouse => {
|
||||
_lastX = mouse.x;
|
||||
}
|
||||
onPositionChanged: mouse => {
|
||||
if (_lastX == -1) {
|
||||
return;
|
||||
}
|
||||
if (mouse.x > _lastX) {
|
||||
// we moved to the right
|
||||
if (_private.currentWidth < _private.collapseWidth && _private.currentWidth + (mouse.x - _lastX) >= _private.collapseWidth) {
|
||||
// Here we get back directly to a more wide mode.
|
||||
_private.currentWidth = _private.collapseWidth;
|
||||
Config.collapsed = false;
|
||||
} else if (_private.currentWidth >= _private.collapseWidth) {
|
||||
// Increase page width
|
||||
_private.currentWidth = Math.min(_private.defaultWidth, _private.currentWidth + (mouse.x - _lastX));
|
||||
}
|
||||
} else if (mouse.x < _lastX) {
|
||||
const tmpWidth = _private.currentWidth - (_lastX - mouse.x);
|
||||
if (tmpWidth < _private.collapseWidth) {
|
||||
_private.currentWidth = Qt.binding(() => _private.collapsedSize + (root.contentItem.QQC2.ScrollBar.vertical.visible ? root.contentItem.QQC2.ScrollBar.vertical.width : 0));
|
||||
Config.collapsed = true;
|
||||
} else {
|
||||
_private.currentWidth = tmpWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Hold the modifiable currentWidth in a private object so that only internal
|
||||
* members can modify it.
|
||||
*/
|
||||
QtObject {
|
||||
id: _private
|
||||
property int currentWidth: Config.collapsed ? collapsedSize : defaultWidth
|
||||
readonly property int defaultWidth: Kirigami.Units.gridUnit * 17
|
||||
readonly property int collapseWidth: Kirigami.Units.gridUnit * 10
|
||||
readonly property int collapsedSize: Kirigami.Units.gridUnit * 3 - Kirigami.Units.smallSpacing * 3
|
||||
}
|
||||
}
|
||||
136
src/qml/Page/RoomList/RoomDelegate.qml
Normal file
136
src/qml/Page/RoomList/RoomDelegate.qml
Normal file
@@ -0,0 +1,136 @@
|
||||
// SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQml.Models 2.15
|
||||
|
||||
import org.kde.kirigami 2.15 as Kirigami
|
||||
import org.kde.kitemmodels 1.0
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
import './' as RoomList
|
||||
|
||||
Kirigami.BasicListItem {
|
||||
id: root
|
||||
|
||||
required property int index
|
||||
required property int unreadCount
|
||||
required property int notificationCount
|
||||
required property int highlightCount
|
||||
required property var currentRoom
|
||||
required property bool categoryVisible
|
||||
required property string filterText
|
||||
required property string avatar
|
||||
required property string subtitleText
|
||||
|
||||
required property string name
|
||||
|
||||
readonly property bool hasUnread: unreadCount > 0
|
||||
|
||||
topPadding: Kirigami.Units.largeSpacing
|
||||
bottomPadding: Kirigami.Units.largeSpacing
|
||||
|
||||
visible: root.categoryVisible || root.filterText.length > 0 || Config.mergeRoomList
|
||||
highlighted: ListView.view.currentIndex === index
|
||||
focus: true
|
||||
icon: undefined
|
||||
bold: root.unreadCount > 0
|
||||
|
||||
label: root.name ?? ""
|
||||
labelItem.textFormat: Text.PlainText
|
||||
|
||||
subtitle: root.subtitleText
|
||||
subtitleItem {
|
||||
textFormat: Text.PlainText
|
||||
visible: !Config.compactRoomList
|
||||
}
|
||||
|
||||
onClicked: RoomManager.enterRoom(root.currentRoom)
|
||||
onPressAndHold: createRoomListContextMenu()
|
||||
|
||||
Keys.onEnterPressed: RoomManager.enterRoom(root.currentRoom)
|
||||
Keys.onReturnPressed: RoomManager.enterRoom(root.currentRoom)
|
||||
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.RightButton
|
||||
acceptedDevices: PointerDevice.Mouse
|
||||
onTapped: createRoomListContextMenu()
|
||||
}
|
||||
|
||||
leading: Kirigami.Avatar {
|
||||
source: root.avatar ? `image://mxc/${root.avatar}` : ""
|
||||
name: root.name || i18n("No Name")
|
||||
implicitWidth: visible ? height : 0
|
||||
visible: Config.showAvatarInRoomDrawer
|
||||
sourceSize {
|
||||
width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
||||
height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
|
||||
}
|
||||
}
|
||||
|
||||
trailing: RowLayout {
|
||||
Kirigami.Icon {
|
||||
source: "notifications-disabled"
|
||||
enabled: false
|
||||
implicitWidth: Kirigami.Units.iconSizes.smallMedium
|
||||
implicitHeight: Kirigami.Units.iconSizes.smallMedium
|
||||
visible: currentRoom.pushNotificationState === PushNotificationState.Mute && !configButton.visible && unreadCount <= 0
|
||||
Accessible.name: i18n("Muted room")
|
||||
Layout.rightMargin: Kirigami.Units.smallSpacing
|
||||
}
|
||||
QQC2.Label {
|
||||
id: notificationCountLabel
|
||||
text: notificationCount > 0 ? notificationCount : "●"
|
||||
visible: unreadCount > 0
|
||||
color: Kirigami.Theme.textColor
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
background: Rectangle {
|
||||
visible: notificationCount > 0
|
||||
Kirigami.Theme.colorSet: Kirigami.Theme.Button
|
||||
color: highlightCount > 0 ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.disabledTextColor
|
||||
opacity: highlightCount > 0 ? 1 : 0.3
|
||||
radius: height / 2
|
||||
}
|
||||
|
||||
Layout.rightMargin: Kirigami.Units.smallSpacing
|
||||
Layout.minimumHeight: Kirigami.Units.iconSizes.smallMedium
|
||||
Layout.minimumWidth: Math.max(notificationCountTextMetrics.advanceWidth + Kirigami.Units.smallSpacing * 2, height)
|
||||
|
||||
TextMetrics {
|
||||
id: notificationCountTextMetrics
|
||||
text: notificationCountLabel.text
|
||||
}
|
||||
}
|
||||
QQC2.Button {
|
||||
id: configButton
|
||||
visible: root.hovered && !Kirigami.Settings.isMobile && !Config.compactRoomList
|
||||
text: i18n("Configure room")
|
||||
display: QQC2.Button.IconOnly
|
||||
|
||||
icon.name: "configure"
|
||||
onClicked: createRoomListContextMenu()
|
||||
}
|
||||
}
|
||||
|
||||
function createRoomListContextMenu() {
|
||||
const component = Qt.createComponent(Qt.resolvedUrl("./ContextMenu.qml"))
|
||||
const menu = component.createObject(root, {
|
||||
room: root.currentRoom,
|
||||
});
|
||||
if (!Kirigami.Settings.isMobile && !Config.compactRoomList) {
|
||||
configButton.visible = true;
|
||||
configButton.down = true;
|
||||
}
|
||||
menu.closed.connect(function() {
|
||||
configButton.down = undefined;
|
||||
configButton.visible = Qt.binding(() => {
|
||||
return root.hovered && !Kirigami.Settings.isMobile
|
||||
&& !Config.compactRoomList;
|
||||
});
|
||||
})
|
||||
menu.open()
|
||||
}
|
||||
}
|
||||
47
src/qml/Page/RoomList/SpaceDelegate.qml
Normal file
47
src/qml/Page/RoomList/SpaceDelegate.qml
Normal file
@@ -0,0 +1,47 @@
|
||||
// SPDX-FileCopyrightText: 2022 Snehit Sah <snehitsah@protonmail.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.20 as Kirigami
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
QQC2.ItemDelegate {
|
||||
id: root
|
||||
|
||||
required property string avatar
|
||||
required property var currentRoom
|
||||
required property int index
|
||||
required property string id
|
||||
|
||||
signal createContextMenu(currentRoom: var)
|
||||
signal spaceSelected(spaceId: string)
|
||||
|
||||
height: ListView.view.height
|
||||
width: height
|
||||
|
||||
leftPadding: topPadding
|
||||
rightPadding: topPadding
|
||||
|
||||
contentItem: Kirigami.Avatar {
|
||||
name: currentRoom.displayName
|
||||
source: avatar !== "" ? "image://mxc/" + avatar : ""
|
||||
}
|
||||
|
||||
onClicked: root.spaceSelected(id)
|
||||
onPressAndHold: root.createContextMenu(root.currentRoom)
|
||||
|
||||
Accessible.name: currentRoom.displayName
|
||||
|
||||
QQC2.ToolTip.text: currentRoom.displayName
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.RightButton
|
||||
acceptedDevices: PointerDevice.Mouse
|
||||
onTapped: root.createContextMenu(root.currentRoom)
|
||||
}
|
||||
}
|
||||
124
src/qml/Page/RoomList/SpaceListContextMenu.qml
Normal file
124
src/qml/Page/RoomList/SpaceListContextMenu.qml
Normal file
@@ -0,0 +1,124 @@
|
||||
// SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
|
||||
// SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.19 as Kirigami
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
/**
|
||||
* Context menu when clicking on a room in the room list
|
||||
*/
|
||||
Loader {
|
||||
id: root
|
||||
property var room
|
||||
signal closed()
|
||||
|
||||
Component {
|
||||
id: regularMenu
|
||||
QQC2.Menu {
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("'Space' is a matrix space", "View Space")
|
||||
onTriggered: RoomManager.enterRoom(room);
|
||||
}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("@action:inmenu", "Copy Address to Clipboard")
|
||||
onTriggered: if (room.canonicalAlias.length === 0) {
|
||||
Clipboard.saveText(room.id)
|
||||
} else {
|
||||
Clipboard.saveText(room.canonicalAlias)
|
||||
}
|
||||
}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("'Space' is a matrix space", "Space Settings")
|
||||
onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Space Settings") })
|
||||
}
|
||||
|
||||
QQC2.MenuSeparator {}
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("'Space' is a matrix space", "Leave Space")
|
||||
onTriggered: RoomManager.leaveRoom(room)
|
||||
}
|
||||
|
||||
onClosed: {
|
||||
root.closed()
|
||||
destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: mobileMenu
|
||||
|
||||
Kirigami.OverlayDrawer {
|
||||
id: drawer
|
||||
height: popupContent.implicitHeight
|
||||
edge: Qt.BottomEdge
|
||||
padding: 0
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
bottomPadding: 0
|
||||
topPadding: 0
|
||||
|
||||
parent: applicationWindow().overlay
|
||||
|
||||
ColumnLayout {
|
||||
id: popupContent
|
||||
width: parent.width
|
||||
spacing: 0
|
||||
RowLayout {
|
||||
id: headerLayout
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: Kirigami.Units.largeSpacing
|
||||
spacing: Kirigami.Units.largeSpacing
|
||||
Kirigami.Avatar {
|
||||
id: avatar
|
||||
source: room.avatarMediaId ? ("image://mxc/" + room.avatarMediaId) : ""
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 3
|
||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
|
||||
Layout.alignment: Qt.AlignTop
|
||||
}
|
||||
Kirigami.Heading {
|
||||
level: 5
|
||||
Layout.fillWidth: true
|
||||
text: room.displayName
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
QQC2.ToolButton {
|
||||
icon.name: 'settings-configure'
|
||||
onClicked: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Space Settings") })
|
||||
}
|
||||
}
|
||||
Kirigami.BasicListItem {
|
||||
text: i18nc("'Space' is a matrix space", "Leave Space")
|
||||
onClicked: RoomManager.leaveRoom(room)
|
||||
implicitHeight: visible ? Kirigami.Units.gridUnit * 3 : 0
|
||||
}
|
||||
}
|
||||
onClosed: root.closed()
|
||||
}
|
||||
}
|
||||
|
||||
asynchronous: true
|
||||
sourceComponent: Kirigami.Settings.isMobile ? mobileMenu : regularMenu
|
||||
|
||||
function open() {
|
||||
active = true;
|
||||
}
|
||||
|
||||
onStatusChanged: if (status == Loader.Ready) {
|
||||
if (Kirigami.Settings.isMobile) {
|
||||
item.open();
|
||||
} else {
|
||||
item.popup();
|
||||
}
|
||||
}
|
||||
}
|
||||
64
src/qml/Page/RoomList/SpaceListView.qml
Normal file
64
src/qml/Page/RoomList/SpaceListView.qml
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2022 Snehit Sah <snehitsah@protonmail.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.20 as Kirigami
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
ListView {
|
||||
id: root
|
||||
|
||||
required property RoomListModel roomListModel
|
||||
|
||||
orientation: Qt.Horizontal
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
clip: true
|
||||
visible: root.count > 0
|
||||
|
||||
model: SortFilterSpaceListModel {
|
||||
id: sortFilterSpaceListModel
|
||||
sourceModel: root.roomListModel
|
||||
}
|
||||
|
||||
header: QQC2.ItemDelegate {
|
||||
id: homeButton
|
||||
icon.name: "home"
|
||||
text: i18nc("@action:button", "Show All Rooms")
|
||||
height: parent.height
|
||||
width: height
|
||||
leftPadding: topPadding
|
||||
rightPadding: topPadding
|
||||
|
||||
contentItem: Kirigami.Icon {
|
||||
source: "home"
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
sortFilterRoomListModel.activeSpaceId = "";
|
||||
listView.positionViewAtIndex(0, ListView.Beginning);
|
||||
}
|
||||
|
||||
QQC2.ToolTip.text: homeButton.text
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
}
|
||||
|
||||
delegate: SpaceDelegate {
|
||||
onSpaceSelected: (spaceId) => {
|
||||
sortFilterRoomListModel.activeSpaceId = spaceId;
|
||||
}
|
||||
|
||||
onCreateContextMenu: () => {
|
||||
const menu = spaceListContextMenu.createObject(page, {
|
||||
room: currentRoom,
|
||||
});
|
||||
menu.open();
|
||||
}
|
||||
}
|
||||
|
||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 2
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
229
src/qml/Page/RoomList/UserInfo.qml
Normal file
229
src/qml/Page/RoomList/UserInfo.qml
Normal file
@@ -0,0 +1,229 @@
|
||||
// SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
import QtQuick.Layouts 1.15
|
||||
import org.kde.kirigami 2.20 as Kirigami
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
QQC2.ToolBar {
|
||||
id: userInfo
|
||||
|
||||
padding: 0
|
||||
|
||||
height: content.height
|
||||
|
||||
property var addAccount
|
||||
|
||||
ColumnLayout {
|
||||
id: content
|
||||
width: parent.width
|
||||
|
||||
spacing: 0
|
||||
|
||||
ListView {
|
||||
id: accounts
|
||||
|
||||
currentIndex: Controller.activeConnectionIndex
|
||||
|
||||
header: Kirigami.Separator {}
|
||||
|
||||
footer: Kirigami.BasicListItem {
|
||||
width: parent.width
|
||||
highlighted: focus
|
||||
background: Rectangle {
|
||||
id: background
|
||||
color: addAccount.backgroundColor
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
visible: !Kirigami.Settings.tabletMode && addAccount.hoverEnabled
|
||||
color: addAccount.activeBackgroundColor
|
||||
opacity: {
|
||||
if ((addAccount.highlighted || addAccount.ListView.isCurrentItem) && !addAccount.pressed) {
|
||||
return .6
|
||||
} else if (addAccount.hovered && !addAccount.pressed) {
|
||||
return .3
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Component.onCompleted: userInfo.addAccount = this
|
||||
icon: "list-add"
|
||||
text: i18n("Add Account")
|
||||
subtitle: i18n("Log in to an existing account")
|
||||
onClicked: {
|
||||
pageStack.pushDialogLayer("qrc:/WelcomePage.qml", {}, {title: i18nc("@title:window", "Login")})
|
||||
if (switchUserButton.checked) {
|
||||
switchUserButton.checked = false
|
||||
}
|
||||
accounts.currentIndex = Controller.activeConnectionIndex
|
||||
}
|
||||
Keys.onUpPressed: {
|
||||
accounts.currentIndex = accounts.count - 1
|
||||
accounts.forceActiveFocus()
|
||||
}
|
||||
Keys.onDownPressed: {
|
||||
accounts.currentIndex = 0
|
||||
accounts.forceActiveFocus()
|
||||
}
|
||||
}
|
||||
|
||||
visible: switchUserButton.checked
|
||||
onVisibleChanged: if (visible) accounts.forceActiveFocus()
|
||||
clip: true
|
||||
model: AccountRegistry
|
||||
|
||||
keyNavigationEnabled: false
|
||||
Keys.onDownPressed: {
|
||||
if (accounts.currentIndex === accounts.count - 1) {
|
||||
addAccount.forceActiveFocus()
|
||||
accounts.currentIndex = -1
|
||||
} else {
|
||||
accounts.incrementCurrentIndex()
|
||||
}
|
||||
}
|
||||
Keys.onUpPressed: {
|
||||
if (accounts.currentIndex === 0) {
|
||||
addAccount.forceActiveFocus()
|
||||
accounts.currentIndex = -1
|
||||
} else {
|
||||
accounts.decrementCurrentIndex()
|
||||
}
|
||||
}
|
||||
|
||||
Keys.onReleased: if (event.key == Qt.Key_Escape) {
|
||||
if (switchUserButton.checked) {
|
||||
switchUserButton.checked = false
|
||||
}
|
||||
}
|
||||
|
||||
width: parent.width
|
||||
Layout.preferredHeight: contentHeight
|
||||
delegate: Kirigami.BasicListItem {
|
||||
leftPadding: topPadding
|
||||
leading: Kirigami.Avatar {
|
||||
width: height
|
||||
source: model.connection.localUser.avatarMediaId ? ("image://mxc/" + model.connection.localUser.avatarMediaId) : ""
|
||||
name: model.connection.localUser.displayName ?? model.connection.localUser.id
|
||||
}
|
||||
width: parent.width
|
||||
text: model.connection.localUser.displayName
|
||||
labelItem.textFormat: Text.PlainText
|
||||
subtitleItem.textFormat: Text.PlainText
|
||||
subtitle: model.connection.localUser.id
|
||||
|
||||
onClicked: {
|
||||
Controller.activeConnection = model.connection
|
||||
if (switchUserButton.checked) {
|
||||
switchUserButton.checked = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kirigami.Separator {
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
|
||||
Item {
|
||||
Layout.fillHeight: true
|
||||
Layout.preferredWidth: height
|
||||
Kirigami.Avatar {
|
||||
readonly property string mediaId: Controller.activeConnection.localUser.avatarMediaId
|
||||
anchors.fill: parent
|
||||
anchors.margins: Kirigami.Units.smallSpacing
|
||||
source: mediaId ? ("image://mxc/" + mediaId) : ""
|
||||
name: Controller.activeConnection.localUser.displayName ?? Controller.activeConnection.localUser.id
|
||||
actions.main: Kirigami.Action {
|
||||
text: i18n("Edit this account")
|
||||
icon.name: "document-edit"
|
||||
onTriggered: pageStack.pushDialogLayer(Qt.resolvedUrl('qrc:/AccountEditorPage.qml'), {
|
||||
connection: Controller.activeConnection
|
||||
}, {
|
||||
title: i18n("Account editor")
|
||||
});
|
||||
}
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.RightButton
|
||||
acceptedDevices: PointerDevice.Mouse
|
||||
onTapped: accountMenu.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 0
|
||||
QQC2.Label {
|
||||
id: displayNameLabel
|
||||
text: Controller.activeConnection.localUser.displayName
|
||||
textFormat: Text.PlainText
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
QQC2.Label {
|
||||
text: (Controller.activeConnection.localUser.accountLabel.length > 0 ? (Controller.activeConnection.localUser.accountLabel + " ") : "") + Controller.activeConnection.localUser.id
|
||||
font.pointSize: displayNameLabel.font.pointSize * 0.8
|
||||
opacity: 0.7
|
||||
textFormat: Text.PlainText
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
QQC2.ToolButton {
|
||||
id: switchUserButton
|
||||
icon.name: "system-switch-user"
|
||||
checkable: true
|
||||
text: i18n("Switch User")
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
Accessible.name: text
|
||||
QQC2.ToolTip.text: text
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
Layout.minimumWidth: Layout.preferredWidth
|
||||
Layout.alignment: Qt.AlignRight
|
||||
Shortcut {
|
||||
sequence: "Ctrl+U"
|
||||
onActivated: switchUserButton.toggle()
|
||||
}
|
||||
}
|
||||
QQC2.ToolButton {
|
||||
icon.name: "list-add"
|
||||
onClicked: ; //TODO
|
||||
text: i18n("Add") //TODO find better message
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
QQC2.ToolTip.text: text
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
Layout.minimumWidth: Layout.preferredWidth
|
||||
Layout.alignment: Qt.AlignRight
|
||||
visible: false
|
||||
}
|
||||
QQC2.ToolButton {
|
||||
icon.name: "settings-configure"
|
||||
onClicked: pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {}, { title: i18n("Configure") })
|
||||
text: i18n("Open Settings")
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
Layout.minimumWidth: Layout.preferredWidth
|
||||
Layout.alignment: Qt.AlignRight
|
||||
QQC2.ToolTip {
|
||||
text: parent.text
|
||||
}
|
||||
}
|
||||
Item {
|
||||
width: 1
|
||||
}
|
||||
|
||||
AccountMenu {
|
||||
id: accountMenu
|
||||
y: -height
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user