From 622e6614992b417dd028276200c9df0eb872d406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sat, 8 Aug 2026 20:14:26 +0200 Subject: [PATCH] Minor fixes to search Took 13 minutes --- .../widgets/dialogs/dlg_settings.cpp | 22 ++++++++---- .../settings_page/abstract_settings_page.cpp | 34 +++++++++++-------- .../settings_page/messages_settings_page.cpp | 1 + .../settings_page/shortcut_settings_page.cpp | 1 + 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp index 8a8573818..883cfcd03 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp @@ -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(pagesWidget->currentWidget()); - if (scrollArea) { - scrollArea->ensureWidgetVisible(entry.widget); + QWidget *widget = entry.widget; + while (widget) { + if (auto *scrollArea = qobject_cast(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) { diff --git a/cockatrice/src/interface/widgets/settings_page/abstract_settings_page.cpp b/cockatrice/src/interface/widgets/settings_page/abstract_settings_page.cpp index 542d48c04..9a70e94c5 100644 --- a/cockatrice/src/interface/widgets/settings_page/abstract_settings_page.cpp +++ b/cockatrice/src/interface/widgets/settings_page/abstract_settings_page.cpp @@ -3,7 +3,6 @@ #include "settings_search_model.h" #include -#include #include #include #include @@ -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(control)) { parts.append(spinBox->prefix()); parts.append(spinBox->suffix()); - } else if (auto *comboBox = qobject_cast(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 AbstractSettingsPage::autoDetectSearchEntries(QWidget QWidget *control = widget; if (auto *labelWidget = qobject_cast(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}); } } diff --git a/cockatrice/src/interface/widgets/settings_page/messages_settings_page.cpp b/cockatrice/src/interface/widgets/settings_page/messages_settings_page.cpp index e9878434b..e4f24ab73 100644 --- a/cockatrice/src/interface/widgets/settings_page/messages_settings_page.cpp +++ b/cockatrice/src/interface/widgets/settings_page/messages_settings_page.cpp @@ -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); diff --git a/cockatrice/src/interface/widgets/settings_page/shortcut_settings_page.cpp b/cockatrice/src/interface/widgets/settings_page/shortcut_settings_page.cpp index e3b9994ea..1f1867f7c 100644 --- a/cockatrice/src/interface/widgets/settings_page/shortcut_settings_page.cpp +++ b/cockatrice/src/interface/widgets/settings_page/shortcut_settings_page.cpp @@ -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("%2").arg(WIKI_CUSTOM_SHORTCUTS).arg(tr("How to set custom shortcuts"))); btnResetAll->setText(tr("Restore all default shortcuts"));