~boghison/lang/trunk

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
72
73
74
75
76
77
import QtQuick 2.0

import Ubuntu.Components 1.1
import Ubuntu.Components.Popups 1.0
import Ubuntu.Components.ListItems 1.0 as ListItem


Page {
    id: page
    title: i18n.tr("Vocabulary Collections")

    head.actions: [
        Action {
            text: i18n.tr("Add Collection")
            iconName: "add"
            onTriggered: PopupUtils.open(addVocab)
        }
    ]

    property int columns: width/units.gu(20)

    property int padding: units.gu(2)
    property int columnWidth: gridView.count < columns ? units.gu(20) : (width - padding * (columns + 1))/columns

    // We must set this to null when displaying the empty label so the label is centered
    // correctly under the header
    flickable: gridView.count == 0 ? null : gridView

    GridView {
        id: gridView

        anchors {
            fill: parent
            margins: page.padding/2
        }

        cellWidth: columnWidth + padding
        cellHeight: columnWidth * 4/3 + padding

        model: vocabDB.contents["vocabularies"]
        delegate: Item {
            width: gridView.cellWidth
            height: gridView.cellHeight

            UbuntuShape {
                anchors.centerIn: parent

                width: columnWidth
                height: width * 4/3
                color: modelData.color

                Label {
                    anchors.centerIn: parent
                    text: modelData.name
                    color: "white"
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: handleShape(parent.color, parent.children[0].text)
                }
            }
        }
    }

    Scrollbar {
        flickableItem: gridView
    }

    Label {
        anchors.centerIn: parent
        fontSize: "large"
        opacity: 0.5
        visible: gridView.count == 0

        text: "No vocabulary collections yet"
    }
}