134 \a actionWidget as a convenience. |
135 \a actionWidget as a convenience. |
135 |
136 |
136 */ |
137 */ |
137 QAction *QSoftKeyManager::createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget) |
138 QAction *QSoftKeyManager::createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget) |
138 { |
139 { |
|
140 #ifndef QT_NO_ACTION |
139 QScopedPointer<QAction> action(createAction(standardKey, actionWidget)); |
141 QScopedPointer<QAction> action(createAction(standardKey, actionWidget)); |
140 |
142 |
141 connect(action.data(), SIGNAL(triggered()), QSoftKeyManager::instance(), SLOT(sendKeyEvent())); |
143 connect(action.data(), SIGNAL(triggered()), QSoftKeyManager::instance(), SLOT(sendKeyEvent())); |
142 |
144 connect(action.data(), SIGNAL(destroyed(QObject*)), QSoftKeyManager::instance(), SLOT(cleanupHash(QObject*))); |
143 QSoftKeyManager::instance()->d_func()->keyedActions.insert(action.data(), key); |
145 QSoftKeyManager::instance()->d_func()->keyedActions.insert(action.data(), key); |
144 return action.take(); |
146 return action.take(); |
|
147 #endif //QT_NO_ACTION |
|
148 } |
|
149 |
|
150 void QSoftKeyManager::cleanupHash(QObject* obj) |
|
151 { |
|
152 Q_D(QSoftKeyManager); |
|
153 QAction *action = qobject_cast<QAction*>(obj); |
|
154 d->keyedActions.remove(action); |
145 } |
155 } |
146 |
156 |
147 void QSoftKeyManager::sendKeyEvent() |
157 void QSoftKeyManager::sendKeyEvent() |
148 { |
158 { |
149 Q_D(QSoftKeyManager); |
159 Q_D(QSoftKeyManager); |
165 QApplication::postEvent(QSoftKeyManager::instance(), event); |
175 QApplication::postEvent(QSoftKeyManager::instance(), event); |
166 } |
176 } |
167 |
177 |
168 bool QSoftKeyManager::event(QEvent *e) |
178 bool QSoftKeyManager::event(QEvent *e) |
169 { |
179 { |
|
180 #ifndef QT_NO_ACTION |
170 if (e->type() == QEvent::UpdateSoftKeys) { |
181 if (e->type() == QEvent::UpdateSoftKeys) { |
171 QList<QAction*> softKeys; |
182 QList<QAction*> softKeys; |
172 QWidget *source = QApplication::focusWidget(); |
183 QWidget *source = QApplication::focusWidget(); |
173 do { |
184 do { |
174 if (source) { |
185 if (source) { |
177 if (actions.at(i)->softKeyRole() != QAction::NoSoftKey) |
188 if (actions.at(i)->softKeyRole() != QAction::NoSoftKey) |
178 softKeys.append(actions.at(i)); |
189 softKeys.append(actions.at(i)); |
179 } |
190 } |
180 |
191 |
181 QWidget *parent = source->parentWidget(); |
192 QWidget *parent = source->parentWidget(); |
182 if (parent && softKeys.isEmpty()) |
193 if (parent && softKeys.isEmpty() && !source->isWindow()) |
183 source = parent; |
194 source = parent; |
184 else |
195 else |
185 break; |
196 break; |
186 } else { |
197 } else { |
187 source = QApplication::activeWindow(); |
198 source = QApplication::activeWindow(); |
190 |
201 |
191 QSoftKeyManagerPrivate::softKeySource = source; |
202 QSoftKeyManagerPrivate::softKeySource = source; |
192 QSoftKeyManagerPrivate::updateSoftKeys_sys(softKeys); |
203 QSoftKeyManagerPrivate::updateSoftKeys_sys(softKeys); |
193 return true; |
204 return true; |
194 } |
205 } |
|
206 #endif //QT_NO_ACTION |
195 return false; |
207 return false; |
196 } |
208 } |
197 |
209 |
198 #ifdef Q_WS_S60 |
210 #ifdef Q_WS_S60 |
199 void QSoftKeyManagerPrivate::updateSoftKeys_sys(const QList<QAction*> &softkeys) |
211 void QSoftKeyManagerPrivate::updateSoftKeys_sys(const QList<QAction*> &softkeys) |
200 { |
212 { |
|
213 // lets not update softkeys if s60 native dialog or menu is shown |
|
214 if (CCoeEnv::Static()->AppUi()->IsDisplayingMenuOrDialog()) |
|
215 return; |
|
216 |
201 CEikButtonGroupContainer* nativeContainer = S60->buttonGroupContainer(); |
217 CEikButtonGroupContainer* nativeContainer = S60->buttonGroupContainer(); |
|
218 nativeContainer->DrawableWindow()->SetOrdinalPosition(0); |
202 nativeContainer->DrawableWindow()->SetPointerCapturePriority(1); //keep softkeys available in modal dialog |
219 nativeContainer->DrawableWindow()->SetPointerCapturePriority(1); //keep softkeys available in modal dialog |
203 QT_TRAP_THROWING(nativeContainer->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY_WITH_IDS)); |
220 nativeContainer->DrawableWindow()->SetFaded(EFalse, RWindowTreeNode::EFadeIncludeChildren); |
204 |
221 |
205 int position = -1; |
222 int position = -1; |
206 int command; |
|
207 bool needsExitButton = true; |
223 bool needsExitButton = true; |
|
224 QT_TRAP_THROWING( |
|
225 //Using -1 instead of EAknSoftkeyEmpty to avoid flickering. |
|
226 nativeContainer->SetCommandL(0, -1, KNullDesC); |
|
227 nativeContainer->SetCommandL(2, -1, KNullDesC); |
|
228 ); |
208 |
229 |
209 for (int index = 0; index < softkeys.count(); index++) { |
230 for (int index = 0; index < softkeys.count(); index++) { |
210 const QAction* softKeyAction = softkeys.at(index); |
231 const QAction* softKeyAction = softkeys.at(index); |
211 switch (softKeyAction->softKeyRole()) { |
232 switch (softKeyAction->softKeyRole()) { |
212 // Positive Actions on the LSK |
233 // Positive Actions on the LSK |
223 break; |
244 break; |
224 default: |
245 default: |
225 break; |
246 break; |
226 } |
247 } |
227 |
248 |
228 command = (softKeyAction->objectName().contains("_q_menuSoftKeyAction")) |
249 int command = (softKeyAction->objectName().contains(QLatin1String("_q_menuSoftKeyAction"))) |
229 ? EAknSoftkeyOptions |
250 ? EAknSoftkeyOptions |
230 : s60CommandStart + index; |
251 : s60CommandStart + index; |
|
252 |
|
253 // _q_menuSoftKeyAction action is set to "invisible" and all invisible actions are by default |
|
254 // disabled. However we never want to dim options softkey, even it is set to "invisible" |
|
255 bool dimmed = (command == EAknSoftkeyOptions) ? false : !softKeyAction->isEnabled(); |
231 |
256 |
232 if (position != -1) { |
257 if (position != -1) { |
233 const int underlineShortCut = QApplication::style()->styleHint(QStyle::SH_UnderlineShortcut); |
258 const int underlineShortCut = QApplication::style()->styleHint(QStyle::SH_UnderlineShortcut); |
234 QString iconText = softKeyAction->iconText(); |
259 QString iconText = softKeyAction->iconText(); |
235 TPtrC text = qt_QString2TPtrC( underlineShortCut ? softKeyAction->text() : iconText); |
260 TPtrC text = qt_QString2TPtrC( underlineShortCut ? softKeyAction->text() : iconText); |
236 QT_TRAP_THROWING(nativeContainer->SetCommandL(position, command, text)); |
261 QT_TRAP_THROWING( |
|
262 nativeContainer->SetCommandL(position, command, text); |
|
263 nativeContainer->DimCommand(command, dimmed); |
|
264 ); |
237 } |
265 } |
238 } |
266 } |
239 |
267 |
240 if (needsExitButton) |
268 const Qt::WindowType sourceWindowType = QSoftKeyManagerPrivate::softKeySource |
241 QT_TRAP_THROWING(nativeContainer->SetCommandL(2, EAknSoftkeyExit, qt_QString2TPtrC(QSoftKeyManager::tr("Exit")))); |
269 ? QSoftKeyManagerPrivate::softKeySource->window()->windowType() |
|
270 : Qt::Widget; |
|
271 |
|
272 if (needsExitButton && sourceWindowType != Qt::Dialog && sourceWindowType != Qt::Popup) |
|
273 QT_TRAP_THROWING( |
|
274 nativeContainer->SetCommandL(2, EAknSoftkeyExit, qt_QString2TPtrC(QSoftKeyManager::tr("Exit")))); |
242 |
275 |
243 nativeContainer->DrawDeferred(); // 3.1 needs an extra invitation |
276 nativeContainer->DrawDeferred(); // 3.1 needs an extra invitation |
244 } |
277 } |
245 |
278 |
246 bool QSoftKeyManager::handleCommand(int command) |
279 bool QSoftKeyManager::handleCommand(int command) |