Initial Import
[profile/ivi/hfdialer.git] / qml / DialNumberEntry.qml
1 /*
2  * dialer - QML User Interface Component
3  *
4  * Copyright (c) 2011, Tom Swindell.
5  *
6  * This program is licensed under the terms and conditions of the
7  * Apache License, version 2.0.  The full text of the Apache License is at
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  */
11
12 import Qt 4.7
13
14 Image
15 {
16     property string placeHolderText: qsTr("Enter Number")
17     property TextInput textInput: input
18
19     id: root
20     source: "/usr/share/hfdialer/images/ivi_textarea.png"
21     function clear()
22     {
23         input.color = "#3B3A39";
24         input.text = placeHolderText;
25     }
26
27     function isBlank()
28     {
29         return (input.text == placeHolderText);
30     }
31
32     function appendChar(character)
33     {
34         if(input.text == placeHolderText) {input.text = character} else {input.text += character};
35     }
36
37     TextInput
38     {
39         id: input
40         anchors.centerIn: parent   
41         color: "#3B3A39"
42         cursorVisible: false
43         activeFocusOnPress: false
44         inputMethodHints: Qt.ImhDialableCharactersOnly
45         font {pixelSize: 42}
46         text: placeHolderText
47
48         Component.onCompleted: forceActiveFocus();
49
50         onTextChanged: {
51             if(text.length == 0) root.clear();
52
53             if(text.length > placeHolderText.length && text.substr(0, placeHolderText.length) == placeHolderText)
54             {
55               text = text.substr(placeHolderText.length);
56             }
57
58             if(text.length < placeHolderText.length && placeHolderText.substr(0, text.length) == text)
59             {
60               text = placeHolderText;
61             }
62
63             if(text == placeHolderText)
64             {
65                 color = "#3B3A39";
66             }
67             else
68             {
69                 color = "#3B3A39";
70             }
71         }
72
73         onAccepted: {
74           main.dial(text)
75         }
76     }
77 }