diff options
author | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-05-11 11:58:24 (GMT) |
---|---|---|
committer | Markku Luukkainen <markku.luukkainen@digia.com> | 2009-05-11 11:58:24 (GMT) |
commit | 4bf005f424ed4aa86f3539ee3018bf11779550cd (patch) | |
tree | af9d616bf5bfff56b5a24d6bc16bd28bf779c56f /src/gui/widgets/qmenu_symbian.cpp | |
parent | 23909776fb7b9283239f61b6fc819285b87200ef (diff) | |
download | Qt-4bf005f424ed4aa86f3539ee3018bf11779550cd.zip Qt-4bf005f424ed4aa86f3539ee3018bf11779550cd.tar.gz Qt-4bf005f424ed4aa86f3539ee3018bf11779550cd.tar.bz2 |
Refactored implementation so that it works with multiple QMainWindows
Diffstat (limited to 'src/gui/widgets/qmenu_symbian.cpp')
-rw-r--r-- | src/gui/widgets/qmenu_symbian.cpp | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/gui/widgets/qmenu_symbian.cpp b/src/gui/widgets/qmenu_symbian.cpp index 9e53df5..4c8b4ae 100644 --- a/src/gui/widgets/qmenu_symbian.cpp +++ b/src/gui/widgets/qmenu_symbian.cpp @@ -32,8 +32,10 @@ QT_BEGIN_NAMESPACE // ### FIX/Document this, we need some safe range of menu id's for Qt that don't clash with AIW ones +typedef QHash<QWidget *, QMenuBarPrivate *> MenuBarHash; +Q_GLOBAL_STATIC(MenuBarHash, menubars) + #define QT_FIRST_MENU_ITEM 32000 -static QList<QMenuBarPrivate *> s60_menubars; struct SymbianMenuItem { @@ -47,6 +49,15 @@ static QList<SymbianMenuItem*> symbianMenus; static QList<QMenuBar*> nativeMenuBars; static uint qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; +bool menuExists() +{ + QWidget *w = qApp->activeWindow(); + QMenuBarPrivate *mb = menubars()->value(w); + if (!mb) + return false; + return true; +} + // ### FIX THIS, copy/paste of original (faulty) stripped text implementation. // Implementation should be removed from QAction implementation to some generic place static QString qt_strippedText_copy_from_qaction(QString s) @@ -167,7 +178,7 @@ static void setSoftkeys() { CEikButtonGroupContainer* cba = CEikonEnv::Static()->AppUiFactory()->Cba(); if (cba){ - if (s60_menubars.count()>0) + if (menuExists()) cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT); else cba->SetCommandSetL(R_AVKON_SOFTKEYS_EXIT); @@ -176,24 +187,23 @@ static void setSoftkeys() static void rebuildMenu() { - qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; - deleteAll( &symbianMenus ); - if (s60_menubars.count()==0) - return; - for (int i = 0; i < s60_menubars.last()->actions.size(); ++i) { - QSymbianMenuAction *symbianActionTopLevel = new QSymbianMenuAction; - symbianActionTopLevel->action = s60_menubars.last()->actions.at(i); - symbianActionTopLevel->parent = 0; - symbianActionTopLevel->command = qt_symbian_menu_static_cmd_id++; - qt_symbian_insert_action(symbianActionTopLevel, &symbianMenus); + QMenuBarPrivate *mb = 0; + setSoftkeys(); + QWidget *w = qApp->activeWindow(); + if (w) + { + mb = menubars()->value(w); + qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; + deleteAll( &symbianMenus ); + if (!mb) + return; + mb->symbian_menubar->rebuild(); } - - return; } Q_GUI_EXPORT void qt_symbian_show_toplevel( CEikMenuPane* menuPane) { - if (s60_menubars.count()==0) + if (!menuExists()) return; rebuildMenu(); for (int i = 0; i < symbianMenus.count(); ++i) @@ -251,6 +261,7 @@ void QMenuBarPrivate::symbianCreateMenuBar(QWidget *parent) { Q_Q(QMenuBar); if (parent && parent->isWindow()){ + menubars()->insert(q->window(), this); symbian_menubar = new QSymbianMenuBarPrivate(this); nativeMenuBars.append(q); } @@ -261,7 +272,7 @@ void QMenuBarPrivate::symbianDestroyMenuBar() Q_Q(QMenuBar); int index = nativeMenuBars.indexOf(q); nativeMenuBars.removeAt(index); - s60_menubars.removeLast(); + menubars()->remove(q->window()); rebuildMenu(); if (symbian_menubar) delete symbian_menubar; @@ -271,7 +282,6 @@ void QMenuBarPrivate::symbianDestroyMenuBar() QMenuBarPrivate::QSymbianMenuBarPrivate::QSymbianMenuBarPrivate(QMenuBarPrivate *menubar) { d = menubar; - s60_menubars.append(menubar); } QMenuBarPrivate::QSymbianMenuBarPrivate::~QSymbianMenuBarPrivate() @@ -364,10 +374,17 @@ void QMenuBarPrivate::QSymbianMenuBarPrivate::removeAction(QSymbianMenuAction *a void QMenuBarPrivate::QSymbianMenuBarPrivate::rebuild() { setSoftkeys(); - if (s60_menubars.count()==0) + qt_symbian_menu_static_cmd_id = QT_FIRST_MENU_ITEM; + deleteAll( &symbianMenus ); + if (!d) return; - - rebuildMenu(); - } + for (int i = 0; i < d->actions.size(); ++i) { + QSymbianMenuAction *symbianActionTopLevel = new QSymbianMenuAction; + symbianActionTopLevel->action = d->actions.at(i); + symbianActionTopLevel->parent = 0; + symbianActionTopLevel->command = qt_symbian_menu_static_cmd_id++; + qt_symbian_insert_action(symbianActionTopLevel, &symbianMenus); + } +} #endif //QT_NO_MENUBAR |