aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-03-24 16:07:12 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-03-24 16:07:13 +0100
commit33480a083aa5cb2a3e5203fccf23238ac0644e34 (patch)
treeb830b3021a10a7f9a0639fe1f46a97fbdb4824f6
parent0e1279ccdffa9d704a6e1ae4d0bf626841b434dc (diff)
parent3d7f132db4f91eccce1987c2860834a0b88d392d (diff)
Merge remote-tracking branch 'origin/stable' into dev
-rw-r--r--src/macextras/qmacfunctions.mm36
-rw-r--r--src/macextras/qmacfunctions_ios.mm17
-rw-r--r--src/macextras/qmacfunctions_mac.mm30
-rw-r--r--src/macextras/qmacfunctions_p.h14
-rw-r--r--src/macextras/qmactoolbar.mm3
-rw-r--r--src/macextras/qmactoolbardelegate.mm11
-rw-r--r--tests/manual/mactoolbar/toolbarcontrollerwidget.cpp2
7 files changed, 63 insertions, 50 deletions
diff --git a/src/macextras/qmacfunctions.mm b/src/macextras/qmacfunctions.mm
index 187c6ee..881826a 100644
--- a/src/macextras/qmacfunctions.mm
+++ b/src/macextras/qmacfunctions.mm
@@ -44,6 +44,7 @@
#include <QByteArray>
#include <QPixmap>
#include <QUrl>
+#include <QString>
#include "qmacfunctions_p.h"
@@ -65,38 +66,21 @@ QT_BEGIN_NAMESPACE
namespace QtMac
{
-NSString *toNSString(const QString &string)
-{
- return [NSString stringWithCharacters:reinterpret_cast<const UniChar*>(string.unicode()) length:string.length()];
-}
-
-QString fromNSString(const NSString *string)
-{
- if (!string)
- return QString();
-
- QString qstring;
- qstring.resize([string length]);
- [string getCharacters:reinterpret_cast<unichar*>(qstring.data()) range:NSMakeRange(0, [string length])];
-
- return qstring;
-}
-
-NSURL* toNSURL(const QUrl &url)
-{
- return [NSURL URLWithString:toNSString(url.toString())];
-}
-
-QUrl fromNSURL(const NSURL *url)
-{
- return QUrl(fromNSString([url absoluteString]));
-}
+/*!
+ \obsolete
+ Use QByteArray::toNSData() instead.
+ */
NSData* toNSData(const QByteArray &data)
{
return [NSData dataWithBytes:data.constData() length:data.size()];
}
+/*!
+ \obsolete
+
+ Use QByteArray::fromNSData() instead.
+ */
QByteArray fromNSData(const NSData *data)
{
QByteArray ba;
diff --git a/src/macextras/qmacfunctions_ios.mm b/src/macextras/qmacfunctions_ios.mm
index ddc6a03..4004f5b 100644
--- a/src/macextras/qmacfunctions_ios.mm
+++ b/src/macextras/qmacfunctions_ios.mm
@@ -49,16 +49,31 @@ QT_BEGIN_NAMESPACE
namespace QtMac
{
+/*!
+ Returns the current CoreGraphics context.
+*/
CGContextRef currentCGContext()
{
return UIGraphicsGetCurrentContext();
}
+/*!
+ Sets the value shown on the application icon a.k.a badge.
+
+ Unlike its OS X counterpart, only numbers can be used.
+
+ \sa applicationIconBadgeNumber(), setBadgeLabelText()
+*/
void setApplicationIconBadgeNumber(int number)
{
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber: number];
+ [[UIApplication sharedApplication] setApplicationIconBadgeNumber:number];
}
+/*!
+ Returns the value of the application icon a.k.a badge.
+
+ \sa setApplicationIconBadgeNumber(), badgeLabelText()
+*/
int applicationIconBadgeNumber()
{
return [[UIApplication sharedApplication] applicationIconBadgeNumber];
diff --git a/src/macextras/qmacfunctions_mac.mm b/src/macextras/qmacfunctions_mac.mm
index 9901314..38f941f 100644
--- a/src/macextras/qmacfunctions_mac.mm
+++ b/src/macextras/qmacfunctions_mac.mm
@@ -45,6 +45,8 @@
#include "qmacfunctions.h"
#include "qmacfunctions_p.h"
+#include <QtCore/QString>
+
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/QWindow>
#include <QtWidgets/QMenu>
@@ -57,6 +59,12 @@ QT_BEGIN_NAMESPACE
namespace QtMac
{
+/*!
+ Creates an \c NSImage equivalent to the QPixmap. Returns the \c NSImage handle.
+
+ It is the caller's responsibility to release the \c NSImage data
+ after use.
+*/
NSImage* toNSImage(const QPixmap &pixmap)
{
NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:toCGImageRef(pixmap)];
@@ -67,6 +75,9 @@ NSImage* toNSImage(const QPixmap &pixmap)
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+/*!
+ Returns whether the given QWindow is the application's main window
+*/
bool isMainWindow(QWindow *window)
{
NSWindow *macWindow = static_cast<NSWindow*>(
@@ -78,19 +89,34 @@ bool isMainWindow(QWindow *window)
}
#endif
+/*!
+ Returns the current CoreGraphics context.
+*/
CGContextRef currentCGContext()
{
return reinterpret_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]);
}
+/*!
+ Sets the text shown on the application icon a.k.a badge.
+
+ This is generally used with numbers (e.g. number of unread emails); it can also show a string.
+
+ \sa badgeLabelText()
+*/
void setBadgeLabelText(const QString &text)
{
- [[[NSApplication sharedApplication] dockTile] setBadgeLabel:toNSString(text)];
+ [[[NSApplication sharedApplication] dockTile] setBadgeLabel:text.toNSString()];
}
+/*!
+ Returns the text of the application icon a.k.a badge.
+
+ \sa setBadgeText()
+*/
QString badgeLabelText()
{
- return fromNSString([[[NSApplication sharedApplication] dockTile] badgeLabel]);
+ return QString::fromNSString([[[NSApplication sharedApplication] dockTile] badgeLabel]);
}
} // namespace QtMac
diff --git a/src/macextras/qmacfunctions_p.h b/src/macextras/qmacfunctions_p.h
index b03b7ae..6d8211b 100644
--- a/src/macextras/qmacfunctions_p.h
+++ b/src/macextras/qmacfunctions_p.h
@@ -49,22 +49,8 @@
#include <QtGui/QGuiApplication>
#include <qpa/qplatformnativeinterface.h>
-// ### remove when merged to QtCore
-
-Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
-Q_FORWARD_DECLARE_OBJC_CLASS(NSURL);
-
QT_BEGIN_NAMESPACE
-namespace QtMac
-{
- Q_MACEXTRAS_EXPORT NSString *toNSString(const QString &string);
- Q_MACEXTRAS_EXPORT QString fromNSString(const NSString *string);
-
- Q_MACEXTRAS_EXPORT NSURL *toNSURL(const QUrl &url);
- Q_MACEXTRAS_EXPORT QUrl fromNSURL(const NSURL *url);
-}
-
inline QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePlatformFunction(const QByteArray &functionName)
{
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
diff --git a/src/macextras/qmactoolbar.mm b/src/macextras/qmactoolbar.mm
index 8093920..c75c9e8 100644
--- a/src/macextras/qmactoolbar.mm
+++ b/src/macextras/qmactoolbar.mm
@@ -45,6 +45,7 @@
#include <QtCore/QDebug>
#include <QtCore/QTimer>
#include <QtCore/QUuid>
+#include <QtCore/QString>
#include <QtCore/qdebug.h>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
@@ -324,7 +325,7 @@ NSMutableArray *QMacToolBarPrivate::getItemIdentifiers(const QList<QMacToolBarIt
void QMacToolBarPrivate::itemClicked(NSToolbarItem *item)
{
- QString identifier = QtMac::fromNSString([item itemIdentifier]);
+ QString identifier = QString::fromNSString([item itemIdentifier]);
QMacToolBarItem *toolButton = reinterpret_cast<QMacToolBarItem *>(identifier.toULongLong());
Q_EMIT toolButton->activated();
}
diff --git a/src/macextras/qmactoolbardelegate.mm b/src/macextras/qmactoolbardelegate.mm
index b6f3768..804879f 100644
--- a/src/macextras/qmactoolbardelegate.mm
+++ b/src/macextras/qmactoolbardelegate.mm
@@ -44,8 +44,9 @@
#include <QtGui/QImage>
#include <QtGui/QPixmap>
+#include <QtCore/QString>
+
#include "qmacfunctions.h"
-#include "qmacfunctions_p.h"
#include "qmactoolbar.h"
QT_USE_NAMESPACE
@@ -54,7 +55,7 @@ NSArray *toNSArray(const QList<QString> &stringList)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
foreach (const QString &string, stringList) {
- [array addObject : QtMac::toNSString(string)];
+ [array addObject:string.toNSString()];
}
return array;
}
@@ -107,12 +108,12 @@ QString qt_strippedText(QString s)
{
Q_UNUSED(toolbar);
Q_UNUSED(willBeInserted);
- const QString identifier = QtMac::fromNSString(itemIdentifier);
+ const QString identifier = QString::fromNSString(itemIdentifier);
QMacToolBarItem *toolButton = reinterpret_cast<QMacToolBarItem *>(identifier.toULongLong()); // string -> unisgned long long -> pointer
NSToolbarItem *toolbarItem = toolButton->nativeToolBarItem();
- [toolbarItem setTarget : self];
- [toolbarItem setAction : @selector(itemClicked:)];
+ [toolbarItem setTarget:self];
+ [toolbarItem setAction:@selector(itemClicked:)];
return toolbarItem;
}
diff --git a/tests/manual/mactoolbar/toolbarcontrollerwidget.cpp b/tests/manual/mactoolbar/toolbarcontrollerwidget.cpp
index 09148a8..1a38e53 100644
--- a/tests/manual/mactoolbar/toolbarcontrollerwidget.cpp
+++ b/tests/manual/mactoolbar/toolbarcontrollerwidget.cpp
@@ -62,7 +62,7 @@ ToolBarControllerWidget::ToolBarControllerWidget()
QLineEdit *fooItemText = new QLineEdit(this);
fooItemText->setText("Foo");
fooItemText->move(10, 10);
- connect(fooItemText, SIGNAL(textChanged(const QString &)), this, SLOT(changeItemText(const QString &)));
+ connect(fooItemText, SIGNAL(textChanged(QString)), this, SLOT(changeItemText(QString)));
winId();
toolBar->attachToWindow(windowHandle());