MessageEditComponent Updates
Rename MessageEditComponent to ChatBarComponent in preparation for also using it with threads and cleanup.
This commit is contained in:
@@ -395,8 +395,7 @@ QQC2.Control {
|
|||||||
repeatTimer.stop();
|
repeatTimer.stop();
|
||||||
root.currentRoom.markAllMessagesAsRead();
|
root.currentRoom.markAllMessagesAsRead();
|
||||||
textField.clear();
|
textField.clear();
|
||||||
_private.chatBarCache.replyId = "";
|
_private.chatBarCache.clearRelations();
|
||||||
_private.chatBarCache.threadId = "";
|
|
||||||
messageSent();
|
messageSent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,6 +160,16 @@ void ChatBarCache::setAttachmentPath(const QString &attachmentPath)
|
|||||||
Q_EMIT relationIdChanged(oldEventId, m_relationId);
|
Q_EMIT relationIdChanged(oldEventId, m_relationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatBarCache::clearRelations()
|
||||||
|
{
|
||||||
|
const auto oldEventId = std::exchange(m_relationId, QString());
|
||||||
|
m_threadId = QString();
|
||||||
|
m_attachmentPath = QString();
|
||||||
|
Q_EMIT relationIdChanged(oldEventId, m_relationId);
|
||||||
|
Q_EMIT threadIdChanged();
|
||||||
|
Q_EMIT attachmentPathChanged();
|
||||||
|
}
|
||||||
|
|
||||||
QList<Mention> *ChatBarCache::mentions()
|
QList<Mention> *ChatBarCache::mentions()
|
||||||
{
|
{
|
||||||
return &m_mentions;
|
return &m_mentions;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ struct Mention {
|
|||||||
* A class to cache data from a chat bar.
|
* A class to cache data from a chat bar.
|
||||||
*
|
*
|
||||||
* A chat bar can be anything that allows users to compose or edit message, it doesn't
|
* A chat bar can be anything that allows users to compose or edit message, it doesn't
|
||||||
* necessarily have to use the ChatBar component, e.g. MessageEditComponent.
|
* necessarily have to use the ChatBar component, e.g. ChatBarComponent.
|
||||||
*
|
*
|
||||||
* This object is intended to allow the current contents of a chat bar to be cached
|
* This object is intended to allow the current contents of a chat bar to be cached
|
||||||
* between different rooms, i.e. there is an expectation that each NeoChatRoom could
|
* between different rooms, i.e. there is an expectation that each NeoChatRoom could
|
||||||
@@ -43,7 +43,7 @@ struct Mention {
|
|||||||
* as it's parent. This is necessary for certain functions which need to get
|
* as it's parent. This is necessary for certain functions which need to get
|
||||||
* relevant room information.
|
* relevant room information.
|
||||||
*
|
*
|
||||||
* @sa ChatBar, MessageEditComponent, NeoChatRoom
|
* @sa ChatBar, ChatBarComponent, NeoChatRoom
|
||||||
*/
|
*/
|
||||||
class ChatBarCache : public QObject
|
class ChatBarCache : public QObject
|
||||||
{
|
{
|
||||||
@@ -165,6 +165,13 @@ public:
|
|||||||
QString attachmentPath() const;
|
QString attachmentPath() const;
|
||||||
void setAttachmentPath(const QString &attachmentPath);
|
void setAttachmentPath(const QString &attachmentPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear all relations in the cache.
|
||||||
|
*
|
||||||
|
* This includes relation ID, thread root ID and attachment path.
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE void clearRelations();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve the mentions for the current chat bar text.
|
* @brief Retrieve the mentions for the current chat bar text.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ void MessageContentModel::initializeModel()
|
|||||||
if (m_eventId == newEvent->id()) {
|
if (m_eventId == newEvent->id()) {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
intiializeEvent(newEvent);
|
intiializeEvent(newEvent);
|
||||||
|
resetContent();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ ecm_add_qml_module(timeline GENERATE_PLUGIN_SOURCE
|
|||||||
ReplyMessageComponentChooser.qml
|
ReplyMessageComponentChooser.qml
|
||||||
AuthorComponent.qml
|
AuthorComponent.qml
|
||||||
AudioComponent.qml
|
AudioComponent.qml
|
||||||
|
ChatBarComponent.qml
|
||||||
CodeComponent.qml
|
CodeComponent.qml
|
||||||
EncryptedComponent.qml
|
EncryptedComponent.qml
|
||||||
FileComponent.qml
|
FileComponent.qml
|
||||||
@@ -40,7 +41,6 @@ ecm_add_qml_module(timeline GENERATE_PLUGIN_SOURCE
|
|||||||
LiveLocationComponent.qml
|
LiveLocationComponent.qml
|
||||||
LoadComponent.qml
|
LoadComponent.qml
|
||||||
LocationComponent.qml
|
LocationComponent.qml
|
||||||
MessageEditComponent.qml
|
|
||||||
MimeComponent.qml
|
MimeComponent.qml
|
||||||
PdfPreviewComponent.qml
|
PdfPreviewComponent.qml
|
||||||
PollComponent.qml
|
PollComponent.qml
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.kde.neochat
|
|||||||
import org.kde.neochat.chatbar
|
import org.kde.neochat.chatbar
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A component to show an edit text field for a text message being edited.
|
* @brief A component to show a chat bar in a message bubble.
|
||||||
*/
|
*/
|
||||||
QQC2.TextArea {
|
QQC2.TextArea {
|
||||||
id: root
|
id: root
|
||||||
@@ -20,10 +20,12 @@ QQC2.TextArea {
|
|||||||
* @brief The NeoChatRoom the delegate is being displayed in.
|
* @brief The NeoChatRoom the delegate is being displayed in.
|
||||||
*/
|
*/
|
||||||
required property NeoChatRoom room
|
required property NeoChatRoom room
|
||||||
onRoomChanged: {
|
|
||||||
_private.chatBarCache = room.editCache;
|
/**
|
||||||
_private.chatBarCache.relationIdChanged.connect(_private.updateEditText());
|
* @brief The ChatBarCache to use.
|
||||||
}
|
*/
|
||||||
|
required property ChatBarCache chatBarCache
|
||||||
|
onChatBarCacheChanged: documentHandler.chatBarCache = chatBarCache
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ActionsHandler object to use.
|
* @brief The ActionsHandler object to use.
|
||||||
@@ -33,27 +35,28 @@ QQC2.TextArea {
|
|||||||
*/
|
*/
|
||||||
required property ActionsHandler actionsHandler
|
required property ActionsHandler actionsHandler
|
||||||
|
|
||||||
property var minimumHeight: editButtons.height + topPadding + bottomPadding
|
|
||||||
property var preferredWidth: editTextMetrics.advanceWidth + rightPadding + Kirigami.Units.smallSpacing + Kirigami.Units.gridUnit
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The maximum width that the bubble's content can be.
|
* @brief The maximum width that the bubble's content can be.
|
||||||
*/
|
*/
|
||||||
property real maxContentWidth: -1
|
property real maxContentWidth: -1
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
Layout.preferredWidth: textMetrics.advanceWidth + rightPadding + Kirigami.Units.smallSpacing + Kirigami.Units.gridUnit
|
||||||
Layout.maximumWidth: root.maxContentWidth
|
Layout.maximumWidth: root.maxContentWidth
|
||||||
|
Layout.minimumHeight: chatButtons.height + topPadding + bottomPadding
|
||||||
|
|
||||||
Component.onCompleted: _private.updateEditText()
|
Component.onCompleted: _private.updateText()
|
||||||
|
|
||||||
rightPadding: editButtons.width + editButtons.anchors.rightMargin * 2
|
topPadding: Kirigami.Units.smallSpacing
|
||||||
|
bottomPadding: Kirigami.Units.smallSpacing
|
||||||
|
rightPadding: chatButtons.width + chatButtons.anchors.rightMargin * 2
|
||||||
|
|
||||||
color: Kirigami.Theme.textColor
|
color: Kirigami.Theme.textColor
|
||||||
verticalAlignment: TextEdit.AlignVCenter
|
verticalAlignment: TextEdit.AlignVCenter
|
||||||
wrapMode: TextEdit.Wrap
|
wrapMode: TextEdit.Wrap
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
_private.chatBarCache.text = text;
|
root.chatBarCache.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onEnterPressed: {
|
Keys.onEnterPressed: {
|
||||||
@@ -62,7 +65,7 @@ QQC2.TextArea {
|
|||||||
} else if (event.modifiers & Qt.ShiftModifier) {
|
} else if (event.modifiers & Qt.ShiftModifier) {
|
||||||
root.insert(cursorPosition, "\n");
|
root.insert(cursorPosition, "\n");
|
||||||
} else {
|
} else {
|
||||||
root.postEdit();
|
_private.post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
@@ -71,7 +74,7 @@ QQC2.TextArea {
|
|||||||
} else if (event.modifiers & Qt.ShiftModifier) {
|
} else if (event.modifiers & Qt.ShiftModifier) {
|
||||||
root.insert(cursorPosition, "\n");
|
root.insert(cursorPosition, "\n");
|
||||||
} else {
|
} else {
|
||||||
root.postEdit();
|
_private.post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Keys.onTabPressed: {
|
Keys.onTabPressed: {
|
||||||
@@ -88,11 +91,11 @@ QQC2.TextArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is anchored like this so that control expands properly as the edited
|
* This is anchored like this so that control expands properly as the
|
||||||
* text grows in length.
|
* text grows in length.
|
||||||
*/
|
*/
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: editButtons
|
id: chatButtons
|
||||||
anchors.verticalCenter: root.verticalCenter
|
anchors.verticalCenter: root.verticalCenter
|
||||||
anchors.right: root.right
|
anchors.right: root.right
|
||||||
anchors.rightMargin: Kirigami.Units.smallSpacing
|
anchors.rightMargin: Kirigami.Units.smallSpacing
|
||||||
@@ -100,10 +103,10 @@ QQC2.TextArea {
|
|||||||
QQC2.ToolButton {
|
QQC2.ToolButton {
|
||||||
display: QQC2.AbstractButton.IconOnly
|
display: QQC2.AbstractButton.IconOnly
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: i18nc("@action:button", "Confirm edit")
|
text: root.chatBarCache.isEditing ? i18nc("@action:button", "Confirm edit") : i18nc("@action:button", "Post message in thread")
|
||||||
icon.name: "checkmark"
|
icon.name: "document-send"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.postEdit();
|
_private.post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QQC2.ToolTip.text: text
|
QQC2.ToolTip.text: text
|
||||||
@@ -112,10 +115,10 @@ QQC2.TextArea {
|
|||||||
QQC2.ToolButton {
|
QQC2.ToolButton {
|
||||||
display: QQC2.AbstractButton.IconOnly
|
display: QQC2.AbstractButton.IconOnly
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: i18nc("@action:button", "Cancel edit")
|
text: i18nc("@action:button", "Cancel")
|
||||||
icon.name: "dialog-close"
|
icon.name: "dialog-close"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
_private.chatBarCache.editId = "";
|
root.chatBarCache.editId = "";
|
||||||
}
|
}
|
||||||
shortcut: "Escape"
|
shortcut: "Escape"
|
||||||
}
|
}
|
||||||
@@ -155,30 +158,28 @@ QQC2.TextArea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextMetrics {
|
TextMetrics {
|
||||||
id: editTextMetrics
|
id: textMetrics
|
||||||
text: root.text
|
text: root.text
|
||||||
}
|
}
|
||||||
|
|
||||||
function postEdit() {
|
|
||||||
root.actionsHandler.handleMessageEvent(_private.chatBarCache);
|
|
||||||
root.clear();
|
|
||||||
_private.chatBarCache.editId = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: _private
|
id: _private
|
||||||
property ChatBarCache chatBarCache
|
|
||||||
onChatBarCacheChanged: documentHandler.chatBarCache = chatBarCache
|
|
||||||
|
|
||||||
function updateEditText() {
|
function updateText() {
|
||||||
// This could possibly be undefined due to some esoteric QtQuick issue. Referencing it somewhere in JS is enough.
|
// This could possibly be undefined due to some esoteric QtQuick issue. Referencing it somewhere in JS is enough.
|
||||||
documentHandler.document;
|
documentHandler.document;
|
||||||
if (chatBarCache?.isEditing && chatBarCache.relationMessage.length > 0) {
|
if (chatBarCache?.isEditing && chatBarCache.relationMessage.length > 0) {
|
||||||
root.text = chatBarCache.relationMessage;
|
root.text = chatBarCache.relationMessage;
|
||||||
chatBarCache.updateMentions(root.textDocument, documentHandler);
|
root.chatBarCache.updateMentions(root.textDocument, documentHandler);
|
||||||
root.forceActiveFocus();
|
root.forceActiveFocus();
|
||||||
root.cursorPosition = root.length;
|
root.cursorPosition = root.text.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function post() {
|
||||||
|
root.actionsHandler.handleMessageEvent(root.chatBarCache);
|
||||||
|
root.clear();
|
||||||
|
root.chatBarCache.clearRelations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,8 +206,9 @@ DelegateChooser {
|
|||||||
|
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
roleValue: MessageComponentType.Edit
|
roleValue: MessageComponentType.Edit
|
||||||
delegate: MessageEditComponent {
|
delegate: ChatBarComponent {
|
||||||
room: root.room
|
room: root.room
|
||||||
|
chatBarCache: room.editCache
|
||||||
actionsHandler: root.actionsHandler
|
actionsHandler: root.actionsHandler
|
||||||
maxContentWidth: root.maxContentWidth
|
maxContentWidth: root.maxContentWidth
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user