-
Notifications
You must be signed in to change notification settings - Fork 1
/
macintegration.cpp
97 lines (80 loc) · 2.54 KB
/
macintegration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "macintegration.h"
#include "myprivate.h"
#include <QApplication>
extern void qt_mac_set_dock_menu(QMenu *);
MacIntegration::MacIntegration(QObject *parent) :
QObject(parent)
{
connect(MyPrivate::instance(), SIGNAL(dockClicked()), SIGNAL(dockClicked()));
connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), SLOT(onFocusChanged(QWidget*,QWidget*)));
MyPrivate::installCustomFrame();
MyPrivate::setCustomBorderColor(QColor(126, 161, 177));
MyPrivate::setCustomTitleColor(QColor(255, 255, 255));
// init menus
_macMenuBar = new QMenuBar(NULL);
_windowMenu = new QMenu;
_windowMenu->menuAction()->setText("Window");
_macMenuBar->addMenu(_windowMenu);
closeAction = new QAction("Close Window", _windowMenu);
closeAction->setShortcut(QKeySequence("Ctrl+W"));
connect(closeAction, SIGNAL(triggered()), SLOT(onCloseAction()));
_windowMenu->addAction(closeAction);
minimizeAction = new QAction("Minimize", _windowMenu);
minimizeAction->setShortcut(QKeySequence("Ctrl+M"));
connect(minimizeAction, SIGNAL(triggered()), SLOT(onMinimizeAction()));
_windowMenu->addAction(minimizeAction);
zoomAction = new QAction("Zoom", _windowMenu);
connect(zoomAction, SIGNAL(triggered()), SLOT(onZoomAction()));
_windowMenu->addAction(zoomAction);
_dockMenu = new QMenu;
_dockMenu->addAction("Test!");
qt_mac_set_dock_menu(_dockMenu);
}
void MacIntegration::setDockBadge(const QString & text)
{
MyPrivate::setDockBadge(text);
}
void MacIntegration::setDockOverlay(QWidget * overlay)
{
MyPrivate::setDockOverlay(overlay);
}
QMenu * MacIntegration::dockMenu()
{
return _dockMenu;
}
void MacIntegration::requestAttention()
{
MyPrivate::requestAttention();
}
void MacIntegration::onCloseAction()
{
if (QApplication::activeWindow())
QApplication::activeWindow()->close();
}
void MacIntegration::onMinimizeAction()
{
if (QApplication::activeWindow())
QApplication::activeWindow()->showMinimized();
}
void MacIntegration::onZoomAction()
{
if (QApplication::activeWindow())
if (QApplication::activeWindow()->isMaximized())
QApplication::activeWindow()->showNormal();
else
QApplication::activeWindow()->showMaximized();
}
void MacIntegration::onFocusChanged(QWidget * old, QWidget * now)
{
Q_UNUSED(old)
if (now)
{
closeAction->setEnabled(true);
minimizeAction->setEnabled(true);
}
else
{
closeAction->setEnabled(false);
minimizeAction->setEnabled(false);
}
}