From 6d4343ca948d81d30698cf9442c84fc595bd2bed Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Mon, 6 Nov 2023 20:24:37 +0100 Subject: [PATCH] More prominent search (#6968) Make the search features more prominent by adding an icon with a magnifying glass to the line edits. Because there is no specific icon for "search" the same icon as for "zoom" is used. Make the "Search" text translatable in `PluginBrowser.cpp` and add a search icon. Make the search in the effects selection dialog more similar to the other ones by adding a search icon and a placeholder text and by enabling the clear button. Make some whitespace adjustments in the vicinity of the other adjustments. Use function pointers instead of signals and slots for some connections. Use a lambda for the slot in the file browser code because GCC does not compile if the parameters differ between the connected functions. It seems that it cannot deal with default parameters. It could be considered to create the search line edits in a factory although this would not work for the effects select dialog because its line edit is created in the UI file. In that case we'd have to add an additional method like `embellishLineEditForSearch(QLineEdit*)` or something similar to the factory. Fixes #6966. --- src/gui/FileBrowser.cpp | 11 ++++++----- src/gui/PluginBrowser.cpp | 7 ++++--- src/gui/modals/EffectSelectDialog.cpp | 13 +++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/gui/FileBrowser.cpp b/src/gui/FileBrowser.cpp index 74d8f755a..1be344c98 100644 --- a/src/gui/FileBrowser.cpp +++ b/src/gui/FileBrowser.cpp @@ -121,11 +121,12 @@ FileBrowser::FileBrowser(const QString & directories, const QString & filter, searchWidgetLayout->setContentsMargins(0, 0, 0, 0); searchWidgetLayout->setSpacing( 0 ); - m_filterEdit = new QLineEdit( searchWidget ); - m_filterEdit->setPlaceholderText( tr("Search") ); - m_filterEdit->setClearButtonEnabled( true ); - connect( m_filterEdit, SIGNAL( textEdited( const QString& ) ), - this, SLOT( filterAndExpandItems( const QString& ) ) ); + m_filterEdit = new QLineEdit(searchWidget); + m_filterEdit->setPlaceholderText(tr("Search")); + m_filterEdit->setClearButtonEnabled(true); + m_filterEdit->addAction(embed::getIconPixmap("zoom"), QLineEdit::LeadingPosition); + + connect(m_filterEdit, &QLineEdit::textEdited, [this](const QString & filter) { filterAndExpandItems(filter); }); auto reload_btn = new QPushButton(embed::getIconPixmap("reload"), QString(), searchWidget); reload_btn->setToolTip( tr( "Refresh list" ) ); diff --git a/src/gui/PluginBrowser.cpp b/src/gui/PluginBrowser.cpp index 7ba8bcc53..0217e3037 100644 --- a/src/gui/PluginBrowser.cpp +++ b/src/gui/PluginBrowser.cpp @@ -68,9 +68,10 @@ PluginBrowser::PluginBrowser( QWidget * _parent ) : hint->setWordWrap( true ); auto searchBar = new QLineEdit(m_view); - searchBar->setPlaceholderText( "Search" ); - searchBar->setMaxLength( 64 ); - searchBar->setClearButtonEnabled( true ); + searchBar->setPlaceholderText(tr("Search")); + searchBar->setMaxLength(64); + searchBar->setClearButtonEnabled(true); + searchBar->addAction(embed::getIconPixmap("zoom"), QLineEdit::LeadingPosition); m_descTree = new QTreeWidget( m_view ); m_descTree->setColumnCount( 1 ); diff --git a/src/gui/modals/EffectSelectDialog.cpp b/src/gui/modals/EffectSelectDialog.cpp index 31ffd7728..993052fab 100644 --- a/src/gui/modals/EffectSelectDialog.cpp +++ b/src/gui/modals/EffectSelectDialog.cpp @@ -98,12 +98,13 @@ EffectSelectDialog::EffectSelectDialog( QWidget * _parent ) : m_model.setSourceModel( &m_sourceModel ); m_model.setFilterCaseSensitivity( Qt::CaseInsensitive ); - connect( ui->filterEdit, SIGNAL( textChanged( const QString& ) ), - &m_model, SLOT( setFilterFixedString( const QString& ) ) ); - connect( ui->filterEdit, SIGNAL( textChanged( const QString& ) ), - this, SLOT(updateSelection())); - connect( ui->filterEdit, SIGNAL( textChanged( const QString& ) ), - SLOT(sortAgain())); + ui->filterEdit->setPlaceholderText(tr("Search")); + ui->filterEdit->setClearButtonEnabled(true); + ui->filterEdit->addAction(embed::getIconPixmap("zoom"), QLineEdit::LeadingPosition); + + connect(ui->filterEdit, &QLineEdit::textChanged, &m_model, &QSortFilterProxyModel::setFilterFixedString); + connect(ui->filterEdit, &QLineEdit::textChanged, this, &EffectSelectDialog::updateSelection); + connect(ui->filterEdit, &QLineEdit::textChanged, this, &EffectSelectDialog::sortAgain); ui->pluginList->setModel( &m_model );