From: stv Date: Thu, 27 Mar 2008 12:24:20 +0000 (+0000) Subject: Tooltips and status tips for actions in the drop down list. X-Git-Tag: V5_0_0a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c84258630e557d54771f3aa89d39f26a856d6b83;p=modules%2Fgui.git Tooltips and status tips for actions in the drop down list. --- diff --git a/src/Qtx/QtxMultiAction.cxx b/src/Qtx/QtxMultiAction.cxx index 37b8f440a..88e2b764b 100644 --- a/src/Qtx/QtxMultiAction.cxx +++ b/src/Qtx/QtxMultiAction.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,57 @@ public: } }; +/*! + \class QtxMultiAction::Menu + \brief Custom menu to be used with the toolbuttons as drop down list. + \internal +*/ + +class QtxMultiAction::Menu : public QMenu +{ +public: + //! \brief Constructor + Menu( QWidget* parent = 0 ) : QMenu( parent ) {} + //! \brief Destructor + ~Menu() {}; + +protected: + //! \brief Paint the button + virtual bool event( QEvent* e ) + { + bool res = false; + switch ( e->type() ) + { + case QEvent::ToolTip: + case QEvent::WhatsThis: + case QEvent::QueryWhatsThis: + { + QHelpEvent* help = static_cast( e ); + QWidget* w = QApplication::widgetAt( help->globalPos() ); + if ( w && Qtx::isParent( w, this ) ) + { + QHelpEvent he( help->type(), w->mapFromGlobal( help->globalPos() ), help->globalPos() ); + QApplication::sendEvent( w, &he ); + res = true; + } + } + break; + case QEvent::StatusTip: + case QEvent::WhatsThisClicked: + if ( parentWidget() ) + { + QApplication::sendEvent( parentWidget(), e ); + res = true; + } + break; + default: + res = QMenu::event( e ); + break; + } + return res; + } +}; + /*! \class QtxMultiAction::Button \brief Custom button to be used in the toolbar. @@ -170,7 +222,8 @@ QtxMultiAction::~QtxMultiAction() */ void QtxMultiAction::setActiveAction( QAction* a ) { - if ( a && actions().contains( a ) && a != myCurrent && a->isEnabled() ) { + if ( a && actions().contains( a ) && a != myCurrent && a->isEnabled() ) + { myCurrent = a; updateAction(); } @@ -276,7 +329,8 @@ QWidget* QtxMultiAction::createWidget( QWidget* parent ) return 0; QToolButton* w = new Button( tb ); - w->setMenu( new QMenu( w ) ); + w->setMenu( new Menu( w ) ); + w->setMouseTracking( true ); w->setFocusPolicy( Qt::NoFocus ); w->setIconSize( tb->iconSize() ); w->setToolButtonStyle( tb->toolButtonStyle() ); @@ -352,6 +406,7 @@ void QtxMultiAction::updateButton( QToolButton* btn ) QToolButton* b = new QToolButton( pm ); b->setDefaultAction( *itr ); b->setToolTip( (*itr)->toolTip() ); + b->setStatusTip( (*itr)->statusTip() ); b->setAutoRaise( true ); b->setIconSize( btn->iconSize() ); b->setToolButtonStyle( btn->toolButtonStyle() ); diff --git a/src/Qtx/QtxMultiAction.h b/src/Qtx/QtxMultiAction.h index 07bb3e062..a4d9683bd 100644 --- a/src/Qtx/QtxMultiAction.h +++ b/src/Qtx/QtxMultiAction.h @@ -31,6 +31,7 @@ class QTX_EXPORT QtxMultiAction : public QtxActionSet { Q_OBJECT + class Menu; class Button; class Filter;