Warning, /maui/mauikit/src/controls.6/GridBrowser.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright 2018 Camilo Higuita <milo.h@aol.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 import QtQuick
0021 import QtQuick.Controls
0022 
0023 import org.mauikit.controls 1.3 as Maui
0024 
0025 /**
0026  * @inherit QtQuick.Item
0027  * @brief A browser view with a grid layout.
0028  * 
0029  * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-item.html">This controls inherits from QQC2 Item, to checkout its inherited properties refer to the Qt Docs.</a>
0030  * 
0031  * This component might seem similar to QQC2 GridView - and it does uses it underneath - but this one includes a few more predefined elements, such as auto adaptable uniform cell width, a placeholder element, pinch to zoom gestures, and lasso selection support. 
0032  * 
0033  *  @section structure Structure
0034  * The browser has a dedicated placeholder element handled by MauiKit Holder, where a message can be set when the view is on a determined state the user should be warned about, such as if the view is empty, or not search results were found.
0035  * @see Holder
0036  * 
0037  * The lasso selection feature works with a mouse or a track-pad, and allows to select multiple items in the browser-view that are under the lasso rectangle area. A signal is emitted when the selection has been triggered - this is when the lasso rectangle is released - sending as an argument an array of numbers representing the indexes of the selected items.
0038  * @see itemsSelected 
0039  * 
0040  * @image html Browsers/gridbrowser_resize.gif "The GridBrowser with adaptable content enabled"
0041  * 
0042  * @note Notice the yellow rectangles vs the grey ones. The yellow rectangles will preserve the `itemSize` dimensions, while the cell area, represented by the gray rectangle, will vary. The example below demonstrates this behavior.
0043  * 
0044  * @section notes Notes
0045  * Use the `itemSize` property to set an uniform size for the cell item. At first the `cellWidth` will have the same value as the `itemSize`.
0046  * 
0047  * If the `adaptContent` is enabled, the cell width will vary, while the cell height will maintain the same value as the `itemSize`. 
0048  * @see adaptContent
0049  * 
0050  * When the view is resized and the `adaptContent` is enabled, the cell width - `cellWidth` - values will be updated to a value that can fill the width of the view-port uniformly. The modified values of the `cellWidth` will never be less than the value defined in the `itemSize` property.
0051  * @see itemSize
0052  * 
0053  * @warning Keep in mind that the `cellWidth` values will be modified when enabling the `adaptContent` property. So any binding to this property will break.
0054  * 
0055  * @code
0056  * Maui.Page
0057  * {
0058  *    id: _page
0059  *    anchors.fill: parent
0060  *    Maui.Controls.showCSD: true
0061  *    headBar.forceCenterMiddleContent: true
0062  * 
0063  *    headBar.leftContent: Switch
0064  *    {
0065  *        text: "Adapt Content"
0066  *        checked: _gridBrowser.adaptContent
0067  *        onToggled: _gridBrowser.adaptContent = !_gridBrowser.adaptContent
0068  *    }
0069  * 
0070  *    Maui.GridBrowser
0071  *    {
0072  *        id: _gridBrowser
0073  *        anchors.fill: parent
0074  *        model: 30
0075  * 
0076  *        itemSize: 200
0077  *        itemHeight: 300
0078  * 
0079  *        adaptContent: true
0080  * 
0081  *        delegate: Rectangle
0082  *        {
0083  *            width: GridView.view.cellWidth
0084  *            height: GridView.view.cellHeight
0085  *            color: "gray"
0086  *            border.color: "white"
0087  * 
0088  *            Rectangle
0089  *            {
0090  *                width: _gridBrowser.itemSize
0091  *                height: _gridBrowser.itemSize
0092  * 
0093  *                color: "yellow"
0094  * 
0095  *                anchors.centerIn: parent
0096  *            }
0097  *        }
0098  *    }
0099  * }
0100  * @endcode
0101  *  
0102  * @note You can use the GridView attached properties to refer to the control properties from the delegates. For example, you could use `GridView.view.itemSize` or GridView.view.cellWidth`. * 
0103  *  
0104  * @image html Browsers/gridbrowser_alt.png "The GridBrowser with adaptable content disabled"
0105  * 
0106  * @note Notice the yellow rectangles vs the grey ones. The yellow rectangles will preserve the `itemSize` dimensions, and the cell width - as the gray area- will also keep the same dimensions as `itemSize`.
0107  *  
0108  * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/GridBrowser.qml">You can find a more complete example at this link.</a>
0109  */
0110 Item
0111 {
0112     id: control
0113     focus: true
0114     clip: false
0115     
0116     implicitHeight: contentHeight + topPadding + bottomPadding
0117     implicitWidth: contentWidth + leftPadding + rightPadding
0118     
0119     /**
0120      * @brief The uniform size of the element in the cell. This value is used for the width and height. This value will stay the same even when the width of the cell changes.
0121      * 
0122      * The dimensions of the item can be changed manually for its height and its width.
0123      * @see itemHeight
0124      * @see itemWidth
0125      * 
0126      * @note This is meant to set an initial uniform size, so notice this value will be use for the `cellWidth`, `cellHeight`, `itemHeight` and `itemWidth`.
0127      * 
0128      * @property int GridBrowser::itemSize
0129      */
0130     property alias itemSize: controlView.itemSize
0131     
0132     /**
0133      * @brief The width of the element in the cell. This value will vary even if `adaptContent` is enabled.
0134      * This value is used as the `cellWidth` value by default.
0135      * @property int GridBrowser::itemWidth
0136      */
0137     property alias itemWidth : controlView.itemWidth
0138     
0139     /**
0140      * @brief The height of the element in the cell. This value will vary even if `adaptContent` is enabled.
0141      * This value is used as the `cellHeight` value by default. 
0142      * @property int GridBrowser::itemHeight
0143      */
0144     property alias itemHeight : controlView.itemHeight
0145     
0146     /**
0147      * @brief The width size of the cell area.
0148      * 
0149      * @warning This value will be modified when the viewport area is resized and the `adaptContent` is enabled. So any binding will be lost. To have a fixed cell width value, set `adaptContent: false`.
0150      * @see adaptContent
0151      * @property int GridBrowser::cellWidth
0152      */
0153     property alias cellWidth: controlView.cellWidth
0154     
0155     /**
0156      * @brief The height size of the cell area.
0157      * This value is set to the `itemHeight` value, or `itemSize` if the formerly one has not been set.
0158      * This value will not be modified by the adaptable behaviour.
0159      * Notice you can make the cell bigger than the itemHeight, in order to create a sense of vertical padding for each cell element.
0160      * @property int GridBrowser::cellHeight
0161      */
0162     property alias cellHeight: controlView.cellHeight
0163     
0164     /**
0165      * @brief The model to be used to populate the browsing view.
0166      * @property var GridBrowser::model
0167      */
0168     property alias model : controlView.model
0169     
0170     /**
0171      * @brief The component to be used as the delegate.
0172      * @note Consider using the MauiKit delegate controls, such as GridBrowserDelegate, GalleryRollItem or CollageItem.
0173      * @property Component GridBrowser::delegate
0174      */
0175     property alias delegate : controlView.delegate
0176     
0177     /**
0178      * @brief The position of the view contents on the Y axis.
0179      * @property double GridBrowser::contentY
0180      */
0181     property alias contentY: controlView.contentY
0182     
0183     /**
0184      * @brief The index number of the current element selected.
0185      * @property int GridBrowser::currentIndex
0186      */
0187     property alias currentIndex : controlView.currentIndex
0188     
0189     /**
0190      * @brief The total amount of elements listed in the view.
0191      * @property int GridBrowser::count
0192      */
0193     property alias count : controlView.count
0194     
0195     /**
0196      * @brief The cache buffer. 
0197      * Refer to the QQC2 GridView documentation.
0198      * @property int GridBrowser::cacheBuffer
0199      */
0200     property alias cacheBuffer : controlView.cacheBuffer
0201     
0202     /**
0203      * @brief The element controlling the layout fo element, AKA the flickable element.
0204      * This is an alias to the QQC2 GridView control.
0205      * @property GridView GridBrowser::flickable
0206      */
0207     property alias flickable : controlView
0208     
0209     /**
0210      * @brief The total height of all the elements listed in the view.
0211      * @property int GridBrowser::contentHeight
0212      */
0213     property alias contentHeight : controlView.contentHeight
0214     
0215     /**
0216      * @brief The total width of all the elements.
0217      * @property int GridBrowser::contentWidth 
0218      */
0219     property alias contentWidth : controlView.contentWidth
0220     
0221     /**
0222      * @brief An alias to the QQC2 ScrollView element attached to the view.
0223      * @property ScrollView GridBrowser::scrollView
0224      */
0225     property alias scrollView: _scrollView
0226     
0227     /**
0228      * @brief Top padding of the view. This padding is added to the scroll view container.
0229      * @see scrollView
0230      * @property int GridBrowser::topPadding
0231      */
0232     property alias topPadding: _scrollView.topPadding
0233     
0234     /**
0235      * @brief Bottom padding of the view. This padding is added to the scroll view container.
0236      * @see scrollView
0237      * @property int GridBrowser::bottomPadding
0238      */
0239     property alias bottomPadding: _scrollView.bottomPadding
0240     
0241     /**
0242      * @brief Right padding of the view. This padding is added to the scroll view container.
0243      * @see scrollView
0244      * @property int GridBrowser::rightPadding
0245      */
0246     property alias rightPadding: _scrollView.rightPadding
0247     
0248     /**
0249      * @brief Left padding of the view. This padding is added to the scroll view container.
0250      * @see scrollView
0251      * @property int GridBrowser::leftPadding
0252      */
0253     property alias leftPadding: _scrollView.leftPadding
0254     
0255     /**
0256      * @brief Padding of the view. This padding is added to the scroll view container.
0257      * @see scrollView
0258      * @property int GridBrowser::padding
0259      */
0260     property alias padding: _scrollView.padding
0261     
0262     /**
0263      * @brief The policy of the vertical scroll bar from the scroll view.
0264      * @see scrollView
0265      * The default value of this is picked based on the Style property `Style.scrollBarPolicy`, unless the orientation of the view is set to horizontal, in which case this is set to 'ScrollBar.AlwaysOff`.
0266      * Possible values are:
0267      * - ScrollBar.AlwaysOff
0268      * - ScrollBar.AlwaysOn
0269      * - ScrollBar.AsNeeded
0270      */
0271     property int verticalScrollBarPolicy:
0272     {
0273         if(control.orientation === GridView.Horizontal)
0274             return ScrollBar.AlwaysOff
0275             
0276             switch(Maui.Style.scrollBarPolicy)
0277             {
0278                 case Maui.Style.AlwaysOn: return ScrollBar.AlwaysOn;
0279                 case Maui.Style.AlwaysOff: return ScrollBar.AlwaysOff;
0280                 case Maui.Style.AsNeeded: return ScrollBar.AsNeeded;
0281                 case Maui.Style.AutoHide: return ScrollBar.AsNeeded;
0282             }
0283     }
0284     
0285     /**
0286      * @brief The policy of the horizontal scroll bar from the scroll view.
0287      * @see scrollView
0288      * The default value of this is picked based on the Style property `Style.scrollBarPolicy`, unless the orientation of the view is set to vertical, in which case this is set to 'ScrollBar.AlwaysOff`.
0289      * Possible values are:
0290      * - ScrollBar.AlwaysOff
0291      * - ScrollBar.AlwaysOn
0292      * - ScrollBar.AsNeeded
0293      */
0294     property int horizontalScrollBarPolicy:
0295     {
0296         if(control.orientation === GridView.Vertical)
0297             return ScrollBar.AlwaysOff
0298             
0299             switch(Maui.Style.scrollBarPolicy)
0300             {
0301                 case Maui.Style.AlwaysOn: return ScrollBar.AlwaysOn;
0302                 case Maui.Style.AlwaysOff: return ScrollBar.AlwaysOff;
0303                 case Maui.Style.AsNeeded: return ScrollBar.AsNeeded;
0304                 case Maui.Style.AutoHide: return ScrollBar.AsNeeded;
0305             }
0306     }
0307     
0308     /**
0309      * @brief An alias to access the placeholder properties. This is handled by a MauiKit Holder.
0310      * @see Holder::title
0311      * @see Holder::body
0312      * 
0313      * @property Holder GridBrowser::holder
0314      */
0315     property alias holder : _holder
0316     
0317     /**
0318      * @brief Whether the width value of the cells should be recalculated when the view-port is resized. This will result in a uniform set of cells. The minimum width of the cells is constrained by the `itemSize` property.
0319      * By default this is set to `true`.
0320      */
0321     property bool adaptContent: true
0322     onAdaptContentChanged:
0323     {
0324         if(adaptContent)
0325             control.adaptGrid()
0326             else
0327                 control.resetCellWidth()
0328     }
0329     
0330     /**
0331      * @brief Whether to enable the lasso selection, to select multiple items.
0332      * By default this is set to `false`.
0333      * @see itemsSelected
0334      */
0335     property bool enableLassoSelection : false
0336     
0337     /**
0338      * @brief 
0339      */
0340     property bool selectionMode: false
0341     
0342     /**
0343      * @brief An alias to the lasso rectangle.
0344      * @property Rectangle GridBrowser::lassoRec
0345      */
0346     readonly property alias lassoRec : selectLayer
0347     
0348     /**
0349      * @brief Whether the pinch-to-zoom gesture is enabled.
0350      * By default this is set to `false`.
0351      */
0352     property bool pinchEnabled : false
0353     
0354     /**
0355      * @brief The current item selected.
0356      * @property Item GridBrowser::currentItem
0357      */
0358     property alias currentItem : controlView.currentItem
0359     
0360     /**
0361      * @brief The header section of the GridView element.
0362      * @see flickable
0363      * @property Component GridBrowser::header
0364      */
0365     property alias header : controlView.header
0366     
0367     /**
0368      * @brief The footer section of the GridView element
0369      * @see flickable
0370      * @property Component GridBrowser::footer
0371      */
0372     property alias footer : controlView.footer
0373     
0374     /**
0375      * @brief The actual width of the view-port. This is the actual width without any padding.
0376      * @property int GridBrowser::availableWidth
0377      */
0378     readonly property alias availableWidth: controlView.width
0379     
0380     /**
0381      * @brief The actual height of the view-port. This is the actual height without any padding.
0382      * @property int GridBrowser::availableHeight
0383      */
0384     readonly property alias availableHeight: controlView.height
0385     
0386     /**
0387      * @brief Whether the view is moving horizontally or vertically. This reacts to changes in the content Y and/or X axis.
0388      * @see contentY
0389      * @see contentX
0390      * @property bool GridBrowser::moving
0391      */
0392     readonly property alias moving: updateContentDelay.running
0393     
0394     /**
0395      * @brief Emitted when the lasso selection has been released.
0396      * @param indexes A array of index numbers is sent as the argument, representing the index value of the items under the lasso rectangle area.
0397      */
0398     signal itemsSelected(var indexes)
0399     
0400     /**
0401      * @brief Emitted when an empty space of the background area has been clicked.
0402      * @param mouse Object with information about the click event.
0403      */
0404     signal areaClicked(var mouse)
0405     
0406     /**
0407      * @brief Emitted when an empty space of the area area background has been right clicked.
0408      */
0409     signal areaRightClicked()
0410     
0411     /**
0412      * @brief Emitted when a physical key from the device has been pressed.
0413      * @param event The object with information about the event.
0414      */
0415     signal keyPress(var event)
0416     
0417     Keys.enabled : true
0418     Keys.forwardTo : controlView
0419     
0420     onItemSizeChanged :
0421     {
0422         controlView.size_ = itemSize
0423         control.itemWidth = itemSize
0424         control.cellWidth = itemWidth
0425         if(adaptContent)
0426             control.adaptGrid()
0427     }
0428     
0429     ScrollView
0430     {
0431         id: _scrollView
0432         anchors.fill: parent
0433         focus: true
0434         padding: Maui.Style.contentMargins
0435         
0436         clip: control.clip
0437         
0438         ScrollBar.horizontal.policy: control.horizontalScrollBarPolicy
0439         ScrollBar.vertical.policy: control.verticalScrollBarPolicy
0440         
0441         contentHeight: controlView.contentHeight
0442         contentWidth: availableWidth
0443         
0444         // background: Rectangle
0445         // {
0446         //     color: "magenta"
0447         // 
0448         //     MouseArea
0449         //     {
0450         //         anchors.fill: parent
0451         //         onClicked: console.log("clickcycky")
0452         //     }
0453         // }
0454         
0455         Item
0456         {
0457             // color: "orange"
0458             height: controlView.contentHeight
0459             width: parent.width
0460             
0461             Loader
0462             {
0463                 asynchronous: true
0464                 //                active: !Maui.Handy.hasTransientTouchInput && !Maui.Handy.isMobile
0465                 anchors.fill: parent
0466                 
0467                 sourceComponent: MouseArea
0468                 {
0469                     id: _mouseArea
0470                     
0471                     propagateComposedEvents: true
0472                     preventStealing: true
0473                     acceptedButtons:  Qt.RightButton | Qt.LeftButton
0474                     
0475                     onClicked: (mouse) =>
0476                     {
0477                         console.log("Area clicked")
0478                         control.areaClicked(mouse)
0479                         control.forceActiveFocus()
0480                         
0481                         if(mouse.button === Qt.RightButton)
0482                         {
0483                             control.areaRightClicked()
0484                             return
0485                         }
0486                     }
0487                     
0488                     onWheel: (wheel) =>
0489                     {
0490                         if (wheel.modifiers & Qt.ControlModifier)
0491                         {
0492                             if (wheel.angleDelta.y != 0)
0493                             {
0494                                 var factor = 1 + wheel.angleDelta.y / 600;
0495                                 control.resizeContent(factor)
0496                             }
0497                         }else
0498                             wheel.accepted = false
0499                     }
0500                     
0501                     onPositionChanged: (mouse) =>
0502                     {
0503                         console.log("Area clicked >>> Moving")
0504                         
0505                         if(_mouseArea.pressed && control.enableLassoSelection && selectLayer.visible)
0506                         {
0507                             if(mouseX >= selectLayer.newX)
0508                             {
0509                                 selectLayer.width = (mouseX + 10) < (control.x + control.width) ? (mouseX - selectLayer.x) : selectLayer.width;
0510                             } else {
0511                                 selectLayer.x = mouseX < control.x ? control.x : mouseX;
0512                                 selectLayer.width = selectLayer.newX - selectLayer.x;
0513                             }
0514                             
0515                             if(mouseY >= selectLayer.newY) {
0516                                 selectLayer.height = (mouseY + 10) < (control.y + control.height) ? (mouseY - selectLayer.y) : selectLayer.height;
0517                                 if(!controlView.atYEnd &&  mouseY > (control.y + control.height))
0518                                     controlView.contentY += 10
0519                             } else {
0520                                 selectLayer.y = mouseY < control.y ? control.y : mouseY;
0521                                 selectLayer.height = selectLayer.newY - selectLayer.y;
0522                                 
0523                                 if(!controlView.atYBeginning && selectLayer.y === 0)
0524                                     controlView.contentY -= 10
0525                             }
0526                         }
0527                     }
0528                     
0529                     onPressed: (mouse) =>
0530                     {
0531                         if (mouse.source === Qt.MouseEventNotSynthesized)
0532                         {
0533                             if(control.enableLassoSelection && mouse.button === Qt.LeftButton && control.count > 0)
0534                             {
0535                                 selectLayer.visible = true;
0536                                 selectLayer.x = mouseX;
0537                                 selectLayer.y = mouseY;
0538                                 selectLayer.newX = mouseX;
0539                                 selectLayer.newY = mouseY;
0540                                 selectLayer.width = 0
0541                                 selectLayer.height = 0;
0542                             }
0543                         }
0544                     }
0545                     
0546                     onPressAndHold: (mouse) =>
0547                     {
0548                         if ( mouse.source !== Qt.MouseEventNotSynthesized && control.enableLassoSelection && !selectLayer.visible )
0549                         {
0550                             selectLayer.visible = true;
0551                             selectLayer.x = mouseX;
0552                             selectLayer.y = mouseY;
0553                             selectLayer.newX = mouseX;
0554                             selectLayer.newY = mouseY;
0555                             selectLayer.width = 0
0556                             selectLayer.height = 0;
0557                             
0558                             mouse.accepted = true
0559                         }else
0560                         {
0561                             mouse.accepted = false
0562                         }
0563                     }
0564                     
0565                     onReleased: (mouse) =>
0566                     {
0567                         if(mouse.button !== Qt.LeftButton || !control.enableLassoSelection || !selectLayer.visible)
0568                         {
0569                             mouse.accepted = false
0570                             return;
0571                         }
0572                         
0573                         if(selectLayer.y > controlView.contentHeight)
0574                         {
0575                             return selectLayer.reset();
0576                         }
0577                         
0578                         var lassoIndexes = []
0579                         const limitX = mouse.x === lassoRec.x ? lassoRec.x+lassoRec.width : mouse.x
0580                         const limitY =  mouse.y === lassoRec.y ?  lassoRec.y+lassoRec.height : mouse.y
0581                         
0582                         for(var i =lassoRec.x; i < limitX; i+=(lassoRec.width/(controlView.cellWidth* 0.5)))
0583                         {
0584                             for(var y = lassoRec.y; y < limitY; y+=(lassoRec.height/(controlView.cellHeight * 0.5)))
0585                             {
0586                                 const index = controlView.indexAt(i,y+controlView.contentY)
0587                                 if(!lassoIndexes.includes(index) && index>-1 && index< controlView.count)
0588                                     lassoIndexes.push(index)
0589                             }
0590                         }
0591                         
0592                         if(lassoIndexes.length > 0)
0593                         {
0594                             control.itemsSelected(lassoIndexes)
0595                         }
0596                         
0597                         selectLayer.reset()
0598                     }
0599                 }
0600             }
0601             
0602             GridView
0603             {
0604                 id: controlView
0605                 focus: true
0606                 anchors.fill: parent
0607                 
0608                 /**
0609                  * itemSize : int
0610                  */
0611                 property int itemSize: 0
0612                 
0613                 /**
0614                  * itemWidth : int
0615                  */
0616                 property int itemWidth : itemSize
0617                 
0618                 /**
0619                  * itemHeight : int
0620                  */
0621                 property int itemHeight : itemSize
0622                 
0623                 
0624                 property bool firstSelectionPress
0625                 property var selectedIndexes : []
0626                 
0627                 //nasty trick
0628                 property int size_
0629                 Component.onCompleted:
0630                 {
0631                     controlView.size_ = control.itemWidth
0632                 }
0633                 
0634                 flow: GridView.FlowLeftToRight
0635                 clip: control.clip
0636                 
0637                 displayMarginBeginning: Maui.Style.effectsEnabled ? Maui.Style.toolBarHeight * 4 : 0
0638                 displayMarginEnd: displayMarginBeginning
0639                 cacheBuffer: control.itemHeight * 4
0640                 
0641                 cellWidth: control.itemWidth
0642                 cellHeight: control.itemHeight
0643                 
0644                 boundsBehavior: Flickable.StopAtBounds
0645                 
0646                 flickableDirection: Flickable.AutoFlickDirection
0647                 snapMode: GridView.NoSnap
0648                 highlightMoveDuration: 0
0649                 interactive: false
0650                 onWidthChanged: if(adaptContent) control.adaptGrid()
0651                 onCountChanged: if(adaptContent) control.adaptGrid()
0652                 
0653                 keyNavigationEnabled : true
0654                 keyNavigationWraps : true
0655                 Keys.onPressed: (event) =>
0656                 {
0657                     control.keyPress(event)
0658                 }
0659                 
0660                 Maui.Holder
0661                 {
0662                     id: _holder
0663                     visible: false
0664                     anchors.fill : parent
0665                     anchors.topMargin: controlView.headerItem ? controlView.headerItem.height : 0
0666                     anchors.bottomMargin: controlView.footerItem ? controlView.footerItem.height : 0
0667                 }
0668                 
0669                 onContentXChanged:
0670                 {
0671                     updateContentDelay.restart()
0672                 }
0673                 
0674                 onContentYChanged:
0675                 {
0676                     updateContentDelay.restart()
0677                 }
0678                 
0679                 Timer
0680                 {
0681                     id: updateContentDelay
0682                     interval: 500
0683                     repeat: false
0684                 }
0685                 
0686                 Loader
0687                 {
0688                     asynchronous: true
0689                     active: control.pinchEnabled
0690                     
0691                     anchors.fill: parent
0692                     z: -1
0693                     
0694                     sourceComponent: PinchArea
0695                     {
0696                         onPinchFinished: (pinch) =>
0697                         {
0698                             resizeContent(pinch.scale)
0699                         }
0700                     }
0701                 }
0702                 
0703                 Maui.Rectangle
0704                 {
0705                     id: selectLayer
0706                     property int newX: 0
0707                     property int newY: 0
0708                     height: 0
0709                     width: 0
0710                     x: 0
0711                     y: 0
0712                     visible: false
0713                     color: Qt.rgba(control.Maui.Theme.highlightColor.r,control.Maui.Theme.highlightColor.g, control.Maui.Theme.highlightColor.b, 0.2)
0714                     opacity: 0.7
0715                     
0716                     borderColor: control.Maui.Theme.highlightColor
0717                     borderWidth: 2
0718                     solidBorder: false
0719                     
0720                     function reset()
0721                     {
0722                         selectLayer.x = 0;
0723                         selectLayer.y = 0;
0724                         selectLayer.newX = 0;
0725                         selectLayer.newY = 0;
0726                         selectLayer.visible = false;
0727                         selectLayer.width = 0;
0728                         selectLayer.height = 0;
0729                     }
0730                 }
0731             }
0732         }
0733     }
0734     
0735     /**
0736      * @brief Request to resize the view elements. This will result in the `itemSize` property being modified.
0737      * @param factor a factor for resizing.
0738      * The minimum size is `Style.iconSizes.small`.
0739      */
0740     function resizeContent(factor)
0741     {
0742         const newSize = control.itemSize * factor
0743         
0744         if(newSize > control.itemSize)
0745         {
0746             control.itemSize =  newSize
0747         }
0748         else
0749         {
0750             if(newSize >= Maui.Style.iconSizes.small)
0751                 control.itemSize =  newSize
0752         }
0753     }
0754     
0755     /**
0756      * @brief Forces to adapt the width of the grid cells. This will result on the `cellWidth` property being modified.
0757      */
0758     function adaptGrid()
0759     {
0760         var fullWidth = controlView.width
0761         var realAmount = parseInt(fullWidth / controlView.size_, 0)
0762         var amount = parseInt(fullWidth / control.cellWidth, 0)
0763         
0764         var leftSpace = parseInt(fullWidth - ( realAmount * controlView.size_ ), 0)
0765         var size = Math.min(amount, realAmount) >= control.count ? Math.max(control.cellWidth, control.itemSize) : parseInt((controlView.size_) + (parseInt(leftSpace/realAmount, 0)), 0)
0766         
0767         control.cellWidth = size
0768     }
0769     
0770     /**
0771      * @brief Resets the value of the `cellWidth` back to the initial size set with `itemSize`.
0772      */
0773     function resetCellWidth()
0774     {
0775         control.cellWidth = control.itemSize
0776     }
0777 }