Exemplo n.º 1
2
void PdfViewer::showToolBarStylePopupMenu(const QPoint &pos)
{
	QMenu *popupMenu = new QMenu(this);
	popupMenu->setAttribute(Qt::WA_DeleteOnClose);
	popupMenu->move(mapToGlobal(QPoint(0,0)) + pos);

	QWidgetAction *iconOnlyAction = new QWidgetAction(popupMenu);
	QRadioButton *iconOnlyRadio = new QRadioButton(tr("&Icons Only"), popupMenu);
	iconOnlyAction->setDefaultWidget(iconOnlyRadio);

	QWidgetAction *textOnlyAction = new QWidgetAction(popupMenu);
	QRadioButton *textOnlyRadio = new QRadioButton(tr("&Text Only"), popupMenu);
	textOnlyAction->setDefaultWidget(textOnlyRadio);

	QWidgetAction *textBesideIconAction = new QWidgetAction(popupMenu);
	QRadioButton *textBesideIconRadio = new QRadioButton(tr("Text &Alongside Icons"), popupMenu);
	textBesideIconAction->setDefaultWidget(textBesideIconRadio);

	QWidgetAction *textUnderIconAction = new QWidgetAction(popupMenu);
	QRadioButton *textUnderIconRadio = new QRadioButton(tr("Text &Under Icons"), popupMenu);
	textUnderIconAction->setDefaultWidget(textUnderIconRadio);

	QButtonGroup *popupButtonGroup = new QButtonGroup(popupMenu);
	popupButtonGroup->addButton(iconOnlyRadio);
	popupButtonGroup->addButton(textOnlyRadio);
	popupButtonGroup->addButton(textBesideIconRadio);
	popupButtonGroup->addButton(textUnderIconRadio);
	popupButtonGroup->setId(iconOnlyRadio, 0);
	popupButtonGroup->setId(textOnlyRadio, 1);
	popupButtonGroup->setId(textBesideIconRadio, 2);
	popupButtonGroup->setId(textUnderIconRadio, 3);
	connect(popupButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotChangeToolBarStyle(int)));

	popupMenu->addAction(iconOnlyAction);
	popupMenu->addAction(textOnlyAction);
	popupMenu->addAction(textBesideIconAction);
	popupMenu->addAction(textUnderIconAction);
	popupMenu->setContentsMargins(5, 0, 5, 0);

	QSettings settings;
	settings.beginGroup("MainWindow");
	const int toolBarStyleNumber = settings.value("ToolBarStyle", 0).toInt();
	switch (toolBarStyleNumber)
	{
		case 0: iconOnlyRadio->setChecked(true); break;
		case 1: textOnlyRadio->setChecked(true); break;
		case 2: textBesideIconRadio->setChecked(true); break;
		case 3: textUnderIconRadio->setChecked(true); break;
	}
	settings.endGroup();

	popupMenu->show();
	// make sure that the popupMenu stays completely inside the screen (must be done after popupMenu->show() in order to have the correct width)
	const int desktopWidth = QApplication::desktop()->availableGeometry(this).width();
	if (popupMenu->x() + popupMenu->width() > desktopWidth)
		popupMenu->move(desktopWidth - popupMenu->width(), popupMenu->y());
}
Exemplo 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
}
Exemplo n.º 3
0
QT_END_NAMESPACE
#endif

void tst_QMenu::focus()
{
    QMenu menu;
    menu.addAction("One");
    menu.addAction("Two");
    menu.addAction("Three");

#ifdef Q_OS_MAC
    if (!qt_tab_all_widgets())
        QSKIP("Computer is currently set up to NOT tab to all widgets,"
             " this test assumes you can tab to all widgets");
#endif

    QWidget window;
    QPushButton button("Push me", &window);
    window.show();
    qApp->setActiveWindow(&window);

    QVERIFY(button.hasFocus());
    QCOMPARE(QApplication::focusWidget(), (QWidget *)&button);
    QCOMPARE(QApplication::activeWindow(), &window);
    menu.show();
    QVERIFY(button.hasFocus());
    QCOMPARE(QApplication::focusWidget(), (QWidget *)&button);
    QCOMPARE(QApplication::activeWindow(), &window);
    menu.hide();
    QVERIFY(button.hasFocus());
    QCOMPARE(QApplication::focusWidget(), (QWidget *)&button);
    QCOMPARE(QApplication::activeWindow(), &window);
}
bool AnimatedVectorControl::buttonClicked(unsigned int index)
{
	bool isAnimated = m_pairedValue->isAnimated();

	QMenu* m = new QMenu(m_pAnimationButton);
	if (!isAnimated)
	{
		m->addAction(m_actSetAnimated);
	}
	else
	{
		m->addAction(m_actDeleteAnimation);
		m->addAction(m_actSetKey);
		m->addAction(m_actDeleteKey);
		m->addSeparator();

		m->addAction(m_actLinearInterpolation);
		m->addAction(m_actQuadraticInterpolation);
		m->addAction(m_actCubicInterpolation);
	}

	QSize menuSize = m->sizeHint();

	QSize buttonSize = m_pAnimationButton->geometry().size();

	m->move(m_pAnimationButton->mapToGlobal(QPoint(buttonSize.width() - menuSize.width(), buttonSize.height())));
	m->show();

	return false;
}
Exemplo n.º 5
0
void Strings::mousePressEvent(QMouseEvent *event)
{
    if(event->button()==Qt::RightButton){
        if(reducable_ || closable_ || modifiable_){
            QMenu * menu = new QMenu(this);

            if(modifiable_){
                QAction* actionModify = menu->addAction(tr("Modify"));
                actionModify->setEnabled(false);
                //connect(actionModify,SIGNAL(triggered()),this,SLOT(()));
            }

            if(reducable_){
                QAction* actionReduce = menu->addAction(tr("Reduce"));
                connect(actionReduce,SIGNAL(triggered()),(Guitar*)this->parent(),SLOT(pressReduce()));
            }

            if(closable_){
                QAction* actionClose = menu->addAction(tr("Close"));
                connect(actionClose,SIGNAL(triggered()),(Guitar*)this->parent(),SLOT(pressClose()));
            }

            menu->move(event->globalPos());
            menu->show();
        }
    }
}
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);
}
Exemplo n.º 7
0
QT_END_NAMESPACE
#endif

void tst_QMenu::focus()
{
    QMenu menu;
    menu.addAction("One");
    menu.addAction("Two");
    menu.addAction("Three");
    bool fullKeyboardControl = true;

#ifdef Q_WS_MAC
    fullKeyboardControl = qt_tab_all_widgets;
#endif

    if (!fullKeyboardControl)
        QSKIP("Computer is currently set up to NOT tab to all widgets,"
             " this test assumes you can tab to all widgets", SkipAll);

    QWidget window;
    QPushButton button("Push me", &window);
    window.show();
    qApp->setActiveWindow(&window);

    QVERIFY(button.hasFocus());
    QCOMPARE(QApplication::focusWidget(), (QWidget *)&button);
    QCOMPARE(QApplication::activeWindow(), &window);
    menu.show();
#if 0
    QVERIFY(!button.hasFocus());
    QCOMPARE(QApplication::focusWidget(), &menu);
    QCOMPARE(QApplication::activeWindow(), &window);
#else
    QVERIFY(button.hasFocus());
    QCOMPARE(QApplication::focusWidget(), (QWidget *)&button);
    QCOMPARE(QApplication::activeWindow(), &window);
#endif
    menu.hide();
    QVERIFY(button.hasFocus());
    QCOMPARE(QApplication::focusWidget(), (QWidget *)&button);
    QCOMPARE(QApplication::activeWindow(), &window);
}
Exemplo n.º 8
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();
        }
    }
}
Exemplo n.º 9
0
void LXQtTaskGroup::contextMenuEvent(QContextMenuEvent *event)
{
    setPopupVisible(false, true);
    mPreventPopup = true;
    if (windowId())
    {
        LXQtTaskButton::contextMenuEvent(event);
        return;
    }

    QMenu * menu = new QMenu(tr("Group"));
    menu->setAttribute(Qt::WA_DeleteOnClose);
    QAction *a = menu->addAction(XdgIcon::fromTheme("process-stop"), tr("Close group"));
    connect(a, SIGNAL(triggered()), this, SLOT(closeGroup()));
    connect(menu, &QMenu::aboutToHide, [this] {
        mPreventPopup = false;
    });
    menu->setGeometry(mPlugin->panel()->calculatePopupWindowPos(mapToGlobal(event->pos()), menu->sizeHint()));
    mPlugin->willShowWindow(menu);
    menu->show();
}