MauiKit Controls

CollageItem.qml
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import Qt5Compat.GraphicalEffects
6
7import org.mauikit.controls 1.3 as Maui
8
9/**
10 * @inherit GridBrowserDelegate
11 * @since org.mauikit.controls 1.0
12 * @brief A custom item to be used as a delegate in the browsing views or as a standalone card. This element presents a group of images in a vignette-form.
13 *
14 * This control inherits all properties from the MauiKit GridBrowserDelegate control.
15 *
16 * @image html Delegates/collageitem.png "As delegate with a vary number of images"
17 * @code
18 * Maui.GridBrowser
19 * {
20 * anchors.fill: parent
21 * model: 30
22 *
23 * itemSize: 200
24 *
25 * delegate: Item
26 * {
27 * width: GridView.view.cellWidth
28 * height: GridView.view.cellHeight
29 *
30 * Maui.CollageItem
31 * {
32 * anchors.fill: parent
33 * anchors.margins: Maui.Style.space.small
34 *
35 * label1.text: "Demo"
36 * label2.text: index
37 * images: index %2 === 0 ? ['/home/camiloh/Downloads/street-1234360.jpg', '/home/camiloh/Downloads/flat-coated-retriever-1339154.jpg', '/home/camiloh/Downloads/5911329.jpeg'] : ['/home/camiloh/Downloads/street-1234360.jpg', '/home/camiloh/Downloads/flat-coated-retriever-1339154.jpg', '/home/camiloh/Downloads/5911329.jpeg', '/home/camiloh/Pictures/LastLights_by_Mushcube/LastLightsScreenPreview.png']
38 * }
39 * }
40 * }
41 * @endcode
42 *
43 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/CollageItem.qml">You can find a more complete example at this link.</a>
44 *
45 */
46Maui.GridBrowserDelegate
47{
48 id: control
49
50 maskRadius: radius
51
52 fillMode: Image.PreserveAspectCrop
53
54 /**
55 * @brief A list of images to be used. The maximum value that should be displayed is 4.
56 */
57 property var images : []
58
59 /**
60 * @brief A callback function to manage what image is positioned. This callback function is called for each image source set in the model `images`, so the final source can be modified. This function should return a - new or modified - image source URL.
61 *
62 * As an example, if the `images` model looks like: `["page1", "page2", "page3"]` - which are not file URLs, this callback function can be use to map each individual source to an actual file URL.
63 * @code
64 * images: ["page1", "page2", "page3"]
65 * cb : (source) =>
66 * {
67 * return mapSourceToImageFile(source) //here the "page1" could be mapped to "file:///some/path/to/image1.jpg" and return this new source to be use.
68 * }
69 * @endcode
70 */
71 property var cb
72
73 label1.font.weight: Font.DemiBold
74 label1.font.pointSize: Maui.Style.fontSizes.big
75
76 template.labelSizeHint: 32
77 template.alignment: Qt.AlignLeft
78
79 template.iconComponent: Item
80 {
81 id: _collageLayout
82
83 Loader
84 {
85 asynchronous: true
86 anchors.fill: parent
87
88 sourceComponent: GridLayout
89 {
90 columns: 3
91 rows: 2
92 columnSpacing: 2
93 rowSpacing: 2
94
95 Repeater
96 {
97 id: _repeater
98 model: control.images
99
100 delegate: Rectangle
101 {
102 Layout.fillHeight: true
103 Layout.fillWidth: true
104 Layout.maximumHeight: index === 0 ? control.height : control.height * 0.3
105 Layout.columnSpan: spanColumn(index, _repeater.count)
106 Layout.rowSpan: 1
107 color: Qt.rgba(0,0,0,0.3)
108
109 Image
110 {
111 anchors.fill: parent
112 sourceSize.width: control.imageWidth >= 0 ? control.imageWidth : width
113 sourceSize.height: control.imageHeight >= 0 ? control.imageHeight : height
114 cache: !Maui.Handy.isMobile
115 smooth: !Maui.Handy.isMobile
116 asynchronous: true
117 source: control.cb ? control.cb(modelData) : modelData
118 fillMode: control.fillMode
119 }
120 }
121 }
122
123 layer.enabled: control.maskRadius
124 layer.effect: OpacityMask
125 {
126 maskSource: Rectangle
127 {
128 width: _collageLayout.width
129 height: _collageLayout.height
130 radius: control.maskRadius
131 }
132 }
133 }
134 }
135
136 function randomHexColor()
137 {
138 var color = '#', i = 5;
139 do{ color += "0123456789abcdef".substr(Math.random() * 16,1); }while(i--);
140 return color;
141 }
142
143 function spanColumn(index, count)
144 {
145 if(index === 0)
146 {
147 return 3;
148 }
149
150 if(count === 2 || count === 3)
151 {
152 return 3;
153 }
154
155 return 1;
156 }
157 }
158}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.