53 #ifndef QT_NO_SOFTKEYMANAGER |
53 #ifndef QT_NO_SOFTKEYMANAGER |
54 QT_BEGIN_NAMESPACE |
54 QT_BEGIN_NAMESPACE |
55 |
55 |
56 QSoftKeyManager *QSoftKeyManagerPrivate::self = 0; |
56 QSoftKeyManager *QSoftKeyManagerPrivate::self = 0; |
57 |
57 |
58 const char *QSoftKeyManager::standardSoftKeyText(StandardSoftKey standardKey) |
58 QString QSoftKeyManager::standardSoftKeyText(StandardSoftKey standardKey) |
59 { |
59 { |
60 const char *softKeyText = 0; |
60 QString softKeyText; |
61 switch (standardKey) { |
61 switch (standardKey) { |
62 case OkSoftKey: |
62 case OkSoftKey: |
63 softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Ok"); |
63 softKeyText = QSoftKeyManager::tr("Ok"); |
64 break; |
64 break; |
65 case SelectSoftKey: |
65 case SelectSoftKey: |
66 softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Select"); |
66 softKeyText = QSoftKeyManager::tr("Select"); |
67 break; |
67 break; |
68 case DoneSoftKey: |
68 case DoneSoftKey: |
69 softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Done"); |
69 softKeyText = QSoftKeyManager::tr("Done"); |
70 break; |
70 break; |
71 case MenuSoftKey: |
71 case MenuSoftKey: |
72 softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Options"); |
72 softKeyText = QSoftKeyManager::tr("Options"); |
73 break; |
73 break; |
74 case CancelSoftKey: |
74 case CancelSoftKey: |
75 softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Cancel"); |
75 softKeyText = QSoftKeyManager::tr("Cancel"); |
76 break; |
76 break; |
77 default: |
77 default: |
78 break; |
78 break; |
79 }; |
79 }; |
80 |
80 |
98 { |
98 { |
99 } |
99 } |
100 |
100 |
101 QAction *QSoftKeyManager::createAction(StandardSoftKey standardKey, QWidget *actionWidget) |
101 QAction *QSoftKeyManager::createAction(StandardSoftKey standardKey, QWidget *actionWidget) |
102 { |
102 { |
103 const char* text = standardSoftKeyText(standardKey); |
103 QAction *action = new QAction(standardSoftKeyText(standardKey), actionWidget); |
104 QAction *action = new QAction(QSoftKeyManager::tr(text), actionWidget); |
|
105 QAction::SoftKeyRole softKeyRole = QAction::NoSoftKey; |
104 QAction::SoftKeyRole softKeyRole = QAction::NoSoftKey; |
106 switch (standardKey) { |
105 switch (standardKey) { |
107 case MenuSoftKey: // FALL-THROUGH |
106 case MenuSoftKey: // FALL-THROUGH |
108 action->setProperty(MENU_ACTION_PROPERTY, QVariant(true)); // TODO: can be refactored away to use _q_action_menubar |
107 action->setProperty(MENU_ACTION_PROPERTY, QVariant(true)); // TODO: can be refactored away to use _q_action_menubar |
109 case OkSoftKey: |
108 case OkSoftKey: |
167 |
168 |
168 bool QSoftKeyManager::appendSoftkeys(const QWidget &source, int level) |
169 bool QSoftKeyManager::appendSoftkeys(const QWidget &source, int level) |
169 { |
170 { |
170 Q_D(QSoftKeyManager); |
171 Q_D(QSoftKeyManager); |
171 bool ret = false; |
172 bool ret = false; |
172 QList<QAction*> actions = source.actions(); |
173 foreach(QAction *action, source.actions()) { |
173 for (int i = 0; i < actions.count(); ++i) { |
174 if (action->softKeyRole() != QAction::NoSoftKey |
174 if (actions.at(i)->softKeyRole() != QAction::NoSoftKey) { |
175 && (action->isVisible() || isForceEnabledInSofkeys(action))) { |
175 d->requestedSoftKeyActions.insert(level, actions.at(i)); |
176 d->requestedSoftKeyActions.insert(level, action); |
176 ret = true; |
177 ret = true; |
177 } |
178 } |
178 } |
179 } |
179 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; |
180 } |
192 } |
181 |
193 |
182 QWidget *QSoftKeyManager::softkeySource(QWidget *previousSource, bool& recursiveMerging) |
194 QWidget *QSoftKeyManager::softkeySource(QWidget *previousSource, bool& recursiveMerging) |
183 { |
195 { |
184 Q_D(QSoftKeyManager); |
196 Q_D(QSoftKeyManager); |
185 QWidget *source = NULL; |
197 QWidget *source = NULL; |
186 if (!previousSource) { |
198 if (!previousSource) { |
187 // Initial source is primarily focuswidget and secondarily activeWindow |
199 // Initial source is primarily focuswidget and secondarily activeWindow |
188 source = QApplication::focusWidget(); |
200 QWidget *focus = QApplication::focusWidget(); |
189 if (!source) |
201 QWidget *popup = QApplication::activePopupWidget(); |
190 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 } |
191 } else { |
222 } else { |
192 // Softkey merging is based on four criterias |
223 // Softkey merging is based on four criterias |
193 // 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 |
194 bool implicitMerging = d->requestedSoftKeyActions.isEmpty(); |
225 bool implicitMerging = d->requestedSoftKeyActions.isEmpty(); |
195 // 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 |
209 Q_D(QSoftKeyManager); |
240 Q_D(QSoftKeyManager); |
210 int level = 0; |
241 int level = 0; |
211 d->requestedSoftKeyActions.clear(); |
242 d->requestedSoftKeyActions.clear(); |
212 bool recursiveMerging = false; |
243 bool recursiveMerging = false; |
213 QWidget *source = softkeySource(NULL, recursiveMerging); |
244 QWidget *source = softkeySource(NULL, recursiveMerging); |
214 do { |
245 while (source) { |
215 if (source) { |
246 if (appendSoftkeys(*source, level)) |
216 bool added = appendSoftkeys(*source, level); |
247 ++level; |
217 source = softkeySource(source, recursiveMerging); |
248 source = softkeySource(source, recursiveMerging); |
218 level = added ? ++level : level; |
249 } |
219 } |
|
220 } while (source); |
|
221 |
250 |
222 d->updateSoftKeys_sys(); |
251 d->updateSoftKeys_sys(); |
223 return true; |
252 return true; |
|
253 } |
|
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; |
224 } |
267 } |
225 |
268 |
226 bool QSoftKeyManager::event(QEvent *e) |
269 bool QSoftKeyManager::event(QEvent *e) |
227 { |
270 { |
228 #ifndef QT_NO_ACTION |
271 #ifndef QT_NO_ACTION |