diff --git a/src/nexus.cpp b/src/nexus.cpp index 1d0bc6fe6..9398f7c45 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -39,6 +39,11 @@ #include #endif +#ifdef Q_OS_MAC +#include +#include +#endif + static Nexus* nexus{nullptr}; Nexus::Nexus(QObject *parent) : @@ -60,6 +65,9 @@ Nexus::~Nexus() delete loginScreen; delete profile; Settings::getInstance().saveGlobal(); +#ifdef Q_OS_MAC + delete globalMenuBar; +#endif } void Nexus::start() @@ -81,6 +89,25 @@ void Nexus::start() qRegisterMetaType("ToxFile::FileDirection"); qRegisterMetaType>("std::shared_ptr"); +#ifdef Q_OS_MAC + globalMenuBar = new QMenuBar(0); + + windowMenu = globalMenuBar->addMenu(tr("Window")); + globalMenuBar->addAction(windowMenu->menuAction()); + + QAction* minimizeAction = Nexus::getInstance().windowMenu->addAction(tr("Minimize")); + minimizeAction->setShortcut(Qt::CTRL + Qt::Key_M); + connect(minimizeAction, &QAction::triggered, [minimizeAction]() + { + QApplication::focusWindow()->showMinimized(); + }); + Nexus::getInstance().windowMenu->addSeparator(); + + QAction* quitAction = new QAction(globalMenuBar); + quitAction->setMenuRole(QAction::QuitRole); + connect(quitAction, &QAction::triggered, qApp, &QApplication::quit); +#endif + loginScreen = new LoginScreen(); if (profile) diff --git a/src/nexus.h b/src/nexus.h index be161c7ee..53b2a0df2 100644 --- a/src/nexus.h +++ b/src/nexus.h @@ -29,6 +29,11 @@ class Profile; class LoginScreen; class Core; +#ifdef Q_OS_MAC +class QMenuBar; +class QMenu; +#endif + /// This class is in charge of connecting various systems together /// and forwarding signals appropriately to the right objects /// It is in charge of starting the GUI and the Core @@ -52,6 +57,11 @@ public: static QString getSupportedImageFilter(); static bool tryRemoveFile(const QString& filepath); ///< Dangerous way to find out if a path is writable +#ifdef Q_OS_MAC + QMenuBar* globalMenuBar; + QMenu* windowMenu; +#endif + private: explicit Nexus(QObject *parent = 0); ~Nexus(); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 52ec607f0..377845d5b 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -258,37 +258,32 @@ void Widget::init() new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact())); #ifdef Q_OS_MAC - mainMenu = new QMenuBar(0); - mainMenu->setNativeMenuBar(true); + QAction* windowMenu = Nexus::getInstance().windowMenu->menuAction(); + QAction* fileMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("File"), this)); - QMenu* fileMenu = new QMenu(tr("File")); - mainMenu->addAction(fileMenu->menuAction()); - - QAction* editProfileAction = fileMenu->addAction(tr("Edit Profile")); + QAction* editProfileAction = fileMenu->menu()->addAction(tr("Edit Profile")); connect(editProfileAction, &QAction::triggered, this, &Widget::showProfile); - QMenu* changeStatusMenu = new QMenu(tr("Change Status")); - fileMenu->addAction(changeStatusMenu->menuAction()); + QMenu* changeStatusMenu = fileMenu->menu()->addMenu(tr("Change Status")); + fileMenu->menu()->addAction(changeStatusMenu->menuAction()); changeStatusMenu->addAction(statusOnline); changeStatusMenu->addSeparator(); changeStatusMenu->addAction(statusAway); changeStatusMenu->addAction(statusBusy); - fileMenu->addSeparator(); - QAction* logoutAction = fileMenu->addAction(tr("Log out")); + fileMenu->menu()->addSeparator(); + QAction* logoutAction = fileMenu->menu()->addAction(tr("Log out")); connect(logoutAction, &QAction::triggered, [this]() { Nexus::getInstance().showLogin(); }); - QMenu* editMenu = new QMenu(tr("Edit")); - mainMenu->addAction(editMenu->menuAction()); + QAction* editMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("Edit"), this)); + editMenu->menu()->addSeparator(); - QMenu* viewMenu = new QMenu(tr("View")); - mainMenu->addAction(viewMenu->menuAction()); + QAction* viewMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("View"), this)); - QMenu* filterMenu = new QMenu(tr("Filter...")); - viewMenu->addAction(filterMenu->menuAction()); + QMenu* filterMenu = viewMenu->menu()->addMenu(tr("Filter...")); filterMenu->addAction(filterDisplayName); filterMenu->addAction(filterDisplayActivity); filterMenu->addSeparator(); @@ -298,46 +293,33 @@ void Widget::init() filterMenu->addAction(filterFriendsAction); filterMenu->addAction(filterGroupsAction); - viewMenu->addSeparator(); - fullscreenAction = viewMenu->addAction(tr("Enter Fullscreen")); + viewMenu->menu()->addSeparator(); + fullscreenAction = viewMenu->menu()->addAction(tr("Enter Fullscreen")); fullscreenAction->setShortcut(QKeySequence::FullScreen); connect(fullscreenAction, &QAction::triggered, this, &Widget::toggleFullscreen); - QMenu* contactMenu = new QMenu(tr("Contacts")); - mainMenu->addAction(contactMenu->menuAction()); + QAction* contactMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("Contacts"), this)); - QAction* addContactAction = contactMenu->addAction(tr("Add Contact...")); + QAction* addContactAction = contactMenu->menu()->addAction(tr("Add Contact...")); connect(addContactAction, &QAction::triggered, this, &Widget::onAddClicked); - QMenu* windowMenu = new QMenu(tr("Window")); - mainMenu->addAction(windowMenu->menuAction()); - - QAction* minimizeAction = windowMenu->addAction(tr("Minimize")); - minimizeAction->setShortcut(Qt::CTRL + Qt::Key_M); - connect(minimizeAction, &QAction::triggered, this, &Widget::showMinimized); - windowMenu->addSeparator(); - - QAction* nextConversationAction = windowMenu->addAction(tr("Next Conversation")); + QAction* nextConversationAction = Nexus::getInstance().windowMenu->addAction(tr("Next Conversation")); nextConversationAction->setShortcut(QKeySequence::SelectNextPage); connect(nextConversationAction, &QAction::triggered, this, &Widget::nextContact); - QAction* previousConversationAction = windowMenu->addAction(tr("Previous Conversation")); + QAction* previousConversationAction = Nexus::getInstance().windowMenu->addAction(tr("Previous Conversation")); previousConversationAction->setShortcut(QKeySequence::SelectPreviousPage); connect(previousConversationAction, &QAction::triggered, this, &Widget::previousContact); - windowMenu->addSeparator(); - QAction* frontAction = windowMenu->addAction(tr("Bring All to Front")); + Nexus::getInstance().windowMenu->addSeparator(); + QAction* frontAction = Nexus::getInstance().windowMenu->addAction(tr("Bring All to Front")); connect(frontAction, &QAction::triggered, this, &Widget::bringAllToFront); - QAction* preferencesAction = viewMenu->addAction(QString()); + QAction* preferencesAction = viewMenu->menu()->addAction(QString()); preferencesAction->setMenuRole(QAction::PreferencesRole); connect(preferencesAction, &QAction::triggered, this, &Widget::onSettingsClicked); - QAction* quitAction = viewMenu->addAction(QString()); - quitAction->setMenuRole(QAction::QuitRole); - connect(quitAction, &QAction::triggered, this, &Widget::close); - - QAction* aboutAction = viewMenu->addAction(QString()); + QAction* aboutAction = viewMenu->menu()->addAction(QString()); aboutAction->setMenuRole(QAction::AboutRole); connect(aboutAction, &QAction::triggered, [this]() { @@ -433,6 +415,11 @@ Widget::~Widget() delete trayMenu; delete ui; instance = nullptr; + +#ifdef Q_OS_MAC + //Nexus::getInstance().globalMenuBar->clear(); + //Nexus::getInstance().globalMenuBar->addMenu(Nexus::getInstance().windowMenu); +#endif } Widget* Widget::getInstance() @@ -1344,6 +1331,19 @@ void Widget::onTryCreateTrayIcon() { show(); } + +#ifdef Q_OS_MAC + QMenu* changeStatusMenu = new QMenu(tr("Status"), this); + changeStatusMenu->addAction(statusOnline); + statusOnline->setIconVisibleInMenu(true); + changeStatusMenu->addSeparator(); + changeStatusMenu->addAction(statusAway); + changeStatusMenu->addAction(statusBusy); + + QMenu* dockMenu = new QMenu(this); + dockMenu->addAction(changeStatusMenu->menuAction()); + qt_mac_set_dock_menu(dockMenu); +#endif } else if (!isVisible()) { diff --git a/src/widget/widget.h b/src/widget/widget.h index 6b6b543d0..443fd7068 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -243,7 +243,6 @@ private: bool wasMaximized = false; #ifdef Q_OS_MAC - QMenuBar* mainMenu; QAction* fullscreenAction; #endif };