replace trayicon activation with menu actions (#4632)
This commit is contained in:
parent
176c52daf2
commit
244cb847fb
2 changed files with 23 additions and 19 deletions
|
@ -62,6 +62,7 @@
|
|||
#include <QSystemTrayIcon>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QWindow>
|
||||
#include <QtConcurrent>
|
||||
#include <QtNetwork>
|
||||
|
||||
|
@ -671,6 +672,9 @@ void MainWindow::retranslateUi()
|
|||
aUpdate->setText(tr("Check for Client Updates"));
|
||||
aCheckCardUpdates->setText(tr("Check for Card Updates..."));
|
||||
aViewLog->setText(tr("View &Debug Log"));
|
||||
|
||||
aShow->setText(tr("Show/Hide"));
|
||||
|
||||
tabSupervisor->retranslateUi();
|
||||
}
|
||||
|
||||
|
@ -721,6 +725,9 @@ void MainWindow::createActions()
|
|||
aViewLog = new QAction(this);
|
||||
connect(aViewLog, SIGNAL(triggered()), this, SLOT(actViewLog()));
|
||||
|
||||
aShow = new QAction(this);
|
||||
connect(aShow, SIGNAL(triggered()), this, SLOT(actShow()));
|
||||
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
aSettings->setMenuRole(QAction::PreferencesRole);
|
||||
aExit->setMenuRole(QAction::QuitRole);
|
||||
|
@ -846,7 +853,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
aFullScreen->setChecked(static_cast<bool>(windowState() & Qt::WindowFullScreen));
|
||||
|
||||
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
createTrayActions();
|
||||
createTrayIcon();
|
||||
}
|
||||
|
||||
|
@ -931,27 +937,32 @@ MainWindow::~MainWindow()
|
|||
void MainWindow::createTrayIcon()
|
||||
{
|
||||
trayIconMenu = new QMenu(this);
|
||||
trayIconMenu->addAction(closeAction);
|
||||
trayIconMenu->addAction(aShow);
|
||||
trayIconMenu->addSeparator();
|
||||
trayIconMenu->addAction(aSettings);
|
||||
trayIconMenu->addAction(aCheckCardUpdates);
|
||||
trayIconMenu->addAction(aAbout);
|
||||
trayIconMenu->addSeparator();
|
||||
trayIconMenu->addAction(aExit);
|
||||
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
trayIcon->setIcon(QPixmap("theme:cockatrice"));
|
||||
trayIcon->show();
|
||||
|
||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
|
||||
SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
|
||||
}
|
||||
|
||||
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
void MainWindow::actShow()
|
||||
{
|
||||
if (reason == QSystemTrayIcon::DoubleClick) {
|
||||
if ((windowState() & Qt::WindowMinimized) == 0) {
|
||||
// wait 50 msec before actually checking the active window, this is because the trayicon menu will actually take
|
||||
// focus and we have to wait for the focus to come back to the application
|
||||
QTimer::singleShot(50, this, [this]() {
|
||||
if (isActiveWindow()) {
|
||||
showMinimized();
|
||||
} else {
|
||||
showNormal();
|
||||
activateWindow();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::promptForgotPasswordChallenge()
|
||||
|
@ -962,12 +973,6 @@ void MainWindow::promptForgotPasswordChallenge()
|
|||
dlg.getPlayerName(), dlg.getEmail());
|
||||
}
|
||||
|
||||
void MainWindow::createTrayActions()
|
||||
{
|
||||
closeAction = new QAction(tr("&Exit"), this);
|
||||
connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
// workaround Qt bug where closeEvent gets called twice
|
||||
|
|
|
@ -84,7 +84,7 @@ private slots:
|
|||
void forgotPasswordSuccess();
|
||||
void forgotPasswordError();
|
||||
void promptForgotPasswordReset();
|
||||
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
void actShow();
|
||||
void promptForgotPasswordChallenge();
|
||||
void showWindowIfHidden();
|
||||
|
||||
|
@ -114,7 +114,6 @@ private:
|
|||
void createMenus();
|
||||
|
||||
void createTrayIcon();
|
||||
void createTrayActions();
|
||||
int getNextCustomSetPrefix(QDir dataDir);
|
||||
inline QString getCardUpdaterBinaryName()
|
||||
{
|
||||
|
@ -125,8 +124,8 @@ private:
|
|||
QList<QMenu *> tabMenus;
|
||||
QMenu *cockatriceMenu, *dbMenu, *helpMenu, *trayIconMenu;
|
||||
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
|
||||
*aAbout, *aTips, *aCheckCardUpdates, *aRegister, *aForgotPassword, *aUpdate, *aViewLog, *closeAction;
|
||||
QAction *aManageSets, *aEditTokens, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet;
|
||||
*aAbout, *aTips, *aCheckCardUpdates, *aRegister, *aForgotPassword, *aUpdate, *aViewLog, *aManageSets,
|
||||
*aEditTokens, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet, *aShow;
|
||||
TabSupervisor *tabSupervisor;
|
||||
WndSets *wndSets;
|
||||
RemoteClient *client;
|
||||
|
|
Loading…
Reference in a new issue