matrixion/qml/dialogs/RoomDirectory.qml

168 lines
5.5 KiB
QML
Raw Permalink Normal View History

2021-08-12 17:45:42 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-08-12 17:45:42 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
2022-04-16 03:13:01 +03:00
import "../"
import "../ui"
2021-08-12 17:45:42 +03:00
import QtQuick 2.9
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import im.nheko
2021-08-12 17:45:42 +03:00
ApplicationWindow {
id: roomDirectoryWindow
2022-04-16 03:13:01 +03:00
property RoomDirectoryModel publicRooms: RoomDirectoryModel {
}
2021-08-12 17:45:42 +03:00
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.window
2021-08-19 17:55:54 +03:00
flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
2022-04-16 03:13:01 +03:00
height: 420
minimumHeight: 340
minimumWidth: 340
modality: Qt.WindowModal
palette: timelineRoot.palette
2021-08-12 17:45:42 +03:00
title: qsTr("Explore Public Rooms")
2022-04-16 03:13:01 +03:00
visible: true
width: 650
header: RowLayout {
id: searchBarLayout
implicitHeight: roomSearch.height
spacing: Nheko.paddingMedium
width: parent.width
MatrixTextField {
id: roomSearch
Layout.fillWidth: true
color: timelineRoot.palette.text
focus: true
font.pixelSize: fontMetrics.font.pixelSize
placeholderText: qsTr("Search for public rooms")
selectByMouse: true
onTextChanged: searchTimer.restart()
}
MatrixTextField {
id: chooseServer
Layout.maximumWidth: 0.3 * header.width
Layout.minimumWidth: 0.3 * header.width
color: timelineRoot.palette.text
placeholderText: qsTr("Choose custom homeserver")
onTextChanged: publicRooms.setMatrixServer(text)
}
Timer {
id: searchTimer
interval: 350
onTriggered: roomDirView.model.setSearchTerm(roomSearch.text)
}
}
2021-08-12 17:45:42 +03:00
Shortcut {
sequence: StandardKey.Cancel
2022-04-16 03:13:01 +03:00
2021-08-12 17:45:42 +03:00
onActivated: roomDirectoryWindow.close()
}
ListView {
id: roomDirView
anchors.fill: parent
model: publicRooms
delegate: Rectangle {
id: roomDirDelegate
2022-04-16 03:13:01 +03:00
property int avatarSize: fontMetrics.height * 3.2
2022-04-11 05:18:16 +03:00
property color background: timelineRoot.palette.window
property color importantText: timelineRoot.palette.text
2022-04-15 06:53:41 +03:00
property color unimportantText: timelineRoot.palette.placeholderText
2021-08-12 17:45:42 +03:00
color: background
2021-08-14 16:44:34 +03:00
height: avatarSize + Nheko.paddingLarge
2021-08-12 17:45:42 +03:00
width: ListView.view.width
RowLayout {
anchors.fill: parent
2022-02-22 00:27:35 +03:00
anchors.margins: Nheko.paddingMedium
implicitHeight: textContent.implicitHeight
2022-04-16 03:13:01 +03:00
spacing: Nheko.paddingMedium
2021-08-12 17:45:42 +03:00
Avatar {
id: roomAvatar
Layout.alignment: Qt.AlignVCenter
2022-02-22 00:27:35 +03:00
Layout.rightMargin: Nheko.paddingMedium
2022-04-16 03:13:01 +03:00
displayName: model.name
2021-08-12 17:45:42 +03:00
height: avatarSize
roomid: model.roomid
2022-04-16 03:13:01 +03:00
url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
width: avatarSize
2021-08-12 17:45:42 +03:00
}
2022-02-22 00:27:35 +03:00
GridLayout {
2021-08-12 17:45:42 +03:00
id: textContent
Layout.alignment: Qt.AlignLeft
Layout.preferredWidth: parent.width - avatar.width
2022-04-16 03:13:01 +03:00
columns: 2
rows: 2
width: parent.width - avatar.width
2021-08-12 17:45:42 +03:00
2021-08-15 04:47:11 +03:00
ElidedLabel {
2022-02-22 00:27:35 +03:00
Layout.column: 0
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
Layout.row: 0
2021-08-15 04:47:11 +03:00
color: roomDirDelegate.importantText
2022-02-22 00:27:35 +03:00
elideWidth: width
2021-08-15 04:47:11 +03:00
fullText: model.name
2021-08-12 17:45:42 +03:00
}
2022-02-22 00:27:35 +03:00
Label {
id: roomTopic
Layout.column: 0
2022-04-16 03:13:01 +03:00
Layout.fillWidth: true
Layout.row: 1
color: roomDirDelegate.unimportantText
2022-02-22 00:27:35 +03:00
elide: Text.ElideRight
2022-04-16 03:13:01 +03:00
font.pointSize: fontMetrics.font.pointSize * 0.9
2022-02-22 00:27:35 +03:00
maximumLineCount: 2
text: model.topic
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
}
Label {
2022-04-16 03:13:01 +03:00
id: roomCount
2022-02-22 00:27:35 +03:00
Layout.alignment: Qt.AlignHCenter
Layout.column: 1
2022-04-16 03:13:01 +03:00
Layout.row: 0
2022-02-22 00:27:35 +03:00
color: roomDirDelegate.unimportantText
2022-04-16 03:13:01 +03:00
font.pointSize: fontMetrics.font.pointSize * 0.9
2022-02-22 00:27:35 +03:00
text: model.numMembers.toString()
}
Button {
id: joinRoomButton
2022-04-16 03:13:01 +03:00
Layout.column: 1
Layout.row: 1
2022-02-22 00:27:35 +03:00
enabled: model.canJoin
text: "Join"
2022-04-16 03:13:01 +03:00
2022-02-22 00:27:35 +03:00
onClicked: publicRooms.joinRoom(model.index)
2021-08-12 17:45:42 +03:00
}
}
}
}
footer: Item {
anchors.horizontalCenter: parent.horizontalCenter
2022-04-16 03:13:01 +03:00
anchors.margins: Nheko.paddingLarge
2021-08-12 17:45:42 +03:00
// hacky but works
height: loadingSpinner.height + 2 * Nheko.paddingLarge
2022-04-16 03:13:01 +03:00
visible: !publicRooms.reachedEndOfPagination && publicRooms.loadingMoreRooms
width: parent.width
2021-08-12 17:45:42 +03:00
Spinner {
id: loadingSpinner
anchors.centerIn: parent
anchors.margins: Nheko.paddingLarge
2022-04-11 05:18:16 +03:00
foreground: timelineRoot.palette.mid
2022-04-16 03:13:01 +03:00
running: visible
2021-08-12 17:45:42 +03:00
}
}
}
}