Fix Qxt for Qt5?

BUG: 486
This commit is contained in:
craig.p.drummond
2014-05-27 18:30:40 +00:00
parent 9b47fdea16
commit 7b15a23795
5 changed files with 40 additions and 2 deletions

View File

@@ -24,24 +24,41 @@
****************************************************************************/
#include "qxtglobalshortcut.h"
#include "qxtglobalshortcut_p.h"
#if QT_VERSION<0x050000
#include <QAbstractEventDispatcher>
#else
#include <QAbstractNativeEventFilter>
#include <QCoreApplication>
#endif
#include <QtDebug>
bool QxtGlobalShortcutPrivate::error = false;
int QxtGlobalShortcutPrivate::ref = 0;
#if QT_VERSION<0x050000
QAbstractEventDispatcher::EventFilter QxtGlobalShortcutPrivate::prevEventFilter = 0;
#endif
QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts;
QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier)
{
if (!ref++)
if (!ref++) {
#if QT_VERSION<0x050000
prevEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter);
#else
QCoreApplication::instance()->installNativeEventFilter(this);
#endif
}
}
QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate()
{
if (!--ref)
if (!--ref) {
#if QT_VERSION<0x050000
QAbstractEventDispatcher::instance()->setEventFilter(prevEventFilter);
#else
QCoreApplication::instance()->removeNativeEventFilter(this);
#endif
}
}
bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)

View File

@@ -43,7 +43,11 @@ OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event,
return noErr;
}
#if QT_VERSION<0x050000
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
#else
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray &, void *message, long *result)
#endif
//bool QxtGlobalShortcutPrivate::macEventFilter(EventHandlerCallRef caller, EventRef event)
{
EventRef event = (EventRef) message;

View File

@@ -26,7 +26,12 @@
#define QXTGLOBALSHORTCUT_P_H
#include "qxtglobalshortcut.h"
#if QT_VERSION<0x050000
#include <QAbstractEventDispatcher>
#else
#include <QAbstractNativeEventFilter>
#include <QCoreApplication>
#endif
#include <QKeySequence>
#include <QHash>
@@ -46,8 +51,12 @@ public:
static bool error;
static int ref;
#if QT_VERSION<0x050000
static QAbstractEventDispatcher::EventFilter prevEventFilter;
static bool eventFilter(void* message);
#else
bool nativeEventFilter(const QByteArray &, void *message, long *result)
#endif
private:
static quint32 nativeKeycode(Qt::Key keycode);

View File

@@ -25,7 +25,11 @@
#include "qxtglobalshortcut_p.h"
#include <qt_windows.h>
#if QT_VERSION<0x050000
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
#else
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray &, void *message, long *result)
#endif
{
MSG* msg = static_cast<MSG*>(message);
if (msg->message == WM_HOTKEY)

View File

@@ -51,7 +51,11 @@ static int qxt_x_errhandler(Display* display, XErrorEvent *event)
}
}
#if QT_VERSION<0x050000
bool QxtGlobalShortcutPrivate::eventFilter(void* message)
#else
bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray &, void *message, long *result)
#endif
{
XEvent* event = static_cast<XEvent*>(message);
if (event->type == KeyPress)