Debian Codegraph @

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

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