From 7b0e45269f60a687b92e37816518a4b069d7b528 Mon Sep 17 00:00:00 2001 From: "S. Razi Alavizadeh" Date: Fri, 8 Feb 2013 17:51:00 +0330 Subject: [PATCH] [Mac] Create menubar's instance just for FirstAppWindow --- src/lib/app/qupzilla.cpp | 83 +++++++++++++++++++++++++------ src/lib/app/qupzilla.h | 7 +-- src/lib/other/macmenureceiver.cpp | 1 + src/lib/other/macmenureceiver.h | 6 +++ 4 files changed, 79 insertions(+), 18 deletions(-) diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index 827c09e9e..45ff3da46 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -114,9 +114,6 @@ QupZilla::QupZilla(Qz::BrowserWindow type, QUrl startUrl) , m_startingUrl(startUrl) , m_startBehaviour(type) , m_menuBookmarksAction(0) -#ifdef Q_OS_MAC - , m_macMenuBar(new QMenuBar()) -#endif , m_actionPrivateBrowsing(0) , m_sideBarManager(new SideBarManager(this)) , m_statusBarMessage(new StatusBarMessage(this)) @@ -318,6 +315,17 @@ void QupZilla::setupUi() void QupZilla::setupMenu() { +#ifdef Q_OS_MAC + if (menuBar()) { + setupMacMenu(); + setupOtherActions(); + return; + } + else { + mApp->macMenuReceiver()->setMenuBar(new QMenuBar(0)); + } +#endif + // Standard actions - needed on Mac to be placed correctly in "application" menu m_actionAbout = new QAction(QIcon(":/icons/qupzilla.png"), tr("&About QupZilla"), 0); m_actionAbout->setMenuRole(QAction::AboutRole); @@ -403,6 +411,9 @@ void QupZilla::setupMenu() m_actionShowMenubar = new QAction(tr("&Menu Bar"), this); m_actionShowMenubar->setCheckable(true); connect(m_actionShowMenubar, SIGNAL(triggered(bool)), MENU_RECEIVER, SLOT(showMenubar())); + m_menuEncoding = new QMenu(this); +#else + m_menuEncoding = new QMenu(0); #endif m_actionShowFullScreen = new QAction(tr("&Fullscreen"), MENU_RECEIVER); m_actionShowFullScreen->setCheckable(true); @@ -415,7 +426,6 @@ void QupZilla::setupMenu() connect(m_actionReload, SIGNAL(triggered()), MENU_RECEIVER, SLOT(reload())); m_actionReload->setShortcut(QKeySequence("F5")); QAction* actionEncoding = new QAction(tr("Character &Encoding"), MENU_RECEIVER); - m_menuEncoding = new QMenu(this); actionEncoding->setMenu(m_menuEncoding); connect(m_menuEncoding, SIGNAL(aboutToShow()), MENU_RECEIVER, SLOT(aboutToShowEncodingMenu())); m_actionCaretBrowsing = new QAction(tr("Enable &Caret Browsing"), MENU_RECEIVER); @@ -556,6 +566,21 @@ void QupZilla::setupMenu() /***************** * Other Actions * *****************/ + setupOtherActions(); + +#ifndef Q_OS_MAC + m_superMenu->addMenu(m_menuFile); + m_superMenu->addMenu(m_menuEdit); + m_superMenu->addMenu(m_menuView); + m_superMenu->addMenu(m_menuHistory); + m_superMenu->addMenu(m_menuBookmarks); + m_superMenu->addMenu(m_menuTools); + m_superMenu->addMenu(m_menuHelp); +#endif +} + +void QupZilla::setupOtherActions() +{ m_actionRestoreTab = new QAction(QIcon::fromTheme("user-trash"), tr("Restore &Closed Tab"), this); m_actionRestoreTab->setShortcut(QKeySequence("Ctrl+Shift+T")); connect(m_actionRestoreTab, SIGNAL(triggered()), MENU_RECEIVER, SLOT(restoreClosedTab())); @@ -589,18 +614,46 @@ void QupZilla::setupMenu() } addAction(action); } - -#ifndef Q_OS_MAC - m_superMenu->addMenu(m_menuFile); - m_superMenu->addMenu(m_menuEdit); - m_superMenu->addMenu(m_menuView); - m_superMenu->addMenu(m_menuHistory); - m_superMenu->addMenu(m_menuBookmarks); - m_superMenu->addMenu(m_menuTools); - m_superMenu->addMenu(m_menuHelp); -#endif } +#ifdef Q_OS_MAC +void QupZilla::setupMacMenu() +{ + // menus + m_menuFile = menuBar()->actions().at(0)->menu(); + m_menuEdit = menuBar()->actions().at(1)->menu(); + m_menuView = menuBar()->actions().at(2)->menu(); + m_menuHistory = qobject_cast(menuBar()->actions().at(3)->menu()); + m_menuBookmarks = qobject_cast(menuBar()->actions().at(4)->menu()); + m_menuTools = menuBar()->actions().at(5)->menu(); + m_menuHelp = menuBar()->actions().at(6)->menu(); + + m_menuEncoding = m_menuView->actions().at(12)->menu(); + + m_menuHistoryRecent = qobject_cast(m_menuHistory->actions().at(5)->menu()); + m_menuHistoryMost = qobject_cast(m_menuHistory->actions().at(6)->menu()); + m_menuClosedTabs = m_menuHistory->actions().at(7)->menu(); + + // actions + m_actionCloseWindow = m_menuFile->actions().at(5); + m_actionQuit = m_menuFile->actions().at(13); + m_actionAbout = m_menuFile->actions().at(14); + m_actionPreferences = m_menuFile->actions().at(15); + + m_actionShowToolbar = m_menuView->actions().at(0)->menu()->actions().at(0); + m_actionShowBookmarksToolbar = m_menuView->actions().at(0)->menu()->actions().at(1); + m_actionShowStatusbar = m_menuView->actions().at(2); + m_actionStop = m_menuView->actions().at(4); + m_actionReload = m_menuView->actions().at(5); + m_actionCaretBrowsing = m_menuView->actions().at(11); + m_actionPageSource = m_menuView->actions().at(14); + m_actionShowFullScreen = m_menuView->actions().at(15); + + m_actionPageInfo = m_menuTools->actions().at(1); + m_actionPrivateBrowsing = m_menuTools->actions().at(9); +} +#endif + void QupZilla::loadSettings() { Settings settings; @@ -712,7 +765,7 @@ void QupZilla::goBack() QMenuBar* QupZilla::menuBar() const { #ifdef Q_OS_MAC - return m_macMenuBar; + return mApp->macMenuReceiver()->menuBar(); #else return QMainWindow::menuBar(); #endif diff --git a/src/lib/app/qupzilla.h b/src/lib/app/qupzilla.h index 41321c9df..ce75460ec 100644 --- a/src/lib/app/qupzilla.h +++ b/src/lib/app/qupzilla.h @@ -215,6 +215,10 @@ private: void setupUi(); void setupMenu(); + void setupOtherActions(); +#ifdef Q_OS_MAC + void setupMacMenu(); +#endif void disconnectObjects(); @@ -255,9 +259,6 @@ private: Menu* m_menuHistoryMost; QMenu* m_menuEncoding; QAction* m_menuBookmarksAction; -#ifdef Q_OS_MAC - QMenuBar* m_macMenuBar; -#endif QAction* m_actionAbout; QAction* m_actionPreferences; diff --git a/src/lib/other/macmenureceiver.cpp b/src/lib/other/macmenureceiver.cpp index 3fb9f2c3a..e68d96e45 100644 --- a/src/lib/other/macmenureceiver.cpp +++ b/src/lib/other/macmenureceiver.cpp @@ -28,6 +28,7 @@ MacMenuReceiver::MacMenuReceiver(QObject* parent) : QObject(parent) + , m_macMenuBar(0) { } diff --git a/src/lib/other/macmenureceiver.h b/src/lib/other/macmenureceiver.h index d624184f1..dbd136f12 100644 --- a/src/lib/other/macmenureceiver.h +++ b/src/lib/other/macmenureceiver.h @@ -26,6 +26,8 @@ class QWebFrame; class Menu; class QMenu; +class QAction; +class QMenuBar; class QT_QUPZILLA_EXPORT MacMenuReceiver : public QObject { @@ -33,6 +35,8 @@ class QT_QUPZILLA_EXPORT MacMenuReceiver : public QObject public: MacMenuReceiver(QObject* parent = 0); + inline QMenuBar* menuBar() { return m_macMenuBar; } + inline void setMenuBar(QMenuBar* menuBar) { m_macMenuBar = menuBar; } bool bookmarksMenuChanged(); private: @@ -42,6 +46,8 @@ private: QGenericArgument val0 = QGenericArgument(0), QGenericArgument val1 = QGenericArgument()); + QMenuBar* m_macMenuBar; + private slots: void goNext(); void goBack();