From dff6ab66f1425567bc4d9e3014559c8048c5508a Mon Sep 17 00:00:00 2001 From: James Graham Date: Tue, 3 Feb 2026 18:52:23 +0000 Subject: [PATCH] Comment updates --- autotests/chatkeyhelpertesthelper.h | 1 - autotests/chatmarkdownhelpertestwrapper.h | 1 - autotests/chattextitemhelpertesthelper.h | 1 - src/chatbar/ChatBar.qml | 6 ++ src/chatbar/ImageDialog.qml | 55 ------------------- src/chatbar/SendBar.qml | 10 ++-- src/libneochat/chatkeyhelper.cpp | 1 - src/libneochat/chattextitemhelper.cpp | 2 +- src/libneochat/chattextitemhelper.h | 1 - src/libneochat/messagecomponent.h | 2 +- src/libneochat/models/completionmodel.h | 2 +- .../models/chatbarmessagecontentmodel.cpp | 7 +-- .../models/chatbarmessagecontentmodel.h | 2 +- .../models/messagecontentmodel.cpp | 18 +++--- .../models/messagecontentmodel.h | 6 +- 15 files changed, 28 insertions(+), 87 deletions(-) delete mode 100644 src/chatbar/ImageDialog.qml diff --git a/autotests/chatkeyhelpertesthelper.h b/autotests/chatkeyhelpertesthelper.h index 20528cec5..0322a2c7a 100644 --- a/autotests/chatkeyhelpertesthelper.h +++ b/autotests/chatkeyhelpertesthelper.h @@ -8,7 +8,6 @@ #include #include #include -#include #include "chatkeyhelper.h" #include "chattextitemhelper.h" diff --git a/autotests/chatmarkdownhelpertestwrapper.h b/autotests/chatmarkdownhelpertestwrapper.h index c117f8a19..3f1e04177 100644 --- a/autotests/chatmarkdownhelpertestwrapper.h +++ b/autotests/chatmarkdownhelpertestwrapper.h @@ -6,7 +6,6 @@ #include #include #include -#include #include "chatmarkdownhelper.h" #include "chattextitemhelper.h" diff --git a/autotests/chattextitemhelpertesthelper.h b/autotests/chattextitemhelpertesthelper.h index 7da1af3a9..0d51f00e3 100644 --- a/autotests/chattextitemhelpertesthelper.h +++ b/autotests/chattextitemhelpertesthelper.h @@ -8,7 +8,6 @@ #include #include #include -#include #include "chattextitemhelper.h" diff --git a/src/chatbar/ChatBar.qml b/src/chatbar/ChatBar.qml index db2316848..b00050b0f 100644 --- a/src/chatbar/ChatBar.qml +++ b/src/chatbar/ChatBar.qml @@ -103,8 +103,14 @@ Item { height: Kirigami.Units.iconSizes.smallMedium icon.name: NeoChatConfig.sendMessageWith === 0 ? "arrow-up" : "arrow-down" + text: NeoChatConfig.sendMessageWith === 0 ? i18nc("@action:button", "Enter rich text mode") : i18nc("@action:button", "Exit rich text mode") + display: QQC2.AbstractButton.IconOnly onClicked: NeoChatConfig.sendMessageWith = NeoChatConfig.sendMessageWith === 0 ? 1 : 0 + + QQC2.ToolTip.visible: hovered + QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay + QQC2.ToolTip.text: text } LibNeoChat.DelegateSizeHelper { diff --git a/src/chatbar/ImageDialog.qml b/src/chatbar/ImageDialog.qml deleted file mode 100644 index dea6d5a13..000000000 --- a/src/chatbar/ImageDialog.qml +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Carl Schwan -// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - -import QtQuick -import QtCore -import org.kde.kirigami as Kirigami -import org.kde.kirigamiaddons.formcard as FormCard -import QtQuick.Controls as QQC2 -import QtQuick.Layouts -import QtQuick.Dialogs - -FormCard.FormCardDialog { - id: root - - readonly property alias imagePath: imageField.path - - title: i18nc("@title:window", "Insert Image") - standardButtons: QQC2.Dialog.Ok | QQC2.Dialog.Cancel - - FileDialog { - id: fileDialog - - title: i18nc("@title:window", "Select an image") - currentFolder: StandardPaths.writableLocation(StandardPaths.PicturesLocation) - fileMode: FileDialog.OpenFile - nameFilters: [i18n("Image files (*.jpg *.jpeg *.png *.svg *.webp)"), i18n("All files (*)")] - onAccepted: imageField.path = selectedFile - } - - FormCard.FormButtonDelegate { - id: imageField - - property url path - - text: i18nc("@label:textbox", "Image Location:") - description: path.toString().length > 0 ? path.toString().split('/').slice(-1)[0] : '' - - onClicked: fileDialog.open() - } - - Item { - visible: imageField.path.toString().length > 0 - - Layout.fillWidth: true - Layout.preferredHeight: 200 - Layout.topMargin: Kirigami.Units.largeSpacing - - Image { - anchors.fill: parent - source: imageField.path - fillMode: Image.PreserveAspectFit - horizontalAlignment: Image.AlignHCenter - } - } -} diff --git a/src/chatbar/SendBar.qml b/src/chatbar/SendBar.qml index d3ff28f6a..78b509273 100644 --- a/src/chatbar/SendBar.qml +++ b/src/chatbar/SendBar.qml @@ -33,7 +33,7 @@ RowLayout { visible: !root.contentModel.hasAttachment && (root.contentModel?.type ?? true) === LibNeoChat.ChatBarType.Room icon.name: "mail-attachment" - text: i18n("Attach an image or file") + text: i18nc("@action:button", "Attach an image or file") display: QQC2.AbstractButton.IconOnly onClicked: { @@ -48,8 +48,8 @@ RowLayout { let warningDialog = Qt.createComponent('org.kde.kirigami', 'PromptDialog').createObject(QQC2.Overlay.overlay, { dialogType: Kirigami.PromptDialog.Warning, - title: i18n("Attach an image or file?"), - subtitle: i18n("Attachments can only have plain text captions, all rich formatting will be removed"), + title: attachmentButton.text, + subtitle: i18nc("@Warning: that any rich text in the chat bar will be switched for the plain text equivalent.", "Attachments can only have plain text captions, all rich formatting will be removed"), standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel }); warningDialog.onAccepted.connect(() => { @@ -87,7 +87,7 @@ RowLayout { visible: (root.contentModel?.type ?? true) === LibNeoChat.ChatBarType.Room icon.name: "globe" property bool isBusy: false - text: i18n("Send a Location") + text: i18nc("@action:button", "Send a Location") display: QQC2.AbstractButton.IconOnly onClicked: { @@ -122,7 +122,7 @@ RowLayout { property bool isBusy: false icon.name: "document-send" - text: i18n("Send message") + text: i18nc("@action:button", "Send message") display: QQC2.AbstractButton.IconOnly onClicked: root.contentModel.postMessage(); diff --git a/src/libneochat/chatkeyhelper.cpp b/src/libneochat/chatkeyhelper.cpp index 14bf0339b..c2f61dadf 100644 --- a/src/libneochat/chatkeyhelper.cpp +++ b/src/libneochat/chatkeyhelper.cpp @@ -6,7 +6,6 @@ #include "chattextitemhelper.h" #include "clipboard.h" #include "neochatroom.h" -#include ChatKeyHelper::ChatKeyHelper(QObject *parent) : QObject(parent) diff --git a/src/libneochat/chattextitemhelper.cpp b/src/libneochat/chattextitemhelper.cpp index 286567c4f..4c80f901c 100644 --- a/src/libneochat/chattextitemhelper.cpp +++ b/src/libneochat/chattextitemhelper.cpp @@ -156,7 +156,7 @@ void ChatTextItemHelper::initializeChars() return; } - QTextCursor cursor = QTextCursor(doc); + QTextCursor cursor(doc); if (cursor.isNull()) { return; } diff --git a/src/libneochat/chattextitemhelper.h b/src/libneochat/chattextitemhelper.h index 9aac1dca7..3a1bee607 100644 --- a/src/libneochat/chattextitemhelper.h +++ b/src/libneochat/chattextitemhelper.h @@ -5,7 +5,6 @@ #include #include -#include #include "enums/chatbartype.h" #include "enums/richformat.h" diff --git a/src/libneochat/messagecomponent.h b/src/libneochat/messagecomponent.h index 4375e4d09..c84e7083a 100644 --- a/src/libneochat/messagecomponent.h +++ b/src/libneochat/messagecomponent.h @@ -8,7 +8,7 @@ struct MessageComponent { MessageComponentType::Type type = MessageComponentType::Other; QString display; - QVariantMap attributes = {}; + QVariantMap attributes; bool operator==(const MessageComponent &right) const { diff --git a/src/libneochat/models/completionmodel.h b/src/libneochat/models/completionmodel.h index a5f9a0aac..b6fc3e8d5 100644 --- a/src/libneochat/models/completionmodel.h +++ b/src/libneochat/models/completionmodel.h @@ -36,7 +36,7 @@ class CompletionModel : public QAbstractListModel Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) /** - * @brief The QQuickTextDocument that is being handled. + * @brief The ChatBarType::Type of the chat bar. */ Q_PROPERTY(ChatBarType::Type type READ type WRITE setType NOTIFY typeChanged) diff --git a/src/messagecontent/models/chatbarmessagecontentmodel.cpp b/src/messagecontent/models/chatbarmessagecontentmodel.cpp index bbbf438ff..93e2150f4 100644 --- a/src/messagecontent/models/chatbarmessagecontentmodel.cpp +++ b/src/messagecontent/models/chatbarmessagecontentmodel.cpp @@ -4,7 +4,6 @@ #include "chatbarmessagecontentmodel.h" #include -#include #include "chatbarcache.h" #include "chatkeyhelper.h" @@ -332,7 +331,7 @@ QModelIndex ChatBarMessageContentModel::indexForTextItem(ChatTextItemHelper *tex bool ChatBarMessageContentModel::hasRichFormatting() const { - for (const auto &component : m_components) { + return std::ranges::any_of(m_components, [this](const auto &component) { if (component.type != MessageComponentType::Text) { return true; } @@ -341,8 +340,8 @@ bool ChatBarMessageContentModel::hasRichFormatting() const return true; } } - } - return false; + return false; + }); } bool ChatBarMessageContentModel::hasAttachment() const diff --git a/src/messagecontent/models/chatbarmessagecontentmodel.h b/src/messagecontent/models/chatbarmessagecontentmodel.h index 0f6bb0288..7fa3d989a 100644 --- a/src/messagecontent/models/chatbarmessagecontentmodel.h +++ b/src/messagecontent/models/chatbarmessagecontentmodel.h @@ -18,7 +18,7 @@ /** * @class ChatBarMessageContentModel * - * Inherited from MessageContentModel this visulaises the content of a Quotient::RoomMessageEvent. + * Inherited from MessageContentModel this visualises the content of a Quotient::RoomMessageEvent. */ class ChatBarMessageContentModel : public MessageContentModel { diff --git a/src/messagecontent/models/messagecontentmodel.cpp b/src/messagecontent/models/messagecontentmodel.cpp index c87eacad7..0d1806667 100644 --- a/src/messagecontent/models/messagecontentmodel.cpp +++ b/src/messagecontent/models/messagecontentmodel.cpp @@ -201,7 +201,7 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const } return QVariant::fromValue(m_room->editCache()); } - if (role == Editable) { + if (role == EditableRole) { return m_editableActive; } if (role == CurrentFocusRole) { @@ -239,7 +239,7 @@ QHash MessageContentModel::roleNamesStatic() roles[MessageContentModel::ThreadRootRole] = "threadRoot"; roles[MessageContentModel::LinkPreviewerRole] = "linkPreviewer"; roles[MessageContentModel::ChatBarCacheRole] = "chatBarCache"; - roles[MessageContentModel::Editable] = "editable"; + roles[MessageContentModel::EditableRole] = "editable"; roles[MessageContentModel::CurrentFocusRole] = "currentFocus"; return roles; } @@ -254,14 +254,11 @@ bool MessageContentModel::hasComponentType(MessageComponentType::Type type) cons != m_components.cend(); } -bool MessageContentModel::hasComponentType(QList types) const +bool MessageContentModel::hasComponentType(const QList &types) const { - for (const auto &type : types) { - if (hasComponentType(type)) { - return true; - } - } - return false; + return std::ranges::any_of(types, [this](const MessageComponentType::Type &type) { + return hasComponentType(type); + }); } void MessageContentModel::forEachComponentOfType(MessageComponentType::Type type, @@ -316,8 +313,7 @@ void MessageContentModel::updateReplyModel() m_replyModel = new EventMessageContentModel(m_room, *eventId, true, false, this); - bool hasModel = hasComponentType(MessageComponentType::Reply); - if (!hasModel) { + if (!hasComponentType(MessageComponentType::Reply)) { int insertRow = 0; if (m_components.first().type == MessageComponentType::Author) { insertRow = 1; diff --git a/src/messagecontent/models/messagecontentmodel.h b/src/messagecontent/models/messagecontentmodel.h index 4169cda75..36b83daf8 100644 --- a/src/messagecontent/models/messagecontentmodel.h +++ b/src/messagecontent/models/messagecontentmodel.h @@ -67,7 +67,7 @@ public: ThreadRootRole, /**< The thread root event ID for the event. */ LinkPreviewerRole, /**< The link preview details. */ ChatBarCacheRole, /**< The ChatBarCache to use. */ - Editable, /**< Whether the component can be edited. */ + EditableRole, /**< Whether the component can be edited. */ CurrentFocusRole, /**< Whteher the delegate should have focus. */ }; Q_ENUM(Roles) @@ -138,7 +138,7 @@ Q_SIGNALS: protected: QPointer m_room; - QString m_eventId = {}; + QString m_eventId; /** * @brief NeoChatDateTime for the message. @@ -165,7 +165,7 @@ protected: QList m_components; bool hasComponentType(MessageComponentType::Type type) const; - bool hasComponentType(QList types) const; + bool hasComponentType(const QList &types) const; void forEachComponentOfType(MessageComponentType::Type type, std::function function); void forEachComponentOfType(QList types, std::function function);