From bbf29e29b18d3e049fb45b8623b4ec9e74b41df2 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 21 Apr 2019 10:44:04 -0400 Subject: [PATCH] Add InviteOffer component --- TODO.md | 4 ++ harmonyqml/backend/backend.py | 6 ++ harmonyqml/components/UI.qml | 8 +-- harmonyqml/components/base/HButton.qml | 11 +++ harmonyqml/components/base/HRowLayout.qml | 11 +++ harmonyqml/components/chat/InviteOffer.qml | 80 ++++++++++++++++++++++ harmonyqml/components/chat/Root.qml | 22 ++++-- harmonyqml/components/chat/SendBox.qml | 1 + harmonyqml/icons/accept.svg | 1 + harmonyqml/icons/decline.svg | 1 + 10 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 harmonyqml/components/base/HButton.qml create mode 100644 harmonyqml/components/base/HRowLayout.qml create mode 100644 harmonyqml/components/chat/InviteOffer.qml create mode 100644 harmonyqml/icons/accept.svg create mode 100644 harmonyqml/icons/decline.svg diff --git a/TODO.md b/TODO.md index 363a6bdc..95441728 100644 --- a/TODO.md +++ b/TODO.md @@ -15,8 +15,12 @@ - ![A picture](https://picsum.photos/256/256) not clickable? - UI + - Use HRowLayout and its totalSpacing wherever possible + - Spacer component - One line label componant + - Proper button background componant - Collapsible roomList sections, + button + - Prevent using the SendBox if no permission (power levels) - Reorganize SidePane - Proper theme, with components taking their colors from theme settings - Settings page diff --git a/harmonyqml/backend/backend.py b/harmonyqml/backend/backend.py index 9c1f537e..d3fd24cf 100644 --- a/harmonyqml/backend/backend.py +++ b/harmonyqml/backend/backend.py @@ -103,6 +103,12 @@ class Backend(QObject): def pdb(self, additional_data: Sequence = ()) -> None: # pylint: disable=all ad = additional_data + cm = self.clientManager + cl = self.clientManager.clients + m = self.models + + tcl = lambda user: cl[f"@test_{user}:matrix.org"] + import pdb from PyQt5.QtCore import pyqtRemoveInputHook pyqtRemoveInputHook() diff --git a/harmonyqml/components/UI.qml b/harmonyqml/components/UI.qml index b637b896..738dd2c1 100644 --- a/harmonyqml/components/UI.qml +++ b/harmonyqml/components/UI.qml @@ -15,7 +15,7 @@ Controls1.SplitView { } StackView { - function showRoom(userId, roomId) { + function showRoom(userId, roomId, isInvite) { pageStack.replace( "chat/Root.qml", { userId: userId, roomId: roomId } ) @@ -26,9 +26,9 @@ Controls1.SplitView { onCurrentItemChanged: currentItem.forceActiveFocus() - initialItem: MouseArea { // TODO: (test, remove) - onClicked: pageStack.showRoom( - "@test_mary:matrix.org", "!VDSsFIzQnXARSCVNxS:matrix.org" + initialItem: Item { // TODO: (test, remove) + Keys.onPressed: pageStack.showRoom( + "@test_mary:matrix.org", "!TSXGsbBbdwsdylIOJZ:matrix.org" ) } diff --git a/harmonyqml/components/base/HButton.qml b/harmonyqml/components/base/HButton.qml new file mode 100644 index 00000000..cdb3b04e --- /dev/null +++ b/harmonyqml/components/base/HButton.qml @@ -0,0 +1,11 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.4 + +Button { + property string iconName: "" + + id: button + display: Button.TextBesideIcon + icon.source: "../../icons/" + iconName + ".svg" +} diff --git a/harmonyqml/components/base/HRowLayout.qml b/harmonyqml/components/base/HRowLayout.qml new file mode 100644 index 00000000..e96bc281 --- /dev/null +++ b/harmonyqml/components/base/HRowLayout.qml @@ -0,0 +1,11 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.4 + +RowLayout { + id: rowLayout + spacing: 0 + + property int totalSpacing: + spacing * Math.max(0, (rowLayout.visibleChildren.length - 1)) +} diff --git a/harmonyqml/components/chat/InviteOffer.qml b/harmonyqml/components/chat/InviteOffer.qml new file mode 100644 index 00000000..a7701ee8 --- /dev/null +++ b/harmonyqml/components/chat/InviteOffer.qml @@ -0,0 +1,80 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.4 +import "../base" as Base + +Rectangle { + id: inviteOffer + Layout.fillWidth: true + Layout.preferredHeight: 32 + color: "#BBB" + + Base.HRowLayout { + id: inviteRow + anchors.fill: parent + + Base.Avatar { + id: inviteAvatar + name: "" + dimmension: inviteOffer.Layout.preferredHeight + } + + Base.HLabel { + id: inviteLabel + text: "" + "Person" + " " + + qsTr("invited you to join the room.") + textFormat: Text.StyledText + maximumLineCount: 1 + elide: Text.ElideRight + + visible: + inviteRow.width - inviteAvatar.width - inviteButtons.width > 30 + + Layout.maximumWidth: + inviteRow.width - + inviteAvatar.width - inviteButtons.width - + Layout.leftMargin - Layout.rightMargin + + Layout.leftMargin: 10 + Layout.rightMargin: Layout.leftMargin + } + + Item { Layout.fillWidth: true } + + Base.HRowLayout { + id: inviteButtons + spacing: 0 + + property bool compact: + inviteRow.width < + inviteAvatar.width + inviteLabel.implicitWidth + + acceptButton.implicitWidth + declineButton.implicitWidth + + property int displayMode: + compact ? Button.IconOnly : Button.TextBesideIcon + + Base.HButton { + id: acceptButton + text: qsTr("Accept") + iconName: "accept" + icon.color: Qt.hsla(0.45, 0.9, 0.3, 1) + display: inviteButtons.displayMode + + Layout.maximumWidth: inviteButtons.compact ? height : -1 + Layout.fillHeight: true + } + + Base.HButton { + id: declineButton + text: qsTr("Decline") + iconName: "decline" + icon.color: Qt.hsla(0.95, 0.9, 0.35, 1) + icon.width: 32 + display: inviteButtons.displayMode + + Layout.maximumWidth: inviteButtons.compact ? height : -1 + Layout.fillHeight: true + } + } + } +} diff --git a/harmonyqml/components/chat/Root.qml b/harmonyqml/components/chat/Root.qml index 523153fa..208d769d 100644 --- a/harmonyqml/components/chat/Root.qml +++ b/harmonyqml/components/chat/Root.qml @@ -3,23 +3,35 @@ import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 ColumnLayout { - property var userId: null - property var roomId: null + property string userId: "" + property string roomId: "" - property var roomInfo: + readonly property var roomInfo: Backend.models.rooms.get(userId).getWhere("roomId", roomId) + property bool isInvite: roomInfo.category === "Invites" + id: chatPage spacing: 0 onFocusChanged: sendBox.setFocus() RoomHeader { - id: roomHeader displayName: roomInfo.displayName topic: roomInfo.topic } + MessageList {} + + TypingUsersBar {} - SendBox { id: sendBox } + + InviteOffer { + visible: isInvite + } + + SendBox { + id: sendBox + visible: ! isInvite + } } diff --git a/harmonyqml/components/chat/SendBox.qml b/harmonyqml/components/chat/SendBox.qml index cf59b940..80734900 100644 --- a/harmonyqml/components/chat/SendBox.qml +++ b/harmonyqml/components/chat/SendBox.qml @@ -39,6 +39,7 @@ Rectangle { placeholderText: qsTr("Type a message...") wrapMode: TextEdit.Wrap selectByMouse: true + readOnly: ! visible font.family: "Roboto" font.pixelSize: 16 focus: true diff --git a/harmonyqml/icons/accept.svg b/harmonyqml/icons/accept.svg new file mode 100644 index 00000000..9d13fa19 --- /dev/null +++ b/harmonyqml/icons/accept.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/harmonyqml/icons/decline.svg b/harmonyqml/icons/decline.svg new file mode 100644 index 00000000..a7c8b2c0 --- /dev/null +++ b/harmonyqml/icons/decline.svg @@ -0,0 +1 @@ + \ No newline at end of file