Warning, /sdk/cutehmi/extensions/CuteHMI/GUI.1/NumberDisplay.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.5 0002 0003 import CuteHMI.GUI 1.0 0004 0005 /** 0006 Number display. 0007 0008 Number display can be used to conveniently display numerical values with corresponding units of measurement. Number display tries 0009 to keep constant width. If that's not possible it expands to fit to its contents. 0010 0011 ![Number display preview](doc/NumberDisplay_preview.png) 0012 0013 Above image has been obtained with the following sample code demonstrating basic use of number display. 0014 0015 @snippet tests/tst_NumberDisplay.qml NumberDisplay preview 0016 */ 0017 Element { 0018 id: root 0019 0020 implicitWidth: background.width - valueDisplay.overfull 0021 implicitHeight: background.height 0022 0023 active: value === value // NaN === NaN equals false, thus NaN value deactivates display. 0024 0025 /** 0026 Font. Font that is used by the display. It may be desirable to set some monospace font. 0027 */ 0028 property alias font: valueDisplay.font 0029 0030 /** 0031 Left padding. 0032 */ 0033 property real leftPadding: font.pixelSize * 0.25 0034 0035 /** 0036 Right padding. 0037 */ 0038 property real rightPadding: font.pixelSize * 0.25 0039 0040 /** 0041 Top padding. 0042 */ 0043 property real topPadding: font.pixelSize * 0.25 0044 0045 /** 0046 Bottom padding. 0047 */ 0048 property real bottomPadding: font.pixelSize * 0.25 0049 0050 /** 0051 Value. 0052 */ 0053 property real value: NaN 0054 0055 /** 0056 Fractional width. 0057 */ 0058 property int fractionalWidth: 1 0059 0060 /** 0061 Integral width. 0062 */ 0063 property int integralWidth: 3 0064 0065 /** 0066 Unit of measurment. 0067 */ 0068 property string unit: "°C" 0069 0070 /** 0071 Text formatter. 0072 */ 0073 property var textFormatter: function(value) { return value.toFixed(root.fractionalWidth) } 0074 0075 Rectangle { 0076 id: background 0077 0078 x: -0.5 * valueDisplay.overfull 0079 width: contentItem.width + leftPadding + rightPadding 0080 height: contentItem.height + topPadding + bottomPadding 0081 0082 radius: height / 5 0083 color: root.color.background 0084 border.color: root.color.stroke 0085 border.width: units.strokeWidth 0086 } 0087 0088 Row { 0089 id: contentItem 0090 0091 x: leftPadding - 0.5 * valueDisplay.overfull 0092 y: topPadding 0093 0094 spacing: root.font.pixelSize * 0.25 0095 0096 Text { 0097 id: valueDisplay 0098 0099 width: Math.max(contentWidth, nominaLWidth) 0100 0101 text: textFormatter(root.value) 0102 color: root.color.foreground 0103 horizontalAlignment: Text.AlignRight 0104 font.pixelSize: units.quadrat * 0.25 0105 font.family: Theme.fonts.monospace.family 0106 0107 property real overfull: width - nominaLWidth 0108 property real nominaLWidth: contentWidth / text.length * (root.fractionalWidth + root.integralWidth + 1) 0109 } 0110 0111 Text { 0112 id: unitDisplay 0113 0114 text: root.unit 0115 font: root.font 0116 color: root.color.foreground 0117 } 0118 } 0119 } 0120 0121 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved. 0122 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT 0123 //(c)C: This file is a part of CuteHMI. 0124 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 0125 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 0126 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>. 0127 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below. 0128 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 0129 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 0130 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.