Set the mention and error color according to colorscheme

Use kirigami to set the proper link and error color for mentions and error underlining in chatbox

This is with my own colorscheme:

![image](/uploads/6269b85f936a98b02f42a9ce01da76b1/image.png)
This commit is contained in:
Akseli Lahtinen
2023-03-30 16:25:01 +00:00
parent 0d1b35b610
commit 8f141cd88d
4 changed files with 51 additions and 0 deletions

View File

@@ -324,3 +324,35 @@ void ChatDocumentHandler::pushMention(const Mention mention) const
m_room->mentions()->push_back(mention); 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();
}

View File

@@ -35,6 +35,9 @@ class ChatDocumentHandler : public QObject
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) 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: public:
explicit ChatDocumentHandler(QObject *parent = nullptr); explicit ChatDocumentHandler(QObject *parent = nullptr);
@@ -60,6 +63,13 @@ public:
void updateCompletions(); void updateCompletions();
CompletionModel *completionModel() const; CompletionModel *completionModel() const;
[[nodiscard]] QColor mentionColor() const;
void setMentionColor(const QColor &color);
[[nodiscard]] QColor errorColor() const;
void setErrorColor(const QColor &color);
Q_SIGNALS: Q_SIGNALS:
void isEditChanged(); void isEditChanged();
void documentChanged(); void documentChanged();
@@ -68,6 +78,8 @@ Q_SIGNALS:
void completionModelChanged(); void completionModelChanged();
void selectionStartChanged(); void selectionStartChanged();
void selectionEndChanged(); void selectionEndChanged();
void errorColorChanged();
void mentionColorChanged();
private: private:
int completionStartIndex() const; int completionStartIndex() const;
@@ -79,6 +91,9 @@ private:
NeoChatRoom *m_room = nullptr; NeoChatRoom *m_room = nullptr;
bool completionVisible = false; bool completionVisible = false;
QColor m_mentionColor;
QColor m_errorColor;
int m_cursorPosition; int m_cursorPosition;
int m_selectionStart; int m_selectionStart;
int m_selectionEnd; int m_selectionEnd;

View File

@@ -394,6 +394,8 @@ QQC2.Control {
cursorPosition: textField.cursorPosition cursorPosition: textField.cursorPosition
selectionStart: textField.selectionStart selectionStart: textField.selectionStart
selectionEnd: textField.selectionEnd selectionEnd: textField.selectionEnd
mentionColor: Kirigami.Theme.linkColor
errorColor: Kirigami.Theme.negativeTextColor
Component.onCompleted: { Component.onCompleted: {
RoomManager.chatDocumentHandler = documentHandler; RoomManager.chatDocumentHandler = documentHandler;
} }

View File

@@ -119,6 +119,8 @@ QQC2.TextArea {
selectionStart: root.selectionStart selectionStart: root.selectionStart
selectionEnd: root.selectionEnd selectionEnd: root.selectionEnd
room: root.room // We don't care about saving for edits so this is OK. room: root.room // We don't care about saving for edits so this is OK.
mentionColor: Kirigami.Theme.linkColor
errorColor: Kirigami.Theme.negativeTextColor
} }
TextMetrics { TextMetrics {