diff --git a/client/client.pro b/client/client.pro index 2c5202ead..726958cdc 100644 --- a/client/client.pro +++ b/client/client.pro @@ -100,5 +100,5 @@ macx { HEADERS += ui/macos_util.h SOURCES += ui/macos_util.mm - LIBS += -framework Cocoa + LIBS += -framework Cocoa -framework ApplicationServices -framework CoreServices -framework Foundation -framework AppKit } diff --git a/client/ui/macos_util.h b/client/ui/macos_util.h index 831f1f88f..f5add9021 100644 --- a/client/ui/macos_util.h +++ b/client/ui/macos_util.h @@ -3,6 +3,7 @@ #include #include +void setDockIconVisible(bool visible); void fixWidget(QWidget *widget); #endif diff --git a/client/ui/macos_util.mm b/client/ui/macos_util.mm index 9f4337475..8adda58aa 100644 --- a/client/ui/macos_util.mm +++ b/client/ui/macos_util.mm @@ -2,6 +2,19 @@ #include #include "macos_util.h" + +#import +#import + +void setDockIconVisible(bool visible) +{ + if (!visible) { + [NSApp setActivationPolicy: NSApplicationActivationPolicyAccessory]; + } else { + [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]; + } +} + //this Objective-c class is used to override the action of system close button and zoom button //https://stackoverflow.com/questions/27643659/setting-c-function-as-selector-for-nsbutton-produces-no-results @interface ButtonPasser : NSObject{ diff --git a/client/ui/mainwindow.cpp b/client/ui/mainwindow.cpp index e5b723030..c5c00f248 100644 --- a/client/ui/mainwindow.cpp +++ b/client/ui/mainwindow.cpp @@ -196,6 +196,24 @@ void MainWindow::closeEvent(QCloseEvent *event) hide(); } +void MainWindow::showEvent(QShowEvent *event) +{ +#ifdef Q_OS_MACX + if (!event->spontaneous()) { + setDockIconVisible(true); + } +#endif +} + +void MainWindow::hideEvent(QHideEvent *event) +{ +#ifdef Q_OS_MACX + if (!event->spontaneous()) { + setDockIconVisible(false); + } +#endif +} + void MainWindow::onPushButtonNewServerConnectWithNewData(bool) { if (ui->lineEdit_new_server_ip->text().isEmpty() || @@ -414,9 +432,11 @@ void MainWindow::setupTray() }); m_menu->addAction(QIcon(":/images/tray/cancel.png"), tr("Quit") + " " + APPLICATION_NAME, this, [&](){ +// QMessageBox::question(this, QMessageBox::question(this, tr("Exit"), tr("Do you really want to quit?"), QMessageBox::Yes | QMessageBox::No, ); + QMessageBox msgBox(QMessageBox::Question, tr("Exit"), tr("Do you really want to quit?"), - QMessageBox::Yes | QMessageBox::No, Q_NULLPTR, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); - msgBox.setDefaultButton(QMessageBox::No); + QMessageBox::Yes | QMessageBox::No, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); + msgBox.setDefaultButton(QMessageBox::Yes); msgBox.raise(); if (msgBox.exec() == QMessageBox::Yes) { qApp->quit(); @@ -528,11 +548,13 @@ void MainWindow::setTrayState(VpnProtocol::ConnectionState state) void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) { +#ifndef Q_OS_MAC if(reason == QSystemTrayIcon::DoubleClick || reason == QSystemTrayIcon::Trigger) { show(); raise(); setWindowState(Qt::WindowActive); } +#endif } void MainWindow::onConnect() diff --git a/client/ui/mainwindow.h b/client/ui/mainwindow.h index db3cae1a8..ef2215fb8 100644 --- a/client/ui/mainwindow.h +++ b/client/ui/mainwindow.h @@ -84,6 +84,8 @@ private: bool eventFilter(QObject *obj, QEvent *event) override; void keyPressEvent(QKeyEvent* event) override; void closeEvent(QCloseEvent *event) override; + void showEvent(QShowEvent *event) override; + void hideEvent(QHideEvent *event) override; const QString ConnectedTrayIconName = "active.png"; const QString DisconnectedTrayIconName = "default.png"; diff --git a/client/ui/mainwindow.ui b/client/ui/mainwindow.ui index bac7689d9..adb10a6fd 100644 --- a/client/ui/mainwindow.ui +++ b/client/ui/mainwindow.ui @@ -14,25 +14,7 @@ - QWidget { - font: 16px "Lato"; - outline: none; - font-style: normal; - font-weight: normal; -} - -/*----------------------*/ - -QPushButton { - border: none; - color: rgb(216, 216, 216); -} -QPushButton:disabled { - border: none; - color: rgb(127, 127, 127); -} - -/*----------------------*/ + /*----------------------*/ QLabel { color: #181922; @@ -41,14 +23,14 @@ QLabel:disabled { color: #A7A7A7; } -/*----------------------*/ - -QMessageBox { - background-color: #333333; -} QMessageBox QLabel { - color: #aaa; + font: 16px "Lato"; } +/* +QMessageBox QPushButton { + border: 1; +} +*/ /*----------------------*/ @@ -176,7 +158,25 @@ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { - QWidget #widget_main { + QWidget { + font: 16px "Lato"; + outline: none; + font-style: normal; + font-weight: normal; +} + +/*----------------------*/ + +QPushButton { + border: none; +} +QPushButton:disabled { + border: none; +} + +/*----------------------*/ + +QWidget #widget_main { background: white; } @@ -902,15 +902,15 @@ QPushButton:hover { Lato - 12 - 7 + -1 + 50 false false color: rgb(66, 209, 133); -font: 63 12pt "Lato"; +font: 16px "Lato"; 0 Mbps @@ -931,15 +931,15 @@ font: 63 12pt "Lato"; Lato - 12 - 7 + -1 + 50 false false color: rgb(65, 113, 214); -font: 63 12pt "Lato"; +font: 16px "Lato"; 0 Mbps