summaryrefslogtreecommitdiffstats
path: root/src/libcommuni/examples/quick/qml/UserListView.qml
blob: 6daf06b9c2f08a9347da0474dd2f1723ac31eb81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (C) 2008-2014 The Communi Project
 *
 * This example is free, and not covered by the BSD license. There is no
 * restriction applied to their modification, redistribution, using and so on.
 * You can study them, modify them, use them in your own program - either
 * completely or partially.
 */

import QtQuick 2.1
import QtQuick.Controls 1.0
import Communi 3.0

Rectangle {
    id: background

    property IrcChannel channel

    signal queried(IrcUser user)

    color: "#edf3fe"

    Rectangle {
        id: frame
        anchors.fill: parent
        color: "transparent"
        border.color: "#aaa"
        anchors.topMargin: -1
        anchors.leftMargin: -1
        anchors.bottomMargin: -1
    }

    ScrollView {
        id: scrollView

        anchors.fill: parent
        anchors.topMargin: -1
        anchors.bottomMargin: -1

        ListView {
            id: listView

            model: IrcUserModel {
                id: userModel
                sortMethod: Irc.SortByTitle
                channel: background.channel
                onChannelChanged: listView.currentIndex = -1
            }

            delegate: Rectangle {
                width: parent.width
                height: Math.max(20, label.implicitHeight + 4)
                color: ListView.isCurrentItem ? "#b5d5ff" : "transparent"
                Label {
                    id: label
                    text: model.title
                    anchors.margins: 2
                    anchors.leftMargin: 6
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.verticalCenter: parent.verticalCenter
                }
                MouseArea {
                    anchors.fill: parent
                    onPressed: listView.currentIndex = index
                    onDoubleClicked: queried(model.user)
                }
            }
        }
    }
}