aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quickcontrols/chattutorial/chapter5/ConversationPage.qml
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quickcontrols/chattutorial/chapter5/ConversationPage.qml')
-rw-r--r--examples/quickcontrols/chattutorial/chapter5/ConversationPage.qml117
1 files changed, 117 insertions, 0 deletions
diff --git a/examples/quickcontrols/chattutorial/chapter5/ConversationPage.qml b/examples/quickcontrols/chattutorial/chapter5/ConversationPage.qml
new file mode 100644
index 0000000000..6e209b7a85
--- /dev/null
+++ b/examples/quickcontrols/chattutorial/chapter5/ConversationPage.qml
@@ -0,0 +1,117 @@
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls
+
+import io.qt.examples.chattutorial
+
+Page {
+ id: root
+
+ property string inConversationWith
+
+ header: ChatToolBar {
+ ToolButton {
+ text: qsTr("Back")
+ anchors.left: parent.left
+ anchors.leftMargin: 10
+ anchors.verticalCenter: parent.verticalCenter
+ onClicked: root.StackView.view.pop()
+ }
+
+ Label {
+ id: pageTitle
+ text: inConversationWith
+ font.pixelSize: 20
+ anchors.centerIn: parent
+ }
+ }
+
+ ColumnLayout {
+ anchors.fill: parent
+
+ ListView {
+ id: listView
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ Layout.margins: pane.leftPadding + messageField.leftPadding
+ displayMarginBeginning: 40
+ displayMarginEnd: 40
+ verticalLayoutDirection: ListView.BottomToTop
+ spacing: 12
+ model: SqlConversationModel {
+ recipient: inConversationWith
+ }
+ delegate: Column {
+ anchors.right: sentByMe ? listView.contentItem.right : undefined
+ spacing: 6
+
+ readonly property bool sentByMe: model.recipient !== "Me"
+
+ Row {
+ id: messageRow
+ spacing: 6
+ anchors.right: sentByMe ? parent.right : undefined
+
+ Image {
+ id: avatar
+ source: !sentByMe ? "images/" + model.author.replace(" ", "_") + ".png" : ""
+ }
+
+ Rectangle {
+ width: Math.min(messageText.implicitWidth + 24, listView.width - avatar.width - messageRow.spacing)
+ height: messageText.implicitHeight + 24
+ color: sentByMe ? "lightgrey" : "steelblue"
+
+ Label {
+ id: messageText
+ text: model.message
+ color: sentByMe ? "black" : "white"
+ anchors.fill: parent
+ anchors.margins: 12
+ wrapMode: Label.Wrap
+ }
+ }
+ }
+
+ Label {
+ id: timestampText
+ text: Qt.formatDateTime(model.timestamp, "d MMM hh:mm")
+ color: "lightgrey"
+ anchors.right: sentByMe ? parent.right : undefined
+ }
+ }
+
+ ScrollBar.vertical: ScrollBar {}
+ }
+
+ Pane {
+ id: pane
+ Layout.fillWidth: true
+
+ RowLayout {
+ width: parent.width
+
+ TextArea {
+ id: messageField
+ Layout.fillWidth: true
+ placeholderText: qsTr("Compose message")
+ wrapMode: TextArea.Wrap
+ }
+
+ Button {
+ id: sendButton
+ text: qsTr("Send")
+ enabled: messageField.length > 0
+ onClicked: {
+ listView.model.sendMessage(inConversationWith, messageField.text);
+ messageField.text = "";
+ }
+ }
+ }
+ }
+ }
+}
+