on xenial help sign in
First quick unfinished stab at the category expansion
commita6d169ba23a0f923752f0b02b447a98e8c8b2211 authorAlbert Astals <albert.astals@canonical.com> dateFri 2 Aug 2013, 16:44 (13 years ago) parent6554dea
10 files changed+64−93
Components/FilterGrid.qml+1−59 Components/ListItems/Header.qml+7 Dash/Apps/ApplicationsFilterGrid.qml−2 Dash/DashApps.qml+12−13 Dash/Music/MusicFilterGrid.qml−1 Dash/Video/VideosFilterGrid.qml−1 plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+34−10 plugins/ListViewWithPageHeader/listviewwithpageheader.h+4−1 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+3−3 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+3−3
Components/FilterGrid.qml+1−59
@@ -35,7 +35,7 @@ Item {
3535
3636 /* Whether, when collapsed, a button should be displayed enabling the user to expand
3737 the grid to its full size. */
38− property bool expandable: true
38+ readonly property bool expandable: model.count > collapsedRowCount * iconTileGrid.columns
3939
4040 property var model: null
4141
@@ -76,62 +76,4 @@ Item {
7676 }
7777
7878 }
79−
80− Item {
81− anchors {
82− left: parent.left
83− right: parent.right
84− top: iconTileGrid.bottom
85− }
86− visible: (expandable && filter && model.count > collapsedRowCount * iconTileGrid.columns)
87− height: (visible) ? childrenRect.height + units.gu(2) : 0
88−
89− AbstractButton {
90− id: button
91− objectName: "filterToggleButton"
92−
93− anchors {
94− top: parent.top
95− horizontalCenter: parent.horizontalCenter
96− }
97− width: units.gu(22)
98− height: units.gu(4)
99−
100− UbuntuShape {
101− anchors.fill: parent
102− color: "#33ffffff" // FIXME no palette
103− radius: "small"
104− }
105−
106− UbuntuShape {
107− id: borderPressed
108−
109− anchors.fill: parent
110− radius: "small"
111− borderSource: "radius_pressed.sci"
112− opacity: button.pressed ? 1.0 : 0.0
113− Behavior on opacity { NumberAnimation { duration: 200; easing.type: Easing.OutQuint } }
114− }
115−
116− Label {
117− anchors {
118− verticalCenter: parent.verticalCenter
119− left: parent.left
120− right: parent.right
121− leftMargin: units.gu(1)
122− rightMargin: units.gu(1)
123− }
124− text: (filter) ? "+ View all (" + model.count + ")" : "- Show fewer"
125− fontSize: "small"
126− color: Theme.palette.selected.backgroundText
127− opacity: 0.6
128− style: Text.Raised
129− styleColor: "black"
130− elide: Text.ElideMiddle
131− horizontalAlignment: Text.AlignHCenter
132− }
133−
134− onClicked: filter = !filter
135− }
136− }
13779}
Components/ListItems/Header.qml+7
@@ -25,6 +25,8 @@ Item {
2525 */
2626 property alias text: label.text
2727
28+ signal clicked(variant mouse)
29+
2830 height: units.gu(4.5)
2931
3032 Item {
@@ -64,4 +66,9 @@ Item {
6466 bottom: parent.bottom
6567 }
6668 }
69+
70+ MouseArea {
71+ anchors.fill: parent
72+ onClicked: parent.clicked(mouse)
73+ }
6774}
Dash/Apps/ApplicationsFilterGrid.qml−2
@@ -22,8 +22,6 @@ import "../../Components/IconUtil.js" as IconUtil
2222FilterGrid {
2323 id: filterGrid
2424
25− filter: false
26− expandable: false
2725 minimumHorizontalSpacing: units.gu(0.5)
2826 maximumNumberOfColumns: 6
2927 delegateWidth: units.gu(11)
Dash/DashApps.qml+12−13
@@ -117,8 +117,13 @@ ScopeView {
117117 delegate: Base {
118118 id: container
119119 highlightWhenPressed: false
120+ property var loader: loader
121+ // Needed because of the GridView.onRemove anim in Tile.qml
122+ // TODO see how can we do away without the clip (i.e. not run the animation if we are collapsing)
123+ clip: true
120124
121125 Loader {
126+ id: loader
122127 anchors {
123128 top: parent.top
124129 left: parent.left
@@ -142,25 +147,19 @@ ScopeView {
142147 }
143148 }
144149 }
145−
146− ListView.onRemove: SequentialAnimation {
147− PropertyAction {
148− target: container; property: "ListView.delayRemove"; value: true
149− }
150− NumberAnimation {
151− target: container; property: "height"; to: 0;
152− duration: 250; easing.type: Easing.InOutQuad
153− }
154− PropertyAction {
155− target: container; property: "ListView.delayRemove"; value: false
156− }
157− }
158150 }
159151
160152 sectionProperty: "category"
161153 sectionDelegate: Header {
162154 width: categoryView.width
163155 text: categoryListModel.getCategory(section)
156+ onClicked: {
157+ var obj = categoryView.item(delegateIndex)
158+ if (obj && obj.loader.item.expandable) {
159+ obj.loader.item.filter = !obj.loader.item.filter
160+ categoryView.maximizeVisibleArea(delegateIndex);
161+ }
162+ }
164163 }
165164 pageHeader: PageHeader {
166165 id: pageHeader
Dash/Music/MusicFilterGrid.qml−1
@@ -20,7 +20,6 @@ import "../../Components"
2020FilterGrid {
2121 id: filterGrid
2222
23− expandable: false
2423 minimumHorizontalSpacing: units.gu(2)
2524 maximumNumberOfColumns: 5
2625 delegateWidth: units.gu(17)
Dash/Video/VideosFilterGrid.qml−1
@@ -20,7 +20,6 @@ import "../../Components"
2020FilterGrid {
2121 id: filtergrid
2222
23− expandable: false
2423 minimumHorizontalSpacing: units.gu(0.5)
2524 maximumNumberOfColumns: 5
2625 delegateWidth: units.gu(11)
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+34−10
@@ -160,16 +160,16 @@ ListViewWithPageHeader::ListViewWithPageHeader()
160160// m_clipItem = new QQuickRectangle(contentItem());
161161// ((QQuickRectangle*)m_clipItem)->setColor(Qt::gray);
162162
163− m_headerShowAnimation = new QQuickNumberAnimation(this);
164− m_headerShowAnimation->setEasing(QEasingCurve::OutQuad);
165− m_headerShowAnimation->setProperty("contentY");
166− m_headerShowAnimation->setDuration(200);
167− m_headerShowAnimation->setTargetObject(this);
163+ m_contentYAnimation = new QQuickNumberAnimation(this);
164+ m_contentYAnimation->setEasing(QEasingCurve::OutQuad);
165+ m_contentYAnimation->setProperty("contentY");
166+ m_contentYAnimation->setDuration(200);
167+ m_contentYAnimation->setTargetObject(this);
168168
169169 connect(this, SIGNAL(contentWidthChanged()), this, SLOT(onContentWidthChanged()));
170170 connect(this, SIGNAL(contentHeightChanged()), this, SLOT(onContentHeightChanged()));
171171 connect(this, SIGNAL(heightChanged()), this, SLOT(onHeightChanged()));
172− connect(m_headerShowAnimation, SIGNAL(stopped()), this, SLOT(onShowHeaderAnimationFinished()));
172+ connect(m_contentYAnimation, SIGNAL(stopped()), this, SLOT(onShowHeaderAnimationFinished()));
173173}
174174
175175ListViewWithPageHeader::~ListViewWithPageHeader()
@@ -374,8 +374,32 @@ void ListViewWithPageHeader::showHeader()
374374 layout();
375375 }
376376 }
377− m_headerShowAnimation->setTo(to);
378− m_headerShowAnimation->start();
377+ m_contentYAnimation->setTo(to);
378+ contentYAnimationIsShownHeader = true;
379+ m_contentYAnimation->start();
380+ }
381+}
382+
383+QQuickItem *ListViewWithPageHeader::item(int modelIndex) const
384+{
385+ ListItem *item = itemAtIndex(modelIndex);
386+ if (item)
387+ return item->m_item;
388+ else
389+ return nullptr;
390+}
391+
392+void ListViewWithPageHeader::maximizeVisibleArea(int modelIndex)
393+{
394+ ListItem *listItem = itemAtIndex(modelIndex);
395+ if (listItem)
396+ {
397+ // Check if we can scroll the list up to show more stuff
398+ if (m_clipItem->y() + listItem->y() > contentY() && m_clipItem->y() + listItem->y() + listItem->height() > contentY() + height()) {
399+ m_contentYAnimation->setTo(m_clipItem->y() + listItem->y());
400+ contentYAnimationIsShownHeader = false;
401+ m_contentYAnimation->start();
402+ }
379403 }
380404}
381405
@@ -435,7 +459,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
435459 // We will be changing the clip item, need to accomadate for it
436460 // otherwise we move the firstItem down/up twice (unless the
437461 // show header animation is running, where we want to keep the viewport stable)
438− if (!m_headerShowAnimation->isRunning()) {
462+ if (!(m_contentYAnimation->isRunning() && contentYAnimationIsShownHeader)) {
439463 diff += oldHeaderItemShownHeight - m_headerItemShownHeight;
440464 } else {
441465 diff = -diff;
@@ -445,7 +469,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
445469 updateClipItem();
446470 ListItem *firstItem = m_visibleItems.first();
447471 firstItem->setY(firstItem->y() + diff);
448− if (m_headerShowAnimation->isRunning()) {
472+ if (m_contentYAnimation->isRunning() && contentYAnimationIsShownHeader) {
449473 adjustMinYExtent();
450474 }
451475 }
plugins/ListViewWithPageHeader/listviewwithpageheader.h+4−1
@@ -88,6 +88,8 @@ public:
8888
8989 Q_INVOKABLE void positionAtBeginning();
9090 Q_INVOKABLE void showHeader();
91+ Q_INVOKABLE QQuickItem *item(int modelIndex) const;
92+ Q_INVOKABLE void maximizeVisibleArea(int modelIndex);
9193
9294Q_SIGNALS:
9395 void modelChanged();
@@ -182,7 +184,8 @@ private:
182184 qreal m_previousContentY;
183185 qreal m_headerItemShownHeight; // The height of header shown when the header is shown outside its topmost position
184186 // i.e. it's being shown after dragging down in the middle of the list
185− QQuickNumberAnimation *m_headerShowAnimation;
187+ bool contentYAnimationIsShownHeader;
188+ QQuickNumberAnimation *m_contentYAnimation;
186189
187190 QQmlComponent *m_sectionDelegate;
188191 QString m_sectionProperty;
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+3−3
@@ -1245,7 +1245,7 @@ private Q_SLOTS:
12451245
12461246 lvwph->showHeader();
12471247
1248− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1248+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
12491249 QTRY_COMPARE(lvwph->m_visibleItems.count(), 5);
12501250 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
12511251 verifyItem(0, -375., 150., true);
@@ -1301,7 +1301,7 @@ private Q_SLOTS:
13011301
13021302 lvwph->showHeader();
13031303
1304− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1304+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
13051305 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
13061306 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
13071307 verifyItem(0, -20., 150., false);
@@ -1339,7 +1339,7 @@ private Q_SLOTS:
13391339
13401340 lvwph->showHeader();
13411341
1342− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1342+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
13431343 QTRY_VERIFY (lvwph->isAtYEnd());
13441344 }
13451345
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+3−3
@@ -1506,7 +1506,7 @@ private Q_SLOTS:
15061506
15071507 lvwph->showHeader();
15081508
1509− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1509+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
15101510 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
15111511 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
15121512 verifyItem(0, -20., 190., false, "Agressive", true);
@@ -1565,7 +1565,7 @@ private Q_SLOTS:
15651565
15661566 lvwph->showHeader();
15671567
1568− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1568+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
15691569 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
15701570 QCOMPARE(lvwph->m_firstVisibleIndex, 0);
15711571 verifyItem(0, -375., 190., true, "Agressive", true);
@@ -1607,7 +1607,7 @@ private Q_SLOTS:
16071607
16081608 lvwph->showHeader();
16091609
1610− QTRY_VERIFY(!lvwph->m_headerShowAnimation->isRunning());
1610+ QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
16111611 QTRY_VERIFY (lvwph->isAtYEnd());
16121612 }
16131613