MauiKit Controls

CollageItem.qml
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QtQuick.Effects
6
7import org.mauikit.controls 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: true
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: GraphicsInfo.api !== GraphicsInfo.Software && control.maskRadius > 0
124 layer.effect: MultiEffect
125 {
126 maskEnabled: true
127 maskThresholdMin: 0.5
128 maskSpreadAtMin: 1.0
129 maskSpreadAtMax: 0.0
130 maskThresholdMax: 1.0
131 maskSource: ShaderEffectSource
132 {
133 sourceItem: Rectangle
134 {
135 x: _collageLayout.x
136 y: _collageLayout.y
137 width: _collageLayout.width
138 height: _collageLayout.height
139 radius: control.maskRadius
140 }
141 }
142 }
143 }
144 }
145
146 function randomHexColor()
147 {
148 var color = '#', i = 5;
149 do{ color += "0123456789abcdef".substr(Math.random() * 16,1); }while(i--);
150 return color;
151 }
152
153 function spanColumn(index, count)
154 {
155 if(index === 0)
156 {
157 return 3;
158 }
159
160 if(count === 2 || count === 3)
161 {
162 return 3;
163 }
164
165 return 1;
166 }
167 }
168}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:16:12 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.