author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
child 8 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the S60 port 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 "qmenu.h" |
|
43 |
#include "qapplication.h" |
|
44 |
#include "qevent.h" |
|
45 |
#include "qstyle.h" |
|
46 |
#include "qdebug.h" |
|
47 |
#include "qwidgetaction.h" |
|
48 |
#include <private/qapplication_p.h> |
|
49 |
#include <private/qmenu_p.h> |
|
50 |
#include <private/qmenubar_p.h> |
|
51 |
#include <qt_s60_p.h> |
|
52 |
#include <QtCore/qlibrary.h> |
|
53 |
||
54 |
#ifdef Q_WS_S60 |
|
55 |
#include <eikmenub.h> |
|
56 |
#include <eikmenup.h> |
|
57 |
#include <eikaufty.h> |
|
58 |
#include <eikbtgpc.h> |
|
59 |
#include <avkon.rsg> |
|
60 |
#endif |
|
61 |
||
62 |
#if !defined(QT_NO_MENUBAR) && defined(Q_WS_S60) |
|
63 |
||
64 |
QT_BEGIN_NAMESPACE |
|
65 |
||
66 |
typedef QMultiHash<QWidget *, QMenuBarPrivate *> MenuBarHash; |
|
67 |
Q_GLOBAL_STATIC(MenuBarHash, menubars) |
|
68 |
||
69 |
struct SymbianMenuItem |
|
70 |
{ |
|
71 |
int id; |
|
72 |
CEikMenuPaneItem::SData menuItemData; |
|
73 |
QList<SymbianMenuItem*> children; |
|
74 |
QAction* action; |
|
75 |
}; |
|
76 |
||
77 |
Q_GLOBAL_STATIC_WITH_ARGS(QAction, contextAction, (0)) |
|
78 |
||
79 |
static QList<SymbianMenuItem*> symbianMenus; |
|
80 |
static QList<QMenuBar*> nativeMenuBars; |
|
81 |
static uint qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM; |
|
82 |
static QPointer<QWidget> widgetWithContextMenu; |
|
83 |
static QList<QAction*> contextMenuActionList; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
84 |
static QWidget* actionMenu = NULL; |
0 | 85 |
static int contexMenuCommand=0; |
86 |
||
87 |
bool menuExists() |
|
88 |
{ |
|
89 |
QWidget *w = qApp->activeWindow(); |
|
90 |
QMenuBarPrivate *mb = menubars()->value(w); |
|
91 |
if ((!mb) && !menubars()->count()) |
|
92 |
return false; |
|
93 |
return true; |
|
94 |
} |
|
95 |
||
96 |
static bool hasContextMenu(QWidget* widget) |
|
97 |
{ |
|
98 |
if (!widget) |
|
99 |
return false; |
|
100 |
const Qt::ContextMenuPolicy policy = widget->contextMenuPolicy(); |
|
101 |
if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { |
|
102 |
return true; |
|
103 |
} |
|
104 |
return false; |
|
105 |
} |
|
106 |
||
107 |
static SymbianMenuItem* qt_symbian_find_menu(int id, const QList<SymbianMenuItem*> &parent) |
|
108 |
{ |
|
109 |
int index=0; |
|
110 |
while (index < parent.count()) { |
|
111 |
SymbianMenuItem* temp = parent[index]; |
|
112 |
if (temp->menuItemData.iCascadeId == id) |
|
113 |
return temp; |
|
114 |
else if (temp->menuItemData.iCascadeId != 0) { |
|
115 |
SymbianMenuItem* result = qt_symbian_find_menu( id, temp->children); |
|
116 |
if (result) |
|
117 |
return result; |
|
118 |
} |
|
119 |
index++; |
|
120 |
} |
|
121 |
return 0; |
|
122 |
} |
|
123 |
||
124 |
static SymbianMenuItem* qt_symbian_find_menu_item(int id, const QList<SymbianMenuItem*> &parent) |
|
125 |
{ |
|
126 |
int index=0; |
|
127 |
while (index < parent.count()) { |
|
128 |
SymbianMenuItem* temp = parent[index]; |
|
129 |
if (temp->menuItemData.iCascadeId != 0) { |
|
130 |
SymbianMenuItem* result = qt_symbian_find_menu_item( id, temp->children); |
|
131 |
if (result) |
|
132 |
return result; |
|
133 |
} |
|
134 |
else if (temp->menuItemData.iCommandId == id) |
|
135 |
return temp; |
|
136 |
index++; |
|
137 |
||
138 |
} |
|
139 |
return 0; |
|
140 |
} |
|
141 |
||
142 |
static void qt_symbian_insert_action(QSymbianMenuAction* action, QList<SymbianMenuItem*>* parent) |
|
143 |
{ |
|
144 |
if (action->action->isVisible()) { |
|
145 |
if (action->action->isSeparator()) |
|
146 |
return; |
|
147 |
||
148 |
Q_ASSERT_X(action->command <= QT_SYMBIAN_LAST_MENU_ITEM, "qt_symbian_insert_action", |
|
149 |
"Too many menu actions"); |
|
150 |
||
151 |
const int underlineShortCut = QApplication::style()->styleHint(QStyle::SH_UnderlineShortcut); |
|
152 |
QString iconText = action->action->iconText(); |
|
153 |
TPtrC menuItemText = qt_QString2TPtrC( underlineShortCut ? action->action->text() : iconText); |
|
154 |
if (action->action->menu()) { |
|
155 |
SymbianMenuItem* menuItem = new SymbianMenuItem(); |
|
156 |
menuItem->menuItemData.iCascadeId = action->command; |
|
157 |
menuItem->menuItemData.iCommandId = action->command; |
|
158 |
menuItem->menuItemData.iFlags = 0; |
|
159 |
menuItem->menuItemData.iText = menuItemText; |
|
160 |
menuItem->action = action->action; |
|
161 |
if (action->action->menu()->actions().size() == 0 || !action->action->isEnabled() ) |
|
162 |
menuItem->menuItemData.iFlags |= EEikMenuItemDimmed; |
|
163 |
parent->append(menuItem); |
|
164 |
||
165 |
if (action->action->menu()->actions().size() > 0) { |
|
166 |
for (int c2= 0; c2 < action->action->menu()->actions().size(); ++c2) { |
|
167 |
QSymbianMenuAction *symbianAction2 = new QSymbianMenuAction; |
|
168 |
symbianAction2->action = action->action->menu()->actions().at(c2); |
|
169 |
QMenu * menu = symbianAction2->action->menu(); |
|
170 |
symbianAction2->command = qt_symbian_menu_static_cmd_id++; |
|
171 |
qt_symbian_insert_action(symbianAction2, &(menuItem->children)); |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
} else { |
|
176 |
SymbianMenuItem* menuItem = new SymbianMenuItem(); |
|
177 |
menuItem->menuItemData.iCascadeId = 0; |
|
178 |
menuItem->menuItemData.iCommandId = action->command; |
|
179 |
menuItem->menuItemData.iFlags = 0; |
|
180 |
menuItem->menuItemData.iText = menuItemText; |
|
181 |
menuItem->action = action->action; |
|
182 |
if (!action->action->isEnabled()){ |
|
183 |
menuItem->menuItemData.iFlags += EEikMenuItemDimmed; |
|
184 |
} |
|
185 |
||
186 |
if (action->action->isCheckable()) { |
|
187 |
if (action->action->isChecked()) |
|
188 |
menuItem->menuItemData.iFlags += EEikMenuItemCheckBox | EEikMenuItemSymbolOn; |
|
189 |
else |
|
190 |
menuItem->menuItemData.iFlags += EEikMenuItemCheckBox; |
|
191 |
} |
|
192 |
parent->append(menuItem); |
|
193 |
} |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
void deleteAll(QList<SymbianMenuItem*> *items) |
|
198 |
{ |
|
199 |
while (!items->isEmpty()) { |
|
200 |
SymbianMenuItem* temp = items->takeFirst(); |
|
201 |
deleteAll(&temp->children); |
|
202 |
delete temp; |
|
203 |
} |
|
204 |
} |
|
205 |
||
206 |
static void rebuildMenu() |
|
207 |
{ |
|
208 |
widgetWithContextMenu = 0; |
|
209 |
QMenuBarPrivate *mb = 0; |
|
210 |
QWidget *w = qApp->activeWindow(); |
|
211 |
QWidget* focusWidget = QApplication::focusWidget(); |
|
212 |
if (focusWidget) { |
|
213 |
if (hasContextMenu(focusWidget)) |
|
214 |
widgetWithContextMenu = focusWidget; |
|
215 |
} |
|
216 |
||
217 |
if (w) { |
|
218 |
mb = menubars()->value(w); |
|
219 |
qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM; |
|
220 |
deleteAll( &symbianMenus ); |
|
221 |
if (!mb) |
|
222 |
return; |
|
223 |
mb->symbian_menubar->rebuild(); |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
#ifdef Q_WS_S60 |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
228 |
void qt_symbian_next_menu_from_action(QWidget *actionContainer) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
229 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
230 |
actionMenu = actionContainer; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
231 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
232 |
|
0 | 233 |
void qt_symbian_show_toplevel( CEikMenuPane* menuPane) |
234 |
{ |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
235 |
if (actionMenu) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
236 |
QMenuBarPrivate *mb = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
237 |
mb = menubars()->value(actionMenu); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
238 |
qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
239 |
deleteAll( &symbianMenus ); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
240 |
Q_ASSERT(mb); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
241 |
mb->symbian_menubar->rebuild(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
242 |
for (int i = 0; i < symbianMenus.count(); ++i) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
243 |
QT_TRAP_THROWING(menuPane->AddMenuItemL(symbianMenus.at(i)->menuItemData)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
244 |
actionMenu = NULL; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
245 |
return; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
246 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
247 |
|
0 | 248 |
if (!menuExists()) |
249 |
return; |
|
250 |
rebuildMenu(); |
|
251 |
for (int i = 0; i < symbianMenus.count(); ++i) |
|
252 |
QT_TRAP_THROWING(menuPane->AddMenuItemL(symbianMenus.at(i)->menuItemData)); |
|
253 |
} |
|
254 |
||
255 |
void qt_symbian_show_submenu( CEikMenuPane* menuPane, int id) |
|
256 |
{ |
|
257 |
SymbianMenuItem* menu = qt_symbian_find_menu(id, symbianMenus); |
|
258 |
if (menu) { |
|
259 |
for (int i = 0; i < menu->children.count(); ++i) |
|
260 |
QT_TRAP_THROWING(menuPane->AddMenuItemL(menu->children.at(i)->menuItemData)); |
|
261 |
} |
|
262 |
} |
|
263 |
#endif // Q_WS_S60 |
|
264 |
||
265 |
int QMenuBarPrivate::symbianCommands(int command) |
|
266 |
{ |
|
267 |
int ret = 0; |
|
268 |
||
269 |
if (command == contexMenuCommand && !widgetWithContextMenu.isNull()) { |
|
270 |
QContextMenuEvent* event = new QContextMenuEvent(QContextMenuEvent::Keyboard, QPoint(0,0)); |
|
271 |
QCoreApplication::postEvent(widgetWithContextMenu, event); |
|
272 |
ret = 1; |
|
273 |
} |
|
274 |
||
275 |
int size = nativeMenuBars.size(); |
|
276 |
for (int i = 0; i < nativeMenuBars.size(); ++i) { |
|
277 |
SymbianMenuItem* menu = qt_symbian_find_menu_item(command, symbianMenus); |
|
278 |
if (!menu) |
|
279 |
continue; |
|
280 |
||
281 |
emit nativeMenuBars.at(i)->triggered(menu->action); |
|
282 |
menu->action->activate(QAction::Trigger); |
|
283 |
ret = 1; |
|
284 |
break; |
|
285 |
} |
|
286 |
||
287 |
return ret; |
|
288 |
} |
|
289 |
||
290 |
void QMenuBarPrivate::symbianCreateMenuBar(QWidget *parent) |
|
291 |
{ |
|
292 |
Q_Q(QMenuBar); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
293 |
if (parent) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
294 |
if(parent->isWindow()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
295 |
menubars()->insert(q->window(), this); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
296 |
symbian_menubar = new QSymbianMenuBarPrivate(this); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
297 |
nativeMenuBars.append(q); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
298 |
} else { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
299 |
menubars()->insert(q->parentWidget(), this); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
300 |
symbian_menubar = new QSymbianMenuBarPrivate(this); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
301 |
nativeMenuBars.append(q); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
302 |
} |
0 | 303 |
} |
304 |
} |
|
305 |
||
306 |
void QMenuBarPrivate::symbianDestroyMenuBar() |
|
307 |
{ |
|
308 |
Q_Q(QMenuBar); |
|
309 |
int index = nativeMenuBars.indexOf(q); |
|
310 |
nativeMenuBars.removeAt(index); |
|
311 |
menubars()->remove(q->window(), this); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
312 |
menubars()->remove(q->parentWidget(), this); |
0 | 313 |
rebuildMenu(); |
314 |
if (symbian_menubar) |
|
315 |
delete symbian_menubar; |
|
316 |
symbian_menubar = 0; |
|
317 |
} |
|
318 |
||
319 |
QMenuBarPrivate::QSymbianMenuBarPrivate::QSymbianMenuBarPrivate(QMenuBarPrivate *menubar) |
|
320 |
{ |
|
321 |
d = menubar; |
|
322 |
} |
|
323 |
||
324 |
QMenuBarPrivate::QSymbianMenuBarPrivate::~QSymbianMenuBarPrivate() |
|
325 |
{ |
|
326 |
qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM; |
|
327 |
deleteAll( &symbianMenus ); |
|
328 |
symbianMenus.clear(); |
|
329 |
d = 0; |
|
330 |
rebuild(); |
|
331 |
} |
|
332 |
||
333 |
QMenuPrivate::QSymbianMenuPrivate::QSymbianMenuPrivate() |
|
334 |
{ |
|
335 |
} |
|
336 |
||
337 |
QMenuPrivate::QSymbianMenuPrivate::~QSymbianMenuPrivate() |
|
338 |
{ |
|
339 |
||
340 |
} |
|
341 |
||
342 |
void QMenuPrivate::QSymbianMenuPrivate::addAction(QAction *a, QSymbianMenuAction *before) |
|
343 |
{ |
|
344 |
QSymbianMenuAction *action = new QSymbianMenuAction; |
|
345 |
action->action = a; |
|
346 |
action->command = qt_symbian_menu_static_cmd_id++; |
|
347 |
addAction(action, before); |
|
348 |
} |
|
349 |
||
350 |
void QMenuPrivate::QSymbianMenuPrivate::addAction(QSymbianMenuAction *action, QSymbianMenuAction *before) |
|
351 |
{ |
|
352 |
if (!action) |
|
353 |
return; |
|
354 |
int before_index = actionItems.indexOf(before); |
|
355 |
if (before_index < 0) { |
|
356 |
before = 0; |
|
357 |
before_index = actionItems.size(); |
|
358 |
} |
|
359 |
actionItems.insert(before_index, action); |
|
360 |
} |
|
361 |
||
362 |
||
363 |
void QMenuPrivate::QSymbianMenuPrivate::syncAction(QSymbianMenuAction *) |
|
364 |
{ |
|
365 |
rebuild(); |
|
366 |
} |
|
367 |
||
368 |
void QMenuPrivate::QSymbianMenuPrivate::removeAction(QSymbianMenuAction *action) |
|
369 |
{ |
|
370 |
actionItems.removeAll(action); |
|
371 |
delete action; |
|
372 |
action = 0; |
|
373 |
rebuild(); |
|
374 |
} |
|
375 |
||
376 |
void QMenuPrivate::QSymbianMenuPrivate::rebuild(bool) |
|
377 |
{ |
|
378 |
} |
|
379 |
||
380 |
void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QAction *a, QSymbianMenuAction *before) |
|
381 |
{ |
|
382 |
QSymbianMenuAction *action = new QSymbianMenuAction; |
|
383 |
action->action = a; |
|
384 |
action->command = qt_symbian_menu_static_cmd_id++; |
|
385 |
addAction(action, before); |
|
386 |
} |
|
387 |
||
388 |
void QMenuBarPrivate::QSymbianMenuBarPrivate::addAction(QSymbianMenuAction *action, QSymbianMenuAction *before) |
|
389 |
{ |
|
390 |
if (!action) |
|
391 |
return; |
|
392 |
int before_index = actionItems.indexOf(before); |
|
393 |
if (before_index < 0) { |
|
394 |
before = 0; |
|
395 |
before_index = actionItems.size(); |
|
396 |
} |
|
397 |
actionItems.insert(before_index, action); |
|
398 |
} |
|
399 |
||
400 |
void QMenuBarPrivate::QSymbianMenuBarPrivate::syncAction(QSymbianMenuAction*) |
|
401 |
{ |
|
402 |
rebuild(); |
|
403 |
} |
|
404 |
||
405 |
void QMenuBarPrivate::QSymbianMenuBarPrivate::removeAction(QSymbianMenuAction *action) |
|
406 |
{ |
|
407 |
actionItems.removeAll(action); |
|
408 |
delete action; |
|
409 |
rebuild(); |
|
410 |
} |
|
411 |
||
412 |
void QMenuBarPrivate::QSymbianMenuBarPrivate::insertNativeMenuItems(const QList<QAction*> &actions) |
|
413 |
{ |
|
414 |
for (int i = 0; i <actions.size(); ++i) { |
|
415 |
QSymbianMenuAction *symbianActionTopLevel = new QSymbianMenuAction; |
|
416 |
symbianActionTopLevel->action = actions.at(i); |
|
417 |
symbianActionTopLevel->parent = 0; |
|
418 |
symbianActionTopLevel->command = qt_symbian_menu_static_cmd_id++; |
|
419 |
qt_symbian_insert_action(symbianActionTopLevel, &symbianMenus); |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
||
424 |
||
425 |
void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() |
|
426 |
{ |
|
427 |
contexMenuCommand = 0; |
|
428 |
qt_symbian_menu_static_cmd_id = QT_SYMBIAN_FIRST_MENU_ITEM; |
|
429 |
deleteAll( &symbianMenus ); |
|
430 |
if (d) |
|
431 |
insertNativeMenuItems(d->actions); |
|
432 |
||
433 |
contextMenuActionList.clear(); |
|
434 |
if (widgetWithContextMenu) { |
|
435 |
contexMenuCommand = qt_symbian_menu_static_cmd_id; // Increased inside insertNativeMenuItems |
|
436 |
contextAction()->setText(QMenuBar::tr("Actions")); |
|
437 |
contextMenuActionList.append(contextAction()); |
|
438 |
insertNativeMenuItems(contextMenuActionList); |
|
439 |
} |
|
440 |
} |
|
441 |
QT_END_NAMESPACE |
|
442 |
||
443 |
#endif //QT_NO_MENUBAR |