From 24d45304aa363c9a08f7157d549cb37c07212108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 18 Sep 2013 12:07:45 +0200 Subject: 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 --- examples/embeddedqwindow/main.mm | 5 +- examples/examples.pro | 5 +- examples/macfunctions/main.cpp | 10 +- examples/macpasteboardmime/macpasteboardmime.pro | 2 +- examples/macunifiedtoolbar/macunifiedtoolbar.pro | 20 -- examples/macunifiedtoolbar/macunifiedtoolbar.qrc | 5 - examples/macunifiedtoolbar/main.cpp | 52 ----- examples/macunifiedtoolbar/preferenceswindow.cpp | 101 ---------- examples/macunifiedtoolbar/preferenceswindow.h | 65 ------- examples/macunifiedtoolbar/preferenceswindow.ui | 209 --------------------- examples/macunifiedtoolbar/qtlogo.icns | Bin 129539 -> 0 bytes examples/macunifiedtoolbar/qtlogo.png | Bin 1478 -> 0 bytes examples/macunifiedtoolbar/window.cpp | 140 -------------- examples/macunifiedtoolbar/window.h | 72 ------- examples/macunifiedtoolbar/window.ui | 151 --------------- examples/qmaccocoaviewcontainer/main.mm | 67 ------- .../qmaccocoaviewcontainer.pro | 7 - examples/qmacnativewidget/main.mm | 137 -------------- examples/qmacnativewidget/qmacnativewidget.pro | 7 - src/macextras/macextras-lib.pri | 10 +- src/macextras/macextras.pro | 1 - src/macextras/qmaccocoaviewcontainer.h | 70 ------- src/macextras/qmaccocoaviewcontainer.mm | 166 ---------------- src/macextras/qmacextrasglobal.h | 2 + src/macextras/qmacfunctions.h | 25 +-- src/macextras/qmacfunctions.mm | 5 +- src/macextras/qmacfunctions_ios.mm | 1 + src/macextras/qmacfunctions_mac.mm | 61 ------ src/macextras/qmacfunctions_p.h | 14 ++ src/macextras/qmacnativetoolbar.h | 154 --------------- src/macextras/qmacnativetoolbar.mm | 157 +++------------- src/macextras/qmacnativetoolbar_p.h | 139 ++++++++++++++ src/macextras/qmacnativewidget.h | 72 ------- src/macextras/qmacnativewidget.mm | 148 --------------- src/macextras/qmacpasteboardmime.mm | 5 +- src/macextras/qmactoolbardelegate.mm | 85 ++++----- src/macextras/qmactoolbardelegate_p.h | 27 +-- src/macextras/qmactoolbutton.h | 96 ---------- src/macextras/qmactoolbutton.mm | 33 ++-- src/macextras/qmactoolbutton_p.h | 106 +++++++++++ tests/auto/auto.pro | 3 +- tests/auto/macfunctions/tst_qmacfunctions.mm | 30 +-- 42 files changed, 371 insertions(+), 2094 deletions(-) delete mode 100644 examples/macunifiedtoolbar/macunifiedtoolbar.pro delete mode 100644 examples/macunifiedtoolbar/macunifiedtoolbar.qrc delete mode 100644 examples/macunifiedtoolbar/main.cpp delete mode 100644 examples/macunifiedtoolbar/preferenceswindow.cpp delete mode 100644 examples/macunifiedtoolbar/preferenceswindow.h delete mode 100644 examples/macunifiedtoolbar/preferenceswindow.ui delete mode 100644 examples/macunifiedtoolbar/qtlogo.icns delete mode 100644 examples/macunifiedtoolbar/qtlogo.png delete mode 100644 examples/macunifiedtoolbar/window.cpp delete mode 100644 examples/macunifiedtoolbar/window.h delete mode 100644 examples/macunifiedtoolbar/window.ui delete mode 100644 examples/qmaccocoaviewcontainer/main.mm delete mode 100644 examples/qmaccocoaviewcontainer/qmaccocoaviewcontainer.pro delete mode 100644 examples/qmacnativewidget/main.mm delete mode 100644 examples/qmacnativewidget/qmacnativewidget.pro delete mode 100644 src/macextras/qmaccocoaviewcontainer.h delete mode 100644 src/macextras/qmaccocoaviewcontainer.mm delete mode 100644 src/macextras/qmacnativetoolbar.h create mode 100644 src/macextras/qmacnativetoolbar_p.h delete mode 100644 src/macextras/qmacnativewidget.h delete mode 100644 src/macextras/qmacnativewidget.mm delete mode 100644 src/macextras/qmactoolbutton.h create mode 100644 src/macextras/qmactoolbutton_p.h diff --git a/examples/embeddedqwindow/main.mm b/examples/embeddedqwindow/main.mm index 810d789..f24533b 100644 --- a/examples/embeddedqwindow/main.mm +++ b/examples/embeddedqwindow/main.mm @@ -39,15 +39,14 @@ ** ****************************************************************************/ +#include + #include "window.h" #include #include -#include - - NSView *getEmbeddableView(QWindow *qtWindow) { // Make sure the platform window is created diff --git a/examples/examples.pro b/examples/examples.pro index 891e3d6..8fe1d13 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -2,7 +2,4 @@ TEMPLATE = subdirs mac:SUBDIRS = macfunctions mac:!ios:SUBDIRS += embeddedqwindow \ - macpasteboardmime \ - macunifiedtoolbar \ - qmaccocoaviewcontainer \ - qmacnativewidget \ + macpasteboardmime diff --git a/examples/macfunctions/main.cpp b/examples/macfunctions/main.cpp index de77b08..a1563ba 100644 --- a/examples/macfunctions/main.cpp +++ b/examples/macfunctions/main.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ -#include +#include #include #include #include @@ -48,17 +48,11 @@ int main(int argc, char **argv) { - QApplication app(argc, argv); + QGuiApplication app(argc, argv); QWidget widget; widget.show(); - // Dock menu - QMenu menu; - menu.addAction("Item 1"); - menu.addAction("Item 2"); - QtMac::setDockMenu(&menu); - // Pixmap <-> CGImage conversion QPixmap pixmap(":qtlogo.png"); CGImageRef cgImage = QtMac::toCGImageRef(pixmap); diff --git a/examples/macpasteboardmime/macpasteboardmime.pro b/examples/macpasteboardmime/macpasteboardmime.pro index 9869637..3ce4cd4 100644 --- a/examples/macpasteboardmime/macpasteboardmime.pro +++ b/examples/macpasteboardmime/macpasteboardmime.pro @@ -1,4 +1,4 @@ -QT += macextras +QT += macextras widgets SOURCES += main.cpp diff --git a/examples/macunifiedtoolbar/macunifiedtoolbar.pro b/examples/macunifiedtoolbar/macunifiedtoolbar.pro deleted file mode 100644 index c13f714..0000000 --- a/examples/macunifiedtoolbar/macunifiedtoolbar.pro +++ /dev/null @@ -1,20 +0,0 @@ -QT += core gui macextras -greaterThan(QT_MAJOR_VERSION, 4):QT += widgets - -SOURCES += \ - main.cpp \ - preferenceswindow.cpp \ - window.cpp - -HEADERS += \ - preferenceswindow.h \ - window.h - -FORMS += \ - preferenceswindow.ui \ - window.ui - -RESOURCES += \ - macunifiedtoolbar.qrc - -ICON = qtlogo.icns diff --git a/examples/macunifiedtoolbar/macunifiedtoolbar.qrc b/examples/macunifiedtoolbar/macunifiedtoolbar.qrc deleted file mode 100644 index 04a9419..0000000 --- a/examples/macunifiedtoolbar/macunifiedtoolbar.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - qtlogo.png - - diff --git a/examples/macunifiedtoolbar/main.cpp b/examples/macunifiedtoolbar/main.cpp deleted file mode 100644 index 9b764c7..0000000 --- a/examples/macunifiedtoolbar/main.cpp +++ /dev/null @@ -1,52 +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$ -** -****************************************************************************/ - -#include -#include "window.h" - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - Window window; - window.show(); - return app.exec(); -} - diff --git a/examples/macunifiedtoolbar/preferenceswindow.cpp b/examples/macunifiedtoolbar/preferenceswindow.cpp deleted file mode 100644 index 4991023..0000000 --- a/examples/macunifiedtoolbar/preferenceswindow.cpp +++ /dev/null @@ -1,101 +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$ -** -****************************************************************************/ - -#include "preferenceswindow.h" -#include -#include - -PreferencesWindow::PreferencesWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::PreferencesWindow) -{ - ui->setupUi(this); - - // Ensure we can only select one 'tab' at a time - QActionGroup *items = new QActionGroup(this); - foreach (QAction *action, ui->toolBar->actions()) - items->addAction(action); - - // This single line of code is all that's needed to transform a QToolBar into a native toolbar! - QtMac::setNativeToolBar(ui->toolBar, ui->useNativeToolbarCheckBox->isChecked()); - - QTimer::singleShot(0, this, SLOT(pack())); -} - -PreferencesWindow::~PreferencesWindow() -{ - delete ui; -} - -void PreferencesWindow::toolbarItemTriggered() -{ - QAction *action = qobject_cast(sender()); - if (action) - { - setWindowTitle(action->text()); - } - - if (sender() == ui->actionGeneral) - { - ui->stackedWidget->setCurrentWidget(ui->generalPage); - } - else if (sender() == ui->actionNetwork) - { - ui->stackedWidget->setCurrentWidget(ui->networkPage); - } - else if (sender() == ui->actionAdvanced) - { - ui->stackedWidget->setCurrentWidget(ui->advancedPage); - } - - QTimer::singleShot(0, this, SLOT(pack())); -} - -void PreferencesWindow::useNativeToolBarToggled(bool on) -{ - QtMac::setNativeToolBar(ui->toolBar, on); - QTimer::singleShot(0, this, SLOT(pack())); -} - -void PreferencesWindow::pack() -{ - resize(QSize()); -} diff --git a/examples/macunifiedtoolbar/preferenceswindow.h b/examples/macunifiedtoolbar/preferenceswindow.h deleted file mode 100644 index 0accb83..0000000 --- a/examples/macunifiedtoolbar/preferenceswindow.h +++ /dev/null @@ -1,65 +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 PREFERENCESWINDOW_H -#define PREFERENCESWINDOW_H - -#include -#include "ui_preferenceswindow.h" - -class PreferencesWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit PreferencesWindow(QWidget *parent = 0); - ~PreferencesWindow(); - -private slots: - void toolbarItemTriggered(); - void useNativeToolBarToggled(bool); - void pack(); - -private: - Ui::PreferencesWindow *ui; -}; - -#endif // PREFERENCESWINDOW_H diff --git a/examples/macunifiedtoolbar/preferenceswindow.ui b/examples/macunifiedtoolbar/preferenceswindow.ui deleted file mode 100644 index 7f3ef00..0000000 --- a/examples/macunifiedtoolbar/preferenceswindow.ui +++ /dev/null @@ -1,209 +0,0 @@ - - - PreferencesWindow - - - - 0 - 0 - 400 - 300 - - - - Preferences - - - - - - - Use native NSToolbar - - - true - - - - - - - - - - - General preferences would go here - - - Qt::AlignCenter - - - - - - - - - - - Network preferences would go here - - - Qt::AlignCenter - - - - - - - - - - - Advanced preferences would go here - - - Qt::AlignCenter - - - - - - - - - - - - false - - - Qt::ToolButtonTextUnderIcon - - - false - - - TopToolBarArea - - - false - - - - - - - - true - - - true - - - - :/qtlogo.png:/qtlogo.png - - - General - - - - - true - - - - :/qtlogo.png:/qtlogo.png - - - Network - - - - - true - - - - :/qtlogo.png:/qtlogo.png - - - Advanced - - - - - - - - - actionGeneral - triggered() - PreferencesWindow - toolbarItemTriggered() - - - -1 - -1 - - - 399 - 299 - - - - - actionNetwork - triggered() - PreferencesWindow - toolbarItemTriggered() - - - -1 - -1 - - - 399 - 299 - - - - - actionAdvanced - triggered() - PreferencesWindow - toolbarItemTriggered() - - - -1 - -1 - - - 399 - 299 - - - - - useNativeToolbarCheckBox - toggled(bool) - PreferencesWindow - useNativeToolBarToggled(bool) - - - 61 - 87 - - - 199 - 149 - - - - - - toolbarItemTriggered() - useNativeToolBarToggled(bool) - - diff --git a/examples/macunifiedtoolbar/qtlogo.icns b/examples/macunifiedtoolbar/qtlogo.icns deleted file mode 100644 index def5f0e..0000000 Binary files a/examples/macunifiedtoolbar/qtlogo.icns and /dev/null differ diff --git a/examples/macunifiedtoolbar/qtlogo.png b/examples/macunifiedtoolbar/qtlogo.png deleted file mode 100644 index d75936b..0000000 Binary files a/examples/macunifiedtoolbar/qtlogo.png and /dev/null differ diff --git a/examples/macunifiedtoolbar/window.cpp b/examples/macunifiedtoolbar/window.cpp deleted file mode 100644 index dde27e3..0000000 --- a/examples/macunifiedtoolbar/window.cpp +++ /dev/null @@ -1,140 +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$ -** -****************************************************************************/ - -#include "window.h" -#include "preferenceswindow.h" -#include -#include -#include -#include - -class WindowPrivate -{ -public: - PreferencesWindow *preferencesWindow; - QMenuBar *mainMenuBar; - QMacNativeToolBar *toolBar; -}; - -Window::Window(QWidget *parent) : - QWidget(parent), - d(new WindowPrivate), - ui(new Ui::Window) -{ - ui->setupUi(this); - - d->preferencesWindow = new PreferencesWindow(); - - d->mainMenuBar = new QMenuBar(); - QMenu *toolsMenu = d->mainMenuBar->addMenu("Tools"); - toolsMenu->addAction("Options", d->preferencesWindow, SLOT(show())); - - d->toolBar = new QMacNativeToolBar(this); - d->toolBar->addAction(QIcon(":/qtlogo.png"), "Hello"); - d->toolBar->addAction(QIcon(":/qtlogo.png"), "World"); - d->toolBar->addStandardItem(QMacToolButton::FlexibleSpace); - d->toolBar->addStandardItem(QMacToolButton::ShowColors); - d->toolBar->addStandardItem(QMacToolButton::ShowFonts); - d->toolBar->addStandardItem(QMacToolButton::PrintItem); - - d->toolBar->addAllowedAction(QIcon(":/qtlogo.png"), "Extra Button 1"); - d->toolBar->addAllowedAction(QIcon(":/qtlogo.png"), "Extra Button 2"); - - d->toolBar->showInWindowForWidget(this); - - connect(d->toolBar, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), SLOT(displayModeChanged(Qt::ToolButtonStyle))); - ui->displayModeComboBox->setCurrentIndex(d->toolBar->toolButtonStyle()); - - connect(d->toolBar, SIGNAL(iconSizeChanged(QMacToolButton::IconSize)), SLOT(sizeModeChanged(QMacToolButton::IconSize))); - ui->sizeModeComboBox->setCurrentIndex(d->toolBar->iconSizeType()); - - connect(ui->visibleCheckBox, SIGNAL(clicked(bool)), d->toolBar, SLOT(setVisible(bool))); - connect(d->toolBar, SIGNAL(visibilityChanged(bool)), ui->visibleCheckBox, SLOT(setChecked(bool))); - ui->visibleCheckBox->setChecked(d->toolBar->isVisible()); - - connect(ui->showsBaselineSeparatorCheckBox, SIGNAL(clicked(bool)), d->toolBar, SLOT(setShowsBaselineSeparator(bool))); - connect(d->toolBar, SIGNAL(showsBaselineSeparatorChanged(bool)), ui->showsBaselineSeparatorCheckBox, SLOT(setChecked(bool))); - ui->showsBaselineSeparatorCheckBox->setChecked(d->toolBar->showsBaselineSeparator()); - - connect(ui->allowsUserCustomizationCheckBox, SIGNAL(clicked(bool)), d->toolBar, SLOT(setAllowsUserCustomization(bool))); - connect(d->toolBar, SIGNAL(allowsUserCustomizationChanged(bool)), ui->allowsUserCustomizationCheckBox, SLOT(setChecked(bool))); - ui->allowsUserCustomizationCheckBox->setChecked(d->toolBar->allowsUserCustomization()); - - connect(ui->showCustomizationSheetPushButton, SIGNAL(clicked()), d->toolBar, SLOT(showCustomizationSheet())); - connect(d->toolBar, SIGNAL(allowsUserCustomizationChanged(bool)), ui->showCustomizationSheetPushButton, SLOT(setEnabled(bool))); - ui->showCustomizationSheetPushButton->setEnabled(d->toolBar->allowsUserCustomization()); - - QTimer::singleShot(0, this, SLOT(positionWindow())); -} - -Window::~Window() -{ - delete ui; - delete d->mainMenuBar; - delete d->preferencesWindow; - delete d; -} - -void Window::changeDisplayMode(int toolButtonStyle) -{ - d->toolBar->setToolButtonStyle(static_cast(toolButtonStyle)); -} - -void Window::displayModeChanged(Qt::ToolButtonStyle toolButtonStyle) -{ - ui->displayModeComboBox->setCurrentIndex(toolButtonStyle); -} - -void Window::changeSizeMode(int sizeMode) -{ - d->toolBar->setIconSize(static_cast(sizeMode)); -} - -void Window::sizeModeChanged(QMacToolButton::IconSize size) -{ - ui->sizeModeComboBox->setCurrentIndex(size); -} - -void Window::positionWindow() -{ - resize(QSize()); - setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, size(), qApp->desktop()->availableGeometry())); -} diff --git a/examples/macunifiedtoolbar/window.h b/examples/macunifiedtoolbar/window.h deleted file mode 100644 index 7f0dc54..0000000 --- a/examples/macunifiedtoolbar/window.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 WINDOW_H -#define WINDOW_H - -#include -#include "qmactoolbutton.h" -#include "ui_window.h" - -class WindowPrivate; -class Window : public QWidget -{ - Q_OBJECT - -public: - explicit Window(QWidget *parent = 0); - ~Window(); - -private slots: - void changeDisplayMode(int); - void displayModeChanged(Qt::ToolButtonStyle); - - void changeSizeMode(int); - void sizeModeChanged(QMacToolButton::IconSize); - - void positionWindow(); - -private: - WindowPrivate *d; - Ui::Window *ui; -}; - -#endif // WINDOW_H diff --git a/examples/macunifiedtoolbar/window.ui b/examples/macunifiedtoolbar/window.ui deleted file mode 100644 index 90081a0..0000000 --- a/examples/macunifiedtoolbar/window.ui +++ /dev/null @@ -1,151 +0,0 @@ - - - Window - - - - 0 - 0 - 265 - 173 - - - - Qt Mac Toolbar Example - - - - QFormLayout::FieldsStayAtSizeHint - - - - - Display mode: - - - - - - - - IconOnly - - - - - TextOnly - - - - - TextBesideIcon - - - - - TextUnderIcon - - - - - FollowStyle - - - - - - - - Size mode: - - - - - - - - Default - - - - - Regular - - - - - Small - - - - - - - - Visible - - - - - - - Shows baseline separator - - - - - - - Allows user customization - - - - - - - Show customization sheet - - - - - - - - - displayModeComboBox - currentIndexChanged(int) - Window - changeDisplayMode(int) - - - 337 - 22 - - - 288 - 149 - - - - - sizeModeComboBox - currentIndexChanged(int) - Window - changeSizeMode(int) - - - 158 - 52 - - - 132 - 86 - - - - - - changeDisplayMode(int) - changeSizeMode(int) - - diff --git a/examples/qmaccocoaviewcontainer/main.mm b/examples/qmaccocoaviewcontainer/main.mm deleted file mode 100644 index e8ebc23..0000000 --- a/examples/qmaccocoaviewcontainer/main.mm +++ /dev/null @@ -1,67 +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$ -** -****************************************************************************/ - -#include -#include -#include - -class WindowWidget : public QWidget -{ -public: - WindowWidget() - { - QMacCocoaViewContainer *cocoaViewContainer = new QMacCocoaViewContainer(0, this); - cocoaViewContainer->move(100, 100); - cocoaViewContainer->resize(300, 300); - NSTextView *text = [[NSTextView alloc] initWithFrame : NSMakeRect(0, 0, 300, 300)]; - cocoaViewContainer->setCocoaView(text); - } -}; - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - WindowWidget widget; - widget.show(); - - return app.exec(); -} diff --git a/examples/qmaccocoaviewcontainer/qmaccocoaviewcontainer.pro b/examples/qmaccocoaviewcontainer/qmaccocoaviewcontainer.pro deleted file mode 100644 index 47b5de1..0000000 --- a/examples/qmaccocoaviewcontainer/qmaccocoaviewcontainer.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = app - -OBJECTIVE_SOURCES += main.mm -LIBS += -framework Cocoa - -QT += gui widgets macextras - diff --git a/examples/qmacnativewidget/main.mm b/examples/qmacnativewidget/main.mm deleted file mode 100644 index 22d0957..0000000 --- a/examples/qmacnativewidget/main.mm +++ /dev/null @@ -1,137 +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 test suite 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class RedWidget : public QWidget -{ -public: - RedWidget() { - - } - - void resizeEvent(QResizeEvent *) - { - qDebug() << "RedWidget::resize" << size(); - } - - void paintEvent(QPaintEvent *event) - { - QPainter p(this); - Q_UNUSED(event); - QRect rect(QPoint(0, 0), size()); - qDebug() << "Painting geometry" << rect; - p.fillRect(rect, QColor(133, 50, 50)); - } -}; - -@interface WindowCreator : NSObject {} -- (void)createWindow; -@end - -@implementation WindowCreator -- (void)createWindow { - - // Create the NSWindow - NSRect frame = NSMakeRect(500, 500, 500, 500); - NSWindow* window = [[NSWindow alloc] initWithContentRect:frame - styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask - backing:NSBackingStoreBuffered - defer:NO]; - [window setTitle:@"NSWindow"]; - - // Create widget hierarchy with QPushButton and QLineEdit - QMacNativeWidget *nativeWidget = new QMacNativeWidget(); - - QHBoxLayout *hlayout = new QHBoxLayout(); - hlayout->addWidget(new QPushButton("Push", nativeWidget)); - hlayout->addWidget(new QLineEdit); - - QVBoxLayout *vlayout = new QVBoxLayout(); - vlayout->addLayout(hlayout); - - //RedWidget * redWidget = new RedWidget; - //vlayout->addWidget(redWidget); - - nativeWidget->setLayout(vlayout); - - // Get the NSView for QMacNativeWidget and set it as the content view for the NSWindow - [window setContentView:nativeWidget->nativeView()]; - - // show() must be called on nativeWiget to get the widgets int he correct state. - nativeWidget->show(); - - // Show the NSWindow - [window makeKeyAndOrderFront:NSApp]; -} -@end - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - // Start Cocoa. Create NSApplicaiton. - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - [NSApplication sharedApplication]; - - // Schedule call to create the UI using a zero timer. - WindowCreator *windowCreator= [WindowCreator alloc]; - [NSTimer scheduledTimerWithTimeInterval:0 target:windowCreator selector:@selector(createWindow) userInfo:nil repeats:NO]; - - // Stare the Cocoa event loop. - [(NSApplication *)NSApp run]; - [NSApp release]; - [pool release]; - exit(0); - return 0; -} - - - diff --git a/examples/qmacnativewidget/qmacnativewidget.pro b/examples/qmacnativewidget/qmacnativewidget.pro deleted file mode 100644 index df5f825..0000000 --- a/examples/qmacnativewidget/qmacnativewidget.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = app - -OBJECTIVE_SOURCES += main.mm -LIBS += -framework Cocoa - -QT += gui widgets macextras -QT += widgets-private gui-private core-private 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 - -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 - -#include "qmaccocoaviewcontainer.h" - -#include -#include - -/*! - \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(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 #include #include + +#include "qmacfunctions_p.h" + #import #ifdef Q_OS_IOS #import 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 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(reinterpret_cast(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(reinterpret_cast(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(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([reinterpret_cast(widget->window()->winId()) window]); - return [macWindow isMainWindow]; -#endif -} - CGContextRef currentCGContext() { return reinterpret_cast([[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 #include +// ### 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.h b/src/macextras/qmacnativetoolbar.h deleted file mode 100644 index 4c903cf..0000000 --- a/src/macextras/qmacnativetoolbar.h +++ /dev/null @@ -1,154 +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.h" - -#include -#include -#include -#include - -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 QMacNativeToolBarPrivate; -class Q_MACEXTRAS_EXPORT QMacNativeToolBar : public QObject -{ - friend class QMacNativeToolBarPrivate; - - Q_OBJECT - Q_PROPERTY(QList buttons READ buttons) - Q_PROPERTY(QList allowedButtons READ allowedButtons) -public: - QMacNativeToolBar(QObject *parent = 0); - QMacNativeToolBar(const QString &identifier, QObject *parent = 0); - ~QMacNativeToolBar(); - - NSToolbar* nativeToolbar() const; - - static QMacNativeToolBar* fromQToolBar(const QToolBar *toolBar, const QString &identifier = QString()); - - QString identifier() const; - bool isVisible() const; - bool showsBaselineSeparator() const; - bool allowsUserCustomization() const; - Qt::ToolButtonStyle toolButtonStyle() const; - QSize iconSize() const; - QMacToolButton::IconSize iconSizeType() const; - - QList buttons(); - QList 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 void addSeparator(); - Q_INVOKABLE QAction *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_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(); - QAction *setSelectedItem(QAction *action); - void checkSelectableItemSanity(); -private: - QWindow *targetWindow; - QWidget *targetWidget; - QList m_buttons; - QList m_allowedButtons; - QMacNativeToolBarPrivate *d; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QMacNativeToolBar*) - -#endif - 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 -#include "qmacfunctions.h" -#include "qmacnativetoolbar.h" -#include "qmactoolbardelegate_p.h" -#include "qnstoolbar_p.h" -#include -#include -#include -#include -#include -#include -#include +#include "qmacnativetoolbar_p.h" + +#include +#include +#include +#include #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include +#include #include #else -#include +#include #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(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()) { - macToolBar = toolBarProperty.value(); - } 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( QGuiApplication::platformNativeInterface()->nativeResourceForWindow("nswindow", targetWindow)); -#else - NSWindow *macWindow = reinterpret_cast([reinterpret_cast(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([reinterpret_cast(widget->winId()) window]); - [macWindow setToolbar:nil]; -} void QMacNativeToolBar::setSelectedItem() { - setSelectedItem(qobject_cast(sender())); +// setSelectedItem(qobject_cast(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 selectableActions; + QList 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_p.h b/src/macextras/qmacnativetoolbar_p.h new file mode 100644 index 0000000..fe15ea2 --- /dev/null +++ b/src/macextras/qmacnativetoolbar_p.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include + +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 buttons READ buttons) + Q_PROPERTY(QList 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 buttons(); + QList 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 m_buttons; + QList m_allowedButtons; + QMacNativeToolBarPrivate *d; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QMacNativeToolBar*) + +#endif + 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 - -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 -#include "qmacnativewidget.h" -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include -#include -#include -#endif -#include - - -/*! - \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(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(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 #include "qmacpasteboardmime.h" -#include -#include -#include +#include +#include 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 -#include -#include + +#include +#include + +#include "qmacfunctions.h" +#include "qmacfunctions_p.h" +#include "qmacnativetoolbar_p.h" QT_USE_NAMESPACE @@ -73,7 +76,7 @@ NSMutableArray *itemIdentifiers(const QList &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(sender); QString identifier = QtMac::fromNSString([item itemIdentifier]); QMacToolButton *toolButton = reinterpret_cast(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(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 -#include "qmactoolbutton.h" -//#include -//#include +#include "qmactoolbutton_p.h" -#include +#include #include - -#include -#include +#include @interface QT_MANGLE_NAMESPACE(QMacToolbarDelegate) : NSObject { @public QList items; QList allowedItems; - -// QHash actions; -// QHash 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.h b/src/macextras/qmactoolbutton.h deleted file mode 100644 index e63fefc..0000000 --- a/src/macextras/qmactoolbutton.h +++ /dev/null @@ -1,96 +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 QMACTOOLBUTTON_H -#define QMACTOOLBUTTON_H - -#include - -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_ENUMS(StandardItem) -public: - enum StandardItem - { - NoItem, - ShowColors, - ShowFonts, - PrintItem, - Space, - FlexibleSpace - }; - - enum IconSize - { - IconSizeDefault, - IconSizeRegular, - IconSizeSmall - }; - - QMacToolButton(); - QMacToolButton(QObject *parent); - virtual ~QMacToolButton(); - - bool selectable() const; - void setSelectable(bool selectable); - - StandardItem standardItem() const; - void setStandardItem(StandardItem standardItem); -Q_SIGNALS: - void activated(); -private: - bool m_selectable; - StandardItem m_standardItem; -public: // (not really public) - QAction *m_action; - void emitActivated() { Q_EMIT activated(); } -}; - -QT_END_NAMESPACE - -#endif 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 +#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_p.h b/src/macextras/qmactoolbutton_p.h new file mode 100644 index 0000000..584b391 --- /dev/null +++ b/src/macextras/qmactoolbutton_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 QMACTOOLBUTTON_H +#define QMACTOOLBUTTON_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +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 + { + NoItem, + ShowColors, + ShowFonts, + PrintItem, + Space, + FlexibleSpace + }; + + enum IconSize + { + IconSizeDefault, + IconSizeRegular, + IconSizeSmall + }; + + QMacToolButton(); + QMacToolButton(QObject *parent); + virtual ~QMacToolButton(); + + bool selectable() const; + void setSelectable(bool selectable); + + 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) + void emitActivated() { Q_EMIT activated(); } +}; + +QT_END_NAMESPACE + +#endif diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 915b01e..bfa2c7c 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs SUBDIRS = \ - cmake \ headersclean \ macfunctions +### FIXME Mac native toolbar is now private in this module +#SUBDIRS += cmake diff --git a/tests/auto/macfunctions/tst_qmacfunctions.mm b/tests/auto/macfunctions/tst_qmacfunctions.mm index f34ed25..591d1dd 100644 --- a/tests/auto/macfunctions/tst_qmacfunctions.mm +++ b/tests/auto/macfunctions/tst_qmacfunctions.mm @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#import #include #include @@ -47,47 +48,18 @@ #include #include -#import - class tst_QMacFunctions : public QObject { Q_OBJECT public: tst_QMacFunctions(); - -private slots: - void testToNSMenu(); }; tst_QMacFunctions::tst_QMacFunctions() { } -void tst_QMacFunctions::testToNSMenu() -{ - QMainWindow window; - QMenu *qMenu = new QMenu("Menu", &window); - QAction *action = new QAction("&Item", &window); - qMenu->addAction(action); - window.menuBar()->addMenu(qMenu); - - NSMenu *nsMenu = QtMac::toNSMenu(qMenu); - QVERIFY(nsMenu != NULL); - QCOMPARE([[nsMenu title] UTF8String], "Menu"); - - NSMenuItem *item = [nsMenu itemAtIndex:0]; - QCOMPARE([[item title] UTF8String], "Item"); - - // get NSMenu from QMenuBar - nsMenu = QtMac::toNSMenu(window.menuBar()); - QVERIFY(nsMenu != NULL); - - // the first item should be our menu - item = [nsMenu itemAtIndex:0]; - QCOMPARE([[item title] UTF8String], "Menu"); -} - QTEST_MAIN(tst_QMacFunctions) #include "tst_qmacfunctions.moc" -- cgit v1.2.3