| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2017 The Qt Company Ltd. |
| 4 |
** Contact: https://www.qt.io/licensing/ |
| 5 |
** |
| 6 |
** This file is part of the test suite of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 |
** Commercial License Usage |
| 10 |
** Licensees holding valid commercial Qt licenses may use this file in |
| 11 |
** accordance with the commercial license agreement provided with the |
| 12 |
** Software or, alternatively, in accordance with the terms contained in |
| 13 |
** a written agreement between you and The Qt Company. For licensing terms |
| 14 |
** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 |
** information use the contact form at https://www.qt.io/contact-us. |
| 16 |
** |
| 17 |
** GNU General Public License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU |
| 19 |
** General Public License version 3 as published by the Free Software |
| 20 |
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 |
** included in the packaging of this file. Please review the following |
| 22 |
** information to ensure the GNU General Public License requirements will |
| 23 |
** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 |
** |
| 25 |
** $QT_END_LICENSE$ |
| 26 |
** |
| 27 |
****************************************************************************/ |
| 28 |
|
| 29 |
#include "mainwindow.h" |
| 30 |
#include "ui_mainwindow.h" |
| 31 |
#include "menuramaapplication.h" |
| 32 |
#include <QDebug> |
| 33 |
|
| 34 |
MainWindow::MainWindow(QWidget *parent) : |
| 35 |
QMainWindow(parent), |
| 36 |
ui(new Ui::MainWindow) |
| 37 |
{ |
| 38 |
ui->setupUi(this); |
| 39 |
|
| 40 |
auto *a = ui->menuStuff->addAction("Enabled Submenu (QTBUG-63172)"); |
| 41 |
auto *qtbug63172_Menu = new QMenu; |
| 42 |
qtbug63172_Menu->addAction("We're Good!"); |
| 43 |
a->setMenu(qtbug63172_Menu); |
| 44 |
|
| 45 |
startTimer(1000); |
| 46 |
|
| 47 |
connect(ui->menuAfter_aboutToShow, &QMenu::aboutToShow, [=] { |
| 48 |
menuApp->populateMenu(ui->menuAfter_aboutToShow, true /*clear*/); |
| 49 |
}); |
| 50 |
|
| 51 |
connect(ui->menuDynamic_Stuff, &QMenu::aboutToShow, [=] { |
| 52 |
menuApp->addDynMenu(QLatin1String("Menu Added After aboutToShow()"), ui->menuDynamic_Stuff); |
| 53 |
|
| 54 |
const QLatin1String itemTitle = QLatin1String("Disabled Item Added After aboutToShow()"); |
| 55 |
if (QAction *a = menuApp->findAction(itemTitle, ui->menuDynamic_Stuff)) |
| 56 |
ui->menuDynamic_Stuff->removeAction(a); |
| 57 |
QAction *a = ui->menuDynamic_Stuff->addAction(itemTitle); |
| 58 |
a->setEnabled(false); |
| 59 |
}); |
| 60 |
|
| 61 |
connect(ui->pushButton, &QPushButton::clicked, [=] { |
| 62 |
menuApp->populateMenu(ui->menuOn_Click, true /*clear*/); |
| 63 |
}); |
| 64 |
|
| 65 |
connect(ui->addManyButton, &QPushButton::clicked, [=] { |
| 66 |
QMenu *menu = new QMenu(QLatin1String("Many More ") + |
| 67 |
QString::number(ui->menuBar->actions().count())); |
| 68 |
ui->menuBar->insertMenu(ui->menuDynamic_Stuff->menuAction(), menu); |
| 69 |
for (int i = 0; i < 2000; i++) { |
| 70 |
auto *action = menu->addAction(QLatin1String("Item ") + QString::number(i)); |
| 71 |
if (i & 0x1) |
| 72 |
action->setEnabled(false); |
| 73 |
if (i & 0x2) |
| 74 |
action->setVisible(false); |
| 75 |
} |
| 76 |
}); |
| 77 |
} |
| 78 |
|
| 79 |
MainWindow::~MainWindow() |
| 80 |
{ |
| 81 |
delete ui; |
| 82 |
} |
| 83 |
|
| 84 |
void MainWindow::timerEvent(QTimerEvent *) |
| 85 |
{ |
| 86 |
menuApp->populateMenu(ui->menuPopulated_by_Timer, true /*clear*/); |
| 87 |
menuApp->addDynMenu(QLatin1String("Added by Timer"), ui->menuDynamic_Stuff); |
| 88 |
} |
| 89 |
|
| 90 |
void MainWindow::enableStuffMenu(bool enable) |
| 91 |
{ |
| 92 |
ui->menuStuff->setEnabled(enable); |
| 93 |
} |
| 94 |
|
| 95 |
void MainWindow::on_actionQuit_triggered() |
| 96 |
{ |
| 97 |
menuApp->exit(); |
| 98 |
} |