Warning, /sdk/cutehmi/extensions/CuteHMI/GUI.1/PropItem.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.3 0002 0003 import CuteHMI.GUI 1.0 0004 0005 /** 0006 Prop item. 0007 0008 This simple item can be used to draw small props around an actual item, which can be placed inside PropItem. Prop size 0009 can be controlled with padding properties (@a leftPadding, @a rightPadding, @a topPadding, @a bottomPadding). 0010 0011 ![Prop item preview](doc/PropItem_preview.png) 0012 0013 Above image has been obtained with the following sample code demonstrating basic use of prop item. 0014 0015 @snippet tests/tst_PropItem.qml PropItem preview 0016 */ 0017 Canvas { 0018 id: root 0019 0020 implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding 0021 implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding 0022 0023 /** 0024 Prop thickness. 0025 */ 0026 property real thickness: Theme.units.strokeWidth 0027 0028 /** 0029 Prop color. 0030 */ 0031 property color color: Theme.palette.neutral.stroke 0032 0033 /** 0034 Left padding. 0035 */ 0036 property real leftPadding: 0.0 0037 0038 /** 0039 Right padding. 0040 */ 0041 property real rightPadding: 0.0 0042 0043 /** 0044 Top padding. 0045 */ 0046 property real topPadding: 0.0 0047 0048 /** 0049 Bottom padding. 0050 */ 0051 property real bottomPadding: 0.0 0052 0053 /** 0054 Content data. 0055 */ 0056 default property alias contentData: contentItem.data 0057 0058 Item { 0059 id: contentItem 0060 0061 x: leftPadding 0062 y: topPadding 0063 0064 implicitWidth: childrenRect.width 0065 implicitHeight: childrenRect.height 0066 } 0067 0068 onThicknessChanged: requestPaint() 0069 0070 onColorChanged: requestPaint() 0071 0072 onLeftPaddingChanged: requestPaint() 0073 0074 onRightPaddingChanged: requestPaint() 0075 0076 onTopPaddingChanged: requestPaint() 0077 0078 onBottomPaddingChanged: requestPaint() 0079 0080 onPaint: { 0081 var ctx = getContext('2d') 0082 ctx.save() 0083 ctx.reset() 0084 0085 ctx.strokeStyle = color 0086 ctx.lineWidth = thickness 0087 0088 var xCenter = leftPadding + contentItem.implicitWidth / 2.0 0089 var yCenter = topPadding + contentItem.implicitHeight / 2.0 0090 var offset = thickness * 0.5 0091 0092 // Draw horizontal props(s). 0093 if (topPadding > 0.0 && bottomPadding > 0.0) { 0094 if (leftPadding > 0.0) { 0095 ctx.moveTo(0.0, offset) 0096 ctx.lineTo(xCenter, offset) 0097 ctx.moveTo(0.0, height - offset) 0098 ctx.lineTo(xCenter, height - offset) 0099 } 0100 if (rightPadding > 0.0) { 0101 ctx.moveTo(xCenter, offset) 0102 ctx.lineTo(width, offset) 0103 ctx.moveTo(xCenter, height - offset) 0104 ctx.lineTo(width, height - offset) 0105 } 0106 } else { 0107 ctx.moveTo(0.0, yCenter) 0108 ctx.lineTo(width, yCenter) 0109 } 0110 0111 // Draw vertical prop(s). 0112 if (leftPadding > 0.0 && rightPadding > 0.0) { 0113 // Draw two side props. 0114 if (topPadding > 0.0) { 0115 ctx.moveTo(offset, 0.0) 0116 ctx.lineTo(offset, yCenter) 0117 ctx.moveTo(width - offset, 0.0) 0118 ctx.lineTo(width - offset, yCenter) 0119 } 0120 if (bottomPadding > 0.0) { 0121 ctx.moveTo(offset, yCenter) 0122 ctx.lineTo(offset, height) 0123 ctx.moveTo(width - offset, yCenter) 0124 ctx.lineTo(width - offset, height) 0125 } 0126 } else { 0127 // Draw single prop. 0128 ctx.moveTo(xCenter, 0.0) 0129 ctx.lineTo(xCenter, height) 0130 } 0131 ctx.stroke() 0132 0133 ctx.restore(); 0134 } 0135 0136 } 0137 0138 //(c)C: Copyright © 2020, Michał Policht <michal@policht.pl>. All rights reserved. 0139 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT 0140 //(c)C: This file is a part of CuteHMI. 0141 //(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. 0142 //(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. 0143 //(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/>. 0144 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below. 0145 //(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: 0146 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 0147 //(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.