Warning, /frameworks/kquickcharts/controls/LegendDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * This file is part of KQuickCharts
0003  * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 import QtQuick 2.12
0009 import QtQuick.Layouts 1.12
0010 import QtQuick.Controls 2.12
0011 
0012 import org.kde.quickcharts 1.0 as Charts
0013 import org.kde.quickcharts.controls 1.0
0014 
0015 /**
0016  * A delegate that can be used as part of a Legend.
0017  */
0018 Control {
0019     id: control
0020 
0021     property string name
0022     property string shortName
0023     property color color
0024     property string value
0025 
0026     property real maximumValueWidth
0027 
0028     property Component indicator: Rectangle {
0029         implicitWidth: Theme.smallSpacing
0030         color: control.color
0031     }
0032 
0033     readonly property real minimumWidth: contentItem.minimumWidth
0034     readonly property real preferredWidth: contentItem.preferredWidth
0035 
0036     property real valueWidth
0037     onValueWidthChanged: Logging.deprecated("LegendDelegate", "valueWidth", "5.82", "Use maximumValueWidth instead")
0038     property real colorWidth
0039     onColorWidthChanged: Logging.deprecated("LegendDelegate", "colorWidth", "5.82", "Customize the indicator instead")
0040     property color valueColor
0041     onValueColorChanged: Logging.deprecated("LegendDelegate", "valueColor", "5.82", "Customize the delegate instead")
0042     property bool colorVisible: true
0043     onColorVisibleChanged: Logging.deprecated("LegendDelegate", "colorVisible", "5.82", "Use an empty indicator instead")
0044     property bool valueVisible: true
0045     onValueVisibleChanged: Logging.deprecated("LegendDelegate", "valueVisible", "5.82", "Customize the delegate instead")
0046     property real layoutWidth
0047     onLayoutWidthChanged: Logging.deprecated("LegendDelegate", "layoutWidth", "5.82", "Unused")
0048 
0049     implicitHeight: Math.max(implicitContentHeight, implicitBackgroundHeight) + topPadding + bottomPadding
0050 
0051     // Note: Do not use implicitContentWidth here as it indirectly depends on the item width and will lead to a
0052     // nasty infinite layout loop. Instead use something more stable that doesn't change depending on the item
0053     // width.
0054     implicitWidth: Math.max(contentItem.preferredWidth, implicitBackgroundWidth) + leftPadding + rightPadding
0055 
0056     hoverEnabled: true
0057 
0058     leftPadding: 0
0059     rightPadding: 0
0060     topPadding: 0
0061     bottomPadding: 0
0062 
0063     spacing: Theme.smallSpacing
0064 
0065     contentItem: RowLayout {
0066         property real actualValueWidth: control.maximumValueWidth > 0 ? control.maximumValueWidth : value.implicitWidth
0067         property real minimumValueWidth: control.width - indicator.width - control.spacing
0068 
0069         property real minimumWidth: indicator.width + actualValueWidth + control.spacing
0070         property real preferredWidth: indicator.width + labelContainer.implicitWidth + actualValueWidth + control.spacing * 2
0071 
0072         spacing: control.spacing
0073 
0074         Loader {
0075             id: indicator
0076 
0077             Layout.preferredWidth: item ? item.implicitWidth : 0
0078             Layout.fillHeight: true
0079 
0080             sourceComponent: control.colorVisible ? control.indicator : null
0081         }
0082 
0083         Item {
0084             id: labelContainer
0085 
0086             Layout.fillHeight: true
0087             Layout.fillWidth: true
0088 
0089             implicitWidth: metrics.advanceWidth(control.name)
0090 
0091             Label {
0092                 id: name
0093                 anchors.fill: parent
0094                 text: control.name + (control.shortName.length > 0 ? "\x9C" + control.shortName : "")
0095                 elide: Text.ElideRight
0096                 font: control.font
0097                 verticalAlignment: Qt.AlignVCenter
0098             }
0099 
0100             FontMetrics {
0101                 id: metrics
0102                 font: control.font
0103             }
0104         }
0105 
0106         Label {
0107             id: value
0108 
0109             Layout.fillHeight: true
0110             Layout.fillWidth: true
0111 
0112             Layout.minimumWidth: Math.min(parent.actualValueWidth, parent.minimumValueWidth)
0113 
0114             text: control.value;
0115             elide: Text.ElideRight
0116             font: name.font
0117 
0118             verticalAlignment: Qt.AlignVCenter
0119             horizontalAlignment: Qt.AlignRight
0120         }
0121     }
0122 
0123     ToolTip.visible: control.hovered && (name.truncated || value.truncated)
0124     ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
0125     ToolTip.text: "%1: %2".arg(control.name).arg(control.value)
0126 }
0127