diff options
author | Jake Petroules <jake.petroules@petroules.com> | 2013-02-06 03:01:33 -0500 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-02-25 08:13:19 +0100 |
commit | 859a35f03599e4a9218fd89c31b8e43f06ef564e (patch) | |
tree | 9def10c2a13b52f927c56902e3ff46f3c9099bb7 | |
parent | 2ee7abead671c0b4a5dbd322977adeb5885691b8 (diff) |
Fix QtMacNativeWidget build with Qt 4.x and 5.0.
Change-Id: I66b3676251c32c4959828ba637d40e8b2aa62598
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
-rw-r--r-- | examples/qtmacnativewidget/main.mm | 9 | ||||
-rw-r--r-- | src/qtmacnativewidget.h | 12 | ||||
-rw-r--r-- | src/qtmacnativewidget.mm | 13 |
3 files changed, 24 insertions, 10 deletions
diff --git a/examples/qtmacnativewidget/main.mm b/examples/qtmacnativewidget/main.mm index c40518a..927eb73 100644 --- a/examples/qtmacnativewidget/main.mm +++ b/examples/qtmacnativewidget/main.mm @@ -39,7 +39,14 @@ ** ****************************************************************************/ -#include <QtWidgets> +#include <QApplication> +#include <QDebug> +#include <QHBoxLayout> +#include <QLineEdit> +#include <QPainter> +#include <QPushButton> +#include <QVBoxLayout> +#include <QWidget> #include <Cocoa/Cocoa.h> #include <qtmacnativewidget.h> diff --git a/src/qtmacnativewidget.h b/src/qtmacnativewidget.h index 78c453e..e6684de 100644 --- a/src/qtmacnativewidget.h +++ b/src/qtmacnativewidget.h @@ -41,7 +41,7 @@ #ifndef QTMACNATIVEWIDGET_H #define QTMACNATIVEWIDGET_H -#include <QtWidgets/QWidget> +#include <QWidget> #import <Availability.h> QT_BEGIN_HEADER @@ -52,24 +52,18 @@ QT_MODULE(Gui) #ifdef __OBJC__ @class NSView; +#else +typedef struct objc_object NSView; #endif class QtMacNativeWidget : public QWidget { Q_OBJECT public: -#ifdef __OBJC__ QtMacNativeWidget(NSView *parentView = 0); -#else - QtMacNativeWidget(void *parentView = 0); -#endif ~QtMacNativeWidget(); -#ifdef __OBJC__ NSView *nativeView() const; -#else - void *nativeView() const; -#endif QSize sizeHint() const; protected: diff --git a/src/qtmacnativewidget.mm b/src/qtmacnativewidget.mm index 83add40..8249d60 100644 --- a/src/qtmacnativewidget.mm +++ b/src/qtmacnativewidget.mm @@ -40,9 +40,11 @@ ****************************************************************************/ #include "qtmacnativewidget.h" +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #include <QtGui/QWindow> #include <QtGui/QGuiApplication> #include <qpa/qplatformnativeinterface.h> +#endif #include <qdebug.h> #import <Cocoa/Cocoa.h> @@ -67,6 +69,7 @@ QT_BEGIN_NAMESPACE +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) NSView *getEmbeddableView(QWindow *qtWindow) { // Set Qt::SubWindow flag. Should be done before crate() is @@ -83,6 +86,7 @@ NSView *getEmbeddableView(QWindow *qtWindow) NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow); return qtView; // qtView is ready for use. } +#endif /*! Create a QtMacNativeWidget with \a parentView as its "superview" (i.e., @@ -101,8 +105,12 @@ QtMacNativeWidget::QtMacNativeWidget(NSView *parentView) NSView *QtMacNativeWidget::nativeView() const { +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) winId(); return getEmbeddableView(windowHandle()); +#else + return reinterpret_cast<NSView*>(winId()); +#endif } /*! @@ -119,9 +127,14 @@ QSize QtMacNativeWidget::sizeHint() const { // QtMacNativeWidget really does not have any other choice // than to fill its designated area. +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) if (windowHandle()) return windowHandle()->size(); return QWidget::sizeHint(); +#else + NSRect frame = [nativeView() frame]; + return QSize(frame.size.width, frame.size.height); +#endif } /*! \reimp |