From 640b0ee4057a0993a515d7db7c875d314aab9bdf Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 3 Sep 2020 17:01:58 +0200 Subject: Port top bar to Qml Also fixes some resize issues with stupid workarounds to our resize logic. This really needs to be cleaned up at some point! --- resources/qml/Avatar.qml | 2 + resources/qml/TimelineView.qml | 135 ++++++++++++++++++++++++++++++++++------- 2 files changed, 116 insertions(+), 21 deletions(-) (limited to 'resources/qml') diff --git a/resources/qml/Avatar.qml b/resources/qml/Avatar.qml index f934e2f6..0c4343c7 100644 --- a/resources/qml/Avatar.qml +++ b/resources/qml/Avatar.qml @@ -50,6 +50,8 @@ Rectangle { anchors.bottom: avatar.bottom anchors.right: avatar.right + visible: !!userid + height: avatar.height / 6 width: height radius: settings.avatarCircles ? height / 2 : height / 4 diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index dd9c4029..ea85acf9 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -115,6 +115,112 @@ Page { z: 3 } + ColumnLayout { + anchors.fill: parent + Rectangle { + id: topBar + + Layout.fillWidth: true + implicitHeight: topLayout.height + 16 + z: 3 + + color: colors.base + + GridLayout { + id: topLayout + + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 8 + anchors.verticalCenter: parent.verticalCenter + + //Layout.margins: 8 + + ImageButton { + id: backToRoomsButton + + Layout.column: 0 + Layout.row: 0 + Layout.rowSpan: 2 + Layout.alignment: Qt.AlignVCenter + + visible: timelineManager.isNarrowView + + image: ":/icons/icons/ui/angle-pointing-to-left.png" + + ToolTip.visible: hovered + ToolTip.text: qsTr("Back to room list") + + onClicked: timelineManager.backToRooms() + } + + Avatar { + Layout.column: 1 + Layout.row: 0 + Layout.rowSpan: 2 + Layout.alignment: Qt.AlignVCenter + + width: avatarSize + height: avatarSize + url: chat.model.roomAvatarUrl.replace("mxc://", "image://MxcImage/") + displayName: chat.model.roomName + } + + Label { + Layout.fillWidth: true + Layout.column: 2 + Layout.row: 0 + + font.pointSize: fontMetrics.font.pointSize * 1.1 + text: chat.model.roomName + } + MatrixText { + Layout.fillWidth: true + Layout.column: 2 + Layout.row: 1 + text: chat.model.roomTopic + Layout.maximumHeight: fontMetrics.lineSpacing * 2 // show 2 lines + clip: true + } + + ImageButton { + id: roomOptionsButton + + Layout.column: 3 + Layout.row: 0 + Layout.rowSpan: 2 + Layout.alignment: Qt.AlignVCenter + + image: ":/icons/icons/ui/vertical-ellipsis.png" + + ToolTip.visible: hovered + ToolTip.text: qsTr("Room options") + + onClicked: roomOptionsMenu.popup(roomOptionsButton) + + Menu { + id: roomOptionsMenu + MenuItem { + text: qsTr("Invite users") + onTriggered: timelineManager.openInviteUsersDialog(); + } + MenuItem { + text: qsTr("Members") + onTriggered: timelineManager.openMemberListDialog(); + } + MenuItem { + text: qsTr("Leave room") + onTriggered: timelineManager.openLeaveRoomDialog(); + } + MenuItem { + text: qsTr("Settings") + onTriggered: timelineManager.openRoomSettings(); + } + } + } + } + } + ListView { id: chat @@ -122,13 +228,8 @@ Page { cacheBuffer: 400 - anchors.horizontalCenter: parent.horizontalCenter - anchors.top: parent.top - anchors.bottom: chatFooter.top - width: parent.width - - anchors.leftMargin: 4 - anchors.rightMargin: scrollbar.width + Layout.fillWidth: true + Layout.fillHeight: true model: timelineManager.timeline @@ -167,10 +268,6 @@ Page { ScrollBar.vertical: ScrollBar { id: scrollbar - parent: chat.parent - anchors.top: chat.top - anchors.right: chat.right - anchors.bottom: chat.bottom } spacing: 4 @@ -178,9 +275,9 @@ Page { onCountChanged: if (atYEnd) model.currentIndex = 0 // Mark last event as read, since we are at the bottom - property int delegateMaxWidth: (settings.timelineMaxWidth > 100 && (parent.width - settings.timelineMaxWidth) > 32) ? settings.timelineMaxWidth : (parent.width - 32) + property int delegateMaxWidth: (settings.timelineMaxWidth > 100 && (parent.width - settings.timelineMaxWidth) > scrollbar.width*2) ? settings.timelineMaxWidth : (parent.width - scrollbar.width*2) - delegate: Rectangle { + delegate: Item { // This would normally be previousSection, but our model's order is inverted. property bool sectionBoundary: (ListView.nextSection != "" && ListView.nextSection !== ListView.section) || model.index === chat.count - 1 @@ -189,7 +286,6 @@ Page { anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined width: chat.delegateMaxWidth height: section ? section.height + timelinerow.height : timelinerow.height - color: "transparent" TimelineRow { id: timelinerow @@ -309,17 +405,13 @@ Page { } } - Rectangle { + Item { id: chatFooter - height: Math.max(fontMetrics.height * 1.2, footerContent.height) - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom + implicitHeight: Math.max(fontMetrics.height * 1.2, footerContent.height) + Layout.fillWidth: true z: 3 - color: "transparent" - Column { id: footerContent anchors.left: parent.left @@ -382,4 +474,5 @@ Page { } } } + } } -- cgit 1.5.1 From 77e241b9e57a3248e2efb16e6cb081a19a666db7 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 3 Sep 2020 19:34:17 +0200 Subject: Reenable top bar room settings menus on avatar or title clicks Also fixes a bug with an empty room settings window introduced in the port. --- resources/qml/TimelineView.qml | 15 +++++++++++++++ src/ChatPage.cpp | 3 +++ src/MainWindow.cpp | 13 ++++--------- src/MainWindow.h | 6 +++--- src/timeline/TimelineModel.h | 1 + src/timeline/TimelineViewManager.cpp | 6 +++--- 6 files changed, 29 insertions(+), 15 deletions(-) (limited to 'resources/qml') diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index ea85acf9..49f523a5 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -126,6 +126,11 @@ Page { color: colors.base + MouseArea { + anchors.fill: parent + onClicked: timelineManager.openRoomSettings(); + } + GridLayout { id: topLayout @@ -164,6 +169,11 @@ Page { height: avatarSize url: chat.model.roomAvatarUrl.replace("mxc://", "image://MxcImage/") displayName: chat.model.roomName + + MouseArea { + anchors.fill: parent + onClicked: timelineManager.openRoomSettings(); + } } Label { @@ -173,6 +183,11 @@ Page { font.pointSize: fontMetrics.font.pointSize * 1.1 text: chat.model.roomName + + MouseArea { + anchors.fill: parent + onClicked: timelineManager.openRoomSettings(); + } } MatrixText { Layout.fillWidth: true diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 1339f353..cf1a6062 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -225,6 +225,9 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) } }); + connect(room_list_, &RoomList::roomChanged, this, [this](QString room_id) { + this->current_room_ = room_id; + }); connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::stopTyping); connect(room_list_, &RoomList::roomChanged, splitter, &Splitter::showChatView); connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::focusLineEdit); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 90bffa70..29abed86 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -340,9 +340,7 @@ MainWindow::openUserProfile(const QString &user_id, const QString &room_id) void MainWindow::openRoomSettings(const QString &room_id) { - const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : ""; - - auto dialog = new dialogs::RoomSettings(roomToSearch, this); + auto dialog = new dialogs::RoomSettings(room_id, this); showDialog(dialog); } @@ -350,8 +348,7 @@ MainWindow::openRoomSettings(const QString &room_id) void MainWindow::openMemberListDialog(const QString &room_id) { - const auto roomToSearch = room_id.isEmpty() ? chat_page_->currentRoom() : ""; - auto dialog = new dialogs::MemberList(roomToSearch, this); + auto dialog = new dialogs::MemberList(room_id, this); showDialog(dialog); } @@ -359,11 +356,9 @@ MainWindow::openMemberListDialog(const QString &room_id) void MainWindow::openLeaveRoomDialog(const QString &room_id) { - auto roomToLeave = room_id.isEmpty() ? chat_page_->currentRoom() : room_id; - auto dialog = new dialogs::LeaveRoom(this); - connect(dialog, &dialogs::LeaveRoom::leaving, this, [this, roomToLeave]() { - chat_page_->leaveRoom(roomToLeave); + connect(dialog, &dialogs::LeaveRoom::leaving, this, [this, room_id]() { + chat_page_->leaveRoom(room_id); }); showDialog(dialog); diff --git a/src/MainWindow.h b/src/MainWindow.h index e3e04698..4f54a195 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -68,14 +68,14 @@ public: static MainWindow *instance() { return instance_; }; void saveCurrentWindowSize(); - void openLeaveRoomDialog(const QString &room_id = ""); + void openLeaveRoomDialog(const QString &room_id); void openInviteUsersDialog(std::function callback); void openCreateRoomDialog( std::function callback); void openJoinRoomDialog(std::function callback); void openLogoutDialog(); - void openRoomSettings(const QString &room_id = ""); - void openMemberListDialog(const QString &room_id = ""); + void openRoomSettings(const QString &room_id); + void openMemberListDialog(const QString &room_id); void openUserProfile(const QString &user_id, const QString &room_id); void openReadReceiptsDialog(const QString &event_id); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 34f2f78a..1e482be2 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -260,6 +260,7 @@ public slots: QString roomName() const; QString roomTopic() const; QString roomAvatarUrl() const; + QString roomId() const { return room_id_; } private slots: void addPendingMessage(mtx::events::collections::TimelineEvents event); diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 32d8b0b2..06f0fa3d 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -253,17 +253,17 @@ TimelineViewManager::openInviteUsersDialog() void TimelineViewManager::openMemberListDialog() const { - MainWindow::instance()->openMemberListDialog(); + MainWindow::instance()->openMemberListDialog(timeline_->roomId()); } void TimelineViewManager::openLeaveRoomDialog() const { - MainWindow::instance()->openLeaveRoomDialog(); + MainWindow::instance()->openLeaveRoomDialog(timeline_->roomId()); } void TimelineViewManager::openRoomSettings() const { - MainWindow::instance()->openRoomSettings(); + MainWindow::instance()->openRoomSettings(timeline_->roomId()); } void -- cgit 1.5.1 From b05c10102148a388a5abedc890db52abc70d71b5 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 3 Sep 2020 19:51:50 +0200 Subject: Fix null errors in qml --- resources/qml/Avatar.qml | 2 +- resources/qml/TimelineView.qml | 13 ++++++++----- resources/qml/delegates/MessageDelegate.qml | 2 +- resources/qml/delegates/Reply.qml | 2 +- src/timeline/TimelineModel.cpp | 18 ++++++------------ src/timeline/TimelineModel.h | 1 - src/timeline/TimelineViewManager.cpp | 6 ++++++ src/timeline/TimelineViewManager.h | 1 + 8 files changed, 24 insertions(+), 21 deletions(-) (limited to 'resources/qml') diff --git a/resources/qml/Avatar.qml b/resources/qml/Avatar.qml index 0c4343c7..a3943806 100644 --- a/resources/qml/Avatar.qml +++ b/resources/qml/Avatar.qml @@ -14,7 +14,7 @@ Rectangle { Label { anchors.fill: parent - text: chat.model.escapeEmoji(String.fromCodePoint(displayName.codePointAt(0))) + text: timelineManager.escapeEmoji(String.fromCodePoint(displayName.codePointAt(0))) textFormat: Text.RichText font.pixelSize: avatar.height/2 verticalAlignment: Text.AlignVCenter diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 49f523a5..e4643635 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -167,8 +167,9 @@ Page { width: avatarSize height: avatarSize - url: chat.model.roomAvatarUrl.replace("mxc://", "image://MxcImage/") - displayName: chat.model.roomName + + url: chat.model ? chat.model.roomAvatarUrl.replace("mxc://", "image://MxcImage/") : "" + displayName: chat.model ? chat.model.roomName : qsTr("No room selected") MouseArea { anchors.fill: parent @@ -182,7 +183,8 @@ Page { Layout.row: 0 font.pointSize: fontMetrics.font.pointSize * 1.1 - text: chat.model.roomName + + text: chat.model ? chat.model.roomName : qsTr("No room selected") MouseArea { anchors.fill: parent @@ -193,9 +195,10 @@ Page { Layout.fillWidth: true Layout.column: 2 Layout.row: 1 - text: chat.model.roomTopic Layout.maximumHeight: fontMetrics.lineSpacing * 2 // show 2 lines clip: true + + text: chat.model ? chat.model.roomTopic : "" } ImageButton { @@ -387,7 +390,7 @@ Page { Label { id: userName - text: chat.model.escapeEmoji(modelData.userName) + text: timelineManager.escapeEmoji(modelData.userName) color: timelineManager.userColor(modelData.userId, colors.window) textFormat: Text.RichText diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 56b8040e..90e52442 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -36,7 +36,7 @@ Item { DelegateChoice { roleValue: MtxEvent.EmoteMessage NoticeMessage { - formatted: chat.model.escapeEmoji(modelData.userName) + " " + model.data.formattedBody + formatted: timelineManager.escapeEmoji(modelData.userName) + " " + model.data.formattedBody color: timelineManager.userColor(modelData.userId, colors.window) } } diff --git a/resources/qml/delegates/Reply.qml b/resources/qml/delegates/Reply.qml index f9fd3f11..36a6d373 100644 --- a/resources/qml/delegates/Reply.qml +++ b/resources/qml/delegates/Reply.qml @@ -37,7 +37,7 @@ Item { Text { id: userName - text: chat.model ? chat.model.escapeEmoji(reply.modelData.userName) : "" + text: timelineManager.escapeEmoji(reply.modelData.userName) color: replyComponent.userColor textFormat: Text.RichText diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index f596a587..32e9f92c 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -719,12 +719,6 @@ TimelineModel::formatDateSeparator(QDate date) const return date.toString(fmt); } -QString -TimelineModel::escapeEmoji(QString str) const -{ - return utils::replaceEmoji(str); -} - void TimelineModel::viewRawMessage(QString id) const { @@ -1389,7 +1383,7 @@ TimelineModel::formatTypingUsers(const std::vector &users, QColor bg) QStringList uidWithoutLast; auto formatUser = [this, bg](const QString &user_id) -> QString { - auto uncoloredUsername = escapeEmoji(displayName(user_id)); + auto uncoloredUsername = utils::replaceEmoji(displayName(user_id)); QString prefix = QString("").arg(manager_->userColor(user_id, bg).name()); @@ -1439,7 +1433,7 @@ TimelineModel::formatJoinRuleEvent(QString id) return ""; QString user = QString::fromStdString(event->sender); - QString name = escapeEmoji(displayName(user)); + QString name = utils::replaceEmoji(displayName(user)); switch (event->content.join_rule) { case mtx::events::state::JoinRule::Public: @@ -1464,7 +1458,7 @@ TimelineModel::formatGuestAccessEvent(QString id) return ""; QString user = QString::fromStdString(event->sender); - QString name = escapeEmoji(displayName(user)); + QString name = utils::replaceEmoji(displayName(user)); switch (event->content.guest_access) { case mtx::events::state::AccessState::CanJoin: @@ -1489,7 +1483,7 @@ TimelineModel::formatHistoryVisibilityEvent(QString id) return ""; QString user = QString::fromStdString(event->sender); - QString name = escapeEmoji(displayName(user)); + QString name = utils::replaceEmoji(displayName(user)); switch (event->content.history_visibility) { case mtx::events::state::Visibility::WorldReadable: @@ -1522,7 +1516,7 @@ TimelineModel::formatPowerLevelEvent(QString id) return ""; QString user = QString::fromStdString(event->sender); - QString name = escapeEmoji(displayName(user)); + QString name = utils::replaceEmoji(displayName(user)); // TODO: power levels rendering is actually a bit complex. work on this later. return tr("%1 has changed the room's permissions.").arg(name); @@ -1551,7 +1545,7 @@ TimelineModel::formatMemberEvent(QString id) } QString user = QString::fromStdString(event->state_key); - QString name = escapeEmoji(displayName(user)); + QString name = utils::replaceEmoji(displayName(user)); QString rendered; // see table https://matrix.org/docs/spec/client_server/latest#m-room-member diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 1e482be2..6daaac1b 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -197,7 +197,6 @@ public: Q_INVOKABLE QString formatGuestAccessEvent(QString id); Q_INVOKABLE QString formatPowerLevelEvent(QString id); - Q_INVOKABLE QString escapeEmoji(QString str) const; Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void viewDecryptedRawMessage(QString id) const; Q_INVOKABLE void openUserProfile(QString userid) const; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 06f0fa3d..abb807b3 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -206,6 +206,12 @@ TimelineViewManager::setHistoryView(const QString &room_id) } } +QString +TimelineViewManager::escapeEmoji(QString str) const +{ + return utils::replaceEmoji(str); +} + void TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId) const { diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 2de94b77..1a98f64d 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -50,6 +50,7 @@ public: bool isNarrowView() const { return isNarrowView_; } Q_INVOKABLE void openImageOverlay(QString mxcUrl, QString eventId) const; Q_INVOKABLE QColor userColor(QString id, QColor background); + Q_INVOKABLE QString escapeEmoji(QString str) const; Q_INVOKABLE QString userPresence(QString id) const; Q_INVOKABLE QString userStatus(QString id) const; -- cgit 1.5.1