aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-12-09 11:01:42 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-10 11:48:04 +0100
commit6c8706cdfa961a42230048e944613639a3c25536 (patch)
tree0b15fa7642d00524e05ed7b1a8c8a9871ef686d1
parent2f2ba9d199154732d942aa4c18874e40446919d5 (diff)
Rewrite the Mac native toolbar classes.
Rename the classes to QMacToolBar and QMacToolBarItem. (Keep the Qt-style ToolBar name capitalization.) API-review and document a core set of the API, remove the rest. Missing functionality can be added back later on. Add a simple QWindow-based mactoolbar example that shows the core toolbar functionality. Add manual test for more comprehensive testing. Make the QToolbarItem properties actually work, you can now change the text and icon after the toolbar has been displayed. Update license headers. Change-Id: I99fb207df7f1b3cf0d5df178aa863c77cd372a1f Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
-rw-r--r--examples/macextras/macextras.pro3
-rw-r--r--examples/macextras/mactoolbar/mactoolbar.pro5
-rw-r--r--examples/macextras/mactoolbar/mactoolbar.qrc5
-rw-r--r--examples/macextras/mactoolbar/main.cpp53
-rw-r--r--examples/macextras/mactoolbar/qtlogo.pngbin0 -> 1478 bytes
-rw-r--r--examples/macextras/mactoolbar/rasterwindow.cpp87
-rw-r--r--examples/macextras/mactoolbar/rasterwindow.h59
-rw-r--r--examples/macextras/mactoolbar/toolbarcontrollerwindow.cpp81
-rw-r--r--examples/macextras/mactoolbar/toolbarcontrollerwindow.h57
-rw-r--r--src/macextras/macextras-lib.pri15
-rw-r--r--src/macextras/qmacnativetoolbar.mm493
-rw-r--r--src/macextras/qmacnativetoolbar_p.h139
-rw-r--r--src/macextras/qmactoolbar.h94
-rw-r--r--src/macextras/qmactoolbar.mm327
-rw-r--r--src/macextras/qmactoolbar_p.h (renamed from src/macextras/qmactoolbutton.mm)78
-rw-r--r--src/macextras/qmactoolbardelegate.mm94
-rw-r--r--src/macextras/qmactoolbardelegate_p.h20
-rw-r--r--src/macextras/qmactoolbaritem.h (renamed from src/macextras/qmactoolbutton_p.h)43
-rw-r--r--src/macextras/qmactoolbaritem.mm241
-rw-r--r--src/macextras/qmactoolbaritem_p.h72
-rw-r--r--tests/manual/mactoolbar/mactoolbar.pro5
-rw-r--r--tests/manual/mactoolbar/mactoolbar.qrc5
-rw-r--r--tests/manual/mactoolbar/main.cpp54
-rw-r--r--tests/manual/mactoolbar/qtlogo.pngbin0 -> 1478 bytes
-rw-r--r--tests/manual/mactoolbar/toolbarcontrollerwidget.cpp79
-rw-r--r--tests/manual/mactoolbar/toolbarcontrollerwidget.h58
26 files changed, 1353 insertions, 814 deletions
diff --git a/examples/macextras/macextras.pro b/examples/macextras/macextras.pro
index 8fe1d13..a9c135d 100644
--- a/examples/macextras/macextras.pro
+++ b/examples/macextras/macextras.pro
@@ -2,4 +2,5 @@ TEMPLATE = subdirs
mac:SUBDIRS = macfunctions
mac:!ios:SUBDIRS += embeddedqwindow \
- macpasteboardmime
+ macpasteboardmime \
+ mactoolbar
diff --git a/examples/macextras/mactoolbar/mactoolbar.pro b/examples/macextras/mactoolbar/mactoolbar.pro
new file mode 100644
index 0000000..88d5cde
--- /dev/null
+++ b/examples/macextras/mactoolbar/mactoolbar.pro
@@ -0,0 +1,5 @@
+QT += macextras
+
+HEADERS += toolbarcontrollerwindow.h rasterwindow.h
+SOURCES += toolbarcontrollerwindow.cpp rasterwindow.cpp main.cpp
+RESOURCES += mactoolbar.qrc
diff --git a/examples/macextras/mactoolbar/mactoolbar.qrc b/examples/macextras/mactoolbar/mactoolbar.qrc
new file mode 100644
index 0000000..04a9419
--- /dev/null
+++ b/examples/macextras/mactoolbar/mactoolbar.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>qtlogo.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/macextras/mactoolbar/main.cpp b/examples/macextras/mactoolbar/main.cpp
new file mode 100644
index 0000000..460e9ed
--- /dev/null
+++ b/examples/macextras/mactoolbar/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "toolbarcontrollerwindow.h"
+
+#include <QtGui/QGuiApplication>
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ ToolBarControllerWindow toolbarControllerWindow;
+ toolbarControllerWindow.show();
+
+ return app.exec();
+}
diff --git a/examples/macextras/mactoolbar/qtlogo.png b/examples/macextras/mactoolbar/qtlogo.png
new file mode 100644
index 0000000..d75936b
--- /dev/null
+++ b/examples/macextras/mactoolbar/qtlogo.png
Binary files differ
diff --git a/examples/macextras/mactoolbar/rasterwindow.cpp b/examples/macextras/mactoolbar/rasterwindow.cpp
new file mode 100644
index 0000000..88abad9
--- /dev/null
+++ b/examples/macextras/mactoolbar/rasterwindow.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "rasterwindow.h"
+
+RasterWindow::RasterWindow(QWindow *parent)
+ : QWindow(parent)
+{
+ m_backingStore = new QBackingStore(this);
+ create();
+
+ setGeometry(100, 100, 300, 200);
+}
+
+void RasterWindow::setText(const QString &text)
+{
+ m_text = text;
+ renderNow();
+}
+
+void RasterWindow::exposeEvent(QExposeEvent *)
+{
+ if (isExposed()) {
+ m_backingStore->resize(size());
+ renderNow();
+ }
+}
+
+void RasterWindow::renderNow()
+{
+ if (!isExposed())
+ return;
+
+ QRect rect(0, 0, width(), height());
+ m_backingStore->beginPaint(rect);
+
+ QPaintDevice *device = m_backingStore->paintDevice();
+ QPainter painter(device);
+
+ painter.fillRect(0, 0, width(), height(), Qt::white);
+ render(&painter);
+
+ m_backingStore->endPaint();
+ m_backingStore->flush(rect);
+}
+
+void RasterWindow::render(QPainter *painter)
+{
+ painter->drawText(QRectF(0, 0, width(), height()), Qt::AlignCenter, m_text);
+} \ No newline at end of file
diff --git a/examples/macextras/mactoolbar/rasterwindow.h b/examples/macextras/mactoolbar/rasterwindow.h
new file mode 100644
index 0000000..35f7d23
--- /dev/null
+++ b/examples/macextras/mactoolbar/rasterwindow.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+class RasterWindow : public QWindow
+{
+ Q_OBJECT
+public:
+ explicit RasterWindow(QWindow *parent = 0);
+
+ void setText(const QString &text);
+public slots:
+ void renderNow();
+protected:
+ virtual void render(QPainter *painter);
+ void exposeEvent(QExposeEvent *event);
+
+private:
+ QBackingStore *m_backingStore;
+ QString m_text;
+}; \ No newline at end of file
diff --git a/examples/macextras/mactoolbar/toolbarcontrollerwindow.cpp b/examples/macextras/mactoolbar/toolbarcontrollerwindow.cpp
new file mode 100644
index 0000000..4aa76fb
--- /dev/null
+++ b/examples/macextras/mactoolbar/toolbarcontrollerwindow.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "toolbarcontrollerwindow.h"
+
+ToolBarControllerWindow::ToolBarControllerWindow()
+ :RasterWindow(0)
+{
+ setTitle("QMacToolBar Example");
+ RasterWindow::setText("QMacToolBar Example");
+ resize(400, 200);
+
+ QMacToolBar *toolBar = new QMacToolBar(this);
+
+ QIcon qtIcon(QStringLiteral(":qtlogo.png"));
+
+ // add Items
+ QMacToolBarItem *item1 = toolBar->addItem(qtIcon, QStringLiteral("Foo 1"));
+ connect(item1, SIGNAL(activated()), this, SLOT(activated()));
+ QMacToolBarItem *item2 = toolBar->addItem(qtIcon, QStringLiteral("Bar 1"));
+ connect(item2, SIGNAL(activated()), this, SLOT(activated()));
+
+ toolBar->addSeparator();
+
+ QMacToolBarItem *item3 = toolBar->addItem(qtIcon, QStringLiteral("Foo 2"));
+ connect(item3, SIGNAL(activated()), this, SLOT(activated()));
+ QMacToolBarItem *item4 = toolBar->addItem(qtIcon, QStringLiteral("Bar 2"));
+ connect(item4, SIGNAL(activated()), this, SLOT(activated()));
+
+ // add allowed items for the customization menu.
+ QMacToolBarItem *item5 = toolBar->addAllowedItem(qtIcon, QStringLiteral("AllowedFoo"));
+ connect(item5, SIGNAL(activated()), this, SLOT(activated()));
+ QMacToolBarItem *item6 = toolBar->addAllowedItem(qtIcon, QStringLiteral("AllowedBar"));
+ connect(item6, SIGNAL(activated()), this, SLOT(activated()));
+
+ // Attach to the window
+ toolBar->attachToWindow(this);
+}
+
+void ToolBarControllerWindow::activated()
+{
+ QMacToolBarItem *item = static_cast<QMacToolBarItem *>(sender());
+ setText(QStringLiteral("Activated ") + item->text());
+}
diff --git a/examples/macextras/mactoolbar/toolbarcontrollerwindow.h b/examples/macextras/mactoolbar/toolbarcontrollerwindow.h
new file mode 100644
index 0000000..b7251d2
--- /dev/null
+++ b/examples/macextras/mactoolbar/toolbarcontrollerwindow.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qdebug.h>
+#include <QtGui/QWindow>
+#include <QMacToolBar>
+
+#include "rasterwindow.h"
+
+class ToolBarControllerWindow : public RasterWindow
+{
+Q_OBJECT
+public:
+ ToolBarControllerWindow();
+public Q_SLOTS:
+ void activated();
+private:
+
+};
+
diff --git a/src/macextras/macextras-lib.pri b/src/macextras/macextras-lib.pri
index 388a905..2ce4f05 100644
--- a/src/macextras/macextras-lib.pri
+++ b/src/macextras/macextras-lib.pri
@@ -1,7 +1,9 @@
INCLUDEPATH += $$PWD
mac {
- PUBLIC_HEADERS += $$PWD/qmacfunctions.h
+ PUBLIC_HEADERS += \
+ $$PWD/qmacfunctions.h \
+
PRIVATE_HEADERS += $$PWD/qmacfunctions_p.h
OBJECTIVE_SOURCES += $$PWD/qmacfunctions.mm
@@ -11,17 +13,20 @@ mac {
LIBS_PRIVATE += -framework UIKit
} else {
+ PUBLIC_HEADERS += \
+ $$PWD/qmactoolbar.h \
+ $$PWD/qmactoolbaritem.h \
+
PRIVATE_HEADERS += \
- $$PWD/qmacnativetoolbar_p.h \
- $$PWD/qmactoolbutton_p.h \
+ $$PWD/qmactoolbar_p.h \
$$PWD/qmactoolbardelegate_p.h \
$$PWD/qnstoolbar_p.h
OBJECTIVE_SOURCES += \
$$PWD/qmacfunctions_mac.mm \
- $$PWD/qmacnativetoolbar.mm \
+ $$PWD/qmactoolbar.mm \
+ $$PWD/qmactoolbaritem.mm \
$$PWD/qmactoolbardelegate.mm \
- $$PWD/qmactoolbutton.mm \
$$PWD/qnstoolbar.mm
greaterThan(QT_MAJOR_VERSION, 4) {
diff --git a/src/macextras/qmacnativetoolbar.mm b/src/macextras/qmacnativetoolbar.mm
deleted file mode 100644
index 22c6a6b..0000000
--- a/src/macextras/qmacnativetoolbar.mm
+++ /dev/null
@@ -1,493 +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 <AppKit/AppKit.h>
-#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 <QtGui/QGuiApplication>
-#include <qpa/qplatformnativeinterface.h>
-#else
-#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
-#define kNSToolbarIconSizeRegular 32
-#define kNSToolbarIconSizeDefault kNSToolbarIconSizeRegular
-
-NSString *toNSStandardItem(QMacToolButton::StandardItem standardItem)
-{
- if (standardItem == QMacToolButton::ShowColors)
- return NSToolbarShowColorsItemIdentifier;
- else if (standardItem == QMacToolButton::ShowFonts)
- return NSToolbarShowFontsItemIdentifier;
- else if (standardItem == QMacToolButton::PrintItem)
- return NSToolbarPrintItemIdentifier;
- else if (standardItem == QMacToolButton::Space)
- return NSToolbarSpaceItemIdentifier;
- else if (standardItem == QMacToolButton::FlexibleSpace)
- return NSToolbarFlexibleSpaceItemIdentifier;
- return @"";
-}
-
-QT_BEGIN_NAMESPACE
-
-NSToolbarDisplayMode toNSToolbarDisplayMode(Qt::ToolButtonStyle toolButtonStyle)
-{
- switch (toolButtonStyle)
- {
- case Qt::ToolButtonIconOnly:
- return NSToolbarDisplayModeIconOnly;
- case Qt::ToolButtonTextOnly:
- return NSToolbarDisplayModeLabelOnly;
- case Qt::ToolButtonTextBesideIcon:
- case Qt::ToolButtonTextUnderIcon:
- return NSToolbarDisplayModeIconAndLabel;
- case Qt::ToolButtonFollowStyle:
- default:
- return NSToolbarDisplayModeDefault;
- }
-}
-
-Qt::ToolButtonStyle toQtToolButtonStyle(NSToolbarDisplayMode toolbarDisplayMode)
-{
- switch (toolbarDisplayMode)
- {
- case NSToolbarDisplayModeIconAndLabel:
- return Qt::ToolButtonTextUnderIcon;
- case NSToolbarDisplayModeIconOnly:
- return Qt::ToolButtonIconOnly;
- case NSToolbarDisplayModeLabelOnly:
- return Qt::ToolButtonTextOnly;
- case NSToolbarDisplayModeDefault:
- default:
- return Qt::ToolButtonFollowStyle;
- }
-}
-
-QT_END_NAMESPACE
-
-#include <qglobal.h>
-
-@interface QT_MANGLE_NAMESPACE(QNSToolbarNotifier) : NSObject
-{
-@public
- QMacNativeToolBarPrivate *pimpl;
-}
-- (void)notification:(NSNotification*)note;
-@end
-
-QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSToolbarNotifier);
-
-QT_BEGIN_NAMESPACE
-
-class QMacNativeToolBarPrivate
-{
-public:
- QMacNativeToolBar *qtToolbar;
- QtNSToolbar *toolbar;
- QMacToolbarDelegate *delegate;
- QNSToolbarNotifier *notifier;
-
- QMacNativeToolBarPrivate(QMacNativeToolBar *parent, const QString &identifier = QString())
- {
- qtToolbar = parent;
- toolbar = [[QtNSToolbar alloc] initWithIdentifier:QtMac::toNSString(identifier.isEmpty() ? QUuid::createUuid().toString() : identifier)];
- [toolbar setAutosavesConfiguration:NO];
-
- delegate = [[QMacToolbarDelegate alloc] init];
- [toolbar setDelegate:delegate];
-
- notifier = [[QNSToolbarNotifier alloc] init];
- notifier->pimpl = this;
- [[NSNotificationCenter defaultCenter] addObserver:notifier selector:@selector(notification:) name:nil object:toolbar];
- }
-
- ~QMacNativeToolBarPrivate()
- {
- [[NSNotificationCenter defaultCenter] removeObserver:notifier name:nil object:toolbar];
- }
-
- void fireVisibilityChanged()
- {
- Q_ASSERT(qtToolbar);
- Q_EMIT qtToolbar->visibilityChanged(qtToolbar->isVisible());
- }
-
- void fireShowsBaselineSeparatorChanged()
- {
- Q_ASSERT(qtToolbar);
- Q_EMIT qtToolbar->showsBaselineSeparatorChanged(qtToolbar->showsBaselineSeparator());
- }
-
- void fireToolButtonStyleChanged()
- {
- Q_ASSERT(qtToolbar);
- Q_EMIT qtToolbar->toolButtonStyleChanged(qtToolbar->toolButtonStyle());
- }
-
- void fireSizeModeChangedNotification()
- {
- Q_ASSERT(qtToolbar);
- Q_EMIT qtToolbar->iconSizeChanged(qtToolbar->iconSize());
- Q_EMIT qtToolbar->iconSizeChanged(qtToolbar->iconSizeType());
- }
-
- void fireAllowsUserCustomizationChanged()
- {
- Q_ASSERT(qtToolbar);
- Q_EMIT qtToolbar->allowsUserCustomizationChanged(qtToolbar->allowsUserCustomization());
- }
-};
-
-QMacNativeToolBar::QMacNativeToolBar(QObject *parent)
- : QObject(parent), targetWindow(NULL), targetWidget(NULL), d(new QMacNativeToolBarPrivate(this))
-{
- setAllowsUserCustomization(true);
- setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
-}
-
-QMacNativeToolBar::QMacNativeToolBar(const QString &identifier, QObject *parent)
- : QObject(parent), targetWindow(NULL), targetWidget(NULL), d(new QMacNativeToolBarPrivate(this, identifier))
-{
- setAllowsUserCustomization(true);
- setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
-}
-
-QMacNativeToolBar::~QMacNativeToolBar()
-{
- [d->toolbar release];
- delete d;
-}
-
-NSToolbar *QMacNativeToolBar::nativeToolbar() const
-{
- return d->toolbar;
-}
-
-QString QMacNativeToolBar::identifier() const
-{
- return QtMac::fromNSString([d->toolbar identifier]);
-}
-
-bool QMacNativeToolBar::isVisible() const
-{
- return [d->toolbar isVisible];
-}
-
-void QMacNativeToolBar::setVisible(bool visible)
-{
- [d->toolbar setVisible:visible];
-}
-
-bool QMacNativeToolBar::showsBaselineSeparator() const
-{
- return [d->toolbar showsBaselineSeparator];
-}
-
-void QMacNativeToolBar::setShowsBaselineSeparator(bool show)
-{
- [d->toolbar setShowsBaselineSeparator:show];
-}
-
-bool QMacNativeToolBar::allowsUserCustomization() const
-{
- return [d->toolbar allowsUserCustomization];
-}
-
-void QMacNativeToolBar::setAllowsUserCustomization(bool allow)
-{
- [d->toolbar setAllowsUserCustomization:allow];
-}
-
-Qt::ToolButtonStyle QMacNativeToolBar::toolButtonStyle() const
-{
- return toQtToolButtonStyle([d->toolbar displayMode]);
-}
-
-void QMacNativeToolBar::setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle)
-{
- [d->toolbar setDisplayMode:toNSToolbarDisplayMode(toolButtonStyle)];
-
- // Since this isn't supported, no change event will be fired so do it manually
- if (toolButtonStyle == Qt::ToolButtonTextBesideIcon)
- d->fireToolButtonStyleChanged();
-}
-
-QSize QMacNativeToolBar::iconSize() const
-{
- switch (iconSizeType())
- {
- case QMacToolButton::IconSizeRegular:
- return QSize(kNSToolbarIconSizeRegular, kNSToolbarIconSizeRegular);
- case QMacToolButton::IconSizeSmall:
- return QSize(kNSToolbarIconSizeSmall, kNSToolbarIconSizeSmall);
- case QMacToolButton::IconSizeDefault:
- default:
- return QSize(kNSToolbarIconSizeDefault, kNSToolbarIconSizeDefault);
- }
-}
-
-QMacToolButton::IconSize QMacNativeToolBar::iconSizeType() const
-{
- switch ([d->toolbar sizeMode])
- {
- case NSToolbarSizeModeRegular:
- return QMacToolButton::IconSizeRegular;
- case NSToolbarSizeModeSmall:
- return QMacToolButton::IconSizeSmall;
- case NSToolbarSizeModeDefault:
- default:
- return QMacToolButton::IconSizeDefault;
- }
-}
-
-void QMacNativeToolBar::setIconSize(const QSize &iconSize)
-{
- if (iconSize.isEmpty())
- setIconSize(QMacToolButton::IconSizeDefault);
- else if (iconSize.width() <= kNSToolbarIconSizeSmall && iconSize.height() <= kNSToolbarIconSizeSmall)
- setIconSize(QMacToolButton::IconSizeSmall);
- else
- setIconSize(QMacToolButton::IconSizeRegular);
-}
-
-void QMacNativeToolBar::setIconSize(QMacToolButton::IconSize iconSize)
-{
- switch (iconSize)
- {
- case QMacToolButton::IconSizeRegular:
- [d->toolbar setSizeMode:NSToolbarSizeModeRegular];
- break;
- case QMacToolButton::IconSizeSmall:
- [d->toolbar setSizeMode:NSToolbarSizeModeSmall];
- break;
- case QMacToolButton::IconSizeDefault:
- default:
- [d->toolbar setSizeMode:NSToolbarSizeModeDefault];
- break;
- }
-}
-
-void QMacNativeToolBar::showCustomizationSheet()
-{
- [d->toolbar runCustomizationPalette:nil];
-}
-
-QList<QMacToolButton *> QMacNativeToolBar::buttons()
-{
- return d->delegate->items;
-}
-
-QList<QMacToolButton *> QMacNativeToolBar::allowedButtons()
-{
- return d->delegate->allowedItems;
-}
-
-void QMacNativeToolBar::showInWindow(QWindow *window)
-{
- targetWindow = window;
- QTimer::singleShot(100, this, SLOT(showInWindow_impl())); // ### hackety hack
-}
-
-void QMacNativeToolBar::showInWindow_impl()
-{
- if (!targetWindow) {
- QTimer::singleShot(100, this, SLOT(showInWindow_impl()));
- return;
- }
-
- NSWindow *macWindow = static_cast<NSWindow*>(
- QGuiApplication::platformNativeInterface()->nativeResourceForWindow("nswindow", targetWindow));
-
- if (!macWindow) {
- QTimer::singleShot(100, this, SLOT(showInWindow_impl()));
- return;
- }
-
- [macWindow setToolbar: d->toolbar];
- [macWindow setShowsToolbarButton:YES];
-}
-void QMacNativeToolBar::removeFromWindow(QWindow *window)
-{
- if (!window)
- return;
-
- NSWindow *macWindow = static_cast<NSWindow*>(
- QGuiApplication::platformNativeInterface()->nativeResourceForWindow("nswindow", window));
- [macWindow setToolbar:nil];
-}
-
-
-void QMacNativeToolBar::setSelectedItem()
-{
-// setSelectedItem(qobject_cast<QMacToolButton*>(sender()));
-}
-
-//### 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
- if (action && action->isCheckable())
- {
- checkSelectableItemSanity();
-
- foreach (QMacToolButton *toolButton, allowedButtons())
- {
- if (toolButton->m_action && toolButton->m_action->isChecked())
- {
- [d->toolbar setSelectedItemIdentifier:QtMac::toNSString(QString::number(qulonglong(toolButton)))];
- break;
- }
- else
- {
- [d->toolbar setSelectedItemIdentifier:nil];
- }
- }
- }
-
- return action;
-}
-
-void QMacNativeToolBar::checkSelectableItemSanity()
-{
- // Find a list of all selectable actions
- QList<QMacToolButton*> selectableActions;
- foreach (QMacToolButton *button, allowedButtons())
- if (button->m_action && button->m_action->isCheckable())
- selectableActions.append(button->m_action);
-
- // If there's more than one, we need to do some sanity checks
- if (selectableActions.size() > 1)
- {
- // The action group that all selectable actions must belong to
- QMacToolButtonGroup *group = NULL;
-
- foreach (QMacToolButton *action, selectableActions)
- {
- // The first action group we find is "the" action group that
- // all selectable actions on the toolbar must belong to
- if (!group)
- group = action->actionGroup();
-
- // An action not having a group is a failure
- // All actions not belonging to the same group is a failure
- // 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 QMacToolButtonGroup if there is more than one selectable action.";
- break;
- }
- }
- }
-}
-#endif
-
-QMacToolButton *QMacNativeToolBar::addAction(const QString &text)
-{
- return [d->delegate addActionWithText:&text];
-}
-
-QMacToolButton *QMacNativeToolBar::addAction(const QIcon &icon, const QString &text)
-{
- return [d->delegate addActionWithText:&text icon:&icon];
-}
-
-void QMacNativeToolBar::addSeparator()
-{
- addStandardItem(QMacToolButton::Space); // No Seprator on OS X.
-}
-
-QMacToolButton *QMacNativeToolBar::addStandardItem(QMacToolButton::StandardItem standardItem)
-{
- return [d->delegate addStandardItem:standardItem];
-}
-
-QMacToolButton *QMacNativeToolBar::addAllowedAction(const QString &text)
-{
- return [d->delegate addAllowedActionWithText:&text];
-}
-
-QMacToolButton *QMacNativeToolBar::addAllowedAction(const QIcon &icon, const QString &text)
-{
- return [d->delegate addAllowedActionWithText:&text icon:&icon];
-}
-
-
-QMacToolButton *QMacNativeToolBar::addAllowedStandardItem(QMacToolButton::StandardItem standardItem)
-{
- return [d->delegate addAllowedStandardItem:standardItem];
-}
-
-QT_END_NAMESPACE
-
-QT_USE_NAMESPACE
-
-@implementation QNSToolbarNotifier
-
-- (void)notification:(NSNotification*)note
-{
- Q_ASSERT(pimpl);
- if ([[note name] isEqualToString:QtNSToolbarVisibilityChangedNotification])
- pimpl->fireVisibilityChanged();
- else if ([[note name] isEqualToString:QtNSToolbarShowsBaselineSeparatorChangedNotification])
- pimpl->fireShowsBaselineSeparatorChanged();
- else if ([[note name] isEqualToString:QtNSToolbarDisplayModeChangedNotification])
- pimpl->fireToolButtonStyleChanged();
- else if ([[note name] isEqualToString:QtNSToolbarSizeModeChangedNotification])
- pimpl->fireSizeModeChangedNotification();
- else if ([[note name] isEqualToString:QtNSToolbarAllowsUserCustomizationChangedNotification])
- pimpl->fireAllowsUserCustomizationChanged();
-}
-
-@end
diff --git a/src/macextras/qmacnativetoolbar_p.h b/src/macextras/qmacnativetoolbar_p.h
deleted file mode 100644
index fe15ea2..0000000
--- a/src/macextras/qmacnativetoolbar_p.h
+++ /dev/null
@@ -1,139 +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 QMACTOOLBAR_H
-#define QMACTOOLBAR_H
-
-#include "qmacextrasglobal.h"
-#include "qmactoolbutton_p.h"
-
-#include <QtCore/QString>
-#include <QtCore/QObject>
-#include <QtCore/QVariant>
-#include <QtGui/QIcon>
-
-Q_FORWARD_DECLARE_OBJC_CLASS(NSToolbar);
-
-QT_BEGIN_NAMESPACE
-
-class QWindow;
-class QMacNativeToolBar;
-class QMacNativeToolBarPrivate;
-
-class Q_MACEXTRAS_EXPORT QMacNativeToolBar : public QObject
-{
- friend class QMacNativeToolBarPrivate;
-
- Q_OBJECT
- Q_PROPERTY(QList<QMacToolButton *> buttons READ buttons)
- Q_PROPERTY(QList<QMacToolButton *> allowedButtons READ allowedButtons)
-public:
- QMacNativeToolBar(QObject *parent = 0);
- QMacNativeToolBar(const QString &identifier, QObject *parent = 0);
- ~QMacNativeToolBar();
-
- NSToolbar* nativeToolbar() const;
-
- QString identifier() const;
- bool isVisible() const;
- bool showsBaselineSeparator() const;
- bool allowsUserCustomization() const;
- Qt::ToolButtonStyle toolButtonStyle() const;
- QSize iconSize() const;
- QMacToolButton::IconSize iconSizeType() const;
-
- QList<QMacToolButton *> buttons();
- QList<QMacToolButton *> allowedButtons();
-
- void showInWindow(QWindow *window);
-
- void removeFromWindow(QWindow *window);
-
- // Add actions to the toolbar
- Q_INVOKABLE QMacToolButton *addAction(const QString &text);
- Q_INVOKABLE QMacToolButton *addAction(const QIcon &icon, const QString &text);
- Q_INVOKABLE void addSeparator();
- Q_INVOKABLE QMacToolButton *addStandardItem(QMacToolButton::StandardItem standardItem);
-
- // Add actions to the "Customize Toolbar" menu
- 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);
- void showsBaselineSeparatorChanged(bool show);
- void allowsUserCustomizationChanged(bool allow);
- void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle);
- void iconSizeChanged(const QSize &iconSize);
- void iconSizeChanged(QMacToolButton::IconSize iconSize);
-
-public Q_SLOTS:
- void setVisible(bool visible);
- void setShowsBaselineSeparator(bool show);
- void setAllowsUserCustomization(bool allow);
- void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle);
- void setIconSize(const QSize &iconSize);
- void setIconSize(QMacToolButton::IconSize iconSize);
- void showCustomizationSheet();
-
-private Q_SLOTS:
- void showInWindow_impl();
- void setSelectedItem();
-//### TODO- re-implement
-#if 0
- QMacToolButton *setSelectedItem(QMacToolbarAction *action);
- void checkSelectableItemSanity();
-#endif
-private:
- QWindow *targetWindow;
- void *targetWidget;
- QList<QMacToolButton *> m_buttons;
- QList<QMacToolButton *> m_allowedButtons;
- QMacNativeToolBarPrivate *d;
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QMacNativeToolBar*)
-
-#endif
-
diff --git a/src/macextras/qmactoolbar.h b/src/macextras/qmactoolbar.h
new file mode 100644
index 0000000..10f3ddb
--- /dev/null
+++ b/src/macextras/qmactoolbar.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 QMACTOOLBAR_H
+#define QMACTOOLBAR_H
+
+#include "qmacextrasglobal.h"
+#include "qmactoolbaritem.h"
+
+#include <QtCore/QString>
+#include <QtCore/QObject>
+#include <QtCore/QVariant>
+#include <QtGui/QIcon>
+
+Q_FORWARD_DECLARE_OBJC_CLASS(NSToolbar);
+
+QT_BEGIN_NAMESPACE
+
+class QWindow;
+class QMacToolBarPrivate;
+
+class Q_MACEXTRAS_EXPORT QMacToolBar : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QMacToolBar(QObject *parent = 0);
+ QMacToolBar(const QString &identifier, QObject *parent = 0);
+ ~QMacToolBar();
+
+ QMacToolBarItem *addItem(const QIcon &icon, const QString &text);
+ QMacToolBarItem *addAllowedItem(const QIcon &icon, const QString &text);
+ QMacToolBarItem *addStandardItem(QMacToolBarItem::StandardItem standardItem);
+ QMacToolBarItem *addAllowedStandardItem(QMacToolBarItem::StandardItem standardItem);
+ void addSeparator();
+
+ void setItems(QList<QMacToolBarItem *> &items);
+ QList<QMacToolBarItem *> items();
+ void setAllowedItems(QList<QMacToolBarItem *> &allowedItems);
+ QList<QMacToolBarItem *> allowedItems();
+
+ void attachToWindow(QWindow *window);
+ void detachFromWindow();
+
+ NSToolbar* nativeToolbar() const;
+private Q_SLOTS:
+ void showInWindow_impl();
+private:
+ Q_DECLARE_PRIVATE(QMacToolBar)
+};
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QMacToolBar*)
+
+#endif
+
diff --git a/src/macextras/qmactoolbar.mm b/src/macextras/qmactoolbar.mm
new file mode 100644
index 0000000..686c9a3
--- /dev/null
+++ b/src/macextras/qmactoolbar.mm
@@ -0,0 +1,327 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 <AppKit/AppKit.h>
+#include "qmactoolbar.h"
+#include "qmactoolbar_p.h"
+
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+#include <QtCore/QUuid>
+#include <QtCore/qdebug.h>
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#include <QtGui/QGuiApplication>
+#include <qpa/qplatformnativeinterface.h>
+#else
+#include <QtGui/QMainWindow>
+#endif
+
+#include "qmacfunctions.h"
+#include "qmacfunctions_p.h"
+#include "qmactoolbaritem_p.h"
+#include "qmactoolbardelegate_p.h"
+#include "qnstoolbar_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QMacToolBar
+ \inmodule QtMacExtras
+ \since 5.3
+ \brief The QMacToolBar class wraps the native NSToolbar class.
+
+ QMacToolBar provides a Qt-based API for NSToolBar. The toolbar displays one or
+ more \e items. Each toolbar item has an icon and a text label.
+
+ The toolbar must be attached to a QWindow with \fn attachToWindow in order to be
+ visible. The toolbar is attached to the native NSWindow and is displayed above
+ the QWindow. QMacToolBar visibility follows window visibility.
+
+ Add items by calling addItem(). The toolbar has a customization menu which
+ is available to the user from the toolbar context menu. Use addAllowedItem() to
+ add items to the customization menu.
+
+ Usage: (QtWidgets)
+ \code
+ QMacToolBar *toolBar = new QMacToolBar(this);
+ QMacToolBarItem *toolBarItem = toolBar->addItem(QIcon(), QStringLiteral("foo"));
+ connect(toolButton, SIGNAL(activated()), this, SLOT(fooClicked()))
+
+ this->window()->winId(); // create window->windowhandle()
+ toolBar->attachToWindow(this->window()->windowHandle())
+ \endcode
+
+ \sa QMacToolBarItem
+*/
+
+/*!
+ Constructs a QMacToolBar with the given \a parent
+*/
+QMacToolBar::QMacToolBar(QObject *parent)
+ : QObject(*new QMacToolBarPrivate(), parent)
+{
+}
+
+/*!
+ Constructs a QMacToolBar with the given \a identifier and \a parent. The identifier is used
+ to uniquely identify the toolbar within the appliation, for example when autosaving the
+ toolbar configuration.
+*/
+QMacToolBar::QMacToolBar(const QString &identifier, QObject *parent)
+ : QObject(*new QMacToolBarPrivate(identifier), parent)
+{
+}
+
+/*!
+ Destroys the toolbar.
+*/
+QMacToolBar::~QMacToolBar()
+{
+ Q_D(QMacToolBar);
+ [d->toolbar release];
+}
+
+/*!
+ Add a toolbar item with \a icon and \a text.
+*/
+QMacToolBarItem *QMacToolBar::addItem(const QIcon &icon, const QString &text)
+{
+ Q_D(QMacToolBar);
+ QMacToolBarItem *item = new QMacToolBarItem(this);
+ item->setText(text);
+ item->setIcon(icon);
+ d->items.append(item);
+ d->allowedItems.append(item);
+ return item;
+}
+
+/*!
+ Add a toolbar separator item.
+*/
+void QMacToolBar::addSeparator()
+{
+ addStandardItem(QMacToolBarItem::Space); // No Seprator on OS X.
+}
+
+/*!
+ Add a toolbar standard item.
+ \omitvalue standardItem
+ \internal
+*/
+QMacToolBarItem *QMacToolBar::addStandardItem(QMacToolBarItem::StandardItem standardItem)
+{
+ Q_D(QMacToolBar);
+ QMacToolBarItem *item = new QMacToolBarItem(this);
+ item->setStandardItem(standardItem);
+ d->items.append(item);
+ d->allowedItems.append(item);
+ return item;
+}
+
+/*!
+ Add atoolbar item with \a icon and \a text to the toolbar customization menu.
+*/
+QMacToolBarItem *QMacToolBar::addAllowedItem(const QIcon &icon, const QString &text)
+{
+ Q_D(QMacToolBar);
+ QMacToolBarItem *item = new QMacToolBarItem(this);
+ item->setText(text);
+ item->setIcon(icon);
+ d->allowedItems.append(item);
+ return item;
+}
+
+/*!
+ Add a standard toolbar item to the toolbar customization menu.
+ \omitvalue standardItem
+ \internal
+*/
+QMacToolBarItem *QMacToolBar::addAllowedStandardItem(QMacToolBarItem::StandardItem standardItem)
+{
+ Q_D(QMacToolBar);
+ QMacToolBarItem *item = new QMacToolBarItem(this);
+ item->setStandardItem(standardItem);
+ d->allowedItems.append(item);
+ return item;
+}
+
+/*!
+ Sets the list of the default toolbar items.
+*/
+void QMacToolBar::setItems(QList<QMacToolBarItem *> &items)
+{
+ Q_D(QMacToolBar);
+ d->items = items;
+}
+
+/*!
+ Returns the list of the default toolbar items.
+*/
+QList<QMacToolBarItem *> QMacToolBar::items()
+{
+ Q_D(QMacToolBar);
+ return d->items;
+}
+
+/*!
+ Sets the list of toolbar items shown on the the toolbar customization menu.
+*/
+void QMacToolBar::setAllowedItems(QList<QMacToolBarItem *> &allowedItems)
+{
+ Q_D(QMacToolBar);
+ d->allowedItems = allowedItems;
+}
+
+/*!
+ Returns the list oftoolbar items shown on the the toolbar customization menu.
+*/
+QList<QMacToolBarItem *> QMacToolBar::allowedItems()
+{
+ Q_D(QMacToolBar);
+ return d->allowedItems;
+}
+
+/*!
+ Attaches the toolbar to \a window. The toolbar will be displayed at the top of the
+ native window, under and attached to the title bar above the QWindow. The toolbar is displayed
+ outside the QWidnow area.
+
+ Use QWidget::windowHandle() to get a QWindow pointer from a QWidget instance. At app startup
+ the QWindow might not have been created yet, call QWidget::winId() to make sure it is.
+*/
+void QMacToolBar::attachToWindow(QWindow *window)
+{
+ Q_D(QMacToolBar);
+ if (!window) {
+ detachFromWindow();
+ return;
+ }
+
+ d->targetWindow = window;
+ QTimer::singleShot(100, this, SLOT(showInWindow_impl())); // ### hackety hack
+}
+
+/*!
+ \internal
+*/
+void QMacToolBar::showInWindow_impl()
+{
+ Q_D(QMacToolBar);
+ if (!d->targetWindow) {
+ QTimer::singleShot(100, this, SLOT(showInWindow_impl()));
+ return;
+ }
+
+ NSWindow *macWindow = static_cast<NSWindow*>(
+ QGuiApplication::platformNativeInterface()->nativeResourceForWindow("nswindow", d->targetWindow));
+
+ if (!macWindow) {
+ QTimer::singleShot(100, this, SLOT(showInWindow_impl()));
+ return;
+ }
+
+ [macWindow setToolbar: d->toolbar];
+ [macWindow setShowsToolbarButton:YES];
+}
+
+/*!
+ Detatches the toolbar from the current window.
+*/
+void QMacToolBar::detachFromWindow()
+{
+ Q_D(QMacToolBar);
+ if (!d->targetWindow)
+ return;
+
+ NSWindow *macWindow = static_cast<NSWindow*>(
+ QGuiApplication::platformNativeInterface()->nativeResourceForWindow("nswindow", d->targetWindow));
+ [macWindow setToolbar:nil];
+}
+
+/*!
+ Returns the naitve NSTooolbar object.
+*/
+NSToolbar *QMacToolBar::nativeToolbar() const
+{
+ Q_D(const QMacToolBar);
+ return d->toolbar;
+}
+
+QMacToolBarPrivate::QMacToolBarPrivate(const QString &identifier)
+{
+ QString ident = identifier.isEmpty() ? QUuid::createUuid().toString() : identifier;
+ toolbar = [[NSToolbar alloc] initWithIdentifier:ident.toNSString()];
+ [toolbar setAutosavesConfiguration:NO];
+ [toolbar setAllowsUserCustomization:YES];
+
+ QMacToolbarDelegate *delegate = [[QMacToolbarDelegate alloc] init];
+ delegate->toolbarPrivate = this;
+ [toolbar setDelegate:delegate];
+
+ targetWindow = 0;
+}
+
+QMacToolBarPrivate::~QMacToolBarPrivate()
+{
+ [[toolbar delegate]release];
+ [toolbar release];
+}
+
+NSMutableArray *QMacToolBarPrivate::getItemIdentifiers(const QList<QMacToolBarItem *> &items, bool cullUnselectable)
+{
+ NSMutableArray *array = [[NSMutableArray alloc] init];
+ foreach (const QMacToolBarItem * item, items) {
+ if (cullUnselectable && item->selectable() == false)
+ continue;
+ [array addObject : item->d_func()->itemIdentifier()];
+ }
+ return array;
+}
+
+void QMacToolBarPrivate::itemClicked(NSToolbarItem *item)
+{
+ QString identifier = QtMac::fromNSString([item itemIdentifier]);
+ QMacToolBarItem *toolButton = reinterpret_cast<QMacToolBarItem *>(identifier.toULongLong());
+ Q_EMIT toolButton->activated();
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/macextras/qmactoolbutton.mm b/src/macextras/qmactoolbar_p.h
index ca41f2a..17d0e7c 100644
--- a/src/macextras/qmactoolbutton.mm
+++ b/src/macextras/qmactoolbar_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -39,66 +39,42 @@
**
****************************************************************************/
-#include "qmactoolbutton_p.h"
+#ifndef QMACTOOLBAR_P_H
+#define QMACTOOLBAR_P_H
+#import <AppKit/AppKit.h>
-QT_BEGIN_NAMESPACE
-
-QMacToolButton::QMacToolButton()
-{
- m_standardItem = NoItem;
- m_selectable = false;
-}
-
-QMacToolButton::QMacToolButton(QObject *parent)
- :QObject(parent)
-{
- m_standardItem = NoItem;
- m_selectable = false;
-}
+#include "qmactoolbar.h"
-QMacToolButton::~QMacToolButton()
-{
+#include "qmacextrasglobal.h"
+#include "qmactoolbaritem.h"
-}
+#include <QtCore/QString>
+#include <QtCore/QObject>
+#include <QtCore/private/qobject_p.h>
-bool QMacToolButton::selectable() const
-{
- return m_selectable;
-}
+Q_FORWARD_DECLARE_OBJC_CLASS(NSToolbar);
-void QMacToolButton::setSelectable(bool selectable)
-{
- m_selectable = selectable;
-}
+QT_BEGIN_NAMESPACE
-QMacToolButton::StandardItem QMacToolButton::standardItem() const
+class QMacToolBarPrivate : public QObjectPrivate
{
- return m_standardItem;
-}
+public:
+ QMacToolBarPrivate(const QString &identifier = QString());
+ ~QMacToolBarPrivate();
-void QMacToolButton::setStandardItem(StandardItem standardItem)
-{
- m_standardItem = standardItem;
-}
+ static NSString *getItemIdentifier(const QMacToolBarItem *item);
+ static NSMutableArray *getItemIdentifiers(const QList<QMacToolBarItem *> &items, bool cullUnselectable);
+ void itemClicked(NSToolbarItem *itemClicked);
-QString QMacToolButton::text() const
-{
- return m_text;
-}
+ NSToolbar *toolbar;
+ QWindow *targetWindow;
+ QList<QMacToolBarItem *> items;
+ QList<QMacToolBarItem *> allowedItems;
-void QMacToolButton::setText(const QString &text)
-{
- m_text = text;
-}
+ Q_DECLARE_PUBLIC(QMacToolBar)
+};
-QIcon QMacToolButton::icon() const
-{
- return m_icon;
-}
+QT_END_NAMESPACE
-void QMacToolButton::setIcon(const QIcon &icon)
-{
- m_icon = icon;
-}
+#endif
-QT_END_NAMESPACE
diff --git a/src/macextras/qmactoolbardelegate.mm b/src/macextras/qmactoolbardelegate.mm
index 678423e..b6f3768 100644
--- a/src/macextras/qmactoolbardelegate.mm
+++ b/src/macextras/qmactoolbardelegate.mm
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -46,7 +46,7 @@
#include "qmacfunctions.h"
#include "qmacfunctions_p.h"
-#include "qmacnativetoolbar_p.h"
+#include "qmactoolbar.h"
QT_USE_NAMESPACE
@@ -59,23 +59,6 @@ NSArray *toNSArray(const QList<QString> &stringList)
return array;
}
-NSString *toNSStandardItem(QMacToolButton::StandardItem standardItem);
-
-NSMutableArray *itemIdentifiers(const QList<QMacToolButton *> &items, bool cullUnselectable)
-{
- NSMutableArray *array = [[NSMutableArray alloc] init];
- foreach (const QMacToolButton * item, items) {
- if (cullUnselectable && item->selectable() == false)
- continue;
- if (item->standardItem() == QMacToolButton::NoItem) {
- [array addObject : QtMac::toNSString(QString::number(qulonglong(item)))];
- } else {
- [array addObject : toNSStandardItem(item->standardItem())];
- }
- }
- return array;
-}
-
// from QMacToolButton.cpp
QString qt_strippedText(QString s)
{
@@ -97,29 +80,27 @@ QString qt_strippedText(QString s)
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
Q_UNUSED(toolbar);
- return itemIdentifiers(self->items, false);
+ return toolbarPrivate->getItemIdentifiers(toolbarPrivate->items, false);
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
Q_UNUSED(toolbar);
- return itemIdentifiers(self->allowedItems, false);
+ return toolbarPrivate->getItemIdentifiers(toolbarPrivate->allowedItems, false);
}
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
{
Q_UNUSED(toolbar);
- NSMutableArray *array = itemIdentifiers(self->items, true);
- [array addObjectsFromArray : itemIdentifiers(self->allowedItems, true)];
+ NSMutableArray *array = toolbarPrivate->getItemIdentifiers(toolbarPrivate->items, true);
+ [array addObjectsFromArray:toolbarPrivate->getItemIdentifiers(toolbarPrivate->allowedItems, true)];
return array;
}
- (IBAction)itemClicked:(id)sender
{
NSToolbarItem *item = reinterpret_cast<NSToolbarItem *>(sender);
- QString identifier = QtMac::fromNSString([item itemIdentifier]);
- QMacToolButton *toolButton = reinterpret_cast<QMacToolButton *>(identifier.toULongLong());
- toolButton->emitActivated();
+ toolbarPrivate->itemClicked(item);
}
- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdentifier willBeInsertedIntoToolbar:(BOOL) willBeInserted
@@ -127,16 +108,8 @@ QString qt_strippedText(QString s)
Q_UNUSED(toolbar);
Q_UNUSED(willBeInserted);
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(toolButton->text())];
- [toolbarItem setPaletteLabel :[toolbarItem label]];
-
- QPixmap icon = toolButton->icon().pixmap(64, 64);
- if (icon.isNull() == false) {
- [toolbarItem setImage: QtMac::toNSImage(icon)];
- }
+ QMacToolBarItem *toolButton = reinterpret_cast<QMacToolBarItem *>(identifier.toULongLong()); // string -> unisgned long long -> pointer
+ NSToolbarItem *toolbarItem = toolButton->nativeToolBarItem();
[toolbarItem setTarget : self];
[toolbarItem setAction : @selector(itemClicked:)];
@@ -144,53 +117,4 @@ QString qt_strippedText(QString s)
return toolbarItem;
}
-- (QMacToolButton *)addActionWithText:(const QString *)text
-{
- QIcon nullIcon;
- return [self addActionWithText:text icon:&nullIcon];
-}
-
-- (QMacToolButton *)addActionWithText:(const QString *)text icon:(const QIcon *)icon
-{
- QMacToolButton *button = new QMacToolButton(0);
- button->setText(*text);
- button->setIcon(*icon);
- items.append(button);
- allowedItems.append(button);
- return button;
-}
-
-- (QMacToolButton *)addStandardItem:(QMacToolButton::StandardItem) standardItem
-{
- QMacToolButton *button = new QMacToolButton(0);
- button->setStandardItem(standardItem);
- items.append(button);
- allowedItems.append(button);
- return button;
-}
-
-- (QMacToolButton *)addAllowedActionWithText:(const QString *)text
-{
- QIcon nullIcon;
- return [self addAllowedActionWithText:text icon:&nullIcon];
-}
-
-- (QMacToolButton *)addAllowedActionWithText:(const QString *)text icon:(const QIcon *)icon
-{
- QMacToolButton *button = new QMacToolButton(0);
- button->setText(*text);
- button->setIcon(*icon);
- allowedItems.append(button);
- return button;
-}
-
-- (QMacToolButton *)addAllowedStandardItem:(QMacToolButton::StandardItem)standardItem
-{
- QMacToolButton *button = new QMacToolButton(0);
- button->setStandardItem(standardItem);
- allowedItems.append(button);
- return button;
-}
-
-
@end
diff --git a/src/macextras/qmactoolbardelegate_p.h b/src/macextras/qmactoolbardelegate_p.h
index 8c71804..73976e3 100644
--- a/src/macextras/qmactoolbardelegate_p.h
+++ b/src/macextras/qmactoolbardelegate_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -43,32 +43,22 @@
#define QMACTOOLBARDELEGATE_H
#import <AppKit/AppKit.h>
-#include "qmactoolbutton_p.h"
+#include "qmactoolbar.h"
+#include "qmactoolbar_p.h"
#include <QtCore/qglobal.h>
#include <private/qcore_mac_p.h>
-#include <QtGui/QIcon>
@interface QT_MANGLE_NAMESPACE(QMacToolbarDelegate) : NSObject <NSToolbarDelegate>
{
@public
- QList<QMacToolButton *> items;
- QList<QMacToolButton *> allowedItems;
+ QMacToolBarPrivate *toolbarPrivate;
}
-- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted;
+- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar;
-
-- (QMacToolButton *)addActionWithText:(const QString *)text;
-- (QMacToolButton *)addActionWithText:(const QString *)text icon:(const QIcon *)icon;
-- (QMacToolButton *)addStandardItem:(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_p.h b/src/macextras/qmactoolbaritem.h
index 584b391..0efddb4 100644
--- a/src/macextras/qmactoolbutton_p.h
+++ b/src/macextras/qmactoolbaritem.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -39,16 +39,21 @@
**
****************************************************************************/
-#ifndef QMACTOOLBUTTON_H
-#define QMACTOOLBUTTON_H
+#ifndef QMACTOOLBARITEM_H
+#define QMACTOOLBARITEM_H
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtGui/QIcon>
+#include "qmacextrasglobal.h"
+
+Q_FORWARD_DECLARE_OBJC_CLASS(NSToolbarItem);
+
QT_BEGIN_NAMESPACE
-class QMacToolButton : public QObject
+class QMacToolBarItemPrivate;
+class Q_MACEXTRAS_EXPORT QMacToolBarItem : public QObject
{
Q_OBJECT
Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
@@ -56,27 +61,17 @@ class QMacToolButton : public QObject
Q_PROPERTY(QString text READ text WRITE setText)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_ENUMS(StandardItem)
+
public:
enum StandardItem
{
- NoItem,
- ShowColors,
- ShowFonts,
- PrintItem,
+ NoStandardItem,
Space,
FlexibleSpace
};
- enum IconSize
- {
- IconSizeDefault,
- IconSizeRegular,
- IconSizeSmall
- };
-
- QMacToolButton();
- QMacToolButton(QObject *parent);
- virtual ~QMacToolButton();
+ QMacToolBarItem(QObject *parent = 0);
+ virtual ~QMacToolBarItem();
bool selectable() const;
void setSelectable(bool selectable);
@@ -89,16 +84,14 @@ public:
QIcon icon() const;
void setIcon(const QIcon &icon);
+
+ NSToolbarItem *nativeToolBarItem() const;
+
Q_SIGNALS:
void activated();
private:
- bool m_selectable;
- StandardItem m_standardItem;
- QString m_text;
- QIcon m_icon;
-
-public: // (not really public)
- void emitActivated() { Q_EMIT activated(); }
+ friend class QMacToolBarPrivate;
+ Q_DECLARE_PRIVATE(QMacToolBarItem)
};
QT_END_NAMESPACE
diff --git a/src/macextras/qmactoolbaritem.mm b/src/macextras/qmactoolbaritem.mm
new file mode 100644
index 0000000..6e9b569
--- /dev/null
+++ b/src/macextras/qmactoolbaritem.mm
@@ -0,0 +1,241 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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$
+**
+****************************************************************************/
+
+#include "qmactoolbaritem.h"
+#include "qmactoolbaritem_p.h"
+#include "qmacfunctions.h"
+#include "qmacfunctions_p.h"
+#include "qmactoolbar_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QMacToolBarItem
+ \inmodule QtMacExtras
+ \since 5.3
+ \brief The QMacToolBarItem class provides an item for QMacToolBar.
+
+ All items should have the text and icon properites set, or have the
+ standardItem property set to something else than NoStandardItem.
+
+ \sa QMacToolBar
+*/
+
+/*!
+ \enum QMacToolBarItem::StandardItem
+ \value NoStandardItem Don't use a standard item
+ \value Space A spacing item
+ \value FlexibleSpace A spacing item which grows to fill available space
+*/
+
+
+/*!
+ Constructs a QMacToolBarItem with \a parent.
+*/
+QMacToolBarItem::QMacToolBarItem(QObject *parent)
+ :QObject(*new QMacToolBarItemPrivate, parent)
+{
+ Q_D(QMacToolBarItem);
+ d->initNativeToolbarItem();
+}
+
+/*!
+ Destroys a QMacToolBarItem
+*/
+QMacToolBarItem::~QMacToolBarItem()
+{
+
+}
+
+/*!
+ \property QMacToolBarItem::selectable
+ \brief Whether the item is selecatble
+
+ This property's default is false.
+*/
+bool QMacToolBarItem::selectable() const
+{
+ Q_D(const QMacToolBarItem);
+ return d->selectable;
+}
+
+void QMacToolBarItem::setSelectable(bool selectable)
+{
+ Q_D(QMacToolBarItem);
+ d->selectable = selectable;
+}
+
+/*!
+ \property QMacToolBarItem::standardItem
+ \brief Whether the item is a standard item.
+
+ This property's default is NoStandardItem, in which case the icon and text
+ property determines the item contents.
+
+ Setting this property to somthing else than NoStandardItem takes precendense
+ over icon and text.
+*/
+QMacToolBarItem::StandardItem QMacToolBarItem::standardItem() const
+{
+ Q_D(const QMacToolBarItem);
+ return d->standardItem;
+}
+
+void QMacToolBarItem::setStandardItem(StandardItem standardItem)
+{
+ Q_D(QMacToolBarItem);
+
+ if (d->standardItem == standardItem)
+ return;
+
+ d->standardItem = standardItem;
+ d->initNativeToolbarItem();
+}
+
+/*!
+ \property QMacToolBarItem::text
+ \brief The item's text.
+*/
+QString QMacToolBarItem::text() const
+{
+ Q_D(const QMacToolBarItem);
+ return d->text;
+}
+
+void QMacToolBarItem::setText(const QString &text)
+{
+ Q_D(QMacToolBarItem);
+ d->text = text;
+
+ if (d->standardItem != QMacToolBarItem::NoStandardItem)
+ return;
+
+ [d->toolbarItem setLabel:text.toNSString()];
+}
+
+/*!
+ \property QMacToolBarItem::icon
+ \brief The item's icon.
+*/
+QIcon QMacToolBarItem::icon() const
+{
+ Q_D(const QMacToolBarItem);
+ return d->icon;
+}
+
+void QMacToolBarItem::setIcon(const QIcon &icon)
+{
+ Q_D(QMacToolBarItem);
+ d->icon = icon;
+ QPixmap pixmap = icon.pixmap(64, 64);
+
+ if (d->standardItem != QMacToolBarItem::NoStandardItem)
+ return;
+
+ if (pixmap.isNull() == false) {
+ [d->toolbarItem setImage: QtMac::toNSImage(pixmap)];
+ }
+}
+
+/*!
+ Returns the native NSToolbarItem.
+*/
+NSToolbarItem *QMacToolBarItem::nativeToolBarItem() const
+{
+ Q_D(const QMacToolBarItem);
+ return d->toolbarItem;
+}
+
+/*!
+ \fn void QMacToolBarItem::activated();
+
+ This signal is emitted when the toolbar item is clicked or otherwise activated.
+*/
+
+QMacToolBarItemPrivate::QMacToolBarItemPrivate()
+{
+ standardItem = QMacToolBarItem::NoStandardItem;
+ selectable = false;
+ toolbarItem = 0;
+}
+
+QMacToolBarItemPrivate::~QMacToolBarItemPrivate()
+{
+ [toolbarItem release];
+}
+
+NSString *QMacToolBarItemPrivate::toNSStandardItem(QMacToolBarItem::StandardItem standardItem)
+{
+ /*
+ ### not supported yet; Qt does not handle the action
+ messages these send.
+
+ if (standardItem == QMacToolBarItem::ShowColors)
+ return NSToolbarShowColorsItemIdentifier;
+ else if (standardItem == QMacToolBarItem::ShowFonts)
+ return NSToolbarShowFontsItemIdentifier;
+ else if (standardItem == QMacToolBarItem::PrintItem)
+ return NSToolbarPrintItemIdentifier;
+ else
+*/
+ if (standardItem == QMacToolBarItem::Space)
+ return NSToolbarSpaceItemIdentifier;
+ else if (standardItem == QMacToolBarItem::FlexibleSpace)
+ return NSToolbarFlexibleSpaceItemIdentifier;
+ return @"";
+}
+
+NSString *QMacToolBarItemPrivate::itemIdentifier() const
+{
+ if (standardItem == QMacToolBarItem::NoStandardItem)
+ return QString::number(qulonglong(q_func())).toNSString();
+
+ return toNSStandardItem(standardItem);
+}
+
+// Initializes the NSToolBarItem based on QMacToolBarItem properties.
+void QMacToolBarItemPrivate::initNativeToolbarItem()
+{
+ NSString *identifier = itemIdentifier();
+ toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:identifier];
+}
+
+QT_END_NAMESPACE
diff --git a/src/macextras/qmactoolbaritem_p.h b/src/macextras/qmactoolbaritem_p.h
new file mode 100644
index 0000000..975bf95
--- /dev/null
+++ b/src/macextras/qmactoolbaritem_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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 QMACTOOLBARITEM_P_H
+#define QMACTOOLBARITEM_P_H
+
+#undef slots
+#import <AppKit/AppKit.h>
+
+#include <QtCore/private/qobject_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QMacToolBarItem;
+class QMacToolBarItemPrivate : public QObjectPrivate
+{
+public:
+ QMacToolBarItemPrivate();
+ ~QMacToolBarItemPrivate();
+ static NSString *toNSStandardItem(QMacToolBarItem::StandardItem standardItem);
+ NSString *itemIdentifier() const;
+ void initNativeToolbarItem();
+
+ bool selectable;
+ QMacToolBarItem::StandardItem standardItem;
+ QString text;
+ QIcon icon;
+ NSToolbarItem *toolbarItem;
+ Q_DECLARE_PUBLIC(QMacToolBarItem)
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/tests/manual/mactoolbar/mactoolbar.pro b/tests/manual/mactoolbar/mactoolbar.pro
new file mode 100644
index 0000000..ff1fe0d
--- /dev/null
+++ b/tests/manual/mactoolbar/mactoolbar.pro
@@ -0,0 +1,5 @@
+QT += macextras widgets
+
+HEADERS += toolbarcontrollerwidget.h
+SOURCES += toolbarcontrollerwidget.cpp main.cpp
+RESOURCES += mactoolbar.qrc
diff --git a/tests/manual/mactoolbar/mactoolbar.qrc b/tests/manual/mactoolbar/mactoolbar.qrc
new file mode 100644
index 0000000..04a9419
--- /dev/null
+++ b/tests/manual/mactoolbar/mactoolbar.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>qtlogo.png</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/mactoolbar/main.cpp b/tests/manual/mactoolbar/main.cpp
new file mode 100644
index 0000000..df72002
--- /dev/null
+++ b/tests/manual/mactoolbar/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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$
+**
+****************************************************************************/
+
+#include "toolbarcontrollerwidget.h"
+
+#include <QtGui/QGuiApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ ToolBarControllerWidget toolbarControllerWidget;
+ toolbarControllerWidget.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/mactoolbar/qtlogo.png b/tests/manual/mactoolbar/qtlogo.png
new file mode 100644
index 0000000..d75936b
--- /dev/null
+++ b/tests/manual/mactoolbar/qtlogo.png
Binary files differ
diff --git a/tests/manual/mactoolbar/toolbarcontrollerwidget.cpp b/tests/manual/mactoolbar/toolbarcontrollerwidget.cpp
new file mode 100644
index 0000000..09148a8
--- /dev/null
+++ b/tests/manual/mactoolbar/toolbarcontrollerwidget.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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$
+**
+****************************************************************************/
+
+#include "toolbarcontrollerwidget.h"
+
+ToolBarControllerWidget::ToolBarControllerWidget()
+ :QWidget(0)
+{
+
+ setWindowTitle("QMacToolBar Test");
+ resize(400, 200);
+
+ QMacToolBar *toolBar = new QMacToolBar(this);
+
+ QIcon qtIcon(QStringLiteral(":qtlogo.png"));
+ fooItem = toolBar->addItem(qtIcon, QStringLiteral("Foo"));
+ fooItem->setText("foo");
+
+ connect(fooItem, SIGNAL(activated()), this, SLOT(activated()));
+
+ QMacToolBarItem *item5 = toolBar->addAllowedItem(qtIcon, QStringLiteral("AllowedFoo"));
+ connect(item5, SIGNAL(activated()), this, SLOT(activated()));
+
+ QLineEdit *fooItemText = new QLineEdit(this);
+ fooItemText->setText("Foo");
+ fooItemText->move(10, 10);
+ connect(fooItemText, SIGNAL(textChanged(const QString &)), this, SLOT(changeItemText(const QString &)));
+
+ winId();
+ toolBar->attachToWindow(windowHandle());
+}
+
+void ToolBarControllerWidget::activated()
+{
+ qDebug() << "activated" << sender();
+}
+
+void ToolBarControllerWidget::changeItemText(const QString &text)
+{
+ fooItem->setText(text);
+}
diff --git a/tests/manual/mactoolbar/toolbarcontrollerwidget.h b/tests/manual/mactoolbar/toolbarcontrollerwidget.h
new file mode 100644
index 0000000..c949c85
--- /dev/null
+++ b/tests/manual/mactoolbar/toolbarcontrollerwidget.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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$
+**
+****************************************************************************/
+
+#include <QtCore/qdebug.h>
+#include <QtWidgets>
+#include <QtMacExtras/QMacToolBar>
+
+class ToolBarControllerWidget : public QWidget
+{
+Q_OBJECT
+public:
+ ToolBarControllerWidget();
+public Q_SLOTS:
+ void activated();
+ void changeItemText(const QString &);
+private:
+ QVBoxLayout *layout;
+ QMacToolBarItem *fooItem;
+};
+