Warning, /maui/mauikit/src/controls.6/CollageItem.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 0002 import QtQuick.Controls 0003 import QtQuick.Layouts 0004 0005 import Qt5Compat.GraphicalEffects 0006 0007 import org.mauikit.controls 1.3 as Maui 0008 0009 /** 0010 * @inherit GridBrowserDelegate 0011 * @since org.mauikit.controls 1.0 0012 * @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. 0013 * 0014 * This control inherits all properties from the MauiKit GridBrowserDelegate control. 0015 * 0016 * @image html Delegates/collageitem.png "As delegate with a vary number of images" 0017 * @code 0018 * Maui.GridBrowser 0019 * { 0020 * anchors.fill: parent 0021 * model: 30 0022 * 0023 * itemSize: 200 0024 * 0025 * delegate: Item 0026 * { 0027 * width: GridView.view.cellWidth 0028 * height: GridView.view.cellHeight 0029 * 0030 * Maui.CollageItem 0031 * { 0032 * anchors.fill: parent 0033 * anchors.margins: Maui.Style.space.small 0034 * 0035 * label1.text: "Demo" 0036 * label2.text: index 0037 * 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'] 0038 * } 0039 * } 0040 * } 0041 * @endcode 0042 * 0043 * <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> 0044 * 0045 */ 0046 Maui.GridBrowserDelegate 0047 { 0048 id: control 0049 0050 maskRadius: radius 0051 0052 fillMode: Image.PreserveAspectCrop 0053 0054 /** 0055 * @brief A list of images to be used. The maximum value that should be displayed is 4. 0056 */ 0057 property var images : [] 0058 0059 /** 0060 * @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. 0061 * 0062 * 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. 0063 * @code 0064 * images: ["page1", "page2", "page3"] 0065 * cb : (source) => 0066 * { 0067 * return mapSourceToImageFile(source) //here the "page1" could be mapped to "file:///some/path/to/image1.jpg" and return this new source to be use. 0068 * } 0069 * @endcode 0070 */ 0071 property var cb 0072 0073 label1.font.weight: Font.DemiBold 0074 label1.font.pointSize: Maui.Style.fontSizes.big 0075 0076 template.labelSizeHint: 32 0077 template.alignment: Qt.AlignLeft 0078 0079 template.iconComponent: Item 0080 { 0081 id: _collageLayout 0082 0083 Loader 0084 { 0085 asynchronous: true 0086 anchors.fill: parent 0087 0088 sourceComponent: GridLayout 0089 { 0090 columns: 3 0091 rows: 2 0092 columnSpacing: 2 0093 rowSpacing: 2 0094 0095 Repeater 0096 { 0097 id: _repeater 0098 model: control.images 0099 0100 delegate: Rectangle 0101 { 0102 Layout.fillHeight: true 0103 Layout.fillWidth: true 0104 Layout.maximumHeight: index === 0 ? control.height : control.height * 0.3 0105 Layout.columnSpan: spanColumn(index, _repeater.count) 0106 Layout.rowSpan: 1 0107 color: Qt.rgba(0,0,0,0.3) 0108 0109 Image 0110 { 0111 anchors.fill: parent 0112 sourceSize.width: control.imageWidth >= 0 ? control.imageWidth : width 0113 sourceSize.height: control.imageHeight >= 0 ? control.imageHeight : height 0114 cache: true 0115 asynchronous: true 0116 source: control.cb ? control.cb(modelData) : modelData 0117 fillMode: control.fillMode 0118 } 0119 } 0120 } 0121 0122 layer.enabled: control.maskRadius 0123 layer.effect: OpacityMask 0124 { 0125 maskSource: Rectangle 0126 { 0127 width: _collageLayout.width 0128 height: _collageLayout.height 0129 radius: control.maskRadius 0130 } 0131 } 0132 } 0133 } 0134 0135 function randomHexColor() 0136 { 0137 var color = '#', i = 5; 0138 do{ color += "0123456789abcdef".substr(Math.random() * 16,1); }while(i--); 0139 return color; 0140 } 0141 0142 function spanColumn(index, count) 0143 { 0144 if(index === 0) 0145 { 0146 return 3; 0147 } 0148 0149 if(count === 2 || count === 3) 0150 { 0151 return 3; 0152 } 0153 0154 return 1; 0155 } 0156 } 0157 }