Changeset View
Changeset View
Standalone View
Standalone View
src/controls/CardsListView.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 | * CardsListView is a ListView which can have AbstractCard as its delegete: it will | ||||
27 | * automatically assign the proper spacings and margins around the cards adhering | ||||
28 | * to the design guidelines. | ||||
29 | * CardsListView should be used only with cards which can look good at any | ||||
30 | * horizontal size, so It is recommended to use directly AbstractCard with an | ||||
31 | * appropriate layout inside, because they are stretching for the whole list width. | ||||
32 | * Therefore is discouraged to use it with the Card type, unless it has | ||||
33 | * Horizontal as headerOrientation. | ||||
34 | * The choice between using this view with AbstractCard or a normal ListView | ||||
35 | * with AbstractListItem/BasicListItem is purely a choice based on aestetics alone. | ||||
36 | * It is discouraged to tweak the properties of this ListView. | ||||
37 | * @inherits ListView | ||||
38 | * @since 2.4 | ||||
39 | */ | ||||
40 | ListView { | ||||
41 | id: root | ||||
42 | spacing: Kirigami.Units.largeSpacing * 2 | ||||
43 | topMargin: headerPositioning != ListView.InlineHeader ? spacing : 0 | ||||
44 | | ||||
45 | headerPositioning: ListView.OverlayHeader | ||||
46 | | ||||
47 | onContentHeightChanged: { | ||||
48 | var item = contentItem.children[0]; | ||||
49 | if (item && !item.hasOwnProperty("header") && !item.hasOwnProperty("_contentItem")) { | ||||
50 | print("Warning: only AbstractCard items are supported in CardsListView") | ||||
51 | } | ||||
52 | } | ||||
53 | } |