166 |
168 |
167 bool QSoftKeyManager::appendSoftkeys(const QWidget &source, int level) |
169 bool QSoftKeyManager::appendSoftkeys(const QWidget &source, int level) |
168 { |
170 { |
169 Q_D(QSoftKeyManager); |
171 Q_D(QSoftKeyManager); |
170 bool ret = false; |
172 bool ret = false; |
171 QList<QAction*> actions = source.actions(); |
173 foreach(QAction *action, source.actions()) { |
172 for (int i = 0; i < actions.count(); ++i) { |
174 if (action->softKeyRole() != QAction::NoSoftKey |
173 if (actions.at(i)->softKeyRole() != QAction::NoSoftKey) { |
175 && (action->isVisible() || isForceEnabledInSofkeys(action))) { |
174 d->requestedSoftKeyActions.insert(level, actions.at(i)); |
176 d->requestedSoftKeyActions.insert(level, action); |
175 ret = true; |
177 ret = true; |
176 } |
178 } |
177 } |
179 } |
178 return ret; |
180 return ret; |
|
181 } |
|
182 |
|
183 |
|
184 static bool isChildOf(const QWidget *c, const QWidget *p) |
|
185 { |
|
186 while (c) { |
|
187 if (c == p) |
|
188 return true; |
|
189 c = c->parentWidget(); |
|
190 } |
|
191 return false; |
179 } |
192 } |
180 |
193 |
181 QWidget *QSoftKeyManager::softkeySource(QWidget *previousSource, bool& recursiveMerging) |
194 QWidget *QSoftKeyManager::softkeySource(QWidget *previousSource, bool& recursiveMerging) |
182 { |
195 { |
183 Q_D(QSoftKeyManager); |
196 Q_D(QSoftKeyManager); |
184 QWidget *source = NULL; |
197 QWidget *source = NULL; |
185 if (!previousSource) { |
198 if (!previousSource) { |
186 // Initial source is primarily focuswidget and secondarily activeWindow |
199 // Initial source is primarily focuswidget and secondarily activeWindow |
187 source = QApplication::focusWidget(); |
200 QWidget *focus = QApplication::focusWidget(); |
188 if (!source) |
201 QWidget *popup = QApplication::activePopupWidget(); |
189 source = QApplication::activeWindow(); |
202 if (popup) { |
|
203 if (isChildOf(focus, popup)) |
|
204 source = focus; |
|
205 else |
|
206 source = popup; |
|
207 } |
|
208 if (!source) { |
|
209 QWidget *modal = QApplication::activeModalWidget(); |
|
210 if (modal) { |
|
211 if (isChildOf(focus, modal)) |
|
212 source = focus; |
|
213 else |
|
214 source = modal; |
|
215 } |
|
216 } |
|
217 if (!source) { |
|
218 source = focus; |
|
219 if (!source) |
|
220 source = QApplication::activeWindow(); |
|
221 } |
190 } else { |
222 } else { |
191 // Softkey merging is based on four criterias |
223 // Softkey merging is based on four criterias |
192 // 1. Implicit merging is used whenever focus widget does not specify any softkeys |
224 // 1. Implicit merging is used whenever focus widget does not specify any softkeys |
193 bool implicitMerging = d->requestedSoftKeyActions.isEmpty(); |
225 bool implicitMerging = d->requestedSoftKeyActions.isEmpty(); |
194 // 2. Explicit merging with parent is used whenever WA_MergeSoftkeys widget attribute is set |
226 // 2. Explicit merging with parent is used whenever WA_MergeSoftkeys widget attribute is set |
218 |
250 |
219 d->updateSoftKeys_sys(); |
251 d->updateSoftKeys_sys(); |
220 return true; |
252 return true; |
221 } |
253 } |
222 |
254 |
|
255 void QSoftKeyManager::setForceEnabledInSoftkeys(QAction *action) |
|
256 { |
|
257 action->setProperty(FORCE_ENABLED_PROPERTY, QVariant(true)); |
|
258 } |
|
259 |
|
260 bool QSoftKeyManager::isForceEnabledInSofkeys(QAction *action) |
|
261 { |
|
262 bool ret = false; |
|
263 QVariant property = action->property(FORCE_ENABLED_PROPERTY); |
|
264 if (property.isValid() && property.toBool()) |
|
265 ret = true; |
|
266 return ret; |
|
267 } |
|
268 |
223 bool QSoftKeyManager::event(QEvent *e) |
269 bool QSoftKeyManager::event(QEvent *e) |
224 { |
270 { |
225 #ifndef QT_NO_ACTION |
271 #ifndef QT_NO_ACTION |
226 if (e->type() == QEvent::UpdateSoftKeys) |
272 if (e->type() == QEvent::UpdateSoftKeys) |
227 return handleUpdateSoftKeys(); |
273 return handleUpdateSoftKeys(); |