From aa29f5252d1fdb70a35673da205dc732634ad220 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Tue, 4 Sep 2018 21:13:14 +0800 Subject: [PATCH] Reformat code. --- qml/Login.qml | 20 ++++++----- qml/Room.qml | 9 ++--- qml/Setting.qml | 18 ++++++---- qml/component/AutoImage.qml | 12 +++---- qml/component/AutoLabel.qml | 1 + qml/component/AutoMouseArea.qml | 1 + qml/component/DownloadableContent.qml | 17 ++++----- qml/component/EmojiPicker.qml | 1 + qml/component/GenericBubble.qml | 6 ++-- qml/component/ImageStatus.qml | 5 ++- qml/component/MaterialIcon.qml | 3 +- qml/component/MessageDelegate.qml | 12 ++++--- qml/form/RoomForm.qml | 52 +++++++++++++++------------ qml/form/RoomListForm.qml | 14 +++++--- qml/main.qml | 49 ++++++++++++++++--------- qml/menu/MessageContextMenu.qml | 5 +++ qml/menu/RoomContextMenu.qml | 4 +++ 17 files changed, 139 insertions(+), 90 deletions(-) diff --git a/qml/Login.qml b/qml/Login.qml index 811955b..25b6db9 100644 --- a/qml/Login.qml +++ b/qml/Login.qml @@ -57,17 +57,19 @@ Page { Pane { width: parent.width / 2 height: parent.height + padding: 64 ColumnLayout { - id: mainCol width: parent.width - TextField { - id: serverField + id: mainCol + TextField { Layout.fillWidth: true + id: serverField + leftPadding: 16 topPadding: 0 bottomPadding: 0 @@ -85,10 +87,10 @@ Page { } TextField { - id: usernameField - Layout.fillWidth: true + id: usernameField + leftPadding: 16 topPadding: 0 bottomPadding: 0 @@ -105,10 +107,10 @@ Page { } TextField { - id: passwordField - Layout.fillWidth: true + id: passwordField + leftPadding: 16 topPadding: 0 bottomPadding: 0 @@ -126,10 +128,10 @@ Page { } Button { - id: loginButton - Layout.fillWidth: true + id: loginButton + text: "LOGIN" highlighted: true diff --git a/qml/Room.qml b/qml/Room.qml index ed1f17b..3c16583 100644 --- a/qml/Room.qml +++ b/qml/Room.qml @@ -29,28 +29,29 @@ Page { spacing: 0 RoomListForm { - id: roomListForm - Layout.fillHeight: true Layout.preferredWidth: MSettings.miniMode ? 64 : page.width * 0.35 Layout.minimumWidth: 64 Layout.maximumWidth: 360 + id: roomListForm + listModel: roomListModel } Rectangle { Layout.preferredWidth: 1 Layout.fillHeight: true + color: MSettings.darkTheme ? "#363636" : "#ececec" } RoomForm { - id: roomForm - Layout.fillWidth: true Layout.fillHeight: true + id: roomForm + currentRoom: roomListForm.enteredRoom } } diff --git a/qml/Setting.qml b/qml/Setting.qml index d268159..2fcf080 100644 --- a/qml/Setting.qml +++ b/qml/Setting.qml @@ -58,23 +58,28 @@ Page { Page { id: generalForm + parent: null + Column { Switch { text: "Lazy load at initial sync" checked: MSettings.lazyLoad + onCheckedChanged: MSettings.lazyLoad = checked } Switch { text: "Use RichText instead of StyledText" checked: MSettings.richText + onCheckedChanged: MSettings.richText = checked } Switch { text: "Use press and hold instead of right click" checked: MSettings.pressAndHold + onCheckedChanged: MSettings.pressAndHold = checked } } @@ -82,23 +87,28 @@ Page { Page { id: appearanceForm + parent: null + Column { Switch { text: "Dark theme" checked: MSettings.darkTheme + onCheckedChanged: MSettings.darkTheme = checked } Switch { text: "Mini Room List" checked: MSettings.miniMode + onCheckedChanged: MSettings.miniMode = checked } Switch { text: "Rearrange rooms by activity" checked: MSettings.rearrangeByActivity + onCheckedChanged: MSettings.rearrangeByActivity = checked } } @@ -118,12 +128,8 @@ Page { source: "qrc:/asset/img/icon.png" } - Label { - text: "Matrique, an IM client for the Matrix protocol." - } - Label { - text: "Released under GNU General Public License, version 3." - } + Label { text: "Matrique, an IM client for the Matrix protocol." } + Label { text: "Released under GNU General Public License, version 3." } } } diff --git a/qml/component/AutoImage.qml b/qml/component/AutoImage.qml index 75fbc61..c7050de 100644 --- a/qml/component/AutoImage.qml +++ b/qml/component/AutoImage.qml @@ -6,22 +6,22 @@ Item { property alias sourceSize: baseImage.sourceSize.width readonly property bool loading: baseImage.status == Image.Loading - signal clicked() - id: rekt + signal clicked() width: loading ? 128 : baseImage.implicitWidth height: loading ? progressBar.height : baseImage.implicitHeight - Image { - id: baseImage - } + id: rekt + + Image { id: baseImage } ProgressBar { - id: progressBar width: parent.width visible: loading + id: progressBar + indeterminate: true } diff --git a/qml/component/AutoLabel.qml b/qml/component/AutoLabel.qml index 238c831..684f892 100644 --- a/qml/component/AutoLabel.qml +++ b/qml/component/AutoLabel.qml @@ -11,5 +11,6 @@ Label { wrapMode: Label.Wrap linkColor: coloredBackground ? "white" : Material.accent textFormat: MSettings.richText ? Text.RichText : Text.StyledText + onLinkActivated: Qt.openUrlExternally(link) } diff --git a/qml/component/AutoMouseArea.qml b/qml/component/AutoMouseArea.qml index 270ee25..7d0cc0e 100644 --- a/qml/component/AutoMouseArea.qml +++ b/qml/component/AutoMouseArea.qml @@ -6,6 +6,7 @@ MouseArea { signal secondaryClicked() acceptedButtons: MSettings.pressAndHold ? Qt.LeftButton : (Qt.LeftButton | Qt.RightButton) + onClicked: mouse.button == Qt.RightButton ? secondaryClicked() : primaryClicked() onPressAndHold: MSettings.pressAndHold ? secondaryClicked() : {} } diff --git a/qml/component/DownloadableContent.qml b/qml/component/DownloadableContent.qml index a0f1072..e2bbaea 100644 --- a/qml/component/DownloadableContent.qml +++ b/qml/component/DownloadableContent.qml @@ -11,20 +11,18 @@ Item { z: -2 height: parent.height width: progressInfo.active && !progressInfo.completed ? progressInfo.progress / progressInfo.total * parent.width : 0 + color: Material.accent opacity: 0.4 } - onDownloadedChanged: downloaded && openOnFinished ? openSavedFile() : {} + onDownloadedChanged: if (downloaded && openOnFinished) openSavedFile() - function saveFileAs() { - currentRoom.saveFileAs(eventId) - } + function saveFileAs() { currentRoom.saveFileAs(eventId) } function downloadAndOpen() { - if (downloaded) - openSavedFile() + if (downloaded) openSavedFile() else { openOnFinished = true @@ -34,10 +32,7 @@ Item { function openSavedFile() { - if (Qt.openUrlExternally(progressInfo.localPath)) - return; - - if (Qt.openUrlExternally(progressInfo.localDir)) - return; + if (Qt.openUrlExternally(progressInfo.localPath)) return; + if (Qt.openUrlExternally(progressInfo.localDir)) return; } } diff --git a/qml/component/EmojiPicker.qml b/qml/component/EmojiPicker.qml index 7860539..f58189a 100644 --- a/qml/component/EmojiPicker.qml +++ b/qml/component/EmojiPicker.qml @@ -52,6 +52,7 @@ Popup { Rectangle { Layout.fillWidth: true Layout.preferredHeight: 2 + color: Material.accent } diff --git a/qml/component/GenericBubble.qml b/qml/component/GenericBubble.qml index 369423e..3c754be 100644 --- a/qml/component/GenericBubble.qml +++ b/qml/component/GenericBubble.qml @@ -12,13 +12,11 @@ Control { padding: 12 - background: Rectangle { - color: colored ? Material.accent : highlighted ? Material.primary : backgroundColor - } - AutoMouseArea { anchors.fill: parent onSecondaryClicked: Qt.createComponent("qrc:/qml/menu/MessageContextMenu.qml").createObject(this) } + + background: Rectangle { color: colored ? Material.accent : highlighted ? Material.primary : backgroundColor } } diff --git a/qml/component/ImageStatus.qml b/qml/component/ImageStatus.qml index 137bb06..2144783 100644 --- a/qml/component/ImageStatus.qml +++ b/qml/component/ImageStatus.qml @@ -13,9 +13,11 @@ Item { id: item Image { - id: avatar width: item.width height: item.width + + id: avatar + visible: showImage source: item.source @@ -40,6 +42,7 @@ Item { Label { anchors.fill: parent + color: "white" visible: showInitial text: showInitial ? getInitials(displayText)[0] : "" diff --git a/qml/component/MaterialIcon.qml b/qml/component/MaterialIcon.qml index bfb4ca6..d1b2f0e 100644 --- a/qml/component/MaterialIcon.qml +++ b/qml/component/MaterialIcon.qml @@ -10,8 +10,9 @@ Item { id: item Text { - id: iconText anchors.fill: parent + + id: iconText font.pointSize: 16 font.family: materialFont.name color: item.color diff --git a/qml/component/MessageDelegate.qml b/qml/component/MessageDelegate.qml index a78ab35..745212d 100644 --- a/qml/component/MessageDelegate.qml +++ b/qml/component/MessageDelegate.qml @@ -14,10 +14,10 @@ RowLayout { signal saveFileAs() signal openExternally() - id: messageRow - z: -5 + id: messageRow + Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft spacing: 6 @@ -100,14 +100,16 @@ RowLayout { id: imageComponent DownloadableContent { - id: downloadable - width: messageImage.width height: messageImage.height + id: downloadable + AutoImage { - id: messageImage z: -4 + + id: messageImage + sourceSize: 128 source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url) diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index 60be6d9..4ec648d 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -22,11 +22,11 @@ Item { } Drawer { - id: roomDrawer - width: Math.min(item.width * 0.7, 480) height: item.height + id: roomDrawer + edge: Qt.RightEdge interactive: false @@ -51,12 +51,14 @@ Item { Label { Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter text: currentRoom && currentRoom.id ? currentRoom.id : "" } Label { Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter text: currentRoom && currentRoom.canonicalAlias ? currentRoom.canonicalAlias : "No Canonical Alias" } @@ -65,8 +67,9 @@ Item { Layout.fillWidth: true TextField { - id: roomNameField Layout.fillWidth: true + + id: roomNameField text: currentRoom && currentRoom.name ? currentRoom.name : "" } @@ -84,9 +87,10 @@ Item { Layout.fillWidth: true TextField { + Layout.fillWidth: true + id: roomTopicField - Layout.fillWidth: true text: currentRoom && currentRoom.topic ? currentRoom.topic : "" } @@ -176,6 +180,7 @@ Item { ImageStatus { Layout.preferredWidth: height Layout.fillHeight: true + source: currentRoom && currentRoom.avatarUrl != "" ? "image://mxc/" + currentRoom.avatarUrl : null displayText: currentRoom ? currentRoom.displayName : "" } @@ -222,10 +227,11 @@ Item { spacing: 0 ListView { - id: messageListView - Layout.fillWidth: true Layout.fillHeight: true + + id: messageListView + clip: true displayMarginBeginning: 40 displayMarginEnd: 40 @@ -243,13 +249,12 @@ Item { delegate: ColumnLayout { readonly property bool hidden: marks === EventStatus.Redacted || marks === EventStatus.Hidden - id: delegateColumn - width: parent.width height: hidden ? -8 : undefined - clip: true + id: delegateColumn + clip: true spacing: 8 Label { @@ -283,9 +288,7 @@ Item { topPadding: 4 bottomPadding: 4 - background: Rectangle { - color: MSettings.darkTheme ? "#484848" : "grey" - } + background: Rectangle { color: MSettings.darkTheme ? "#484848" : "grey" } } MessageDelegate { @@ -294,6 +297,7 @@ Item { StateDelegate { Layout.maximumWidth: messageListView.width * 0.8 + visible: eventType === "emote" || eventType === "state" } } @@ -304,9 +308,11 @@ Item { onAtYEndChanged: atYEnd && currentRoom ? currentRoom.markAllMessagesAsRead() : {} RoundButton { - id: goTopFab width: 64 height: 64 + + id: goTopFab + visible: !parent.atYEnd anchors.right: parent.right @@ -328,10 +334,10 @@ Item { } ScrollBar { - id: messageListViewScrollBar - Layout.preferredWidth: 16 Layout.fillHeight: true + + id: messageListViewScrollBar } } @@ -354,9 +360,11 @@ Item { TextField { property real progress: 0 - id: inputField Layout.fillWidth: true Layout.preferredHeight: 48 + + id: inputField + placeholderText: "Send a Message" leftPadding: 16 topPadding: 0 @@ -455,11 +463,11 @@ Item { } ItemDelegate { - id: emojiButton - Layout.preferredWidth: 48 Layout.preferredHeight: 48 + id: emojiButton + contentItem: MaterialIcon { icon: "\ue24e" } background: Rectangle { color: MSettings.darkTheme ? "#282828" : "#eaeaea" } @@ -467,16 +475,16 @@ Item { onClicked: emojiPicker.visible ? emojiPicker.close() : emojiPicker.open() EmojiPicker { - id: emojiPicker - - parent: ApplicationWindow.overlay - x: window.width - 370 y: window.height - 440 width: 360 height: 360 + id: emojiPicker + + parent: ApplicationWindow.overlay + textArea: inputField } } diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml index ef7a0a6..8448898 100644 --- a/qml/form/RoomListForm.qml +++ b/qml/form/RoomListForm.qml @@ -16,6 +16,7 @@ Item { Label { z: 10 + text: MSettings.miniMode ? "Empty" : "Here? No, not here." anchors.centerIn: parent visible: listView.count === 0 @@ -26,18 +27,18 @@ Item { spacing: 0 TextField { - id: searchField Layout.fillWidth: true Layout.preferredHeight: 40 Layout.margins: 12 + + id: searchField + leftPadding: MSettings.miniMode ? 4 : 32 topPadding: 0 bottomPadding: 0 placeholderText: "Search..." - background: Rectangle { - color: MSettings.darkTheme ? "#282828" : "#fafafa" - } + background: Rectangle { color: MSettings.darkTheme ? "#282828" : "#fafafa" } Shortcut { sequence: StandardKey.Find @@ -47,6 +48,7 @@ Item { SortFilterProxyModel { id: roomListProxyModel + filters: RegExpFilter { roleName: "name" pattern: searchField.text @@ -120,6 +122,7 @@ Item { Rectangle { anchors.fill: parent + visible: highlighted color: Material.accent opacity: 0.1 @@ -128,6 +131,7 @@ Item { Rectangle { width: 4 height: parent.height + color: Material.accent visible: unreadCount > 0 || highlighted } @@ -135,6 +139,7 @@ Item { RowLayout { anchors.fill: parent anchors.margins: 12 + spacing: 12 ImageStatus { @@ -179,6 +184,7 @@ Item { section.delegate: Label { width: parent.width height: 24 + text: section color: "grey" leftPadding: MSettings.miniMode ? undefined : 16 diff --git a/qml/main.qml b/qml/main.qml index a2d4186..a0a3d0a 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -13,12 +13,14 @@ import "form" ApplicationWindow { readonly property var connection: matriqueController.connection - id: window - visible: true width: 960 height: 640 minimumWidth: 800 minimumHeight: 480 + + id: window + + visible: true title: qsTr("Matrique") Material.theme: MSettings.darkTheme ? Material.Dark : Material.Light @@ -40,10 +42,11 @@ ApplicationWindow { Popup { property bool busy: matriqueController.busy - id: busyPopup - x: (window.width - width) / 2 y: (window.height - height) / 2 + + id: busyPopup + modal: true focus: true @@ -81,9 +84,11 @@ ApplicationWindow { spacing: 0 Rectangle { - id: sideNav Layout.preferredWidth: 64 Layout.fillHeight: true + + id: sideNav + color: Material.primary ColumnLayout { @@ -106,8 +111,9 @@ ApplicationWindow { } Rectangle { - color: "transparent" Layout.fillHeight: true + + color: "transparent" } SideNavButton { @@ -125,6 +131,7 @@ ApplicationWindow { Menu { id: addRoomMenu + MenuItem { text:"New Room" onTriggered: addRoomDialog.open() @@ -143,14 +150,17 @@ ApplicationWindow { contentItem: Column { TextField { - id: addRoomDialogNameTextField width: parent.width + id: addRoomDialogNameTextField + placeholderText: "Name" } TextField { - id: addRoomDialogTopicTextField width: parent.width + + id: addRoomDialogTopicTextField + placeholderText: "Topic" } } @@ -160,16 +170,18 @@ ApplicationWindow { } MenuItem { text: "Join Room" + onTriggered: joinRoomDialog.open() Dialog { - id: joinRoomDialog - parent: ApplicationWindow.overlay - x: (window.width - width) / 2 y: (window.height - height) / 2 width: 360 + id: joinRoomDialog + + parent: ApplicationWindow.overlay + title: "Input Room Alias or ID" modal: true standardButtons: Dialog.Ok | Dialog.Cancel @@ -185,16 +197,18 @@ ApplicationWindow { MenuItem { text: "Direct Chat" + onTriggered: directChatDialog.open() Dialog { - id: directChatDialog - parent: ApplicationWindow.overlay - x: (window.width - width) / 2 y: (window.height - height) / 2 width: 360 + id: directChatDialog + + parent: ApplicationWindow.overlay + title: "Input User ID" modal: true standardButtons: Dialog.Ok | Dialog.Cancel @@ -240,11 +254,12 @@ ApplicationWindow { } StackView { - id: stackView - initialItem: roomPage - Layout.fillWidth: true Layout.fillHeight: true + + id: stackView + + initialItem: roomPage } } diff --git a/qml/menu/MessageContextMenu.qml b/qml/menu/MessageContextMenu.qml index 91c8e03..1fbfa11 100644 --- a/qml/menu/MessageContextMenu.qml +++ b/qml/menu/MessageContextMenu.qml @@ -8,28 +8,33 @@ Menu { MenuItem { text: "Copy" + onTriggered: matriqueController.copyToClipboard(plainText) } MenuItem { text: "Copy Source" + onTriggered: matriqueController.copyToClipboard(toolTip) } MenuItem { visible: isFile height: visible ? undefined : 0 text: "Open Externally" + onTriggered: messageRow.openExternally() } MenuItem { visible: isFile height: visible ? undefined : 0 text: "Save As" + onTriggered: messageRow.saveFileAs() } MenuItem { visible: sentByMe height: visible ? undefined : 0 text: "Redact" + onTriggered: currentRoom.redactEvent(eventId) } diff --git a/qml/menu/RoomContextMenu.qml b/qml/menu/RoomContextMenu.qml index 280947b..9aff67f 100644 --- a/qml/menu/RoomContextMenu.qml +++ b/qml/menu/RoomContextMenu.qml @@ -8,21 +8,25 @@ Menu { text: "Favourite" checkable: true checked: currentRoom && currentRoom.isFavourite + onTriggered: currentRoom.isFavourite ? currentRoom.removeTag("m.favourite") : currentRoom.addTag("m.favourite", "1") } MenuItem { text: "Deprioritize" checkable: true checked: currentRoom && currentRoom.isLowPriority + onTriggered: currentRoom.isLowPriority ? currentRoom.removeTag("m.lowpriority") : currentRoom.addTag("m.lowpriority", "1") } MenuSeparator {} MenuItem { text: "Mark as Read" + onTriggered: currentRoom.markAllMessagesAsRead() } MenuItem { text: "Leave Room" + onTriggered: currentRoom.forget() }