void FlameGraphViewTest::testContextMenu()
{
    int targetWidth = 0;
    int targetHeight = 0;
    {
        QMenu testMenu;
        testMenu.addActions(QmlProfilerTool::profilerContextMenuActions());
        testMenu.addSeparator();
        testMenu.show();
        QTest::qWaitForWindowExposed(testMenu.window());
        targetWidth = testMenu.width() / 2;
        int prevHeight = testMenu.height();
        QAction dummy(QString("target"), this);
        testMenu.addAction(&dummy);
        targetHeight = (testMenu.height() + prevHeight) / 2;
    }

    QTimer timer;
    timer.setInterval(50);
    timer.start();

    connect(&timer, &QTimer::timeout, this, [&]() {
        auto activePopup = qApp->activePopupWidget();
        if (!activePopup || !activePopup->windowHandle()->isExposed())
            return;
        QTest::mouseMove(activePopup, QPoint(targetWidth, targetHeight));
        QTest::mouseClick(activePopup, Qt::LeftButton, Qt::NoModifier,
                          QPoint(targetWidth, targetHeight));

        if (!manager.isRestrictedToRange()) {
            // click somewhere else to remove the menu and return to outer function
            QTest::mouseClick(qApp->activePopupWidget(), Qt::LeftButton, Qt::NoModifier,
                              QPoint(500, 500));
        }
    });

    QTest::mouseMove(&view, QPoint(250, 250));
    QSignalSpy spy(&view, SIGNAL(showFullRange()));

    QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(250, 250));
    QVERIFY(qApp->notify(&view, &event));
    QCOMPARE(spy.count(), 0);

    manager.restrictToRange(1, 10);

    QVERIFY(qApp->notify(&view, &event));

    if (spy.count() != 1)
        QTRY_COMPARE(spy.count(), 1);
}
bool ApplicationsMenuApplet::init(QWidget* parent)
{
  if(m_settings.type() == QVariant::List)
  {
    QVariantList list = m_settings.value<QVariantList>();

    while(!list.isEmpty())
    {
      const char** names = reinterpret_cast<const char**>(list.takeFirst().value<void*>());

      QMenu* menu = m_menu->addMenu(g_menu_names.value(names[0]));
      menu->setIcon(QIcon::fromTheme(names[1]).pixmap(menu->height(),menu->height()));
      m_menus.insert(g_menu_names.value(names[0]), menu);
    }

    QStringList categories;
    for(QList<DesktopEntryObject*>::iterator pos = m_entries.begin(); pos != m_entries.end(); ++pos)
    {
      if(m_menus.contains((*pos)->Category()))
        m_menus[(*pos)->Category()]->addAction((*pos)->Action());
      else
        m_menus["Other"]->addAction((*pos)->Action());
/*
      categories = (*pos)->Categories();
      for(QStringList::iterator pos2 = categories.begin(); pos2 != categories.end(); ++pos2)
        if(m_menus.contains(*pos2))
          m_menus[*pos2]->addAction((*pos)->Action());
*/
    }
  }

  m_menu->addSeparator();
  m_menu->addAction(QIcon::fromTheme("application-exit"), "Quit", qApp, SLOT(quit()));

/*
  connect(DesktopApplications::instance(), SIGNAL(applicationUpdated(const DesktopApplication&)), this, SLOT(onApplicationUpdated(const DesktopApplication&)));
  connect(DesktopApplications::instance(), SIGNAL(applicationRemoved(const QString&)), this, SLOT(onApplicationRemoved(const QString&)));

  QList<DesktopApplication> apps = DesktopApplications::instance()->applications();
  foreach(const DesktopApplication& app, apps)
    onApplicationUpdated(app);
*/

  return true;
}