~nick-dedekind/unity8/indicators.hint-interval

« back to all changes in this revision

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

  • Committer: Nick Dedekind
  • Date: 2014-03-07 15:54:57 UTC
  • mfrom: (638.1.118 unity8)
  • Revision ID: nicholas.dedekind@gmail.com-20140307155457-f0s1zu5ll2czt3rq
merged with 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.0
 
18
import Ubuntu.Components 0.1
 
19
 
 
20
/*! \brief This component constructs the Preview UI.
 
21
 *
 
22
 *  Currently it displays all the widgets in a flickable column.
 
23
 */
 
24
 
 
25
Item {
 
26
    id: root
 
27
 
 
28
    /*! \brief Model containing preview widgets.
 
29
     *
 
30
     *  The model should expose "widgetId", "type" and "properties" roles, as well as
 
31
     *  have a triggered(QString widgetId, QString actionId, QVariantMap data) method,
 
32
     *  that's called when actions are executed in widgets.
 
33
     */
 
34
    property var previewModel
 
35
 
 
36
    //! \brief Should be set to true if this preview is currently displayed.
 
37
    property bool isCurrent: false
 
38
 
 
39
    clip: true
 
40
 
 
41
    Connections {
 
42
        target: shell.applicationManager
 
43
        onMainStageFocusedApplicationChanged: {
 
44
            root.close();
 
45
        }
 
46
        onSideStageFocusedApplicationChanged: {
 
47
            root.close();
 
48
        }
 
49
    }
 
50
 
 
51
    onPreviewModelChanged: processingMouseArea.enabled = false
 
52
 
 
53
    MouseArea {
 
54
        anchors.fill: parent
 
55
    }
 
56
 
 
57
    Row {
 
58
        id: row
 
59
 
 
60
        spacing: units.gu(1)
 
61
        anchors { fill: parent; margins: spacing }
 
62
 
 
63
        Repeater {
 
64
            model: 1
 
65
 
 
66
            delegate: ListView {
 
67
                id: column
 
68
                anchors { top: parent.top; bottom: parent.bottom }
 
69
                width: row.width
 
70
                spacing: row.spacing
 
71
                bottomMargin: Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height : 0
 
72
 
 
73
                model: previewModel
 
74
                cacheBuffer: units.gu(40)
 
75
 
 
76
                Behavior on contentY { UbuntuNumberAnimation { } }
 
77
 
 
78
                delegate: PreviewWidgetFactory {
 
79
                    widgetId: model.widgetId
 
80
                    widgetType: model.type
 
81
                    widgetData: model.properties
 
82
                    isCurrentPreview: root.isCurrent
 
83
                    anchors { left: parent.left; right: parent.right }
 
84
 
 
85
                    onTriggered: {
 
86
                        processingMouseArea.enabled = true;
 
87
                        previewModel.triggered(widgetId, actionId, data);
 
88
                    }
 
89
 
 
90
                    onFocusChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
 
91
 
 
92
                    onHeightChanged: if (focus) column.positionViewAtIndex(index, ListView.Contain)
 
93
                }
 
94
            }
 
95
        }
 
96
    }
 
97
 
 
98
    MouseArea {
 
99
        id: processingMouseArea
 
100
        objectName: "processingMouseArea"
 
101
        anchors.fill: parent
 
102
        enabled: false
 
103
    }
 
104
}