diff --git a/src/chatdocumenthandler.cpp b/src/chatdocumenthandler.cpp index 7c02cbd22..ba799ebf3 100644 --- a/src/chatdocumenthandler.cpp +++ b/src/chatdocumenthandler.cpp @@ -14,8 +14,6 @@ #include #include -#include "models/actionsmodel.h" -#include "models/roomlistmodel.h" #include "neochatroom.h" class SyntaxHighlighter : public QSyntaxHighlighter diff --git a/src/chatdocumenthandler.h b/src/chatdocumenthandler.h index 4ab077057..cf9735aeb 100644 --- a/src/chatdocumenthandler.h +++ b/src/chatdocumenthandler.h @@ -8,13 +8,54 @@ #include #include "models/completionmodel.h" -#include "models/userlistmodel.h" #include "neochatroom.h" class QTextDocument; class NeoChatRoom; class SyntaxHighlighter; +/** + * @class ChatDocumentHandler + * + * Handle the QQuickTextDocument of a qml text item. + * + * The class provides functionality to highlight text in the text document as well + * as providing completion functionality via a CompletionModel. + * + * The ChatDocumentHandler is also linked to a NeoChatRoom to provide functionality + * to save the chat document text when switching between rooms. + * + * To get the full functionality the cursor position and text selection information + * need to be passed in. For example: + * + * @code{.qml} + * import QtQuick 2.0 + * import QtQuick.Controls 2.15 as QQC2 + * + * import org.kde.kirigami 2.12 as Kirigami + * import org.kde.neochat 1.0 + * + * QQC2.TextArea { + * id: textField + * + * // Set this to a NeoChatRoom object. + * property var room + * + * ChatDocumentHandler { + * id: documentHandler + * document: textField.textDocument + * cursorPosition: textField.cursorPosition + * selectionStart: textField.selectionStart + * selectionEnd: textField.selectionEnd + * mentionColor: Kirigami.Theme.linkColor + * errorColor: Kirigami.Theme.negativeTextColor + * room: textField.room + * } + * } + * @endcode + * + * @sa QQuickTextDocument, CompletionModel, NeoChatRoom + */ class ChatDocumentHandler : public QObject { Q_OBJECT @@ -26,16 +67,48 @@ class ChatDocumentHandler : public QObject * from the correct parameters in the assigned room. */ Q_PROPERTY(bool isEdit READ isEdit WRITE setIsEdit NOTIFY isEditChanged) + + /** + * @brief The QQuickTextDocument that is being handled. + */ Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged) + + /** + * @brief The current saved cursor position. + */ Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged) + + /** + * @brief The start position of any currently selected text. + */ Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged) + + /** + * @brief The end position of any currently selected text. + */ Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged) + /** + * @brief The current CompletionModel. + * + * This is typically provided to a qml component to visualise the current + * completion results. + */ Q_PROPERTY(CompletionModel *completionModel READ completionModel NOTIFY completionModelChanged) + /** + * @brief The current room that the the text document is being handled for. + */ Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) + /** + * @brief The color to highlight user mentions. + */ Q_PROPERTY(QColor mentionColor READ mentionColor WRITE setMentionColor NOTIFY mentionColorChanged); + + /** + * @brief The color to highlight spelling errors. + */ Q_PROPERTY(QColor errorColor READ errorColor WRITE setErrorColor NOTIFY errorColorChanged); public: