Warning, /plasma/plasma-desktop/kcms/keyboard/tastenbrett/qml/Key.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 import QtQuick 2.12
0008 import QtQuick.Controls 2.5
0009 
0010 ShapeCanvas {
0011     id: root
0012 
0013     property QtObject key
0014     property variant keyColor: key.pressed ? activePalette.highlight : activePalette.button
0015     property variant labelColor: key.pressed ? activePalette.highlightedText : activePalette.buttonText
0016 
0017     shape: key ? key.shape : null
0018     strokeSyle: activePalette.shadow
0019     fillStyle: keyColor
0020 
0021     onKeyColorChanged: requestPaint()
0022 
0023     KeyCap {
0024         key: parent.key
0025 
0026         anchors.fill: parent
0027         anchors.margins: 22 // arbitrary spacing to key outlines
0028     }
0029 
0030     Component.onCompleted: {
0031         if (!parent || !parent.row) {
0032             // There's implicit layout logic below when used inside a row.
0033             // Key may also be used standalone, so skip the layout bits.
0034             return;
0035         }
0036 
0037         if (parent.row.orientation === Qt.Horizontal) {
0038             x = 0
0039 
0040             for (var i in parent.children) {
0041                 // find the furthest sibling -> it is our nearst one
0042                 var sibling = parent.children[i]
0043                 if (sibling === this) {
0044                     continue
0045                 }
0046                 x = Math.max(x, sibling.x + sibling.width)
0047             }
0048             if (x > 0) {
0049                 x += key.gap // found a sibling, gap us from it
0050             }
0051 
0052             y = shape.bounds.y
0053         } else {
0054             y = 0
0055 
0056             for (var i in parent.children) {
0057                 // find the furthest sibling -> it is our nearst one
0058                 var sibling = parent.children[i]
0059                 if (sibling === this) {
0060                     continue
0061                 }
0062                 y = Math.max(y, sibling.y + sibling.height)
0063             }
0064             if (y > 0) {
0065                 y += key.gap // found a sibling, gap us from it
0066             }
0067 
0068             x = shape.bounds.x
0069         }
0070     }
0071 }