Spectral/qml/main.qml

300 lines
8.3 KiB
QML
Raw Normal View History

2018-07-12 01:44:41 +00:00
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2
import Qt.labs.settings 1.0
2018-02-23 14:39:14 +00:00
import QtGraphicalEffects 1.0
import Matrique 0.1
import Matrique.Settings 0.1
2018-02-23 14:39:14 +00:00
import "component"
import "form"
2018-09-13 03:58:02 +00:00
import "qrc:/js/util.js" as Util
2018-02-23 14:39:14 +00:00
ApplicationWindow {
readonly property var currentConnection: accountListView.currentConnection ? accountListView.currentConnection : null
2018-07-20 14:36:19 +00:00
2018-02-23 14:39:14 +00:00
width: 960
height: 640
2018-09-15 11:07:38 +00:00
minimumWidth: 720
minimumHeight: 360
2018-09-04 13:13:14 +00:00
id: window
visible: true
2018-02-23 14:39:14 +00:00
title: qsTr("Matrique")
Material.theme: MSettings.darkTheme ? Material.Dark : Material.Light
2018-09-10 07:01:01 +00:00
Material.accent: matriqueController.color(currentConnection ? currentConnection.localUserId : "")
FontLoader { id: materialFont; source: "qrc:/asset/font/material.ttf" }
2018-02-27 11:07:50 +00:00
Controller {
id: matriqueController
2018-08-19 06:51:09 +00:00
2018-09-14 04:16:25 +00:00
onShowWindow: {
window.show()
window.raise()
window.requestActivate()
2018-09-06 13:00:58 +00:00
}
2018-09-14 04:16:25 +00:00
onHideWindow: window.hide()
2018-02-26 12:41:20 +00:00
}
2018-02-23 14:39:14 +00:00
AccountListModel {
id: accountListModel
controller: matriqueController
}
Popup {
property bool busy: matriqueController.busy
x: (window.width - width) / 2
y: (window.height - height) / 2
2018-09-04 13:13:14 +00:00
id: busyPopup
modal: true
focus: true
closePolicy: Popup.NoAutoClose
BusyIndicator { running: true }
2018-08-07 15:41:18 +00:00
onBusyChanged: busyPopup.busy ? busyPopup.open() : busyPopup.close()
2018-03-02 11:58:55 +00:00
}
2018-02-23 14:39:14 +00:00
Component {
id: loginPage
2018-02-23 14:39:14 +00:00
Login { controller: matriqueController }
}
Room {
id: roomPage
parent: null
connection: currentConnection
}
2018-02-23 14:39:14 +00:00
2018-07-19 05:54:59 +00:00
Setting {
id: settingPage
parent: null
listModel: accountListModel
2018-07-19 05:54:59 +00:00
}
RowLayout {
anchors.fill: parent
spacing: 0
2018-02-23 14:39:14 +00:00
Rectangle {
2018-09-02 13:26:42 +00:00
Layout.preferredWidth: 64
Layout.fillHeight: true
2018-09-04 13:13:14 +00:00
id: sideNav
2018-09-02 13:26:42 +00:00
color: Material.primary
2018-02-23 14:39:14 +00:00
ColumnLayout {
anchors.fill: parent
spacing: 0
2018-03-02 15:05:32 +00:00
ListView {
property var currentConnection: null
2018-09-02 13:26:42 +00:00
Layout.fillWidth: true
Layout.fillHeight: true
2018-09-02 13:26:42 +00:00
id: accountListView
model: accountListModel
spacing: 0
2018-03-02 15:05:32 +00:00
2018-09-10 08:22:45 +00:00
clip: true
delegate: SideNavButton {
width: parent.width
height: width
2018-09-11 05:14:56 +00:00
selected: stackView.currentItem === page && currentConnection === connection
ImageItem {
anchors.fill: parent
anchors.margins: 12
2018-09-04 13:13:14 +00:00
2018-09-10 04:56:16 +00:00
hint: user.displayName
image: user.avatar
}
2018-09-10 08:22:45 +00:00
highlightColor: matriqueController.color(user.id)
page: roomPage
onClicked: accountListView.currentConnection = connection
}
2018-03-02 15:05:32 +00:00
}
2018-02-23 14:39:14 +00:00
SideNavButton {
2018-09-02 13:26:42 +00:00
Layout.fillWidth: true
Layout.preferredHeight: width
MaterialIcon {
anchors.fill: parent
icon: "\ue145"
color: "white"
}
onClicked: addRoomMenu.popup()
Menu {
id: addRoomMenu
2018-09-04 13:13:14 +00:00
MenuItem {
text:"New Room"
onTriggered: addRoomDialog.open()
Dialog {
id: addRoomDialog
parent: ApplicationWindow.overlay
x: (window.width - width) / 2
y: (window.height - height) / 2
width: 360
title: "New Room"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: Column {
TextField {
width: parent.width
2018-09-04 13:13:14 +00:00
id: addRoomDialogNameTextField
placeholderText: "Name"
}
TextField {
width: parent.width
2018-09-04 13:13:14 +00:00
id: addRoomDialogTopicTextField
placeholderText: "Topic"
}
}
onAccepted: matriqueController.createRoom(currentConnection, addRoomDialogNameTextField.text, addRoomDialogTopicTextField.text)
}
}
MenuItem {
text: "Join Room"
2018-09-04 13:13:14 +00:00
onTriggered: joinRoomDialog.open()
Dialog {
x: (window.width - width) / 2
y: (window.height - height) / 2
width: 360
2018-09-04 13:13:14 +00:00
id: joinRoomDialog
parent: ApplicationWindow.overlay
title: "Input Room Alias or ID"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: TextField {
id: joinRoomDialogTextField
placeholderText: "#matrix:matrix.org"
}
onAccepted: matriqueController.joinRoom(currentConnection, joinRoomDialogTextField.text)
}
}
2018-09-02 13:26:42 +00:00
MenuItem {
text: "Direct Chat"
2018-09-04 13:13:14 +00:00
onTriggered: directChatDialog.open()
Dialog {
x: (window.width - width) / 2
y: (window.height - height) / 2
width: 360
2018-09-04 13:13:14 +00:00
id: directChatDialog
parent: ApplicationWindow.overlay
title: "Input User ID"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
contentItem: TextField {
id: directChatDialogTextField
placeholderText: "@bot:matrix.org"
}
onAccepted: currentConnection.createDirectChat(directChatDialogTextField.text)
}
}
}
}
SideNavButton {
Layout.fillWidth: true
Layout.preferredHeight: width
MaterialIcon {
anchors.fill: parent
icon: "\ue8b8"
color: "white"
2018-09-02 13:26:42 +00:00
}
2018-07-19 05:54:59 +00:00
page: settingPage
2018-02-23 14:39:14 +00:00
}
SideNavButton {
2018-09-02 13:26:42 +00:00
Layout.fillWidth: true
Layout.preferredHeight: width
MaterialIcon {
anchors.fill: parent
icon: "\ue879"
color: "white"
}
onClicked: Qt.quit()
}
2018-02-23 14:39:14 +00:00
}
}
2018-02-23 14:39:14 +00:00
StackView {
Layout.fillWidth: true
Layout.fillHeight: true
2018-09-04 13:13:14 +00:00
id: stackView
2018-09-10 00:06:32 +00:00
initialItem: roomPage
2018-02-23 14:39:14 +00:00
}
}
Binding {
target: imageProvider
property: "connection"
value: currentConnection
2018-02-23 14:39:14 +00:00
}
2018-09-13 00:22:41 +00:00
Component.onCompleted: {
matriqueController.initiated.connect(function() {
if (matriqueController.accountCount == 0) stackView.push(loginPage)
})
}
2018-02-23 14:39:14 +00:00
}