Debian Codegraph @

src/imports/Lomiri/AddressBook/ContactEditor/TextInputDetail.qml

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright (C) 2012-2015 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
17 import QtQuick 2.4
18 import Lomiri.Components 1.3
19 import Lomiri.Telephony.PhoneNumber 0.1
20
21 //style
22 import Lomiri.Components.Themes.Ambiance 0.1
23
24 FocusScope {
25 id: root
26
27 //WORKAROUND: SDK does not allow us to disable focus for items due bug: #1514822
28 //because of that we need this
29 readonly property bool _allowFocus: true
30 readonly property bool isTextField: true
31
32 property QtObject detail
33 property int field: -1
34 property variant originalValue: root.detail && (root.field >= 0) ? root.detail.value(root.field) : null
35
36 // proxy textField
37 property alias font: field.font
38 property alias placeholderText: field.placeholderText
39 property alias inputMethodHints: field.inputMethodHints
40 property alias text: field.text
41 property alias hasClearButton: field.hasClearButton
42 // proxy PhoneNumberField
43 property alias autoFormat: field.autoFormat
44
45 signal removeClicked()
46
47 //FIXME: Move this property to TextField as soon as the SDK get ported to QtQuick 2.2
48 activeFocusOnTab: true
49 onOriginalValueChanged: {
50 if (originalValue && (originalValue !== "")) {
51 field.text = originalValue
52 }
53 }
54
55 // propage focus to text field
56 onActiveFocusChanged: {
57 if (activeFocus)
58 field.forceActiveFocus()
59 }
60
61 PhoneNumberField {
62 id: field
63
64 function forceActiveFocusForNextField(keyEvent)
65 {
66 var backward = (keyEvent.modifiers & Qt.ShiftModifier)
67 var next = field.nextItemInFocusChain(!backward)
68
69 if (next) {
70 next.forceActiveFocus()
71 }
72 }
73
74 anchors.fill: parent
75 defaultRegion: PhoneUtils.defaultRegion
76 autoFormat: false
77
•78 property variant __inputMethodExtensions: {
79 // TRANSLATORS: This is the text that will be used on the "return" key
80 // for the virtual keyboard. This word must be less than 5 characters.
81 "enterKeyText": i18n.dtr("lomiri-addressbook-app", "Next"),
82 }
83
84 readOnly: root.detail ? root.detail.readOnly : true
85 style: TextFieldStyle {
86 overlaySpacing: 0
87 frameSpacing: 0
88 background: Item {}
89 }
90 onActiveFocusChanged: {
91 if (activeFocus) {
92 makeMeVisible(root)
93 }
94 }
95
96 // default style
97 font {
98 family: "Ubuntu"
99 pixelSize: activeFocus ? FontUtils.sizeToPixels("large") : FontUtils.sizeToPixels("medium")
100 }
101
102 Keys.onReturnPressed: forceActiveFocusForNextField(event)
103 }
104 }