author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qapplication.h" |
|
43 |
#include "qevent.h" |
|
44 |
#ifdef Q_WS_S60 |
|
45 |
#include "qstyle.h" |
|
46 |
#include "private/qt_s60_p.h" |
|
47 |
#endif |
|
48 |
#include "private/qsoftkeymanager_p.h" |
|
49 |
#include "private/qobject_p.h" |
|
50 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
#ifndef QT_NO_SOFTKEYMANAGER |
0 | 52 |
QT_BEGIN_NAMESPACE |
53 |
||
54 |
#ifdef Q_WS_S60 |
|
55 |
static const int s60CommandStart = 6000; |
|
56 |
#endif |
|
57 |
||
58 |
class QSoftKeyManagerPrivate : public QObjectPrivate |
|
59 |
{ |
|
60 |
Q_DECLARE_PUBLIC(QSoftKeyManager) |
|
61 |
||
62 |
public: |
|
63 |
static void updateSoftKeys_sys(const QList<QAction*> &softKeys); |
|
64 |
||
65 |
private: |
|
66 |
QHash<QAction*, Qt::Key> keyedActions; |
|
67 |
static QSoftKeyManager *self; |
|
68 |
static QWidget *softKeySource; |
|
69 |
}; |
|
70 |
||
71 |
QWidget *QSoftKeyManagerPrivate::softKeySource = 0; |
|
72 |
QSoftKeyManager *QSoftKeyManagerPrivate::self = 0; |
|
73 |
||
74 |
const char *QSoftKeyManager::standardSoftKeyText(StandardSoftKey standardKey) |
|
75 |
{ |
|
76 |
const char *softKeyText = 0; |
|
77 |
switch (standardKey) { |
|
78 |
case OkSoftKey: |
|
79 |
softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Ok"); |
|
80 |
break; |
|
81 |
case SelectSoftKey: |
|
82 |
softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Select"); |
|
83 |
break; |
|
84 |
case DoneSoftKey: |
|
85 |
softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Done"); |
|
86 |
break; |
|
87 |
case MenuSoftKey: |
|
88 |
softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Options"); |
|
89 |
break; |
|
90 |
case CancelSoftKey: |
|
91 |
softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Cancel"); |
|
92 |
break; |
|
93 |
default: |
|
94 |
break; |
|
95 |
}; |
|
96 |
||
97 |
return softKeyText; |
|
98 |
} |
|
99 |
||
100 |
QSoftKeyManager *QSoftKeyManager::instance() |
|
101 |
{ |
|
102 |
if (!QSoftKeyManagerPrivate::self) |
|
103 |
QSoftKeyManagerPrivate::self = new QSoftKeyManager; |
|
104 |
||
105 |
return QSoftKeyManagerPrivate::self; |
|
106 |
} |
|
107 |
||
108 |
QSoftKeyManager::QSoftKeyManager() : QObject(*(new QSoftKeyManagerPrivate), 0) |
|
109 |
{ |
|
110 |
} |
|
111 |
||
112 |
QAction *QSoftKeyManager::createAction(StandardSoftKey standardKey, QWidget *actionWidget) |
|
113 |
{ |
|
114 |
const char* text = standardSoftKeyText(standardKey); |
|
115 |
QAction *action = new QAction(QSoftKeyManager::tr(text), actionWidget); |
|
116 |
QAction::SoftKeyRole softKeyRole = QAction::NoSoftKey; |
|
117 |
switch (standardKey) { |
|
118 |
case OkSoftKey: |
|
119 |
case SelectSoftKey: |
|
120 |
case DoneSoftKey: |
|
121 |
case MenuSoftKey: |
|
122 |
softKeyRole = QAction::PositiveSoftKey; |
|
123 |
break; |
|
124 |
case CancelSoftKey: |
|
125 |
softKeyRole = QAction::NegativeSoftKey; |
|
126 |
break; |
|
127 |
} |
|
128 |
action->setSoftKeyRole(softKeyRole); |
|
129 |
return action; |
|
130 |
} |
|
131 |
||
132 |
/*! \internal |
|
133 |
||
134 |
Creates a QAction and registers the 'triggered' signal to send the given key event to |
|
135 |
\a actionWidget as a convenience. |
|
136 |
||
137 |
*/ |
|
138 |
QAction *QSoftKeyManager::createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget) |
|
139 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
#ifndef QT_NO_ACTION |
0 | 141 |
QScopedPointer<QAction> action(createAction(standardKey, actionWidget)); |
142 |
||
143 |
connect(action.data(), SIGNAL(triggered()), QSoftKeyManager::instance(), SLOT(sendKeyEvent())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
connect(action.data(), SIGNAL(destroyed(QObject*)), QSoftKeyManager::instance(), SLOT(cleanupHash(QObject*))); |
0 | 145 |
QSoftKeyManager::instance()->d_func()->keyedActions.insert(action.data(), key); |
146 |
return action.take(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
#endif //QT_NO_ACTION |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
void QSoftKeyManager::cleanupHash(QObject* obj) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
Q_D(QSoftKeyManager); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
QAction *action = qobject_cast<QAction*>(obj); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
d->keyedActions.remove(action); |
0 | 155 |
} |
156 |
||
157 |
void QSoftKeyManager::sendKeyEvent() |
|
158 |
{ |
|
159 |
Q_D(QSoftKeyManager); |
|
160 |
QAction *action = qobject_cast<QAction*>(sender()); |
|
161 |
||
162 |
if (!action) |
|
163 |
return; |
|
164 |
||
165 |
Qt::Key keyToSend = d->keyedActions.value(action, Qt::Key_unknown); |
|
166 |
||
167 |
if (keyToSend != Qt::Key_unknown) |
|
168 |
QApplication::postEvent(action->parentWidget(), |
|
169 |
new QKeyEvent(QEvent::KeyPress, keyToSend, Qt::NoModifier)); |
|
170 |
} |
|
171 |
||
172 |
void QSoftKeyManager::updateSoftKeys() |
|
173 |
{ |
|
174 |
QEvent *event = new QEvent(QEvent::UpdateSoftKeys); |
|
175 |
QApplication::postEvent(QSoftKeyManager::instance(), event); |
|
176 |
} |
|
177 |
||
178 |
bool QSoftKeyManager::event(QEvent *e) |
|
179 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
#ifndef QT_NO_ACTION |
0 | 181 |
if (e->type() == QEvent::UpdateSoftKeys) { |
182 |
QList<QAction*> softKeys; |
|
183 |
QWidget *source = QApplication::focusWidget(); |
|
184 |
do { |
|
185 |
if (source) { |
|
186 |
QList<QAction*> actions = source->actions(); |
|
187 |
for (int i = 0; i < actions.count(); ++i) { |
|
188 |
if (actions.at(i)->softKeyRole() != QAction::NoSoftKey) |
|
189 |
softKeys.append(actions.at(i)); |
|
190 |
} |
|
191 |
||
192 |
QWidget *parent = source->parentWidget(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
if (parent && softKeys.isEmpty() && !source->isWindow()) |
0 | 194 |
source = parent; |
195 |
else |
|
196 |
break; |
|
197 |
} else { |
|
198 |
source = QApplication::activeWindow(); |
|
199 |
} |
|
200 |
} while (source); |
|
201 |
||
202 |
QSoftKeyManagerPrivate::softKeySource = source; |
|
203 |
QSoftKeyManagerPrivate::updateSoftKeys_sys(softKeys); |
|
204 |
return true; |
|
205 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
#endif //QT_NO_ACTION |
0 | 207 |
return false; |
208 |
} |
|
209 |
||
210 |
#ifdef Q_WS_S60 |
|
211 |
void QSoftKeyManagerPrivate::updateSoftKeys_sys(const QList<QAction*> &softkeys) |
|
212 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
// lets not update softkeys if s60 native dialog or menu is shown |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
if (CCoeEnv::Static()->AppUi()->IsDisplayingMenuOrDialog()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
|
0 | 217 |
CEikButtonGroupContainer* nativeContainer = S60->buttonGroupContainer(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
nativeContainer->DrawableWindow()->SetOrdinalPosition(0); |
0 | 219 |
nativeContainer->DrawableWindow()->SetPointerCapturePriority(1); //keep softkeys available in modal dialog |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
nativeContainer->DrawableWindow()->SetFaded(EFalse, RWindowTreeNode::EFadeIncludeChildren); |
0 | 221 |
|
222 |
int position = -1; |
|
223 |
bool needsExitButton = true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
QT_TRAP_THROWING( |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
//Using -1 instead of EAknSoftkeyEmpty to avoid flickering. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
nativeContainer->SetCommandL(0, -1, KNullDesC); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
nativeContainer->SetCommandL(2, -1, KNullDesC); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
); |
0 | 229 |
|
230 |
for (int index = 0; index < softkeys.count(); index++) { |
|
231 |
const QAction* softKeyAction = softkeys.at(index); |
|
232 |
switch (softKeyAction->softKeyRole()) { |
|
233 |
// Positive Actions on the LSK |
|
234 |
case QAction::PositiveSoftKey: |
|
235 |
position = 0; |
|
236 |
break; |
|
237 |
case QAction::SelectSoftKey: |
|
238 |
position = 0; |
|
239 |
break; |
|
240 |
// Negative Actions on the RSK |
|
241 |
case QAction::NegativeSoftKey: |
|
242 |
needsExitButton = false; |
|
243 |
position = 2; |
|
244 |
break; |
|
245 |
default: |
|
246 |
break; |
|
247 |
} |
|
248 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
int command = (softKeyAction->objectName().contains(QLatin1String("_q_menuSoftKeyAction"))) |
0 | 250 |
? EAknSoftkeyOptions |
251 |
: s60CommandStart + index; |
|
252 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
// _q_menuSoftKeyAction action is set to "invisible" and all invisible actions are by default |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
// disabled. However we never want to dim options softkey, even it is set to "invisible" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
bool dimmed = (command == EAknSoftkeyOptions) ? false : !softKeyAction->isEnabled(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
|
0 | 257 |
if (position != -1) { |
258 |
const int underlineShortCut = QApplication::style()->styleHint(QStyle::SH_UnderlineShortcut); |
|
259 |
QString iconText = softKeyAction->iconText(); |
|
260 |
TPtrC text = qt_QString2TPtrC( underlineShortCut ? softKeyAction->text() : iconText); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
QT_TRAP_THROWING( |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
nativeContainer->SetCommandL(position, command, text); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
nativeContainer->DimCommand(command, dimmed); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
); |
0 | 265 |
} |
266 |
} |
|
267 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
const Qt::WindowType sourceWindowType = QSoftKeyManagerPrivate::softKeySource |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
? QSoftKeyManagerPrivate::softKeySource->window()->windowType() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
: Qt::Widget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
if (needsExitButton && sourceWindowType != Qt::Dialog && sourceWindowType != Qt::Popup) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
QT_TRAP_THROWING( |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
nativeContainer->SetCommandL(2, EAknSoftkeyExit, qt_QString2TPtrC(QSoftKeyManager::tr("Exit")))); |
0 | 275 |
|
276 |
nativeContainer->DrawDeferred(); // 3.1 needs an extra invitation |
|
277 |
} |
|
278 |
||
279 |
bool QSoftKeyManager::handleCommand(int command) |
|
280 |
{ |
|
281 |
if (command >= s60CommandStart && QSoftKeyManagerPrivate::softKeySource) { |
|
282 |
int index = command - s60CommandStart; |
|
283 |
const QList<QAction*>& softKeys = QSoftKeyManagerPrivate::softKeySource->actions(); |
|
284 |
for (int i = 0, j = 0; i < softKeys.count(); ++i) { |
|
285 |
QAction *action = softKeys.at(i); |
|
286 |
if (action->softKeyRole() != QAction::NoSoftKey) { |
|
287 |
if (j == index) { |
|
288 |
QWidget *parent = action->parentWidget(); |
|
289 |
if (parent && parent->isEnabled()) { |
|
290 |
action->activate(QAction::Trigger); |
|
291 |
return true; |
|
292 |
} |
|
293 |
} |
|
294 |
j++; |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
return false; |
|
300 |
} |
|
301 |
||
302 |
#else |
|
303 |
||
304 |
void QSoftKeyManagerPrivate::updateSoftKeys_sys(const QList<QAction*> &) |
|
305 |
{ |
|
306 |
} |
|
307 |
||
308 |
#endif |
|
309 |
||
310 |
QT_END_NAMESPACE |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
#endif //QT_NO_SOFTKEYMANAGER |