summaryrefslogtreecommitdiff
path: root/examples/webchannel/chatclient-qml/qmlchatclient.qml
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webchannel/chatclient-qml/qmlchatclient.qml')
-rw-r--r--examples/webchannel/chatclient-qml/qmlchatclient.qml108
1 files changed, 39 insertions, 69 deletions
diff --git a/examples/webchannel/chatclient-qml/qmlchatclient.qml b/examples/webchannel/chatclient-qml/qmlchatclient.qml
index 1bc67ec..47f5f59 100644
--- a/examples/webchannel/chatclient-qml/qmlchatclient.qml
+++ b/examples/webchannel/chatclient-qml/qmlchatclient.qml
@@ -61,6 +61,7 @@ ApplicationWindow {
id: root
property var channel
+ property string loginName: loginUi.userName.text
title: "Chat client"
width: 640
@@ -101,22 +102,23 @@ ApplicationWindow {
//connect to the changed signal of the userList property
ch.objects.chatserver.userListChanged.connect(function(args) {
- userlist.text = '';
+ mainUi.userlist.text = '';
ch.objects.chatserver.userList.forEach(function(user) {
- userlist.text += user + '\n';
+ mainUi.userlist.text += user + '\n';
});
});
//connect to the newMessage signal
ch.objects.chatserver.newMessage.connect(function(time, user, message) {
- chat.text = chat.text + "[" + time + "] " + user + ": " + message + '\n';
+ var line = "[" + time + "] " + user + ": " + message + '\n';
+ mainUi.chat.text = mainUi.chat.text + line;
});
//connect to the keep alive signal
ch.objects.chatserver.keepAlive.connect(function(args) {
- if (loginName.text !== '')
+ if (loginName !== '')
//and call the keep alive response method as an answer
- ch.objects.chatserver.keepAliveResponse(loginName.text);
+ ch.objects.chatserver.keepAliveResponse(loginName);
});
});
@@ -126,86 +128,54 @@ ApplicationWindow {
}
}
- GridLayout {
- id: grid
- columns: 2
+ MainForm {
+ id: mainUi
anchors.fill: parent
- Text {
- id: chat
-
- text: ""
- Layout.fillHeight: true
- Layout.fillWidth: true
- }
-
- Text {
- id: userlist
-
- text: ""
- width: 150
- Layout.fillHeight: true
- }
- TextField {
- id: message
-
- height: 50
- Layout.columnSpan: 2
- Layout.fillWidth: true
-
+ Connections {
+ target: mainUi.message
onEditingFinished: {
- if (message.text.length) {
+ if (mainUi.message.text.length) {
//call the sendMessage method to send the message
- root.channel.objects.chatserver.sendMessage(loginName.text, message.text);
+ root.channel.objects.chatserver.sendMessage(loginName,
+ mainUi.message.text);
}
- message.text = '';
+ mainUi.message.text = '';
}
}
}
-
Window {
id: loginWindow
title: "Login"
modality: Qt.ApplicationModal
-
- TextField {
- id: loginName
-
- anchors.top: parent.top
- anchors.horizontalCenter: parent.horizontalCenter
- }
-
- Button {
- id: loginButton
-
- anchors.top: loginName.bottom
- anchors.horizontalCenter: parent.horizontalCenter
- text: "Login"
-
- onClicked: {
- //call the login method
- root.channel.objects.chatserver.login(loginName.text, function(arg) {
- //check the return value for success
- if (arg === true) {
- loginError.visible = false;
- loginWindow.close();
- } else {
- loginError.visible = true;
- }
- });
+ width: 300
+ height: 200
+
+ LoginForm {
+ id: loginUi
+ anchors.fill: parent
+
+ nameInUseError.visible: false
+
+ Connections {
+ target: loginUi.loginButton
+
+ onClicked: {
+ //call the login method
+ root.channel.objects.chatserver.login(loginName, function(arg) {
+ //check the return value for success
+ if (arg === true) {
+ loginUi.nameInUseError.visible = false;
+ loginWindow.close();
+ } else {
+ loginUi.nameInUseError.visible = true;
+ }
+ });
+ }
}
}
-
- Text {
- id: loginError
-
- anchors.top: loginButton.bottom
- anchors.horizontalCenter: parent.horizontalCenter
- text: "Name already in use"
- visible: false
- }
}
MessageDialog {