From ad475e3b8935b1314382e2d2c6a7d09ace98b550 Mon Sep 17 00:00:00 2001 From: Markku Luukkainen Date: Tue, 19 May 2009 14:44:47 +0200 Subject: First hacky approach to context menus. This was commited so stuff relied on context menus can be implemented concurrently while making the internals of context menu implementation cleaner. --- src/gui/widgets/qmenu_symbian.cpp | 30 +++++++++++++++++++++++------- src/gui/widgets/qsoftkeystack.cpp | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index b9633b5..1cff1bf 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -49,6 +49,9 @@ static QList symbianMenus; static QList nativeMenuBars; static uint qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; static QWidget* widgetWithContextMenu=0; +static QList contextMenuActionList; +static QAction contextAction(0); +static int contexMenuCommand=0; bool menuExists() { @@ -177,6 +180,7 @@ void deleteAll(QList *items) static void rebuildMenu() { + widgetWithContextMenu = 0; QMenuBarPrivate *mb = 0; QWidget *w = qApp->activeWindow(); QMainWindow *mainWindow = qobject_cast(w); @@ -185,8 +189,7 @@ static void rebuildMenu() int index=0; bool found=false; - while( indexrole(); if(softAction->role() == QSoftKeyAction::ContextMenu) { @@ -195,8 +198,8 @@ static void rebuildMenu() } index++; } - if (w) - { + + if (w) { mb = menubars()->value(w); qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; deleteAll( &symbianMenus ); @@ -204,7 +207,6 @@ static void rebuildMenu() return; mb->symbian_menubar->rebuild(); } - widgetWithContextMenu = 0; } Q_GUI_EXPORT void qt_symbian_show_toplevel( CEikMenuPane* menuPane) @@ -233,6 +235,11 @@ void QMenu::symbianCommands(int command) void QMenuBar::symbianCommands(int command) { + if (command == contexMenuCommand) { + QContextMenuEvent* event = new QContextMenuEvent(QContextMenuEvent::Keyboard, QPoint(0,0)); + QCoreApplication::postEvent(widgetWithContextMenu, event); + } + int size = nativeMenuBars.size(); for (int i = 0; i < nativeMenuBars.size(); ++i) { bool result = nativeMenuBars.at(i)->d_func()->symbianCommands(command); @@ -388,16 +395,25 @@ void QMenuBarPrivate::QSymbianMenuBarPrivate::InsertNativeMenuItems(const QList< } } + + void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() { + contexMenuCommand = 0; qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; deleteAll( &symbianMenus ); if (d) InsertNativeMenuItems(d->actions); - if (widgetWithContextMenu) - InsertNativeMenuItems(widgetWithContextMenu->actions()); + contextMenuActionList.clear(); + if (widgetWithContextMenu) { + contexMenuCommand = qt_symbian_menu_static_cmd_id; + contextAction.setText(QString("Actions")); + contextMenuActionList.append(&contextAction); + InsertNativeMenuItems(contextMenuActionList); } + +} QT_END_NAMESPACE #endif //QT_NO_MENUBAR diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 14daecd..f702530 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -118,6 +118,24 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) { if (!now) return; + QWidget *w = qApp->activeWindow(); + QMainWindow *mainWindow = qobject_cast(w); + QSoftKeyStack* softKeyStack = mainWindow->softKeyStack(); + if (old) + softKeyStack->pop(); + + Qt::ContextMenuPolicy policy = now->contextMenuPolicy(); + if (policy != Qt::NoContextMenu && policy != Qt::PreventContextMenu ) { + QList actionList; + QSoftKeyAction* menu = new QSoftKeyAction(QSoftKeyAction::Menu, QString("Menu"), now); + QSoftKeyAction* contextMenu = new QSoftKeyAction(QSoftKeyAction::ContextMenu, QString("ContextMenu"), now); + actionList.append(menu); + actionList.append(contextMenu); + softKeyStack->push(actionList); + } + +/* if (!now) + return; bool nowInOurMainWindow = false; const QMainWindow *ourMainWindow = qobject_cast(parent()); Q_ASSERT(ourMainWindow); @@ -136,6 +154,7 @@ void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) QList actions = now->actions(); // Do something with these actions. +*/ } void QSoftKeyStack::handleSoftKeyPress(int command) -- cgit v0.12