qmlFrontend/qml/qmlFrontend/Chat.qml
author unc0rr
Thu, 19 Nov 2015 23:04:53 +0300
branchqmlfrontend
changeset 11415 05cf35103206
child 11416 78d6b99ddcb0
permissions -rw-r--r--
Lobby page with chat widget(readonly)
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
    id: chat
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     6
    color: "#15193a"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     7
    radius: 8
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     8
    border.width: 4
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
     9
    opacity: 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    10
    border.color: "#ea761d"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    11
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    12
    ListView {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    13
        id: chatLines
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    14
        x: 0
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    15
        y: 0
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    16
        width: parent.width - clientsList.width
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    17
        height: parent.height
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    18
        focus: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    19
        clip: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    20
        highlightFollowsCurrentItem: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    21
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    22
        model: ListModel {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    23
            id: chatLinesModel
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    24
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    25
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    26
        delegate: Rectangle {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    27
            id: chatLinesDelegate
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    28
            height: 24
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    29
            width: parent.width
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    30
            color: "transparent"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    31
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    32
            Row {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    33
                spacing: 8;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    34
                Text {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    35
                    color: "#ffffa0"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    36
                    text: nick
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    37
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    38
                    MouseArea {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    39
                         z: 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    40
                         anchors.fill: parent
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    41
                         onClicked: ;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    42
                    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    43
                }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    44
                Text {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    45
                    color: "#ffffff"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    46
                    text: name
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    47
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    48
                    MouseArea {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    49
                         z: 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    50
                         anchors.fill: parent
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    51
                         onClicked: ;
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
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    56
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    57
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    58
        Connections {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    59
            target: HWEngine
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    60
            onLobbyChatLine: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    61
                chatLinesModel.append({"nick" : nickname, "name": line})
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    62
                if(chatLinesModel.count > 200)
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    63
                    chatLinesModel.remove(0)
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    64
                chatLines.currentIndex = chatLinesModel.count - 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    65
            }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    66
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    67
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    68
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    69
    ListView {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    70
        id: clientsList
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    71
        x: parent.width - width
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    72
        width: 100
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    73
        height: parent.height
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    74
        focus: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    75
        clip: true
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    76
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    77
        model: ListModel {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    78
            id: chatClientsModel
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    79
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    80
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    81
        delegate: Rectangle {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    82
            id: chatClientDelegate
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    83
            height: 24
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    84
            width: parent.width
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    85
            color: "transparent"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    86
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    87
            Row {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    88
                Text {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    89
                    color: "#ffffff"
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    90
                    text: name
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    91
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    92
                    MouseArea {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    93
                         z: 1
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    94
                         anchors.fill: parent
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    95
                         onClicked: ;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    96
                    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    97
                }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    98
            }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
    99
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   100
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   101
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   102
        Connections {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   103
            target: HWEngine
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   104
            onLobbyClientAdded: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   105
                chatClientsModel.append({"isAdmin": false, "name": clientName})
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   106
            }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   107
            onLobbyClientRemoved: {
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   108
                var i = chatClientsModel.count - 1;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   109
                while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   110
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   111
                if(i >= 0) chatClientsModel.remove(i, 1);
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   112
            }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   113
        }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   114
    }
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   115
}
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   116
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents:
diff changeset
   117