void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentSeveralActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); selectAction.addAction(new QAction("action1", &selectAction)); selectAction.addAction(new QAction("action2", &selectAction)); selectAction.addAction(new QAction("action3", &selectAction)); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QToolButton* toolButton = qobject_cast<QToolButton*>(widget); QVERIFY(toolButton); QVERIFY(toolButton->isEnabled()); QVERIFY(toolButton->autoRaise()); QCOMPARE((int)toolButton->focusPolicy(), (int)Qt::NoFocus); QCOMPARE(toolButton->defaultAction(), (QAction*)&selectAction); QCOMPARE(toolButton->actions().count(), 4); QCOMPARE(toolButton->actions().at(0)->text(), QString("selectAction")); QCOMPARE(toolButton->actions().at(1)->text(), QString("action1")); QCOMPARE(toolButton->actions().at(2)->text(), QString("action2")); QCOMPARE(toolButton->actions().at(3)->text(), QString("action3")); }
QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid ) { QgsAttributeTableConfig attributeTableConfig = mFilterModel->layer()->attributeTableConfig(); QgsActionManager* actions = mFilterModel->layer()->actions(); QToolButton* toolButton = nullptr; QWidget* container = nullptr; if ( attributeTableConfig.actionWidgetStyle() == QgsAttributeTableConfig::DropDown ) { toolButton = new QToolButton( this ); toolButton->setPopupMode( QToolButton::MenuButtonPopup ); container = toolButton; } else { container = new QWidget( this ); container->setLayout( new QHBoxLayout() ); container->layout()->setMargin( 0 ); } for ( int i = 0; i < actions->size(); ++i ) { const QgsAction& action = actions->at( i ); if ( !action.showInAttributeTable() ) continue; QAction* act = new QAction( action.icon(), action.shortTitle().isEmpty() ? action.name() : action.shortTitle(), toolButton ); act->setToolTip( action.name() ); act->setData( i ); act->setProperty( "fid", fid ); connect( act, SIGNAL( triggered( bool ) ), this, SLOT( actionTriggered() ) ); if ( attributeTableConfig.actionWidgetStyle() == QgsAttributeTableConfig::DropDown ) { toolButton->addAction( act ); if ( actions->defaultAction() == i ) toolButton->setDefaultAction( act ); container = toolButton; } else { QToolButton* btn = new QToolButton; btn->setDefaultAction( act ); container->layout()->addWidget( btn ); } } if ( toolButton && !toolButton->actions().isEmpty() && actions->defaultAction() == -1 ) toolButton->setDefaultAction( toolButton->actions().first() ); return container; }
bool FullScreenBar::eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::MouseMove) { QApplication::restoreOverrideCursor(); d->mAutoHideCursorTimer->start(); if (y() == 0) { if (d->shouldHide()) { slideOut(); } } else { QMouseEvent* mouseEvent = static_cast<QMouseEvent *>(event); if (mouseEvent->buttons() == 0 && d->slideInTriggerRect().contains(QCursor::pos())) { slideIn(); } } return false; } if (event->type() == QEvent::MouseButtonRelease) { // This can happen if user released the mouse after using a scrollbar // in the content (the bar does not hide while a button is down) if (y() == 0 && d->shouldHide()) { slideOut(); } return false; } // Filtering message on tooltip text for CJK to remove accelerators. // Quoting ktoolbar.cpp: // """ // CJK languages use more verbose accelerator marker: they add a Latin // letter in parenthesis, and put accelerator on that. Hence, the default // removal of ampersand only may not be enough there, instead the whole // parenthesis construct should be removed. Use KLocale's method to do this. // """ if (event->type() == QEvent::Show || event->type() == QEvent::Paint) { QToolButton* button = qobject_cast<QToolButton*>(object); if (button && !button->actions().isEmpty()) { QAction* action = button->actions().first(); QString toolTip = KGlobal::locale()->removeAcceleratorMarker(action->toolTip()); // Filtering message requested by translators (scripting). button->setToolTip(i18nc("@info:tooltip of custom toolbar button", "%1", toolTip)); } } return false; }