Warning, /maui/mauikit/src/controls.5/IconItem.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 2.14
0021 import QtQuick.Controls 2.14
0022 import QtGraphicalEffects 1.0
0023 
0024 import org.mauikit.controls 1.3 as Maui
0025 
0026 /*!
0027   \since org.mauikit.controls.labs 1.0
0028   \inqmlmodule org.mauikit.controls.labs
0029 */
0030 Item
0031 {
0032     id: control
0033  
0034 //     color: "transparent"
0035 implicitHeight: Math.max(iconSizeHint, imageSizeHint)
0036 implicitWidth: Math.max(iconSizeHint, imageSizeHint)
0037 
0038     /**
0039      * iconSizeHint : int
0040      */
0041     property bool highlighted: false
0042     
0043     /**
0044      * iconSizeHint : int
0045      */
0046     property bool hovered: false
0047     
0048     /**
0049      * iconSizeHint : int
0050      */
0051     property int iconSizeHint : Maui.Style.iconSizes.big
0052     
0053     /**
0054      * iconSizeHint : int
0055      */
0056     property int imageSizeHint : -1
0057     
0058     
0059     /**
0060      * imageSource : string
0061      */
0062     property string imageSource
0063     
0064     /**
0065      * iconSource : string
0066      */
0067     property string iconSource
0068     
0069     /**
0070      * fillMode : Image.fillMode
0071      */
0072     property int fillMode : Image.PreserveAspectFit
0073     /**
0074      * maskRadius : int
0075      */
0076     property int maskRadius: 0
0077     
0078     property int imageWidth : -1
0079     property int imageHeight : -1
0080     
0081     property bool smooth: false
0082 
0083     property alias isMask : icon.isMask
0084     property alias image : img
0085     property alias icon: icon
0086     
0087     property int alignment: Qt.AlignHCenter
0088     
0089     Maui.Icon
0090     {
0091         id: icon
0092         visible: img.status === Image.Null || img.status !== Image.Ready || img.status === Image.Error
0093         smooth: control.smooth
0094          anchors.centerIn: parent
0095 //anchors.verticalCenter: parent.verticalCenter
0096 
0097 //        x: switch(control.alignment)
0098 //        {
0099 //            case Qt.AlignLeft: return 0
0100 //            case Qt.AlignHCenter: return control.width/2 - width/2
0101 //            case Qt.AlignRight: return control.width - width
0102 //        }
0103         source: control.iconSource || "folder-images"
0104         height: Math.floor(Math.min(parent.height, control.iconSizeHint))
0105         width: height
0106         color: isMask ? (control.highlighted ? Maui.Theme.highlightedTextColor : Maui.Theme.textColor) : "transparent"
0107         isMask: (height <= Maui.Style.iconSizes.small) || control.isMask
0108 //         selected: control.highlighted        
0109     }
0110 
0111     Image
0112     {
0113         id: img
0114 
0115         width: Math.min(imageSizeHint >=0  ? imageSizeHint : parent.width, parent.width)
0116         height: Math.min(imageSizeHint >= 0 ? imageSizeHint : parent.height, parent.height)
0117 
0118 //         anchors.fill: parent
0119         anchors.verticalCenter: parent.verticalCenter
0120         x: switch(control.alignment)
0121         {
0122             case Qt.AlignLeft: return 0
0123             case Qt.AlignHCenter: return control.width/2 - width/2
0124             case Qt.AlignRight: return control.width - width
0125         }
0126 
0127         sourceSize.width: (control.imageWidth > -1 ? control.imageWidth : width)
0128         sourceSize.height: (control.imageHeight > -1 ? control.imageHeight : height)
0129 
0130         horizontalAlignment: Qt.AlignHCenter
0131         verticalAlignment: Qt.AlignVCenter
0132 
0133         fillMode: control.fillMode
0134 
0135         source: control.imageSource
0136 
0137         cache: true
0138         asynchronous: true
0139         smooth: control.smooth
0140         mipmap: false
0141 
0142         layer.enabled: control.maskRadius
0143         layer.effect: OpacityMask
0144         {
0145             maskSource: Item
0146             {
0147                 width: img.width
0148                 height: img.height
0149 
0150                 Rectangle
0151                 {
0152                     anchors.centerIn: parent
0153                     width: Math.min(parent.width, img.paintedWidth)
0154                     height: Math.min(parent.height, img.paintedHeight)                    
0155                     radius: control.maskRadius
0156                 }
0157             }
0158         }
0159     }
0160 }