Macos doc icon

This commit is contained in:
pokamest 2021-01-16 21:04:16 +03:00
parent c37ddd83d5
commit bfa0ac4c34
6 changed files with 73 additions and 35 deletions

View file

@ -100,5 +100,5 @@ macx {
HEADERS += ui/macos_util.h HEADERS += ui/macos_util.h
SOURCES += ui/macos_util.mm SOURCES += ui/macos_util.mm
LIBS += -framework Cocoa LIBS += -framework Cocoa -framework ApplicationServices -framework CoreServices -framework Foundation -framework AppKit
} }

View file

@ -3,6 +3,7 @@
#include <QDialog> #include <QDialog>
#include <QWidget> #include <QWidget>
void setDockIconVisible(bool visible);
void fixWidget(QWidget *widget); void fixWidget(QWidget *widget);
#endif #endif

View file

@ -2,6 +2,19 @@
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#include "macos_util.h" #include "macos_util.h"
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
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 //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 //https://stackoverflow.com/questions/27643659/setting-c-function-as-selector-for-nsbutton-produces-no-results
@interface ButtonPasser : NSObject{ @interface ButtonPasser : NSObject{

View file

@ -196,6 +196,24 @@ void MainWindow::closeEvent(QCloseEvent *event)
hide(); 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) void MainWindow::onPushButtonNewServerConnectWithNewData(bool)
{ {
if (ui->lineEdit_new_server_ip->text().isEmpty() || 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, [&](){ 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 msgBox(QMessageBox::Question, tr("Exit"), tr("Do you really want to quit?"),
QMessageBox::Yes | QMessageBox::No, Q_NULLPTR, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); QMessageBox::Yes | QMessageBox::No, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
msgBox.setDefaultButton(QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes);
msgBox.raise(); msgBox.raise();
if (msgBox.exec() == QMessageBox::Yes) { if (msgBox.exec() == QMessageBox::Yes) {
qApp->quit(); qApp->quit();
@ -528,11 +548,13 @@ void MainWindow::setTrayState(VpnProtocol::ConnectionState state)
void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
{ {
#ifndef Q_OS_MAC
if(reason == QSystemTrayIcon::DoubleClick || reason == QSystemTrayIcon::Trigger) { if(reason == QSystemTrayIcon::DoubleClick || reason == QSystemTrayIcon::Trigger) {
show(); show();
raise(); raise();
setWindowState(Qt::WindowActive); setWindowState(Qt::WindowActive);
} }
#endif
} }
void MainWindow::onConnect() void MainWindow::onConnect()

View file

@ -84,6 +84,8 @@ private:
bool eventFilter(QObject *obj, QEvent *event) override; bool eventFilter(QObject *obj, QEvent *event) override;
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
const QString ConnectedTrayIconName = "active.png"; const QString ConnectedTrayIconName = "active.png";
const QString DisconnectedTrayIconName = "default.png"; const QString DisconnectedTrayIconName = "default.png";

View file

@ -14,25 +14,7 @@
<string/> <string/>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QWidget { <string notr="true">/*----------------------*/
font: 16px &quot;Lato&quot;;
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 { QLabel {
color: #181922; color: #181922;
@ -41,14 +23,14 @@ QLabel:disabled {
color: #A7A7A7; color: #A7A7A7;
} }
/*----------------------*/
QMessageBox {
background-color: #333333;
}
QMessageBox QLabel { QMessageBox QLabel {
color: #aaa; font: 16px &quot;Lato&quot;;
} }
/*
QMessageBox QPushButton {
border: 1;
}
*/
/*----------------------*/ /*----------------------*/
@ -176,7 +158,25 @@ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
</rect> </rect>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QWidget #widget_main { <string notr="true">QWidget {
font: 16px &quot;Lato&quot;;
outline: none;
font-style: normal;
font-weight: normal;
}
/*----------------------*/
QPushButton {
border: none;
}
QPushButton:disabled {
border: none;
}
/*----------------------*/
QWidget #widget_main {
background: white; background: white;
} }
</string> </string>
@ -902,15 +902,15 @@ QPushButton:hover {
<property name="font"> <property name="font">
<font> <font>
<family>Lato</family> <family>Lato</family>
<pointsize>12</pointsize> <pointsize>-1</pointsize>
<weight>7</weight> <weight>50</weight>
<italic>false</italic> <italic>false</italic>
<bold>false</bold> <bold>false</bold>
</font> </font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">color: rgb(66, 209, 133); <string notr="true">color: rgb(66, 209, 133);
font: 63 12pt &quot;Lato&quot;;</string> font: 16px &quot;Lato&quot;; </string>
</property> </property>
<property name="text"> <property name="text">
<string>0 Mbps</string> <string>0 Mbps</string>
@ -931,15 +931,15 @@ font: 63 12pt &quot;Lato&quot;;</string>
<property name="font"> <property name="font">
<font> <font>
<family>Lato</family> <family>Lato</family>
<pointsize>12</pointsize> <pointsize>-1</pointsize>
<weight>7</weight> <weight>50</weight>
<italic>false</italic> <italic>false</italic>
<bold>false</bold> <bold>false</bold>
</font> </font>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">color: rgb(65, 113, 214); <string notr="true">color: rgb(65, 113, 214);
font: 63 12pt &quot;Lato&quot;;</string> font: 16px &quot;Lato&quot;; </string>
</property> </property>
<property name="text"> <property name="text">
<string>0 Mbps</string> <string>0 Mbps</string>