~mterry/unity8/greeter-misc-cleanups

« back to all changes in this revision

Viewing changes to qml/Dash/Previews/PreviewExpandable.qml

  • Committer: Michael Terry
  • Date: 2014-08-07 15:30:54 UTC
  • mfrom: (1086.1.48 unity8)
  • Revision ID: michael.terry@canonical.com-20140807153054-nqahwmptl0dw9bum
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.3
 
18
import Ubuntu.Components 1.1
 
19
import "../../Components"
 
20
 
 
21
/*! \brief Preview widget for expandable widgets.
 
22
 
 
23
    This widget shows a list of widgets defined in widgetData["widgets"]
 
24
    Those widgets can be collapsed or uncollapsed. When uncollapsed
 
25
    all the widgets are shown, when collapsed only the first
 
26
    widgetData["collapsed-widgets"] are shown. It has a title that comes
 
27
    in via widgetData["title"]
 
28
 */
 
29
 
 
30
PreviewWidget {
 
31
    id: root
 
32
    implicitHeight: childrenRect.height
 
33
 
 
34
    expanded: false
 
35
 
 
36
    Label {
 
37
        id: titleLabel
 
38
        objectName: "titleLabel"
 
39
        anchors {
 
40
            left: parent.left
 
41
            right: expandButton.left
 
42
        }
 
43
        fontSize: "large"
 
44
        color: root.scopeStyle ? root.scopeStyle.foreground : "grey"
 
45
        visible: text !== ""
 
46
        opacity: .8
 
47
        text: widgetData["title"] || ""
 
48
        wrapMode: Text.Wrap
 
49
    }
 
50
 
 
51
    AbstractButton {
 
52
        id: expandButton
 
53
        objectName: "expandButton"
 
54
        width: titleLabel.height
 
55
        height: titleLabel.height
 
56
        anchors.right: parent.right
 
57
        onClicked: {
 
58
            root.expanded = !root.expanded;
 
59
        }
 
60
        Icon {
 
61
            anchors.fill: parent
 
62
            width: 64
 
63
            height: 64
 
64
            name: root.expanded ? "view-collapse" : "view-expand"
 
65
        }
 
66
    }
 
67
 
 
68
    Column {
 
69
        anchors {
 
70
            top: titleLabel.bottom
 
71
            topMargin: units.gu(1)
 
72
            left: parent.left
 
73
            right: parent.right
 
74
        }
 
75
        spacing: units.gu(1)
 
76
        Repeater {
 
77
            id: repeater
 
78
            objectName: "repeater"
 
79
            model: widgetData["widgets"]
 
80
            delegate: PreviewWidgetFactory {
 
81
                height: visible ? implicitHeight : 0
 
82
                width: parent.width
 
83
                widgetId: modelData.widgetId
 
84
                widgetType: modelData.type
 
85
                widgetData: modelData.properties
 
86
                isCurrentPreview: root.isCurrentPreview
 
87
                scopeStyle: root.scopeStyle
 
88
                anchors {
 
89
                    left: parent.left
 
90
                    right: parent.right
 
91
                }
 
92
                expanded: root.expanded
 
93
                visible: root.expanded || index < root.widgetData["collapsed-widgets"]
 
94
 
 
95
                onTriggered: {
 
96
                    root.triggered(widgetId, actionId, data);
 
97
                }
 
98
            }
 
99
        }
 
100
    }
 
101
}