From d918b29be7ba7a9b200dc396dd76627c7a8232fa Mon Sep 17 00:00:00 2001 From: Benjamin Long Date: Mon, 30 Jan 2012 13:35:10 -0500 Subject: [PATCH] Add QtoolButton long click --- pqAbstractActivateEventPlayer.cxx | 24 ++++++++++++++++++------ pqAbstractButtonEventTranslator.cxx | 23 +++++++++++++++++++++-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/pqAbstractActivateEventPlayer.cxx b/pqAbstractActivateEventPlayer.cxx index 121fdc0..c8b0a80 100644 --- a/pqAbstractActivateEventPlayer.cxx +++ b/pqAbstractActivateEventPlayer.cxx @@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #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(Object)) { @@ -109,7 +110,6 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, else if(QMenu* menu = qobject_cast(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(Object)) { - object->click(); - //QApplication::processEvents(); - return true; + if (Command == "activate") + { + object->click(); + //QApplication::processEvents(); + return true; + } + if(Command == "longActivate") + { + QToolButton* tButton = qobject_cast(Object); + if(tButton) + { + tButton->showMenu(); + return true; + } + } } if (QAction* const action = qobject_cast(Object)) diff --git a/pqAbstractButtonEventTranslator.cxx b/pqAbstractButtonEventTranslator.cxx index 8670fb8..04a0b3a 100644 --- a/pqAbstractButtonEventTranslator.cxx +++ b/pqAbstractButtonEventTranslator.cxx @@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqAbstractButtonEventTranslator.h" +#include #include #include #include @@ -51,7 +52,7 @@ bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Ev QAbstractButton* const object = qobject_cast(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(object); + if(toolButton && + e->button() == Qt::LeftButton && + object->rect().contains(e->pos()) && + toolButton->menu()) + { + onActivate(object); + } + } + break; + case QEvent::Timer: + { + QToolButton* tButton = qobject_cast(object); + if(tButton && + tButton->popupMode() == QToolButton::DelayedPopup) + { + emit recordEvent(object, "longActivate", ""); + } } - break; + break; case QEvent::MouseButtonRelease: { QMouseEvent* const e = static_cast(Event); -- GitLab