diff --git a/src/chatdocumenthandler.cpp b/src/chatdocumenthandler.cpp index faa7b59e6..0c81f0ad3 100644 --- a/src/chatdocumenthandler.cpp +++ b/src/chatdocumenthandler.cpp @@ -324,3 +324,35 @@ void ChatDocumentHandler::pushMention(const Mention mention) const m_room->mentions()->push_back(mention); } } + +QColor ChatDocumentHandler::mentionColor() const +{ + return m_mentionColor; +} + +void ChatDocumentHandler::setMentionColor(const QColor &color) +{ + if (m_mentionColor == color) { + return; + } + m_mentionColor = color; + m_highlighter->mentionFormat.setForeground(m_mentionColor); + m_highlighter->rehighlight(); + Q_EMIT mentionColorChanged(); +} + +QColor ChatDocumentHandler::errorColor() const +{ + return m_errorColor; +} + +void ChatDocumentHandler::setErrorColor(const QColor &color) +{ + if (m_errorColor == color) { + return; + } + m_errorColor = color; + m_highlighter->errorFormat.setForeground(m_errorColor); + m_highlighter->rehighlight(); + Q_EMIT errorColorChanged(); +} \ No newline at end of file diff --git a/src/chatdocumenthandler.h b/src/chatdocumenthandler.h index 096f0f098..4ab077057 100644 --- a/src/chatdocumenthandler.h +++ b/src/chatdocumenthandler.h @@ -35,6 +35,9 @@ class ChatDocumentHandler : public QObject Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) + Q_PROPERTY(QColor mentionColor READ mentionColor WRITE setMentionColor NOTIFY mentionColorChanged); + Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor NOTIFY errorColorChanged); + public: explicit ChatDocumentHandler(QObject *parent = nullptr); @@ -60,6 +63,13 @@ public: void updateCompletions(); CompletionModel *completionModel() const; + + [[nodiscard]] QColor mentionColor() const; + void setMentionColor(const QColor &color); + + [[nodiscard]] QColor errorColor() const; + void setErrorColor(const QColor &color); + Q_SIGNALS: void isEditChanged(); void documentChanged(); @@ -68,6 +78,8 @@ Q_SIGNALS: void completionModelChanged(); void selectionStartChanged(); void selectionEndChanged(); + void errorColorChanged(); + void mentionColorChanged(); private: int completionStartIndex() const; @@ -79,6 +91,9 @@ private: NeoChatRoom *m_room = nullptr; bool completionVisible = false; + QColor m_mentionColor; + QColor m_errorColor; + int m_cursorPosition; int m_selectionStart; int m_selectionEnd; diff --git a/src/qml/Component/ChatBox/ChatBar.qml b/src/qml/Component/ChatBox/ChatBar.qml index c98403928..1cdfef473 100644 --- a/src/qml/Component/ChatBox/ChatBar.qml +++ b/src/qml/Component/ChatBox/ChatBar.qml @@ -394,6 +394,8 @@ QQC2.Control { cursorPosition: textField.cursorPosition selectionStart: textField.selectionStart selectionEnd: textField.selectionEnd + mentionColor: Kirigami.Theme.linkColor + errorColor: Kirigami.Theme.negativeTextColor Component.onCompleted: { RoomManager.chatDocumentHandler = documentHandler; } diff --git a/src/qml/Component/Timeline/MessageEditComponent.qml b/src/qml/Component/Timeline/MessageEditComponent.qml index e2678a79e..2a1ddc67e 100644 --- a/src/qml/Component/Timeline/MessageEditComponent.qml +++ b/src/qml/Component/Timeline/MessageEditComponent.qml @@ -119,6 +119,8 @@ QQC2.TextArea { selectionStart: root.selectionStart selectionEnd: root.selectionEnd room: root.room // We don't care about saving for edits so this is OK. + mentionColor: Kirigami.Theme.linkColor + errorColor: Kirigami.Theme.negativeTextColor } TextMetrics {