|
1 /*! |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Input field |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtGui> |
|
19 |
|
20 #include <hblineedit.h> |
|
21 #include <hbinputeditorinterface.h> |
|
22 #include <hbinputstandardfilters.h> |
|
23 #include <hbdeviceprofile.h> |
|
24 |
|
25 #include "dialpadinputfield.h" |
|
26 #include "dialpadbuttonstyle.h" |
|
27 #include "dialpadbutton.h" |
|
28 |
|
29 static const QString HbBackspaceIcon(":/inputmethods/qtg_mono_backspace2"); |
|
30 static const int DialpadAutoRepeatInterval = 150; // ms |
|
31 static const int DialpadAutoRepeatDelay = 1000; // ms |
|
32 static const qreal DialpadComponentMargin = 0.75; // units |
|
33 static const qreal DialpadBackspaceHeight = 9.4; // units |
|
34 static const qreal DialpadInputFieldHeight = 6.3; // units |
|
35 |
|
36 DialpadInputField::DialpadInputField(QGraphicsItem* parent) |
|
37 : HbWidget(parent) |
|
38 { |
|
39 // create editor |
|
40 mNumberEditor = new HbLineEdit(this); |
|
41 HbEditorInterface editorInterface(mNumberEditor); |
|
42 editorInterface.setFilter(HbPhoneNumberFilter::instance()); |
|
43 editorInterface.setUpAsPhoneNumberEditor(); |
|
44 editorInterface.setConstraints(HbEditorConstraintIgnoreFocus); |
|
45 |
|
46 // create backspace button |
|
47 mBackspace = new DialpadButton(this); |
|
48 mFunctionButtonStyle = new DialpadButtonStyle(); |
|
49 mFunctionButtonStyle->setButtonStyle( |
|
50 DialpadButtonStyle::FunctionButtonStyle); |
|
51 mBackspace->setStyle(mFunctionButtonStyle); |
|
52 mBackspace->setFocusPolicy(Qt::NoFocus); |
|
53 mBackspace->setFlag(QGraphicsItem::ItemIsFocusable,false); |
|
54 mBackspace->setIcon(HbIcon(HbBackspaceIcon)); |
|
55 mBackspace->setEnabled(false); |
|
56 QString buttonName; |
|
57 buttonName.setNum(Qt::Key_Backspace); |
|
58 mBackspace->setObjectName(buttonName); |
|
59 mBackspace->setAutoRepeat(true); |
|
60 mBackspace->setAutoRepeatInterval(DialpadAutoRepeatInterval); |
|
61 mBackspace->setAutoRepeatDelay(DialpadAutoRepeatDelay); |
|
62 |
|
63 connect(mNumberEditor,SIGNAL(contentsChanged()), |
|
64 SLOT(onEditorContentChanged())); |
|
65 |
|
66 // set input field layout |
|
67 qreal unit = HbDeviceProfile::current().unitValue(); |
|
68 mHeight = (int) DialpadInputFieldHeight * unit; |
|
69 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout; |
|
70 layout->addItem(mNumberEditor); |
|
71 layout->setAlignment(mNumberEditor,Qt::AlignVCenter); |
|
72 layout->addItem(mBackspace); |
|
73 layout->setContentsMargins(0,0,0,0); |
|
74 layout->setSpacing(DialpadComponentMargin* unit); |
|
75 // layout parameters |
|
76 mBackspace->setPreferredWidth(DialpadBackspaceHeight * unit); |
|
77 mBackspace->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding); |
|
78 setLayout(layout); |
|
79 |
|
80 HbFontSpec editFont(HbFontSpec::Primary); |
|
81 // 85% of input field height |
|
82 editFont.setTextHeight(mHeight*0.85); |
|
83 mNumberEditor->setFontSpec(editFont); |
|
84 } |
|
85 |
|
86 DialpadInputField::~DialpadInputField() |
|
87 { |
|
88 delete mFunctionButtonStyle; |
|
89 } |
|
90 |
|
91 HbLineEdit& DialpadInputField::editor() const |
|
92 { |
|
93 return *mNumberEditor; |
|
94 } |
|
95 |
|
96 DialpadButton& DialpadInputField::backspaceButton() const |
|
97 { |
|
98 return *mBackspace; |
|
99 } |
|
100 |
|
101 void DialpadInputField::onEditorContentChanged() |
|
102 { |
|
103 mBackspace->setEnabled(mNumberEditor->text().length()); |
|
104 } |
|
105 |
|
106 QSizeF DialpadInputField::sizeHint( |
|
107 Qt::SizeHint which, |
|
108 const QSizeF & constraint) const |
|
109 { |
|
110 Q_UNUSED(which); |
|
111 Q_UNUSED(constraint); |
|
112 |
|
113 // input field height is fixed |
|
114 QSizeF sh; |
|
115 sh.setHeight(mHeight); |
|
116 return sh; |
|
117 } |