From: Anthony Geay Date: Wed, 24 Feb 2016 11:00:46 +0000 (+0100) Subject: Better with context menu. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b0a9b1c284d79d22ddace2d92862073eea508e9e;p=modules%2Fgui.git Better with context menu. --- diff --git a/src/PyConsoleBase/PyConsole_ConsoleBase.cxx b/src/PyConsoleBase/PyConsole_ConsoleBase.cxx index 6500ed86e..306dd998c 100644 --- a/src/PyConsoleBase/PyConsole_ConsoleBase.cxx +++ b/src/PyConsoleBase/PyConsole_ConsoleBase.cxx @@ -40,6 +40,7 @@ #include #include #include +#include #include PyConsole_EditorBase *PyConsole_ConsoleBase::PyConsole_Interp_CreatorBase::createEditor( PyConsole_Interp *interp, PyConsole_ConsoleBase *console ) const @@ -383,3 +384,30 @@ PyConsole_EnhConsoleBase::PyConsole_EnhConsoleBase( QWidget* parent, PyConsole_I PyConsole_Interp_EnhCreatorBase crea; defaultConstructor(interp,crea); } + +/*! + \brief Event handler. + + Handles context menu request event. + + \param o object + \param e event + \return True if the event is processed and further processing should be stopped +*/ +bool PyConsole_EnhConsoleBase::eventFilter( QObject* o, QEvent* e ) +{ + if ( o == myEditor->viewport() && e->type() == QEvent::ContextMenu ) + { + contextMenuRequest( (QContextMenuEvent*)e ); + return true; + } + return QWidget::eventFilter( o, e ); +} + +void PyConsole_EnhConsoleBase::contextMenuRequest( QContextMenuEvent * e ) +{ + QMenu *menu(new QMenu(this)); + contextMenuPopup(menu); + menu->move(e->globalPos()); + menu->show(); +} diff --git a/src/PyConsoleBase/PyConsole_ConsoleBase.h b/src/PyConsoleBase/PyConsole_ConsoleBase.h index 001e981f1..b0a07273d 100644 --- a/src/PyConsoleBase/PyConsole_ConsoleBase.h +++ b/src/PyConsoleBase/PyConsole_ConsoleBase.h @@ -120,6 +120,8 @@ public: public: PyConsole_EnhConsoleBase( QWidget* parent, PyConsole_Interp* interp = 0 ); virtual ~PyConsole_EnhConsoleBase() {} + virtual bool eventFilter( QObject * o, QEvent * e ); + virtual void contextMenuRequest( QContextMenuEvent * e ) ; }; #endif // PYCONSOLE_CONSOLEBASE_H