]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Better with context menu.
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 24 Feb 2016 11:00:46 +0000 (12:00 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 24 Feb 2016 11:00:46 +0000 (12:00 +0100)
src/PyConsoleBase/PyConsole_ConsoleBase.cxx
src/PyConsoleBase/PyConsole_ConsoleBase.h

index 6500ed86e7c2ce5f09f11115f65cf360a80137d0..306dd998c6ec10aff11d60c34cba00375ffe90d1 100644 (file)
@@ -40,6 +40,7 @@
 #include <QClipboard>
 #include <QEvent>
 #include <QMenu>
+#include <QContextMenuEvent>
 #include <QVBoxLayout>
 
 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();
+}
index 001e981f140a82a72fe0d40be302f0ad02b68afe..b0a07273d6663bd4fd3b124a44890c7dc72e4fb4 100644 (file)
@@ -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