on xenial help sign in
Add Generic Preview
commita4e4266ecc7b51ce87b65f991473fe73b23bbd66 authorYing-Chun Liu <paul.liu@canonical.com> dateFri 5 Jul 2013, 01:56 (13 years ago) parent5993b18
3 files changed+221
Dash/Generic/GenericPreview.qml+84 Dash/GenericScopeView.qml+105 Dash/PreviewDelegateMapper.qml+32
Dash/Generic/GenericPreview.qmlnew file+84
@@ -0,0 +1,84 @@
1+/*
2+ * Copyright (C) 2013 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+import "../../Components"
20+import "../../Components/ListItems" as ListItems
21+import "../../Components/IconUtil.js" as IconUtil
22+import ".."
23+
24+DashPreview {
25+ id: genericPreview
26+ property var previewData
27+
28+ title: previewData.title
29+ url: previewData.image
30+ previewWidthRatio: 0.6
31+
32+ buttons: GridView {
33+ id: buttons
34+ model: genericPreview.previewData.actions
35+
36+ property int numOfRows: (count+1)/2
37+ property int spacing: units.gu(1)
38+ height: Math.max(units.gu(4), units.gu(4)*numOfRows+spacing*(numOfRows-1))
39+
40+ cellWidth: Math.max(units.gu(9), width/2)
41+ cellHeight: buttonHeight+spacing
42+ property int buttonWidth: Math.max(0, width/2-spacing)
43+ property int buttonHeight: units.gu(4)
44+
45+ delegate: Button {
46+ width: Math.max(units.gu(4), buttons.buttonWidth)
47+ height: buttons.buttonHeight
48+ color: "#dd4814"
49+ text: modelData.displayName
50+ iconSource: modelData.iconHint
51+ iconPosition: "right"
52+ visible: true
53+ onClicked: {
54+ genericPreview.previewData.execute(modelData.id, { })
55+ }
56+ }
57+ focus: false
58+ }
59+ description: Column {
60+ spacing: units.gu(2)
61+
62+ Label {
63+ visible: text != ""
64+ fontSize: "medium"
65+ opacity: 0.6
66+ color: "white"
67+ text: previewData.subtitle
68+ style: Text.Raised
69+ styleColor: "black"
70+ wrapMode: Text.WordWrap
71+ }
72+
73+ Label {
74+ visible: text != ""
75+ fontSize: "small"
76+ opacity: 0.6
77+ color: "white"
78+ text: previewData.description
79+ style: Text.Raised
80+ styleColor: "black"
81+ wrapMode: Text.WordWrap
82+ }
83+ }
84+}
Dash/GenericScopeView.qml+105
@@ -19,6 +19,7 @@ import Ubuntu.Components 0.1
1919import "../Components"
2020import "../Components/ListItems" as ListItems
2121import "../Components/IconUtil.js" as IconUtil
22+import "Generic"
2223
2324ScopeView {
2425 id: scopeView
@@ -75,7 +76,32 @@ ScopeView {
7576 text: title
7677 imageWidth: units.gu(11)
7778 imageHeight: units.gu(16)
79+
7880 source: IconUtil.from_gicon(icon)
81+
82+ MouseArea {
83+ anchors {
84+ fill: parent
85+ }
86+ onClicked: {
87+ mouse.accepted = true
88+ effect.positionPx = mapToItem(categoryView, 0, 0).y
89+ scopeView.scope.activate(column_0, column_1,
90+ column_2, column_3,
91+ column_4, column_5,
92+ column_6, column_7,
93+ column_8)
94+ }
95+ onPressAndHold: {
96+ mouse.accepted = true
97+ effect.positionPx = mapToItem(categoryView, 0, 0).y
98+ scopeView.scope.preview(column_0, column_1,
99+ column_2, column_3,
100+ column_4, column_5,
101+ column_6, column_7,
102+ column_8)
103+ }
104+ }
79105 }
80106 }
81107 }
@@ -93,4 +119,83 @@ ScopeView {
93119 searchEntryEnabled: true
94120 }
95121 }
122+
123+ OpenEffect {
124+ id: effect
125+ anchors {
126+ fill: parent
127+ bottomMargin: -bottomOverflow
128+ }
129+ sourceItem: categoryView
130+
131+ enabled: gap > 0.0
132+
133+ topGapPx: (1 - gap) * positionPx
134+ topOpacity: (1 - gap * 1.2)
135+ bottomGapPx: positionPx + gap * (targetBottomGapPx - positionPx)
136+ bottomOverflow: units.gu(20)
137+ bottomOpacity: 1 - (gap * 0.8)
138+
139+ property int targetBottomGapPx: height - units.gu(8) - bottomOverflow
140+ property real gap: previewLoader.open ? 1.0 : 0.0
141+
142+ Behavior on gap {
143+ NumberAnimation {
144+ duration: 200
145+ easing.type: Easing.InOutQuad
146+ onRunningChanged: {
147+ if (!previewLoader.open && !running) {
148+ previewLoader.onScreen = false
149+ }
150+ }
151+ }
152+ }
153+ }
154+
155+ Connections {
156+ target: scopeView.scope
157+ onPreviewReady: {
158+ previewLoader.previewData = preview
159+ previewLoader.open = true
160+ }
161+ }
162+
163+ PreviewDelegateMapper {
164+ id: previewDelegateMapper
165+ }
166+
167+ Connections {
168+ ignoreUnknownSignals: true
169+ target: previewLoader.valid ? previewLoader.item : null
170+ onClose: {
171+ previewLoader.open = false
172+ }
173+ }
174+
175+ Loader {
176+ id: previewLoader
177+ property var previewData
178+ height: effect.bottomGapPx - effect.topGapPx
179+ anchors {
180+ top: parent.top
181+ topMargin: effect.topGapPx
182+ left: parent.left
183+ right: parent.right
184+ }
185+ source: onScreen ? previewDelegateMapper.map(previewLoader.previewData.rendererName) : ""
186+
187+ property bool open: false
188+ property bool onScreen: false
189+ property bool valid: item !== null
190+
191+ onOpenChanged: {
192+ if (open) {
193+ onScreen = true
194+ }
195+ }
196+
197+ onLoaded: {
198+ item.previewData = previewLoader.previewData
199+ }
200+ }
96201}
Dash/PreviewDelegateMapper.qmlnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2013 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+
19+QtObject {
20+ property var previewDelegateMapping: {"preview-generic": "Generic/GenericPreview.qml",
21+ }
22+ property string genericPreview: "Generic/GenericPreview.qml"
23+
24+ function map(rendererName) {
25+ var customPreview = previewDelegateMapping[rendererName]
26+ if (customPreview != undefined) {
27+ return customPreview
28+ }
29+ console.info("Renderer "+rendererName+" not found, using preview-generic")
30+ return genericPreview
31+ }
32+}