mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
OSX usable menu bar on login screen
This commit is contained in:
parent
7bb56bcda9
commit
49071baac7
|
@ -39,6 +39,11 @@
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
#include <QWindow>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#endif
|
||||||
|
|
||||||
static Nexus* nexus{nullptr};
|
static Nexus* nexus{nullptr};
|
||||||
|
|
||||||
Nexus::Nexus(QObject *parent) :
|
Nexus::Nexus(QObject *parent) :
|
||||||
|
@ -60,6 +65,9 @@ Nexus::~Nexus()
|
||||||
delete loginScreen;
|
delete loginScreen;
|
||||||
delete profile;
|
delete profile;
|
||||||
Settings::getInstance().saveGlobal();
|
Settings::getInstance().saveGlobal();
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
delete globalMenuBar;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Nexus::start()
|
void Nexus::start()
|
||||||
|
@ -81,6 +89,25 @@ void Nexus::start()
|
||||||
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
|
qRegisterMetaType<ToxFile::FileDirection>("ToxFile::FileDirection");
|
||||||
qRegisterMetaType<std::shared_ptr<VideoFrame>>("std::shared_ptr<VideoFrame>");
|
qRegisterMetaType<std::shared_ptr<VideoFrame>>("std::shared_ptr<VideoFrame>");
|
||||||
|
|
||||||
|
#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();
|
loginScreen = new LoginScreen();
|
||||||
|
|
||||||
if (profile)
|
if (profile)
|
||||||
|
|
10
src/nexus.h
10
src/nexus.h
|
@ -29,6 +29,11 @@ class Profile;
|
||||||
class LoginScreen;
|
class LoginScreen;
|
||||||
class Core;
|
class Core;
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
class QMenuBar;
|
||||||
|
class QMenu;
|
||||||
|
#endif
|
||||||
|
|
||||||
/// This class is in charge of connecting various systems together
|
/// This class is in charge of connecting various systems together
|
||||||
/// and forwarding signals appropriately to the right objects
|
/// and forwarding signals appropriately to the right objects
|
||||||
/// It is in charge of starting the GUI and the Core
|
/// It is in charge of starting the GUI and the Core
|
||||||
|
@ -52,6 +57,11 @@ public:
|
||||||
static QString getSupportedImageFilter();
|
static QString getSupportedImageFilter();
|
||||||
static bool tryRemoveFile(const QString& filepath); ///< Dangerous way to find out if a path is writable
|
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:
|
private:
|
||||||
explicit Nexus(QObject *parent = 0);
|
explicit Nexus(QObject *parent = 0);
|
||||||
~Nexus();
|
~Nexus();
|
||||||
|
|
|
@ -258,37 +258,32 @@ void Widget::init()
|
||||||
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
|
new QShortcut(Qt::CTRL + Qt::Key_PageDown, this, SLOT(nextContact()));
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
mainMenu = new QMenuBar(0);
|
QAction* windowMenu = Nexus::getInstance().windowMenu->menuAction();
|
||||||
mainMenu->setNativeMenuBar(true);
|
QAction* fileMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("File"), this));
|
||||||
|
|
||||||
QMenu* fileMenu = new QMenu(tr("File"));
|
QAction* editProfileAction = fileMenu->menu()->addAction(tr("Edit Profile"));
|
||||||
mainMenu->addAction(fileMenu->menuAction());
|
|
||||||
|
|
||||||
QAction* editProfileAction = fileMenu->addAction(tr("Edit Profile"));
|
|
||||||
connect(editProfileAction, &QAction::triggered, this, &Widget::showProfile);
|
connect(editProfileAction, &QAction::triggered, this, &Widget::showProfile);
|
||||||
|
|
||||||
QMenu* changeStatusMenu = new QMenu(tr("Change Status"));
|
QMenu* changeStatusMenu = fileMenu->menu()->addMenu(tr("Change Status"));
|
||||||
fileMenu->addAction(changeStatusMenu->menuAction());
|
fileMenu->menu()->addAction(changeStatusMenu->menuAction());
|
||||||
changeStatusMenu->addAction(statusOnline);
|
changeStatusMenu->addAction(statusOnline);
|
||||||
changeStatusMenu->addSeparator();
|
changeStatusMenu->addSeparator();
|
||||||
changeStatusMenu->addAction(statusAway);
|
changeStatusMenu->addAction(statusAway);
|
||||||
changeStatusMenu->addAction(statusBusy);
|
changeStatusMenu->addAction(statusBusy);
|
||||||
|
|
||||||
fileMenu->addSeparator();
|
fileMenu->menu()->addSeparator();
|
||||||
QAction* logoutAction = fileMenu->addAction(tr("Log out"));
|
QAction* logoutAction = fileMenu->menu()->addAction(tr("Log out"));
|
||||||
connect(logoutAction, &QAction::triggered, [this]()
|
connect(logoutAction, &QAction::triggered, [this]()
|
||||||
{
|
{
|
||||||
Nexus::getInstance().showLogin();
|
Nexus::getInstance().showLogin();
|
||||||
});
|
});
|
||||||
|
|
||||||
QMenu* editMenu = new QMenu(tr("Edit"));
|
QAction* editMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("Edit"), this));
|
||||||
mainMenu->addAction(editMenu->menuAction());
|
editMenu->menu()->addSeparator();
|
||||||
|
|
||||||
QMenu* viewMenu = new QMenu(tr("View"));
|
QAction* viewMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("View"), this));
|
||||||
mainMenu->addAction(viewMenu->menuAction());
|
|
||||||
|
|
||||||
QMenu* filterMenu = new QMenu(tr("Filter..."));
|
QMenu* filterMenu = viewMenu->menu()->addMenu(tr("Filter..."));
|
||||||
viewMenu->addAction(filterMenu->menuAction());
|
|
||||||
filterMenu->addAction(filterDisplayName);
|
filterMenu->addAction(filterDisplayName);
|
||||||
filterMenu->addAction(filterDisplayActivity);
|
filterMenu->addAction(filterDisplayActivity);
|
||||||
filterMenu->addSeparator();
|
filterMenu->addSeparator();
|
||||||
|
@ -298,46 +293,33 @@ void Widget::init()
|
||||||
filterMenu->addAction(filterFriendsAction);
|
filterMenu->addAction(filterFriendsAction);
|
||||||
filterMenu->addAction(filterGroupsAction);
|
filterMenu->addAction(filterGroupsAction);
|
||||||
|
|
||||||
viewMenu->addSeparator();
|
viewMenu->menu()->addSeparator();
|
||||||
fullscreenAction = viewMenu->addAction(tr("Enter Fullscreen"));
|
fullscreenAction = viewMenu->menu()->addAction(tr("Enter Fullscreen"));
|
||||||
fullscreenAction->setShortcut(QKeySequence::FullScreen);
|
fullscreenAction->setShortcut(QKeySequence::FullScreen);
|
||||||
connect(fullscreenAction, &QAction::triggered, this, &Widget::toggleFullscreen);
|
connect(fullscreenAction, &QAction::triggered, this, &Widget::toggleFullscreen);
|
||||||
|
|
||||||
QMenu* contactMenu = new QMenu(tr("Contacts"));
|
QAction* contactMenu = Nexus::getInstance().globalMenuBar->insertMenu(windowMenu, new QMenu(tr("Contacts"), this));
|
||||||
mainMenu->addAction(contactMenu->menuAction());
|
|
||||||
|
|
||||||
QAction* addContactAction = contactMenu->addAction(tr("Add Contact..."));
|
QAction* addContactAction = contactMenu->menu()->addAction(tr("Add Contact..."));
|
||||||
connect(addContactAction, &QAction::triggered, this, &Widget::onAddClicked);
|
connect(addContactAction, &QAction::triggered, this, &Widget::onAddClicked);
|
||||||
|
|
||||||
QMenu* windowMenu = new QMenu(tr("Window"));
|
QAction* nextConversationAction = Nexus::getInstance().windowMenu->addAction(tr("Next Conversation"));
|
||||||
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"));
|
|
||||||
nextConversationAction->setShortcut(QKeySequence::SelectNextPage);
|
nextConversationAction->setShortcut(QKeySequence::SelectNextPage);
|
||||||
connect(nextConversationAction, &QAction::triggered, this, &Widget::nextContact);
|
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);
|
previousConversationAction->setShortcut(QKeySequence::SelectPreviousPage);
|
||||||
connect(previousConversationAction, &QAction::triggered, this, &Widget::previousContact);
|
connect(previousConversationAction, &QAction::triggered, this, &Widget::previousContact);
|
||||||
|
|
||||||
windowMenu->addSeparator();
|
Nexus::getInstance().windowMenu->addSeparator();
|
||||||
QAction* frontAction = windowMenu->addAction(tr("Bring All to Front"));
|
QAction* frontAction = Nexus::getInstance().windowMenu->addAction(tr("Bring All to Front"));
|
||||||
connect(frontAction, &QAction::triggered, this, &Widget::bringAllToFront);
|
connect(frontAction, &QAction::triggered, this, &Widget::bringAllToFront);
|
||||||
|
|
||||||
QAction* preferencesAction = viewMenu->addAction(QString());
|
QAction* preferencesAction = viewMenu->menu()->addAction(QString());
|
||||||
preferencesAction->setMenuRole(QAction::PreferencesRole);
|
preferencesAction->setMenuRole(QAction::PreferencesRole);
|
||||||
connect(preferencesAction, &QAction::triggered, this, &Widget::onSettingsClicked);
|
connect(preferencesAction, &QAction::triggered, this, &Widget::onSettingsClicked);
|
||||||
|
|
||||||
QAction* quitAction = viewMenu->addAction(QString());
|
QAction* aboutAction = viewMenu->menu()->addAction(QString());
|
||||||
quitAction->setMenuRole(QAction::QuitRole);
|
|
||||||
connect(quitAction, &QAction::triggered, this, &Widget::close);
|
|
||||||
|
|
||||||
QAction* aboutAction = viewMenu->addAction(QString());
|
|
||||||
aboutAction->setMenuRole(QAction::AboutRole);
|
aboutAction->setMenuRole(QAction::AboutRole);
|
||||||
connect(aboutAction, &QAction::triggered, [this]()
|
connect(aboutAction, &QAction::triggered, [this]()
|
||||||
{
|
{
|
||||||
|
@ -433,6 +415,11 @@ Widget::~Widget()
|
||||||
delete trayMenu;
|
delete trayMenu;
|
||||||
delete ui;
|
delete ui;
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
//Nexus::getInstance().globalMenuBar->clear();
|
||||||
|
//Nexus::getInstance().globalMenuBar->addMenu(Nexus::getInstance().windowMenu);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget* Widget::getInstance()
|
Widget* Widget::getInstance()
|
||||||
|
@ -1344,6 +1331,19 @@ void Widget::onTryCreateTrayIcon()
|
||||||
{
|
{
|
||||||
show();
|
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())
|
else if (!isVisible())
|
||||||
{
|
{
|
||||||
|
|
|
@ -243,7 +243,6 @@ private:
|
||||||
bool wasMaximized = false;
|
bool wasMaximized = false;
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QMenuBar* mainMenu;
|
|
||||||
QAction* fullscreenAction;
|
QAction* fullscreenAction;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user