~unity-2d-team/unity-2d/shortcut-hint-overlay

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * This file is part of unity-2d
 *
 * Copyright 2010-2011 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 1.0
import "../common"
import "../common/utils.js" as Utils

FocusScope {
    id: filterLoader
    objectName: filterModel.rendererName

    property variant lens
    property variant filterModel
    property bool isFirst

    height: childrenRect.height

    FocusScope {
        id: header

        function accessibleDescription() {
            if (filterModel.filtering) {
                return u2d.tr("Filter %1 active").arg(filterModel.name)
            } else {
                return u2d.tr("Filter %1 inactive").arg(filterModel.name)
            }
        }

        Accessible.name: accessibleDescription()

        KeyNavigation.down: filterView

        focus: true
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        height: childrenRect.height

        Rectangle {
            id: separatorLine

            color: "#21ffffff"

            height: 1
            visible: !isFirst
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
        }

        TextCustom {
            id: title

            anchors.verticalCenter: clearButton.verticalCenter
            anchors.topMargin: isFirst ? 0 : 13
            anchors.left: parent.left

            text: u2d.tr(filterModel.name)
            fontSize: "large"
            font.bold: true
            font.underline: ( parent.state == "selected" || parent.state == "hovered" )
        }

        TickBox {
            id: clearButton

            focus: true

            // FIXME: that will probably break with non-latin LANG
            // dynamically calculate button width, but limit to 100
            width: Math.min(100, (10 * u2d.tr("All").length) + 18)
            height: 30
            anchors.top: parent.top
            anchors.topMargin: isFirst ? 0 : 13
            anchors.right: parent.right

            text: u2d.tr("All")
            checked: !filterModel.filtering
            onClicked: filterModel.clear()
        }
    }

    Loader {
        id: filterView
        objectName: filterModel.rendererName

        KeyNavigation.up: header
        anchors.top: header.bottom
        anchors.topMargin: 15
        anchors.left: parent.left
        anchors.right: parent.right

        source: Utils.convertToCamelCase(filterModel.rendererName) + ".qml"
        onStatusChanged: {
            if (status == Loader.Error) {
                console.log("Failed to load filter renderer", filterModel.rendererName)
            }
        }

        Binding { target: filterView.item; property: "lens"; value: filterLoader.lens }
        Binding { target: filterView.item; property: "filterModel"; value: filterLoader.filterModel }

        onLoaded: item.focus = true
    }
}