on 551c708 help sign in
unity8/plugins/DashViews/verticaljournal.h
104 lines 3.5 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);
68Q_SIGNALS:
69 void columnWidthChanged();
71private:
72 class ViewItem
73 {
74 public:
75 ViewItem(QQuickItem *item, int modelIndex) : m_item(item), m_modelIndex(modelIndex) {}
76 qreal x() const { return m_item->x(); }
77 qreal y() const { return m_item->y(); }
78 qreal height() const { return m_item->height(); }
79 bool operator<(const ViewItem &v) const { return m_modelIndex < v.m_modelIndex; }
81 QQuickItem *m_item;
82 int m_modelIndex;
83 };
85 void findBottomModelIndexToAdd(int *modelIndex, qreal *yPos) override;
86 void findTopModelIndexToAdd(int *modelIndex, qreal *yPos) override;
87 bool removeNonVisibleItems(qreal bufferFromY, qreal bufferToY) override;
88 void addItemToView(int modelIndex, QQuickItem *item) override;
89 void cleanupExistingItems() override;
90 void calculateImplicitHeight() override;
91 void doRelayout() override;
92 void updateItemCulling(qreal visibleFromY, qreal visibleToY) override;
93#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
94 void processModelRemoves(const QVector<QQuickChangeSet::Remove> &removes) override;
95#else
96 void processModelRemoves(const QVector<QQmlChangeSet::Remove> &removes) override;
97#endif
99 QVector<QList<ViewItem>> m_columnVisibleItems;
100 QHash<int, int> m_indexColumnMap;
101 int m_columnWidth;
102};
104#endif