Changeset View
Changeset View
Standalone View
Standalone View
kcms/keyboard/tastenbrett/qml/Key.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2019 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public License as | ||||
6 | published by the Free Software Foundation; either version 2 of | ||||
7 | the License or (at your option) version 3 or any later version | ||||
8 | accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | defined in Section 14 of version 3 of the license. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | import QtQuick 2.12 | ||||
22 | import QtQuick.Controls 2.5 | ||||
23 | | ||||
24 | ShapeCanvas { | ||||
25 | id: root | ||||
26 | | ||||
27 | property QtObject key | ||||
28 | property variant keyColor: key.pressed ? activePalette.highlight : activePalette.button | ||||
29 | property variant labelColor: key.pressed ? activePalette.highlightedText : activePalette.buttonText | ||||
30 | | ||||
31 | shape: key ? key.shape : null | ||||
32 | strokeSyle: activePalette.shadow | ||||
33 | fillStyle: keyColor | ||||
34 | | ||||
35 | onKeyColorChanged: requestPaint() | ||||
36 | | ||||
37 | KeyCap { | ||||
38 | key: parent.key | ||||
39 | | ||||
40 | anchors.fill: parent | ||||
41 | anchors.margins: 22 // arbitrary spacing to key outlines | ||||
42 | } | ||||
43 | | ||||
44 | Component.onCompleted: { | ||||
45 | if (!parent || !parent.row) { | ||||
46 | // There's implicit layout logic below when used inside a row. | ||||
47 | // Key may also be used standalone, so skip the layout bits. | ||||
48 | return; | ||||
49 | } | ||||
50 | | ||||
51 | if (parent.row.orientation === Qt.Horizontal) { | ||||
52 | x = 0 | ||||
53 | | ||||
54 | for (var i in parent.children) { | ||||
55 | // find the furthest sibling -> it is our nearst one | ||||
56 | var sibling = parent.children[i] | ||||
57 | if (sibling === this) { | ||||
58 | continue | ||||
59 | } | ||||
60 | x = Math.max(x, sibling.x + sibling.width) | ||||
61 | } | ||||
62 | if (x > 0) { | ||||
63 | x += key.gap // found a sibling, gap us from it | ||||
64 | } | ||||
65 | | ||||
66 | y = shape.bounds.y | ||||
67 | } else { | ||||
68 | y = 0 | ||||
69 | | ||||
70 | for (var i in parent.children) { | ||||
71 | // find the furthest sibling -> it is our nearst one | ||||
72 | var sibling = parent.children[i] | ||||
73 | if (sibling === this) { | ||||
74 | continue | ||||
75 | } | ||||
76 | y = Math.max(y, sibling.y + sibling.height) | ||||
77 | } | ||||
78 | if (y > 0) { | ||||
79 | y += key.gap // found a sibling, gap us from it | ||||
80 | } | ||||
81 | | ||||
82 | x = shape.bounds.x | ||||
83 | } | ||||
84 | } | ||||
85 | } |