Code cleanup && add minimum room management. #13

This commit is contained in:
Black Hat 2018-08-09 19:58:19 +08:00
parent b5328ec140
commit 587e298988
13 changed files with 145 additions and 200 deletions

View File

@ -15,7 +15,7 @@ Page {
connection: page.connection connection: page.connection
// onNewMessage: trayIcon.showMessage("New message", "New message for room " + room.displayName) onNewMessage: trayIcon.showMessage("New message", "New message for room " + room.displayName)
} }
RowLayout { RowLayout {

View File

@ -2,6 +2,8 @@ import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
Row { Row {
readonly property bool avatarVisible: !sentByMe && aboveAuthor !== author || section !== aboveSection
spacing: 6 spacing: 6
ImageStatus { ImageStatus {
@ -10,7 +12,7 @@ Row {
width: height width: height
height: 40 height: 40
round: false round: false
visible: !sentByMe && aboveAuthor !== author visible: avatarVisible
source: author.avatarUrl != "" ? "image://mxc/" + author.avatarUrl : null source: author.avatarUrl != "" ? "image://mxc/" + author.avatarUrl : null
displayText: author.displayName displayText: author.displayName
@ -27,6 +29,6 @@ Row {
width: height width: height
height: 40 height: 40
color: "transparent" color: "transparent"
visible: !sentByMe && aboveAuthor === author visible: !avatarVisible
} }
} }

View File

@ -1,6 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
ItemDelegate {
id: itemDelegate
}

View File

@ -4,7 +4,6 @@ import QtGraphicalEffects 1.0
import QtQuick.Controls.Material 2.2 import QtQuick.Controls.Material 2.2
Item { Item {
property bool opaqueBackground: false
property bool round: true property bool round: true
property string source: "" property string source: ""
property string displayText: "" property string displayText: ""
@ -13,14 +12,6 @@ Item {
id: item id: item
Rectangle {
width: item.width
height: item.width
radius: round ? item.width / 2 : 0
color: "white"
visible: opaqueBackground
}
Image { Image {
id: avatar id: avatar
width: item.width width: item.width

View File

@ -3,9 +3,6 @@ import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2 import QtQuick.Controls.Material 2.2
Item {
Rectangle { Rectangle {
anchors.fill: parent
color: Material.accent color: Material.accent
} }
}

View File

@ -24,7 +24,7 @@ Item {
} }
} }
ButtonDelegate { ItemDelegate {
id: buttonDelegate id: buttonDelegate
anchors.fill: parent anchors.fill: parent

View File

@ -6,7 +6,7 @@ import QtQuick.Layouts 1.3
Rectangle { Rectangle {
property bool flat: false property bool flat: false
property bool highlighted: false property bool highlighted: false
property string displayText property string displayText: ""
property alias timeLabelVisible: timeText.visible property alias timeLabelVisible: timeText.visible
property int maximumWidth property int maximumWidth

View File

@ -1,99 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2
import "qrc:/qml/component"
Item {
ColumnLayout {
anchors.fill: parent
spacing: 0
Pane {
Layout.fillWidth: true
Layout.preferredHeight: 250
padding: 32
background: Rectangle {
color: Material.accent
}
Column {
anchors.fill: parent
ImageStatus {
z: 10
width: 96
height: width
source: "qrc:/asset/img/avatar.png"
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: "Astolfo"
color: "white"
font.pointSize: 28
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: "Rider of Black"
color: "#cdcdcd"
font.pointSize: 12
anchors.horizontalCenter: parent.horizontalCenter
}
Row {
height: 48
anchors.horizontalCenter: parent.horizontalCenter
ItemDelegate {
width: parent.height
height: parent.height
contentItem: MaterialIcon { icon: "\ue0b7" }
}
ItemDelegate {
width: parent.height
height: parent.height
contentItem: MaterialIcon { icon: "\ue62e" }
}
}
}
}
Pane {
Layout.fillWidth: true
Layout.fillHeight: true
leftPadding: 96
rightPadding: 96
GridLayout {
width: parent.width
columns: 2
flow: GridLayout.LeftToRight
anchors.horizontalCenter: parent.horizontalCenter
columnSpacing: 32
Text {
text: "Matrix ID"
}
Text {
Layout.fillWidth: true
text: "Welcome"
}
Text {
text: "Status"
}
Text {
text: "Overline"
}
}
}
}
}

View File

@ -12,19 +12,89 @@ Item {
id: item id: item
property var currentRoom: null property var currentRoom: null
Drawer {
id: roomDrawer
width: Math.min(item.width * 0.7, 480)
height: item.height
edge: Qt.RightEdge
interactive: false
ToolButton {
contentItem: MaterialIcon { icon: "\ue5c4" }
onClicked: roomDrawer.close()
}
Column {
anchors.fill: parent
anchors.margins: 32
spacing: 16
ImageStatus {
width: 64
height: 64
anchors.horizontalCenter: parent.horizontalCenter
source: currentRoom && currentRoom.avatarUrl != "" ? "image://mxc/" + currentRoom.avatarUrl : null
displayText: currentRoom ? currentRoom.displayName : ""
}
Label {
width: parent.width
text: currentRoom && currentRoom.id ? currentRoom.id : ""
}
RowLayout {
width: parent.width
TextField {
id: roomNameField
Layout.fillWidth: true
text: currentRoom && currentRoom.name ? currentRoom.name : ""
}
ItemDelegate {
Layout.preferredWidth: height
Layout.fillHeight: true
contentItem: MaterialIcon { icon: "\ue5ca" }
onClicked: currentRoom.setName(roomNameField.text)
}
}
RowLayout {
width: parent.width
TextField {
id: roomTopicField
Layout.fillWidth: true
text: currentRoom && currentRoom.topic ? currentRoom.topic : ""
}
ItemDelegate {
Layout.preferredWidth: height
Layout.fillHeight: true
contentItem: MaterialIcon { icon: "\ue5ca" }
onClicked: currentRoom.setTopic(roomTopicField.text)
}
}
}
}
Pane { Pane {
anchors.fill: parent anchors.fill: parent
padding: 0 padding: 0
background: Item { background: Label {
anchors.fill: parent
visible: !currentRoom
Pane { anchors.fill: parent }
Label {
text: "Please choose a room."
anchors.centerIn: parent anchors.centerIn: parent
} visible: !currentRoom
text: "Please choose a room."
} }
ColumnLayout { ColumnLayout {
@ -33,16 +103,16 @@ Item {
visible: currentRoom visible: currentRoom
Pane { Rectangle {
padding: 16
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 80 Layout.preferredHeight: 80
background: Rectangle { color: Material.theme == Material.Light ? "#eaeaea" : "#242424" } color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
anchors.margins: 16
spacing: 16 spacing: 16
ImageStatus { ImageStatus {
@ -52,12 +122,12 @@ Item {
displayText: currentRoom ? currentRoom.displayName : "" displayText: currentRoom ? currentRoom.displayName : ""
} }
ColumnLayout { Column {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Label { Label {
Layout.fillWidth: true width: parent.width
text: currentRoom ? currentRoom.displayName : "" text: currentRoom ? currentRoom.displayName : ""
font.pointSize: 16 font.pointSize: 16
elide: Text.ElideRight elide: Text.ElideRight
@ -65,15 +135,20 @@ Item {
} }
Label { Label {
Layout.fillWidth: true width: parent.width
text: currentRoom ? currentRoom.topic : "" text: currentRoom ? currentRoom.topic : ""
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }
} }
}
}
ToolButton {
contentItem: MaterialIcon { icon: "\ue5d2" }
onClicked: roomDrawer.open()
}
}
}
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
@ -137,7 +212,7 @@ Item {
ScrollBar.vertical: messageListViewScrollBar ScrollBar.vertical: messageListViewScrollBar
onAtYBeginningChanged: atYBeginning && currentRoom ? currentRoom.getPreviousContent(50) : {} onAtYBeginningChanged: atYBeginning && currentRoom ? currentRoom.getPreviousContent(20) : {}
onAtYEndChanged: atYEnd && currentRoom ? currentRoom.markAllMessagesAsRead() : {} onAtYEndChanged: atYEnd && currentRoom ? currentRoom.markAllMessagesAsRead() : {}
RoundButton { RoundButton {
@ -234,7 +309,9 @@ Item {
} }
} }
background: Item { background: Rectangle {
color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
Rectangle { Rectangle {
z: 5 z: 5
width: inputField.width * inputField.progress width: inputField.width * inputField.progress
@ -242,7 +319,6 @@ Item {
color: Material.accent color: Material.accent
opacity: 0.4 opacity: 0.4
} }
Rectangle { anchors.fill: parent; color: Material.theme == Material.Light ? "#eaeaea" : "#242424" }
} }
function postMessage(text) { function postMessage(text) {

View File

@ -20,28 +20,23 @@ Item {
anchors.fill: parent anchors.fill: parent
spacing: 0 spacing: 0
Pane { Rectangle {
z: 10 z: 10
Layout.fillWidth: true Layout.fillWidth: true
Layout.preferredHeight: 80 Layout.preferredHeight: 80
background: Rectangle {
color: Qt.tint(Material.accent, "#20FFFFFF") color: Qt.tint(Material.accent, "#20FFFFFF")
}
TextField { TextField {
id: searchField id: searchField
width: parent.width width: parent.width - 18
height: 36 height: 36
color: "black" color: "black"
leftPadding: mini ? 4 : 16 leftPadding: mini ? 4 : 16
topPadding: 0 topPadding: 0
bottomPadding: 0 bottomPadding: 0
anchors.verticalCenter: parent.verticalCenter anchors.centerIn: parent
background: Item {
Row {
anchors.fill: parent
background: Row {
MaterialIcon { MaterialIcon {
icon: "\ue8b6" icon: "\ue8b6"
color: "white" color: "white"
@ -72,19 +67,12 @@ Item {
} }
} }
} }
}
Pane { Rectangle {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
padding: 0
background: Item {
anchors.fill: parent
Rectangle {
anchors.fill: parent
color: Material.theme == Material.Light ? "#eaeaea" : "#242424" color: Material.theme == Material.Light ? "#eaeaea" : "#242424"
}
Label { Label {
z: 10 z: 10
@ -92,7 +80,6 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
visible: listView.count === 0 visible: listView.count === 0
} }
}
SortFilterProxyModel { SortFilterProxyModel {
id: roomListProxyModel id: roomListProxyModel
@ -116,8 +103,7 @@ Item {
ListView { ListView {
id: listView id: listView
width: parent.width anchors.fill: parent
height: parent.height
model: roomListProxyModel model: roomListProxyModel
@ -138,8 +124,8 @@ Item {
width: parent.width width: parent.width
height: 80 height: 80
onPressed: listView.currentIndex = index onPressed: listView.currentIndex = index
onClicked: enterRoom()
onPressAndHold: roomListMenu.popup() onPressAndHold: roomListMenu.popup()
onClicked: enterRoom()
ToolTip.visible: mini && hovered ToolTip.visible: mini && hovered
ToolTip.text: name ToolTip.text: name
@ -239,5 +225,5 @@ Item {
} }
} }
onCurrentRoomChanged: if (currentRoom && !currentRoom.timelineSize) currentRoom.getPreviousContent(50) onCurrentRoomChanged: if (currentRoom && !currentRoom.timelineSize) currentRoom.getPreviousContent(20)
} }

View File

@ -17,7 +17,6 @@ Page {
source: matriqueController.isLogin ? connection.localUser && connection.localUser.avatarUrl ? "image://mxc/" + connection.localUser.avatarUrl : "" : "qrc:/asset/img/avatar.png" source: matriqueController.isLogin ? connection.localUser && connection.localUser.avatarUrl ? "image://mxc/" + connection.localUser.avatarUrl : "" : "qrc:/asset/img/avatar.png"
displayText: matriqueController.isLogin && connection.localUser.displayName ? connection.localUser.displayName : "N" displayText: matriqueController.isLogin && connection.localUser.displayName ? connection.localUser.displayName : "N"
opaqueBackground: false
} }
ColumnLayout { ColumnLayout {

View File

@ -115,7 +115,6 @@ ApplicationWindow {
source: matriqueController.isLogin ? connection.localUser && connection.localUser.avatarUrl ? "image://mxc/" + connection.localUser.avatarUrl : "" : "qrc:/asset/img/avatar.png" source: matriqueController.isLogin ? connection.localUser && connection.localUser.avatarUrl ? "image://mxc/" + connection.localUser.avatarUrl : "" : "qrc:/asset/img/avatar.png"
displayText: matriqueController.isLogin && connection.localUser.displayName ? connection.localUser.displayName : "N" displayText: matriqueController.isLogin && connection.localUser.displayName ? connection.localUser.displayName : "N"
opaqueBackground: false
} }
page: roomPage page: roomPage
@ -183,6 +182,7 @@ ApplicationWindow {
contentItem: TextField { contentItem: TextField {
id: joinRoomDialogTextField id: joinRoomDialogTextField
placeholderText: "#matrix:matrix.org"
} }
onAccepted: matriqueController.joinRoom(joinRoomDialogTextField.text) onAccepted: matriqueController.joinRoom(joinRoomDialogTextField.text)
@ -206,6 +206,7 @@ ApplicationWindow {
contentItem: TextField { contentItem: TextField {
id: directChatDialogTextField id: directChatDialogTextField
placeholderText: "@bot:matrix.org"
} }
onAccepted: matriqueController.createDirectChat(directChatDialogTextField.text) onAccepted: matriqueController.createDirectChat(directChatDialogTextField.text)

View File

@ -6,12 +6,10 @@
<file>asset/font/material.ttf</file> <file>asset/font/material.ttf</file>
<file>qml/Login.qml</file> <file>qml/Login.qml</file>
<file>qml/main.qml</file> <file>qml/main.qml</file>
<file>qml/component/ButtonDelegate.qml</file>
<file>qml/component/ImageStatus.qml</file> <file>qml/component/ImageStatus.qml</file>
<file>qml/component/SideNav.qml</file> <file>qml/component/SideNav.qml</file>
<file>qml/form/RoomForm.qml</file> <file>qml/form/RoomForm.qml</file>
<file>qml/Room.qml</file> <file>qml/Room.qml</file>
<file>qml/form/DetailForm.qml</file>
<file>qml/component/SideNavButton.qml</file> <file>qml/component/SideNavButton.qml</file>
<file>qml/component/MaterialIcon.qml</file> <file>qml/component/MaterialIcon.qml</file>
<file>asset/img/icon.png</file> <file>asset/img/icon.png</file>