2016-08-11 00:24:04 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2017-02-21 09:48:17 +00:00
|
|
|
** 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.
|
2016-08-11 00:24:04 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "menuramaapplication.h"
|
|
|
|
|
2017-11-14 16:23:49 +00:00
|
|
|
MenuramaApplication::MenuramaApplication(int &argc, char **argv)
|
2016-08-11 00:24:04 +00:00
|
|
|
: QApplication (argc, argv)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
QMenuBar *mb = new QMenuBar();
|
|
|
|
QMenu *menu = mb->addMenu("App Dynamic");
|
|
|
|
QMenu *dynMenu = menu->addMenu("After aboutToShow()");
|
|
|
|
connect(dynMenu, &QMenu::aboutToShow, [=] {
|
|
|
|
qDebug() << "aboutToShow(), populating" << dynMenu;
|
|
|
|
menuApp->populateMenu(dynMenu, true /*clear*/);
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuramaApplication::populateMenu(QMenu *menu, bool clear)
|
|
|
|
{
|
|
|
|
if (clear)
|
|
|
|
menu->clear();
|
|
|
|
|
|
|
|
static const char *sym[] = { "Foo", "Bar", "Baz", "Huux" };
|
|
|
|
static int id = 0;
|
|
|
|
for (unsigned i = 0; i < sizeof(sym) / sizeof(sym[0]); i++)
|
|
|
|
menu->addAction(QStringLiteral("%1 — %2 %3 ")
|
|
|
|
.arg(menu->title()).arg(sym[i]).arg(id));
|
|
|
|
++id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuramaApplication::addDynMenu(QLatin1String title, QMenu *parentMenu)
|
|
|
|
{
|
QCocoaMenu: Force NSMenuValidation when syncing items
When a menu item's enabled state changes after
-[QCocoaMenuDelegate menuWillOpen:] is invoked, i.e.,
during or after QMenu::aboutToShow() is emitted, that
state change may not be taken into account. This is
because the automatic menu validation, upon which Qt
relies, is not made aware of any such change.
By calling -[NSMenu update] when syncing the QPA menu
item, we induce Cocoa to invoke -[QCocoaMenuDelegate
validateMenuItem:] and ensure that previously synced
items, whose state may have changed, will be properly
updated. This, however, has a small side effect, namely
that menu-holding items will also go through the automatic
menu enabling path and may appear disabled since, until
now, they were not properly configured. In order to solve
this, we set the action on those items as well, and make
sure that both of QCocoaMenuDelegate's relevant methods,
validateMenuItem: and itemFired:, properly process
menu-holding items.
Menurama manual test updated accordingly.
Change-Id: I62f955538b8be09b8494ea0ce87fca7910148d38
Task-number: QTBUG-56850
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2016-11-03 00:37:43 +00:00
|
|
|
if (QAction *a = findAction(title, parentMenu))
|
|
|
|
parentMenu->removeAction(a);
|
2016-08-11 00:24:04 +00:00
|
|
|
|
|
|
|
QMenu *subMenu = new QMenu(title, parentMenu);
|
|
|
|
populateMenu(subMenu, false /*clear*/);
|
|
|
|
parentMenu->addMenu(subMenu);
|
|
|
|
}
|
QCocoaMenu: Force NSMenuValidation when syncing items
When a menu item's enabled state changes after
-[QCocoaMenuDelegate menuWillOpen:] is invoked, i.e.,
during or after QMenu::aboutToShow() is emitted, that
state change may not be taken into account. This is
because the automatic menu validation, upon which Qt
relies, is not made aware of any such change.
By calling -[NSMenu update] when syncing the QPA menu
item, we induce Cocoa to invoke -[QCocoaMenuDelegate
validateMenuItem:] and ensure that previously synced
items, whose state may have changed, will be properly
updated. This, however, has a small side effect, namely
that menu-holding items will also go through the automatic
menu enabling path and may appear disabled since, until
now, they were not properly configured. In order to solve
this, we set the action on those items as well, and make
sure that both of QCocoaMenuDelegate's relevant methods,
validateMenuItem: and itemFired:, properly process
menu-holding items.
Menurama manual test updated accordingly.
Change-Id: I62f955538b8be09b8494ea0ce87fca7910148d38
Task-number: QTBUG-56850
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2016-11-03 00:37:43 +00:00
|
|
|
|
|
|
|
QAction *MenuramaApplication::findAction(QLatin1String title, QMenu *parentMenu)
|
|
|
|
{
|
|
|
|
foreach (QAction *a, parentMenu->actions())
|
|
|
|
if (a->text() == title)
|
|
|
|
return a;
|
|
|
|
|
2017-09-18 09:49:52 +00:00
|
|
|
return nullptr;
|
QCocoaMenu: Force NSMenuValidation when syncing items
When a menu item's enabled state changes after
-[QCocoaMenuDelegate menuWillOpen:] is invoked, i.e.,
during or after QMenu::aboutToShow() is emitted, that
state change may not be taken into account. This is
because the automatic menu validation, upon which Qt
relies, is not made aware of any such change.
By calling -[NSMenu update] when syncing the QPA menu
item, we induce Cocoa to invoke -[QCocoaMenuDelegate
validateMenuItem:] and ensure that previously synced
items, whose state may have changed, will be properly
updated. This, however, has a small side effect, namely
that menu-holding items will also go through the automatic
menu enabling path and may appear disabled since, until
now, they were not properly configured. In order to solve
this, we set the action on those items as well, and make
sure that both of QCocoaMenuDelegate's relevant methods,
validateMenuItem: and itemFired:, properly process
menu-holding items.
Menurama manual test updated accordingly.
Change-Id: I62f955538b8be09b8494ea0ce87fca7910148d38
Task-number: QTBUG-56850
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2016-11-03 00:37:43 +00:00
|
|
|
}
|