Qt5 compatibility
This commit squashes all the changes in the Qt5 branch relative to master. Backward compatibility with Qt4 is retained. Original authors: - Philip Kaufmann <phil.kaufmann@t-online.de> - Jonas Schnelli <jonas.schnelli@include7.ch>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <QMenu>
|
||||
#include <QWidget>
|
||||
|
||||
extern void qt_mac_set_dock_menu(QMenu*);
|
||||
#include <QTemporaryFile>
|
||||
#include <QImageWriter>
|
||||
|
||||
#undef slots
|
||||
#include <Cocoa/Cocoa.h>
|
||||
@@ -47,11 +47,11 @@ extern void qt_mac_set_dock_menu(QMenu*);
|
||||
MacDockIconHandler::MacDockIconHandler() : QObject()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];
|
||||
|
||||
this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];
|
||||
this->m_dummyWidget = new QWidget();
|
||||
this->m_dockMenu = new QMenu(this->m_dummyWidget);
|
||||
qt_mac_set_dock_menu(this->m_dockMenu);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
@@ -74,15 +74,29 @@ QMenu *MacDockIconHandler::dockMenu()
|
||||
void MacDockIconHandler::setIcon(const QIcon &icon)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSImage *image;
|
||||
NSImage *image = nil;
|
||||
if (icon.isNull())
|
||||
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
|
||||
else {
|
||||
// generate NSImage from QIcon and use this as dock icon.
|
||||
QSize size = icon.actualSize(QSize(128, 128));
|
||||
QPixmap pixmap = icon.pixmap(size);
|
||||
CGImageRef cgImage = pixmap.toMacCGImageRef();
|
||||
image = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
|
||||
CFRelease(cgImage);
|
||||
|
||||
// write temp file hack (could also be done through QIODevice [memory])
|
||||
QTemporaryFile notificationIconFile;
|
||||
if (!pixmap.isNull() && notificationIconFile.open()) {
|
||||
QImageWriter writer(¬ificationIconFile, "PNG");
|
||||
if (writer.write(pixmap.toImage())) {
|
||||
const char *cString = notificationIconFile.fileName().toUtf8().data();
|
||||
NSString *macString = [NSString stringWithCString:cString encoding:NSUTF8StringEncoding];
|
||||
image = [[NSImage alloc] initWithContentsOfFile:macString];
|
||||
}
|
||||
}
|
||||
|
||||
if(!image) {
|
||||
// if testnet image could not be created, load std. app icon
|
||||
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
|
||||
}
|
||||
}
|
||||
|
||||
[NSApp setApplicationIconImage:image];
|
||||
|
||||
Reference in New Issue
Block a user