From 5b70efb1258fd7435e8cfbed1a54abb46db0adcc Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Thu, 26 Sep 2013 13:37:08 +0200 Subject: [PATCH] Mac: QWizard default background pixmap works again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-26722 Change-Id: I579111b5d34f8e3cdc6bb016d9c0e42ec3ffb8c9 Reviewed-by: Morten Johan Sørvig Reviewed-by: Gabriel de Dietrich Reviewed-by: Stephen Chu --- .../platforms/cocoa/qcocoanativeinterface.h | 6 +++ .../platforms/cocoa/qcocoanativeinterface.mm | 26 ++++++++++ src/widgets/dialogs/qwizard.cpp | 49 ++++++++----------- .../widgets/dialogs/qwizard/tst_qwizard.cpp | 20 ++------ 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h index 2e5e65f577..d30b281eb8 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h @@ -45,6 +45,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -91,6 +92,11 @@ private: Needed by the native print dialog in the Qt Print Support module. */ Q_INVOKABLE void *NSPrintInfoForPrintEngine(QPrintEngine *printEngine); + /* + Function to return the default background pixmap. + Needed by QWizard in the Qt widget module. + */ + Q_INVOKABLE QPixmap defaultBackgroundPixmapForQWizard(); // QMacPastebardMime support. The mac pasteboard void pointers are // QMacPastebardMime instances from the cocoa plugin or qtmacextras diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index a53a6bca46..972c171f69 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -50,6 +50,7 @@ #include #include +#include #include #include "qsurfaceformat.h" #include @@ -154,6 +155,31 @@ void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine #endif } +QPixmap QCocoaNativeInterface::defaultBackgroundPixmapForQWizard() +{ + QCFType url; + const int ExpectedImageWidth = 242; + const int ExpectedImageHeight = 414; + if (LSFindApplicationForInfo(kLSUnknownCreator, CFSTR("com.apple.KeyboardSetupAssistant"), + 0, 0, &url) == noErr) { + QCFType bundle = CFBundleCreate(kCFAllocatorDefault, url); + if (bundle) { + url = CFBundleCopyResourceURL(bundle, CFSTR("Background"), CFSTR("png"), 0); + if (url) { + QCFType imageSource = CGImageSourceCreateWithURL(url, 0); + QCFType image = CGImageSourceCreateImageAtIndex(imageSource, 0, 0); + if (image) { + int width = CGImageGetWidth(image); + int height = CGImageGetHeight(image); + if (width == ExpectedImageWidth && height == ExpectedImageHeight) + return QPixmap::fromImage(qt_mac_toQImage(image)); + } + } + } + } + return QPixmap(); +} + void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window) { Q_UNUSED(window); diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index dba3e8a97d..02d4d1ca27 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -59,9 +59,10 @@ #include "qset.h" #include "qstyle.h" #include "qvarlengtharray.h" -#if defined(Q_WS_MAC) -#include "private/qt_mac_p.h" -#include "qlibrary.h" +#if defined(Q_OS_MACX) +#include +#include +#include #elif !defined(QT_NO_STYLE_WINDOWSVISTA) #include "qwizard_win_p.h" #include "qtimer.h" @@ -604,7 +605,7 @@ public: void _q_updateButtonStates(); void _q_handleFieldObjectDestroyed(QObject *); void setStyle(QStyle *style); -#ifdef Q_WS_MAC +#ifdef Q_OS_MACX static QPixmap findDefaultBackgroundPixmap(); #endif @@ -1368,7 +1369,7 @@ bool QWizardPrivate::ensureButton(QWizard::WizardButton which) const } break; } -#ifdef Q_WS_MAC +#ifdef Q_OS_MACX pushButton->setAutoDefault(false); #endif pushButton->hide(); @@ -1706,32 +1707,22 @@ void QWizardPrivate::setStyle(QStyle *style) it.value()->setStyle(style); } -#ifdef Q_WS_MAC +#ifdef Q_OS_MACX QPixmap QWizardPrivate::findDefaultBackgroundPixmap() { - QCFType url; - const int ExpectedImageWidth = 242; - const int ExpectedImageHeight = 414; - if (LSFindApplicationForInfo(kLSUnknownCreator, CFSTR("com.apple.KeyboardSetupAssistant"), - 0, 0, &url) == noErr) { - QCFType bundle = CFBundleCreate(kCFAllocatorDefault, url); - if (bundle) { - url = CFBundleCopyResourceURL(bundle, CFSTR("Background"), CFSTR("tif"), 0); - if (url) { - QCFType imageSource = CGImageSourceCreateWithURL(url, 0); - QCFType image = CGImageSourceCreateImageAtIndex(imageSource, 0, 0); - if (image) { - int width = CGImageGetWidth(image); - int height = CGImageGetHeight(image); - if (width == ExpectedImageWidth && height == ExpectedImageHeight) - return QPixmap::fromMacCGImageRef(image); - } - } - } - } - return QPixmap(); - + QGuiApplication *app = qobject_cast(QCoreApplication::instance()); + if (!app) + return QPixmap(); + QPlatformNativeInterface *platformNativeInterface = app->platformNativeInterface(); + int at = platformNativeInterface->metaObject()->indexOfMethod("defaultBackgroundPixmapForQWizard()"); + if (at == -1) + return QPixmap(); + QMetaMethod defaultBackgroundPixmapForQWizard = platformNativeInterface->metaObject()->method(at); + QPixmap result; + if (!defaultBackgroundPixmapForQWizard.invoke(platformNativeInterface, Q_RETURN_ARG(QPixmap, result))) + return QPixmap(); + return result; } #endif @@ -2842,7 +2833,7 @@ QPixmap QWizard::pixmap(WizardPixmap which) const { Q_D(const QWizard); Q_ASSERT(uint(which) < NPixmaps); -#ifdef Q_WS_MAC +#ifdef Q_OS_MACX if (which == BackgroundPixmap && d->defaultPixmaps[BackgroundPixmap].isNull()) d->defaultPixmaps[BackgroundPixmap] = d->findDefaultBackgroundPixmap(); #endif diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index c3fc050275..c240b5eb35 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -439,14 +439,8 @@ void tst_QWizard::setPixmap() QVERIFY(wizard.pixmap(QWizard::BannerPixmap).isNull()); QVERIFY(wizard.pixmap(QWizard::LogoPixmap).isNull()); QVERIFY(wizard.pixmap(QWizard::WatermarkPixmap).isNull()); -#ifdef Q_OS_MAC - if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_3) { - QEXPECT_FAIL("", "QTBUG-23701", Continue); - QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull() == false); - } else { - // fall through since the image doesn't exist on a 10.3 system. - QVERIFY(page->pixmap(QWizard::BackgroundPixmap).isNull()); - } +#ifdef Q_OS_MACX + QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull() == false); #else QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull()); #endif @@ -454,14 +448,8 @@ void tst_QWizard::setPixmap() QVERIFY(page->pixmap(QWizard::BannerPixmap).isNull()); QVERIFY(page->pixmap(QWizard::LogoPixmap).isNull()); QVERIFY(page->pixmap(QWizard::WatermarkPixmap).isNull()); -#ifdef Q_OS_MAC - if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_3) { - QEXPECT_FAIL("", "QTBUG-23701", Continue); - QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull() == false); - } else { - // fall through since the image doesn't exist on a 10.3 system. - QVERIFY(page->pixmap(QWizard::BackgroundPixmap).isNull()); - } +#ifdef Q_OS_MACX + QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull() == false); #else QVERIFY(page->pixmap(QWizard::BackgroundPixmap).isNull()); #endif