Port Qt 5 to Mac.
This commit is contained in:
parent
516f4e283b
commit
864815ef2e
@ -39,7 +39,11 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
int main(int, char **)
|
||||
{
|
||||
|
10
configure
vendored
10
configure
vendored
@ -3311,7 +3311,7 @@ if [ '!' -z "$CFG_SDK" ]; then
|
||||
fi
|
||||
|
||||
# find the default framework value
|
||||
if [ "$PLATFORM_MAC" = "yes" ] && [ "$PLATFORM" != "macx-xlc" ]; then
|
||||
if [ "$CFG_ARCH" = "macosx" ]; then
|
||||
if [ "$CFG_FRAMEWORK" = "auto" ]; then
|
||||
CFG_FRAMEWORK="$CFG_SHARED"
|
||||
elif [ "$CFG_FRAMEWORK" = "yes" ] && [ "$CFG_SHARED" = "no" ]; then
|
||||
@ -3450,7 +3450,7 @@ if [ "$PLATFORM_MAC" = "yes" ] && [ "$XPLATFORM_SYMBIAN" = "no" ]; then
|
||||
fi
|
||||
|
||||
# find the default framework value
|
||||
if [ "$PLATFORM_MAC" = "yes" ] && [ "$PLATFORM" != "macx-xlc" ]; then
|
||||
if [ "$CFG_ARCH" = "macosx" ]; then
|
||||
if [ "$CFG_FRAMEWORK" = "auto" ]; then
|
||||
CFG_FRAMEWORK="$CFG_SHARED"
|
||||
elif [ "$CFG_FRAMEWORK" = "yes" ] && [ "$CFG_SHARED" = "no" ]; then
|
||||
@ -6188,7 +6188,9 @@ fi
|
||||
|
||||
if [ "$PLATFORM_QPA" = "yes" ]; then
|
||||
# auto-detect OpenGL support (es1 = OpenGL ES 1.x Common, es2 = OpenGL ES 2.x)
|
||||
if [ "$CFG_OPENGL" = "auto" ] || [ "$CFG_OPENGL" = "yes" ]; then
|
||||
if [ "$CFG_ARCH" = "macosx" ]; then
|
||||
CFG_OPENGL=desktop
|
||||
elif [ "$CFG_OPENGL" = "auto" ] || [ "$CFG_OPENGL" = "yes" ]; then
|
||||
if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/opengldesktop "OpenGL" $L_FLAGS $I_FLAGS $l_FLAGS $X11TESTS_FLAGS; then
|
||||
CFG_OPENGL=desktop
|
||||
elif "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/opengles2 "OpenGL ES 2.x" $L_FLAGS $I_FLAGS $l_FLAGS; then
|
||||
@ -7342,7 +7344,7 @@ fi
|
||||
[ '!' -z "$L_FLAGS" ] && QMakeVar add QMAKE_LIBDIR_FLAGS "$L_FLAGS"
|
||||
[ '!' -z "$l_FLAGS" ] && QMakeVar add LIBS "$l_FLAGS"
|
||||
|
||||
if [ "$PLATFORM_MAC" = "yes" ]; then
|
||||
if [ "$CFG_ARCH" = "macosx" ]; then
|
||||
if [ "$CFG_RPATH" = "yes" ]; then
|
||||
QMAKE_CONFIG="$QMAKE_CONFIG absolute_library_soname"
|
||||
fi
|
||||
|
@ -39,6 +39,11 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(QWS) && defined(Q_OS_MAC)
|
||||
# include "private/qcore_mac_p.h"
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#include "qglobal.h"
|
||||
|
||||
#ifndef QT_NO_SYSTEMLOCALE
|
||||
@ -65,10 +70,6 @@ QT_END_NAMESPACE
|
||||
# include "qt_windows.h"
|
||||
# include <time.h>
|
||||
#endif
|
||||
#if !defined(QWS) && defined(Q_OS_MAC)
|
||||
# include "private/qcore_mac_p.h"
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
#include "private/qnumeric_p.h"
|
||||
#include "private/qsystemlibrary_p.h"
|
||||
|
||||
|
@ -58,7 +58,7 @@ QT_BEGIN_HEADER
|
||||
# include <QtCore/qt_windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(Q_WS_MAC)
|
||||
#if defined(Q_OS_MAC)
|
||||
# include <OpenGL/gl.h>
|
||||
#elif defined(QT_OPENGL_ES_1)
|
||||
# if defined(Q_OS_MAC)
|
||||
|
@ -55,7 +55,7 @@
|
||||
|
||||
|
||||
#include <qpaintdevice.h>
|
||||
#include <qgl.h>
|
||||
#include <QtOpenGL/qgl.h>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -9,7 +9,8 @@ OBJECTIVE_SOURCES = main.mm \
|
||||
qnsview.mm \
|
||||
qcocoaeventloopintegration.mm \
|
||||
qcocoaautoreleasepool.mm \
|
||||
qnswindowdelegate.mm
|
||||
qnswindowdelegate.mm \
|
||||
qcocoaglcontext.mm
|
||||
|
||||
OBJECTIVE_HEADERS = qcocoaintegration.h \
|
||||
qcocoawindowsurface.h \
|
||||
@ -17,13 +18,16 @@ OBJECTIVE_HEADERS = qcocoaintegration.h \
|
||||
qnsview.h \
|
||||
qcocoaeventloopintegration.h \
|
||||
qcocoaautoreleasepool.h \
|
||||
qnswindowdelegate.h
|
||||
qnswindowdelegate.h \
|
||||
qcocoaglcontext.h
|
||||
|
||||
#add libz for freetype.
|
||||
LIBS += -lz
|
||||
LIBS += -framework cocoa
|
||||
|
||||
include(../fontdatabases/coretext/coretext.pri)
|
||||
QT += core-private gui-private
|
||||
|
||||
include(../fontdatabases/basicunix/basicunix.pri)
|
||||
target.path += $$[QT_INSTALL_PLUGINS]/platforms
|
||||
INSTALLS += target
|
||||
|
||||
|
@ -47,9 +47,6 @@
|
||||
|
||||
#include <QtCore/QElapsedTimer>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
|
||||
void wakeupCallback ( void * ) {
|
||||
QPlatformEventLoopIntegration::processEvents();
|
||||
}
|
||||
|
27
src/plugins/platforms/cocoa/qcocoaglcontext.h
Normal file
27
src/plugins/platforms/cocoa/qcocoaglcontext.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef QCOCOAGLCONTEXT_H
|
||||
#define QCOCOAGLCONTEXT_H
|
||||
|
||||
#include <QtGui/QPlatformGLContext>
|
||||
#include <QtGui/QWindowFormat>
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QCocoaGLContext : public QPlatformGLContext
|
||||
{
|
||||
public:
|
||||
QCocoaGLContext(NSOpenGLView *glView);
|
||||
void makeCurrent();
|
||||
void doneCurrent();
|
||||
void swapBuffers();
|
||||
void* getProcAddress(const QString& procName);
|
||||
QWindowFormat windowFormat() const;
|
||||
static NSOpenGLPixelFormat *createNSOpenGLPixelFormat();
|
||||
private:
|
||||
NSOpenGLView *m_glView;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QCOCOAGLCONTEXT_H
|
78
src/plugins/platforms/cocoa/qcocoaglcontext.mm
Normal file
78
src/plugins/platforms/cocoa/qcocoaglcontext.mm
Normal file
@ -0,0 +1,78 @@
|
||||
#include "qcocoaglcontext.h"
|
||||
#include <qdebug.h>
|
||||
#include <QtCore/private/qcore_mac_p.h>
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
QCocoaGLContext::QCocoaGLContext(NSOpenGLView *glView)
|
||||
:m_glView(glView)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QCocoaGLContext::makeCurrent()
|
||||
{
|
||||
[[m_glView openGLContext] makeCurrentContext];
|
||||
}
|
||||
void QCocoaGLContext::doneCurrent()
|
||||
{
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
}
|
||||
|
||||
void QCocoaGLContext::swapBuffers()
|
||||
{
|
||||
[[m_glView openGLContext] flushBuffer];
|
||||
}
|
||||
|
||||
void* QCocoaGLContext::getProcAddress(const QString& procName)
|
||||
{
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
||||
CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, false);
|
||||
CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url);
|
||||
CFStringRef procNameCF = QCFString::toCFStringRef(procName);
|
||||
void *proc = CFBundleGetFunctionPointerForName(bundle, procNameCF);
|
||||
CFRelease(url);
|
||||
CFRelease(bundle);
|
||||
CFRelease(procNameCF);
|
||||
return proc;
|
||||
}
|
||||
|
||||
// Match up with createNSOpenGLPixelFormat below!
|
||||
QWindowFormat QCocoaGLContext::windowFormat() const
|
||||
{
|
||||
QWindowFormat format;
|
||||
format.setRedBufferSize(8);
|
||||
format.setGreenBufferSize(8);
|
||||
format.setBlueBufferSize(8);
|
||||
format.setAlphaBufferSize(8);
|
||||
|
||||
/*
|
||||
format.setDepthBufferSize(24);
|
||||
format.setAccumBufferSize(0);
|
||||
format.setStencilBufferSize(8);
|
||||
format.setSampleBuffers(false);
|
||||
format.setSamples(1);
|
||||
format.setDepth(true);
|
||||
format.setRgba(true);
|
||||
format.setAlpha(true);
|
||||
format.setAccum(false);
|
||||
format.setStencil(true);
|
||||
format.setStereo(false);
|
||||
format.setDirectRendering(false);
|
||||
*/
|
||||
return format;
|
||||
}
|
||||
|
||||
NSOpenGLPixelFormat *QCocoaGLContext::createNSOpenGLPixelFormat()
|
||||
{
|
||||
NSOpenGLPixelFormatAttribute attrs[] =
|
||||
{
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
NSOpenGLPFADepthSize, 32,
|
||||
0
|
||||
};
|
||||
|
||||
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
||||
return pixelFormat;
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ public:
|
||||
|
||||
bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||
QPixmapData *createPixmapData(QPixmapData::PixelType type) const;
|
||||
QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const;
|
||||
QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const;
|
||||
QPlatformWindow *createPlatformWindow(QWindow *window) const;
|
||||
QWindowSurface *createWindowSurface(QWindow *widget, WId winId) const;
|
||||
|
||||
QList<QPlatformScreen *> screens() const { return mScreens; }
|
||||
|
||||
|
@ -45,9 +45,7 @@
|
||||
#include "qcocoawindowsurface.h"
|
||||
#include "qcocoaeventloopintegration.h"
|
||||
|
||||
#include "qcoretextfontdatabase.h"
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include "qbasicunixfontdatabase.h"
|
||||
|
||||
#include <private/qpixmap_raster_p.h>
|
||||
|
||||
@ -74,7 +72,7 @@ QCocoaScreen::~QCocoaScreen()
|
||||
}
|
||||
|
||||
QCocoaIntegration::QCocoaIntegration()
|
||||
: mFontDb(new QCoreTextFontDatabase())
|
||||
: mFontDb(new QBasicUnixFontDatabase())
|
||||
{
|
||||
mPool = new QCocoaAutoReleasePool;
|
||||
|
||||
@ -98,6 +96,7 @@ bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) cons
|
||||
{
|
||||
switch (cap) {
|
||||
case ThreadedPixmaps: return true;
|
||||
case OpenGL : return true;
|
||||
default: return QPlatformIntegration::hasCapability(cap);
|
||||
}
|
||||
}
|
||||
@ -109,15 +108,14 @@ QPixmapData *QCocoaIntegration::createPixmapData(QPixmapData::PixelType type) co
|
||||
return new QRasterPixmapData(type);
|
||||
}
|
||||
|
||||
QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWidget *widget, WId winId) const
|
||||
QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWindow *window) const
|
||||
{
|
||||
Q_UNUSED(winId);
|
||||
return new QCocoaWindow(widget);
|
||||
return new QCocoaWindow(window);
|
||||
}
|
||||
|
||||
QWindowSurface *QCocoaIntegration::createWindowSurface(QWidget *widget, WId winId) const
|
||||
QWindowSurface *QCocoaIntegration::createWindowSurface(QWindow *window, WId winId) const
|
||||
{
|
||||
return new QCocoaWindowSurface(widget,winId);
|
||||
return new QCocoaWindowSurface(window, winId);
|
||||
}
|
||||
|
||||
QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const
|
||||
|
@ -46,27 +46,32 @@
|
||||
|
||||
#include <QPlatformWindow>
|
||||
|
||||
#include "qcocoaglcontext.h"
|
||||
#include "qnsview.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QCocoaWindow : public QPlatformWindow
|
||||
{
|
||||
public:
|
||||
QCocoaWindow(QWidget *tlw);
|
||||
QCocoaWindow(QWindow *tlw);
|
||||
~QCocoaWindow();
|
||||
|
||||
void setGeometry(const QRect &rect);
|
||||
|
||||
void setVisible(bool visible);
|
||||
|
||||
WId winId() const;
|
||||
|
||||
NSView *contentView() const;
|
||||
void setContentView(NSView *contentView);
|
||||
|
||||
void windowDidResize();
|
||||
|
||||
QPlatformGLContext *glContext() const;
|
||||
|
||||
private:
|
||||
friend class QCocoaWindowSurface;
|
||||
NSWindow *m_nsWindow;
|
||||
QNSView *m_contentView;
|
||||
NSView *m_windowSurfaceView;
|
||||
mutable QCocoaGLContext *m_glContext;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -41,17 +41,16 @@
|
||||
#include "qcocoawindow.h"
|
||||
#include "qnswindowdelegate.h"
|
||||
#include "qcocoaautoreleasepool.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include "qcocoaglcontext.h"
|
||||
#include "qnsview.h"
|
||||
|
||||
#include <QWindowSystemInterface>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
QCocoaWindow::QCocoaWindow(QWidget *tlw)
|
||||
QCocoaWindow::QCocoaWindow(QWindow *tlw)
|
||||
: QPlatformWindow(tlw)
|
||||
, m_glContext(0)
|
||||
{
|
||||
QCocoaAutoReleasePool pool;
|
||||
const QRect geo = tlw->geometry();
|
||||
@ -67,6 +66,20 @@ QCocoaWindow::QCocoaWindow(QWidget *tlw)
|
||||
|
||||
[m_nsWindow makeKeyAndOrderFront:nil];
|
||||
[m_nsWindow setAcceptsMouseMovedEvents:YES];
|
||||
|
||||
m_contentView = [[QNSView alloc] initWithQWindow:tlw];
|
||||
|
||||
if (tlw->surfaceType() == QWindow::OpenGLSurface) {
|
||||
NSRect glFrame = NSMakeRect(0, 0, geo.width(), geo.height());
|
||||
m_windowSurfaceView = [[NSOpenGLView alloc] initWithFrame : glFrame pixelFormat : QCocoaGLContext::createNSOpenGLPixelFormat() ];
|
||||
[m_contentView setAutoresizesSubviews : YES];
|
||||
[m_windowSurfaceView setAutoresizingMask : (NSViewWidthSizable | NSViewHeightSizable)];
|
||||
[m_contentView addSubview : m_windowSurfaceView];
|
||||
} else {
|
||||
m_windowSurfaceView = m_contentView;
|
||||
}
|
||||
|
||||
[m_nsWindow setContentView:m_contentView];
|
||||
}
|
||||
|
||||
QCocoaWindow::~QCocoaWindow()
|
||||
@ -88,7 +101,7 @@ void QCocoaWindow::setVisible(bool visible)
|
||||
|
||||
WId QCocoaWindow::winId() const
|
||||
{
|
||||
return WId([m_nsWindow windowNumber]);
|
||||
return WId(m_nsWindow);
|
||||
}
|
||||
|
||||
NSView *QCocoaWindow::contentView() const
|
||||
@ -96,15 +109,18 @@ NSView *QCocoaWindow::contentView() const
|
||||
return [m_nsWindow contentView];
|
||||
}
|
||||
|
||||
void QCocoaWindow::setContentView(NSView *contentView)
|
||||
{
|
||||
[m_nsWindow setContentView:contentView];
|
||||
}
|
||||
|
||||
void QCocoaWindow::windowDidResize()
|
||||
{
|
||||
//jlind: XXX This isn't ideal. Eventdispatcher does not run when resizing...
|
||||
NSRect rect = [[m_nsWindow contentView]frame];
|
||||
QRect geo(rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
|
||||
QWindowSystemInterface::handleGeometryChange(widget(),geo);
|
||||
QWindowSystemInterface::handleGeometryChange(window(),geo);
|
||||
}
|
||||
|
||||
QPlatformGLContext *QCocoaWindow::glContext() const
|
||||
{
|
||||
if (!m_glContext) {
|
||||
m_glContext = new QCocoaGLContext(m_windowSurfaceView);
|
||||
}
|
||||
return m_glContext;
|
||||
}
|
||||
|
@ -54,18 +54,16 @@ QT_BEGIN_NAMESPACE
|
||||
class QCocoaWindowSurface : public QWindowSurface
|
||||
{
|
||||
public:
|
||||
QCocoaWindowSurface(QWidget *window, WId wid);
|
||||
QCocoaWindowSurface(QWindow *window, WId wid);
|
||||
~QCocoaWindowSurface();
|
||||
|
||||
QPaintDevice *paintDevice();
|
||||
void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset);
|
||||
void flush(QWindow *widget, const QRegion ®ion, const QPoint &offset);
|
||||
void resize (const QSize &size);
|
||||
|
||||
private:
|
||||
|
||||
QCocoaWindow *m_cocoaWindow;
|
||||
QImage *m_image;
|
||||
QNSView *m_contentView;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include "qcocoawindowsurface.h"
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -56,17 +55,16 @@ QRect flipedRect(const QRect &sourceRect,int height)
|
||||
return flippedRect;
|
||||
}
|
||||
|
||||
QCocoaWindowSurface::QCocoaWindowSurface(QWidget *window, WId wId)
|
||||
QCocoaWindowSurface::QCocoaWindowSurface(QWindow *window, WId wId)
|
||||
: QWindowSurface(window)
|
||||
{
|
||||
m_cocoaWindow = static_cast<QCocoaWindow *>(window->platformWindow());
|
||||
Q_UNUSED(wId);
|
||||
m_cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
|
||||
|
||||
const QRect geo = window->geometry();
|
||||
NSRect rect = NSMakeRect(geo.x(),geo.y(),geo.width(),geo.height());
|
||||
m_contentView = [[QNSView alloc] initWithWidget:window];
|
||||
m_cocoaWindow->setContentView(m_contentView);
|
||||
|
||||
m_image = new QImage(window->size(),QImage::Format_ARGB32);
|
||||
m_image = new QImage(window->geometry().size(),QImage::Format_ARGB32);
|
||||
}
|
||||
|
||||
QCocoaWindowSurface::~QCocoaWindowSurface()
|
||||
@ -79,7 +77,7 @@ QPaintDevice *QCocoaWindowSurface::paintDevice()
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void QCocoaWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset)
|
||||
void QCocoaWindowSurface::flush(QWindow *widget, const QRegion ®ion, const QPoint &offset)
|
||||
{
|
||||
Q_UNUSED(widget);
|
||||
Q_UNUSED(offset);
|
||||
@ -87,7 +85,7 @@ void QCocoaWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QP
|
||||
QRect geo = region.boundingRect();
|
||||
|
||||
NSRect rect = NSMakeRect(geo.x(), geo.y(), geo.width(), geo.height());
|
||||
[m_contentView displayRect:rect];
|
||||
[m_cocoaWindow->m_windowSurfaceView displayRect:rect];
|
||||
}
|
||||
|
||||
void QCocoaWindowSurface::resize(const QSize &size)
|
||||
@ -96,8 +94,7 @@ void QCocoaWindowSurface::resize(const QSize &size)
|
||||
delete m_image;
|
||||
m_image = new QImage(size,QImage::Format_ARGB32_Premultiplied);
|
||||
NSSize newSize = NSMakeSize(size.width(),size.height());
|
||||
[m_contentView setImage:m_image];
|
||||
|
||||
[m_cocoaWindow->m_windowSurfaceView setImage:m_image];
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -48,17 +48,18 @@
|
||||
|
||||
@interface QNSView : NSView {
|
||||
CGImageRef m_cgImage;
|
||||
QWidget *m_widget;
|
||||
QWindow *m_window;
|
||||
Qt::MouseButtons m_buttons;
|
||||
}
|
||||
|
||||
- (id)init;
|
||||
- (id)initWithWidget:(QWidget *)widget;
|
||||
- (id)initWithQWindow:(QWindow *)window;
|
||||
|
||||
- (void)setImage:(QImage *)image;
|
||||
- (void)drawRect:(NSRect)dirtyRect;
|
||||
|
||||
- (BOOL)isFlipped;
|
||||
- (BOOL)acceptsFirstResponder;
|
||||
|
||||
- (void)handleMouseEvent:(NSEvent *)theEvent;
|
||||
- (void)mouseDown:(NSEvent *)theEvent;
|
||||
@ -74,6 +75,12 @@
|
||||
- (void)otherMouseDragged:(NSEvent *)theEvent;
|
||||
- (void)otherMouseUp:(NSEvent *)theEvent;
|
||||
|
||||
- (int) convertKeyCode : (QChar)keyCode;
|
||||
- (Qt::KeyboardModifiers) convertKeyModifiers : (ulong)modifierFlags;
|
||||
- (void)handleKeyEvent:(NSEvent *)theEvent eventType:(int)eventType;
|
||||
- (void)keyDown:(NSEvent *)theEvent;
|
||||
- (void)keyUp:(NSEvent *)theEvent;
|
||||
|
||||
@end
|
||||
|
||||
#endif //QNSVIEW_H
|
||||
|
@ -52,16 +52,16 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
m_cgImage = 0;
|
||||
m_widget = 0;
|
||||
m_window = 0;
|
||||
m_buttons = Qt::NoButton;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithWidget:(QWidget *)widget {
|
||||
- (id)initWithQWindow:(QWindow *)widget {
|
||||
self = [self init];
|
||||
if (self) {
|
||||
m_widget = widget;
|
||||
m_window = widget;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -130,6 +130,11 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)acceptsFirstResponder
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)handleMouseEvent:(NSEvent *)theEvent;
|
||||
{
|
||||
NSPoint point = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
||||
@ -138,20 +143,23 @@
|
||||
NSTimeInterval timestamp = [theEvent timestamp];
|
||||
ulong qt_timestamp = timestamp * 1000;
|
||||
|
||||
QWindowSystemInterface::handleMouseEvent(m_widget,qt_timestamp,qt_localPoint,QPoint(),m_buttons);
|
||||
QWindowSystemInterface::handleMouseEvent(m_window,qt_timestamp,qt_localPoint,QPoint(),m_buttons);
|
||||
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
m_buttons |= Qt::LeftButton;
|
||||
[self handleMouseEvent:theEvent];
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(NSEvent *)theEvent
|
||||
{
|
||||
if (!(m_buttons & Qt::LeftButton))
|
||||
qWarning("Internal Mousebutton tracking invalid(missing Qt::LeftButton");
|
||||
[self handleMouseEvent:theEvent];
|
||||
}
|
||||
|
||||
- (void)mouseUp:(NSEvent *)theEvent
|
||||
{
|
||||
m_buttons &= QFlag(~int(Qt::LeftButton));
|
||||
@ -160,18 +168,17 @@
|
||||
|
||||
- (void)mouseMoved:(NSEvent *)theEvent
|
||||
{
|
||||
qDebug() << "mouseMove";
|
||||
[self handleMouseEvent:theEvent];
|
||||
}
|
||||
- (void)mouseEntered:(NSEvent *)theEvent
|
||||
{
|
||||
Q_UNUSED(theEvent);
|
||||
QWindowSystemInterface::handleEnterEvent(m_widget);
|
||||
QWindowSystemInterface::handleEnterEvent(m_window);
|
||||
}
|
||||
- (void)mouseExited:(NSEvent *)theEvent
|
||||
{
|
||||
Q_UNUSED(theEvent);
|
||||
QWindowSystemInterface::handleLeaveEvent(m_widget);
|
||||
QWindowSystemInterface::handleLeaveEvent(m_window);
|
||||
}
|
||||
- (void)rightMouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
@ -206,6 +213,84 @@
|
||||
[self handleMouseEvent:theEvent];
|
||||
}
|
||||
|
||||
- (int) convertKeyCode : (QChar)keyChar
|
||||
{
|
||||
if (keyChar.isLower())
|
||||
keyChar = keyChar.toUpper();
|
||||
int keyCode = keyChar.unicode();
|
||||
|
||||
int qtKeyCode = Qt::Key(keyCode); // default case, overrides below
|
||||
switch (keyCode) {
|
||||
case NSEnterCharacter: qtKeyCode = Qt::Key_Enter; break;
|
||||
case NSBackspaceCharacter: qtKeyCode = Qt::Key_Backspace; break;
|
||||
case NSTabCharacter: qtKeyCode = Qt::Key_Tab; break;
|
||||
case NSNewlineCharacter: qtKeyCode = Qt::Key_Return; break;
|
||||
case NSCarriageReturnCharacter: qtKeyCode = Qt::Key_Return; break;
|
||||
case NSBackTabCharacter: qtKeyCode = Qt::Key_Backtab; break;
|
||||
case 27 : qtKeyCode = Qt::Key_Escape; break;
|
||||
case NSDeleteCharacter : qtKeyCode = Qt::Key_Backspace; break; // Cocoa sends us delete when pressing backspace.
|
||||
case NSUpArrowFunctionKey: qtKeyCode = Qt::Key_Up; break;
|
||||
case NSDownArrowFunctionKey: qtKeyCode = Qt::Key_Down; break;
|
||||
case NSLeftArrowFunctionKey: qtKeyCode = Qt::Key_Left; break;
|
||||
case NSRightArrowFunctionKey: qtKeyCode = Qt::Key_Right; break;
|
||||
case NSInsertFunctionKey: qtKeyCode = Qt::Key_Insert; break;
|
||||
case NSDeleteFunctionKey: qtKeyCode = Qt::Key_Delete; break;
|
||||
case NSHomeFunctionKey: qtKeyCode = Qt::Key_Home; break;
|
||||
case NSEndFunctionKey: qtKeyCode = Qt::Key_End; break;
|
||||
case NSPageUpFunctionKey: qtKeyCode = Qt::Key_PageUp; break;
|
||||
case NSPageDownFunctionKey: qtKeyCode = Qt::Key_PageDown; break;
|
||||
case NSPrintScreenFunctionKey: qtKeyCode = Qt::Key_Print; break;
|
||||
case NSScrollLockFunctionKey: qtKeyCode = Qt::Key_ScrollLock; break;
|
||||
case NSPauseFunctionKey: qtKeyCode = Qt::Key_Pause; break;
|
||||
case NSSysReqFunctionKey: qtKeyCode = Qt::Key_SysReq; break;
|
||||
case NSMenuFunctionKey: qtKeyCode = Qt::Key_Menu; break;
|
||||
case NSHelpFunctionKey: qtKeyCode = Qt::Key_Help; break;
|
||||
default : break;
|
||||
}
|
||||
|
||||
// handle all function keys (F1-F35)
|
||||
if (keyCode >= NSF1FunctionKey && keyCode <= NSF35FunctionKey)
|
||||
qtKeyCode = Qt::Key_F1 + (keyCode - NSF1FunctionKey);
|
||||
|
||||
return qtKeyCode;
|
||||
}
|
||||
|
||||
- (Qt::KeyboardModifiers) convertKeyModifiers : (ulong)modifierFlags
|
||||
{
|
||||
Qt::KeyboardModifiers qtMods =Qt::NoModifier;
|
||||
if (modifierFlags & NSShiftKeyMask)
|
||||
qtMods |= Qt::ShiftModifier;
|
||||
if (modifierFlags & NSControlKeyMask)
|
||||
qtMods |= Qt::MetaModifier;
|
||||
if (modifierFlags & NSAlternateKeyMask)
|
||||
qtMods |= Qt::AltModifier;
|
||||
if (modifierFlags & NSCommandKeyMask)
|
||||
qtMods |= Qt::ControlModifier;
|
||||
if (modifierFlags & NSNumericPadKeyMask)
|
||||
qtMods |= Qt::KeypadModifier;
|
||||
return qtMods;
|
||||
}
|
||||
|
||||
- (void)handleKeyEvent:(NSEvent *)theEvent eventType:(int)eventType
|
||||
{
|
||||
NSTimeInterval timestamp = [theEvent timestamp];
|
||||
ulong qt_timestamp = timestamp * 1000;
|
||||
QString characters = QString::fromUtf8([[theEvent characters] UTF8String]);
|
||||
Qt::KeyboardModifiers modifiers = [self convertKeyModifiers : [theEvent modifierFlags]];
|
||||
QChar ch([[theEvent charactersIgnoringModifiers] characterAtIndex:0]);
|
||||
int keyCode = [self convertKeyCode : ch];
|
||||
|
||||
QWindowSystemInterface::handleKeyEvent(m_window, qt_timestamp, QEvent::Type(eventType), keyCode, modifiers, characters);
|
||||
}
|
||||
|
||||
- (void)keyDown:(NSEvent *)theEvent
|
||||
{
|
||||
[self handleKeyEvent : theEvent eventType :int(QEvent::KeyPress)];
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)theEvent
|
||||
{
|
||||
[self handleKeyEvent : theEvent eventType :int(QEvent::KeyRelease)];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -46,6 +46,26 @@
|
||||
|
||||
#include "qcocoawindow.h"
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
|
||||
@protocol NSWindowDelegate <NSObject>
|
||||
//- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
|
||||
//- (void)windowDidMiniaturize:(NSNotification*)notification;
|
||||
- (void)windowDidResize:(NSNotification *)notification;
|
||||
- (void)windowWillClose:(NSNotification *)notification;
|
||||
//- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame;
|
||||
//- (void)windowDidMove:(NSNotification *)notification;
|
||||
//- (BOOL)windowShouldClose:(id)window;
|
||||
//- (void)windowDidDeminiaturize:(NSNotification *)notification;
|
||||
//- (void)windowDidBecomeMain:(NSNotification*)notification;
|
||||
//- (void)windowDidResignMain:(NSNotification*)notification;
|
||||
//- (void)windowDidBecomeKey:(NSNotification*)notification;
|
||||
//- (void)windowDidResignKey:(NSNotification*)notification;
|
||||
//- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu;
|
||||
//- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard;
|
||||
//- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface QNSWindowDelegate : NSObject <NSWindowDelegate>
|
||||
{
|
||||
QCocoaWindow *m_cocoaWindow;
|
||||
|
@ -67,7 +67,7 @@
|
||||
- (void)windowWillClose:(NSNotification *)notification
|
||||
{
|
||||
Q_UNUSED(notification);
|
||||
QWindowSystemInterface::handleCloseEvent(m_cocoaWindow->widget());
|
||||
QWindowSystemInterface::handleCloseEvent(m_cocoaWindow->window());
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user