Fix MessageDelegateContextMenu not being displayed

It turnout that using an QML Singleton was a bad idea, instead create a
qml object in the main component and refer to it in the rest of the
codebase.

This commit also simplify a bit the qml structure of the Menu and fix
some visual bugs.
This commit is contained in:
Carl Schwan
2020-11-16 10:00:18 +01:00
parent 523adace21
commit 6db8354727
7 changed files with 57 additions and 75 deletions

View File

@@ -14,9 +14,9 @@ import NeoChat.Dialog 1.0
Kirigami.OverlaySheet {
id: root
required property var author;
required property string message;
required property string eventId;
required property var author
required property string message
required property string eventId
signal viewSource()
signal reply(var author, string message)
@@ -29,32 +29,31 @@ Kirigami.OverlaySheet {
ColumnLayout {
spacing: 0
QQC2.Control {
leftPadding: Kirigami.Units.largeSpacing
rightPadding: Kirigami.Units.largeSpacing
RowLayout {
id: headerLayout
Layout.fillWidth: true
implicitHeight: headerLayout.implicitHeight
contentItem: RowLayout {
id: headerLayout
Layout.leftMargin: Kirigami.Units.largeSpacing
Layout.rightMargin: Kirigami.Units.largeSpacing
spacing: Kirigami.Units.largeSpacing
Kirigami.Avatar {
id: avatar
source: author.avatarMediaId ? "image://mxc/" + author.avatarMediaId : ""
Layout.preferredWidth: Kirigami.Units.gridUnit * 3
Layout.preferredHeight: Kirigami.Units.gridUnit * 3
Layout.alignment: Qt.AlignTop
}
ColumnLayout {
Layout.fillWidth: true
spacing: Kirigami.Units.largeSpacing
Kirigami.Avatar {
source: author.avatarMediaId ? "image://mxc/" + author.avatarMediaId : ""
Layout.preferredWidth: Kirigami.Units.iconSizes.large
Layout.preferredHeight: Kirigami.Units.iconSizes.large
Layout.alignment: Qt.AlignTop
}
ColumnLayout {
Kirigami.Heading {
level: 3
Layout.fillWidth: true
Kirigami.Heading {
level: 3
Layout.fillWidth: true
text: author.displayName
}
QQC2.Label {
text: message
Layout.fillWidth: true
}
text: author.displayName
wrapMode: Text.WordWrap
}
QQC2.Label {
text: message
Layout.fillWidth: true
wrapMode: Text.WordWrap
}
}
}

View File

@@ -58,7 +58,7 @@ Kirigami.ScrollablePage {
if (!identifierField.isJoined) {
Controller.joinRoom(connection, identifierField.text);
}
RoomManager.enterRoom(connection.room(identifierField.room));
roomManager.enterRoom(connection.room(identifierField.room));
applicationWindow().pageStack.layers.pop();
}
}
@@ -112,7 +112,7 @@ Kirigami.ScrollablePage {
Controller.joinRoom(connection, roomID)
justJoined = true;
} else {
RoomManager.enterRoom(connection.room(roomID))
roomManager.enterRoom(connection.room(roomID))
applicationWindow().pageStack.layers.pop();
}
}

View File

@@ -12,7 +12,6 @@ import org.kde.kirigami 2.13 as Kirigami
import org.kde.kitemmodels 1.0
import org.kde.neochat 1.0
import NeoChat 1.0
import NeoChat.Component 1.0
import NeoChat.Menu 1.0
@@ -135,7 +134,7 @@ Kirigami.ScrollablePage {
if (mouse.button == Qt.RightButton) {
roomListContextMenu.createObject(parent, {"room": currentRoom}).popup()
} else {
RoomManager.enterRoom(currentRoom)
roomManager.enterRoom(currentRoom)
}
}
}

View File

@@ -1,40 +0,0 @@
/**
* SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.eu>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
pragma Singleton
import QtQuick 2.14
import NeoChat.Page 1.0
/**
* Manage opening and close rooms
*/
Item {
id: openRoomAction
property var currentRoom: null
property var pageStack: null
readonly property bool hasOpenRoom: currentRoom != null
signal leaveRoom(string room);
signal openRoom(string room);
function enterRoom(room) {
if (currentRoom != null) {
currentRoom = null;
pageStack.removePage(pageStack.lastItem);
}
pageStack.push(roomPage, {"currentRoom": room});
currentRoom = room;
}
Component {
id: roomPage
RoomPage {}
}
}

View File

@@ -1 +0,0 @@
singleton RoomManager 1.0 RoomManager.qml

View File

@@ -11,7 +11,6 @@ import QtQuick.Layouts 1.14
import org.kde.kirigami 2.12 as Kirigami
import org.kde.neochat 1.0
import NeoChat 1.0
import NeoChat.Component 1.0
import NeoChat.Panel 1.0
import NeoChat.Dialog 1.0
@@ -22,7 +21,35 @@ Kirigami.ApplicationWindow {
id: root
property var currentRoom: null
Component.onCompleted: RoomManager.pageStack = root.pageStack
/**
* Manage opening and close rooms
*/
Item {
id: roomManager
property var currentRoom: null
property alias pageStack: root.pageStack
readonly property bool hasOpenRoom: currentRoom != null
signal leaveRoom(string room);
signal openRoom(string room);
function enterRoom(room) {
if (currentRoom != null) {
currentRoom = null;
pageStack.removePage(pageStack.lastItem);
}
pageStack.push(roomPage, { 'currentRoom': room, });
currentRoom = room;
}
Component {
id: roomPage
RoomPage {}
}
}
contextDrawer: RoomDrawer {
id: contextDrawer

View File

@@ -3,8 +3,6 @@
<file>assets/img/matrix.svg</file>
<file>assets/img/icon.png</file>
<file>qml/main.qml</file>
<file>imports/NeoChat/qmldir</file>
<file>imports/NeoChat/RoomManager.qml</file>
<file>imports/NeoChat/Page/qmldir</file>
<file>imports/NeoChat/Page/LoginPage.qml</file>
<file>imports/NeoChat/Page/LoadingPage.qml</file>