28 #include <QToolButton>
30 #include "core/common/WLogger.h"
31 #include "core/common/WStringUtils.h"
33 #include "WQtMenuFiltered.h"
42 QMenu( title, parent )
55 QWidget* widget =
new QWidget( to );
56 QHBoxLayout* layout =
new QHBoxLayout( widget );
57 widget->setLayout( layout );
59 QLabel* label =
new QLabel(
"Filter:", widget );
60 to->
m_edit =
new QLineEdit( widget );
63 layout->addWidget( label );
64 layout->addWidget( to->
m_edit );
67 QToolButton* cfg =
new QToolButton();
68 cfg->setDefaultAction( config );
69 cfg->setToolButtonStyle( Qt::ToolButtonIconOnly );
70 cfg->setAutoRaise(
true );
71 layout->addWidget( cfg );
75 QWidgetAction* action =
new QWidgetAction( to );
76 action->setDefaultWidget( widget );
77 to->addAction( action );
83 connect( to->
m_edit, SIGNAL( textChanged(
const QString& ) ), to, SLOT(
filterUpdate() ) );
93 if( ( ( e->key() >= Qt::Key_A ) && ( e->key() <= Qt::Key_Z ) ) ||
94 ( ( e->key() >= Qt::Key_0 ) && ( e->key() <= Qt::Key_9 ) ) ||
95 ( e->key() == Qt::Key_Underscore ) ||
96 ( e->key() == Qt::Key_Space ) ||
97 ( e->key() == Qt::Key_Minus ) ||
98 ( e->key() == Qt::Key_Plus )
103 else if( ( e->key() == Qt::Key_Backspace ) )
107 else if( ( e->key() == Qt::Key_Escape ) )
109 if(
m_edit->text() !=
"" )
114 QMenu::keyPressEvent( e );
120 QMenu::hideEvent( e );
131 Actions allActions = this->actions();
133 QAction* lastVisibleAction = NULL;
134 for( Actions::const_iterator a = allActions.begin() + 1; a != allActions.end(); ++a )
139 QString s = ( *a )->text();
143 for( std::vector< std::string >::const_iterator iter = filter.begin(); iter != filter.end(); ++iter )
145 match = match && s.contains( QString::fromStdString( *iter ), Qt::CaseInsensitive );
152 ( *a )->setDisabled(
false );
154 ( *a )->setVisible(
true );
157 lastVisibleAction = *a;
162 ( *a )->setDisabled(
true );
164 ( *a )->setVisible(
false );
173 setActiveAction( lastVisibleAction );
std::vector< std::string > tokenize(const std::string &source, const std::string &delim=WHITESPACE, bool compress=true)
Splits the given string into a vector of strings (so called tokens).