forked from qt-creator/qt-creator
In the FancyActionBar, trigger a button's default action
also when a context menu action is selected. This allows the user e.g. to select and run a specific run configuration with one click.
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
#include <QtGui/QPicture>
|
#include <QtGui/QPicture>
|
||||||
#include <QtGui/QVBoxLayout>
|
#include <QtGui/QVBoxLayout>
|
||||||
#include <QtSvg/QSvgRenderer>
|
#include <QtSvg/QSvgRenderer>
|
||||||
|
#include <QtGui/QAction>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
@@ -154,6 +155,24 @@ void FancyActionBar::insertAction(int index, QAction *action, QMenu *menu)
|
|||||||
if (menu) {
|
if (menu) {
|
||||||
toolButton->setMenu(menu);
|
toolButton->setMenu(menu);
|
||||||
toolButton->setPopupMode(QToolButton::DelayedPopup);
|
toolButton->setPopupMode(QToolButton::DelayedPopup);
|
||||||
|
|
||||||
|
// execute action also if a context menu item is select
|
||||||
|
connect(toolButton, SIGNAL(triggered(QAction*)),
|
||||||
|
this, SLOT(toolButtonContextMenuActionTriggered(QAction*)));
|
||||||
}
|
}
|
||||||
m_actionsLayout->insertWidget(index, toolButton);
|
m_actionsLayout->insertWidget(index, toolButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This slot is invoked when a context menu action of a tool button is triggered.
|
||||||
|
In this case we also want to trigger the default action of the button.
|
||||||
|
|
||||||
|
This allows the user e.g. to select and run a specific run configuration with one click.
|
||||||
|
*/
|
||||||
|
void FancyActionBar::toolButtonContextMenuActionTriggered(QAction* action)
|
||||||
|
{
|
||||||
|
if (QToolButton *button = qobject_cast<QToolButton*>(sender())) {
|
||||||
|
if (action != button->defaultAction())
|
||||||
|
button->defaultAction()->trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -64,6 +64,8 @@ public:
|
|||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
void insertAction(int index, QAction *action, QMenu *menu = 0);
|
void insertAction(int index, QAction *action, QMenu *menu = 0);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void toolButtonContextMenuActionTriggered(QAction*);
|
||||||
private:
|
private:
|
||||||
QVBoxLayout *m_actionsLayout;
|
QVBoxLayout *m_actionsLayout;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user