Ejemplo n.º 1
0
bool AutoHideWidget::visiblePopups() {
    //qDebug() << "AutohideWidget::visiblePopups: internal_widget:" << internal_widget;
    if (!internal_widget) return false;

    // Check if any of the menus in the internal widget is visible
    QObjectList children = internal_widget->children();
    foreach(QObject * child, children) {
        if (child->isWidgetType()) {
            //qDebug() << "AutohideWidget::visiblePopups:" << child << "child name:" << child->objectName();
            QWidget *w = static_cast<QWidget *>(child);

            QList<QAction *> actions = w->actions();
            foreach(QAction * action, actions) {
                //qDebug() << "AutohideWidget::visiblePopups: action:" << action;

                QList<QWidget *> aw = action->associatedWidgets();
                //qDebug() << "AutohideWidget::visiblePopups: aw:" << aw;

                QMenu * menu = 0;
                foreach(QWidget * widget, aw) {
                    //qDebug() << "AutohideWidget::visiblePopups: widget:" << widget;
                    if ((menu = qobject_cast<QMenu *>(widget))) {
                        //qDebug() << "AutohideWidget::visiblePopups: menu:" << menu << "visible:" << menu->isVisible();
                        if (menu->isVisible()) return true;
                    }
                }

                menu = action->menu();
                if (menu) {
                    //qDebug() << "AutohideWidget::visiblePopups: menu:" << menu << "visible:" << menu->isVisible();
                    if (menu->isVisible()) return true;
                }
            }
        }
Ejemplo n.º 2
0
void tst_QMenu::mouseActivation()
{
#ifdef Q_OS_WINCE_WM
    QSKIP("We have a separate mouseActivation test for Windows mobile.", SkipAll);
#endif
    QMenu menu;
    menu.addAction("Menu Action");
    menu.show();
    QTest::mouseClick(&menu, Qt::LeftButton, 0, QPoint(5, 5), 300);
    QVERIFY(!menu.isVisible());

    //context menus can allways be accessed with right click except on windows
    menu.show();
    QTest::mouseClick(&menu, Qt::RightButton, 0, QPoint(5, 5), 300);
    QVERIFY(!menu.isVisible());

#ifdef Q_OS_WIN
    //on windows normal mainwindow menus Can only be accessed with left mouse button
    QMenuBar menubar;
    QMenu submenu("Menu");
    submenu.addAction("action");
    QAction *action = menubar.addMenu(&submenu);
    menubar.show();

    QTest::mouseClick(&menubar, Qt::LeftButton, 0, menubar.actionGeometry(action).center(), 300);
    QVERIFY(submenu.isVisible());
    QTest::mouseClick(&submenu, Qt::LeftButton, 0, QPoint(5, 5), 300);
    QVERIFY(!submenu.isVisible());

    QTest::mouseClick(&menubar, Qt::LeftButton, 0, menubar.actionGeometry(action).center(), 300);
    QVERIFY(submenu.isVisible());
    QTest::mouseClick(&submenu, Qt::RightButton, 0, QPoint(5, 5), 300);
    QVERIFY(submenu.isVisible());
#endif
}
Ejemplo n.º 3
0
void tst_QMenu::activeSubMenuPosition()
{
    QPushButton lab("subMenuPosition test");

    QMenu *sub = new QMenu("Submenu", &lab);
    sub->addAction("Sub-Item1");
    QAction *subAction = sub->addAction("Sub-Item2");

    QMenu *main = new QMenu("Menu-Title", &lab);
    (void)main->addAction("Item 1");
    QAction *menuAction = main->addMenu(sub);
    (void)main->addAction("Item 3");
    (void)main->addAction("Item 4");

    main->setActiveAction(menuAction);
    sub->setActiveAction(subAction);
    main->popup(QPoint(200,200));

    QVERIFY(main->isVisible());
    QCOMPARE(main->activeAction(), menuAction);
    QVERIFY(sub->isVisible());
    QVERIFY(sub->pos() != QPoint(0,0));
    // well, it's enough to check the pos is not (0,0) but it's more safe
    // to check that submenu is to the right of the main menu too.
#ifndef Q_OS_WINCE_WM
    QVERIFY(sub->pos().x() > main->pos().x());
    QCOMPARE(sub->activeAction(), subAction);
#endif
}
Ejemplo n.º 4
0
void
MacMenu::popup(qlonglong key, int idx, int x, int y)
{
    QMenuBar *menu = menuBar(key);
    if (!menu) return;

    QMenu *pop;
    for (int i = 0; i < menu->actions().count(); ++i)
    {
        if (!(pop = menu->actions().at(i)->menu()))
            continue;

        if (i == idx) {
            if (!pop->isVisible())
            {
                connect (pop, SIGNAL(aboutToHide()), this, SLOT(menuClosed()));
                XBAR_SEND( MSG("setOpenPopup") << idx );
                pop->popup(QPoint(x,y));
            }
            else
            {
                XBAR_SEND( MSG("setOpenPopup") << -1000 );
                pop->hide();
            }
        }
        else
            pop->hide();
    }
}
Ejemplo n.º 5
0
//2nd part of the test
void tst_QMenu::onStatusTipTimer()
{
    QMenu *menu = qobject_cast<QMenu*>(QApplication::activePopupWidget());
    QVERIFY(menu != 0);
    QVERIFY(menu->isVisible());
    QTest::keyClick(menu, Qt::Key_Down);

    //we store the statustip to press escape in any case
    //otherwise, if the test fails it blocks (never gets out of QMenu::exec
    const QString st=statustip;

    menu->close(); //goes out of the menu

    QCOMPARE(st, QString("sub action"));
    QVERIFY(menu->isVisible() == false);
}
Ejemplo n.º 6
0
void tst_QMenu::activeSubMenuPosition()
{
    QPushButton lab("subMenuPosition test");

    QMenu *sub = new QMenu("Submenu", &lab);
    sub->addAction("Sub-Item1");
    QAction *subAction = sub->addAction("Sub-Item2");

    QMenu *main = new QMenu("Menu-Title", &lab);
    (void)main->addAction("Item 1");
    QAction *menuAction = main->addMenu(sub);
    (void)main->addAction("Item 3");
    (void)main->addAction("Item 4");

    main->setActiveAction(menuAction);
    sub->setActiveAction(subAction);
#ifdef Q_OS_SYMBIAN
    main->popup(QPoint(50,200));
#else
    main->popup(QPoint(200,200));
#endif

    QVERIFY(main->isVisible());
    QCOMPARE(main->activeAction(), menuAction);
    QVERIFY(sub->isVisible());
    QVERIFY(sub->pos() != QPoint(0,0));
    // well, it's enough to check the pos is not (0,0) but it's more safe
    // to check that submenu is to the right of the main menu too.
#ifdef Q_OS_WINCE_WM
    QSKIP("Not true for Windows Mobile Soft Keys", SkipSingle);
#endif

#ifdef Q_OS_SYMBIAN
    // On Symbian, QS60Style::pixelMetric(QStyle::PM_SubMenuOverlap) is different with other styles.
    QVERIFY(sub->pos().x() < main->pos().x());
#else
    QVERIFY(sub->pos().x() > main->pos().x());
#endif
    QCOMPARE(sub->activeAction(), subAction);
}
Ejemplo n.º 7
0
void tst_QMenu::overrideMenuAction()
{
	//test the override menu action by first creating an action to which we set its menu
	QMainWindow w;

	QAction *aFileMenu = new QAction("&File", &w);
	w.menuBar()->addAction(aFileMenu);

	QMenu *m = new QMenu(&w);
	QAction *menuaction = m->menuAction();
	connect(m, SIGNAL(triggered(QAction*)), SLOT(onActivated(QAction*)));
	aFileMenu->setMenu(m); //this sets the override menu action for the QMenu
    QCOMPARE(m->menuAction(), aFileMenu);

#ifdef Q_WS_MAC
    QSKIP("On Mac, we need to create native key events to test menu action activation", SkipAll);
#elif defined(Q_OS_WINCE)
    QSKIP("On Windows CE, we need to create native key events to test menu action activation", SkipAll);
#elif defined(Q_OS_SYMBIAN)
    QSKIP("On Symbian OS, we need to create native key events to test menu action activation", SkipAll);
#endif

    QAction *aQuit = new QAction("Quit", &w);
	aQuit->setShortcut(QKeySequence("Ctrl+X"));
	m->addAction(aQuit);

	w.show();
    QApplication::setActiveWindow(&w);
    w.setFocus();
    QTest::qWaitForWindowShown(&w);
    QTRY_VERIFY(w.hasFocus());

	//test of the action inside the menu
	QTest::keyClick(&w, Qt::Key_X, Qt::ControlModifier);
    QTRY_COMPARE(activated, aQuit);

	//test if the menu still pops out
	QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier);
    QTRY_VERIFY(m->isVisible());

	delete aFileMenu;

	//after the deletion of the override menu action,
	//the menu should have its default menu action back
	QCOMPARE(m->menuAction(), menuaction);

}
Ejemplo n.º 8
0
void tst_QMenu::widgetActionFocus()
{
    //test if the focus is correctly handled with a QWidgetAction
    QMenu m;
    QListWidget *l = new QListWidget(&m);
    for (int i = 1; i<3 ; i++)
        l->addItem(QString("item%1").arg(i));
    QWidgetAction *wa = new QWidgetAction(&m);
    wa->setDefaultWidget(l);
    m.addAction(wa);
    m.setActiveAction(wa);
    l->setFocus(); //to ensure it has primarily the focus
    QAction *menuitem1=m.addAction("menuitem1");
    QAction *menuitem2=m.addAction("menuitem2");

    m.popup(QPoint());

    QVERIFY(m.isVisible());
    QVERIFY(l->hasFocus());
    QVERIFY(l->currentItem());
    QCOMPARE(l->currentItem()->text(), QString("item1"));

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
    QVERIFY(l->currentItem());
    QCOMPARE(l->currentItem()->text(), QString("item2"));

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
    QVERIFY(m.hasFocus());
    QCOMPARE(m.activeAction(), menuitem1);

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
    QVERIFY(m.hasFocus());
    QCOMPARE(m.activeAction(), menuitem2);

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up);
    QVERIFY(m.hasFocus());
    QCOMPARE(m.activeAction(), menuitem1);

    QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up);
    QVERIFY(l->hasFocus());
    QCOMPARE(m.activeAction(), (QAction *)wa);
}
Ejemplo n.º 9
0
void QDesignerMenuBar::showMenu(int index)
{
    if (index < 0 && m_currentIndex >= 0)
        index = m_currentIndex;

    if (index < 0 || index >= realActionCount())
        return;

    m_currentIndex = index;
    QAction *action = currentAction();

    if (action && action->menu()) {
        if (m_lastMenuActionIndex != -1 && m_lastMenuActionIndex != index) {
            hideMenu(m_lastMenuActionIndex);
        }

        m_lastMenuActionIndex = index;
        QMenu *menu = action->menu();
        const QRect g = actionGeometry(action);

        if (!menu->isVisible()) {
            if ((menu->windowFlags() & Qt::Popup) != Qt::Popup)
                menu->setWindowFlags(Qt::Popup);
            menu->adjustSize();
            if (layoutDirection() == Qt::LeftToRight) {
                menu->move(mapToGlobal(g.bottomLeft()));
            } else {
                // The position is not initially correct due to the unknown width,
                // causing it to overlap a bit the first time it is invoked.
                const QSize menuSize = menu->size();
                QPoint point = g.bottomRight() - QPoint(menu->width(), 0);
                menu->move(mapToGlobal(point));
            }
            menu->setFocus(Qt::MouseFocusReason);
            menu->raise();
            menu->show();
        } else {
            menu->raise();
        }
    }
}
Ejemplo n.º 10
0
/* FIXME make this less of a hack. */
QRect TestCalendarWidget::visualRect(QString const &item) const
{
    TestWidgetsLog() << item << "my geometry is" << geometry();

    QRect ret;

    QAbstractItemView *view = q->findChild<QAbstractItemView*>();
    QtUiTest::ListWidget *calendarView
        = qtuitest_cast<QtUiTest::ListWidget*>(view);

    if (!calendarView) {
        return ret;
    }

    ret = calendarView->visualRect(item);
    if (!ret.isNull()) {
        ret.moveTopLeft( q->mapFromGlobal( view->mapToGlobal(ret.topLeft()) ) );
        TestWidgetsLog() << item << "is a visible day at" << ret;
        return ret;
    }

    QToolButton *yearButton = 0;
    QToolButton *monthButton = 0;
    QSpinBox *yearSpin = q->findChild<QSpinBox*>();
    QMenu *monthMenu = 0;

    QList<QToolButton*> blist = q->findChildren<QToolButton*>();
    foreach(QToolButton *b, blist) {
        if (!monthButton && (monthMenu = b->menu())) {
            monthButton = b;
        }
        if (!b->menu()) {
            yearButton = b;
        }
    }
    TestWidgetsLog() << "monthButton" << monthButton << "yearButton" << yearButton;
    TestWidgetsLog() << "item" << item << "monthMenu" << monthMenu;

    if (yearButton && yearButton->isVisible() && yearButton->text() == item) {
        QPoint p = q->mapFromGlobal( yearButton->mapToGlobal(QPoint(yearButton->width()+5, yearButton->height()/2)) );
        ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
        TestWidgetsLog() << "click near yearbutton";
    } else if (yearSpin && yearSpin->isVisible() && yearSpin->value() == item.toInt()) {
        TestWidgetsLog() << "confirm spinbox";
        QPoint p = q->mapFromGlobal( yearSpin->mapToGlobal(QPoint(yearSpin->width()+5, yearSpin->height()/2)) );
        ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
    } else if (monthButton && monthButton->isVisible() && monthButton->text() == item) {
        QPoint p = q->mapFromGlobal( monthButton->mapToGlobal(QPoint(-5, monthButton->height()/2)) );
        ret = QRect(p.x() - 2, p.y() - 2, 5, 5);
        TestWidgetsLog() << "click near monthbutton";
    } else if (monthMenu && monthMenu->isVisible()
            && qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)
            && qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->list().contains(item)) {
        ret = qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->visualRect(item);
        ret.moveTopLeft( q->mapFromGlobal( monthMenu->mapToGlobal(ret.topLeft()) ) );
        TestWidgetsLog() << "click on monthmenu";
    } else {
        do {
            QStringList items = list();
            if (items.contains(item)) {
                ret = QRect(-1, -1, 1, 1);
                ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) );
                break;
            }
            foreach (QString s, items) {
                if (!s.startsWith(GetListRegExp)) continue;
                QRegExp re(s.mid(GetListRegExp.length()));
                if (re.exactMatch(item)) {
                    ret = QRect(-1, -1, 1, 1);
                    ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) );
                    break;
                }
            }
            if (!ret.isNull()) break;
        } while(0);
    }

    TestWidgetsLog() << "returning rect" << ret;

    return ret;
}