Browse Source
Now it can't be told if this is was a Windows App before. All Mac design principles are fulfilled and some cosmetics have been applied to suit the native look and feel. The biggest change there is the proper use of the Dock icon which takes the role of the Tray icon on Mac. The QDoubleSpinBox improves entering of Bitcoin amounts, no two separate fields are required anymore. All functionality and validation effects have been retained; pressing the comma key will be internally translated to a period to keep it consistent throughout the application and eases entering in countries which use the comma as decimal separator. Additionally, Notificator now supports Growl, Mac's native notification system. This is provided via Apple Script in order to avoid linking to Growl on compile time. Other changes involve encapsulation of Toolbar and Menubar creation, loading of Qt's own translation and some clean up.miguelfreitas
p2k
13 years ago
committed by
Wladimir J. van der Laan
18 changed files with 435 additions and 112 deletions
@ -0,0 +1,37 @@ |
|||||||
|
#ifndef MACDOCKICONHANDLER_H |
||||||
|
#define MACDOCKICONHANDLER_H |
||||||
|
|
||||||
|
#include <QtCore/QObject> |
||||||
|
|
||||||
|
class QMenu; |
||||||
|
class QIcon; |
||||||
|
class QWidget; |
||||||
|
class objc_object; |
||||||
|
|
||||||
|
class MacDockIconHandler : public QObject |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
~MacDockIconHandler(); |
||||||
|
|
||||||
|
QMenu *dockMenu(); |
||||||
|
void setIcon(const QIcon &icon); |
||||||
|
|
||||||
|
static MacDockIconHandler *instance(); |
||||||
|
|
||||||
|
void handleDockIconClickEvent(); |
||||||
|
|
||||||
|
signals: |
||||||
|
void dockIconClicked(); |
||||||
|
|
||||||
|
public slots: |
||||||
|
|
||||||
|
private: |
||||||
|
MacDockIconHandler(); |
||||||
|
|
||||||
|
objc_object *m_dockIconClickEventHandler; |
||||||
|
QWidget *m_dummyWidget; |
||||||
|
QMenu *m_dockMenu; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // MACDOCKICONCLICKHANDLER_H
|
@ -0,0 +1,99 @@ |
|||||||
|
|
||||||
|
#include "macdockiconhandler.h" |
||||||
|
|
||||||
|
#include <QtGui/QMenu> |
||||||
|
#include <QtGui/QWidget> |
||||||
|
|
||||||
|
extern void qt_mac_set_dock_menu(QMenu*); |
||||||
|
|
||||||
|
#undef slots |
||||||
|
#include <Cocoa/Cocoa.h> |
||||||
|
|
||||||
|
@interface DockIconClickEventHandler : NSObject |
||||||
|
{ |
||||||
|
MacDockIconHandler* dockIconHandler; |
||||||
|
} |
||||||
|
|
||||||
|
@end |
||||||
|
|
||||||
|
@implementation DockIconClickEventHandler |
||||||
|
|
||||||
|
- (id)initWithDockIconHandler:(MacDockIconHandler *)aDockIconHandler |
||||||
|
{ |
||||||
|
self = [super init]; |
||||||
|
if (self) { |
||||||
|
dockIconHandler = aDockIconHandler; |
||||||
|
|
||||||
|
[[NSAppleEventManager sharedAppleEventManager] |
||||||
|
setEventHandler:self |
||||||
|
andSelector:@selector(handleDockClickEvent:withReplyEvent:) |
||||||
|
forEventClass:kCoreEventClass |
||||||
|
andEventID:kAEReopenApplication]; |
||||||
|
} |
||||||
|
return self; |
||||||
|
} |
||||||
|
|
||||||
|
- (void)handleDockClickEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent |
||||||
|
{ |
||||||
|
Q_UNUSED(event) |
||||||
|
Q_UNUSED(replyEvent) |
||||||
|
|
||||||
|
if (dockIconHandler) |
||||||
|
dockIconHandler->handleDockIconClickEvent(); |
||||||
|
} |
||||||
|
|
||||||
|
@end |
||||||
|
|
||||||
|
MacDockIconHandler::MacDockIconHandler() : QObject() |
||||||
|
{ |
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
||||||
|
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]; |
||||||
|
} |
||||||
|
|
||||||
|
MacDockIconHandler::~MacDockIconHandler() |
||||||
|
{ |
||||||
|
[this->m_dockIconClickEventHandler release]; |
||||||
|
delete this->m_dummyWidget; |
||||||
|
} |
||||||
|
|
||||||
|
QMenu *MacDockIconHandler::dockMenu() |
||||||
|
{ |
||||||
|
return this->m_dockMenu; |
||||||
|
} |
||||||
|
|
||||||
|
void MacDockIconHandler::setIcon(const QIcon &icon) |
||||||
|
{ |
||||||
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
||||||
|
NSImage *image; |
||||||
|
if (icon.isNull()) |
||||||
|
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]; |
||||||
|
else { |
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
[NSApp setApplicationIconImage:image]; |
||||||
|
[image release]; |
||||||
|
[pool release]; |
||||||
|
} |
||||||
|
|
||||||
|
MacDockIconHandler *MacDockIconHandler::instance() |
||||||
|
{ |
||||||
|
static MacDockIconHandler *s_instance = NULL; |
||||||
|
if (!s_instance) |
||||||
|
s_instance = new MacDockIconHandler(); |
||||||
|
return s_instance; |
||||||
|
} |
||||||
|
|
||||||
|
void MacDockIconHandler::handleDockIconClickEvent() |
||||||
|
{ |
||||||
|
emit this->dockIconClicked(); |
||||||
|
} |
Loading…
Reference in new issue