Commit d918b29b authored by Benjamin Long's avatar Benjamin Long

Add QtoolButton long click

parent cf517f3d
......@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QMenuBar>
#include <QPushButton>
#include <QtDebug>
#include <QToolButton>
#include "pqEventDispatcher.h"
......@@ -52,8 +53,8 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
const QString& Arguments,
bool& Error)
{
if(Command != "activate")
return false;
if(Command != "activate" && Command != "longActivate")
return false;
if (QMenuBar* const menu_bar = qobject_cast<QMenuBar*>(Object))
{
......@@ -109,7 +110,6 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
else if(QMenu* menu = qobject_cast<QMenu*>(p))
{
menu->setActiveAction(next->menuAction());
int max_wait = 0;
while(!next->isVisible() && (++max_wait) <= 2)
{
......@@ -135,9 +135,21 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
if(QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object))
{
object->click();
//QApplication::processEvents();
return true;
if (Command == "activate")
{
object->click();
//QApplication::processEvents();
return true;
}
if(Command == "longActivate")
{
QToolButton* tButton = qobject_cast<QToolButton*>(Object);
if(tButton)
{
tButton->showMenu();
return true;
}
}
}
if (QAction* const action = qobject_cast<QAction*>(Object))
......
......@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqAbstractButtonEventTranslator.h"
#include <QDebug>
#include <QAbstractButton>
#include <QAction>
#include <QKeyEvent>
......@@ -51,7 +52,7 @@ bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Ev
QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object);
if(!object)
return false;
switch(Event->type())
{
case QEvent::KeyPress:
......@@ -74,8 +75,26 @@ bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Ev
{
onActivate(object);
}
QToolButton* toolButton = qobject_cast<QToolButton*>(object);
if(toolButton &&
e->button() == Qt::LeftButton &&
object->rect().contains(e->pos()) &&
toolButton->menu())
{
onActivate(object);
}
}
break;
case QEvent::Timer:
{
QToolButton* tButton = qobject_cast<QToolButton*>(object);
if(tButton &&
tButton->popupMode() == QToolButton::DelayedPopup)
{
emit recordEvent(object, "longActivate", "");
}
}
break;
break;
case QEvent::MouseButtonRelease:
{
QMouseEvent* const e = static_cast<QMouseEvent*>(Event);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment