From 5e3f18e320a698670c41bcf3b0e87bb3702313e0 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Tue, 7 Aug 2018 23:41:18 +0800 Subject: [PATCH] Code cleanup && speed up initial sync. --- qml/Room.qml | 2 +- qml/component/ImageBubble.qml | 11 ----- qml/component/MessageContextMenu.qml | 33 +++++++++++++++ qml/component/MessageDelegate.qml | 38 +---------------- qml/form/RoomListForm.qml | 61 +++++++++++++--------------- qml/main.qml | 21 +--------- res.qrc | 1 + src/roomlistmodel.cpp | 1 - 8 files changed, 66 insertions(+), 102 deletions(-) create mode 100644 qml/component/MessageContextMenu.qml diff --git a/qml/Room.qml b/qml/Room.qml index 9a8e3f7..cb030b8 100644 --- a/qml/Room.qml +++ b/qml/Room.qml @@ -15,7 +15,7 @@ Page { 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 { diff --git a/qml/component/ImageBubble.qml b/qml/component/ImageBubble.qml index 5fd8868..be929d8 100644 --- a/qml/component/ImageBubble.qml +++ b/qml/component/ImageBubble.qml @@ -26,17 +26,6 @@ AvatarContainer { z: -4 sourceSize.width: 128 source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url) - - MouseArea { - anchors.fill: parent - - hoverEnabled: true - propagateComposedEvents: true - ToolTip.visible: containsMouse - ToolTip.text: content.body - - onClicked: downloadable.downloadAndOpen() - } } } } diff --git a/qml/component/MessageContextMenu.qml b/qml/component/MessageContextMenu.qml new file mode 100644 index 0000000..5eab2d8 --- /dev/null +++ b/qml/component/MessageContextMenu.qml @@ -0,0 +1,33 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 + +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: delegateLoader.item.downloadAndOpen() + } + MenuItem { + visible: isFile + height: visible ? undefined : 0 + text: "Save As" + onTriggered: delegateLoader.item.saveFileAs() + } + MenuItem { + visible: sentByMe + height: visible ? undefined : 0 + text: "Redact" + onTriggered: currentRoom.redactEvent(eventId) + } + + Component.onCompleted: popup() +} diff --git a/qml/component/MessageDelegate.qml b/qml/component/MessageDelegate.qml index e0515de..d108ba9 100644 --- a/qml/component/MessageDelegate.qml +++ b/qml/component/MessageDelegate.qml @@ -25,43 +25,7 @@ Item { MouseArea { anchors.fill: parent - onPressAndHold: menuComponent.createObject(this) - - Component { - id: menuComponent - Menu { - id: messageContextMenu - - 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: delegateLoader.item.downloadAndOpen() - } - MenuItem { - visible: isFile - height: visible ? undefined : 0 - text: "Save As" - onTriggered: delegateLoader.item.saveFileAs() - } - MenuItem { - visible: sentByMe - height: visible ? undefined : 0 - text: "Redact" - onTriggered: currentRoom.redactEvent(eventId) - } - - Component.onCompleted: popup() - } - } + onPressAndHold: Qt.createComponent("MessageContextMenu.qml").createObject(this) } Loader { diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml index 1cef370..0eb95b5 100644 --- a/qml/form/RoomListForm.qml +++ b/qml/form/RoomListForm.qml @@ -139,7 +139,7 @@ Item { height: 80 onPressed: listView.currentIndex = index onClicked: enterRoom() - onPressAndHold: menuComponent.createObject(this) + onPressAndHold: roomListMenu.popup() ToolTip.visible: mini && hovered ToolTip.text: name @@ -191,37 +191,6 @@ Item { } } } - - Component { - id: menuComponent - Menu { - id: roomListMenu - - MenuItem { - text: "Favourite" - checkable: true - checked: currentRoom.isFavourite - onTriggered: currentRoom.isFavourite ? currentRoom.removeTag("m.favourite") : currentRoom.addTag("m.favourite", "1") - } - MenuItem { - text: "Deprioritize" - checkable: true - checked: 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: matriqueController.forgetRoom(currentRoom.id) - } - - Component.onCompleted: popup() - } - } } section.property: "category" @@ -240,7 +209,35 @@ Item { color: Material.theme == Material.Light ? "#dbdbdb" : "#363636" } } + + Menu { + id: roomListMenu + + MenuItem { + 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: matriqueController.forgetRoom(currentRoom.id) + } + } } } } + + onCurrentRoomChanged: if (currentRoom && !currentRoom.timelineSize) currentRoom.getPreviousContent(50) } diff --git a/qml/main.qml b/qml/main.qml index d28a020..5736e2b 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -42,18 +42,6 @@ ApplicationWindow { visible: true iconSource: "qrc:/asset/img/icon.png" - menu: Platform.Menu { - MenuItem { - text: "Hide/Show" - onTriggered: window.active ? window.hide() : raiseWindow() - } - - MenuItem { - text: "Quit" - onTriggered: Qt.quit() - } - } - onActivated: window.active ? window.hide() : raiseWindow() function raiseWindow() { @@ -65,10 +53,6 @@ ApplicationWindow { Controller { id: matriqueController - onErrorOccured: { - errorDialog.text = err; - errorDialog.open(); - } } Popup { @@ -85,10 +69,7 @@ ApplicationWindow { BusyIndicator { running: true } - onBusyChanged: { - if(busyPopup.busy) { busyPopup.open(); } - else { busyPopup.close(); } - } + onBusyChanged: busyPopup.busy ? busyPopup.open() : busyPopup.close() } Component { diff --git a/res.qrc b/res.qrc index e5a201b..e7ae79b 100644 --- a/res.qrc +++ b/res.qrc @@ -30,5 +30,6 @@ qml/form/SettingAccountForm.qml qml/form/SettingAppearanceForm.qml qml/component/TextDelegate.qml + qml/component/MessageContextMenu.qml diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index 49029f3..bb6018b 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -42,7 +42,6 @@ void RoomListModel::doAddRoom(Room* r) { if (auto* room = r) { m_rooms.append(room); connectRoomSignals(room); - if (room->timelineSize() == 0) room->getPreviousContent(50); } else { qCritical() << "Attempt to add nullptr to the room list"; Q_ASSERT(false);