qmlFrontend/qml/qmlFrontend/Chat.qml
author unc0rr
Mon, 30 Nov 2015 23:25:18 +0300
branchqmlfrontend
changeset 11434 23912c93935a
parent 11430 f88b3948adf3
permissions -rw-r--r--
- Implement engine runs queue - Many small improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     1
import QtQuick 2.0
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     2
import Hedgewars.Engine 1.0
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     3
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     4
Rectangle {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     5
    color: "#15193a"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     6
    radius: 8
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     7
    border.width: 4
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     8
    border.color: "#ea761d"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     9
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    10
    ListView {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    11
        id: chatLines
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    12
        x: 0
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    13
        width: parent.width - clientsList.width
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
    14
        anchors.top: parent.top
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
    15
        anchors.bottom: input.top
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    16
        focus: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    17
        clip: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    18
        highlightFollowsCurrentItem: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    19
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    20
        model: ListModel {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    21
            id: chatLinesModel
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    22
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    23
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    24
        delegate: Rectangle {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    25
            id: chatLinesDelegate
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    26
            height: 24
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    27
            width: parent.width
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    28
            color: "transparent"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    29
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    30
            Row {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    31
                spacing: 8;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    32
                Text {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    33
                    color: "#ffffa0"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    34
                    text: nick
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    35
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    36
                    MouseArea {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    37
                         z: 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    38
                         anchors.fill: parent
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    39
                         onClicked: ;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    40
                    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    41
                }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    42
                Text {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    43
                    color: "#ffffff"
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11416
diff changeset
    44
                    text: line
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    45
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    46
                    MouseArea {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    47
                         z: 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    48
                         anchors.fill: parent
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    49
                         onClicked: ;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    50
                    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    51
                }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    52
            }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    53
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    54
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    55
11416
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    56
        function addLine(nickname, line) {
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11416
diff changeset
    57
            chatLinesModel.append({"nick" : nickname, "line": line})
11416
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    58
            if(chatLinesModel.count > 200)
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    59
                chatLinesModel.remove(0)
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    60
            chatLines.currentIndex = chatLinesModel.count - 1
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    61
        }
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    62
    }
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    63
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    64
    TextInput {
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    65
        id: input
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    66
        x: 0
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    67
        width: chatLines.width
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    68
        height: 24
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
    69
        anchors.bottom: parent.bottom
11416
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    70
        color: "#eccd2f"
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    71
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    72
        onAccepted: {
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    73
            HWEngine.sendChatMessage(text)
11430
f88b3948adf3 UI knowns local player nickname
unc0rr
parents: 11424
diff changeset
    74
            chatLines.addLine(HWEngine.myNickname(), text)
11416
78d6b99ddcb0 Can send chat messages now
unc0rr
parents: 11415
diff changeset
    75
            text = ""
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    76
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    77
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    78
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    79
    ListView {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    80
        id: clientsList
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    81
        x: parent.width - width
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    82
        width: 100
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    83
        height: parent.height
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    84
        focus: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    85
        clip: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    86
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    87
        model: ListModel {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    88
            id: chatClientsModel
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    89
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    90
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    91
        delegate: Rectangle {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    92
            id: chatClientDelegate
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    93
            height: 24
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    94
            width: parent.width
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    95
            color: "transparent"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    96
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    97
            Row {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    98
                Text {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    99
                    color: "#ffffff"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   100
                    text: name
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   101
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   102
                    MouseArea {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   103
                         z: 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   104
                         anchors.fill: parent
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   105
                         onClicked: ;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   106
                    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   107
                }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   108
            }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   109
        }
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   110
    }
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   111
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   112
    function addChatLine(nickname, line) {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   113
        chatLines.addLine(nickname, line)
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   114
    }
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   115
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   116
    function addClient(clientName) {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   117
        chatClientsModel.append({"isAdmin": false, "name": clientName})
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   118
        chatLines.addLine("***", qsTr("%1 joined").arg(clientName))
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   119
    }
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   120
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   121
    function removeClient(clientName, reason) {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   122
        var i = chatClientsModel.count - 1;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   123
        while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   124
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   125
        if(i >= 0) {
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   126
            chatClientsModel.remove(i, 1);
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   127
            chatLines.addLine("***", qsTr("%1 quit (%2)").arg(clientName).arg(reason))
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   128
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   129
    }
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11430
diff changeset
   130
23912c93935a - Implement engine runs queue
unc0rr
parents: 11430
diff changeset
   131
    function clear() {
23912c93935a - Implement engine runs queue
unc0rr
parents: 11430
diff changeset
   132
        chatClientsModel.clear()
23912c93935a - Implement engine runs queue
unc0rr
parents: 11430
diff changeset
   133
        chatLinesModel.clear()
23912c93935a - Implement engine runs queue
unc0rr
parents: 11430
diff changeset
   134
    }
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   135
}
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   136
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   137