summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorJames Turner <james.turner@kdab.com>2012-05-04 14:16:05 +0100
committerQt by Nokia <qt-info@nokia.com>2012-05-19 10:18:21 +0200
commitb8246f08e49eb672974fd3d3d972a5ff13c1524d (patch)
tree509ab759670f0b24aa8d44ced0584fc2832f5e76 /tests/manual
parent899f1d35a435fd499c73b29aabb6a609d496e5ed (diff)
Cocoa implementation of QPA menu interface.
Implement the QPA platform menu interface for Cocoa, including native menubar support and merging with the predefined menus created from the bundled .nib. Cleanup code previously used to maintain the menus, and add a manual test of the menus code. Change-Id: Ia99267ddb6485e18e05c540eb32c5aee6cbb85db Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/cocoa/menus/main.cpp201
-rw-r--r--tests/manual/cocoa/menus/menus.pro5
2 files changed, 206 insertions, 0 deletions
diff --git a/tests/manual/cocoa/menus/main.cpp b/tests/manual/cocoa/menus/main.cpp
new file mode 100644
index 0000000000..d695c6c138
--- /dev/null
+++ b/tests/manual/cocoa/menus/main.cpp
@@ -0,0 +1,201 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 KDAB
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtWidgets>
+
+
+class Responder : public QObject
+{
+ Q_OBJECT
+
+public:
+ Responder(QObject *pr) :
+ QObject(pr)
+ {
+ }
+
+public slots:
+
+
+ void toggleChecked(bool b)
+ {
+ QAction *a = qobject_cast<QAction *>(sender());
+ }
+
+ void showModalDialog()
+ {
+ QMessageBox::information(NULL, "Something", "Something happened. Modally.");
+ }
+
+ void doPreferences()
+ {
+ qDebug() << "show preferences";
+ }
+
+ void aboutToShowSubmenu()
+ {
+ QMenu* m = (QMenu*) sender();
+ qDebug() << "will show" << m;
+
+ m->clear();
+
+ for (int i=0; i<10; ++i) {
+ m->addAction(QString("Recent File %1").arg(i + 1));
+ }
+ }
+};
+
+void createWindow1()
+{
+
+ QMainWindow *window = new QMainWindow;
+ QMenu *menu = new QMenu("TestMenu", window);
+
+ window->menuBar()->addMenu(menu);
+
+ Responder *r = new Responder(window);
+
+ QAction *a = menu->addAction("TestMenuItem1");
+ a->setShortcut( Qt::Key_A | Qt::SHIFT | Qt::CTRL );
+ QObject::connect(a, SIGNAL(triggered()),
+ r, SLOT(showModalDialog()));
+
+
+ menu->addAction("T&estMenuItem2");
+ a = menu->addAction("Preferences");
+ a->setMenuRole(QAction::PreferencesRole);
+ QObject::connect(a, SIGNAL(triggered()),
+ r, SLOT(doPreferences()));
+
+ a = menu->addAction("TestMenuItem4");
+ a->setShortcut( Qt::Key_W | Qt::CTRL);
+
+ QMenu *menu2 = new QMenu("SecondMenu", window);
+ window->menuBar()->addMenu(menu2);
+
+ menu2->addAction("Yellow");
+ a = menu2->addAction("Mau&ve");
+
+ QFont f;
+ f.setPointSize(9);
+ a->setFont(f);
+
+ menu2->addAction("Taupe");
+
+ QMenu *submenu1 = new QMenu("Submenu", window);
+ submenu1->addAction("Sub Item 1");
+ submenu1->addAction("Sub Item 2");
+ submenu1->addAction("Sub Item 3");
+ menu2->addMenu(submenu1);
+
+ QMenu *submenu2 = new QMenu("Deeper", window);
+ submenu2->addAction("Sub Sub Item 1");
+ submenu2->addAction("Sub Sub Item 2");
+ submenu2->addAction("Sub Sub Item 3");
+ submenu1->addMenu(submenu2);
+
+ QMenu *menu3 = new QMenu("A Third Menu", window);
+
+ menu3->addAction("Eins");
+
+ QMenu *submenu3 = new QMenu("Dynamic", window);
+ QObject::connect(submenu3, SIGNAL(aboutToShow()), r, SLOT(aboutToShowSubmenu()));
+ menu3->addMenu(submenu3);
+
+ a = menu3->addAction("Zwei");
+ a->setShortcut( Qt::Key_3 | Qt::ALT);
+ a = menu3->addAction("About Drei...");
+ a->setMenuRole(QAction::AboutRole);
+
+ window->menuBar()->addMenu(menu3);
+
+ QAction *checkableAction = new QAction("Thing Enabled", window);
+ checkableAction->setCheckable(true);
+ checkableAction->setChecked(true);
+ QObject::connect(checkableAction, SIGNAL(triggered(bool)),
+ r, SLOT(toggleChecked(bool)));
+
+ menu2->addAction(checkableAction);
+
+ window->show();
+
+}
+
+void createWindow2()
+{
+ QMainWindow *window = new QMainWindow;
+ QMenu *menu = new QMenu("Nuts", window);
+
+ window->menuBar()->addMenu(menu);
+
+ menu->addAction("Peanuts");
+ menu->addAction("Walnuts");
+
+ QMenu *menu2 = new QMenu("Colours", window);
+ window->menuBar()->addMenu(menu2);
+
+ menu2->addAction("Pink");
+ menu2->addAction("Yellow");
+ menu2->addAction("Grape");
+
+ QMenu *menu3 = new QMenu("Edit", window);
+ menu3->addAction("Cut");
+ menu3->addAction("Copy boring way");
+ menu3->addAction("Copy awesomely");
+ menu3->addAction("Paste");
+
+ window->menuBar()->addMenu(menu3);
+ window->show();
+}
+
+int main(int argc, char **argv) {
+ QApplication app(argc, argv);
+
+ app.setApplicationName("Banana");
+
+ createWindow1();
+ createWindow2();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/tests/manual/cocoa/menus/menus.pro b/tests/manual/cocoa/menus/menus.pro
new file mode 100644
index 0000000000..0ccb25feb9
--- /dev/null
+++ b/tests/manual/cocoa/menus/menus.pro
@@ -0,0 +1,5 @@
+TEMPLATE = app
+
+SOURCES += main.cpp
+QT += gui widgets
+CONFIG -=app_bundle