Warning, /maui/mauikit/src/controls.6/GalleryRollTemplate.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 0002 import QtQuick.Controls 0003 0004 import org.mauikit.controls 1.3 as Maui 0005 import Qt5Compat.GraphicalEffects 0006 0007 /** 0008 * @inherit ShadowedRectangle 0009 * @brief A template control to display images in a carousel form. This element is use with the GalleryRollItem to display the images, so consider using that control instead of this one. 0010 * 0011 * This control inherits all properties from the MauiKit ShadowedRectangle control. Thus, the corners radius can be modified individually, and a drop shadow can be added, using the `corners` and `shadow` properties respectively. 0012 * 0013 * The transition of the images can be set as vertical or horizontal using the `orientation` property, and the transition time is picked randomly. 0014 * @see orientation 0015 * 0016 * @note If not images are set, then the area is filled with a solid color block. This color can be changed using the `color` property. 0017 */ 0018 Maui.ShadowedRectangle 0019 { 0020 id: control 0021 0022 color: "#333" 0023 0024 /** 0025 * @brief Whether the images in the carousel can be flicked with touch gestures. 0026 * @property bool GalleryRollTemplate::interactive 0027 */ 0028 property alias interactive : _featuredRoll.interactive 0029 0030 /** 0031 * @brief The orientation of the transition of the images. 0032 * By default this is set to `ListView.Horizontal`. 0033 * The possible values are: 0034 * - ListView.Horizontal 0035 * - ListView.Vertical 0036 * @property enum GalleryRollTemplate::orientation. 0037 */ 0038 property alias orientation : _featuredRoll.orientation 0039 0040 /** 0041 * @brief Whether the images should be saved in cache memory to save loading time. 0042 * By default this is set to `true`. 0043 */ 0044 property bool cache : true 0045 0046 /** 0047 * @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. 0048 * 0049 * 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. 0050 * @code 0051 * images: ["page1", "page2", "page3"] 0052 * cb : (source) => 0053 * { 0054 * return mapSourceToImageFile(source) //here the "page1" could be mapped to "file:///some/path/to/image1.jpg" and return this new source to be use. 0055 * } 0056 * @endcode 0057 */ 0058 property var cb 0059 0060 /** 0061 * @brief A list of images to be used. This will be use as the model. 0062 */ 0063 property var images : [] 0064 0065 /** 0066 * @brief The border radius of the images. 0067 * By default this is set to `0`. 0068 */ 0069 radius : 0 0070 0071 /** 0072 * @brief The fill mode of the images. To see possible values refer to the QQC2 Image documentation form Qt. 0073 * By default this is set to `Image.PreserveAspectCrop`. 0074 */ 0075 property int fillMode: Image.PreserveAspectCrop 0076 0077 /** 0078 * @brief Checks and sets whether the transition animation is running or not. 0079 * @property bool GalleryRollTemplate::running 0080 */ 0081 property alias running: _featuredTimer.running 0082 0083 /** 0084 * @brief Sets the painted width size of the image. 0085 * @note If the image has a big resolution it will take longer to load, so make it faster set this property to a lower value. 0086 * 0087 * By default this is set to `-1`, which means that the image will be painted using the full image resolution. 0088 * This is the same as setting the QQC2 Image `sourceSize.width` property. 0089 */ 0090 property int imageWidth : -1 0091 0092 /** 0093 * @brief Sets the painted height size of the image. 0094 * @note If the image has a big resolution it will take longer to load, so make it faster set this property to a lower value. 0095 * 0096 * By default this is set to `-1`, which means that the image will be painted using the full image resolution. 0097 * This is the same as setting the QQC2 Image `sourceSize.height` property. 0098 */ 0099 property int imageHeight : -1 0100 0101 corners 0102 { 0103 topLeftRadius: control.radius 0104 topRightRadius: control.radius 0105 bottomLeftRadius: control.radius 0106 bottomRightRadius: control.radius 0107 } 0108 0109 ListView 0110 { 0111 id: _featuredRoll 0112 anchors.fill: parent 0113 0114 interactive: false 0115 orientation: Qt.Horizontal 0116 snapMode: ListView.SnapOneItem 0117 clip: true 0118 0119 boundsBehavior: Flickable.StopAtBounds 0120 boundsMovement: Flickable.StopAtBounds 0121 0122 model: control.images 0123 0124 Component.onCompleted: _featuredTimer.start() 0125 0126 Timer 0127 { 0128 id: _featuredTimer 0129 interval: _featuredRoll.randomInteger(6000, 8000) 0130 repeat: true 0131 onTriggered: _featuredRoll.cycleSlideForward() 0132 } 0133 0134 function cycleSlideForward() 0135 { 0136 if(_featuredRoll.dragging) 0137 { 0138 return 0139 } 0140 0141 if (_featuredRoll.currentIndex === _featuredRoll.count - 1) 0142 { 0143 _featuredRoll.currentIndex = 0 0144 } else 0145 { 0146 _featuredRoll.incrementCurrentIndex() 0147 } 0148 _featuredTimer.restart() 0149 } 0150 0151 function cycleSlideBackward() 0152 { 0153 if(_featuredRoll.dragging) 0154 { 0155 return 0156 } 0157 0158 if (_featuredRoll.currentIndex === 0) 0159 { 0160 _featuredRoll.currentIndex = _featuredRoll.count - 1; 0161 } else 0162 { 0163 _featuredRoll.decrementCurrentIndex(); 0164 } 0165 0166 _featuredTimer.restart() 0167 } 0168 0169 function randomInteger(min, max) 0170 { 0171 return Math.floor(Math.random() * (max - min + 1)) + min; 0172 } 0173 0174 delegate: Item 0175 { 0176 width: ListView.view.width 0177 height: ListView.view.height 0178 0179 Image 0180 { 0181 anchors.fill: parent 0182 sourceSize.width: (control.imageWidth > -1 ? control.imageWidth : control.width) * 1.5 0183 sourceSize.height: (control.imageHeight > -1 ? control.imageHeight : control.height) * 1.5 0184 asynchronous: true 0185 smooth: true 0186 cache: control.cache 0187 source: control.cb ? control.cb(modelData) : modelData 0188 fillMode: control.fillMode 0189 } 0190 0191 Behavior on height 0192 { 0193 NumberAnimation 0194 { 0195 duration: Maui.Style.units.shortDuration 0196 easing.type: Easing.InOutQuad 0197 } 0198 } 0199 } 0200 0201 layer.enabled: control.radius 0202 layer.effect: OpacityMask 0203 { 0204 maskSource: Maui.ShadowedRectangle 0205 { 0206 width: control.width 0207 height: control.height 0208 0209 corners 0210 { 0211 topLeftRadius: control.corners.topLeftRadius 0212 topRightRadius: control.corners.topRightRadius 0213 bottomLeftRadius: control.corners.bottomLeftRadius 0214 bottomRightRadius: control.corners.bottomRightRadius 0215 } 0216 } 0217 } 0218 } 0219 }