on 19a9ecd help sign in
unity8/plugins/Dash/verticaljournal.h
103 lines 3.4 kB history raw
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 */
17#ifndef VERTICALJOURNAL_H
18#define VERTICALJOURNAL_H
20#include "abstractdashview.h"
22 /** A vertical journal is a view that creates delegates
23 * based on a model and layouts them in columns following
24 * a top-left most position rule.
25 *
26 * The number of columns is calculated using the width of
27 * the view itself, the columnWidth (i.e. the width of each individual delegate)
28 * and the columnSpacing between columns.
29 *
30 * All delegates are forced to columnWidth if they don't have it.
31 *
32 * The first nColumns items are layouted at row 0 from column 0
33 * to column nColumns-1 in order. After that every new item
34 * is positioned in the column which provides the free topmost
35 * position as possible. If more than one column tie in providing
36 * the topmost free position the leftmost column will be used.
37 *
38 * Example:
39 *
40 * +-----+ +-----+ +-----+
41 * | | | 2 | | |
42 * | | | | | |
43 * | 1 | +-----+ | 3 |
44 * | | +-----+ | |
45 * | | | | +-----+
46 * +-----+ | 4 | +-----+
47 * +-----+ | | | 5 |
48 * | 6 | +-----+ | |
49 * | | +-----+
50 * +-----+
51 *
52 */
54class VerticalJournal : public AbstractDashView
56 Q_OBJECT
58 Q_PROPERTY(qreal columnWidth READ columnWidth WRITE setColumnWidth NOTIFY columnWidthChanged)
60friend class VerticalJournalTest;
62public:
63 VerticalJournal();
65 qreal columnWidth() const;
66 void setColumnWidth(qreal columnWidth);
68protected:
69 void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) override;
71Q_SIGNALS:
72 void columnWidthChanged();
74private:
75 class ViewItem
76 {
77 public:
78 ViewItem(QQuickItem *item, int modelIndex) : m_item(item), m_modelIndex(modelIndex) {}
79 qreal x() const { return m_item->x(); }
80 qreal y() const { return m_item->y(); }
81 qreal height() const { return m_item->height(); }
82 bool operator<(const ViewItem v) const { return m_modelIndex < v.m_modelIndex; }
84 QQuickItem *m_item;
85 int m_modelIndex;
86 };
88 void findBottomModelIndexToAdd(int *modelIndex, qreal *yPos) override;
89 void findTopModelIndexToAdd(int *modelIndex, qreal *yPos) override;
90 bool removeNonVisibleItems(qreal bufferFromY, qreal bufferToY) override;
91 void addItemToView(int modelIndex, QQuickItem *item) override;
92 void cleanupExistingItems() override;
93 void calculateImplicitHeight() override;
94 void doRelayout() override;
95 void updateItemCulling(qreal visibleFromY, qreal visibleToY) override;
96 void processModelRemoves(const QVector<QQmlChangeSet::Change> &removes) override;
98 QVector<QList<ViewItem>> m_columnVisibleItems;
99 QHash<int, int> m_indexColumnMap;
100 int m_columnWidth;
101};
103#endif