Move the remaining functionality of ChatDocumentHandler to ChatTextItemHelper or split into own objects
This commit is contained in:
@@ -149,7 +149,9 @@ QQC2.Control {
|
||||
|
||||
CompletionMenu {
|
||||
id: completionMenu
|
||||
chatDocumentHandler: contentModel.focusedDocumentHandler
|
||||
room: root.currentRoom
|
||||
type: LibNeoChat.ChatBarType.Room
|
||||
textItem: chatContentView.model.focusedTextItem
|
||||
|
||||
x: 1
|
||||
y: -height
|
||||
|
||||
@@ -12,11 +12,25 @@ import org.kde.kirigamiaddons.delegates as Delegates
|
||||
import org.kde.kirigamiaddons.labs.components as KirigamiComponents
|
||||
|
||||
import org.kde.neochat
|
||||
import org.kde.neochat.libneochat as LibNeoChat
|
||||
|
||||
QQC2.Popup {
|
||||
id: root
|
||||
|
||||
required property var chatDocumentHandler
|
||||
/**
|
||||
* @brief The current room that user is viewing.
|
||||
*/
|
||||
required property LibNeoChat.NeoChatRoom room
|
||||
|
||||
/**
|
||||
* @brief The chatbar type
|
||||
*/
|
||||
required property int type
|
||||
|
||||
/**
|
||||
* @brief The chatbar type
|
||||
*/
|
||||
required property LibNeoChat.ChatTextItemHelper textItem
|
||||
|
||||
visible: completions.count > 0
|
||||
|
||||
@@ -33,7 +47,7 @@ QQC2.Popup {
|
||||
}
|
||||
|
||||
function complete() {
|
||||
root.chatDocumentHandler.insertCompletion(completions.currentItem.replacedText, completions.currentItem.hRef)
|
||||
completionModel.insertCompletion(completions.currentItem.replacedText, completions.currentItem.hRef)
|
||||
}
|
||||
|
||||
leftPadding: 0
|
||||
@@ -60,8 +74,11 @@ QQC2.Popup {
|
||||
ListView {
|
||||
id: completions
|
||||
|
||||
model: CompletionModel {
|
||||
textItem: root.chatDocumentHandler.textItem
|
||||
model: LibNeoChat.CompletionModel {
|
||||
id: completionModel
|
||||
room: root.room
|
||||
type: root.type
|
||||
textItem: root.textItem
|
||||
roomListModel: RoomManager.roomListModel
|
||||
userListModel: RoomManager.userListModel
|
||||
}
|
||||
@@ -97,7 +114,7 @@ QQC2.Popup {
|
||||
subtitleItem.textFormat: Text.PlainText
|
||||
}
|
||||
}
|
||||
onClicked: root.chatDocumentHandler.insertCompletion(replacedText, hRef)
|
||||
onClicked: completionModel.insertCompletion(replacedText, hRef)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ QQC2.ToolBar {
|
||||
property LibNeoChat.ChatBarCache chatBarCache
|
||||
|
||||
required property MessageContent.ChatBarMessageContentModel contentModel
|
||||
readonly property LibNeoChat.ChatDocumentHandler focusedDocumentHandler: contentModel.focusedDocumentHandler
|
||||
|
||||
Connections {
|
||||
target: contentModel
|
||||
@@ -65,7 +64,7 @@ QQC2.ToolBar {
|
||||
3
|
||||
|
||||
readonly property ChatButtonHelper chatButtonHelper: ChatButtonHelper {
|
||||
textItem: contentModel.currentTextItem
|
||||
textItem: contentModel.focusedTextItem
|
||||
}
|
||||
|
||||
signal clicked
|
||||
|
||||
@@ -17,7 +17,6 @@ QQC2.Popup {
|
||||
|
||||
required property MessageContent.ChatBarMessageContentModel chatContentModel
|
||||
required property ChatButtonHelper chatButtonHelper
|
||||
readonly property LibNeoChat.ChatDocumentHandler focusedDocumentHandler: chatContentModel.focusedDocumentHandler
|
||||
|
||||
y: -implicitHeight
|
||||
|
||||
@@ -88,7 +87,7 @@ QQC2.Popup {
|
||||
radius: Kirigami.Units.cornerRadius
|
||||
border {
|
||||
width: 1
|
||||
color: styleDelegate.hovered || (root.focusedDocumentHandler?.style ?? false) === styleDelegate.index ?
|
||||
color: styleDelegate.hovered || root.chatButtonHelper.currentStyle === styleDelegate.index ?
|
||||
Kirigami.Theme.highlightColor :
|
||||
Kirigami.ColorUtils.linearInterpolation(
|
||||
Kirigami.Theme.backgroundColor,
|
||||
|
||||
@@ -12,12 +12,12 @@ ChatButtonHelper::ChatButtonHelper(QObject *parent)
|
||||
{
|
||||
}
|
||||
|
||||
QmlTextItemWrapper *ChatButtonHelper::textItem() const
|
||||
ChatTextItemHelper *ChatButtonHelper::textItem() const
|
||||
{
|
||||
return m_textItem;
|
||||
}
|
||||
|
||||
void ChatButtonHelper::setTextItem(QmlTextItemWrapper *textItem)
|
||||
void ChatButtonHelper::setTextItem(ChatTextItemHelper *textItem)
|
||||
{
|
||||
if (textItem == m_textItem) {
|
||||
return;
|
||||
@@ -30,11 +30,10 @@ void ChatButtonHelper::setTextItem(QmlTextItemWrapper *textItem)
|
||||
m_textItem = textItem;
|
||||
|
||||
if (m_textItem) {
|
||||
connect(m_textItem, &QmlTextItemWrapper::textItemChanged, this, &ChatButtonHelper::textItemChanged);
|
||||
connect(m_textItem, &QmlTextItemWrapper::formatChanged, this, &ChatButtonHelper::linkChanged);
|
||||
connect(m_textItem, &QmlTextItemWrapper::textFormatChanged, this, &ChatButtonHelper::textFormatChanged);
|
||||
connect(m_textItem, &QmlTextItemWrapper::styleChanged, this, &ChatButtonHelper::styleChanged);
|
||||
connect(m_textItem, &QmlTextItemWrapper::listChanged, this, &ChatButtonHelper::listChanged);
|
||||
connect(m_textItem, &ChatTextItemHelper::formatChanged, this, &ChatButtonHelper::linkChanged);
|
||||
connect(m_textItem, &ChatTextItemHelper::textFormatChanged, this, &ChatButtonHelper::textFormatChanged);
|
||||
connect(m_textItem, &ChatTextItemHelper::styleChanged, this, &ChatButtonHelper::styleChanged);
|
||||
connect(m_textItem, &ChatTextItemHelper::listChanged, this, &ChatButtonHelper::listChanged);
|
||||
}
|
||||
|
||||
Q_EMIT textItemChanged();
|
||||
@@ -88,6 +87,14 @@ bool ChatButtonHelper::orderedList() const
|
||||
return m_textItem->formatsAtCursor().contains(RichFormat::OrderedList);
|
||||
}
|
||||
|
||||
RichFormat::Format ChatButtonHelper::currentStyle() const
|
||||
{
|
||||
if (!m_textItem) {
|
||||
return RichFormat::Paragraph;
|
||||
}
|
||||
return static_cast<RichFormat::Format>(m_textItem->textCursor().blockFormat().headingLevel());
|
||||
}
|
||||
|
||||
void ChatButtonHelper::setFormat(RichFormat::Format format)
|
||||
{
|
||||
if (!m_textItem) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <QObject>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "qmltextitemwrapper.h"
|
||||
#include "chattextitemhelper.h"
|
||||
|
||||
class ChatButtonHelper : public QObject
|
||||
{
|
||||
@@ -16,12 +16,12 @@ class ChatButtonHelper : public QObject
|
||||
/**
|
||||
* @brief The text item that the helper is interfacing with.
|
||||
*
|
||||
* This is a QQuickItem that is a TextEdit (or inherited from) wrapped in a QmlTextItemWrapper
|
||||
* This is a QQuickItem that is a TextEdit (or inherited from) wrapped in a ChatTextItemHelper
|
||||
* to provide easy access to properties and basic QTextDocument manipulation.
|
||||
*
|
||||
* @sa TextEdit, QTextDocument, QmlTextItemWrapper
|
||||
* @sa TextEdit, QTextDocument, ChatTextItemHelper
|
||||
*/
|
||||
Q_PROPERTY(QmlTextItemWrapper *textItem READ textItem WRITE setTextItem NOTIFY textItemChanged)
|
||||
Q_PROPERTY(ChatTextItemHelper *textItem READ textItem WRITE setTextItem NOTIFY textItemChanged)
|
||||
|
||||
/**
|
||||
* @brief Whether the text format at the current cursor is bold.
|
||||
@@ -53,6 +53,11 @@ class ChatButtonHelper : public QObject
|
||||
*/
|
||||
Q_PROPERTY(bool orderedList READ orderedList NOTIFY listChanged)
|
||||
|
||||
/**
|
||||
* @brief The current style at the cursor.
|
||||
*/
|
||||
Q_PROPERTY(RichFormat::Format currentStyle READ currentStyle NOTIFY styleChanged)
|
||||
|
||||
/**
|
||||
* @brief Whether the list at the current cursor can be indented one level more.
|
||||
*/
|
||||
@@ -76,8 +81,8 @@ class ChatButtonHelper : public QObject
|
||||
public:
|
||||
explicit ChatButtonHelper(QObject *parent = nullptr);
|
||||
|
||||
QmlTextItemWrapper *textItem() const;
|
||||
void setTextItem(QmlTextItemWrapper *textItem);
|
||||
ChatTextItemHelper *textItem() const;
|
||||
void setTextItem(ChatTextItemHelper *textItem);
|
||||
|
||||
bool bold() const;
|
||||
bool italic() const;
|
||||
@@ -85,6 +90,7 @@ public:
|
||||
bool strikethrough() const;
|
||||
bool unorderedList() const;
|
||||
bool orderedList() const;
|
||||
RichFormat::Format currentStyle() const;
|
||||
|
||||
/**
|
||||
* @brief Apply the given format at the current cursor position.
|
||||
@@ -129,7 +135,7 @@ Q_SIGNALS:
|
||||
void linkChanged();
|
||||
|
||||
private:
|
||||
QPointer<QmlTextItemWrapper> m_textItem;
|
||||
QPointer<ChatTextItemHelper> m_textItem;
|
||||
|
||||
void selectLinkText(QTextCursor &cursor) const;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ class StyleDelegateHelper : public QObject
|
||||
QML_ELEMENT
|
||||
|
||||
/**
|
||||
* @brief The QML text Item the ChatDocumentHandler is handling.
|
||||
* @brief The QML text Item the StyleDelegateHelper is handling.
|
||||
*/
|
||||
Q_PROPERTY(QQuickItem *textItem READ textItem WRITE setTextItem NOTIFY textItemChanged)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user