diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2014-02-03 22:21:43 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-08 10:39:17 +0100 |
commit | 2a6e372a490f6b539b5417b3275392ba6a041bd3 (patch) | |
tree | 4687ebeed7820359d9655fa7acd3af61a08033da /src/plugins/platforms/cocoa/qcocoahelpers.h | |
parent | fd0f1bc321a684a0dd57329943f1e6264f8fc7c6 (diff) |
Cocoa: Option handling.
Add qt_mac_resolveOption().
Support setting options using either an environment
variable or a QWindow property, with a default fallback
value. The options are resolved with precedence in
the mentioned order.
Adds options for the following:
NSView setWantsBestResolutionOPenGLSurface
NSVIew setWantsLayer
NSOpenGLContext NSOpenGLCPSurfaceOrder
The window properties use the _q_mac_camelCase format.
The environment variables use the QT_MAC_ALL_CAPS format.
Change-Id: I1978a02d62e107a2120d81ffdd0f7b32f7731644
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.h')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 64e1640a69..419bf631aa 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -162,6 +162,39 @@ CGContextRef qt_mac_cg_context(QPaintDevice *pdev); CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy); QImage qt_mac_toQImage(CGImageRef image); +template<typename T> +T qt_mac_resolveOption(const T &fallback, const QByteArray &environment) +{ + // check for environment variable + if (!environment.isEmpty()) { + QByteArray env = qgetenv(environment); + if (!env.isEmpty()) + return T(env.toInt()); // works when T is bool, int. + } + + return fallback; +} + +template<typename T> +T qt_mac_resolveOption(const T &fallback, QWindow *window, const QByteArray &property, const QByteArray &environment) +{ + // check for environment variable + if (!environment.isEmpty()) { + QByteArray env = qgetenv(environment); + if (!env.isEmpty()) + return T(env.toInt()); // works when T is bool, int. + } + + // check for window property + if (window && !property.isNull()) { + QVariant windowProperty = window->property(property); + if (windowProperty.isValid()) + return windowProperty.value<T>(); + } + + // return default value. + return fallback; +} QT_END_NAMESPACE #endif //QCOCOAHELPERS_H |