Debian Codegraph @

app/ui/KeyboardButton.qml

raw
1 /*
2 * Copyright (C) 2017-2019 UBports
3 * Copyright 2013, 2015 Canonical Ltd.
4 *
5 * This file is part of Lomiri Calculator App.
6 *
7 * Lomiri Calculator App is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * Lomiri Calculator App is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 import QtQuick 2.4
21 import Lomiri.Components 1.3
22 import QtQuick.Controls.Suru 2.2
23
24 MouseArea {
25 id: buttonRect
26 objectName: modelname + "Button"
27
28 property alias text: buttonText.text
29 property string role: ""
30
31 readonly property bool kbdPressed: JSON.parse(model.kbdKeys).indexOf(pressedKey) > -1 || (pressedKeyText == text)
32
33 onClicked: {
34 //We need to force active focus to hide Favourites tab from bottom edge
35 textInputField.forceActiveFocus();
36 }
37
38 onKbdPressedChanged: {
39 if (!kbdPressed) {
40 buttonRect.clicked(null);
41 }
42 }
43
44 Rectangle {
45 anchors.fill: parent
46 visible: (role != "button")
47
48 color: (buttonRect.pressed || buttonRect.kbdPressed) ? Suru.secondaryBackgroundColor : Suru.backgroundColor
49
50 Behavior on color {
51 ColorAnimation {
52 duration: LomiriAnimation.SnapDuration
53 }
54 }
55 }
56
57 LomiriShape {
58 anchors {
59 fill: parent
60 topMargin: units.gu(0.5)
61 bottomMargin: units.gu(0.5)
62 leftMargin: units.gu(2.5)
63 rightMargin: units.gu(2.5)
64 }
65 visible: (role == "button")
66 aspect: LomiriShape.Flat
67
68 backgroundColor: (buttonRect.pressed || buttonRect.kbdPressed) ? Qt.darker(Suru.color(Suru.Orange), 1.1) : Suru.color(Suru.Orange)
69
70 Behavior on backgroundColor {
71 ColorAnimation {
72 duration: LomiriAnimation.SnapDuration
73 }
74 }
75 }
76
77 Text {
78 id: buttonText
79 anchors.centerIn: parent
80 color: {
81 if (role == "highlight") {
82 return Suru.color(Suru.Orange);
83 }
84 else if (role == "button") {
85 return Suru.color(Suru.White);
86 }
87
88 return Suru.foregroundColor
89 }
90 font.pixelSize: 0.5 * parent.height
91 opacity: enabled ? 1.0 : 0.5
92 }
93 }