qt5base-lts/tests/manual/cocoa/menurama/main.cpp
Volker Hilsheimer bcaff2b06f Remove QGuiAction again and split QAction implementation up instead
Duplicating the number of classes is a high price to pay to be able to
have some QAction functionality behave differently, or be only available
in widgets applications.

Instead, declare the entire API in QtGui in QAction* classes, and
delegate the implementation of QtWidgets specific functionality to
the private. The creation of the private is then delegated to the
Q(Gui)ApplicationPrivate instance through a virtual factory function.

Change some public APIs that are primarily useful for specialized tools
such as Designer to operate on QObject* rather than QWidget*. APIs that
depend on QtWidgets types have been turned into inline template
functions, so that they are instantiated only at the caller side, where
we can expect the respective types to be fully defined. This way, we
only need to forward declare a few classes in the header, and don't
need to generate any additional code for e.g. language bindings.

Change-Id: Id0b27f9187652ec531a2e8b1b9837e82dc81625c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-03-29 11:18:57 +01:00

77 lines
2.7 KiB
C++

/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "mainwindow.h"
#include "menuramaapplication.h"
#include <QtGui/QAction>
#include <QtWidgets/QMenu>
int main(int argc, char *argv[])
{
MenuramaApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);
auto *dockMenu = new QMenu();
dockMenu->setAsDockMenu();
dockMenu->addAction(QLatin1String("New Window"), [=] {
auto *w = new MainWindow;
w->setAttribute(Qt::WA_DeleteOnClose, true);
w->show();
});
auto *disabledAction = dockMenu->addAction(QLatin1String("Disabled Item"), [=] {
qDebug() << "Should not happen!";
Q_UNREACHABLE();
});
disabledAction->setEnabled(false);
dockMenu->addAction(QLatin1String("Last Item Before Separator"), [=] {
qDebug() << "Last Item triggered";
});
auto *hiddenAction = dockMenu->addAction(QLatin1String("Invisible Item (FIXME rdar:39615815)"), [=] {
qDebug() << "Should not happen!";
Q_UNREACHABLE();
});
hiddenAction->setVisible(false);
dockMenu->addSeparator();
auto *toolsMenu = dockMenu->addMenu(QLatin1String("Menurama Tools"));
toolsMenu->addAction(QLatin1String("Hammer"), [=] {
qDebug() << "Bang! Bang!";
});
toolsMenu->addAction(QLatin1String("Wrench"), [=] {
qDebug() << "Clang! Clang!";
});
toolsMenu->addAction(QLatin1String("Screwdriver"), [=] {
qDebug() << "Squeak! Squeak!";
});
MainWindow w;
w.show();
return a.exec();
}