From 4e05abc7d27cd7392ffeeed5756e8cf9120eee97 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Thu, 1 May 2025 00:01:44 +0200 Subject: [PATCH] feat: Add settings for text format --- ChatView/ChatRootView.cpp | 10 ++++++++++ ChatView/ChatRootView.hpp | 3 +++ ChatView/qml/ChatItem.qml | 13 ++++++++++++- ChatView/qml/RootItem.qml | 1 + ChatView/qml/dialog/TextBlock.qml | 1 - settings/ChatAssistantSettings.cpp | 10 ++++++++++ settings/ChatAssistantSettings.hpp | 1 + settings/SettingsConstants.hpp | 1 + 8 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ChatView/ChatRootView.cpp b/ChatView/ChatRootView.cpp index 89e5a5c..fc81c1d 100644 --- a/ChatView/ChatRootView.cpp +++ b/ChatView/ChatRootView.cpp @@ -122,6 +122,11 @@ ChatRootView::ChatRootView(QQuickItem *parent) &Utils::BaseAspect::changed, this, &ChatRootView::codeFontSizeChanged); + connect( + &Settings::chatAssistantSettings().textFormat, + &Utils::BaseAspect::changed, + this, + &ChatRootView::textFormatChanged); updateInputTokensCount(); } @@ -592,4 +597,9 @@ int ChatRootView::textFontSize() const return Settings::chatAssistantSettings().textFontSize(); } +int ChatRootView::textFormat() const +{ + return Settings::chatAssistantSettings().textFormat(); +} + } // namespace QodeAssist::Chat diff --git a/ChatView/ChatRootView.hpp b/ChatView/ChatRootView.hpp index a72fa70..cd0afe2 100644 --- a/ChatView/ChatRootView.hpp +++ b/ChatView/ChatRootView.hpp @@ -42,6 +42,7 @@ class ChatRootView : public QQuickItem Q_PROPERTY(QString codeFontFamily READ codeFontFamily NOTIFY codeFamilyChanged FINAL) Q_PROPERTY(int codeFontSize READ codeFontSize NOTIFY codeFontSizeChanged FINAL) Q_PROPERTY(int textFontSize READ textFontSize NOTIFY textFontSizeChanged FINAL) + Q_PROPERTY(int textFormat READ textFormat NOTIFY textFormatChanged FINAL) QML_ELEMENT @@ -89,6 +90,7 @@ public: int codeFontSize() const; int textFontSize() const; + int textFormat() const; public slots: void sendMessage(const QString &message); @@ -109,6 +111,7 @@ signals: void codeFamilyChanged(); void codeFontSizeChanged(); void textFontSizeChanged(); + void textFormatChanged(); private: QString getChatsHistoryDir() const; diff --git a/ChatView/qml/ChatItem.qml b/ChatView/qml/ChatItem.qml index 76b1944..04d22a3 100644 --- a/ChatView/qml/ChatItem.qml +++ b/ChatView/qml/ChatItem.qml @@ -42,6 +42,7 @@ Rectangle { } property int textFontSize: Qt.application.font.pointSize property int codeFontSize: Qt.application.font.pointSize + property int textFormat: 0 property bool isUserMessage: false property int messageIndex: -1 @@ -174,9 +175,19 @@ Rectangle { height: implicitHeight + 10 verticalAlignment: Text.AlignVCenter leftPadding: 10 - text: utils.getSafeMarkdownText(itemData.text) + text: textFormat == Text.MarkdownText ? utils.getSafeMarkdownText(itemData.text) + : itemData.text font.family: root.textFontFamily font.pointSize: root.textFontSize + textFormat: { + if (root.textFormat == 0) { + return Text.MarkdownText + } else if (root.textFormat == 1) { + return Text.RichText + } else { + return Text.PlainText + } + } ChatUtils { id: utils diff --git a/ChatView/qml/RootItem.qml b/ChatView/qml/RootItem.qml index 598adcc..dcf0ad3 100644 --- a/ChatView/qml/RootItem.qml +++ b/ChatView/qml/RootItem.qml @@ -104,6 +104,7 @@ ChatRootView { codeFontFamily: root.codeFontFamily codeFontSize: root.codeFontSize textFontSize: root.textFontSize + textFormat: root.textFormat onResetChatToMessage: function(index) { messageInput.text = model.content diff --git a/ChatView/qml/dialog/TextBlock.qml b/ChatView/qml/dialog/TextBlock.qml index 53d3a58..7e41f68 100644 --- a/ChatView/qml/dialog/TextBlock.qml +++ b/ChatView/qml/dialog/TextBlock.qml @@ -25,7 +25,6 @@ TextEdit { readOnly: true selectByMouse: true wrapMode: Text.WordWrap - textFormat: Text.MarkdownText selectionColor: palette.highlight color: palette.text } diff --git a/settings/ChatAssistantSettings.cpp b/settings/ChatAssistantSettings.cpp index 22290ef..0b893a3 100644 --- a/settings/ChatAssistantSettings.cpp +++ b/settings/ChatAssistantSettings.cpp @@ -190,6 +190,14 @@ ChatAssistantSettings::ChatAssistantSettings() codeFontSize.setLabelText(Tr::tr("Code Font Size:")); codeFontSize.setDefaultValue(QApplication::font().pointSize()); + textFormat.setSettingsKey(Constants::CA_TEXT_FORMAT); + textFormat.setLabelText(Tr::tr("Text Format:")); + textFormat.setDefaultValue(0); + textFormat.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox); + textFormat.addOption("Markdown"); + textFormat.addOption("HTML"); + textFormat.addOption("Plain Text"); + resetToDefaults.m_buttonText = TrConstants::RESET_TO_DEFAULTS; readSettings(); @@ -216,6 +224,7 @@ ChatAssistantSettings::ChatAssistantSettings() auto chatViewSettingsGrid = Grid{}; chatViewSettingsGrid.addRow({textFontFamily, textFontSize}); chatViewSettingsGrid.addRow({codeFontFamily, codeFontSize}); + chatViewSettingsGrid.addRow({textFormat}); return Column{ Row{Stretch{1}, resetToDefaults}, @@ -283,6 +292,7 @@ void ChatAssistantSettings::resetSettingsToDefaults() resetAspect(codeFontFamily); resetAspect(textFontSize); resetAspect(codeFontSize); + resetAspect(textFormat); } } diff --git a/settings/ChatAssistantSettings.hpp b/settings/ChatAssistantSettings.hpp index 09c1d7a..cfb9062 100644 --- a/settings/ChatAssistantSettings.hpp +++ b/settings/ChatAssistantSettings.hpp @@ -68,6 +68,7 @@ public: Utils::IntegerAspect textFontSize{this}; Utils::SelectionAspect codeFontFamily{this}; Utils::IntegerAspect codeFontSize{this}; + Utils::SelectionAspect textFormat{this}; private: void setupConnections(); diff --git a/settings/SettingsConstants.hpp b/settings/SettingsConstants.hpp index 528a760..3e3936b 100644 --- a/settings/SettingsConstants.hpp +++ b/settings/SettingsConstants.hpp @@ -155,5 +155,6 @@ const char CA_TEXT_FONT_FAMILY[] = "QodeAssist.caTextFontFamily"; const char CA_TEXT_FONT_SIZE[] = "QodeAssist.caTextFontSize"; const char CA_CODE_FONT_FAMILY[] = "QodeAssist.caCodeFontFamily"; const char CA_CODE_FONT_SIZE[] = "QodeAssist.caCodeFontSize"; +const char CA_TEXT_FORMAT[] = "QodeAssist.caTextFormat"; } // namespace QodeAssist::Constants