Commit 0c3d8350 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] networkEditor now opens the standard add-module menu when pressing...

[ADD] networkEditor now opens the standard add-module menu when pressing middle mouse button or by double clicking while pressing ctrl or shift. Additionally improved the filter to interpret the filter text in a tokenized way (space is delimiter).
parent 1a058f9d
......@@ -81,6 +81,30 @@ public:
*/
virtual ~WQtCombinerActionList();
/**
* Clears a hierarchy of QActions in a list. This deeply clears and deletes the lists.
*
* \param l the list to clear and delete
*/
static void deepDeleteActionList( QList< QAction* >& l ) // NOLINT - we need the non-const ref here.
{
// traverse
for( QList< QAction* >::iterator it = l.begin(); it != l.end(); ++it )
{
if( ( *it )->menu() )
{
// recursively remove sub-menu items
QList< QAction* > subs = ( *it )->menu()->actions();
deepDeleteActionList( subs );
}
delete ( *it );
}
// remove items afterwards
l.clear();
}
protected:
private:
};
......
......@@ -997,37 +997,13 @@ void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boos
}
}
/**
* Clears a hierarchy of QActions in a list. This deeply clears and deletes the lists.
*
* \param l the list to clear and delete
*/
void deepDeleteActionList( QList< QAction* >& l ) // NOLINT - we need the non-const ref here.
{
// traverse
for( QList< QAction* >::iterator it = l.begin(); it != l.end(); ++it )
{
if( ( *it )->menu() )
{
// recursively remove sub-menu items
QList< QAction* > subs = ( *it )->menu()->actions();
deepDeleteActionList( subs );
}
delete ( *it );
}
// remove items afterwards
l.clear();
}
void WQtControlPanel::createCompatibleButtons( boost::shared_ptr< WModule > module )
{
// we need to clean up the action lists
deepDeleteActionList( m_addModuleActionList );
deepDeleteActionList( m_connectWithPrototypeActionList );
deepDeleteActionList( m_connectWithModuleActionList );
deepDeleteActionList( m_disconnectActionList );
WQtCombinerActionList::deepDeleteActionList( m_addModuleActionList );
WQtCombinerActionList::deepDeleteActionList( m_connectWithPrototypeActionList );
WQtCombinerActionList::deepDeleteActionList( m_connectWithModuleActionList );
WQtCombinerActionList::deepDeleteActionList( m_disconnectActionList );
// acquire new action lists
m_connectWithPrototypeActionList = WQtCombinerActionList( this, m_mainWindow->getIconManager(),
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include "core/common/WLogger.h"
#include "core/common/WStringUtils.h"
#include "WQtMenuFiltered.h"
#include "WQtMenuFiltered.moc"
......@@ -113,7 +114,7 @@ void WQtMenuFiltered::hideEvent( QHideEvent* /* e */ )
void WQtMenuFiltered::filterUpdate()
{
QString filter = m_edit->text();
std::vector< std::string > filter = string_utils::tokenize( m_edit->text().toStdString() );
// NOTE: we ignore the first element. It is the filter widget.
......@@ -128,8 +129,16 @@ void WQtMenuFiltered::filterUpdate()
if( ( *a ) != NULL )
{
QString s = ( *a )->text();
// check each token in the filter
bool match = true;
for( std::vector< std::string >::const_iterator iter = filter.begin(); iter != filter.end(); ++iter )
{
match = match && s.contains( QString::fromStdString( *iter ), Qt::CaseInsensitive );
}
// match value against filter
if( s.contains( filter, Qt::CaseInsensitive ) )
if( match )
{
( *a )->setVisible( true );
nbLeft++;
......
......@@ -26,6 +26,11 @@
#include <QtGui/QWheelEvent>
#include "../../../core/common/WLogger.h"
#include "../../../core/kernel/WModuleFactory.h"
#include "../WQtCombinerActionList.h"
#include "../WQt4Gui.h"
#include "../WMainWindow.h"
#include "../guiElements/WQtMenuFiltered.h"
#include "WQtNetworkEditorView.h"
#include "WQtNetworkEditorView.moc"
......@@ -39,6 +44,13 @@ WQtNetworkEditorView::WQtNetworkEditorView( QWidget* parent ):
setCenter( QPointF( 0.0, 0.0 ) );
setResizeAnchor( QGraphicsView::AnchorUnderMouse );
// we need a list of all modules
m_addModuleActionList = WQtCombinerActionList( this, WQt4Gui::getMainWindow()->getIconManager(),
WModuleFactory::getModuleFactory()->getAllPrototypes(),
0, false );
m_addMenu = new WQtMenuFiltered( this );
m_addMenu->addActions( m_addModuleActionList );
}
void WQtNetworkEditorView::setCenter( const QPointF& centerPoint )
......@@ -74,7 +86,18 @@ void WQtNetworkEditorView::mouseDoubleClickEvent( QMouseEvent* event )
return;
}
emit loadAction();
// open the add menu when a modifier was pressed
if( ( event->modifiers() == Qt::ShiftModifier ) ||
( event->modifiers() == Qt::ControlModifier )
)
{
m_addMenu->popup( event->globalPos() );
}
else if ( event->modifiers() == Qt::NoModifier )
{
// plain double-click -> open file
emit loadAction();
}
}
void WQtNetworkEditorView::mousePressEvent( QMouseEvent* event )
......@@ -86,6 +109,13 @@ void WQtNetworkEditorView::mousePressEvent( QMouseEvent* event )
return;
}
// also ignore middle mouse button
if( event->button() == Qt::MidButton )
{
m_addMenu->popup( event->globalPos() );
return;
}
// for panning the view
m_lastPanPoint = event->pos();
setCursor( Qt::ClosedHandCursor );
......@@ -94,6 +124,13 @@ void WQtNetworkEditorView::mousePressEvent( QMouseEvent* event )
void WQtNetworkEditorView::mouseReleaseEvent( QMouseEvent* event )
{
// middle mouse button release: open add-menu
if( event->button() == Qt::MidButton )
{
return;
}
setCursor( Qt::ArrowCursor );
m_lastPanPoint = QPoint();
QGraphicsView::mouseReleaseEvent( event );
......
......@@ -133,6 +133,16 @@ private:
* To keep track of mouse movement, cache last known mouse event point
*/
QPoint m_lastPanPoint;
/**
* Action list
*/
WQtCombinerActionList m_addModuleActionList;
/**
* The menu containing the add actions in m_addModuleActionList.
*/
QMenu* m_addMenu;
};
#endif // WQTNETWORKEDITORVIEW_H
......
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