Further improvements to the ChatBox API

Further improvements to the ChatBox API so that outside components no longer access the ChatBar item directly.
This commit is contained in:
James Graham
2023-06-09 15:02:42 +00:00
parent 9425f24315
commit 105be518c7
3 changed files with 19 additions and 13 deletions

View File

@@ -195,7 +195,7 @@ QQC2.Control {
x: textField.cursorRectangle.x
y: textField.cursorRectangle.y - height
onFormattingSelected: chatBar.formatText(format, selectionStart, selectionEnd)
onFormattingSelected: root.formatText(format, selectionStart, selectionEnd)
}
Keys.onDeletePressed: {
@@ -218,7 +218,7 @@ QQC2.Control {
} else if (event.modifiers & Qt.ShiftModifier || Kirigami.Settings.isMobile) {
textField.insert(cursorPosition, "\n")
} else {
chatBar.postMessage();
root.postMessage();
}
}
Keys.onReturnPressed: {
@@ -227,7 +227,7 @@ QQC2.Control {
} else if (event.modifiers & Qt.ShiftModifier || Kirigami.Settings.isMobile) {
textField.insert(cursorPosition, "\n")
} else {
chatBar.postMessage();
root.postMessage();
}
}
Keys.onTabPressed: {
@@ -237,7 +237,7 @@ QQC2.Control {
}
Keys.onPressed: {
if (event.key === Qt.Key_V && event.modifiers & Qt.ControlModifier) {
chatBar.pasteImage();
root.pasteImage();
} else if (event.key === Qt.Key_Up && event.modifiers & Qt.ControlModifier) {
currentRoom.replyLastMessage();
} else if (event.key === Qt.Key_Up && textField.text.length === 0) {

View File

@@ -37,16 +37,20 @@ ColumnLayout {
*/
property NeoChatRoom currentRoom
/**
* @brief The chatBar object
*/
property alias chatBar: chatBar
/**
* @brief A message has been sent from the chat bar.
*/
signal messageSent()
/**
* @brief Insert the given text into the ChatBar.
*
* The text is inserted at the current cursor location.
*/
function insertText(text) {
chatBar.insertText(text)
}
spacing: 0
Kirigami.Theme.colorSet: Kirigami.Theme.View
@@ -86,4 +90,6 @@ ColumnLayout {
chatBox.messageSent();
}
}
onActiveFocusChanged: chatBar.forceActiveFocus()
}

View File

@@ -38,7 +38,7 @@ Kirigami.Page {
timelineViewLoader.item.positionViewAtBeginning();
hasScrolledUpBefore = false;
if (!Kirigami.Settings.isMobile && chatBoxLoader.item) {
chatBoxLoader.item.chatBar.forceActiveFocus();
chatBoxLoader.item.forceActiveFocus();
}
}
@@ -61,7 +61,7 @@ Kirigami.Page {
currentRoom: root.currentRoom
onFocusChatBox: {
if (chatBoxLoader.item) {
chatBoxLoader.item.chatBar.forceActiveFocus()
chatBoxLoader.item.forceActiveFocus()
}
}
}
@@ -151,8 +151,8 @@ Kirigami.Page {
Keys.onPressed: {
if (!(event.modifiers & Qt.ControlModifier) && event.key < Qt.Key_Escape) {
event.accepted = true;
chatBoxLoader.item.chatBar.insertText(event.text);
chatBoxLoader.item.chatBar.forceActiveFocus();
chatBoxLoader.item.insertText(event.text);
chatBoxLoader.item.forceActiveFocus();
return;
} else if (event.key === Qt.Key_PageUp) {
event.accepted = true;