From 4d8b8c3b816528ece6274bac97d30905f77aabfb Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 22 Jun 2023 19:54:17 +0200 Subject: Create an EventDelegateChooser --- src/timeline/EventDelegateChooser.cpp | 244 ++++++++++++++++++++++++++++++++++ src/timeline/EventDelegateChooser.h | 136 +++++++++++++++++++ src/timeline/TimelineModel.cpp | 20 +++ src/timeline/TimelineModel.h | 2 + 4 files changed, 402 insertions(+) create mode 100644 src/timeline/EventDelegateChooser.cpp create mode 100644 src/timeline/EventDelegateChooser.h (limited to 'src') diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp new file mode 100644 index 00000000..7618e20b --- /dev/null +++ b/src/timeline/EventDelegateChooser.cpp @@ -0,0 +1,244 @@ +// SPDX-FileCopyrightText: Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "EventDelegateChooser.h" +#include "TimelineModel.h" + +#include "Logging.h" + +#include +#include + +// privat qt headers to access required properties +#include +#include + +QQmlComponent * +EventDelegateChoice::delegate() const +{ + return delegate_; +} + +void +EventDelegateChoice::setDelegate(QQmlComponent *delegate) +{ + if (delegate != delegate_) { + delegate_ = delegate; + emit delegateChanged(); + emit changed(); + } +} + +QList +EventDelegateChoice::roleValues() const +{ + return roleValues_; +} + +void +EventDelegateChoice::setRoleValues(const QList &value) +{ + if (value != roleValues_) { + roleValues_ = value; + emit roleValuesChanged(); + emit changed(); + } +} + +QQmlListProperty +EventDelegateChooser::choices() +{ + return QQmlListProperty(this, + this, + &EventDelegateChooser::appendChoice, + &EventDelegateChooser::choiceCount, + &EventDelegateChooser::choice, + &EventDelegateChooser::clearChoices); +} + +void +EventDelegateChooser::appendChoice(QQmlListProperty *p, EventDelegateChoice *c) +{ + EventDelegateChooser *dc = static_cast(p->object); + dc->choices_.append(c); +} + +qsizetype +EventDelegateChooser::choiceCount(QQmlListProperty *p) +{ + return static_cast(p->object)->choices_.count(); +} +EventDelegateChoice * +EventDelegateChooser::choice(QQmlListProperty *p, qsizetype index) +{ + return static_cast(p->object)->choices_.at(index); +} +void +EventDelegateChooser::clearChoices(QQmlListProperty *p) +{ + static_cast(p->object)->choices_.clear(); +} + +void +EventDelegateChooser::componentComplete() +{ + QQuickItem::componentComplete(); + // eventIncubator.reset(eventIndex); +} + +void +EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) +{ + auto item = qobject_cast(obj); + if (!item) + return; + + item->setParentItem(&chooser); + + auto roleNames = chooser.room_->roleNames(); + QHash nameToRole; + for (const auto &[k, v] : roleNames.asKeyValueRange()) { + nameToRole.insert(v, k); + } + + QHash roleToPropIdx; + std::vector roles; + + // Workaround for https://bugreports.qt.io/browse/QTBUG-98846 + QHash requiredProperties; + for (const auto &[propKey, prop] : + QQmlIncubatorPrivate::get(this)->requiredProperties()->asKeyValueRange()) { + requiredProperties.insert(prop.propertyName, propKey); + } + + // collect required properties + auto mo = obj->metaObject(); + for (int i = 0; i < mo->propertyCount(); i++) { + auto prop = mo->property(i); + // nhlog::ui()->critical("Found prop {}", prop.name()); + // See https://bugreports.qt.io/browse/QTBUG-98846 + if (!prop.isRequired() && !requiredProperties.contains(prop.name())) + continue; + + if (auto role = nameToRole.find(prop.name()); role != nameToRole.end()) { + roleToPropIdx.insert(*role, i); + roles.emplace_back(*role); + + nhlog::ui()->critical("Found prop {}, idx {}, role {}", prop.name(), i, *role); + } else { + nhlog::ui()->critical("Required property {} not found in model!", prop.name()); + } + } + + nhlog::ui()->debug("Querying data for id {}", currentId.toStdString()); + chooser.room_->multiData(currentId, forReply ? chooser.eventId_ : QString(), roles); + + QVariantMap rolesToSet; + for (const auto &role : roles) { + const auto &roleName = roleNames[role.role()]; + nhlog::ui()->critical("Setting role {}, {}", role.role(), roleName.toStdString()); + + mo->property(roleToPropIdx[role.role()]).write(obj, role.data()); + rolesToSet.insert(roleName, role.data()); + + if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end()) + QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req); + } + + // setInitialProperties(rolesToSet); + + auto update = + [this, obj, roleToPropIdx = std::move(roleToPropIdx)](const QList &changedRoles) { + std::vector rolesToRequest; + + if (changedRoles.empty()) { + for (auto role : roleToPropIdx.keys()) + rolesToRequest.emplace_back(role); + } else { + for (auto role : changedRoles) { + if (roleToPropIdx.contains(role)) { + rolesToRequest.emplace_back(role); + } + } + } + + if (rolesToRequest.empty()) + return; + + auto mo = obj->metaObject(); + chooser.room_->multiData( + currentId, forReply ? chooser.eventId_ : QString(), rolesToRequest); + for (const auto &role : rolesToRequest) { + mo->property(roleToPropIdx[role.role()]).write(obj, role.data()); + } + }; + + if (!forReply) { + auto row = chooser.room_->idToIndex(currentId); + connect(chooser.room_, + &QAbstractItemModel::dataChanged, + obj, + [row, update](const QModelIndex &topLeft, + const QModelIndex &bottomRight, + const QList &changedRoles) { + if (row < topLeft.row() || row > bottomRight.row()) + return; + + update(changedRoles); + }); + } +} + +void +EventDelegateChooser::DelegateIncubator::reset(QString id) +{ + if (!chooser.room_ || id.isEmpty()) + return; + + nhlog::ui()->debug("Reset with id {}, reply {}", id.toStdString(), forReply); + + this->currentId = id; + + auto role = + chooser.room_ + ->dataById(id, TimelineModel::Roles::Type, forReply ? chooser.eventId_ : QString()) + .toInt(); + + for (const auto choice : qAsConst(chooser.choices_)) { + const auto &choiceValue = choice->roleValues(); + if (choiceValue.contains(role) || choiceValue.empty()) { + if (auto child = qobject_cast(object())) { + child->setParentItem(nullptr); + } + + choice->delegate()->create(*this, QQmlEngine::contextForObject(&chooser)); + return; + } + } +} + +void +EventDelegateChooser::DelegateIncubator::statusChanged(QQmlIncubator::Status status) +{ + if (status == QQmlIncubator::Ready) { + auto child = qobject_cast(object()); + if (child == nullptr) { + nhlog::ui()->error("Delegate has to be derived of Item!"); + return; + } + + child->setParentItem(&chooser); + QQmlEngine::setObjectOwnership(child, QQmlEngine::ObjectOwnership::JavaScriptOwnership); + if (forReply) + emit chooser.replyChanged(); + else + emit chooser.mainChanged(); + + } else if (status == QQmlIncubator::Error) { + auto errors_ = errors(); + for (const auto &e : qAsConst(errors_)) + nhlog::ui()->error("Error instantiating delegate: {}", e.toString().toStdString()); + } +} + diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h new file mode 100644 index 00000000..ce22ca3a --- /dev/null +++ b/src/timeline/EventDelegateChooser.h @@ -0,0 +1,136 @@ +// SPDX-FileCopyrightText: Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +// A DelegateChooser like the one, that was added to Qt5.12 (in labs), but compatible with older Qt +// versions see KDE/kquickitemviews see qtdeclarative/qqmldelagatecomponent + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "TimelineModel.h" + +class EventDelegateChoice : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_CLASSINFO("DefaultProperty", "delegate") + +public: + Q_PROPERTY(QList roleValues READ roleValues WRITE setRoleValues NOTIFY roleValuesChanged + REQUIRED FINAL) + Q_PROPERTY( + QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged REQUIRED FINAL) + + [[nodiscard]] QQmlComponent *delegate() const; + void setDelegate(QQmlComponent *delegate); + + [[nodiscard]] QList roleValues() const; + void setRoleValues(const QList &value); + +signals: + void delegateChanged(); + void roleValuesChanged(); + void changed(); + +private: + QList roleValues_; + QQmlComponent *delegate_ = nullptr; +}; + +class EventDelegateChooser : public QQuickItem +{ + Q_OBJECT + QML_ELEMENT + Q_CLASSINFO("DefaultProperty", "choices") + +public: + Q_PROPERTY(QQmlListProperty choices READ choices CONSTANT FINAL) + Q_PROPERTY(QQuickItem *main READ main NOTIFY mainChanged FINAL) + Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL) + Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged REQUIRED FINAL) + Q_PROPERTY(QString replyTo READ replyTo WRITE setReplyTo NOTIFY replyToChanged REQUIRED FINAL) + + QQmlListProperty choices(); + + [[nodiscard]] QQuickItem *main() const + { + return qobject_cast(eventIncubator.object()); + } + + void setRoom(TimelineModel *m) + { + if (m != room_) { + room_ = m; + eventIncubator.reset(eventId_); + replyIncubator.reset(replyId); + emit roomChanged(); + } + } + [[nodiscard]] TimelineModel *room() { return room_; } + + void setEventId(QString idx) + { + eventId_ = idx; + emit eventIdChanged(); + } + [[nodiscard]] QString eventId() const { return eventId_; } + void setReplyTo(QString id) + { + replyId = id; + emit replyToChanged(); + } + [[nodiscard]] QString replyTo() const { return replyId; } + + void componentComplete() override; + +signals: + void mainChanged(); + void replyChanged(); + void roomChanged(); + void eventIdChanged(); + void replyToChanged(); + +private: + struct DelegateIncubator final : public QQmlIncubator + { + DelegateIncubator(EventDelegateChooser &parent, bool forReply) + : QQmlIncubator(QQmlIncubator::AsynchronousIfNested) + , chooser(parent) + , forReply(forReply) + { + } + void setInitialState(QObject *object) override; + void statusChanged(QQmlIncubator::Status status) override; + + void reset(QString id); + + EventDelegateChooser &chooser; + bool forReply; + QString currentId; + + QString instantiatedId; + int instantiatedRole = -1; + QAbstractItemModel *instantiatedModel = nullptr; + }; + + QVariant roleValue_; + QList choices_; + DelegateIncubator eventIncubator{*this, false}; + DelegateIncubator replyIncubator{*this, true}; + TimelineModel *room_{nullptr}; + QString eventId_; + QString replyId; + + static void appendChoice(QQmlListProperty *, EventDelegateChoice *); + static qsizetype choiceCount(QQmlListProperty *); + static EventDelegateChoice *choice(QQmlListProperty *, qsizetype index); + static void clearChoices(QQmlListProperty *); +}; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index b2a036c5..69ab3f5a 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -926,6 +926,26 @@ TimelineModel::multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSp } } +void +TimelineModel::multiData(const QString &id, + const QString &relatedTo, + QModelRoleDataSpan roleDataSpan) const +{ + if (id.isEmpty()) + return; + + auto event = events.get(id.toStdString(), relatedTo.toStdString()); + + if (!event) + return; + + for (QModelRoleData &roleData : roleDataSpan) { + int role = roleData.role(); + + roleData.setData(data(*event, role)); + } +} + QVariant TimelineModel::dataById(const QString &id, int role, const QString &relatedTo) { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index fccc99eb..57caf26d 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -286,6 +286,8 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override; + void + multiData(const QString &id, const QString &relatedTo, QModelRoleDataSpan roleDataSpan) const; QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const; Q_INVOKABLE QVariant dataById(const QString &id, int role, const QString &relatedTo); Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const -- cgit 1.5.1 From 76b40f452b8313db972e44f5eca30f59b7fdf4d3 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 25 Jun 2023 02:40:44 +0200 Subject: Working text messages in delegate rework --- resources/qml/MatrixText.qml | 32 +++---- resources/qml/MessageView.qml | 148 ++++++++++++++++++++++++++++++-- resources/qml/delegates/TextMessage.qml | 15 ++-- src/timeline/EventDelegateChooser.cpp | 26 +++++- src/timeline/EventDelegateChooser.h | 5 ++ 5 files changed, 191 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/resources/qml/MatrixText.qml b/resources/qml/MatrixText.qml index 94b8bb98..de15e078 100644 --- a/resources/qml/MatrixText.qml +++ b/resources/qml/MatrixText.qml @@ -2,24 +2,24 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -import QtQuick 2.5 -import QtQuick.Controls 2.3 -import im.nheko 1.0 +import QtQuick +import QtQuick.Controls +import im.nheko -TextEdit { +TextArea { id: r property alias cursorShape: cs.cursorShape - //leftInset: 0 - //bottomInset: 0 - //rightInset: 0 - //topInset: 0 - //leftPadding: 0 - //bottomPadding: 0 - //rightPadding: 0 - //topPadding: 0 - //background: null + leftInset: 0 + bottomInset: 0 + rightInset: 0 + topInset: 0 + leftPadding: 0 + bottomPadding: 0 + rightPadding: 0 + topPadding: 0 + background: null ToolTip.text: hoveredLink ToolTip.visible: hoveredLink || false @@ -39,9 +39,9 @@ TextEdit { } onLinkActivated: Nheko.openLink(link) - //// propagate events up - //onPressAndHold: (event) => event.accepted = false - //onPressed: (event) => event.accepted = (event.button == Qt.LeftButton) + // propagate events up + onPressAndHold: (event) => event.accepted = false + onPressed: (event) => event.accepted = (event.button == Qt.LeftButton) NhekoCursorShape { id: cs diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index fde7ee57..2852e5f7 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -63,28 +63,160 @@ Item { id: wrapper ListView.delayRemove: true width: chat.delegateMaxWidth - height: main?.height ?? 10 + height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight, 10) + anchors.horizontalCenter: ListView.view.contentItem.horizontalCenter room: chatRoot.roommodel + required property var day + required property bool isSender + required property bool isStateEvent + //required property var previousMessageDay + //required property bool previousMessageIsStateEvent + //required property string previousMessageUserId + required property int index + property var previousMessageDay: (index + 1) >= chat.count ? 0 : chat.model.dataByIndex(index + 1, Room.Day) + property bool previousMessageIsStateEvent: (index + 1) >= chat.count ? true : chat.model.dataByIndex(index + 1, Room.IsStateEvent) + property string previousMessageUserId: (index + 1) >= chat.count ? "" : chat.model.dataByIndex(index + 1, Room.UserId) + required property date timestamp + required property string userId + required property string userName + required property string threadId + + data: [ + Loader { + id: section + + property var day: wrapper.day + property bool isSender: wrapper.isSender + property bool isStateEvent: wrapper.isStateEvent + property int parentWidth: wrapper.width + property var previousMessageDay: wrapper.previousMessageDay + property bool previousMessageIsStateEvent: wrapper.previousMessageIsStateEvent + property string previousMessageUserId: wrapper.previousMessageUserId + property date timestamp: wrapper.timestamp + property string userId: wrapper.userId + property string userName: wrapper.userName + + active: previousMessageUserId !== userId || previousMessageDay !== day || previousMessageIsStateEvent !== isStateEvent + //asynchronous: true + sourceComponent: sectionHeader + visible: status == Loader.Ready + z: 4 + }, + GridLayout { + id: gridContainer + + width: wrapper.width + y: section.visible && section.active ? section.y + section.height : 0 + + ColumnLayout { + id: contentColumn + Layout.fillWidth: true + Layout.leftMargin: (wrapper.isStateEvent || Settings.smallAvatars ? 0 : (Nheko.avatarSize + 8)) + (wrapper.threadId ? 6 : 0) // align bubble with section header + + AbstractButton { + id: replyRow + visible: wrapper.reply + Layout.fillWidth: true + Layout.maximumHeight: timelineView.height / 8 + Layout.preferredWidth: replyRowLay.implicitWidth + Layout.preferredHeight: replyRowLay.implicitHeight + + property color userColor: TimelineManager.userColor(wrapper.reply?.userId ?? '', palette.base) + + clip: true + + contentItem: RowLayout { + id: replyRowLay + + anchors.fill: parent + + + Rectangle { + id: replyLine + Layout.fillHeight: true + color: replyRow.userColor + Layout.preferredWidth: 4 + } + + ColumnLayout { + AbstractButton { + id: replyUserButton + Layout.fillWidth: true + contentItem: ElidedLabel { + id: userName_ + fullText: wrapper.reply?.userName ?? '' + color: replyRow.userColor + textFormat: Text.RichText + width: parent.width + elideWidth: width + } + onClicked: room.openUserProfile(wrapper.reply?.userId) + } + data: [ + replyUserButton, + wrapper.reply, + ] + } + } + + background: Rectangle { + width: replyRow.implicitContentWidth + color: Qt.tint(palette.base, Qt.hsla(replyRow.userColor.hslHue, 0.5, replyRow.userColor.hslLightness, 0.1)) + } + } + + data: [ + replyRow, wrapper.main, + ] + } + + Rectangle { + color: 'yellow' + Layout.preferredWidth: 100 + Layout.preferredHeight: 20 + Layout.alignment: Qt.AlignRight | Qt.AlignTop + } + }, + + Rectangle { + width: Math.min(contentColumn.implicitWidth, contentColumn.width) + height: contentColumn.implicitHeight + color: "blue" + opacity: 0.2 + } + ] + EventDelegateChoice { roleValues: [ MtxEvent.TextMessage, MtxEvent.NoticeMessage, ] - TextArea { - required property string body + TextMessage { + id: textMes + + keepFullText: true + required property string userId + required property string userName + + Layout.fillWidth: true + //Layout.maximumWidth: implicitWidth - width: parent.width - text: body } } EventDelegateChoice { roleValues: [ ] - TextArea { - width: parent.width - text: "Unsupported" + MatrixText { + Layout.fillWidth: true + + required property string typeString + + text: "Unsupported: " + typeString + + required property string userId + required property string userName } } } diff --git a/resources/qml/delegates/TextMessage.qml b/resources/qml/delegates/TextMessage.qml index 1eb5e2c0..d4b72965 100644 --- a/resources/qml/delegates/TextMessage.qml +++ b/resources/qml/delegates/TextMessage.qml @@ -3,17 +3,19 @@ // SPDX-License-Identifier: GPL-3.0-or-later import ".." -import QtQuick.Controls 2.3 -import im.nheko 1.0 +import QtQuick.Controls +import QtQuick.Layouts +import im.nheko MatrixText { required property string body required property bool isOnlyEmoji required property bool isReply required property bool keepFullText - required property string formatted + required property string formattedBody + property string copyText: selectedText ? getText(selectionStart, selectionEnd) : body - property int metadataWidth + property int metadataWidth: 100 property bool fitsMetadata: false //positionAt(width,height-4) == positionAt(width-metadataWidth-10, height-4) // table border-collapse doesn't seem to work @@ -38,9 +40,8 @@ MatrixText { background-color: " + palette.text + "; }" : "") + // TODO(Nico): Figure out how to support mobile " - " + formatted.replace(//g, "").replace(/<\/del>/g, "").replace(//g, "").replace(/<\/strike>/g, "") - width: parent?.width ?? 0 - height: !keepFullText ? Math.round(Math.min(timelineView.height / 8, implicitHeight)) : implicitHeight + " + formattedBody.replace(//g, "").replace(/<\/del>/g, "").replace(//g, "").replace(/<\/strike>/g, "") + Layout.maximumHeight: !keepFullText ? Math.round(Math.min(timelineView.height / 8, implicitHeight)) : implicitHeight clip: !keepFullText selectByMouse: !Settings.mobileMode && !isReply enabled: !Settings.mobileMode diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp index 7618e20b..5e6ee37e 100644 --- a/src/timeline/EventDelegateChooser.cpp +++ b/src/timeline/EventDelegateChooser.cpp @@ -85,6 +85,7 @@ EventDelegateChooser::componentComplete() { QQuickItem::componentComplete(); // eventIncubator.reset(eventIndex); + // eventIncubator.forceCompletion(); } void @@ -104,6 +105,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) QHash roleToPropIdx; std::vector roles; + bool isReplyNeeded = false; // Workaround for https://bugreports.qt.io/browse/QTBUG-98846 QHash requiredProperties; @@ -121,7 +123,10 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) if (!prop.isRequired() && !requiredProperties.contains(prop.name())) continue; - if (auto role = nameToRole.find(prop.name()); role != nameToRole.end()) { + if (prop.name() == std::string_view("isReply")) { + isReplyNeeded = true; + roleToPropIdx.insert(-1, i); + } else if (auto role = nameToRole.find(prop.name()); role != nameToRole.end()) { roleToPropIdx.insert(*role, i); roles.emplace_back(*role); @@ -134,13 +139,26 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) nhlog::ui()->debug("Querying data for id {}", currentId.toStdString()); chooser.room_->multiData(currentId, forReply ? chooser.eventId_ : QString(), roles); - QVariantMap rolesToSet; for (const auto &role : roles) { const auto &roleName = roleNames[role.role()]; - nhlog::ui()->critical("Setting role {}, {}", role.role(), roleName.toStdString()); + nhlog::ui()->critical("Setting role {}, {} to {}", + role.role(), + roleName.toStdString(), + role.data().toString().toStdString()); + nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[role.role()]).name()); mo->property(roleToPropIdx[role.role()]).write(obj, role.data()); - rolesToSet.insert(roleName, role.data()); + + if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end()) + QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req); + } + + if (isReplyNeeded) { + const auto roleName = QByteArray("isReply"); + nhlog::ui()->critical("Setting role {} to {}", roleName.toStdString(), forReply); + + nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[-1]).name()); + mo->property(roleToPropIdx[-1]).write(obj, forReply); if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end()) QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req); diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h index ce22ca3a..b627b383 100644 --- a/src/timeline/EventDelegateChooser.h +++ b/src/timeline/EventDelegateChooser.h @@ -54,6 +54,7 @@ class EventDelegateChooser : public QQuickItem public: Q_PROPERTY(QQmlListProperty choices READ choices CONSTANT FINAL) Q_PROPERTY(QQuickItem *main READ main NOTIFY mainChanged FINAL) + Q_PROPERTY(QQuickItem *reply READ reply NOTIFY replyChanged FINAL) Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL) Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged REQUIRED FINAL) Q_PROPERTY(QString replyTo READ replyTo WRITE setReplyTo NOTIFY replyToChanged REQUIRED FINAL) @@ -64,6 +65,10 @@ public: { return qobject_cast(eventIncubator.object()); } + [[nodiscard]] QQuickItem *reply() const + { + return qobject_cast(replyIncubator.object()); + } void setRoom(TimelineModel *m) { -- cgit 1.5.1 From eab8731f5bd695342ad6412d42b1065872f12691 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 8 Jul 2023 19:22:50 +0200 Subject: Port state events and images --- resources/qml/MessageView.qml | 82 ++++++++++- resources/qml/delegates/ImageMessage.qml | 15 +- resources/qml/delegates/MessageDelegate.qml | 2 + resources/qml/delegates/TextMessage.qml | 4 +- src/timeline/EventStore.cpp | 4 +- src/timeline/TimelineModel.cpp | 210 +++++++++++++++++----------- src/timeline/TimelineModel.h | 15 +- 7 files changed, 231 insertions(+), 101 deletions(-) (limited to 'src') diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 2852e5f7..2d4f592c 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -191,13 +191,40 @@ Item { roleValues: [ MtxEvent.TextMessage, MtxEvent.NoticeMessage, + MtxEvent.ElementEffectMessage, + MtxEvent.UnknownMessage, ] TextMessage { - id: textMes + keepFullText: true + required property string userId + required property string userName + required property string formattedBody + required property int type + color: type == MtxEvent.NoticeMessage ? palette.buttonText : palette.text + font.italic: type == MtxEvent.NoticeMessage + formatted: formattedBody + + Layout.fillWidth: true + //Layout.maximumWidth: implicitWidth + + } + } + + EventDelegateChoice { + roleValues: [ + MtxEvent.EmoteMessage, + ] + TextMessage { keepFullText: true required property string userId required property string userName + required property string formattedBody + + formatted: TimelineManager.escapeEmoji(userName) + " " + formattedBody + + color: TimelineManager.userColor(userId, palette.base) + font.italic: true Layout.fillWidth: true //Layout.maximumWidth: implicitWidth @@ -205,6 +232,59 @@ Item { } } + EventDelegateChoice { + roleValues: [ + MtxEvent.CanonicalAlias, + MtxEvent.ServerAcl, + MtxEvent.Name, + MtxEvent.Topic, + MtxEvent.Avatar, + MtxEvent.PinnedEvents, + MtxEvent.ImagePackInRoom, + MtxEvent.SpaceParent, + MtxEvent.RoomCreate, + MtxEvent.PowerLevels, + MtxEvent.PolicyRuleUser, + MtxEvent.PolicyRuleRoom, + MtxEvent.PolicyRuleServer, + MtxEvent.RoomJoinRules, + MtxEvent.RoomHistoryVisibility, + MtxEvent.RoomGuestAccess, + ] + TextMessage { + keepFullText: true + + required property string userId + required property string userName + required property string formattedStateEvent + + isOnlyEmoji: false + text: formattedStateEvent + formatted: '' + body: '' + + color: palette.buttonText + font.italic: true + + Layout.fillWidth: true + //Layout.maximumWidth: implicitWidth + + } + } + + EventDelegateChoice { + roleValues: [ + MtxEvent.ImageMessage, + MtxEvent.Sticker, + ] + ImageMessage { + Layout.fillWidth: true + + containerHeight: timelineView.height + Layout.maximumWidth: tempWidth + } + } + EventDelegateChoice { roleValues: [ ] diff --git a/resources/qml/delegates/ImageMessage.qml b/resources/qml/delegates/ImageMessage.qml index 20d727c3..48b7c5e4 100644 --- a/resources/qml/delegates/ImageMessage.qml +++ b/resources/qml/delegates/ImageMessage.qml @@ -2,10 +2,11 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -import QtQuick 2.15 -import QtQuick.Window 2.15 -import QtQuick.Controls 2.3 -import im.nheko 1.0 +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Layouts +import im.nheko AbstractButton { required property int type @@ -17,13 +18,13 @@ AbstractButton { required property string filename required property bool isReply required property string eventId + required property int containerHeight property double divisor: isReply ? 5 : 3 property int tempWidth: originalWidth < 1? 400: originalWidth - implicitWidth: Math.round(tempWidth*Math.min((timelineView.height/divisor)/(tempWidth*proportionalHeight), 1)) - width: Math.min(parent?.width ?? 2000,implicitWidth) - height: width*proportionalHeight + Layout.preferredWidth: Math.round(tempWidth*Math.min((containerHeight/divisor)/(tempWidth*proportionalHeight), 1)) + Layout.preferredHeight: width*proportionalHeight hoverEnabled: true state: (img.status != Image.Ready || timeline.privacyScreen.active) ? "BlurhashVisible" : "ImageVisible" diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 68f65062..44726a63 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -175,6 +175,7 @@ Item { isReply: d.isReply eventId: d.eventId metadataWidth: d.metadataWidth + containerHeight: timelineView.height } } @@ -193,6 +194,7 @@ Item { isReply: d.isReply eventId: d.eventId metadataWidth: d.metadataWidth + containerHeight: timelineView.height } } diff --git a/resources/qml/delegates/TextMessage.qml b/resources/qml/delegates/TextMessage.qml index d4b72965..dc8caf01 100644 --- a/resources/qml/delegates/TextMessage.qml +++ b/resources/qml/delegates/TextMessage.qml @@ -12,7 +12,7 @@ MatrixText { required property bool isOnlyEmoji required property bool isReply required property bool keepFullText - required property string formattedBody + required property string formatted property string copyText: selectedText ? getText(selectionStart, selectionEnd) : body property int metadataWidth: 100 @@ -40,7 +40,7 @@ MatrixText { background-color: " + palette.text + "; }" : "") + // TODO(Nico): Figure out how to support mobile " - " + formattedBody.replace(//g, "").replace(/<\/del>/g, "").replace(//g, "").replace(/<\/strike>/g, "") + " + formatted.replace(//g, "").replace(/<\/del>/g, "").replace(//g, "").replace(/<\/strike>/g, "") Layout.maximumHeight: !keepFullText ? Math.round(Math.min(timelineView.height / 8, implicitHeight)) : implicitHeight clip: !keepFullText selectByMouse: !Settings.mobileMode && !isReply diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index 63b67474..e29dfb4c 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -843,8 +843,8 @@ EventStore::get(const std::string &id, nhlog::net()->error( "Failed to retrieve event with id {}, which was " "requested to show the replyTo for event {}", - relatedTo, - id); + id, + relatedTo); return; } emit eventFetched(id, relatedTo, timeline); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 69ab3f5a..066d8b01 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -532,6 +532,7 @@ TimelineModel::roleNames() const {IsOnlyEmoji, "isOnlyEmoji"}, {Body, "body"}, {FormattedBody, "formattedBody"}, + {FormattedStateEvent, "formattedStateEvent"}, {IsSender, "isSender"}, {UserId, "userId"}, {UserName, "userName"}, @@ -694,6 +695,76 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r return QVariant(utils::replaceEmoji(utils::linkifyMessage(formattedBody_))); } + case FormattedStateEvent: { + if (mtx::accessors::is_state_event(event)) { + return std::visit( + [this](const auto &e) { + constexpr auto t = mtx::events::state_content_to_type; + if constexpr (t == mtx::events::EventType::RoomServerAcl) + return tr("%1 changed which servers are allowed in this room.") + .arg(displayName(QString::fromStdString(e.sender))); + else if constexpr (t == mtx::events::EventType::RoomName) { + if (e.content.name.empty()) + return tr("%1 removed the room name.") + .arg(displayName(QString::fromStdString(e.sender))); + else + return tr("%1 changed the room name to: %2") + .arg(displayName(QString::fromStdString(e.sender))) + .arg(QString::fromStdString(e.content.name).toHtmlEscaped()); + } else if constexpr (t == mtx::events::EventType::RoomTopic) { + if (e.content.topic.empty()) + return tr("%1 removed the topic.") + .arg(displayName(QString::fromStdString(e.sender))); + else + return tr("%1 changed the topic to: %2") + .arg(displayName(QString::fromStdString(e.sender))) + .arg(QString::fromStdString(e.content.topic).toHtmlEscaped()); + } else if constexpr (t == mtx::events::EventType::RoomAvatar) { + if (e.content.url.starts_with("mxc://")) + return tr("%1 changed the room avatar to: %2") + .arg(displayName(QString::fromStdString(e.sender))) + .arg(QStringLiteral("") + .arg(QUrl::toPercentEncoding( + QString::fromStdString(e.content.url)))); + else + return tr("%1 removed the room avatar.") + .arg(displayName(QString::fromStdString(e.sender))); + } else if constexpr (t == mtx::events::EventType::RoomPinnedEvents) + return tr("%1 changed the pinned messages.") + .arg(displayName(QString::fromStdString(e.sender))); + else if constexpr (t == mtx::events::EventType::ImagePackInRoom) + formatImagePackEvent(e); + else if constexpr (t == mtx::events::EventType::RoomCanonicalAlias) + return tr("%1 changed the addresses for this room.") + .arg(displayName(QString::fromStdString(e.sender))); + else if constexpr (t == mtx::events::EventType::SpaceParent) + return tr("%1 changed the parent communities for this room.") + .arg(displayName(QString::fromStdString(e.sender))); + else if constexpr (t == mtx::events::EventType::RoomCreate) + return tr("%1 created and configured room: %2") + .arg(displayName(QString::fromStdString(e.sender))) + .arg(room_id_); + else if constexpr (t == mtx::events::EventType::RoomPowerLevels) + return formatPowerLevelEvent(e); + else if constexpr (t == mtx::events::EventType::PolicyRuleRoom) + return formatPolicyRule(QString::fromStdString(e.event_id)); + else if constexpr (t == mtx::events::EventType::PolicyRuleUser) + return formatPolicyRule(QString::fromStdString(e.event_id)); + else if constexpr (t == mtx::events::EventType::PolicyRuleServer) + return formatPolicyRule(QString::fromStdString(e.event_id)); + else if constexpr (t == mtx::events::EventType::RoomHistoryVisibility) + return formatHistoryVisibilityEvent(e); + else if constexpr (t == mtx::events::EventType::RoomGuestAccess) + return formatGuestAccessEvent(e); + + return tr("%1 changed unknown state event %2.") + .arg(displayName(QString::fromStdString(e.sender))) + .arg(QString::fromStdString(to_string(e.type))); + }, + event); + } + return QString(); + } case Url: return QVariant(QString::fromStdString(url(event))); case ThumbnailUrl: @@ -2308,20 +2379,13 @@ TimelineModel::formatJoinRuleEvent(const QString &id) } QString -TimelineModel::formatGuestAccessEvent(const QString &id) +TimelineModel::formatGuestAccessEvent( + const mtx::events::StateEvent &event) const { - auto e = events.get(id.toStdString(), ""); - if (!e) - return {}; - - auto event = std::get_if>(e); - if (!event) - return {}; - - QString user = QString::fromStdString(event->sender); + QString user = QString::fromStdString(event.sender); QString name = utils::replaceEmoji(displayName(user)); - switch (event->content.guest_access) { + switch (event.content.guest_access) { case mtx::events::state::AccessState::CanJoin: return tr("%1 made the room open to guests.").arg(name); case mtx::events::state::AccessState::Forbidden: @@ -2332,21 +2396,13 @@ TimelineModel::formatGuestAccessEvent(const QString &id) } QString -TimelineModel::formatHistoryVisibilityEvent(const QString &id) +TimelineModel::formatHistoryVisibilityEvent( + const mtx::events::StateEvent &event) const { - auto e = events.get(id.toStdString(), ""); - if (!e) - return {}; - - auto event = std::get_if>(e); - - if (!event) - return {}; - - QString user = QString::fromStdString(event->sender); + QString user = QString::fromStdString(event.sender); QString name = utils::replaceEmoji(displayName(user)); - switch (event->content.history_visibility) { + switch (event.content.history_visibility) { case mtx::events::state::Visibility::WorldReadable: return tr("%1 made the room history world readable. Events may be now read by " "non-joined people.") @@ -2364,32 +2420,25 @@ TimelineModel::formatHistoryVisibilityEvent(const QString &id) } QString -TimelineModel::formatPowerLevelEvent(const QString &id) +TimelineModel::formatPowerLevelEvent( + const mtx::events::StateEvent &event) const { - auto e = events.get(id.toStdString(), ""); - if (!e) - return {}; - - auto event = std::get_if>(e); - if (!event) - return QString(); - mtx::events::StateEvent const *prevEvent = nullptr; - if (!event->unsigned_data.replaces_state.empty()) { - auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id); + if (!event.unsigned_data.replaces_state.empty()) { + auto tempPrevEvent = events.get(event.unsigned_data.replaces_state, event.event_id); if (tempPrevEvent) { prevEvent = std::get_if>(tempPrevEvent); } } - QString user = QString::fromStdString(event->sender); + QString user = QString::fromStdString(event.sender); QString sender_name = utils::replaceEmoji(displayName(user)); // Get the rooms levels for redactions and powerlevel changes to determine "Administrator" and // "Moderator" powerlevels. - auto administrator_power_level = event->content.state_level("m.room.power_levels"); - auto moderator_power_level = event->content.redact; - auto default_powerlevel = event->content.users_default; + auto administrator_power_level = event.content.state_level("m.room.power_levels"); + auto moderator_power_level = event.content.redact; + auto default_powerlevel = event.content.users_default; if (!prevEvent) return tr("%1 has changed the room's permissions.").arg(sender_name); @@ -2399,7 +2448,7 @@ TimelineModel::formatPowerLevelEvent(const QString &id) auto numberOfAffected = 0; // We do only compare to people with explicit PL. Usually others are not going to be // affected either way and this is cheaper to iterate over. - for (auto const &[mxid, currentPowerlevel] : event->content.users) { + for (auto const &[mxid, currentPowerlevel] : event.content.users) { if (currentPowerlevel == newPowerlevelSetting && prevEvent->content.user_level(mxid) < newPowerlevelSetting) { numberOfAffected++; @@ -2413,16 +2462,16 @@ TimelineModel::formatPowerLevelEvent(const QString &id) QStringList resultingMessage{}; // These affect only a few people. Therefor we can print who is affected. - if (event->content.kick != prevEvent->content.kick) { + if (event.content.kick != prevEvent->content.kick) { auto default_message = tr("%1 has changed the room's kick powerlevel from %2 to %3.") .arg(sender_name) .arg(prevEvent->content.kick) - .arg(event->content.kick); + .arg(event.content.kick); // We only calculate affected users if we change to a level above the default users PL // to not accidentally have a DoS vector - if (event->content.kick > default_powerlevel) { - auto [affected, number_of_affected] = calc_affected(event->content.kick); + if (event.content.kick > default_powerlevel) { + auto [affected, number_of_affected] = calc_affected(event.content.kick); if (number_of_affected != 0) { auto true_affected_rest = number_of_affected - affected.size(); @@ -2444,16 +2493,16 @@ TimelineModel::formatPowerLevelEvent(const QString &id) } } - if (event->content.redact != prevEvent->content.redact) { + if (event.content.redact != prevEvent->content.redact) { auto default_message = tr("%1 has changed the room's redact powerlevel from %2 to %3.") .arg(sender_name) .arg(prevEvent->content.redact) - .arg(event->content.redact); + .arg(event.content.redact); // We only calculate affected users if we change to a level above the default users PL // to not accidentally have a DoS vector - if (event->content.redact > default_powerlevel) { - auto [affected, number_of_affected] = calc_affected(event->content.redact); + if (event.content.redact > default_powerlevel) { + auto [affected, number_of_affected] = calc_affected(event.content.redact); if (number_of_affected != 0) { auto true_affected_rest = number_of_affected - affected.size(); @@ -2476,16 +2525,16 @@ TimelineModel::formatPowerLevelEvent(const QString &id) } } - if (event->content.ban != prevEvent->content.ban) { + if (event.content.ban != prevEvent->content.ban) { auto default_message = tr("%1 has changed the room's ban powerlevel from %2 to %3.") .arg(sender_name) .arg(prevEvent->content.ban) - .arg(event->content.ban); + .arg(event.content.ban); // We only calculate affected users if we change to a level above the default users PL // to not accidentally have a DoS vector - if (event->content.ban > default_powerlevel) { - auto [affected, number_of_affected] = calc_affected(event->content.ban); + if (event.content.ban > default_powerlevel) { + auto [affected, number_of_affected] = calc_affected(event.content.ban); if (number_of_affected != 0) { auto true_affected_rest = number_of_affected - affected.size(); @@ -2507,17 +2556,17 @@ TimelineModel::formatPowerLevelEvent(const QString &id) } } - if (event->content.state_default != prevEvent->content.state_default) { + if (event.content.state_default != prevEvent->content.state_default) { auto default_message = tr("%1 has changed the room's state_default powerlevel from %2 to %3.") .arg(sender_name) .arg(prevEvent->content.state_default) - .arg(event->content.state_default); + .arg(event.content.state_default); // We only calculate affected users if we change to a level above the default users PL // to not accidentally have a DoS vector - if (event->content.state_default > default_powerlevel) { - auto [affected, number_of_affected] = calc_affected(event->content.kick); + if (event.content.state_default > default_powerlevel) { + auto [affected, number_of_affected] = calc_affected(event.content.kick); if (number_of_affected != 0) { auto true_affected_rest = number_of_affected - affected.size(); @@ -2541,42 +2590,42 @@ TimelineModel::formatPowerLevelEvent(const QString &id) // These affect potentially the whole room. We there for do not calculate who gets affected // by this to prevent huge lists of people. - if (event->content.invite != prevEvent->content.invite) { + if (event.content.invite != prevEvent->content.invite) { resultingMessage.append(tr("%1 has changed the room's invite powerlevel from %2 to %3.") .arg(sender_name, QString::number(prevEvent->content.invite), - QString::number(event->content.invite))); + QString::number(event.content.invite))); } - if (event->content.events_default != prevEvent->content.events_default) { - if ((event->content.events_default > default_powerlevel) && + if (event.content.events_default != prevEvent->content.events_default) { + if ((event.content.events_default > default_powerlevel) && prevEvent->content.events_default <= default_powerlevel) { resultingMessage.append( tr("%1 has changed the room's events_default powerlevel from %2 to %3. New " "users can now not send any events.") .arg(sender_name, QString::number(prevEvent->content.events_default), - QString::number(event->content.events_default))); - } else if ((event->content.events_default < prevEvent->content.events_default) && - (event->content.events_default < default_powerlevel) && + QString::number(event.content.events_default))); + } else if ((event.content.events_default < prevEvent->content.events_default) && + (event.content.events_default < default_powerlevel) && (prevEvent->content.events_default > default_powerlevel)) { resultingMessage.append( tr("%1 has changed the room's events_default powerlevel from %2 to %3. New " "users can now send events that are not otherwise restricted.") .arg(sender_name, QString::number(prevEvent->content.events_default), - QString::number(event->content.events_default))); + QString::number(event.content.events_default))); } else { resultingMessage.append( tr("%1 has changed the room's events_default powerlevel from %2 to %3.") .arg(sender_name, QString::number(prevEvent->content.events_default), - QString::number(event->content.events_default))); + QString::number(event.content.events_default))); } } // Compare if a Powerlevel of a user changed - for (auto const &[mxid, powerlevel] : event->content.users) { + for (auto const &[mxid, powerlevel] : event.content.users) { auto nameOfChangedUser = utils::replaceEmoji(displayName(QString::fromStdString(mxid))); if (prevEvent->content.user_level(mxid) != powerlevel) { if (powerlevel >= administrator_power_level) { @@ -2601,7 +2650,7 @@ TimelineModel::formatPowerLevelEvent(const QString &id) } // Handle added/removed/changed event type - for (auto const &[event_type, powerlevel] : event->content.events) { + for (auto const &[event_type, powerlevel] : event.content.events) { auto prev_not_present = prevEvent->content.events.find(event_type) == prevEvent->content.events.end(); @@ -2640,26 +2689,19 @@ TimelineModel::formatPowerLevelEvent(const QString &id) } QString -TimelineModel::formatImagePackEvent(const QString &id) +TimelineModel::formatImagePackEvent( + const mtx::events::StateEvent &event) const { - auto e = events.get(id.toStdString(), ""); - if (!e) - return {}; - - auto event = std::get_if>(e); - if (!event) - return {}; - mtx::events::StateEvent const *prevEvent = nullptr; - if (!event->unsigned_data.replaces_state.empty()) { - auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id); + if (!event.unsigned_data.replaces_state.empty()) { + auto tempPrevEvent = events.get(event.unsigned_data.replaces_state, event.event_id); if (tempPrevEvent) { prevEvent = std::get_if>(tempPrevEvent); } } - const auto &newImages = event->content.images; + const auto &newImages = event.content.images; const auto oldImages = prevEvent ? prevEvent->content.images : decltype(newImages){}; auto ascent = QFontMetrics(UserSettings::instance()->font()).ascent(); @@ -2682,12 +2724,12 @@ TimelineModel::formatImagePackEvent(const QString &id) auto added = calcChange(newImages, oldImages); auto removed = calcChange(oldImages, newImages); - auto sender = utils::replaceEmoji(displayName(QString::fromStdString(event->sender))); + auto sender = utils::replaceEmoji(displayName(QString::fromStdString(event.sender))); const auto packId = [&event]() -> QString { - if (event->content.pack && !event->content.pack->display_name.empty()) { - return event->content.pack->display_name.c_str(); - } else if (!event->state_key.empty()) { - return event->state_key.c_str(); + if (event.content.pack && !event.content.pack->display_name.empty()) { + return event.content.pack->display_name.c_str(); + } else if (!event.state_key.empty()) { + return event.state_key.c_str(); } return tr("(empty)"); }(); @@ -2712,7 +2754,7 @@ TimelineModel::formatImagePackEvent(const QString &id) } QString -TimelineModel::formatPolicyRule(const QString &id) +TimelineModel::formatPolicyRule(const QString &id) const { auto idStr = id.toStdString(); auto e = events.get(idStr, ""); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 57caf26d..b81fc209 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -238,6 +238,7 @@ public: IsOnlyEmoji, Body, FormattedBody, + FormattedStateEvent, IsSender, UserId, UserName, @@ -310,11 +311,15 @@ public: Q_INVOKABLE void joinReplacementRoom(const QString &id); Q_INVOKABLE QString formatMemberEvent(const QString &id); Q_INVOKABLE QString formatJoinRuleEvent(const QString &id); - Q_INVOKABLE QString formatHistoryVisibilityEvent(const QString &id); - Q_INVOKABLE QString formatGuestAccessEvent(const QString &id); - Q_INVOKABLE QString formatPowerLevelEvent(const QString &id); - Q_INVOKABLE QString formatImagePackEvent(const QString &id); - Q_INVOKABLE QString formatPolicyRule(const QString &id); + QString formatHistoryVisibilityEvent( + const mtx::events::StateEvent &event) const; + QString + formatGuestAccessEvent(const mtx::events::StateEvent &) const; + QString formatPowerLevelEvent( + const mtx::events::StateEvent &event) const; + QString formatImagePackEvent( + const mtx::events::StateEvent &event) const; + Q_INVOKABLE QString formatPolicyRule(const QString &id) const; Q_INVOKABLE QVariantMap formatRedactedEvent(const QString &id); Q_INVOKABLE void viewRawMessage(const QString &id); -- cgit 1.5.1 From 718a58d388abd228c6a08f9fa3365588c06923ba Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 28 Jul 2023 20:05:47 +0200 Subject: Get rid of redundant constructions and make room implicit --- resources/qml/MessageView.qml | 4 ++-- resources/qml/delegates/Redacted.qml | 9 +++++---- src/timeline/EventDelegateChooser.cpp | 6 +++++- src/timeline/EventDelegateChooser.h | 15 ++++++++++++--- src/timeline/TimelineModel.cpp | 3 +++ src/timeline/TimelineModel.h | 1 + 6 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 41d996c1..417a4f5a 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -65,7 +65,7 @@ Item { width: chat.delegateMaxWidth height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight, 10) anchors.horizontalCenter: ListView.view.contentItem.horizontalCenter - room: chatRoot.roommodel + //room: chatRoot.roommodel required property var day required property bool isSender @@ -203,7 +203,7 @@ Item { color: type == MtxEvent.NoticeMessage ? palette.buttonText : palette.text font.italic: type == MtxEvent.NoticeMessage - formatted: formattedBody + formatted: formattedBody + "a" Layout.fillWidth: true //Layout.maximumWidth: implicitWidth diff --git a/resources/qml/delegates/Redacted.qml b/resources/qml/delegates/Redacted.qml index a09e4c3f..1bb3209f 100644 --- a/resources/qml/delegates/Redacted.qml +++ b/resources/qml/delegates/Redacted.qml @@ -2,10 +2,10 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -import QtQuick 2.15 -import QtQuick.Controls 2.15 -import QtQuick.Layouts 1.15 -import im.nheko 1.0 +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import im.nheko Control { id: msgRoot @@ -14,6 +14,7 @@ Control { property bool fitsMetadata: false //parent.width - redactedLayout.width > metadataWidth + 4 required property string eventId + required property Room room contentItem: RowLayout { id: redactedLayout diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp index 5e6ee37e..7fec38dd 100644 --- a/src/timeline/EventDelegateChooser.cpp +++ b/src/timeline/EventDelegateChooser.cpp @@ -84,7 +84,8 @@ void EventDelegateChooser::componentComplete() { QQuickItem::componentComplete(); - // eventIncubator.reset(eventIndex); + eventIncubator.reset(eventId_); + replyIncubator.reset(replyId); // eventIncubator.forceCompletion(); } @@ -226,6 +227,9 @@ EventDelegateChooser::DelegateIncubator::reset(QString id) for (const auto choice : qAsConst(chooser.choices_)) { const auto &choiceValue = choice->roleValues(); if (choiceValue.contains(role) || choiceValue.empty()) { + nhlog::ui()->debug( + "Instantiating type: {}, c {}", (int)role, choiceValue.contains(role)); + if (auto child = qobject_cast(object())) { child->setParentItem(nullptr); } diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h index b627b383..1cd2d65a 100644 --- a/src/timeline/EventDelegateChooser.h +++ b/src/timeline/EventDelegateChooser.h @@ -55,9 +55,9 @@ public: Q_PROPERTY(QQmlListProperty choices READ choices CONSTANT FINAL) Q_PROPERTY(QQuickItem *main READ main NOTIFY mainChanged FINAL) Q_PROPERTY(QQuickItem *reply READ reply NOTIFY replyChanged FINAL) - Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL) Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged REQUIRED FINAL) Q_PROPERTY(QString replyTo READ replyTo WRITE setReplyTo NOTIFY replyToChanged REQUIRED FINAL) + Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL) QQmlListProperty choices(); @@ -74,9 +74,12 @@ public: { if (m != room_) { room_ = m; - eventIncubator.reset(eventId_); - replyIncubator.reset(replyId); emit roomChanged(); + + if (isComponentComplete()) { + eventIncubator.reset(eventId_); + replyIncubator.reset(replyId); + } } } [[nodiscard]] TimelineModel *room() { return room_; } @@ -85,12 +88,18 @@ public: { eventId_ = idx; emit eventIdChanged(); + + if (isComponentComplete()) + eventIncubator.reset(eventId_); } [[nodiscard]] QString eventId() const { return eventId_; } void setReplyTo(QString id) { replyId = id; emit replyToChanged(); + + if (isComponentComplete()) + replyIncubator.reset(replyId); } [[nodiscard]] QString replyTo() const { return replyId; } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 066d8b01..66f7d5b8 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -561,6 +561,7 @@ TimelineModel::roleNames() const {ReplyTo, "replyTo"}, {ThreadId, "threadId"}, {Reactions, "reactions"}, + {Room, "room"}, {RoomId, "roomId"}, {RoomName, "roomName"}, {RoomTopic, "roomTopic"}, @@ -899,6 +900,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r auto id = relations(event).replaces().value_or(event_id(event)); return QVariant::fromValue(events.reactions(id)); } + case Room: + return QVariant::fromValue(this); case RoomId: return QVariant(room_id_); case RoomName: diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index b81fc209..2b22ad61 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -267,6 +267,7 @@ public: ReplyTo, ThreadId, Reactions, + Room, RoomId, RoomName, RoomTopic, -- cgit 1.5.1 From 2360dfd80ae8991c557c9c7d9474c528c00fdaa6 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 13 Aug 2023 11:30:41 +0200 Subject: Remaining events apart from verification --- resources/qml/MessageView.qml | 184 +++++++++++++++++++++++++- resources/qml/delegates/Encrypted.qml | 33 +++-- resources/qml/delegates/EncryptionEnabled.qml | 47 ++++--- resources/qml/delegates/FileMessage.qml | 36 ++--- resources/qml/delegates/Redacted.qml | 1 - src/timeline/EventDelegateChooser.cpp | 27 ++-- src/timeline/TimelineModel.cpp | 42 +++--- src/timeline/TimelineModel.h | 3 +- src/voip/CallManager.cpp | 3 +- 9 files changed, 287 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 417a4f5a..2f50789f 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -203,7 +203,7 @@ Item { color: type == MtxEvent.NoticeMessage ? palette.buttonText : palette.text font.italic: type == MtxEvent.NoticeMessage - formatted: formattedBody + "a" + formatted: formattedBody Layout.fillWidth: true //Layout.maximumWidth: implicitWidth @@ -262,6 +262,7 @@ Item { text: formattedStateEvent formatted: '' body: '' + horizontalAlignment: Text.AlignHCenter color: palette.buttonText font.italic: true @@ -272,6 +273,79 @@ Item { } } + EventDelegateChoice { + roleValues: [ + MtxEvent.CallInvite, + ] + TextMessage { + keepFullText: true + + required property string userId + required property string userName + required property string callType + + isOnlyEmoji: false + body: formatted + formatted: { + switch (callType) { + case "voice": + return qsTr("%1 placed a voice call.").arg(TimelineManager.escapeEmoji(userName)); + case "video": + return qsTr("%1 placed a video call.").arg(TimelineManager.escapeEmoji(userName)); + default: + return qsTr("%1 placed a call.").arg(TimelineManager.escapeEmoji(userName)); + } + } + + color: palette.buttonText + font.italic: true + + Layout.fillWidth: true + } + } + + EventDelegateChoice { + roleValues: [ + MtxEvent.CallAnswer, + MtxEvent.CallReject, + MtxEvent.CallSelectAnswer, + MtxEvent.CallHangUp, + MtxEvent.CallCandidates, + MtxEvent.CallNegotiate, + ] + TextMessage { + keepFullText: true + + required property string userId + required property string userName + required property int type + + isOnlyEmoji: false + body: formatted + formatted: { + switch (type) { + case MtxEvent.CallAnswer: + return qsTr("%1 answered the call.").arg(TimelineManager.escapeEmoji(userName)); + case MtxEvent.CallReject: + return qsTr("%1 rejected the call.").arg(TimelineManager.escapeEmoji(userName)); + case MtxEvent.CallSelectAnswer: + return qsTr("%1 selected answer.").arg(TimelineManager.escapeEmoji(userName)); + case MtxEvent.CallHangUp: + return qsTr("%1 ended the call.").arg(TimelineManager.escapeEmoji(userName)); + case MtxEvent.CallCandidates: + return qsTr("%1 is negotiating the call...").arg(TimelineManager.escapeEmoji(userName)); + case MtxEvent.CallNegotiate: + return qsTr("%1 is negotiating the call...").arg(TimelineManager.escapeEmoji(userName)); + } + } + + color: palette.buttonText + font.italic: true + + Layout.fillWidth: true + } + } + EventDelegateChoice { roleValues: [ MtxEvent.ImageMessage, @@ -285,6 +359,44 @@ Item { } } + EventDelegateChoice { + roleValues: [ + MtxEvent.FileMessage, + ] + FileMessage { + Layout.fillWidth: true + } + } + + EventDelegateChoice { + roleValues: [ + MtxEvent.VideoMessage, + MtxEvent.AudioMessage, + ] + PlayableMediaMessage { + Layout.fillWidth: true + } + } + + EventDelegateChoice { + roleValues: [ + MtxEvent.Encrypted, + ] + Encrypted { + Layout.fillWidth: true + } + } + + EventDelegateChoice { + roleValues: [ + MtxEvent.Encryption, + ] + EncryptionEnabled { + Layout.fillWidth: true + } + } + + EventDelegateChoice { roleValues: [ MtxEvent.Redacted @@ -298,6 +410,76 @@ Item { } } + EventDelegateChoice { + roleValues: [ + MtxEvent.Member + ] + + ColumnLayout { + id: member + + required property string userId + required property string userName + + required property bool isReply + required property Room room + required property string formattedStateEvent + + NoticeMessage { + body: formatted + isOnlyEmoji: false + isReply: tombstone.isReply + keepFullText: true + isStateEvent: true + Layout.fillWidth: true + formatted: member.formattedStateEvent + } + + Button { + visible: room.showAcceptKnockButton(eventId) + Layout.alignment: Qt.AlignHCenter + text: qsTr("Allow them in") + onClicked: room.acceptKnock(member.eventId) + } + + } + } + + EventDelegateChoice { + roleValues: [ + MtxEvent.Tombstone + ] + + ColumnLayout { + id: tombstone + + required property string userId + required property string userName + + required property string body + required property bool isReply + required property Room room + required property string eventId + + NoticeMessage { + body: formatted + isOnlyEmoji: false + isReply: tombstone.isReply + keepFullText: true + isStateEvent: true + Layout.fillWidth: true + formatted: qsTr("This room was replaced for the following reason: %1").arg(tombstone.body) + } + + Button { + Layout.alignment: Qt.AlignHCenter + text: qsTr("Go to replacement room") + onClicked: tombstone.room.joinReplacementRoom(tombstone.eventId) + } + + } + } + EventDelegateChoice { roleValues: [ ] diff --git a/resources/qml/delegates/Encrypted.qml b/resources/qml/delegates/Encrypted.qml index fdfe958e..7aeeb28a 100644 --- a/resources/qml/delegates/Encrypted.qml +++ b/resources/qml/delegates/Encrypted.qml @@ -8,37 +8,34 @@ import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 import im.nheko 1.0 -Rectangle { +Control { id: r required property int encryptionError required property string eventId - radius: fontMetrics.lineSpacing / 2 + Nheko.paddingMedium - width: parent.width? parent.width : 0 - implicitWidth: encryptedText.implicitWidth+24+Nheko.paddingMedium*3 // Column doesn't provide a useful implicitWidth, should be replaced by ColumnLayout - height: contents.implicitHeight + Nheko.paddingMedium * 2 - color: palette.alternateBase + padding: Nheko.paddingMedium + implicitHeight: contents.implicitHeight + Nheko.paddingMedium * 2 + Layout.maximumWidth: contents.Layout.maximumWidth + padding * 2 + Layout.fillWidth: true - RowLayout { + contentItem: RowLayout { id: contents - anchors.fill: parent - anchors.margins: Nheko.paddingMedium spacing: Nheko.paddingMedium Image { source: "image://colorimage/:/icons/icons/ui/shield-filled-cross.svg?" + Nheko.theme.error Layout.alignment: Qt.AlignVCenter - width: 24 - height: width + Layout.preferredWidth: 24 + Layout.preferredHeight: 24 } - Column { + ColumnLayout { spacing: Nheko.paddingSmall Layout.fillWidth: true - MatrixText { + Label { id: encryptedText text: { switch (encryptionError) { @@ -58,8 +55,11 @@ Rectangle { return qsTr("Unknown decryption error"); } } + textFormat: Text.PlainText + wrapMode: Label.WordWrap color: palette.text - width: parent.width + Layout.fillWidth: true + Layout.maximumWidth: implicitWidth + 1 } Button { @@ -72,4 +72,9 @@ Rectangle { } + background: Rectangle { + color: palette.alternateBase + radius: fontMetrics.lineSpacing / 2 + 2 * Nheko.paddingMedium + visible: !Settings.bubbles // the bubble in a bubble looks odd + } } diff --git a/resources/qml/delegates/EncryptionEnabled.qml b/resources/qml/delegates/EncryptionEnabled.qml index 0e2b7fc0..40894543 100644 --- a/resources/qml/delegates/EncryptionEnabled.qml +++ b/resources/qml/delegates/EncryptionEnabled.qml @@ -3,27 +3,24 @@ // SPDX-License-Identifier: GPL-3.0-or-later import ".." -import QtQuick 2.15 -import QtQuick.Layouts 1.15 -import im.nheko 1.0 +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import im.nheko -Rectangle { +Control { id: r - required property string username + required property string userName - radius: fontMetrics.lineSpacing / 2 + Nheko.paddingMedium - width: parent.width ? Math.min(parent.width, 700) : 0 - height: contents.implicitHeight + Nheko.paddingMedium * 2 - color: palette.alternateBase - border.color: Nheko.theme.green - border.width: 2 + padding: Nheko.paddingMedium + //implicitHeight: contents.implicitHeight + padd * 2 + Layout.maximumWidth: contents.Layout.maximumWidth + padding * 2 + Layout.fillWidth: true - RowLayout { + contentItem: RowLayout { id: contents - anchors.fill: parent - anchors.margins: Nheko.paddingMedium spacing: Nheko.paddingMedium Image { @@ -33,26 +30,36 @@ Rectangle { Layout.preferredHeight: 24 } - Column { + ColumnLayout { spacing: Nheko.paddingSmall Layout.fillWidth: true MatrixText { - text: qsTr("%1 enabled end-to-end encryption").arg(r.username) + text: qsTr("%1 enabled end-to-end encryption").arg(r.userName) font.bold: true font.pointSize: 14 color: palette.text - width: parent.width + Layout.fillWidth: true + Layout.maximumWidth: implicitWidth + 1 } - MatrixText { + Label { text: qsTr("Encryption keeps your messages safe by only allowing the people you sent the message to to read it. For extra security, if you want to make sure you are talking to the right people, you can verify them in real life.") - color: palette.text - width: parent.width + textFormat: Text.PlainText + wrapMode: Label.WordWrap + Layout.fillWidth: true + Layout.maximumWidth: implicitWidth + 1 } } } + background: Rectangle { + radius: fontMetrics.lineSpacing / 2 + Nheko.paddingMedium + height: contents.implicitHeight + Nheko.paddingMedium * 2 + color: palette.alternateBase + border.color: Nheko.theme.green + border.width: 2 + } } diff --git a/resources/qml/delegates/FileMessage.qml b/resources/qml/delegates/FileMessage.qml index 82b82c1b..9f350123 100644 --- a/resources/qml/delegates/FileMessage.qml +++ b/resources/qml/delegates/FileMessage.qml @@ -2,26 +2,30 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -import QtQuick 2.12 -import QtQuick.Layouts 1.2 -import im.nheko 1.0 +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import im.nheko + +Control { + id: evRoot -Item { required property string eventId required property string filename required property string filesize - height: rowa.height + (Settings.bubbles? 16: 24) - implicitWidth: rowa.implicitWidth + metadataWidth - property int metadataWidth - property bool fitsMetadata: true + padding: Settings.bubbles? 8 : 12 + //Layout.preferredHeight: rowa.implicitHeight + padding + //Layout.maximumWidth: rowa.Layout.maximumWidth + metadataWidth + padding + property int metadataWidth: 0 + property bool fitsMetadata: false + + Layout.maximumWidth: rowa.Layout.maximumWidth + padding * 2 - RowLayout { + contentItem: RowLayout { id: rowa - anchors.centerIn: parent - width: parent.width - (Settings.bubbles? 16 : 24) - spacing: 15 + spacing: 16 Rectangle { id: button @@ -63,6 +67,7 @@ Item { id: filename_ Layout.fillWidth: true + Layout.maximumWidth: implicitWidth + 1 text: filename textFormat: Text.PlainText elide: Text.ElideRight @@ -73,6 +78,7 @@ Item { id: filesize_ Layout.fillWidth: true + Layout.maximumWidth: implicitWidth + 1 text: filesize textFormat: Text.PlainText elide: Text.ElideRight @@ -83,11 +89,9 @@ Item { } - Rectangle { + background: Rectangle { color: palette.alternateBase - z: -1 - radius: 10 - anchors.fill: parent + radius: fontMetrics.lineSpacing / 2 + 2 * Nheko.paddingSmall visible: !Settings.bubbles // the bubble in a bubble looks odd } diff --git a/resources/qml/delegates/Redacted.qml b/resources/qml/delegates/Redacted.qml index 1bb3209f..3c496f08 100644 --- a/resources/qml/delegates/Redacted.qml +++ b/resources/qml/delegates/Redacted.qml @@ -36,7 +36,6 @@ Control { property var redactedPair: room.formatRedactedEvent(msgRoot.eventId) text: redactedPair["first"] wrapMode: Label.WordWrap - color: palette.text ToolTip.text: redactedPair["second"] ToolTip.visible: hh.hovered diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp index 7fec38dd..2218d9ee 100644 --- a/src/timeline/EventDelegateChooser.cpp +++ b/src/timeline/EventDelegateChooser.cpp @@ -195,17 +195,22 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) if (!forReply) { auto row = chooser.room_->idToIndex(currentId); - connect(chooser.room_, - &QAbstractItemModel::dataChanged, - obj, - [row, update](const QModelIndex &topLeft, - const QModelIndex &bottomRight, - const QList &changedRoles) { - if (row < topLeft.row() || row > bottomRight.row()) - return; - - update(changedRoles); - }); + auto connection = connect( + chooser.room_, + &QAbstractItemModel::dataChanged, + obj, + [row, update](const QModelIndex &topLeft, + const QModelIndex &bottomRight, + const QList &changedRoles) { + if (row < topLeft.row() || row > bottomRight.row()) + return; + + update(changedRoles); + }, + Qt::QueuedConnection); + connect(&this->chooser, &EventDelegateChooser::destroyed, obj, [connection]() { + QObject::disconnect(connection); + }); } } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 66f7d5b8..3e0c6688 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -757,6 +757,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r return formatHistoryVisibilityEvent(e); else if constexpr (t == mtx::events::EventType::RoomGuestAccess) return formatGuestAccessEvent(e); + else if constexpr (t == mtx::events::EventType::RoomMember) + return formatMemberEvent(e); return tr("%1 changed unknown state event %2.") .arg(displayName(QString::fromStdString(e.sender))) @@ -2958,34 +2960,27 @@ TimelineModel::joinReplacementRoom(const QString &id) } QString -TimelineModel::formatMemberEvent(const QString &id) +TimelineModel::formatMemberEvent( + const mtx::events::StateEvent &event) const { - auto e = events.get(id.toStdString(), ""); - if (!e) - return {}; - - auto event = std::get_if>(e); - if (!event) - return {}; - mtx::events::StateEvent const *prevEvent = nullptr; - if (!event->unsigned_data.replaces_state.empty()) { - auto tempPrevEvent = events.get(event->unsigned_data.replaces_state, event->event_id); + if (!event.unsigned_data.replaces_state.empty()) { + auto tempPrevEvent = events.get(event.unsigned_data.replaces_state, event.event_id); if (tempPrevEvent) { prevEvent = std::get_if>(tempPrevEvent); } } - QString user = QString::fromStdString(event->state_key); + QString user = QString::fromStdString(event.state_key); QString name = utils::replaceEmoji(displayName(user)); QString rendered; - QString sender = QString::fromStdString(event->sender); + QString sender = QString::fromStdString(event.sender); QString senderName = utils::replaceEmoji(displayName(sender)); // see table https://matrix.org/docs/spec/client_server/latest#m-room-member using namespace mtx::events::state; - switch (event->content.membership) { + switch (event.content.membership) { case Membership::Invite: rendered = tr("%1 invited %2.").arg(senderName, name); break; @@ -2994,9 +2989,8 @@ TimelineModel::formatMemberEvent(const QString &id) QString oldName = utils::replaceEmoji( QString::fromStdString(prevEvent->content.display_name).toHtmlEscaped()); - bool displayNameChanged = - prevEvent->content.display_name != event->content.display_name; - bool avatarChanged = prevEvent->content.avatar_url != event->content.avatar_url; + bool displayNameChanged = prevEvent->content.display_name != event.content.display_name; + bool avatarChanged = prevEvent->content.avatar_url != event.content.avatar_url; if (displayNameChanged && avatarChanged) rendered = tr("%1 has changed their avatar and changed their " @@ -3011,30 +3005,30 @@ TimelineModel::formatMemberEvent(const QString &id) // the case of nothing changed but join follows join shouldn't happen, so // just show it as join } else { - if (event->content.join_authorised_via_users_server.empty()) + if (event.content.join_authorised_via_users_server.empty()) rendered = tr("%1 joined.").arg(name); else rendered = tr("%1 joined via authorisation from %2's server.") .arg(name, - QString::fromStdString(event->content.join_authorised_via_users_server)); + QString::fromStdString(event.content.join_authorised_via_users_server)); } break; case Membership::Leave: if (!prevEvent || prevEvent->content.membership == Membership::Join) { - if (event->state_key == event->sender) + if (event.state_key == event.sender) rendered = tr("%1 left the room.").arg(name); else rendered = tr("%2 kicked %1.").arg(name, senderName); } else if (prevEvent->content.membership == Membership::Invite) { - if (event->state_key == event->sender) + if (event.state_key == event.sender) rendered = tr("%1 rejected their invite.").arg(name); else rendered = tr("%2 revoked the invite to %1.").arg(name, senderName); } else if (prevEvent->content.membership == Membership::Ban) { rendered = tr("%2 unbanned %1.").arg(name, senderName); } else if (prevEvent->content.membership == Membership::Knock) { - if (event->state_key == event->sender) + if (event.state_key == event.sender) rendered = tr("%1 redacted their knock.").arg(name); else rendered = tr("%2 rejected the knock from %1.").arg(name, senderName); @@ -3053,8 +3047,8 @@ TimelineModel::formatMemberEvent(const QString &id) break; } - if (event->content.reason != "") { - rendered += " " + tr("Reason: %1").arg(QString::fromStdString(event->content.reason)); + if (event.content.reason != "") { + rendered += " " + tr("Reason: %1").arg(QString::fromStdString(event.content.reason)); } return rendered; diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 2b22ad61..8f787f21 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -310,7 +310,8 @@ public: Q_INVOKABLE bool showAcceptKnockButton(const QString &id); Q_INVOKABLE void acceptKnock(const QString &id); Q_INVOKABLE void joinReplacementRoom(const QString &id); - Q_INVOKABLE QString formatMemberEvent(const QString &id); + Q_INVOKABLE QString + formatMemberEvent(const mtx::events::StateEvent &event) const; Q_INVOKABLE QString formatJoinRuleEvent(const QString &id); QString formatHistoryVisibilityEvent( const mtx::events::StateEvent &event) const; diff --git a/src/voip/CallManager.cpp b/src/voip/CallManager.cpp index 5479ba31..46679e71 100644 --- a/src/voip/CallManager.cpp +++ b/src/voip/CallManager.cpp @@ -92,7 +92,8 @@ CallManager::CallManager(QObject *parent) if (QGuiApplication::platformName() != QStringLiteral("wayland")) { // Selected by default screenShareType_ = ScreenShareType::X11; - std::swap(screenShareTypes_[0], screenShareTypes_[1]); + if (screenShareTypes_.size() >= 2) + std::swap(screenShareTypes_[0], screenShareTypes_[1]); } } #endif -- cgit 1.5.1 From 6c6370c83fab2140a81f431b8909746a0b6833dc Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 8 Oct 2023 20:14:13 +0200 Subject: Switch to manual polishing of event delegates --- resources/qml/MessageView.qml | 4 +- resources/qml/TimelineDefaultMessageStyle.qml | 71 ++++++++++++------------ resources/qml/delegates/MessageDelegate.qml | 1 - resources/qml/delegates/TextMessage.qml | 7 ++- src/timeline/EventDelegateChooser.cpp | 78 ++++++++++++++++++++++++--- src/timeline/EventDelegateChooser.h | 60 +++++++++++++++++++-- src/timeline/TimelineModel.cpp | 8 +-- 7 files changed, 169 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 3cdfda22..3ffe7d9a 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -52,8 +52,8 @@ Item { //onModelChanged: if (room) room.sendReset() //reuseItems: true boundsBehavior: Flickable.StopAtBounds - displayMarginBeginning: height / 2 - displayMarginEnd: height / 2 + displayMarginBeginning: height / 4 + displayMarginEnd: height / 4 model: (filteredTimeline.filterByThread || filteredTimeline.filterByContent) ? filteredTimeline : room //pixelAligned: true spacing: 2 diff --git a/resources/qml/TimelineDefaultMessageStyle.qml b/resources/qml/TimelineDefaultMessageStyle.qml index 1d12daef..0866fab6 100644 --- a/resources/qml/TimelineDefaultMessageStyle.qml +++ b/resources/qml/TimelineDefaultMessageStyle.qml @@ -18,7 +18,7 @@ TimelineEvent { id: wrapper ListView.delayRemove: true width: chat.delegateMaxWidth - height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight + reactionRow.implicitHeight + unreadRow.height, 10) + height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight + reactionRow.implicitHeight + unreadRow.height, 20) anchors.horizontalCenter: ListView.view.contentItem.horizontalCenter //room: chatRoot.roommodel @@ -51,6 +51,8 @@ TimelineEvent { property alias hovered: messageHover.hovered property bool scrolledToThis: false + maxWidth: chat.delegateMaxWidth - avatarMargin - metadata.width + data: [ Loader { id: section @@ -131,7 +133,7 @@ TimelineEvent { anchors.top: gridContainer.top anchors.left: gridContainer.left anchors.topMargin: -2 - anchors.leftMargin: wrapper.avatarMargin + 2 + anchors.leftMargin: -2 color: "transparent" border.color: Nheko.theme.red border.width: wrapper.notificationlevel == MtxEvent.Highlight ? 1 : 0 @@ -139,11 +141,13 @@ TimelineEvent { height: contentColumn.implicitHeight + 4 width: contentColumn.implicitWidth + 4 }, - RowLayout { + Row { id: gridContainer - width: wrapper.width + width: wrapper.width - wrapper.avatarMargin + x: wrapper.avatarMargin y: section.visible && section.active ? section.y + section.height : 0 + spacing: Nheko.paddingSmall HoverHandler { id: messageHover @@ -154,23 +158,20 @@ TimelineEvent { messageActions.model = wrapper; messageActions.attached = wrapper; messageActions.anchors.bottomMargin = -gridContainer.y + messageActions.anchors.rightMargin = metadata.width } } } } - Item { - Layout.preferredWidth: wrapper.avatarMargin - } - AbstractButton { ToolTip.delay: Nheko.tooltipDelay ToolTip.text: qsTr("Part of a thread") ToolTip.visible: hovered - Layout.fillHeight: true + height: contentColumn.height visible: wrapper.threadId - Layout.preferredWidth: 4 + width: 4 onClicked: wrapper.room.thread = wrapper.threadId @@ -181,17 +182,16 @@ TimelineEvent { color: TimelineManager.userColor(wrapper.threadId, palette.base) } } - ColumnLayout { + Column { id: contentColumn - Layout.fillWidth: true AbstractButton { id: replyRow visible: wrapper.reply - Layout.fillWidth: true - Layout.maximumHeight: timelineView.height / 8 - Layout.preferredWidth: replyRowLay.implicitWidth - Layout.preferredHeight: replyRowLay.implicitHeight + //Layout.fillWidth: true + //Layout.maximumHeight: timelineView.height / 8 + //Layout.preferredWidth: replyRowLay.implicitWidth + //Layout.preferredHeight: replyRowLay.implicitHeight property color userColor: TimelineManager.userColor(wrapper.reply?.userId ?? '', palette.base) @@ -202,32 +202,33 @@ TimelineEvent { cursorShape: Qt.PointingHandCursor } - contentItem: RowLayout { + contentItem: Row { id: replyRowLay - anchors.fill: parent - + spacing: Nheko.paddingSmall Rectangle { id: replyLine - Layout.fillHeight: true + height: replyCol.height color: replyRow.userColor - Layout.preferredWidth: 4 + width: 4 } - ColumnLayout { + Column { spacing: 0 + id: replyCol + AbstractButton { id: replyUserButton - Layout.fillWidth: true - contentItem: ElidedLabel { + + contentItem: Label { id: userName_ - fullText: wrapper.reply?.userName ?? '' + text: wrapper.reply?.userName ?? '' color: replyRow.userColor textFormat: Text.RichText - width: parent.width - elideWidth: width + width: wrapper.maxWidth + //elideWidth: wrapper.maxWidth } onClicked: wrapper.room.openUserProfile(wrapper.reply?.userId) } @@ -239,7 +240,7 @@ TimelineEvent { } background: Rectangle { - width: replyRow.implicitContentWidth + //width: replyRow.implicitContentWidth color: Qt.tint(palette.base, Qt.hsla(replyRow.userColor.hslHue, 0.5, replyRow.userColor.hslLightness, 0.1)) } @@ -259,19 +260,16 @@ TimelineEvent { ] } - Item { - // spacer to fill width if needed - Layout.fillWidth: true - } - + }, RowLayout { id: metadata property int iconSize: Math.floor(fontMetrics.ascent * scaling) property double scaling: Settings.bubbles ? 0.75 : 1 - Layout.alignment: Qt.AlignTop | Qt.AlignRight - Layout.preferredWidth: implicitWidth + anchors.right: parent.right + y: section.visible && section.active ? section.y + section.height : 0 + spacing: 2 visible: !isStateEvent @@ -339,8 +337,7 @@ TimelineEvent { } } - } - }, + }, Reactions { id: reactionRow diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 44726a63..cd1bdcd4 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -620,7 +620,6 @@ Item { roleValue: MtxEvent.Member ColumnLayout { - width: parent?.width ?? 100 NoticeMessage { body: formatted diff --git a/resources/qml/delegates/TextMessage.qml b/resources/qml/delegates/TextMessage.qml index 9ef2e6cc..03623924 100644 --- a/resources/qml/delegates/TextMessage.qml +++ b/resources/qml/delegates/TextMessage.qml @@ -4,7 +4,7 @@ import ".." import QtQuick.Controls -import QtQuick.Layouts +//import QtQuick.Layouts import im.nheko MatrixText { @@ -41,7 +41,10 @@ MatrixText { }" : "") + // TODO(Nico): Figure out how to support mobile " " + formatted.replace(//g, "").replace(/<\/del>/g, "").replace(//g, "").replace(/<\/strike>/g, "") - Layout.maximumHeight: !keepFullText ? Math.round(Math.min(timelineView.height / 8, implicitHeight)) : implicitHeight + //Layout.maximumHeight: !keepFullText ? Math.round(Math.min(timelineView.height / 8, implicitHeight)) : implicitHeight + + //EventDelegateChooser.fillWidth: true + clip: !keepFullText selectByMouse: !Settings.mobileMode && !isReply enabled: !Settings.mobileMode && !isReply diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp index 2218d9ee..0060907d 100644 --- a/src/timeline/EventDelegateChooser.cpp +++ b/src/timeline/EventDelegateChooser.cpp @@ -131,7 +131,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) roleToPropIdx.insert(*role, i); roles.emplace_back(*role); - nhlog::ui()->critical("Found prop {}, idx {}, role {}", prop.name(), i, *role); + // nhlog::ui()->critical("Found prop {}, idx {}, role {}", prop.name(), i, *role); } else { nhlog::ui()->critical("Required property {} not found in model!", prop.name()); } @@ -140,14 +140,15 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) nhlog::ui()->debug("Querying data for id {}", currentId.toStdString()); chooser.room_->multiData(currentId, forReply ? chooser.eventId_ : QString(), roles); + Qt::beginPropertyUpdateGroup(); for (const auto &role : roles) { const auto &roleName = roleNames[role.role()]; - nhlog::ui()->critical("Setting role {}, {} to {}", - role.role(), - roleName.toStdString(), - role.data().toString().toStdString()); + // nhlog::ui()->critical("Setting role {}, {} to {}", + // role.role(), + // roleName.toStdString(), + // role.data().toString().toStdString()); - nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[role.role()]).name()); + // nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[role.role()]).name()); mo->property(roleToPropIdx[role.role()]).write(obj, role.data()); if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end()) @@ -156,14 +157,15 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) if (isReplyNeeded) { const auto roleName = QByteArray("isReply"); - nhlog::ui()->critical("Setting role {} to {}", roleName.toStdString(), forReply); + // nhlog::ui()->critical("Setting role {} to {}", roleName.toStdString(), forReply); - nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[-1]).name()); + // nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[-1]).name()); mo->property(roleToPropIdx[-1]).write(obj, forReply); if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end()) QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req); } + Qt::endPropertyUpdateGroup(); // setInitialProperties(rolesToSet); @@ -188,9 +190,12 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) auto mo = obj->metaObject(); chooser.room_->multiData( currentId, forReply ? chooser.eventId_ : QString(), rolesToRequest); + + Qt::beginPropertyUpdateGroup(); for (const auto &role : rolesToRequest) { mo->property(roleToPropIdx[role.role()]).write(obj, role.data()); } + Qt::endPropertyUpdateGroup(); }; if (!forReply) { @@ -257,11 +262,22 @@ EventDelegateChooser::DelegateIncubator::statusChanged(QQmlIncubator::Status sta child->setParentItem(&chooser); QQmlEngine::setObjectOwnership(child, QQmlEngine::ObjectOwnership::JavaScriptOwnership); + + // connect(child, &QQuickItem::parentChanged, child, [child](QQuickItem *) { + // // QTBUG-115687 + // if (child->flags().testFlag(QQuickItem::ItemObservesViewport)) { + // nhlog::ui()->critical("SETTING OBSERVES VIEWPORT"); + // // Re-trigger the parent traversal to get subtreeTransformChangedEnabled turned + // on child->setFlag(QQuickItem::ItemObservesViewport); + // } + // }); + if (forReply) emit chooser.replyChanged(); else emit chooser.mainChanged(); + chooser.polish(); } else if (status == QQmlIncubator::Error) { auto errors_ = errors(); for (const auto &e : qAsConst(errors_)) @@ -269,3 +285,49 @@ EventDelegateChooser::DelegateIncubator::statusChanged(QQmlIncubator::Status sta } } +void +EventDelegateChooser::updatePolish() +{ + auto mainChild = qobject_cast(eventIncubator.object()); + auto replyChild = qobject_cast(replyIncubator.object()); + + nhlog::ui()->critical("POLISHING {}", (void *)this); + + if (mainChild) { + auto attached = qobject_cast( + qmlAttachedPropertiesObject(mainChild)); + Q_ASSERT(attached != nullptr); + + // in theory we could also reset the width, but that doesn't seem to work nicely for text + // areas because of how they cache it. + mainChild->setWidth(maxWidth_); + mainChild->ensurePolished(); + auto width = mainChild->implicitWidth(); + + if (width > maxWidth_ || attached->fillWidth()) + width = maxWidth_; + + nhlog::ui()->debug( + "Made event delegate width: {}, {}", width, mainChild->metaObject()->className()); + mainChild->setWidth(width); + mainChild->ensurePolished(); + } + + if (replyChild) { + auto attached = qobject_cast( + qmlAttachedPropertiesObject(replyChild)); + Q_ASSERT(attached != nullptr); + + // in theory we could also reset the width, but that doesn't seem to work nicely for text + // areas because of how they cache it. + replyChild->setWidth(maxWidth_); + replyChild->ensurePolished(); + auto width = replyChild->implicitWidth(); + + if (width > maxWidth_ || attached->fillWidth()) + width = maxWidth_; + + replyChild->setWidth(width); + replyChild->ensurePolished(); + } +} diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h index 1cd2d65a..ff67ccd8 100644 --- a/src/timeline/EventDelegateChooser.h +++ b/src/timeline/EventDelegateChooser.h @@ -2,9 +2,6 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -// A DelegateChooser like the one, that was added to Qt5.12 (in labs), but compatible with older Qt -// versions see KDE/kquickitemviews see qtdeclarative/qqmldelagatecomponent - #pragma once #include @@ -17,6 +14,32 @@ #include "TimelineModel.h" +class EventDelegateChooserAttachedType : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool fillWidth READ fillWidth WRITE setFillWidth NOTIFY fillWidthChanged) + QML_ANONYMOUS +public: + EventDelegateChooserAttachedType(QObject *parent) + : QObject(parent) + { + } + bool fillWidth() const { return fillWidth_; } + void setFillWidth(bool fill) + { + fillWidth_ = fill; + emit fillWidthChanged(); + } +signals: + void fillWidthChanged(); + +private: + bool fillWidth_ = false, keepAspectRatio = false; + double aspectRatio = 1.; + int maxWidth = -1; + int maxHeight = -1; +}; + class EventDelegateChoice : public QObject { Q_OBJECT @@ -51,14 +74,18 @@ class EventDelegateChooser : public QQuickItem QML_ELEMENT Q_CLASSINFO("DefaultProperty", "choices") -public: + QML_ATTACHED(EventDelegateChooserAttachedType) + Q_PROPERTY(QQmlListProperty choices READ choices CONSTANT FINAL) Q_PROPERTY(QQuickItem *main READ main NOTIFY mainChanged FINAL) Q_PROPERTY(QQuickItem *reply READ reply NOTIFY replyChanged FINAL) Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged REQUIRED FINAL) Q_PROPERTY(QString replyTo READ replyTo WRITE setReplyTo NOTIFY replyToChanged REQUIRED FINAL) Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL) + Q_PROPERTY(bool sameWidth READ sameWidth WRITE setSameWidth NOTIFY sameWidthChanged) + Q_PROPERTY(int maxWidth READ maxWidth WRITE setMaxWidth NOTIFY maxWidthChanged) +public: QQmlListProperty choices(); [[nodiscard]] QQuickItem *main() const @@ -70,6 +97,20 @@ public: return qobject_cast(replyIncubator.object()); } + bool sameWidth() const { return sameWidth_; } + void setSameWidth(bool width) + { + sameWidth_ = width; + emit sameWidthChanged(); + } + bool maxWidth() const { return maxWidth_; } + void setMaxWidth(int width) + { + maxWidth_ = width; + emit maxWidthChanged(); + polish(); + } + void setRoom(TimelineModel *m) { if (m != room_) { @@ -105,12 +146,21 @@ public: void componentComplete() override; + static EventDelegateChooserAttachedType *qmlAttachedProperties(QObject *object) + { + return new EventDelegateChooserAttachedType(object); + } + + void updatePolish() override; + signals: void mainChanged(); void replyChanged(); void roomChanged(); void eventIdChanged(); void replyToChanged(); + void sameWidthChanged(); + void maxWidthChanged(); private: struct DelegateIncubator final : public QQmlIncubator @@ -142,6 +192,8 @@ private: TimelineModel *room_{nullptr}; QString eventId_; QString replyId; + bool sameWidth_ = false; + int maxWidth_ = 400; static void appendChoice(QQmlListProperty *, EventDelegateChoice *); static qsizetype choiceCount(QQmlListProperty *); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 3e0c6688..f5b9e142 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -601,12 +601,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r case UserName: return QVariant(displayName(QString::fromStdString(acc::sender(event)))); case UserPowerlevel: { - return static_cast(mtx::events::state::PowerLevels{ - cache::client() - ->getStateEvent(room_id_.toStdString()) - .value_or(mtx::events::StateEvent{}) - .content} - .user_level(acc::sender(event))); + return static_cast( + permissions_.powerlevelEvent().user_level(acc::sender(event))); } case Day: { -- cgit 1.5.1 From c4d2ec875dfce9c29adab0ec85e4317277b5509d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 8 Oct 2023 23:52:23 +0200 Subject: Fixup reply and state event rendering --- CMakeLists.txt | 1 - resources/qml/TimelineDefaultMessageStyle.qml | 20 +- resources/qml/TimelineEvent.qml | 10 +- resources/qml/delegates/ImageMessage.qml | 30 +- resources/qml/delegates/MessageDelegate.qml | 780 ----------------------- resources/qml/delegates/PlayableMediaMessage.qml | 2 +- resources/qml/delegates/Reply.qml | 50 +- resources/qml/delegates/TextMessage.qml | 3 +- src/timeline/EventDelegateChooser.cpp | 120 ++-- src/timeline/EventDelegateChooser.h | 96 ++- 10 files changed, 211 insertions(+), 901 deletions(-) delete mode 100644 resources/qml/delegates/MessageDelegate.qml (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e02bf34..cbe2b20e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -742,7 +742,6 @@ set(QML_SOURCES resources/qml/delegates/Encrypted.qml resources/qml/delegates/FileMessage.qml resources/qml/delegates/ImageMessage.qml - resources/qml/delegates/MessageDelegate.qml resources/qml/delegates/NoticeMessage.qml resources/qml/delegates/Pill.qml resources/qml/delegates/Placeholder.qml diff --git a/resources/qml/TimelineDefaultMessageStyle.qml b/resources/qml/TimelineDefaultMessageStyle.qml index 0866fab6..8beaa8f0 100644 --- a/resources/qml/TimelineDefaultMessageStyle.qml +++ b/resources/qml/TimelineDefaultMessageStyle.qml @@ -18,7 +18,7 @@ TimelineEvent { id: wrapper ListView.delayRemove: true width: chat.delegateMaxWidth - height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight + reactionRow.implicitHeight + unreadRow.height, 20) + height: Math.max((section.item?.height ?? 0) + gridContainer.implicitHeight + reactionRow.implicitHeight + unreadRow.height, 10) anchors.horizontalCenter: ListView.view.contentItem.horizontalCenter //room: chatRoot.roommodel @@ -51,6 +51,9 @@ TimelineEvent { property alias hovered: messageHover.hovered property bool scrolledToThis: false + mainInset: (threadId ? (4 + Nheko.paddingSmall) : 0) + 4 + replyInset: mainInset + 4 + Nheko.paddingSmall + maxWidth: chat.delegateMaxWidth - avatarMargin - metadata.width data: [ @@ -182,16 +185,21 @@ TimelineEvent { color: TimelineManager.userColor(wrapper.threadId, palette.base) } } + + Item { + visible: wrapper.isStateEvent + width: (wrapper.maxWidth - (wrapper.main?.width ?? 0)) / 2 + height: 1 + } + Column { id: contentColumn AbstractButton { id: replyRow visible: wrapper.reply - //Layout.fillWidth: true - //Layout.maximumHeight: timelineView.height / 8 - //Layout.preferredWidth: replyRowLay.implicitWidth - //Layout.preferredHeight: replyRowLay.implicitHeight + + height: replyLine.height property color userColor: TimelineManager.userColor(wrapper.reply?.userId ?? '', palette.base) @@ -209,7 +217,7 @@ TimelineEvent { Rectangle { id: replyLine - height: replyCol.height + height: Math.min( wrapper.reply?.height, timelineView.height / 5) + Nheko.paddingSmall + replyUserButton.height color: replyRow.userColor width: 4 } diff --git a/resources/qml/TimelineEvent.qml b/resources/qml/TimelineEvent.qml index f1b6bd2a..5120fd12 100644 --- a/resources/qml/TimelineEvent.qml +++ b/resources/qml/TimelineEvent.qml @@ -62,12 +62,10 @@ EventDelegateChooser { required property string userId required property string userName - Layout.fillWidth: true - //Layout.maximumWidth: implicitWidth - body: '' color: palette.buttonText font.italic: true + font.pointSize: Settings.fontSize * 0.8 formatted: '' horizontalAlignment: Text.AlignHCenter isOnlyEmoji: false @@ -202,7 +200,6 @@ EventDelegateChooser { id: member required property string formattedStateEvent - required property bool isReply required property Room room required property string userId required property string userName @@ -212,7 +209,7 @@ EventDelegateChooser { body: formatted formatted: member.formattedStateEvent isOnlyEmoji: false - isReply: member.isReply + isReply: EventDelegateChooser.isReply isStateEvent: true keepFullText: true } @@ -233,7 +230,6 @@ EventDelegateChooser { required property string body required property string eventId - required property bool isReply required property Room room required property string userId required property string userName @@ -243,7 +239,7 @@ EventDelegateChooser { body: formatted formatted: qsTr("This room was replaced for the following reason: %1").arg(tombstone.body) isOnlyEmoji: false - isReply: tombstone.isReply + isReply: EventDelegateChooser.isReply isStateEvent: true keepFullText: true } diff --git a/resources/qml/delegates/ImageMessage.qml b/resources/qml/delegates/ImageMessage.qml index 0369d5a1..06a1a9e7 100644 --- a/resources/qml/delegates/ImageMessage.qml +++ b/resources/qml/delegates/ImageMessage.qml @@ -5,7 +5,6 @@ import QtQuick import QtQuick.Window import QtQuick.Controls -import QtQuick.Layouts import im.nheko AbstractButton { @@ -17,16 +16,17 @@ AbstractButton { required property string blurhash required property string body required property string filename - required property bool isReply required property string eventId required property int containerHeight - property double divisor: isReply ? 5 : 3 + property double divisor: EventDelegateChooser.isReply ? 5 : 3 + + EventDelegateChooser.keepAspectRatio: true + EventDelegateChooser.maxWidth: originalWidth + EventDelegateChooser.maxHeight: containerHeight / divisor + EventDelegateChooser.aspectRatio: proportionalHeight - //Layout.maximumWidth: originalWidth - Layout.maximumHeight: Math.min(originalHeight, containerHeight / divisor) - implicitWidth: height/proportionalHeight - implicitHeight: Math.min(Layout.maximumHeight, width*proportionalHeight) hoverEnabled: true + enabled: !EventDelegateChooser.isReply state: (img.status != Image.Ready || timeline.privacyScreen.active) ? "BlurhashVisible" : "ImageVisible" states: [ @@ -133,8 +133,8 @@ AbstractButton { roomm: room play: !Settings.animateImagesOnHover || parent.hovered eventId: parent.eventId - width: parent.implicitWidth - height: parent.implicitHeight + + anchors.fill: parent } Image { @@ -143,10 +143,10 @@ AbstractButton { source: blurhash ? ("image://blurhash/" + blurhash) : ("image://colorimage/:/icons/icons/ui/image-failed.svg?" + palette.buttonText) asynchronous: true fillMode: Image.PreserveAspectFit - sourceSize.width: parent.implicitWidth * Screen.devicePixelRatio - sourceSize.height: parent.implicitHeight * Screen.devicePixelRatio - width: parent.implicitWidth - height: parent.implicitHeight + sourceSize.width: parent.width * Screen.devicePixelRatio + sourceSize.height: parent.height * Screen.devicePixelRatio + + anchors.fill: parent } onClicked: Settings.openImageExternal ? room.openMedia(eventId) : TimelineManager.openImageOverlay(room, url, eventId, originalWidth, proportionalHeight); @@ -154,8 +154,8 @@ AbstractButton { Item { id: overlay - width: parent.implicitWidth - height: parent.implicitHeight + anchors.fill: parent + visible: parent.hovered Rectangle { diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml deleted file mode 100644 index cd1bdcd4..00000000 --- a/resources/qml/delegates/MessageDelegate.qml +++ /dev/null @@ -1,780 +0,0 @@ -// SPDX-FileCopyrightText: Nheko Contributors -// -// SPDX-License-Identifier: GPL-3.0-or-later - -import QtQuick 2.6 -import QtQuick.Controls 2.1 -import QtQuick.Layouts 1.2 -import im.nheko 1.0 - -Item { - id: d - - required property bool isReply - property bool keepFullText: !isReply - property alias child: chooser.child - //implicitWidth: chooser.child?.implicitWidth ?? 0 - required property double proportionalHeight - required property int type - required property string typeString - required property int originalWidth - required property int duration - required property string blurhash - required property string body - required property string formattedBody - required property string eventId - required property string filename - required property string filesize - required property string url - required property string thumbnailUrl - required property bool isOnlyEmoji - required property bool isStateEvent - required property string userId - required property string userName - required property string roomTopic - required property string roomName - required property string callType - required property int encryptionError - required property int relatedEventCacheBuster - property bool fitsMetadata: (chooser.child && chooser.child.fitsMetadata) ? chooser.child.fitsMetadata : false - property int metadataWidth - - implicitWidth: chooser.child?.implicitWidth - - height: chooser.child ? chooser.child.height : Nheko.paddingLarge - - DelegateChooser { - id: chooser - - //role: "type" //< not supported in our custom implementation, have to use roleValue - roleValue: type - //anchors.fill: parent - - width: parent?.width ?? 0 // this should get rid of "cannot read property 'width' of null" - - DelegateChoice { - roleValue: MtxEvent.UnknownEvent - - Placeholder { - typeString: d.typeString - text: "Unretrieved event" - } - - } - - DelegateChoice { - roleValue: MtxEvent.Tombstone - - - ColumnLayout { - width: parent.width - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - Layout.fillWidth: true - formatted: qsTr("This room was replaced for the following reason: %1").arg(d.body) - } - - Button { - Layout.alignment: Qt.AlignHCenter - text: qsTr("Go to replacement room") - onClicked: room.joinReplacementRoom(eventId) - } - - } - } - - DelegateChoice { - roleValue: MtxEvent.TextMessage - - TextMessage { - formatted: d.formattedBody - body: d.body - isOnlyEmoji: d.isOnlyEmoji - isReply: d.isReply - keepFullText: d.keepFullText - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.UnknownMessage - - TextMessage { - formatted: d.formattedBody - body: d.body - isOnlyEmoji: d.isOnlyEmoji - isReply: d.isReply - keepFullText: d.keepFullText - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.ElementEffectMessage - - TextMessage { - formatted: d.formattedBody - body: d.body - isOnlyEmoji: d.isOnlyEmoji - isReply: d.isReply - keepFullText: d.keepFullText - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.NoticeMessage - - NoticeMessage { - formatted: d.formattedBody - body: d.body - isOnlyEmoji: d.isOnlyEmoji - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.EmoteMessage - - NoticeMessage { - formatted: TimelineManager.escapeEmoji(d.userName) + " " + d.formattedBody - color: TimelineManager.userColor(d.userId, palette.base) - body: d.body - isOnlyEmoji: d.isOnlyEmoji - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.ImageMessage - - ImageMessage { - type: d.type - originalWidth: d.originalWidth - proportionalHeight: d.proportionalHeight - url: d.url - blurhash: d.blurhash - body: d.body - filename: d.filename - isReply: d.isReply - eventId: d.eventId - metadataWidth: d.metadataWidth - containerHeight: timelineView.height - } - - } - - DelegateChoice { - roleValue: MtxEvent.Sticker - - ImageMessage { - type: d.type - originalWidth: d.originalWidth - proportionalHeight: d.proportionalHeight - url: d.url - blurhash: d.blurhash - body: d.body - filename: d.filename - isReply: d.isReply - eventId: d.eventId - metadataWidth: d.metadataWidth - containerHeight: timelineView.height - } - - } - - DelegateChoice { - roleValue: MtxEvent.FileMessage - - FileMessage { - eventId: d.eventId - filename: d.filename - filesize: d.filesize - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.VideoMessage - - PlayableMediaMessage { - proportionalHeight: d.proportionalHeight - type: d.type - originalWidth: d.originalWidth - thumbnailUrl: d.thumbnailUrl - eventId: d.eventId - url: d.url - body: d.body - filesize: d.filesize - duration: d.duration - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.AudioMessage - - PlayableMediaMessage { - proportionalHeight: d.proportionalHeight - type: d.type - originalWidth: d.originalWidth - thumbnailUrl: d.thumbnailUrl - eventId: d.eventId - url: d.url - body: d.body - filesize: d.filesize - duration: d.duration - metadataWidth: d.metadataWidth - } - - } - - DelegateChoice { - roleValue: MtxEvent.Redacted - - Redacted { - metadataWidth: d.metadataWidth - } - } - - DelegateChoice { - roleValue: MtxEvent.Redaction - - Pill { - text: qsTr("%1 removed a message").arg(d.userName) - isStateEvent: d.isStateEvent - } - - } - - DelegateChoice { - roleValue: MtxEvent.Encryption - - EncryptionEnabled { - username: d.userName - } - - } - - DelegateChoice { - roleValue: MtxEvent.Encrypted - - Encrypted { - encryptionError: d.encryptionError - eventId: d.eventId - } - - } - - DelegateChoice { - roleValue: MtxEvent.ServerAcl - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 changed which servers are allowed in this room.").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.Name - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.roomName ? qsTr("%2 changed the room name to: %1").arg(d.roomName).arg(d.userName) : qsTr("%1 removed the room name").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.Topic - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.roomTopic ? qsTr("%2 changed the topic to: %1").arg(d.roomTopic).arg(d.userName): qsTr("%1 removed the topic").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.Avatar - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 changed the room avatar").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.PinnedEvents - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 changed the pinned messages.").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.ImagePackInRoom - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatImagePackEvent(d.eventId) - } - - } - - - DelegateChoice { - roleValue: MtxEvent.CanonicalAlias - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 changed the addresses for this room.").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.SpaceParent - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 changed the parent communities for this room.").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.RoomCreate - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 created and configured room: %2").arg(d.userName).arg(room.roomId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.CallInvite - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: { - switch (d.callType) { - case "voice": - return qsTr("%1 placed a voice call.").arg(d.userName); - case "video": - return qsTr("%1 placed a video call.").arg(d.userName); - default: - return qsTr("%1 placed a call.").arg(d.userName); - } - } - } - - } - - DelegateChoice { - roleValue: MtxEvent.CallAnswer - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 answered the call.").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.CallReject - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 rejected the call.").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.CallSelectAnswer - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 select answer").arg(d.userName) - // formatted: qsTr("Call answered elsewhere") - } - } - - DelegateChoice { - roleValue: MtxEvent.CallHangUp - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 ended the call.").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.CallCandidates - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 is negotiating the call...").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.CallNegotiate - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: qsTr("%1 is negotiating the call...").arg(d.userName) - } - - } - - DelegateChoice { - roleValue: MtxEvent.PowerLevels - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatPowerLevelEvent(d.eventId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.PolicyRuleUser - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatPolicyRule(d.eventId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.PolicyRuleRoom - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatPolicyRule(d.eventId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.PolicyRuleServer - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatPolicyRule(d.eventId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.RoomJoinRules - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatJoinRuleEvent(d.eventId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.RoomHistoryVisibility - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatHistoryVisibilityEvent(d.eventId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.RoomGuestAccess - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: d.relatedEventCacheBuster, room.formatGuestAccessEvent(d.eventId) - } - - } - - DelegateChoice { - roleValue: MtxEvent.Member - - ColumnLayout { - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - Layout.fillWidth: true - formatted: d.relatedEventCacheBuster, room.formatMemberEvent(d.eventId) - } - - Button { - visible: d.relatedEventCacheBuster, room.showAcceptKnockButton(d.eventId) - Layout.alignment: Qt.AlignHCenter - text: qsTr("Allow them in") - onClicked: room.acceptKnock(eventId) - } - - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationRequest - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationRequest" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationStart - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationStart" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationReady - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationReady" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationCancel - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationCancel" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationKey - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationKey" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationMac - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationMac" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationDone - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationDone" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationDone - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationDone" - } - - } - - DelegateChoice { - roleValue: MtxEvent.KeyVerificationAccept - - NoticeMessage { - body: formatted - isOnlyEmoji: false - isReply: d.isReply - keepFullText: d.keepFullText - isStateEvent: d.isStateEvent - formatted: "KeyVerificationAccept" - } - - } - - DelegateChoice { - Placeholder { - typeString: d.typeString - } - - } - - } - -} diff --git a/resources/qml/delegates/PlayableMediaMessage.qml b/resources/qml/delegates/PlayableMediaMessage.qml index fb7bf0cc..ac4a82b0 100644 --- a/resources/qml/delegates/PlayableMediaMessage.qml +++ b/resources/qml/delegates/PlayableMediaMessage.qml @@ -22,7 +22,7 @@ Item { required property string url required property string body required property string filesize - property double divisor: isReply ? 4 : 2 + property double divisor: EventDelegateChooser.isReply ? 5 : 3 property int tempWidth: originalWidth < 1? 400: originalWidth implicitWidth: type == MtxEvent.VideoMessage ? Math.round(tempWidth*Math.min((timelineView.height/divisor)/(tempWidth*proportionalHeight), 1)) : 500 width: Math.min(parent?.width ?? implicitWidth, implicitWidth) diff --git a/resources/qml/delegates/Reply.qml b/resources/qml/delegates/Reply.qml index 52cc982d..1598e8c0 100644 --- a/resources/qml/delegates/Reply.qml +++ b/resources/qml/delegates/Reply.qml @@ -48,51 +48,43 @@ AbstractButton { room: room_ eventId: r.eventId replyTo: "" + mainInset: 4 + Nheko.paddingMedium + maxWidth: r.maxWidth //height: replyContainer.implicitHeight - data: GridLayout { + data: Row { id: replyContainer - width: r.maxWidth - columns: 2 - rows: 2 - columnSpacing: Nheko.paddingMedium - rowSpacing: Nheko.paddingSmall + spacing: Nheko.paddingSmall Rectangle { id: colorline - Layout.preferredWidth: 4 - Layout.rowSpan: 2 - Layout.fillHeight: true - - Layout.row: 0 - Layout.column: 0 + width: 4 color: TimelineManager.userColor(r.userId, palette.base) } - AbstractButton { - id: usernameBtn - Layout.fillWidth: true + Column { + spacing: 0 - Layout.row: 0 - Layout.column: 1 + AbstractButton { + id: usernameBtn - contentItem: ElidedLabel { - id: userName_ - fullText: r.userName - color: r.userColor - textFormat: Text.RichText - width: parent.width - elideWidth: width + contentItem: Label { + id: userName_ + text: r.userName + color: r.userColor + textFormat: Text.RichText + width: timelineEvent.main?.width + } + onClicked: room.openUserProfile(r.userId) } - onClicked: room.openUserProfile(r.userId) - } - data: [ - colorline, usernameBtn, timelineEvent.main, - ] + data: [ + usernameBtn, timelineEvent.main, + ] + } } } diff --git a/resources/qml/delegates/TextMessage.qml b/resources/qml/delegates/TextMessage.qml index 03623924..e9254eed 100644 --- a/resources/qml/delegates/TextMessage.qml +++ b/resources/qml/delegates/TextMessage.qml @@ -10,7 +10,7 @@ import im.nheko MatrixText { required property string body required property bool isOnlyEmoji - required property bool isReply + property bool isReply: EventDelegateChooser.isReply required property bool keepFullText required property string formatted @@ -45,7 +45,6 @@ MatrixText { //EventDelegateChooser.fillWidth: true - clip: !keepFullText selectByMouse: !Settings.mobileMode && !isReply enabled: !Settings.mobileMode && !isReply hoverEnabled: !Settings.mobileMode diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp index 0060907d..a8629b3e 100644 --- a/src/timeline/EventDelegateChooser.cpp +++ b/src/timeline/EventDelegateChooser.cpp @@ -97,6 +97,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) return; item->setParentItem(&chooser); + item->setParent(&chooser); auto roleNames = chooser.room_->roleNames(); QHash nameToRole; @@ -106,8 +107,6 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) QHash roleToPropIdx; std::vector roles; - bool isReplyNeeded = false; - // Workaround for https://bugreports.qt.io/browse/QTBUG-98846 QHash requiredProperties; for (const auto &[propKey, prop] : @@ -124,10 +123,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) if (!prop.isRequired() && !requiredProperties.contains(prop.name())) continue; - if (prop.name() == std::string_view("isReply")) { - isReplyNeeded = true; - roleToPropIdx.insert(-1, i); - } else if (auto role = nameToRole.find(prop.name()); role != nameToRole.end()) { + if (auto role = nameToRole.find(prop.name()); role != nameToRole.end()) { roleToPropIdx.insert(*role, i); roles.emplace_back(*role); @@ -141,6 +137,11 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) chooser.room_->multiData(currentId, forReply ? chooser.eventId_ : QString(), roles); Qt::beginPropertyUpdateGroup(); + auto attached = qobject_cast( + qmlAttachedPropertiesObject(obj)); + Q_ASSERT(attached != nullptr); + attached->setIsReply(this->forReply); + for (const auto &role : roles) { const auto &roleName = roleNames[role.role()]; // nhlog::ui()->critical("Setting role {}, {} to {}", @@ -155,22 +156,25 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req); } - if (isReplyNeeded) { - const auto roleName = QByteArray("isReply"); - // nhlog::ui()->critical("Setting role {} to {}", roleName.toStdString(), forReply); - - // nhlog::ui()->critical("Setting {}", mo->property(roleToPropIdx[-1]).name()); - mo->property(roleToPropIdx[-1]).write(obj, forReply); - - if (const auto &req = requiredProperties.find(roleName); req != requiredProperties.end()) - QQmlIncubatorPrivate::get(this)->requiredProperties()->remove(*req); - } Qt::endPropertyUpdateGroup(); // setInitialProperties(rolesToSet); auto update = [this, obj, roleToPropIdx = std::move(roleToPropIdx)](const QList &changedRoles) { + if (changedRoles.empty() || changedRoles.contains(TimelineModel::Roles::Type)) { + int type = chooser.room_ + ->dataById(currentId, + TimelineModel::Roles::Type, + forReply ? chooser.eventId_ : QString()) + .toInt(); + if (type != oldType) { + nhlog::ui()->debug("Type changed!"); + reset(currentId); + return; + } + } + std::vector rolesToRequest; if (changedRoles.empty()) { @@ -233,6 +237,7 @@ EventDelegateChooser::DelegateIncubator::reset(QString id) chooser.room_ ->dataById(id, TimelineModel::Roles::Type, forReply ? chooser.eventId_ : QString()) .toInt(); + this->oldType = role; for (const auto choice : qAsConst(chooser.choices_)) { const auto &choiceValue = choice->roleValues(); @@ -293,41 +298,58 @@ EventDelegateChooser::updatePolish() nhlog::ui()->critical("POLISHING {}", (void *)this); - if (mainChild) { - auto attached = qobject_cast( - qmlAttachedPropertiesObject(mainChild)); - Q_ASSERT(attached != nullptr); - - // in theory we could also reset the width, but that doesn't seem to work nicely for text - // areas because of how they cache it. - mainChild->setWidth(maxWidth_); - mainChild->ensurePolished(); - auto width = mainChild->implicitWidth(); - - if (width > maxWidth_ || attached->fillWidth()) - width = maxWidth_; - - nhlog::ui()->debug( - "Made event delegate width: {}, {}", width, mainChild->metaObject()->className()); - mainChild->setWidth(width); - mainChild->ensurePolished(); - } - - if (replyChild) { - auto attached = qobject_cast( - qmlAttachedPropertiesObject(replyChild)); - Q_ASSERT(attached != nullptr); + auto layoutItem = [this](QQuickItem *item, int inset) { + if (item) { + auto attached = qobject_cast( + qmlAttachedPropertiesObject(item)); + Q_ASSERT(attached != nullptr); + + int maxWidth = maxWidth_ - inset; + + // in theory we could also reset the width, but that doesn't seem to work nicely for + // text areas because of how they cache it. + if (attached->maxWidth() > 0) + item->setWidth(attached->maxWidth()); + else + item->setWidth(maxWidth); + item->ensurePolished(); + auto width = item->implicitWidth(); + + if (width < 1 || width > maxWidth) + width = maxWidth; + + if (attached->maxWidth() > 0 && width > attached->maxWidth()) + width = attached->maxWidth(); + + if (attached->keepAspectRatio()) { + auto height = width * attached->aspectRatio(); + if (attached->maxHeight() && height > attached->maxHeight()) { + height = attached->maxHeight(); + width = height / attached->aspectRatio(); + } + + item->setHeight(height); + } - // in theory we could also reset the width, but that doesn't seem to work nicely for text - // areas because of how they cache it. - replyChild->setWidth(maxWidth_); - replyChild->ensurePolished(); - auto width = replyChild->implicitWidth(); + nhlog::ui()->debug( + "Made event delegate width: {}, {}", width, item->metaObject()->className()); + item->setWidth(width); + item->ensurePolished(); + } + }; - if (width > maxWidth_ || attached->fillWidth()) - width = maxWidth_; + layoutItem(mainChild, mainInset_); + layoutItem(replyChild, replyInset_); +} - replyChild->setWidth(width); - replyChild->ensurePolished(); +void +EventDelegateChooserAttachedType::polishChooser() +{ + auto p = parent(); + if (p) { + auto chooser = qobject_cast(p->parent()); + if (chooser) { + chooser->polish(); + } } } diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h index ff67ccd8..ce79444a 100644 --- a/src/timeline/EventDelegateChooser.h +++ b/src/timeline/EventDelegateChooser.h @@ -17,27 +17,78 @@ class EventDelegateChooserAttachedType : public QObject { Q_OBJECT - Q_PROPERTY(bool fillWidth READ fillWidth WRITE setFillWidth NOTIFY fillWidthChanged) + Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio NOTIFY + keepAspectRatioChanged) + Q_PROPERTY(double aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged) + Q_PROPERTY(int maxWidth READ maxWidth WRITE setMaxWidth NOTIFY maxWidthChanged) + Q_PROPERTY(int maxHeight READ maxHeight WRITE setMaxHeight NOTIFY maxHeightChanged) + Q_PROPERTY(bool isReply READ isReply WRITE setIsReply NOTIFY isReplyChanged) + QML_ANONYMOUS public: EventDelegateChooserAttachedType(QObject *parent) : QObject(parent) { } - bool fillWidth() const { return fillWidth_; } - void setFillWidth(bool fill) + + bool keepAspectRatio() const { return keepAspectRatio_; } + void setKeepAspectRatio(bool fill) + { + if (fill != keepAspectRatio_) { + keepAspectRatio_ = fill; + emit keepAspectRatioChanged(); + polishChooser(); + } + } + + double aspectRatio() const { return aspectRatio_; } + void setAspectRatio(double fill) { - fillWidth_ = fill; - emit fillWidthChanged(); + aspectRatio_ = fill; + emit aspectRatioChanged(); + polishChooser(); } + + int maxWidth() const { return maxWidth_; } + void setMaxWidth(int fill) + { + maxWidth_ = fill; + emit maxWidthChanged(); + polishChooser(); + } + + int maxHeight() const { return maxHeight_; } + void setMaxHeight(int fill) + { + maxHeight_ = fill; + emit maxHeightChanged(); + } + + bool isReply() const { return isReply_; } + void setIsReply(bool fill) + { + if (fill != isReply_) { + isReply_ = fill; + emit isReplyChanged(); + polishChooser(); + } + } + signals: - void fillWidthChanged(); + void keepAspectRatioChanged(); + void aspectRatioChanged(); + void maxWidthChanged(); + void maxHeightChanged(); + void isReplyChanged(); private: - bool fillWidth_ = false, keepAspectRatio = false; - double aspectRatio = 1.; - int maxWidth = -1; - int maxHeight = -1; + void polishChooser(); + + double aspectRatio_ = 1.; + int maxWidth_ = -1; + int maxHeight_ = -1; + bool keepAspectRatio_ = false; + bool isReply_ = false; }; class EventDelegateChoice : public QObject @@ -84,6 +135,8 @@ class EventDelegateChooser : public QQuickItem Q_PROPERTY(TimelineModel *room READ room WRITE setRoom NOTIFY roomChanged REQUIRED FINAL) Q_PROPERTY(bool sameWidth READ sameWidth WRITE setSameWidth NOTIFY sameWidthChanged) Q_PROPERTY(int maxWidth READ maxWidth WRITE setMaxWidth NOTIFY maxWidthChanged) + Q_PROPERTY(int replyInset READ replyInset WRITE setReplyInset NOTIFY replyInsetChanged) + Q_PROPERTY(int mainInset READ mainInset WRITE setMainInset NOTIFY mainInsetChanged) public: QQmlListProperty choices(); @@ -103,7 +156,7 @@ public: sameWidth_ = width; emit sameWidthChanged(); } - bool maxWidth() const { return maxWidth_; } + int maxWidth() const { return maxWidth_; } void setMaxWidth(int width) { maxWidth_ = width; @@ -111,6 +164,22 @@ public: polish(); } + int replyInset() const { return replyInset_; } + void setReplyInset(int width) + { + replyInset_ = width; + emit replyInsetChanged(); + polish(); + } + + int mainInset() const { return mainInset_; } + void setMainInset(int width) + { + mainInset_ = width; + emit mainInsetChanged(); + polish(); + } + void setRoom(TimelineModel *m) { if (m != room_) { @@ -161,6 +230,8 @@ signals: void replyToChanged(); void sameWidthChanged(); void maxWidthChanged(); + void replyInsetChanged(); + void mainInsetChanged(); private: struct DelegateIncubator final : public QQmlIncubator @@ -183,6 +254,7 @@ private: QString instantiatedId; int instantiatedRole = -1; QAbstractItemModel *instantiatedModel = nullptr; + int oldType = -1; }; QVariant roleValue_; @@ -194,6 +266,8 @@ private: QString replyId; bool sameWidth_ = false; int maxWidth_ = 400; + int replyInset_ = 0; + int mainInset_ = 0; static void appendChoice(QQmlListProperty *, EventDelegateChoice *); static qsizetype choiceCount(QQmlListProperty *); -- cgit 1.5.1 From 2a687a202af605763ce49880cf11379ce4c95d44 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 9 Oct 2023 00:20:30 +0200 Subject: Fix typing notifications --- src/timeline/EventDelegateChooser.cpp | 4 ++-- src/timeline/EventDelegateChooser.h | 6 +++--- src/timeline/RoomlistModel.cpp | 2 +- src/timeline/TimelineModel.cpp | 5 +++-- src/timeline/TimelineModel.h | 14 +++++++------- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp index a8629b3e..e2319460 100644 --- a/src/timeline/EventDelegateChooser.cpp +++ b/src/timeline/EventDelegateChooser.cpp @@ -203,7 +203,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) }; if (!forReply) { - auto row = chooser.room_->idToIndex(currentId); + auto row = chooser.room_->idToIndex(currentId); auto connection = connect( chooser.room_, &QAbstractItemModel::dataChanged, @@ -293,7 +293,7 @@ EventDelegateChooser::DelegateIncubator::statusChanged(QQmlIncubator::Status sta void EventDelegateChooser::updatePolish() { - auto mainChild = qobject_cast(eventIncubator.object()); + auto mainChild = qobject_cast(eventIncubator.object()); auto replyChild = qobject_cast(replyIncubator.object()); nhlog::ui()->critical("POLISHING {}", (void *)this); diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h index ce79444a..df1953ab 100644 --- a/src/timeline/EventDelegateChooser.h +++ b/src/timeline/EventDelegateChooser.h @@ -84,8 +84,8 @@ signals: private: void polishChooser(); - double aspectRatio_ = 1.; - int maxWidth_ = -1; + double aspectRatio_ = 1.; + int maxWidth_ = -1; int maxHeight_ = -1; bool keepAspectRatio_ = false; bool isReply_ = false; @@ -252,7 +252,7 @@ private: QString currentId; QString instantiatedId; - int instantiatedRole = -1; + int instantiatedRole = -1; QAbstractItemModel *instantiatedModel = nullptr; int oldType = -1; }; diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 8d8d2977..2bffc9be 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -541,7 +541,7 @@ RoomlistModel::sync(const mtx::responses::Sync &sync_) if (auto t = std::get_if>( &ev)) { - std::vector typing; + QStringList typing; typing.reserve(t->content.user_ids.size()); for (const auto &user : t->content.user_ids) { if (user != http::client()->user_id().to_string()) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index f5b9e142..c2bcfeb5 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -2288,8 +2288,9 @@ TimelineModel::markSpecialEffectsDone() } QString -TimelineModel::formatTypingUsers(const std::vector &users, const QColor &bg) +TimelineModel::formatTypingUsers(const QStringList &users, const QColor &bg) { + nhlog::db()->critical("TYPING USERS!"); QString temp = tr("%1 and %2 are typing.", "Multiple users are typing. First argument is a comma separated list of potentially " @@ -2335,7 +2336,7 @@ TimelineModel::formatTypingUsers(const std::vector &users, const QColor }; uidWithoutLast.reserve(static_cast(users.size())); - for (size_t i = 0; i + 1 < users.size(); i++) { + for (qsizetype i = 0; i + 1 < users.size(); i++) { uidWithoutLast.append(formatUser(users[i])); } diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 8f787f21..23c3c802 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -199,8 +199,8 @@ class TimelineModel final : public QAbstractListModel QML_UNCREATABLE("") Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(std::vector typingUsers READ typingUsers WRITE updateTypingUsers NOTIFY - typingUsersChanged) + Q_PROPERTY( + QStringList typingUsers READ typingUsers WRITE updateTypingUsers NOTIFY typingUsersChanged) Q_PROPERTY(QString scrollTarget READ scrollTarget NOTIFY scrollTargetChanged) Q_PROPERTY(QString reply READ reply WRITE setReply NOTIFY replyChanged RESET resetReply) Q_PROPERTY(QString edit READ edit WRITE setEdit NOTIFY editChanged RESET resetEdit) @@ -306,7 +306,7 @@ public: Q_INVOKABLE QString displayName(const QString &id) const; Q_INVOKABLE QString avatarUrl(const QString &id) const; Q_INVOKABLE QString formatDateSeparator(QDate date) const; - Q_INVOKABLE QString formatTypingUsers(const std::vector &users, const QColor &bg); + Q_INVOKABLE QString formatTypingUsers(const QStringList &users, const QColor &bg); Q_INVOKABLE bool showAcceptKnockButton(const QString &id); Q_INVOKABLE void acceptKnock(const QString &id); Q_INVOKABLE void joinReplacementRoom(const QString &id); @@ -405,14 +405,14 @@ public slots: void lastReadIdOnWindowFocus(); void checkAfterFetch(); QVariantMap getDump(const QString &eventId, const QString &relatedTo) const; - void updateTypingUsers(const std::vector &users) + void updateTypingUsers(const QStringList &users) { if (this->typingUsers_ != users) { this->typingUsers_ = users; emit typingUsersChanged(typingUsers_); } } - std::vector typingUsers() const { return typingUsers_; } + QStringList typingUsers() const { return typingUsers_; } bool paginationInProgress() const { return m_paginationInProgress; } QString reply() const { return reply_; } void setReply(const QString &newReply); @@ -470,7 +470,7 @@ signals: void redactionFailed(QString id); void mediaCached(QString mxcUrl, QString cacheUrl); void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo); - void typingUsersChanged(std::vector users); + void typingUsersChanged(QStringList users); void replyChanged(QString reply); void editChanged(QString reply); void threadChanged(QString id); @@ -528,7 +528,7 @@ private: QString currentId, currentReadId; QString reply_, edit_, thread_; QString textBeforeEdit, replyBeforeEdit; - std::vector typingUsers_; + QStringList typingUsers_; TimelineViewManager *manager_; -- cgit 1.5.1 From b03bfa53e46215d49e658f226a8eb6acd7993aab Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 9 Oct 2023 04:18:16 +0200 Subject: Fix CPU usage from out of frame animated images --- src/ui/MxcAnimatedImage.cpp | 9 +++++++-- src/ui/MxcAnimatedImage.h | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/MxcAnimatedImage.cpp b/src/ui/MxcAnimatedImage.cpp index 14f5dbd8..ffe54c71 100644 --- a/src/ui/MxcAnimatedImage.cpp +++ b/src/ui/MxcAnimatedImage.cpp @@ -102,10 +102,12 @@ MxcAnimatedImage::startDownload() if (buffer.bytesAvailable() < 4LL * 1024 * 1024 * 1024) // cache images smaller than 4MB in RAM movie.setCacheMode(QMovie::CacheAll); - if (play_) + if (play_ && movie.frameCount() > 1) movie.start(); - else + else { movie.jumpToFrame(0); + movie.setPaused(true); + } emit loadedChanged(); update(); }); @@ -173,6 +175,9 @@ MxcAnimatedImage::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeD if (!imageDirty) return oldNode; + if (clipRect().isEmpty()) + return oldNode; + imageDirty = false; QSGImageNode *n = static_cast(oldNode); if (!n) { diff --git a/src/ui/MxcAnimatedImage.h b/src/ui/MxcAnimatedImage.h index c9f89764..1f2c0b74 100644 --- a/src/ui/MxcAnimatedImage.h +++ b/src/ui/MxcAnimatedImage.h @@ -29,6 +29,7 @@ public: connect(this, &MxcAnimatedImage::roomChanged, &MxcAnimatedImage::startDownload); connect(&movie, &QMovie::frameChanged, this, &MxcAnimatedImage::newFrame); setFlag(QQuickItem::ItemHasContents); + setFlag(QQuickItem::ItemObservesViewport); // setAcceptHoverEvents(true); } @@ -55,7 +56,12 @@ public: { if (play_ != newPlay) { play_ = newPlay; - movie.setPaused(!play_); + if (movie.frameCount() > 1) + movie.setPaused(!play_); + else { + movie.jumpToFrame(0); + movie.setPaused(true); + } emit playChanged(); } } @@ -77,7 +83,8 @@ private slots: { currentFrame = frame; imageDirty = true; - update(); + if (!clipRect().isEmpty()) + update(); } private: -- cgit 1.5.1 From b29ce3ca440760c9681e56a6c8e0067de3dd9e61 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 9 Oct 2023 21:58:21 +0200 Subject: cleanups --- .gitlab-ci.yml | 2 +- resources/qml/TimelineBubbleMessageStyle.qml | 2 +- src/timeline/EventDelegateChooser.cpp | 19 ++++++++++--------- src/timeline/TimelineModel.cpp | 1 - 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0dab93df..c345883d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -106,7 +106,6 @@ build-tw: "pkgconfig" "spdlog-devel" "zlib-devel" - "libQt5PlatformHeaders-devel" "cmake(re2)" "cmake(Qt6Core)" "cmake(Qt6DBus)" @@ -117,6 +116,7 @@ build-tw: "cmake(Qt6Svg)" "cmake(Qt6Widgets)" "cmake(Qt6Gui)" + "qt6-qml-private-devel" "pkgconfig(libcurl)" "pkgconfig(libevent)" "pkgconfig(gstreamer-webrtc-1.0)" diff --git a/resources/qml/TimelineBubbleMessageStyle.qml b/resources/qml/TimelineBubbleMessageStyle.qml index cf6f1dec..7635fba9 100644 --- a/resources/qml/TimelineBubbleMessageStyle.qml +++ b/resources/qml/TimelineBubbleMessageStyle.qml @@ -279,7 +279,7 @@ TimelineEvent { } } - padding: 4 + padding: wrapper.isStateEvent ? 0 : 4 background: Rectangle { color: !wrapper.isStateEvent ? Qt.tint(palette.base, Qt.hsla(messageBubble.userColor.hslHue, 0.5, messageBubble.userColor.hslLightness, 0.2)) : "transparent" radius: 4 diff --git a/src/timeline/EventDelegateChooser.cpp b/src/timeline/EventDelegateChooser.cpp index e2319460..4367bb9c 100644 --- a/src/timeline/EventDelegateChooser.cpp +++ b/src/timeline/EventDelegateChooser.cpp @@ -10,6 +10,8 @@ #include #include +#include + // privat qt headers to access required properties #include #include @@ -133,7 +135,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) } } - nhlog::ui()->debug("Querying data for id {}", currentId.toStdString()); + // nhlog::ui()->debug("Querying data for id {}", currentId.toStdString()); chooser.room_->multiData(currentId, forReply ? chooser.eventId_ : QString(), roles); Qt::beginPropertyUpdateGroup(); @@ -169,7 +171,7 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) forReply ? chooser.eventId_ : QString()) .toInt(); if (type != oldType) { - nhlog::ui()->debug("Type changed!"); + // nhlog::ui()->debug("Type changed!"); reset(currentId); return; } @@ -178,7 +180,8 @@ EventDelegateChooser::DelegateIncubator::setInitialState(QObject *obj) std::vector rolesToRequest; if (changedRoles.empty()) { - for (auto role : roleToPropIdx.keys()) + for (const auto role : + std::ranges::subrange(roleToPropIdx.keyBegin(), roleToPropIdx.keyEnd())) rolesToRequest.emplace_back(role); } else { for (auto role : changedRoles) { @@ -229,7 +232,7 @@ EventDelegateChooser::DelegateIncubator::reset(QString id) if (!chooser.room_ || id.isEmpty()) return; - nhlog::ui()->debug("Reset with id {}, reply {}", id.toStdString(), forReply); + // nhlog::ui()->debug("Reset with id {}, reply {}", id.toStdString(), forReply); this->currentId = id; @@ -242,8 +245,8 @@ EventDelegateChooser::DelegateIncubator::reset(QString id) for (const auto choice : qAsConst(chooser.choices_)) { const auto &choiceValue = choice->roleValues(); if (choiceValue.contains(role) || choiceValue.empty()) { - nhlog::ui()->debug( - "Instantiating type: {}, c {}", (int)role, choiceValue.contains(role)); + // nhlog::ui()->debug( + // "Instantiating type: {}, c {}", (int)role, choiceValue.contains(role)); if (auto child = qobject_cast(object())) { child->setParentItem(nullptr); @@ -296,7 +299,7 @@ EventDelegateChooser::updatePolish() auto mainChild = qobject_cast(eventIncubator.object()); auto replyChild = qobject_cast(replyIncubator.object()); - nhlog::ui()->critical("POLISHING {}", (void *)this); + // nhlog::ui()->trace("POLISHING {}", (void *)this); auto layoutItem = [this](QQuickItem *item, int inset) { if (item) { @@ -331,8 +334,6 @@ EventDelegateChooser::updatePolish() item->setHeight(height); } - nhlog::ui()->debug( - "Made event delegate width: {}, {}", width, item->metaObject()->className()); item->setWidth(width); item->ensurePolished(); } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index c2bcfeb5..aa7a5e6a 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -2290,7 +2290,6 @@ TimelineModel::markSpecialEffectsDone() QString TimelineModel::formatTypingUsers(const QStringList &users, const QColor &bg) { - nhlog::db()->critical("TYPING USERS!"); QString temp = tr("%1 and %2 are typing.", "Multiple users are typing. First argument is a comma separated list of potentially " -- cgit 1.5.1 From 149535efbe5ced135ae16821f97332fb8972c3c5 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 9 Oct 2023 22:50:41 +0200 Subject: Make effect messages stand out more --- resources/qml/ui/TimelineEffects.qml | 3 +-- src/timeline/TimelineModel.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/resources/qml/ui/TimelineEffects.qml b/resources/qml/ui/TimelineEffects.qml index 4e2acea4..35c54c04 100644 --- a/resources/qml/ui/TimelineEffects.qml +++ b/resources/qml/ui/TimelineEffects.qml @@ -24,7 +24,7 @@ Item { ParticleSystem { id: particleSystem - Component.onCompleted: pause(); + Component.onCompleted: stop(); paused: !effectRoot.shouldEffectsRun running: effectRoot.shouldEffectsRun } @@ -32,7 +32,6 @@ Item { Emitter { id: confettiEmitter - Component.onCompleted: stop(); group: "confetti" width: effectRoot.width * 3/4 enabled: false diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index aa7a5e6a..e8b5d40e 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -690,6 +690,16 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r formattedBody_.replace(curImg, imgReplacement); } + if (auto effectMessage = + std::get_if>(&event)) { + if (effectMessage->content.msgtype == std::string_view("nic.custom.confetti")) { + formattedBody_.append(QUtf8StringView(u8"🎊")); + } else if (effectMessage->content.msgtype == + std::string_view("io.element.effect.rainfall")) { + formattedBody_.append(QUtf8StringView(u8"🌧️")); + } + } + return QVariant(utils::replaceEmoji(utils::linkifyMessage(formattedBody_))); } case FormattedStateEvent: { -- cgit 1.5.1