Lomiri
Loading...
Searching...
No Matches
PinPadButton.qml
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.12
18import Lomiri.Components 1.3
19
20Item {
21 id: root
22 opacity: enabled ? 1 : 0.6
23
24 property alias text: label.text
25 property string iconName
26 property color foregroundColor: "#000000"
27
28 signal clicked();
29
30 LomiriShape {
31 anchors.fill: parent
32 opacity: mouseArea.pressed ? 1 : 0
33 Behavior on opacity {
34 LomiriNumberAnimation {}
35 }
36 }
37
38 Label {
39 id: label
40 anchors.centerIn: parent
41 horizontalAlignment: Text.AlignHCenter
42 color: root.foregroundColor
43 fontSize: "x-large"
44 font.weight: Font.DemiBold
45 visible: text.length > 0
46 scale: root.pressed ? 0.9 : 1
47 Behavior on scale {
48 LomiriNumberAnimation {}
49 }
50 }
51
52 Icon {
53 id: icon
54 height: units.gu(3)
55 width: height
56 anchors.centerIn: parent
57 name: root.iconName
58 color: root.foregroundColor
59 visible: name.length > 0
60 scale: root.pressed ? 0.9 : 1
61 Behavior on scale {
62 LomiriNumberAnimation { duration: LomiriAnimation.SlowDuration }
63 }
64 }
65
66 MouseArea {
67 id: mouseArea
68 anchors.fill: parent
69
70 // Intentionally using onReleased here to increase the robustness against
71 // sloppy presses. This often happens when entering a pin very quickly and
72 // the numbers for the pin are far apart.
73 onReleased: {
74 Haptics.play();
75 root.clicked();
76 }
77 }
78}