diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-09-18 12:07:45 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-26 10:24:54 +0200 |
commit | 24d45304aa363c9a08f7157d549cb37c07212108 (patch) | |
tree | f50b6e671f19d663dcd5ce4b18a57479a760b2d8 /src | |
parent | 1ef71fcdb15ac0b93751142629b4a2d1ab1e73c8 (diff) |
Remove QtWidgets dependencies from QtMacExtras.
This makes it possible to use QtMacExtras from other
modules without adding a QtWidgets dependency. It
also makes it possible to use QtMacExtras from
QtWidgets.
Widget-related classes and functions will be added
to QtWidgets.
Specifics:
Make QMacNativeToolBar private, for use by QMainWindow::
setUnifiedTitleAndToolBarOnMac(). Remove the QAction
based APIs. Remove the example. We can make QMacNativeToolBar
public again when the API is ready and documented.
Remove misc functions: toNSMenu, setDockMenu,
isMainWindow.
Make toCfSTring/Url private pending inclusion into
QtCore.
Change-Id: Ic55e78d8ef923149c23884f6589732f7dfb94153
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/macextras/macextras-lib.pri | 10 | ||||
-rw-r--r-- | src/macextras/macextras.pro | 1 | ||||
-rw-r--r-- | src/macextras/qmaccocoaviewcontainer.h | 70 | ||||
-rw-r--r-- | src/macextras/qmaccocoaviewcontainer.mm | 166 | ||||
-rw-r--r-- | src/macextras/qmacextrasglobal.h | 2 | ||||
-rw-r--r-- | src/macextras/qmacfunctions.h | 25 | ||||
-rw-r--r-- | src/macextras/qmacfunctions.mm | 5 | ||||
-rw-r--r-- | src/macextras/qmacfunctions_ios.mm | 1 | ||||
-rw-r--r-- | src/macextras/qmacfunctions_mac.mm | 61 | ||||
-rw-r--r-- | src/macextras/qmacfunctions_p.h | 14 | ||||
-rw-r--r-- | src/macextras/qmacnativetoolbar.mm | 157 | ||||
-rw-r--r-- | src/macextras/qmacnativetoolbar_p.h (renamed from src/macextras/qmacnativetoolbar.h) | 51 | ||||
-rw-r--r-- | src/macextras/qmacnativewidget.h | 72 | ||||
-rw-r--r-- | src/macextras/qmacnativewidget.mm | 148 | ||||
-rw-r--r-- | src/macextras/qmacpasteboardmime.mm | 5 | ||||
-rw-r--r-- | src/macextras/qmactoolbardelegate.mm | 85 | ||||
-rw-r--r-- | src/macextras/qmactoolbardelegate_p.h | 27 | ||||
-rw-r--r-- | src/macextras/qmactoolbutton.mm | 33 | ||||
-rw-r--r-- | src/macextras/qmactoolbutton_p.h (renamed from src/macextras/qmactoolbutton.h) | 18 |
19 files changed, 149 insertions, 802 deletions
diff --git a/src/macextras/macextras-lib.pri b/src/macextras/macextras-lib.pri index 245c4c5..8240436 100644 --- a/src/macextras/macextras-lib.pri +++ b/src/macextras/macextras-lib.pri @@ -11,21 +11,15 @@ mac { LIBS *= -framework UIKit } else { - PUBLIC_HEADERS += \ - $$PWD/qmaccocoaviewcontainer.h \ - $$PWD/qmacnativetoolbar.h \ - $$PWD/qmacnativewidget.h \ - $$PWD/qmactoolbutton.h - PRIVATE_HEADERS += \ + $$PWD/qmacnativetoolbar_p.h \ + $$PWD/qmactoolbutton_p.h \ $$PWD/qmactoolbardelegate_p.h \ $$PWD/qnstoolbar_p.h OBJECTIVE_SOURCES += \ - $$PWD/qmaccocoaviewcontainer.mm \ $$PWD/qmacfunctions_mac.mm \ $$PWD/qmacnativetoolbar.mm \ - $$PWD/qmacnativewidget.mm \ $$PWD/qmactoolbardelegate.mm \ $$PWD/qmactoolbutton.mm \ $$PWD/qnstoolbar.mm diff --git a/src/macextras/macextras.pro b/src/macextras/macextras.pro index 221dbdd..12f00cd 100644 --- a/src/macextras/macextras.pro +++ b/src/macextras/macextras.pro @@ -1,7 +1,6 @@ include($$PWD/macextras-lib.pri) load(qt_build_config) -QT += widgets QT_PRIVATE += gui-private core-private TARGET = QtMacExtras load(qt_module) diff --git a/src/macextras/qmaccocoaviewcontainer.h b/src/macextras/qmaccocoaviewcontainer.h deleted file mode 100644 index a9172ab..0000000 --- a/src/macextras/qmaccocoaviewcontainer.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - ** - ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). - ** Contact: http://www.qt-project.org/legal - ** - ** This file is part of the QtMacExtras module 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$ - ** - ****************************************************************************/ -#ifndef QMACCOCOAVIEWCONTAINER_H -#define QMACCOCOAVIEWCONTAINER_H - -#include "qmacextrasglobal.h" - -#include <QtWidgets/QWidget> - -Q_FORWARD_DECLARE_OBJC_CLASS(NSView); - -QT_BEGIN_NAMESPACE - -class QMacCocoaViewContainerPrivate; -class Q_MACEXTRAS_EXPORT QMacCocoaViewContainer : public QWidget -{ - Q_OBJECT -public: - QMacCocoaViewContainer(NSView *cocoaViewToWrap, QWidget *parent = 0); - virtual ~QMacCocoaViewContainer(); - - void setCocoaView(NSView *view); - NSView *cocoaView() const; - -private: - QMacCocoaViewContainerPrivate *d; -}; - -QT_END_NAMESPACE - -#endif // QMACCOCOAVIEWCONTAINER_H - diff --git a/src/macextras/qmaccocoaviewcontainer.mm b/src/macextras/qmaccocoaviewcontainer.mm deleted file mode 100644 index 8b9acc1..0000000 --- a/src/macextras/qmaccocoaviewcontainer.mm +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** 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$ -** -****************************************************************************/ - -#import <Cocoa/Cocoa.h> - -#include "qmaccocoaviewcontainer.h" - -#include <qpa/qplatformnativeinterface.h> -#include <QtGui/QWindow> - -/*! - \class QMacCocoaViewContainer - - \brief The QMacCocoaViewContainer class provides a widget for Mac OS X that can be used to wrap arbitrary - Cocoa views (i.e., NSView subclasses) and insert them into Qt hierarchies. - - \ingroup advanced - - While Qt offers a lot of classes for writing your application, Apple's - Cocoa framework offers lots of functionality that is not currently in Qt or - may never end up in Qt. Using QMacCocoaViewContainer, it is possible to put an - arbitrary NSView-derived class from Cocoa and put it in a Qt hierarchy. - Depending on how comfortable you are with using objective-C, you can use - QMacCocoaViewContainer directly, or subclass it to wrap further functionality - of the underlying NSView. - - It should be also noted that at the low level on Mac OS X, there is a - difference between windows (top-levels) and view (widgets that are inside a - window). For this reason, make sure that the NSView that you are wrapping - doesn't end up as a top-level. The best way to ensure this is to make sure - you always have a parent and not set the parent to 0. - - If you are using QMacCocoaViewContainer as a sub-class and are mixing and - matching objective-C with C++ (a.k.a. objective-C++). It is probably - simpler to have your file end with \tt{.mm} than \tt{.cpp}. Most Apple tools will - correctly identify the source as objective-C++. - - QMacCocoaViewContainer requires knowledge of how Cocoa works, especially in - regard to its reference counting (retain/release) nature. It is noted in - the functions below if there is any change in the reference count. Cocoa - views often generate temporary objects that are released by an autorelease - pool. If this is done outside of a running event loop, it is up to the - developer to provide the autorelease pool. - - The following is a snippet of subclassing QMacCocoaViewContainer to wrap a NSSearchField. - \snippet demos/macmainwindow/macmainwindow.mm 0 - -*/ - -QT_BEGIN_NAMESPACE - -class QMacCocoaViewContainerPrivate -{ -public: - NSView *nsview; - QMacCocoaViewContainerPrivate(); - ~QMacCocoaViewContainerPrivate(); -}; - -QMacCocoaViewContainerPrivate::QMacCocoaViewContainerPrivate() - : nsview(0) -{ -} - -QMacCocoaViewContainerPrivate::~QMacCocoaViewContainerPrivate() -{ - [nsview release]; -} - -/*! - \fn QMacCocoaViewContainer::QMacCocoaViewContainer(NSView *cocoaViewToWrap, QWidget *parent) - - Create a new QMacCocoaViewContainer using the NSView pointer in \a - cocoaViewToWrap with parent, \a parent. QMacCocoaViewContainer will - retain \a cocoaViewToWrap. - -*/ -QMacCocoaViewContainer::QMacCocoaViewContainer(NSView *view, QWidget *parent) - : QWidget(parent, 0) - , d(new QMacCocoaViewContainerPrivate) -{ - - if (view) - setCocoaView(view); - - // QMacCocoaViewContainer requires a native window handle. - setAttribute(Qt::WA_NativeWindow); -} - -/*! - Destroy the QMacCocoaViewContainer and release the wrapped view. -*/ -QMacCocoaViewContainer::~QMacCocoaViewContainer() -{ - delete d; -} - -/*! - Returns the NSView that has been set on this container. -*/ -NSView *QMacCocoaViewContainer::cocoaView() const -{ - return d->nsview; -} - -/*! - Sets the NSView to contain to be \a cocoaViewToWrap and retains it. If this - container already had a view set, it will release the previously set view. -*/ -void QMacCocoaViewContainer::setCocoaView(NSView *view) -{ - NSView *oldView = d->nsview; - [view retain]; - d->nsview = view; - - // Create window and platformwindow - winId(); - QPlatformWindow *platformWindow = this->windowHandle()->handle(); - - // Set the new view as the content view for the window. - extern QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePlatformFunction(const QByteArray &functionName); - typedef void (*SetWindowContentViewFunction)(QPlatformWindow *window, NSView *nsview); - reinterpret_cast<SetWindowContentViewFunction>(resolvePlatformFunction("setwindowcontentview"))(platformWindow, view); - - [oldView release]; -} - -QT_END_NAMESPACE diff --git a/src/macextras/qmacextrasglobal.h b/src/macextras/qmacextrasglobal.h index f6a6f99..dacb110 100644 --- a/src/macextras/qmacextrasglobal.h +++ b/src/macextras/qmacextrasglobal.h @@ -52,6 +52,8 @@ QT_BEGIN_NAMESPACE # define Q_MACEXTRAS_EXPORT Q_DECL_IMPORT #endif + +// ### remove when merged to QtCore /*! * \macro Q_FORWARD_DECLARE_OBJC_CLASS(classname) * diff --git a/src/macextras/qmacfunctions.h b/src/macextras/qmacfunctions.h index 2f794a9..7ab0cdd 100644 --- a/src/macextras/qmacfunctions.h +++ b/src/macextras/qmacfunctions.h @@ -53,9 +53,6 @@ typedef struct CGContext *CGContextRef; Q_FORWARD_DECLARE_OBJC_CLASS(NSData); Q_FORWARD_DECLARE_OBJC_CLASS(NSImage); -Q_FORWARD_DECLARE_OBJC_CLASS(NSString); -Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu); -Q_FORWARD_DECLARE_OBJC_CLASS(NSURL); QT_BEGIN_NAMESPACE @@ -65,18 +62,11 @@ class QMenuBar; class QPixmap; class QString; class QUrl; -class QWidget; class QWindow; 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); - -Q_MACEXTRAS_EXPORT NSData* toNSData(const QByteArray &data); +Q_MACEXTRAS_EXPORT NSData *toNSData(const QByteArray &data); Q_MACEXTRAS_EXPORT QByteArray fromNSData(const NSData *data); Q_MACEXTRAS_EXPORT CGImageRef toCGImageRef(const QPixmap &pixmap); @@ -85,26 +75,15 @@ Q_MACEXTRAS_EXPORT QPixmap fromCGImageRef(CGImageRef image); Q_MACEXTRAS_EXPORT CGContextRef currentCGContext(); #ifndef Q_OS_IOS -Q_MACEXTRAS_EXPORT NSImage* toNSImage(const QPixmap &pixmap); - -Q_MACEXTRAS_EXPORT NSMenu* toNSMenu(QMenu *menu); -Q_MACEXTRAS_EXPORT NSMenu* toNSMenu(QMenuBar *menubar); - -Q_MACEXTRAS_EXPORT void setDockMenu(QMenu *menu); +Q_MACEXTRAS_EXPORT NSImage *toNSImage(const QPixmap &pixmap); #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) Q_MACEXTRAS_EXPORT bool isMainWindow(QWindow *window); #endif -Q_MACEXTRAS_EXPORT bool isMainWindow(QWidget *widget); #endif } -#ifndef Q_OS_IOS -// ### Qt 4 compatibility; remove in Qt 6 -inline void qt_mac_set_dock_menu(QMenu *menu) { QtMac::setDockMenu(menu); } -#endif - QT_END_NAMESPACE #endif // QMACFUNCTIONS_H diff --git a/src/macextras/qmacfunctions.mm b/src/macextras/qmacfunctions.mm index d5a6dd8..d843981 100644 --- a/src/macextras/qmacfunctions.mm +++ b/src/macextras/qmacfunctions.mm @@ -40,10 +40,13 @@ ****************************************************************************/ #include "qmacfunctions.h" -#include "qmacfunctions_p.h" + #include <QByteArray> #include <QPixmap> #include <QUrl> + +#include "qmacfunctions_p.h" + #import <Foundation/Foundation.h> #ifdef Q_OS_IOS #import <CoreGraphics/CoreGraphics.h> diff --git a/src/macextras/qmacfunctions_ios.mm b/src/macextras/qmacfunctions_ios.mm index 2ea718f..2508941 100644 --- a/src/macextras/qmacfunctions_ios.mm +++ b/src/macextras/qmacfunctions_ios.mm @@ -41,6 +41,7 @@ #include "qmacfunctions.h" #include "qmacfunctions_p.h" + #import <UIKit/UIKit.h> QT_BEGIN_NAMESPACE diff --git a/src/macextras/qmacfunctions_mac.mm b/src/macextras/qmacfunctions_mac.mm index bdb1cae..9209c2f 100644 --- a/src/macextras/qmacfunctions_mac.mm +++ b/src/macextras/qmacfunctions_mac.mm @@ -64,53 +64,6 @@ NSImage* toNSImage(const QPixmap &pixmap) return image; } -NSMenu* toNSMenu(QMenu *menu) -{ -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - // Get the platform menu, which will be a QCocoaMenu - QPlatformMenu *platformMenu = menu->platformMenu(); - - // Get the qMenuToNSMenu function and call it. - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("qmenutonsmenu"); - if (function) { - typedef void* (*QMenuToNSMenuFunction)(QPlatformMenu *platformMenu); - return reinterpret_cast<NSMenu *>(reinterpret_cast<QMenuToNSMenuFunction>(function)(platformMenu)); - } - return nil; -#else - return menu->nsMenu(); -#endif -} - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -NSMenu* toNSMenu(QMenuBar *menubar) -{ - // Get the platform menubar, which will be a QCocoaMenuBar - QPlatformMenuBar *platformMenuBar = menubar->platformMenuBar(); - - // Get the qMenuBarToNSMenu function and call it. - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("qmenubartonsmenu"); - if (function) { - typedef void* (*QMenuBarToNSMenuFunction)(QPlatformMenuBar *platformMenuBar); - return reinterpret_cast<NSMenu *>(reinterpret_cast<QMenuBarToNSMenuFunction>(function)(platformMenuBar)); - } - return nil; -} -#endif - -void setDockMenu(QMenu *menu) -{ - // Get the platform menu, which will be a QCocoaMenu - QPlatformMenu *platformMenu = menu->platformMenu(); - - // Get the setDockMenu function and call it. - QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("setdockmenu"); - if (function) { - typedef void (*SetDockMenuFunction)(QPlatformMenu *platformMenu); - reinterpret_cast<SetDockMenuFunction>(function)(platformMenu); - } -} - #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) bool isMainWindow(QWindow *window) { @@ -123,20 +76,6 @@ bool isMainWindow(QWindow *window) } #endif -bool isMainWindow(QWidget *widget) -{ - if (!widget) - return false; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - return isMainWindow(widget->windowHandle()); -#else - NSWindow *macWindow = - reinterpret_cast<NSWindow*>([reinterpret_cast<NSView*>(widget->window()->winId()) window]); - return [macWindow isMainWindow]; -#endif -} - CGContextRef currentCGContext() { return reinterpret_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]); diff --git a/src/macextras/qmacfunctions_p.h b/src/macextras/qmacfunctions_p.h index 6d8211b..b03b7ae 100644 --- a/src/macextras/qmacfunctions_p.h +++ b/src/macextras/qmacfunctions_p.h @@ -49,8 +49,22 @@ #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/qmacnativetoolbar.mm b/src/macextras/qmacnativetoolbar.mm index f6b9020..22c6a6b 100644 --- a/src/macextras/qmacnativetoolbar.mm +++ b/src/macextras/qmacnativetoolbar.mm @@ -38,27 +38,25 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #import <AppKit/AppKit.h> -#include "qmacfunctions.h" -#include "qmacnativetoolbar.h" -#include "qmactoolbardelegate_p.h" -#include "qnstoolbar_p.h" -#include <QAction> -#include <QApplication> -#include <QDebug> -#include <QTimer> -#include <QToolBar> -#include <QUuid> -#include <QWidget> +#include "qmacnativetoolbar_p.h" + +#include <QtGui/QGuiApplication> +#include <QtCore/QDebug> +#include <QtCore/QTimer> +#include <QtCore/QUuid> #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include <QGuiApplication> +#include <QtGui/QGuiApplication> #include <qpa/qplatformnativeinterface.h> #else -#include <QMainWindow> +#include <QtGui/QMainWindow> #endif +#include "qmacfunctions.h" +#include "qmacfunctions_p.h" +#include "qmactoolbardelegate_p.h" +#include "qnstoolbar_p.h" // from the Apple NSToolbar documentation #define kNSToolbarIconSizeSmall 24 @@ -190,48 +188,6 @@ public: } }; -QMacNativeToolBar* QtMac::setNativeToolBar(QToolBar *toolbar, bool on) -{ - return QtMac::setNativeToolBar(toolbar, QString(), on); -} - -QMacNativeToolBar* QtMac::setNativeToolBar(QToolBar *toolbar, const QString &identifier, bool on) -{ - if (!toolbar) - { - qWarning() << "setNativeToolBar: toolbar was NULL"; - return NULL; - } - -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - // Turn off unified title and toolbar if it's on, because we're adding our own NSToolbar - QMainWindow *mainWindow = qobject_cast<QMainWindow*>(toolbar->window()); - if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) - mainWindow->setUnifiedTitleAndToolBarOnMac(false); -#endif - - static const char *macToolBarProperty = "_q_mac_native_toolbar"; - - // Check if we've already created a Mac equivalent for this toolbar and create one if not - QVariant toolBarProperty = toolbar->property(macToolBarProperty); - QMacNativeToolBar *macToolBar; - if (toolBarProperty.canConvert<QMacNativeToolBar*>()) { - macToolBar = toolBarProperty.value<QMacNativeToolBar*>(); - } else { - macToolBar = QMacNativeToolBar::fromQToolBar(toolbar, identifier); - macToolBar->setParent(toolbar); - toolbar->setProperty(macToolBarProperty, QVariant::fromValue(macToolBar)); - } - - toolbar->setVisible(!on); - if (on) - macToolBar->showInWindowForWidget(toolbar->window()); - else - macToolBar->removeFromWindowForWidget(toolbar->window()); - - return macToolBar; -} - QMacNativeToolBar::QMacNativeToolBar(QObject *parent) : QObject(parent), targetWindow(NULL), targetWidget(NULL), d(new QMacNativeToolBarPrivate(this)) { @@ -257,18 +213,6 @@ NSToolbar *QMacNativeToolBar::nativeToolbar() const return d->toolbar; } -QMacNativeToolBar *QMacNativeToolBar::fromQToolBar(const QToolBar *toolBar, const QString &identifier) -{ - // TODO: add the QToolBar's QWidgets to the Mac toolbar once it supports this - QMacNativeToolBar *macToolBar = new QMacNativeToolBar(identifier); - foreach (QAction *action, toolBar->actions()) - { - macToolBar->addAction(action); - } - - return macToolBar; -} - QString QMacNativeToolBar::identifier() const { return QtMac::fromNSString([d->toolbar identifier]); @@ -394,33 +338,8 @@ void QMacNativeToolBar::showInWindow(QWindow *window) QTimer::singleShot(100, this, SLOT(showInWindow_impl())); // ### hackety hack } -void QMacNativeToolBar::showInWindowForWidget(QWidget *widget) -{ - targetWidget = widget; - widget->winId(); // create window - showInWindow_impl(); -} - -void QMacNativeToolBar::showInMainWindow() -{ - QWidgetList widgets = QApplication::topLevelWidgets(); - if (widgets.isEmpty()) - return; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - showInWindow(widgets.at(0)->windowHandle()); -#else - showInWindowForWidget(widgets.at(0)->window()); -#endif -} - - void QMacNativeToolBar::showInWindow_impl() { -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - if (!targetWindow) - targetWindow = targetWidget->windowHandle(); - if (!targetWindow) { QTimer::singleShot(100, this, SLOT(showInWindow_impl())); return; @@ -428,9 +347,6 @@ void QMacNativeToolBar::showInWindow_impl() NSWindow *macWindow = static_cast<NSWindow*>( QGuiApplication::platformNativeInterface()->nativeResourceForWindow("nswindow", targetWindow)); -#else - NSWindow *macWindow = reinterpret_cast<NSWindow*>([reinterpret_cast<NSView*>(targetWidget->winId()) window]); -#endif if (!macWindow) { QTimer::singleShot(100, this, SLOT(showInWindow_impl())); @@ -440,8 +356,6 @@ void QMacNativeToolBar::showInWindow_impl() [macWindow setToolbar: d->toolbar]; [macWindow setShowsToolbarButton:YES]; } - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) void QMacNativeToolBar::removeFromWindow(QWindow *window) { if (!window) @@ -451,23 +365,16 @@ void QMacNativeToolBar::removeFromWindow(QWindow *window) QGuiApplication::platformNativeInterface()->nativeResourceForWindow("nswindow", window)); [macWindow setToolbar:nil]; } -#endif -void QMacNativeToolBar::removeFromWindowForWidget(QWidget *widget) -{ - if (!widget) - return; - - NSWindow *macWindow = reinterpret_cast<NSWindow*>([reinterpret_cast<NSView*>(widget->winId()) window]); - [macWindow setToolbar:nil]; -} void QMacNativeToolBar::setSelectedItem() { - setSelectedItem(qobject_cast<QAction*>(sender())); +// setSelectedItem(qobject_cast<QMacToolButton*>(sender())); } -QAction *QMacNativeToolBar::setSelectedItem(QAction *action) +//### TODO- re-implement +#if 0 +QMacToolButton *QMacNativeToolBar::setSelectedItem(QMacToolButton *action) { // If this action is checkable, find the corresponding NSToolBarItem on the // real NSToolbar and set it to the selected item if it is checked @@ -495,7 +402,7 @@ QAction *QMacNativeToolBar::setSelectedItem(QAction *action) void QMacNativeToolBar::checkSelectableItemSanity() { // Find a list of all selectable actions - QList<QAction*> selectableActions; + QList<QMacToolButton*> selectableActions; foreach (QMacToolButton *button, allowedButtons()) if (button->m_action && button->m_action->isCheckable()) selectableActions.append(button->m_action); @@ -504,9 +411,9 @@ void QMacNativeToolBar::checkSelectableItemSanity() if (selectableActions.size() > 1) { // The action group that all selectable actions must belong to - QActionGroup *group = NULL; + QMacToolButtonGroup *group = NULL; - foreach (QAction *action, selectableActions) + foreach (QMacToolButton *action, selectableActions) { // The first action group we find is "the" action group that // all selectable actions on the toolbar must belong to @@ -518,56 +425,46 @@ void QMacNativeToolBar::checkSelectableItemSanity() // The group not being exclusive is a failure if (!group || (group != action->actionGroup()) || (group && !group->isExclusive())) { - qWarning() << "All selectable actions in a QMacUnifiedToolBar should belong to the same exclusive QActionGroup if there is more than one selectable action."; + qWarning() << "All selectable actions in a QMacUnifiedToolBar should belong to the same exclusive QMacToolButtonGroup if there is more than one selectable action."; break; } } } } +#endif -QAction *QMacNativeToolBar::addAction(const QString &text) +QMacToolButton *QMacNativeToolBar::addAction(const QString &text) { return [d->delegate addActionWithText:&text]; } -QAction *QMacNativeToolBar::addAction(const QIcon &icon, const QString &text) +QMacToolButton *QMacNativeToolBar::addAction(const QIcon &icon, const QString &text) { return [d->delegate addActionWithText:&text icon:&icon]; } -QAction *QMacNativeToolBar::addAction(QAction *action) -{ - connect(action, SIGNAL(triggered()), this, SLOT(setSelectedItem())); - return setSelectedItem([d->delegate addAction:action]); -} - void QMacNativeToolBar::addSeparator() { addStandardItem(QMacToolButton::Space); // No Seprator on OS X. } -QAction *QMacNativeToolBar::addStandardItem(QMacToolButton::StandardItem standardItem) +QMacToolButton *QMacNativeToolBar::addStandardItem(QMacToolButton::StandardItem standardItem) { return [d->delegate addStandardItem:standardItem]; } -QAction *QMacNativeToolBar::addAllowedAction(const QString &text) +QMacToolButton *QMacNativeToolBar::addAllowedAction(const QString &text) { return [d->delegate addAllowedActionWithText:&text]; } -QAction *QMacNativeToolBar::addAllowedAction(const QIcon &icon, const QString &text) +QMacToolButton *QMacNativeToolBar::addAllowedAction(const QIcon &icon, const QString &text) { return [d->delegate addAllowedActionWithText:&text icon:&icon]; } -QAction *QMacNativeToolBar::addAllowedAction(QAction *action) -{ - connect(action, SIGNAL(triggered()), this, SLOT(setSelectedItem())); - return setSelectedItem([d->delegate addAllowedAction:action]); -} -QAction *QMacNativeToolBar::addAllowedStandardItem(QMacToolButton::StandardItem standardItem) +QMacToolButton *QMacNativeToolBar::addAllowedStandardItem(QMacToolButton::StandardItem standardItem) { return [d->delegate addAllowedStandardItem:standardItem]; } diff --git a/src/macextras/qmacnativetoolbar.h b/src/macextras/qmacnativetoolbar_p.h index 4c903cf..fe15ea2 100644 --- a/src/macextras/qmacnativetoolbar.h +++ b/src/macextras/qmacnativetoolbar_p.h @@ -43,32 +43,21 @@ #define QMACTOOLBAR_H #include "qmacextrasglobal.h" -#include "qmactoolbutton.h" +#include "qmactoolbutton_p.h" -#include <QString> -#include <QObject> -#include <QIcon> -#include <QVariant> +#include <QtCore/QString> +#include <QtCore/QObject> +#include <QtCore/QVariant> +#include <QtGui/QIcon> Q_FORWARD_DECLARE_OBJC_CLASS(NSToolbar); QT_BEGIN_NAMESPACE -class QToolBar; -class QWidget; - -class QMacNativeToolBar; - -namespace QtMac -{ -Q_MACEXTRAS_EXPORT QMacNativeToolBar* setNativeToolBar(QToolBar *toolbar, bool on = true); -Q_MACEXTRAS_EXPORT QMacNativeToolBar* setNativeToolBar(QToolBar *toolbar, const QString &identifier, bool on = true); -} - -class QAction; class QWindow; - +class QMacNativeToolBar; class QMacNativeToolBarPrivate; + class Q_MACEXTRAS_EXPORT QMacNativeToolBar : public QObject { friend class QMacNativeToolBarPrivate; @@ -83,8 +72,6 @@ public: NSToolbar* nativeToolbar() const; - static QMacNativeToolBar* fromQToolBar(const QToolBar *toolBar, const QString &identifier = QString()); - QString identifier() const; bool isVisible() const; bool showsBaselineSeparator() const; @@ -97,24 +84,19 @@ public: QList<QMacToolButton *> allowedButtons(); void showInWindow(QWindow *window); - void showInWindowForWidget(QWidget *widget); - Q_INVOKABLE void showInMainWindow(); void removeFromWindow(QWindow *window); - void removeFromWindowForWidget(QWidget *widget); // Add actions to the toolbar - Q_INVOKABLE QAction *addAction(const QString &text); - Q_INVOKABLE QAction *addAction(const QIcon &icon, const QString &text); - Q_INVOKABLE QAction *addAction(QAction *action); + Q_INVOKABLE QMacToolButton *addAction(const QString &text); + Q_INVOKABLE QMacToolButton *addAction(const QIcon &icon, const QString &text); Q_INVOKABLE void addSeparator(); - Q_INVOKABLE QAction *addStandardItem(QMacToolButton::StandardItem standardItem); + Q_INVOKABLE QMacToolButton *addStandardItem(QMacToolButton::StandardItem standardItem); // Add actions to the "Customize Toolbar" menu - Q_INVOKABLE QAction *addAllowedAction(const QString &text); - Q_INVOKABLE QAction *addAllowedAction(const QIcon &icon, const QString &text); - Q_INVOKABLE QAction *addAllowedAction(QAction *action); - Q_INVOKABLE QAction *addAllowedStandardItem(QMacToolButton::StandardItem standardItem); + Q_INVOKABLE QMacToolButton *addAllowedAction(const QString &text); + Q_INVOKABLE QMacToolButton *addAllowedAction(const QIcon &icon, const QString &text); + Q_INVOKABLE QMacToolButton *addAllowedStandardItem(QMacToolButton::StandardItem standardItem); Q_SIGNALS: void visibilityChanged(bool visible); @@ -136,11 +118,14 @@ public Q_SLOTS: private Q_SLOTS: void showInWindow_impl(); void setSelectedItem(); - QAction *setSelectedItem(QAction *action); +//### TODO- re-implement +#if 0 + QMacToolButton *setSelectedItem(QMacToolbarAction *action); void checkSelectableItemSanity(); +#endif private: QWindow *targetWindow; - QWidget *targetWidget; + void *targetWidget; QList<QMacToolButton *> m_buttons; QList<QMacToolButton *> m_allowedButtons; QMacNativeToolBarPrivate *d; diff --git a/src/macextras/qmacnativewidget.h b/src/macextras/qmacnativewidget.h deleted file mode 100644 index 72c3e8f..0000000 --- a/src/macextras/qmacnativewidget.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** 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$ -** -****************************************************************************/ - -#ifndef QMACNATIVEWIDGET_H -#define QMACNATIVEWIDGET_H - -#include "qmacextrasglobal.h" - -#include <QWidget> - -Q_FORWARD_DECLARE_OBJC_CLASS(NSView); - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -class Q_MACEXTRAS_EXPORT QMacNativeWidget : public QWidget -{ - Q_OBJECT -public: - QMacNativeWidget(NSView *parentView = 0); - ~QMacNativeWidget(); - - NSView *nativeView() const; - - QSize sizeHint() const; -protected: - void init(NSView *parentView); - bool event(QEvent *ev); -}; - -QT_END_NAMESPACE - -#endif // QMACNATIVEWIDGET_H diff --git a/src/macextras/qmacnativewidget.mm b/src/macextras/qmacnativewidget.mm deleted file mode 100644 index 305de86..0000000 --- a/src/macextras/qmacnativewidget.mm +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** 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$ -** -****************************************************************************/ - -#import <Cocoa/Cocoa.h> -#include "qmacnativewidget.h" -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include <QtGui/QWindow> -#include <QtGui/QGuiApplication> -#include <qpa/qplatformnativeinterface.h> -#endif -#include <qdebug.h> - - -/*! - \class QMacNativeWidget - \brief The QMacNativeWidget class provides a widget for Mac OS X that provides a way to put Qt widgets - into Cocoa hierarchies. - - QMacNativeWidget bridges the gap between NSViews and QWidgets and makes it possible to put a - hierarchy of Qt widgets into a non-Qt window or view. - - QMacNativeWidget pretends it is a window (i.e. isWindow() will return true), - but it cannot be shown on its own. It needs to be put into a window - when it is created or later through a native call. - - Note that QMacNativeWidget requires knowledge of Cocoa. All it - does is get the Qt hierarchy into a window not owned by Qt. It is then up - to the programmer to ensure it is placed correctly in the window and - responds correctly to events. -*/ - -QT_BEGIN_NAMESPACE - -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -NSView *getEmbeddableView(QWindow *qtWindow) -{ - // Make sure the platform window is created - qtWindow->create(); - - // Inform the window that it's a subwindow of a non-Qt window. This must be - // done after create() because we need to have a QPlatformWindow instance. - // The corresponding NSWindow will not be shown and can be deleted later. - extern QPlatformNativeInterface::NativeResourceForIntegrationFunction resolvePlatformFunction(const QByteArray &functionName); - typedef void (*SetEmbeddedInForeignViewFunction)(QPlatformWindow *window, bool embedded); - reinterpret_cast<SetEmbeddedInForeignViewFunction>(resolvePlatformFunction("setEmbeddedInForeignView"))(qtWindow->handle(), true); - - // Get the Qt content NSView for the QWindow from the Qt platform plugin - QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface(); - NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow); - return qtView; // qtView is ready for use. -} -#endif - -/*! - Create a QMacNativeWidget with \a parentView as its "superview" (i.e., - parent). The \a parentView is a NSView pointer. -*/ -QMacNativeWidget::QMacNativeWidget(NSView *parentView) - : QWidget(0) -{ - Q_UNUSED(parentView); - - //d_func()->topData()->embedded = true; - setPalette(QPalette(Qt::transparent)); - setAttribute(Qt::WA_SetPalette, false); - setAttribute(Qt::WA_LayoutUsesWidgetRect); -} - -NSView *QMacNativeWidget::nativeView() const -{ -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - winId(); - return getEmbeddableView(windowHandle()); -#else - return reinterpret_cast<NSView*>(winId()); -#endif -} - -/*! - Destroy the QMacNativeWidget. -*/ -QMacNativeWidget::~QMacNativeWidget() -{ -} - -/*! - \reimp -*/ -QSize QMacNativeWidget::sizeHint() const -{ - // QMacNativeWidget really does not have any other choice - // than to fill its designated area. -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) - if (windowHandle()) - return windowHandle()->size(); - return QWidget::sizeHint(); -#else - NSRect frame = [nativeView() frame]; - return QSize(frame.size.width, frame.size.height); -#endif -} -/*! - \reimp -*/ -bool QMacNativeWidget::event(QEvent *ev) -{ - return QWidget::event(ev); -} - -QT_END_NAMESPACE diff --git a/src/macextras/qmacpasteboardmime.mm b/src/macextras/qmacpasteboardmime.mm index 1ad437a..ec8fa7e 100644 --- a/src/macextras/qmacpasteboardmime.mm +++ b/src/macextras/qmacpasteboardmime.mm @@ -41,10 +41,9 @@ #include <Cocoa/Cocoa.h> #include "qmacpasteboardmime.h" -#include <qpa/qplatformnativeinterface.h> -#include <qapplication.h> -#include <qlogging.h> +#include <QtCore/qlogging.h> +#include <qpa/qplatformnativeinterface.h> QT_BEGIN_NAMESPACE diff --git a/src/macextras/qmactoolbardelegate.mm b/src/macextras/qmactoolbardelegate.mm index 2a76e00..678423e 100644 --- a/src/macextras/qmactoolbardelegate.mm +++ b/src/macextras/qmactoolbardelegate.mm @@ -39,11 +39,14 @@ ** ****************************************************************************/ -#include "qmacfunctions.h" #include "qmactoolbardelegate_p.h" -#include <QAction> -#include <QImage> -#include <QPixmap> + +#include <QtGui/QImage> +#include <QtGui/QPixmap> + +#include "qmacfunctions.h" +#include "qmacfunctions_p.h" +#include "qmacnativetoolbar_p.h" QT_USE_NAMESPACE @@ -73,7 +76,7 @@ NSMutableArray *itemIdentifiers(const QList<QMacToolButton *> &items, bool cullU return array; } -// from qaction.cpp +// from QMacToolButton.cpp QString qt_strippedText(QString s) { s.remove( QString::fromLatin1("...") ); @@ -116,9 +119,6 @@ QString qt_strippedText(QString s) NSToolbarItem *item = reinterpret_cast<NSToolbarItem *>(sender); QString identifier = QtMac::fromNSString([item itemIdentifier]); QMacToolButton *toolButton = reinterpret_cast<QMacToolButton *>(identifier.toULongLong()); - if (toolButton->m_action) { - toolButton->m_action->trigger(); - } toolButton->emitActivated(); } @@ -129,14 +129,13 @@ QString qt_strippedText(QString s) const QString identifier = QtMac::fromNSString(itemIdentifier); QMacToolButton *toolButton = reinterpret_cast<QMacToolButton *>(identifier.toULongLong()); // string -> unisgned long long -> pointer - NSToolbarItem *toolbarItem= [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; - [toolbarItem setLabel: QtMac::toNSString(qt_strippedText(toolButton->m_action->iconText()))]; - [toolbarItem setPaletteLabel:[toolbarItem label]]; - [toolbarItem setToolTip: QtMac::toNSString(toolButton->m_action->toolTip())]; + NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; + [toolbarItem setLabel: QtMac::toNSString(toolButton->text())]; + [toolbarItem setPaletteLabel :[toolbarItem label]]; - QPixmap icon = toolButton->m_action->icon().pixmap(64, 64); + QPixmap icon = toolButton->icon().pixmap(64, 64); if (icon.isNull() == false) { - [toolbarItem setImage : QtMac::toNSImage(icon)]; + [toolbarItem setImage: QtMac::toNSImage(icon)]; } [toolbarItem setTarget : self]; @@ -145,73 +144,53 @@ QString qt_strippedText(QString s) return toolbarItem; } -- (QAction *)addActionWithText:(const QString *)text +- (QMacToolButton *)addActionWithText:(const QString *)text { QIcon nullIcon; return [self addActionWithText:text icon:&nullIcon]; } -- (QAction *)addActionWithText:(const QString *)text icon:(const QIcon *)icon +- (QMacToolButton *)addActionWithText:(const QString *)text icon:(const QIcon *)icon { - QAction *action = new QAction(*icon, *text, 0); - QMacToolButton *button = new QMacToolButton(action); - button->m_action = action; + QMacToolButton *button = new QMacToolButton(0); + button->setText(*text); + button->setIcon(*icon); items.append(button); allowedItems.append(button); - return action; + return button; } -- (QAction *)addAction:(QAction *)action +- (QMacToolButton *)addStandardItem:(QMacToolButton::StandardItem) standardItem { - QMacToolButton *button = new QMacToolButton(action); - button->m_action = action; - items.append(button); - allowedItems.append(button); - return action; -} - -- (QAction *)addStandardItem:(QMacToolButton::StandardItem) standardItem -{ - QAction *action = new QAction(0); - QMacToolButton *button = new QMacToolButton(action); - button->m_action = action; + QMacToolButton *button = new QMacToolButton(0); button->setStandardItem(standardItem); items.append(button); allowedItems.append(button); - return action; + return button; } -- (QAction *)addAllowedActionWithText:(const QString *)text +- (QMacToolButton *)addAllowedActionWithText:(const QString *)text { QIcon nullIcon; return [self addAllowedActionWithText:text icon:&nullIcon]; } -- (QAction *)addAllowedActionWithText:(const QString *)text icon:(const QIcon *)icon +- (QMacToolButton *)addAllowedActionWithText:(const QString *)text icon:(const QIcon *)icon { - QAction *action = new QAction(*icon, *text, 0); - QMacToolButton *button = new QMacToolButton(action); - button->m_action = action; + QMacToolButton *button = new QMacToolButton(0); + button->setText(*text); + button->setIcon(*icon); allowedItems.append(button); - return action; + return button; } -- (QAction *)addAllowedAction:(QAction *)action +- (QMacToolButton *)addAllowedStandardItem:(QMacToolButton::StandardItem)standardItem { - QMacToolButton *button = new QMacToolButton(action); - button->m_action = action; - allowedItems.append(button); - return action; -} - -- (QAction *)addAllowedStandardItem:(QMacToolButton::StandardItem)standardItem -{ - QAction *action = new QAction(0); - QMacToolButton *button = new QMacToolButton(action); - button->m_action = action; + QMacToolButton *button = new QMacToolButton(0); button->setStandardItem(standardItem); allowedItems.append(button); - return action; + return button; } + @end diff --git a/src/macextras/qmactoolbardelegate_p.h b/src/macextras/qmactoolbardelegate_p.h index b40a6ed..8c71804 100644 --- a/src/macextras/qmactoolbardelegate_p.h +++ b/src/macextras/qmactoolbardelegate_p.h @@ -43,24 +43,17 @@ #define QMACTOOLBARDELEGATE_H #import <AppKit/AppKit.h> -#include "qmactoolbutton.h" -//#include <QString> -//#include <QHash> +#include "qmactoolbutton_p.h" -#include <qglobal.h> +#include <QtCore/qglobal.h> #include <private/qcore_mac_p.h> - -#include <QAction> -#include <QIcon> +#include <QtGui/QIcon> @interface QT_MANGLE_NAMESPACE(QMacToolbarDelegate) : NSObject <NSToolbarDelegate> { @public QList<QMacToolButton *> items; QList<QMacToolButton *> allowedItems; - -// QHash<QString, QAction*> actions; -// QHash<QString, QAction*> allowedActions; } - (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted; @@ -68,15 +61,13 @@ - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar; - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar; -- (QAction *)addActionWithText:(const QString *)text; -- (QAction *)addActionWithText:(const QString *)text icon:(const QIcon *)icon; -- (QAction *)addAction:(QAction *)action; -- (QAction *)addStandardItem:(QMacToolButton::StandardItem)standardItem; +- (QMacToolButton *)addActionWithText:(const QString *)text; +- (QMacToolButton *)addActionWithText:(const QString *)text icon:(const QIcon *)icon; +- (QMacToolButton *)addStandardItem:(QMacToolButton::StandardItem)standardItem; -- (QAction *)addAllowedActionWithText:(const QString *)text; -- (QAction *)addAllowedActionWithText:(const QString *)text icon:(const QIcon *)icon; -- (QAction *)addAllowedAction:(QAction *)action; -- (QAction *)addAllowedStandardItem:(QMacToolButton::StandardItem)standardItem; +- (QMacToolButton *)addAllowedActionWithText:(const QString *)text; +- (QMacToolButton *)addAllowedActionWithText:(const QString *)text icon:(const QIcon *)icon; +- (QMacToolButton *)addAllowedStandardItem:(QMacToolButton::StandardItem)standardItem; - (IBAction)itemClicked:(id)sender; @end diff --git a/src/macextras/qmactoolbutton.mm b/src/macextras/qmactoolbutton.mm index cd3b343..ca41f2a 100644 --- a/src/macextras/qmactoolbutton.mm +++ b/src/macextras/qmactoolbutton.mm @@ -39,8 +39,7 @@ ** ****************************************************************************/ -#include "qmactoolbutton.h" -#include <QAction> +#include "qmactoolbutton_p.h" QT_BEGIN_NAMESPACE @@ -48,7 +47,6 @@ QMacToolButton::QMacToolButton() { m_standardItem = NoItem; m_selectable = false; - m_action = 0; } QMacToolButton::QMacToolButton(QObject *parent) @@ -56,7 +54,6 @@ QMacToolButton::QMacToolButton(QObject *parent) { m_standardItem = NoItem; m_selectable = false; - m_action = 0; } QMacToolButton::~QMacToolButton() @@ -66,18 +63,12 @@ QMacToolButton::~QMacToolButton() bool QMacToolButton::selectable() const { - if (m_action) - return m_action->isCheckable(); - return m_selectable; } void QMacToolButton::setSelectable(bool selectable) { - if (m_action) - m_action->setCheckable(selectable); - else - m_selectable = selectable; + m_selectable = selectable; } QMacToolButton::StandardItem QMacToolButton::standardItem() const @@ -90,4 +81,24 @@ void QMacToolButton::setStandardItem(StandardItem standardItem) m_standardItem = standardItem; } +QString QMacToolButton::text() const +{ + return m_text; +} + +void QMacToolButton::setText(const QString &text) +{ + m_text = text; +} + +QIcon QMacToolButton::icon() const +{ + return m_icon; +} + +void QMacToolButton::setIcon(const QIcon &icon) +{ + m_icon = icon; +} + QT_END_NAMESPACE diff --git a/src/macextras/qmactoolbutton.h b/src/macextras/qmactoolbutton_p.h index e63fefc..584b391 100644 --- a/src/macextras/qmactoolbutton.h +++ b/src/macextras/qmactoolbutton_p.h @@ -42,17 +42,19 @@ #ifndef QMACTOOLBUTTON_H #define QMACTOOLBUTTON_H -#include <QObject> +#include <QtCore/QObject> +#include <QtCore/QString> +#include <QtGui/QIcon> QT_BEGIN_NAMESPACE -class QAction; - class QMacToolButton : public QObject { Q_OBJECT Q_PROPERTY(bool selectable READ selectable WRITE setSelectable) Q_PROPERTY(StandardItem standardItem READ standardItem WRITE setStandardItem) + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(QIcon icon READ icon WRITE setIcon) Q_ENUMS(StandardItem) public: enum StandardItem @@ -81,13 +83,21 @@ public: StandardItem standardItem() const; void setStandardItem(StandardItem standardItem); + + QString text() const; + void setText(const QString &text); + + QIcon icon() const; + void setIcon(const QIcon &icon); Q_SIGNALS: void activated(); private: bool m_selectable; StandardItem m_standardItem; + QString m_text; + QIcon m_icon; + public: // (not really public) - QAction *m_action; void emitActivated() { Q_EMIT activated(); } }; |