aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@petroules.com>2013-04-15 20:30:56 -0400
committerMorten Johan Sørvig <morten.sorvig@digia.com>2013-04-16 11:35:24 +0200
commit3bd4c28a4ddfe7b2928f5f6adb025b09b25f1887 (patch)
tree7712cf4688b982a5bfd019b8642ecaee2e8a808d
parentdbbe46bf04399c6f4943a5c622c470b6d55809e6 (diff)
Add a method for getting the current CGContext on both Darwin OSes.
Change-Id: I391f7ecaee0b57e5bb61bca1d0c966675af115e4 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
-rw-r--r--src/macextras/macextras-lib.pri7
-rw-r--r--src/macextras/qmacfunctions.h3
-rw-r--r--src/macextras/qmacfunctions_ios.mm58
-rw-r--r--src/macextras/qmacfunctions_mac.mm5
4 files changed, 72 insertions, 1 deletions
diff --git a/src/macextras/macextras-lib.pri b/src/macextras/macextras-lib.pri
index 7d28cb5..4a5dd94 100644
--- a/src/macextras/macextras-lib.pri
+++ b/src/macextras/macextras-lib.pri
@@ -5,7 +5,12 @@ mac {
PRIVATE_HEADERS += $$PWD/qmacfunctions_p.h
OBJECTIVE_SOURCES += $$PWD/qmacfunctions.mm
- !ios {
+ ios {
+ OBJECTIVE_SOURCES += \
+ $$PWD/qmacfunctions_ios.mm
+
+ LIBS *= -framework UIKit
+ } else {
PUBLIC_HEADERS += \
$$PWD/qmaccocoaviewcontainer.h \
$$PWD/qmacnativetoolbar.h \
diff --git a/src/macextras/qmacfunctions.h b/src/macextras/qmacfunctions.h
index 1fd14a0..2150aaf 100644
--- a/src/macextras/qmacfunctions.h
+++ b/src/macextras/qmacfunctions.h
@@ -49,6 +49,7 @@
#include "qmacextrasglobal.h"
typedef struct CGImage *CGImageRef;
+typedef struct CGContext *CGContextRef;
#ifdef __OBJC__
@class NSData;
@@ -87,6 +88,8 @@ Q_MACEXTRAS_EXPORT QByteArray fromNSData(const NSData *data);
Q_MACEXTRAS_EXPORT CGImageRef toCGImageRef(const QPixmap &pixmap);
Q_MACEXTRAS_EXPORT QPixmap fromCGImageRef(CGImageRef image);
+Q_MACEXTRAS_EXPORT CGContextRef currentCGContext();
+
#ifndef Q_OS_IOS
Q_MACEXTRAS_EXPORT NSImage* toNSImage(const QPixmap &pixmap);
diff --git a/src/macextras/qmacfunctions_ios.mm b/src/macextras/qmacfunctions_ios.mm
new file mode 100644
index 0000000..ae09e1f
--- /dev/null
+++ b/src/macextras/qmacfunctions_ios.mm
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Petroules Corporation.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtMacExtras module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmacfunctions.h"
+#include "qmacfunctions_p.h"
+#import <UIKit/UIKit.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QtMacExtras
+{
+
+CGContextRef currentCGContext()
+{
+ return UIGraphicsGetCurrentContext();
+}
+
+} // namespace QtMacExtras
+
+QT_END_NAMESPACE
diff --git a/src/macextras/qmacfunctions_mac.mm b/src/macextras/qmacfunctions_mac.mm
index 728c235..a78792a 100644
--- a/src/macextras/qmacfunctions_mac.mm
+++ b/src/macextras/qmacfunctions_mac.mm
@@ -110,6 +110,11 @@ void setDockMenu(QMenu *menu)
}
}
+CGContextRef currentCGContext()
+{
+ return reinterpret_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]);
+}
+
} // namespace QtMacExtras
QT_END_NAMESPACE