Small chatbox api improvement
Small improvement to the chatbox api by making currentRoom explicit and removing redundant properties.
This commit is contained in:
@@ -10,15 +10,47 @@ import QtQuick.Window 2.15
|
|||||||
import org.kde.kirigami 2.18 as Kirigami
|
import org.kde.kirigami 2.18 as Kirigami
|
||||||
import org.kde.neochat 1.0
|
import org.kde.neochat 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The component which handles the message sending.
|
||||||
|
*
|
||||||
|
* The ChatBox deals with laying out the visual elements with the ChatBar handling
|
||||||
|
* the core functionality of displaying the current message composition before sending.
|
||||||
|
*
|
||||||
|
* This includes support for the following message types:
|
||||||
|
* - text
|
||||||
|
* - media (video, image, file)
|
||||||
|
* - emojis/stickers
|
||||||
|
* - location
|
||||||
|
*
|
||||||
|
* In addition, when replying, this component supports showing the message that is being
|
||||||
|
* replied to.
|
||||||
|
*
|
||||||
|
* @note There is no edit functionality here this, is handled inline by the timeline
|
||||||
|
* text delegate.
|
||||||
|
*
|
||||||
|
* @sa ChatBox
|
||||||
|
*/
|
||||||
QQC2.Control {
|
QQC2.Control {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The current room that user is viewing.
|
||||||
|
*/
|
||||||
|
property var currentRoom
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The QQC2.TextArea object.
|
||||||
|
*
|
||||||
|
* @sa QQC2.TextArea
|
||||||
|
*/
|
||||||
property alias textField: textField
|
property alias textField: textField
|
||||||
property bool isReplying: currentRoom.chatBoxReplyId.length > 0
|
|
||||||
property bool attachmentPaneVisible: currentRoom.chatBoxAttachmentPath.length > 0
|
|
||||||
|
|
||||||
signal messageSent()
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The list of actions in the ChatBar.
|
||||||
|
*
|
||||||
|
* Each of these will be visualised in the ChatBar so new actions can be added
|
||||||
|
* by appending to this list.
|
||||||
|
*/
|
||||||
property list<Kirigami.Action> actions : [
|
property list<Kirigami.Action> actions : [
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
id: attachmentAction
|
id: attachmentAction
|
||||||
@@ -95,6 +127,11 @@ QQC2.Control {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A message has been sent from the chat bar.
|
||||||
|
*/
|
||||||
|
signal messageSent()
|
||||||
|
|
||||||
leftPadding: 0
|
leftPadding: 0
|
||||||
rightPadding: 0
|
rightPadding: 0
|
||||||
topPadding: 0
|
topPadding: 0
|
||||||
@@ -237,8 +274,8 @@ QQC2.Control {
|
|||||||
anchors.rightMargin: root.width > chatBarSizeHelper.currentWidth ? 0 : (chatBarScrollView.QQC2.ScrollBar.vertical.visible ? Kirigami.Units.largeSpacing * 3.5 : Kirigami.Units.largeSpacing)
|
anchors.rightMargin: root.width > chatBarSizeHelper.currentWidth ? 0 : (chatBarScrollView.QQC2.ScrollBar.vertical.visible ? Kirigami.Units.largeSpacing * 3.5 : Kirigami.Units.largeSpacing)
|
||||||
|
|
||||||
active: visible
|
active: visible
|
||||||
visible: root.isReplying || root.attachmentPaneVisible
|
visible: root.currentRoom.chatBoxReplyId.length > 0 || root.currentRoom.chatBoxAttachmentPath.length > 0
|
||||||
sourceComponent: root.isReplying ? replyPane : attachmentPane
|
sourceComponent: root.currentRoom.chatBoxReplyId.length > 0 ? replyPane : attachmentPane
|
||||||
}
|
}
|
||||||
Component {
|
Component {
|
||||||
id: replyPane
|
id: replyPane
|
||||||
@@ -301,7 +338,7 @@ QQC2.Control {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.rightMargin: (root.width - chatBarSizeHelper.currentWidth) / 2 + Kirigami.Units.largeSpacing + (chatBarScrollView.QQC2.ScrollBar.vertical.visible && !(root.width > chatBarSizeHelper.currentWidth) ? Kirigami.Units.largeSpacing * 2.5 : 0)
|
anchors.rightMargin: (root.width - chatBarSizeHelper.currentWidth) / 2 + Kirigami.Units.largeSpacing + (chatBarScrollView.QQC2.ScrollBar.vertical.visible && !(root.width > chatBarSizeHelper.currentWidth) ? Kirigami.Units.largeSpacing * 2.5 : 0)
|
||||||
|
|
||||||
visible: root.isReplying
|
visible: root.currentRoom.chatBoxReplyId.length > 0
|
||||||
display: QQC2.AbstractButton.IconOnly
|
display: QQC2.AbstractButton.IconOnly
|
||||||
action: Kirigami.Action {
|
action: Kirigami.Action {
|
||||||
text: i18nc("@action:button", "Cancel reply")
|
text: i18nc("@action:button", "Cancel reply")
|
||||||
|
|||||||
@@ -9,13 +9,44 @@ import QtQuick.Layouts 1.15
|
|||||||
import org.kde.kirigami 2.15 as Kirigami
|
import org.kde.kirigami 2.15 as Kirigami
|
||||||
import org.kde.neochat 1.0
|
import org.kde.neochat 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A component for typing and sending chat messages.
|
||||||
|
*
|
||||||
|
* This is designed to go to the bottom of the timeline and provides all the functionality
|
||||||
|
* required for the user to send messages to the room.
|
||||||
|
*
|
||||||
|
* This includes support for the following message types:
|
||||||
|
* - text
|
||||||
|
* - media (video, image, file)
|
||||||
|
* - emojis/stickers
|
||||||
|
* - location
|
||||||
|
*
|
||||||
|
* In addition when replying this component supports showing the message that is being
|
||||||
|
* replied to.
|
||||||
|
*
|
||||||
|
* @note The main role of this component is to layout the elements. The main functionality
|
||||||
|
* is handled by ChatBar
|
||||||
|
*
|
||||||
|
* @sa ChatBar
|
||||||
|
*/
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: chatBox
|
id: chatBox
|
||||||
|
|
||||||
signal messageSent()
|
/**
|
||||||
|
* @brief The current room that user is viewing.
|
||||||
|
*/
|
||||||
|
property var currentRoom
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The chatBar object
|
||||||
|
*/
|
||||||
property alias chatBar: chatBar
|
property alias chatBar: chatBar
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A message has been sent from the chat bar.
|
||||||
|
*/
|
||||||
|
signal messageSent()
|
||||||
|
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
Kirigami.Theme.colorSet: Kirigami.Theme.View
|
Kirigami.Theme.colorSet: Kirigami.Theme.View
|
||||||
@@ -44,6 +75,8 @@ ColumnLayout {
|
|||||||
// lineSpacing is height+leading, so subtract leading once since leading only exists between lines.
|
// lineSpacing is height+leading, so subtract leading once since leading only exists between lines.
|
||||||
Layout.maximumHeight: chatBarFontMetrics.lineSpacing * 8 - chatBarFontMetrics.leading + textField.topPadding + textField.bottomPadding
|
Layout.maximumHeight: chatBarFontMetrics.lineSpacing * 8 - chatBarFontMetrics.leading + textField.topPadding + textField.bottomPadding
|
||||||
|
|
||||||
|
currentRoom: root.currentRoom
|
||||||
|
|
||||||
FontMetrics {
|
FontMetrics {
|
||||||
id: chatBarFontMetrics
|
id: chatBarFontMetrics
|
||||||
font: chatBar.textField.font
|
font: chatBar.textField.font
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ Kirigami.Page {
|
|||||||
sourceComponent: ChatBox {
|
sourceComponent: ChatBox {
|
||||||
id: chatBox
|
id: chatBox
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
currentRoom: currentRoom
|
||||||
onMessageSent: {
|
onMessageSent: {
|
||||||
if (!timelineViewLoader.item.atYEnd) {
|
if (!timelineViewLoader.item.atYEnd) {
|
||||||
timelineViewLoader.item.goToLastMessage();
|
timelineViewLoader.item.goToLastMessage();
|
||||||
|
|||||||
Reference in New Issue
Block a user