on xenial help sign in
Implement the Expandable Preview Widget

Now TextSummary is not expandable by itself anymore, you have to use it inside an Expandable to get the behaviour

commit2756788ac2c0d67b01050288bd3e0bb2e3537f05 authorAlbert Astals <albert.astals@canonical.com> dateWed 30 Jul 2014, 16:08 (12 years ago) parentd6e0fa4b0cd21a
13 files changed+129−156
debian/control+1−1 qml/Components/SeeMore.qml−70 qml/Dash/Previews/PreviewExpandable.qml+106 qml/Dash/Previews/PreviewTextSummary.qml+2−15 qml/Dash/Previews/PreviewWidget.qml+3 qml/Dash/Previews/PreviewWidgetFactory.qml+5 tests/mocks/Unity/CMakeLists.txt+1−1 tests/mocks/Unity/fake_scopes.cpp+5 tests/mocks/Unity/fake_scopes.h+1 tests/qmltests/CMakeLists.txt+1−1 tests/qmltests/Components/tst_SeeMore.qml−52 tests/qmltests/Dash/Previews/tst_PreviewTextSummary.qml+3−16 tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
debian/control+1−1
@@ -23,7 +23,7 @@ Build-Depends: cmake,
2323 libpulse-dev,
2424 libqmenumodel-dev (>= 0.2.8),
2525 libqt5xmlpatterns5-dev,
26− libunity-api-dev (>= 7.85),
26+ libunity-api-dev (>= 7.87),
2727 libunity-mir-dev,
2828 libusermetricsoutput1-dev,
2929 libxcb1-dev,
qml/Components/SeeMore.qmldeleted−70
@@ -1,70 +0,0 @@
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−/*! Widget that can be used in combination with a text area to allow easy 'expand/collapse' functionality. */
21−
22−Item {
23− //! Boolean set to true when it suggests expanded functionality
24− property bool more: false
25−
26− implicitHeight: seeMoreLabel.height + units.gu(2)
27−
28− Row {
29− anchors.centerIn: parent
30− spacing: units.gu(2)
31−
32− Label {
33− id: seeMoreLabel
34− objectName: "seeMoreLabel"
35− text: i18n.tr("See more")
36− opacity: !more ? 0.8 : 0.4
37− // TODO: Fix requiring Palette update
38− color: "grey" //Theme.palette.selected.backgroundText
39− font.weight: Font.Bold
40−
41− MouseArea {
42− anchors.fill: parent
43− onClicked: more = true
44− }
45− }
46−
47− Image {
48− anchors {
49− top: parent.top
50− bottom: parent.bottom
51− }
52− width: units.dp(2)
53− source: "ListItems/graphics/ListItemDividerVertical.png"
54− }
55−
56− Label {
57− objectName: "seeLessLabel"
58− text: i18n.tr("See less")
59− opacity: more ? 0.8 : 0.4
60− // TODO: Fix requiring Palette update
61− color: "grey" //Theme.palette.selected.backgroundText
62− font.weight: Font.Bold
63−
64− MouseArea {
65− anchors.fill: parent
66− onClicked: more = false
67− }
68− }
69− }
70−}
qml/Dash/Previews/PreviewExpandable.qmlnew file+106
@@ -0,0 +1,106 @@
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+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+ // TODO Remove when "view-collapse" : "view-expand" are there
61+ Rectangle {
62+ anchors.fill: parent
63+ color: root.expanded ? "red" : "green"
64+ }
65+ Icon {
66+ anchors.fill: parent
67+ width: 64
68+ height: 64
69+ name: root.expanded ? "view-collapse" : "view-expand"
70+ }
71+ }
72+
73+ Column {
74+ anchors {
75+ top: titleLabel.bottom
76+ topMargin: units.gu(1)
77+ left: parent.left
78+ right: parent.right
79+ }
80+ spacing: units.gu(1)
81+ Repeater {
82+ id: repeater
83+ objectName: "repeater"
84+ model: widgetData["widgets"]
85+ delegate: PreviewWidgetFactory {
86+ height: visible ? implicitHeight : 0
87+ width: parent.width
88+ widgetId: modelData.widgetId
89+ widgetType: modelData.type
90+ widgetData: modelData.properties
91+ isCurrentPreview: root.isCurrentPreview
92+ scopeStyle: root.scopeStyle
93+ anchors {
94+ left: parent.left
95+ right: parent.right
96+ }
97+ expanded: root.expanded
98+ visible: root.expanded || index < root.widgetData["collapsed-widgets"]
99+
100+ onTriggered: {
101+ root.triggered(widgetId, actionId, data);
102+ }
103+ }
104+ }
105+ }
106+}
qml/Dash/Previews/PreviewTextSummary.qml+2−15
@@ -50,14 +50,14 @@ PreviewWidget {
5050 id: textLabel
5151 objectName: "textLabel"
5252
53− readonly property int maximumCollapsedLineCount: 7
53+ readonly property int maximumCollapsedLineCount: 3
5454
5555 anchors {
5656 left: parent.left
5757 right: parent.right
5858 top: titleLabel.visible ? titleLabel.bottom : parent.top
5959 }
60− height: (!seeMore.visible || seeMore.more) ? contentHeight : contentHeight / lineCount * (maximumCollapsedLineCount - 2)
60+ height: (lineCount <= maximumCollapsedLineCount || root.expanded) ? contentHeight : contentHeight / lineCount * maximumCollapsedLineCount
6161 clip: true
6262 fontSize: "small"
6363 lineHeight: 1.2
@@ -70,17 +70,4 @@ PreviewWidget {
7070 UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration }
7171 }
7272 }
73−
74− SeeMore {
75− id: seeMore
76− objectName: "seeMore"
77− anchors {
78− left: parent.left
79− right: parent.right
80− top: textLabel.bottom
81− topMargin: visible ? units.gu(1) : 0
82− }
83− height: visible ? implicitHeight : 0
84− visible: textLabel.lineCount > textLabel.maximumCollapsedLineCount
85− }
8673}
qml/Dash/Previews/PreviewWidget.qml+3
@@ -31,6 +31,9 @@ Item {
3131 //! The ScopeStyle component.
3232 property var scopeStyle: null
3333
34+ //! Should the widget show in expanded mode (For those that support it)
35+ property bool expanded: true
36+
3437 /*! \brief This signal should be emitted when a preview action was triggered.
3538 *
3639 * \param widgetId, actionId Respective identifiers from widgetData.
qml/Dash/Previews/PreviewWidgetFactory.qml+5
@@ -34,6 +34,9 @@ Loader {
3434 //! The ScopeStyle component.
3535 property var scopeStyle: null
3636
37+ //! Should the widget show in expanded mode (For those that support it)
38+ property bool expanded: true
39+
3740 //! Set to true if the parent preview is displayed.
3841 property bool isCurrentPreview: false
3942
@@ -47,6 +50,7 @@ Loader {
4750 switch (widgetType) {
4851 case "actions": return "PreviewActions.qml";
4952 case "audio": return "PreviewAudioPlayback.qml";
53+ case "expandable": return "PreviewExpandable.qml";
5054 case "gallery": return "PreviewImageGallery.qml";
5155 case "header": return "PreviewHeader.qml";
5256 case "image": return "PreviewZoomableImage.qml";
@@ -65,6 +69,7 @@ Loader {
6569 item.widgetId = Qt.binding(function() { return root.widgetId } )
6670 item.widgetData = Qt.binding(function() { return root.widgetData } )
6771 item.isCurrentPreview = Qt.binding(function() { return root.isCurrentPreview } )
72+ item.expanded = Qt.binding(function() { return root.expanded } )
6873 if (item.hasOwnProperty("scopeStyle")) item.scopeStyle = root.scopeStyle;
6974 }
7075
tests/mocks/Unity/CMakeLists.txt+1−1
@@ -6,7 +6,7 @@ add_subdirectory(Notifications)
66pkg_search_module(DEE dee-1.0 REQUIRED)
77pkg_search_module(GOBJECT gobject-2.0 REQUIRED)
88pkg_search_module(DEEQT libdee-qt5 REQUIRED)
9−pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=2)
9+pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=3)
1010
1111include_directories(
1212 ${CMAKE_CURRENT_BINARY_DIR}
tests/mocks/Unity/fake_scopes.cpp+5
@@ -125,6 +125,11 @@ bool Scopes::loaded() const
125125 return m_loaded;
126126}
127127
128+unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
129+{
130+ return nullptr;
131+}
132+
128133void Scopes::addScope(Scope* scope)
129134{
130135 int index = rowCount();
tests/mocks/Unity/fake_scopes.h+1
@@ -50,6 +50,7 @@ public:
5050 QModelIndex parent ( const QModelIndex & index ) const;
5151
5252 bool loaded() const override;
53+ unity::shell::scopes::ScopeInterface* overviewScope() const override;
5354
5455private Q_SLOTS:
5556 void updateScopes();
tests/qmltests/CMakeLists.txt+1−1
@@ -30,7 +30,6 @@ add_qml_test(Components Rating)
3030add_qml_test(Components ResponsiveFlowView)
3131add_qml_test(Components ResponsiveGridView)
3232add_qml_test(Components ResponsiveVerticalJournal IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)
33−add_qml_test(Components SeeMore)
3433add_qml_test(Components Showable)
3534add_qml_test(Components PageHeader)
3635add_qml_test(Components ZoomableImage)
@@ -44,6 +43,7 @@ add_qml_test(Dash/Apps RunningApplicationsGrid)
4443add_qml_test(Dash/Previews Preview)
4544add_qml_test(Dash/Previews PreviewActions)
4645add_qml_test(Dash/Previews PreviewAudioPlayback)
46+add_qml_test(Dash/Previews PreviewExpandable)
4747add_qml_test(Dash/Previews PreviewHeader)
4848add_qml_test(Dash/Previews PreviewImageGallery)
4949add_qml_test(Dash/Previews PreviewPayments)
tests/qmltests/Components/tst_SeeMore.qmldeleted−52
@@ -1,52 +0,0 @@
1−/*
2− * Copyright 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 QtTest 1.0
19−import Ubuntu.Components 0.1
20−import "../../../qml/Components"
21−import Unity.Test 0.1 as UT
22−
23−Rectangle {
24− id: root
25− width: units.gu(40)
26− height: units.gu(10)
27− color: Theme.palette.selected.background
28−
29− SeeMore {
30− id: seeMore
31− anchors.fill: parent
32− more: false
33− }
34−
35− UT.UnityTestCase {
36− name: "SeeMoreTest"
37− when: windowShown
38−
39− function test_interaction() {
40− var seeMoreLabel = findChild(seeMore, "seeMoreLabel")
41− var seeLessLabel = findChild(seeMore, "seeLessLabel")
42−
43− compare(seeMore.more, false)
44−
45− mouseClick(seeMoreLabel, seeMoreLabel.width / 2, seeMoreLabel.height / 2)
46− compare(seeMore.more, true)
47−
48− mouseClick(seeLessLabel, seeLessLabel.width / 2, seeLessLabel.height / 2)
49− compare(seeMore.more, false)
50− }
51− }
52−}
tests/qmltests/Dash/Previews/tst_PreviewTextSummary.qml+3−16
@@ -72,28 +72,15 @@ Rectangle {
7272 tryCompare(textLabel, "y", 0)
7373 }
7474
75− function test_see_more() {
76− var seeMore = findChild(previewTextSummary, "seeMore")
77−
75+ function test_show_collapsed() {
7876 // when it's more than textLabel.maximumCollapsedLineCount lines of text, show SeeMore component
7977 verify(textLabel.lineCount > textLabel.maximumCollapsedLineCount)
80− compare(seeMore.visible, true)
81− verify(seeMore.more === false)
82− verify(textLabel.height < textLabel.contentHeight)
8378
84− // test interactions with SeeMore
85− var seeMoreLabel = findChild(seeMore, "seeMoreLabel")
86− var seeLessLabel = findChild(seeMore, "seeLessLabel")
87− var initialTextLabelHeight = textLabel.height
88− mouseClick(seeMoreLabel, seeMoreLabel.width / 2, seeMoreLabel.height / 2)
89− tryCompare(textLabel, "height", textLabel.contentHeight)
90− mouseClick(seeLessLabel, seeLessLabel.width / 2, seeLessLabel.height / 2)
91− tryCompare(textLabel, "height", initialTextLabelHeight)
79+ previewTextSummary.expanded = false;
80+ tryCompareFunction(function() { return textLabel.height < textLabel.contentHeight; }, true)
9281
93− // text SeeMore automatic hiding
9482 previewTextSummary.widgetData = widgetDataShortText
9583 verify(textLabel.lineCount <= textLabel.maximumCollapsedLineCount)
96− compare(seeMore.visible, false)
9784 tryCompare(textLabel, "height", textLabel.contentHeight)
9885 tryCompare(previewTextSummary, "height", titleLabel.height + textLabel.height)
9986 }
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
@@ -77,6 +77,7 @@ Rectangle {
7777 return [
7878 { tag: "Actions", type: "actions", source: "PreviewActions.qml" },
7979 { tag: "Audio", type: "audio", source: "PreviewAudioPlayback.qml" },
80+ { tag: "Expandable", type: "expandable", source: "PreviewExpandable.qml" },
8081 { tag: "Gallery", type: "gallery", source: "PreviewImageGallery.qml" },
8182 { tag: "Header", type: "header", source: "PreviewHeader.qml" },
8283 { tag: "Image", type: "image", source: "PreviewZoomableImage.qml" },