Warning, /plasma/kdeplasma-addons/applets/weather/package/contents/ui/IconAndTextItem.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick
0008 
0009 import QtQuick.Layouts
0010 
0011 import org.kde.kirigami as Kirigami
0012 import org.kde.plasma.components as PlasmaComponents
0013 
0014 GridLayout {
0015     id: iconAndTextRoot
0016 
0017     property alias iconSource: icon.source
0018     property alias text: label.text
0019     property bool vertical: false // too bad we cannot make this an enum
0020     property alias active: icon.active
0021 
0022     readonly property int minimumIconSize: Kirigami.Units.iconSizes.small
0023     readonly property int iconSize: iconAndTextRoot.vertical ? width : height
0024 
0025     columns: iconAndTextRoot.vertical ? 1 : 2
0026     rows: iconAndTextRoot.vertical ? 2 : 1
0027 
0028     columnSpacing: 0
0029     rowSpacing: 0
0030 
0031     Kirigami.Icon {
0032         id: icon
0033 
0034         readonly property int implicitMinimumIconSize: Math.max(iconSize, minimumIconSize)
0035         // reset implicit size, so layout in free dimension does not stop at the default one
0036         implicitWidth: minimumIconSize
0037         implicitHeight: minimumIconSize
0038 
0039         Layout.fillWidth: iconAndTextRoot.vertical
0040         Layout.fillHeight: !iconAndTextRoot.vertical
0041         Layout.minimumWidth: iconAndTextRoot.vertical ? minimumIconSize : implicitMinimumIconSize
0042         Layout.minimumHeight: iconAndTextRoot.vertical ? implicitMinimumIconSize : minimumIconSize
0043     }
0044 
0045     Item {
0046         id: text
0047 
0048         // Otherwise it takes up too much space while loading
0049         visible: label.text.length > 0
0050 
0051         Layout.fillWidth: iconAndTextRoot.vertical
0052         Layout.fillHeight: !iconAndTextRoot.vertical
0053         Layout.minimumWidth: iconAndTextRoot.vertical ? 0 : sizehelper.paintedWidth
0054         Layout.maximumWidth: iconAndTextRoot.vertical ? Infinity : Layout.minimumWidth
0055 
0056         Layout.minimumHeight: iconAndTextRoot.vertical ? sizehelper.paintedHeight : 0
0057         Layout.maximumHeight: iconAndTextRoot.vertical ? Layout.minimumHeight : Infinity
0058 
0059         Text {
0060             id: sizehelper
0061 
0062             font {
0063                 family: label.font.family
0064                 weight: label.font.weight
0065                 italic: label.font.italic
0066                 pixelSize: iconAndTextRoot.vertical ? Kirigami.Units.gridUnit * 2 : 1024 // random "big enough" size - this is used as a max pixelSize by the fontSizeMode
0067             }
0068             minimumPixelSize: Math.round(Kirigami.Units.gridUnit / 2)
0069             fontSizeMode: iconAndTextRoot.vertical ? Text.HorizontalFit : Text.VerticalFit
0070             wrapMode: Text.NoWrap
0071 
0072             horizontalAlignment: Text.AlignHCenter
0073             verticalAlignment: Text.AlignVCenter
0074             anchors {
0075                 leftMargin: Kirigami.Units.smallSpacing
0076                 rightMargin: Kirigami.Units.smallSpacing
0077             }
0078             // These magic values are taken from the digital clock, so that the
0079             // text sizes here are identical with various clock text sizes
0080             height: {
0081                 const textHeightScaleFactor = (parent.height > 26) ? 0.7 : 0.9;
0082                 return Math.min (parent.height * textHeightScaleFactor, 3 * Kirigami.Theme.defaultFont.pixelSize);
0083             }
0084             visible: false
0085 
0086             // pattern to reserve some constant space TODO: improve and take formatting/i18n into account
0087             text: "888° X"
0088             textFormat: Text.PlainText
0089         }
0090 
0091         PlasmaComponents.Label {
0092             id: label
0093 
0094             font {
0095                 weight: Font.Normal
0096                 pixelSize: 1024
0097                 pointSize: 0 // we need to unset pointSize otherwise it breaks the Text.Fit size mode
0098             }
0099             minimumPixelSize: Math.round(Kirigami.Units.gridUnit / 2)
0100             fontSizeMode: Text.Fit
0101             textFormat: Text.PlainText
0102             wrapMode: Text.NoWrap
0103 
0104             height: 0
0105             width: 0
0106             verticalAlignment: Text.AlignVCenter
0107             horizontalAlignment: Text.AlignHCenter
0108             anchors {
0109                 fill: parent
0110                 leftMargin: Kirigami.Units.smallSpacing
0111                 rightMargin: Kirigami.Units.smallSpacing
0112             }
0113         }
0114     }
0115 }