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. ...@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QMenuBar> #include <QMenuBar>
#include <QPushButton> #include <QPushButton>
#include <QtDebug> #include <QtDebug>
#include <QToolButton>
#include "pqEventDispatcher.h" #include "pqEventDispatcher.h"
...@@ -52,8 +53,8 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, ...@@ -52,8 +53,8 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
const QString& Arguments, const QString& Arguments,
bool& Error) bool& Error)
{ {
if(Command != "activate") if(Command != "activate" && Command != "longActivate")
return false; return false;
if (QMenuBar* const menu_bar = qobject_cast<QMenuBar*>(Object)) if (QMenuBar* const menu_bar = qobject_cast<QMenuBar*>(Object))
{ {
...@@ -109,7 +110,6 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, ...@@ -109,7 +110,6 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
else if(QMenu* menu = qobject_cast<QMenu*>(p)) else if(QMenu* menu = qobject_cast<QMenu*>(p))
{ {
menu->setActiveAction(next->menuAction()); menu->setActiveAction(next->menuAction());
int max_wait = 0; int max_wait = 0;
while(!next->isVisible() && (++max_wait) <= 2) while(!next->isVisible() && (++max_wait) <= 2)
{ {
...@@ -135,9 +135,21 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, ...@@ -135,9 +135,21 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
if(QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object)) if(QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object))
{ {
object->click(); if (Command == "activate")
//QApplication::processEvents(); {
return true; 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)) if (QAction* const action = qobject_cast<QAction*>(Object))
......
...@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqAbstractButtonEventTranslator.h" #include "pqAbstractButtonEventTranslator.h"
#include <QDebug>
#include <QAbstractButton> #include <QAbstractButton>
#include <QAction> #include <QAction>
#include <QKeyEvent> #include <QKeyEvent>
...@@ -51,7 +52,7 @@ bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Ev ...@@ -51,7 +52,7 @@ bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Ev
QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object); QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object);
if(!object) if(!object)
return false; return false;
switch(Event->type()) switch(Event->type())
{ {
case QEvent::KeyPress: case QEvent::KeyPress:
...@@ -74,8 +75,26 @@ bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Ev ...@@ -74,8 +75,26 @@ bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Ev
{ {
onActivate(object); 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: case QEvent::MouseButtonRelease:
{ {
QMouseEvent* const e = static_cast<QMouseEvent*>(Event); 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