diff options
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r-- | src/plugins/platforms/cocoa/main.mm | 3 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaglcontext.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaglcontext.mm | 10 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 2 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qprintengine_mac.mm | 77 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qprintengine_mac_p.h | 1 |
6 files changed, 68 insertions, 27 deletions
diff --git a/src/plugins/platforms/cocoa/main.mm b/src/plugins/platforms/cocoa/main.mm index b730514b12..dd063b5da0 100644 --- a/src/plugins/platforms/cocoa/main.mm +++ b/src/plugins/platforms/cocoa/main.mm @@ -61,8 +61,7 @@ QPlatformIntegration * QCocoaIntegrationPlugin::create(const QString& system, co Q_UNUSED(paramList); QCocoaAutoReleasePool pool; - - if (system.toLower() == "cocoa") + if (!system.compare(QLatin1String("cocoa"), Qt::CaseInsensitive)) return new QCocoaIntegration; return 0; diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h index e1d4b602c9..30f1cdc278 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.h +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h @@ -75,6 +75,8 @@ public: bool isSharing() const; bool isValid() const; + void windowWasHidden(); + private: void setActiveWindow(QWindow *window); void updateSurfaceFormat(); diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index ba204236ee..8af90b13bf 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -165,6 +165,16 @@ QSurfaceFormat QCocoaGLContext::format() const return m_format; } +void QCocoaGLContext::windowWasHidden() +{ + // If the window is hidden, we need to unset the m_currentWindow + // variable so that succeeding makeCurrent's will not abort prematurely + // because of the optimization in setActiveWindow. + // Doing a full doneCurrent here is not preferable, because the GL context + // might be rendering in a different thread at this time. + m_currentWindow.clear(); +} + void QCocoaGLContext::swapBuffers(QPlatformSurface *surface) { QWindow *window = static_cast<QCocoaWindow *>(surface)->window(); diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index b5b9cec2be..1aace958ed 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -388,6 +388,8 @@ void QCocoaWindow::setVisible(bool visible) [m_contentView setHidden:NO]; } else { // qDebug() << "close" << this; + if (m_glContext) + m_glContext->windowWasHidden(); if (m_nsWindow) { if (m_hasModalSession) { QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher()); diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm index ee8d7ea157..f363b1772f 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm @@ -40,8 +40,7 @@ ****************************************************************************/ #include "qprintengine_mac_p.h" -#include <qdebug.h> -#include <qthread.h> +#include <quuid.h> #include <QtCore/qcoreapplication.h> #include <qpa/qplatformprintersupport.h> @@ -141,30 +140,51 @@ QMacPrintEnginePrivate::~QMacPrintEnginePrivate() void QMacPrintEnginePrivate::setPaperSize(QPrinter::PaperSize ps) { Q_Q(QMacPrintEngine); - QSizeF newSize = QPlatformPrinterSupport::convertPaperSizeToQSizeF(ps); - QCFType<CFArrayRef> formats; + if (hasCustomPaperSize) { + PMRelease(customPaper); + customPaper = 0; + } + hasCustomPaperSize = (ps == QPrinter::Custom); PMPrinter printer; - - if (PMSessionGetCurrentPrinter(session(), &printer) == noErr - && PMSessionCreatePageFormatList(session(), printer, &formats) == noErr) { - CFIndex total = CFArrayGetCount(formats); - PMPageFormat tmp; - PMRect paper; - for (CFIndex idx = 0; idx < total; ++idx) { - tmp = static_cast<PMPageFormat>( - const_cast<void *>(CFArrayGetValueAtIndex(formats, idx))); - PMGetUnadjustedPaperRect(tmp, &paper); - int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5); - int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5); - if (newSize.width() == wMM && newSize.height() == hMM) { - PMCopyPageFormat(tmp, format()); - // reset the orientation and resolution as they are lost in the copy. - q->setProperty(QPrintEngine::PPK_Orientation, orient); - if (PMSessionValidatePageFormat(session(), format(), kPMDontWantBoolean) != noErr) { - // Don't know, warn for the moment. - qWarning("QMacPrintEngine, problem setting format and resolution for this page size"); + if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) { + if (ps != QPrinter::Custom) { + QSizeF newSize = QPlatformPrinterSupport::convertPaperSizeToQSizeF(ps); + QCFType<CFArrayRef> formats; + if (PMSessionCreatePageFormatList(session(), printer, &formats) == noErr) { + CFIndex total = CFArrayGetCount(formats); + PMPageFormat tmp; + PMRect paper; + for (CFIndex idx = 0; idx < total; ++idx) { + tmp = static_cast<PMPageFormat>(const_cast<void *>(CFArrayGetValueAtIndex(formats, idx))); + PMGetUnadjustedPaperRect(tmp, &paper); + int wMM = int((paper.right - paper.left) / 72 * 25.4 + 0.5); + int hMM = int((paper.bottom - paper.top) / 72 * 25.4 + 0.5); + if (newSize.width() == wMM && newSize.height() == hMM) { + PMCopyPageFormat(tmp, format()); + // reset the orientation and resolution as they are lost in the copy. + q->setProperty(QPrintEngine::PPK_Orientation, orient); + if (PMSessionValidatePageFormat(session(), format(), kPMDontWantBoolean) != noErr) { + // Don't know, warn for the moment. + qWarning("QMacPrintEngine, problem setting format and resolution for this page size"); + } + break; + } } - break; + } + } else { + QCFString paperId = QCFString::toCFStringRef(QUuid::createUuid().toString()); + PMPaperMargins paperMargins; + paperMargins.left = leftMargin; + paperMargins.top = topMargin; + paperMargins.right = rightMargin; + paperMargins.bottom = bottomMargin; + PMPaperCreateCustom(printer, paperId, QCFString("Custom size"), customSize.width(), customSize.height(), &paperMargins, &customPaper); + PMPageFormat tmp; + PMCreatePageFormatWithPMPaper(&tmp, customPaper); + PMCopyPageFormat(tmp, format()); + if (PMSessionValidatePageFormat(session(), format(), kPMDontWantBoolean) != noErr) { + // Don't know, warn for the moment. + qWarning("QMacPrintEngine, problem setting paper name"); } } } @@ -183,6 +203,11 @@ QPrinter::PaperSize QMacPrintEnginePrivate::paperSize() const void QMacPrintEnginePrivate::setPaperName(const QString &name) { Q_Q(QMacPrintEngine); + if (hasCustomPaperSize) { + PMRelease(customPaper); + customPaper = 0; + hasCustomPaperSize = false; + } PMPrinter printer; if (PMSessionGetCurrentPrinter(session(), &printer) == noErr) { @@ -419,6 +444,8 @@ void QMacPrintEnginePrivate::releaseSession() { PMSessionEndPageNoDialog(session()); PMSessionEndDocumentNoDialog(session()); + if (hasCustomPaperSize) + PMRelease(customPaper); [printInfo release]; printInfo = 0; } @@ -665,10 +692,10 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va { PMOrientation orientation; PMGetOrientation(d->format(), &orientation); - d->hasCustomPaperSize = true; d->customSize = value.toSizeF(); if (orientation != kPMPortrait) d->customSize = QSizeF(d->customSize.height(), d->customSize.width()); + d->setPaperSize(QPrinter::Custom); break; } case PPK_PageMargins: diff --git a/src/plugins/platforms/cocoa/qprintengine_mac_p.h b/src/plugins/platforms/cocoa/qprintengine_mac_p.h index 28183118d8..644a07184f 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac_p.h +++ b/src/plugins/platforms/cocoa/qprintengine_mac_p.h @@ -135,6 +135,7 @@ public: qreal rightMargin; qreal bottomMargin; QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant> valueCache; + PMPaper customPaper; QMacPrintEnginePrivate() : mode(QPrinter::ScreenResolution), state(QPrinter::Idle), orient(QPrinter::Portrait), printInfo(0), paintEngine(0), hasCustomPaperSize(false), hasCustomPageMargins(false) {} |