Minor fixes to search

Took 13 minutes
This commit is contained in:
Lukas Brübach 2026-08-08 20:14:26 +02:00
parent 8072eef462
commit 622e661499
4 changed files with 37 additions and 21 deletions

View file

@ -154,7 +154,11 @@ void DlgSettings::setupUi()
connect(searchResultsView, &QListView::clicked, this, &DlgSettings::onSearchResultClicked);
connect(&SettingsCache::instance(), &SettingsCache::themeChanged, this, [this] {
searchDelegate->setPageIcons(pageIconResources());
const QStringList icons = pageIconResources();
for (int i = 0; i < tabButtons.size() && i < icons.size(); ++i) {
tabButtons[i]->setIcon(QPixmap(icons[i]));
}
searchDelegate->setPageIcons(icons);
searchResultsView->viewport()->update();
});
@ -391,9 +395,13 @@ void DlgSettings::navigateToSearchResult(const QModelIndex &index)
// Scroll to the widget, focus it, and flash to highlight it
if (entry.widget) {
QScrollArea *scrollArea = qobject_cast<QScrollArea *>(pagesWidget->currentWidget());
if (scrollArea) {
scrollArea->ensureWidgetVisible(entry.widget);
QWidget *widget = entry.widget;
while (widget) {
if (auto *scrollArea = qobject_cast<QScrollArea *>(widget)) {
scrollArea->ensureWidgetVisible(entry.widget);
break;
}
widget = widget->parentWidget();
}
entry.widget->setFocus();
flashWidget(entry.widget);
@ -423,8 +431,10 @@ bool DlgSettings::eventFilter(QObject *watched, QEvent *event)
return true;
}
} else if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) {
if (searchActive && searchResultsView->currentIndex().isValid()) {
navigateToSearchResult(searchResultsView->currentIndex());
if (searchActive) {
if (searchResultsView->currentIndex().isValid()) {
navigateToSearchResult(searchResultsView->currentIndex());
}
return true;
}
} else if (keyEvent->key() == Qt::Key_Down) {

View file

@ -3,7 +3,6 @@
#include "settings_search_model.h"
#include <QCheckBox>
#include <QComboBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
@ -56,8 +55,8 @@ static bool isValidSettingLabel(const QLabel *label)
* @brief Finds the control associated with a setting label
*
* Uses the explicit buddy if set, otherwise the widget in the cell (or slot)
* immediately following the label within the same layout. Falls back to the
* label itself when no obvious control is found.
* immediately following the label within the same layout. Returns nullptr when
* no obvious control is found.
*/
static QWidget *controlForLabel(QLabel *label, QLayout *containingLayout)
{
@ -92,14 +91,16 @@ static QWidget *controlForLabel(QLabel *label, QLayout *containingLayout)
}
}
return label;
return nullptr;
}
/**
* @brief Builds the extended search text for an entry
*
* Combines the group title, label, and any extra searchable text derived from
* the associated control (tooltip, placeholder, prefix/suffix, combo text).
* the associated control (placeholder, prefix/suffix, tooltip). Combo values
* and numeric tooltips are excluded since they change at runtime and would
* make the search index stale.
*/
static QString buildFullSearchText(const QString &groupTitle, const QString &cleanLabel, QWidget *control)
{
@ -110,11 +111,13 @@ static QString buildFullSearchText(const QString &groupTitle, const QString &cle
} else if (auto *spinBox = qobject_cast<QSpinBox *>(control)) {
parts.append(spinBox->prefix());
parts.append(spinBox->suffix());
} else if (auto *comboBox = qobject_cast<QComboBox *>(control)) {
parts.append(comboBox->currentText());
}
if (!control->toolTip().isEmpty()) {
parts.append(control->toolTip());
bool isNumeric = false;
control->toolTip().toInt(&isNumeric);
if (!isNumeric) {
parts.append(control->toolTip());
}
}
}
parts.removeAll(QString());
@ -176,15 +179,16 @@ QList<SettingsSearchEntry> AbstractSettingsPage::autoDetectSearchEntries(QWidget
QWidget *control = widget;
if (auto *labelWidget = qobject_cast<QLabel *>(widget)) {
control = controlForLabel(labelWidget, pair.second);
if (!control) {
continue;
}
}
SettingsSearchEntry entry;
entry.pageIndex = pageIndex;
entry.groupTitle = groupTitle;
entry.widgetLabel = cleanLabel;
entry.widget = control;
entry.fullSearchText = buildFullSearchText(groupTitle, cleanLabel, control);
entries.append(entry);
entries.append(SettingsSearchEntry{.pageIndex = pageIndex,
.groupTitle = groupTitle,
.widgetLabel = cleanLabel,
.fullSearchText = buildFullSearchText(groupTitle, cleanLabel, control),
.widget = control});
}
}

View file

@ -90,6 +90,7 @@ MessagesSettingsPage::MessagesSettingsPage()
highlightNotice->addWidget(&hexHighlightLabel, 1, 2);
highlightNotice->addWidget(customAlertString, 0, 0);
highlightNotice->addWidget(&customAlertStringLabel, 1, 0);
customAlertStringLabel.setBuddy(customAlertString);
highlightGroupBox = new QGroupBox;
highlightGroupBox->setLayout(highlightNotice);

View file

@ -123,6 +123,7 @@ void ShortcutSettingsPage::retranslateUi()
currentActionGroupLabel->setText(tr("Section:"));
currentActionLabel->setText(tr("Action:"));
currentShortcutLabel->setText(tr("Shortcut:"));
editShortcutGroupBox->setTitle(tr("Shortcut editor"));
editTextBox->retranslateUi();
faqLabel->setText(QString("<a href='%1'>%2</a>").arg(WIKI_CUSTOM_SHORTCUTS).arg(tr("How to set custom shortcuts")));
btnResetAll->setText(tr("Restore all default shortcuts"));