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
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 <QWidget>
void setDockIconVisible(bool visible);
void fixWidget(QWidget *widget);
#endif

View file

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

View file

@ -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()

View file

@ -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";

View file

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