on a142f21 help sign in
unity8/plugins/Dash/organicgrid.h
95 lines 3.0 kB history raw
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 */
17#ifndef ORGANICGRID_H
18#define ORGANICGRID_H
20#include "abstractdashview.h"
22 /** An Organic Grid is is a view that creates delegates
23 * based on a model and layouts them in groups of six items (called module).
24 *
25 * In each module there are 4 items that are forced to the small delegate size
26 * and two that are forced to the big delegate size.
27 *
28 * Example:
29 *
30 * +---+ +---+ +-----+
31 * | 1 | | 2 | | |
32 * +---+ +---+ | 5 |
33 * +-----+ | |
34 * | | +-----+
35 * | 3 | +---+ +---+
36 * | | | 4 | | 6 |
37 * +-----+ +---+ +---+
38 *
39 * Modules are positioned one after the other in a grid like fashion, i.e.
40 *
41 * +---+ +---+
42 * | 1 | | 2 |
43 * +---+ +---+
44 * +---+ +---+
45 * | 3 | | 4 |
46 * +---+ +---+
47 */
49class OrganicGrid : public AbstractDashView
51 Q_OBJECT
53 Q_PROPERTY(QSizeF smallDelegateSize READ smallDelegateSize WRITE setSmallDelegateSize NOTIFY smallDelegateSizeChanged)
54 Q_PROPERTY(QSizeF bigDelegateSize READ bigDelegateSize WRITE setBigDelegateSize NOTIFY bigDelegateSizeChanged)
56friend class OrganicGridTest;
58public:
59 OrganicGrid();
61 QSizeF smallDelegateSize() const;
62 void setSmallDelegateSize(const QSizeF &size);
64 QSizeF bigDelegateSize() const;
65 void setBigDelegateSize(const QSizeF &size);
67Q_SIGNALS:
68 void smallDelegateSizeChanged();
69 void bigDelegateSizeChanged();
70private:
71 QPointF positionForIndex(int modelIndex) const;
72 QSizeF sizeForIndex(int modelIndex) const;
74 void findBottomModelIndexToAdd(int *modelIndex, qreal *yPos) override;
75 void findTopModelIndexToAdd(int *modelIndex, qreal *yPos) override;
76 void addItemToView(int modelIndex, QQuickItem *item) override;
77 bool removeNonVisibleItems(qreal bufferFromY, qreal bufferToY) override;
78 void cleanupExistingItems() override;
79 void doRelayout() override;
80 void updateItemCulling(qreal visibleFromY, qreal visibleToY) override;
81 void calculateImplicitHeight() override;
82#if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0))
83 void processModelRemoves(const QVector<QQmlChangeSet::Remove> &removes) override;
84#else
85 void processModelRemoves(const QVector<QQmlChangeSet::Change> &removes) override;
86#endif
88 QSizeF m_smallDelegateSize;
89 QSizeF m_bigDelegateSize;
90 int m_firstVisibleIndex;
91 int m_numberOfModulesPerRow;
92 QList<QQuickItem*> m_visibleItems;
93};
95#endif