|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbInput module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <QPainter> |
|
27 #include <QPointer> |
|
28 #include <hbicon.h> |
|
29 #include <hbinputmethod.h> |
|
30 #include <hbinputeditorinterface.h> |
|
31 #include <hbinputmodeindicator.h> |
|
32 #include <hbinputfocusobject.h> |
|
33 #include <hbinputsettingproxy.h> |
|
34 |
|
35 /// @cond |
|
36 |
|
37 class HbInputModeIndicatorPrivate |
|
38 { |
|
39 public: |
|
40 HbInputModeIndicatorPrivate(HbTouchKeypadButton& button); |
|
41 ~HbInputModeIndicatorPrivate(); |
|
42 |
|
43 void updatePrediction(); |
|
44 public: |
|
45 HbTouchKeypadButton& mButton; |
|
46 QPointer<HbInputFocusObject> mFocusObject; |
|
47 }; |
|
48 |
|
49 HbInputModeIndicatorPrivate::HbInputModeIndicatorPrivate(HbTouchKeypadButton& button) |
|
50 : mButton(button), |
|
51 mFocusObject(0) |
|
52 { |
|
53 if (HbInputMethod::activeInputMethod()) { |
|
54 mFocusObject = HbInputMethod::activeInputMethod()->focusObject(); |
|
55 } |
|
56 } |
|
57 |
|
58 HbInputModeIndicatorPrivate::~HbInputModeIndicatorPrivate() |
|
59 { |
|
60 } |
|
61 |
|
62 void HbInputModeIndicatorPrivate::updatePrediction() |
|
63 { |
|
64 const QString predictionOnIcon("qtg_mono_predictive_text_on"); |
|
65 const QString predictionOffIcon("qtg_mono_predictive_text_off"); |
|
66 |
|
67 if (HbInputSettingProxy::instance()->predictiveInputStatus()) { |
|
68 mButton.setIcon(HbIcon(predictionOnIcon)); |
|
69 } else { |
|
70 mButton.setIcon(HbIcon(predictionOffIcon)); |
|
71 } |
|
72 } |
|
73 |
|
74 /// @endcond |
|
75 |
|
76 /*! |
|
77 @proto |
|
78 @hbinput |
|
79 \class HbInputModeIndicator |
|
80 \brief Predictive mode indicator |
|
81 |
|
82 Implements automatic mechanism which updates the prediction icon of keypad button based on current predictive status. |
|
83 |
|
84 \sa HbEditorInterface |
|
85 */ |
|
86 |
|
87 /*! |
|
88 Constructor. |
|
89 @param button the keypad button which shows input mode icon |
|
90 @param parent parent of the widget. |
|
91 */ |
|
92 HbInputModeIndicator::HbInputModeIndicator(HbTouchKeypadButton& button, QGraphicsWidget* parent) |
|
93 : QObject(parent) |
|
94 { |
|
95 mPrivate = new HbInputModeIndicatorPrivate(button); |
|
96 if (mPrivate->mFocusObject) { |
|
97 connect( &mPrivate->mFocusObject->editorInterface(), SIGNAL(modified()), this, SLOT(updateIndicator())); |
|
98 } |
|
99 connect(HbInputSettingProxy::instance(), SIGNAL(predictiveInputStateChanged(int)), this, SLOT(udpdatePredictionStatus(int))); |
|
100 updateIndicator(); // check mode of current editor |
|
101 } |
|
102 |
|
103 /*! |
|
104 Destroys the widget. |
|
105 */ |
|
106 HbInputModeIndicator::~HbInputModeIndicator() |
|
107 { |
|
108 delete mPrivate; |
|
109 } |
|
110 |
|
111 /*! |
|
112 Updates the indicator. |
|
113 */ |
|
114 void HbInputModeIndicator::updateIndicator() |
|
115 { |
|
116 if (!mPrivate->mFocusObject) { |
|
117 if (HbInputMethod::activeInputMethod()) { |
|
118 mPrivate->mFocusObject = HbInputMethod::activeInputMethod()->focusObject(); |
|
119 if (mPrivate->mFocusObject) { |
|
120 connect( &mPrivate->mFocusObject->editorInterface(), SIGNAL(modified()), this, SLOT(updateIndicator())); |
|
121 } else { |
|
122 return; |
|
123 } |
|
124 } else { |
|
125 return; |
|
126 } |
|
127 } |
|
128 |
|
129 mPrivate->updatePrediction(); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Updates prediction status. |
|
134 */ |
|
135 void HbInputModeIndicator::udpdatePredictionStatus(int newStatus) |
|
136 { |
|
137 Q_UNUSED(newStatus); |
|
138 mPrivate->updatePrediction(); |
|
139 } |
|
140 |
|
141 // End of file |