Changeset View
Changeset View
Standalone View
Standalone View
src/controls/CardsGridView.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.6 | ||||
21 | import QtQuick.Controls 2.0 as Controls | ||||
22 | import QtQuick.Layouts 1.2 | ||||
23 | import org.kde.kirigami 2.3 as Kirigami | ||||
24 | | ||||
25 | /** | ||||
26 | * CardsGridView is used to display a grid of Cards generated from any model. | ||||
27 | * The behavior is same as CardsLayout, and it allowes cards to be put in one or two | ||||
28 | * columns depending from the available width. | ||||
29 | * GridView has the limitation that every Card must have the same exact height, | ||||
30 | * so cellHeight must be manually set to a value in which the content fits | ||||
31 | * for every item. | ||||
32 | * If possible use cards only when you don't need to instantiate a lot | ||||
33 | * and use CardsLayout intead. | ||||
34 | * @inherits GridView | ||||
35 | * @see CardsLayout | ||||
36 | * @since 2.4 | ||||
37 | */ | ||||
38 | GridView { | ||||
39 | id: root | ||||
40 | | ||||
41 | /** | ||||
42 | * maximumColumnWidth: int | ||||
43 | * The maximum width the columns may have. the cards will never | ||||
44 | * get wider than this size, when the GridView is wider than | ||||
45 | * maximumColumnWidth, it will switch from one to two columns. | ||||
46 | * If the default needs to be overridden for some reason, | ||||
47 | * it is advised to express this unit as a multiple | ||||
48 | * of Kirigami.Units.gridUnit | ||||
49 | */ | ||||
50 | property int maximumColumnWidth: Kirigami.Units.gridUnit * 20 | ||||
51 | cellWidth: width > maximumColumnWidth ? width/2 : width | ||||
52 | cellHeight: Math.max(Kirigami.Units.gridUnit * 15, Math.min(cellWidth, maximumColumnWidth) / 1.2) | ||||
53 | | ||||
54 | topMargin: Kirigami.Units.largeSpacing * 2 | ||||
55 | } |