8 #include <QImageWriter> 14 #include <Cocoa/Cocoa.h> 15 #include <objc/objc.h> 16 #include <objc/message.h> 18 #if QT_VERSION < 0x050000 35 Class cls = objc_getClass(
"NSApplication");
36 id appInst = objc_msgSend((
id)cls, sel_registerName(
"sharedApplication"));
38 if (appInst !=
nullptr) {
39 id delegate = objc_msgSend(appInst, sel_registerName(
"delegate"));
40 Class delClass = (Class)objc_msgSend(delegate, sel_registerName(
"class"));
41 SEL shouldHandle = sel_registerName(
"applicationShouldHandleReopen:hasVisibleWindows:");
42 if (class_getInstanceMethod(delClass, shouldHandle))
45 class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,
"B@:");
52 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
58 #if QT_VERSION < 0x050000 60 #elif QT_VERSION >= 0x050200 83 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
86 image = [[NSImage imageNamed:
@"NSApplicationIcon"] retain];
89 QSize size = icon.actualSize(QSize(128, 128));
90 QPixmap pixmap = icon.pixmap(size);
93 QBuffer notificationBuffer;
94 if (!pixmap.isNull() && notificationBuffer.open(QIODevice::ReadWrite)) {
95 QImageWriter writer(¬ificationBuffer,
"PNG");
96 if (writer.write(pixmap.toImage())) {
97 NSData* macImgData = [NSData dataWithBytes:notificationBuffer.buffer().data()
98 length:notificationBuffer.buffer().size()];
99 image = [[NSImage alloc] initWithData:macImgData];
105 image = [[NSImage imageNamed:
@"NSApplicationIcon"] retain];
109 [NSApp setApplicationIconImage:image];
void setupDockClickHandler()
void qt_mac_set_dock_menu(QMenu *)
Macintosh-specific dock icon handler.
void handleDockIconClickEvent()
void setIcon(const QIcon &icon)
static MacDockIconHandler * instance()
void setMainWindow(QMainWindow *window)
bool dockClickHandler(id self, SEL _cmd,...)