qmlFrontend/qml/qmlFrontend/Chat.qml
author unc0rr
Thu, 19 Nov 2015 23:04:53 +0300
branchqmlfrontend
changeset 11420 05cf35103206
child 11421 78d6b99ddcb0
permissions -rw-r--r--
Lobby page with chat widget(readonly)

import QtQuick 2.0
import Hedgewars.Engine 1.0

Rectangle {
    id: chat
    color: "#15193a"
    radius: 8
    border.width: 4
    opacity: 1
    border.color: "#ea761d"

    ListView {
        id: chatLines
        x: 0
        y: 0
        width: parent.width - clientsList.width
        height: parent.height
        focus: true
        clip: true
        highlightFollowsCurrentItem: true

        model: ListModel {
            id: chatLinesModel
        }

        delegate: Rectangle {
            id: chatLinesDelegate
            height: 24
            width: parent.width
            color: "transparent"

            Row {
                spacing: 8;
                Text {
                    color: "#ffffa0"
                    text: nick

                    MouseArea {
                         z: 1
                         anchors.fill: parent
                         onClicked: ;
                    }
                }
                Text {
                    color: "#ffffff"
                    text: name

                    MouseArea {
                         z: 1
                         anchors.fill: parent
                         onClicked: ;
                    }
                }
            }

        }

        Connections {
            target: HWEngine
            onLobbyChatLine: {
                chatLinesModel.append({"nick" : nickname, "name": line})
                if(chatLinesModel.count > 200)
                    chatLinesModel.remove(0)
                chatLines.currentIndex = chatLinesModel.count - 1
            }
        }
    }

    ListView {
        id: clientsList
        x: parent.width - width
        width: 100
        height: parent.height
        focus: true
        clip: true

        model: ListModel {
            id: chatClientsModel
        }

        delegate: Rectangle {
            id: chatClientDelegate
            height: 24
            width: parent.width
            color: "transparent"

            Row {
                Text {
                    color: "#ffffff"
                    text: name

                    MouseArea {
                         z: 1
                         anchors.fill: parent
                         onClicked: ;
                    }
                }
            }

        }

        Connections {
            target: HWEngine
            onLobbyClientAdded: {
                chatClientsModel.append({"isAdmin": false, "name": clientName})
            }
            onLobbyClientRemoved: {
                var i = chatClientsModel.count - 1;
                while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;

                if(i >= 0) chatClientsModel.remove(i, 1);
            }
        }
    }
}