mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-10-26 01:20:39 -05:00
Fix tab retranslation (#7580)
* Retranslate all open tabs on language change * Address review: deeper Visual DB retranslation, index-based Archidekt size logic In Qt 6, setItemText() on the current item emits currentTextChanged but not currentIndexChanged, so connecting the Archidekt combos to currentTextChanged fired a search on every language change. Both combos now use currentIndexChanged, and buildSearchUrl() compares the size-logic combo by index so translated labels cannot drop sizeLogic. * Derive display mode button text in one place
This commit is contained in:
@@ -220,9 +220,9 @@ void TabArchidekt::setupFilterWidgets()
|
||||
// Advanced filters (in secondary toolbar)
|
||||
|
||||
// EDH Bracket
|
||||
auto *bracketLabel = new QLabel(tr("Bracket:"), secondaryToolbar);
|
||||
bracketLabel = new QLabel(secondaryToolbar);
|
||||
edhBracketCombo = new QComboBox(secondaryToolbar);
|
||||
edhBracketCombo->addItem(tr("Any"));
|
||||
edhBracketCombo->addItem(QString());
|
||||
edhBracketCombo->addItems({"1", "2", "3", "4", "5"});
|
||||
edhBracketCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||
|
||||
@@ -276,7 +276,6 @@ void TabArchidekt::setupFilterWidgets()
|
||||
sizeLayout->setContentsMargins(4, 4, 4, 4);
|
||||
|
||||
minDeckSizeSpin = new QSpinBox(sizeContainer);
|
||||
minDeckSizeSpin->setSpecialValueText(tr("Any"));
|
||||
minDeckSizeSpin->setRange(0, 200);
|
||||
minDeckSizeSpin->setValue(0);
|
||||
|
||||
@@ -284,7 +283,8 @@ void TabArchidekt::setupFilterWidgets()
|
||||
minDeckSizeLogicCombo->addItems({"Exact", "≥", "≤"});
|
||||
minDeckSizeLogicCombo->setCurrentIndex(1);
|
||||
|
||||
sizeLayout->addWidget(new QLabel(tr("Cards:"), sizeContainer));
|
||||
cardsLabel = new QLabel(sizeContainer);
|
||||
sizeLayout->addWidget(cardsLabel);
|
||||
sizeLayout->addWidget(minDeckSizeSpin);
|
||||
sizeLayout->addWidget(minDeckSizeLogicCombo);
|
||||
|
||||
@@ -341,9 +341,9 @@ void TabArchidekt::connectSignals()
|
||||
});
|
||||
|
||||
// Format filters trigger search
|
||||
connect(edhBracketCombo, &QComboBox::currentTextChanged, this, &TabArchidekt::doSearch);
|
||||
connect(edhBracketCombo, &QComboBox::currentIndexChanged, this, &TabArchidekt::doSearch);
|
||||
connect(minDeckSizeSpin, qOverload<int>(&QSpinBox::valueChanged), this, &TabArchidekt::doSearch);
|
||||
connect(minDeckSizeLogicCombo, &QComboBox::currentTextChanged, this, &TabArchidekt::doSearch);
|
||||
connect(minDeckSizeLogicCombo, &QComboBox::currentIndexChanged, this, &TabArchidekt::doSearch);
|
||||
|
||||
// Allow Enter key in text fields to trigger search
|
||||
connect(nameField, &QLineEdit::returnPressed, this, &TabArchidekt::doSearchImmediate);
|
||||
@@ -393,8 +393,15 @@ void TabArchidekt::retranslateUi()
|
||||
commandersField->setPlaceholderText(tr("Commander..."));
|
||||
deckTagNameField->setPlaceholderText(tr("Tag..."));
|
||||
|
||||
bracketLabel->setText(tr("Bracket:"));
|
||||
// Index 0 is the "Any" placeholder added in setupFilterWidgets()
|
||||
edhBracketCombo->setItemText(0, tr("Any"));
|
||||
|
||||
formatButton->setButtonText(tr("Formats"));
|
||||
deckSizeButton->setButtonText(tr("Deck Size"));
|
||||
cardsLabel->setText(tr("Cards:"));
|
||||
minDeckSizeSpin->setSpecialValueText(tr("Any"));
|
||||
minDeckSizeLogicCombo->setItemText(0, tr("Exact"));
|
||||
|
||||
searchButton->setText(tr("Search"));
|
||||
|
||||
@@ -484,13 +491,17 @@ QString TabArchidekt::buildSearchUrl()
|
||||
query.addQueryItem("size", QString::number(minDeckSizeSpin->value()));
|
||||
|
||||
QString logic = "GTE";
|
||||
QString selected = minDeckSizeLogicCombo->currentText();
|
||||
if (selected == "≥") {
|
||||
logic = "GTE";
|
||||
} else if (selected == "≤") {
|
||||
logic = "LTE";
|
||||
} else {
|
||||
logic = "";
|
||||
// Index order matches setupFilterWidgets(): 0 = Exact, 1 = ≥, 2 = ≤
|
||||
switch (minDeckSizeLogicCombo->currentIndex()) {
|
||||
case 1:
|
||||
logic = "GTE";
|
||||
break;
|
||||
case 2:
|
||||
logic = "LTE";
|
||||
break;
|
||||
default:
|
||||
logic = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!logic.isEmpty()) {
|
||||
|
||||
@@ -287,9 +287,11 @@ private:
|
||||
|
||||
SettingsButtonWidget *formatButton; ///< Collapsible button for format filters
|
||||
QVector<QCheckBox *> formatChecks; ///< Individual checkboxes for each format
|
||||
QLabel *bracketLabel; ///< Label for EDH bracket selection
|
||||
QComboBox *edhBracketCombo; ///< Dropdown for EDH bracket selection
|
||||
|
||||
SettingsButtonWidget *deckSizeButton; ///< Collapsible button for deck size filter
|
||||
QLabel *cardsLabel; ///< Label for deck size selection
|
||||
QSpinBox *minDeckSizeSpin; ///< Spinner to select minimum deck size
|
||||
QComboBox *minDeckSizeLogicCombo; ///< Combo box for size comparison logic
|
||||
|
||||
@@ -300,4 +302,4 @@ private:
|
||||
CardInfoPtr cardToQuery; ///< Optional pre-selected card for initial filtering
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_TAB_ARCHIDEKT_H
|
||||
#endif // COCKATRICE_TAB_ARCHIDEKT_H
|
||||
|
||||
@@ -51,8 +51,6 @@
|
||||
#include <QDebug>
|
||||
#include <QFlag>
|
||||
#include <QIcon>
|
||||
#include <QListIterator>
|
||||
#include <QMapIterator>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMessageLogger>
|
||||
@@ -292,49 +290,11 @@ void TabSupervisor::retranslateUi()
|
||||
aTabDeveloper->setText(tr("Developer"));
|
||||
|
||||
// tabs
|
||||
QList<Tab *> tabs;
|
||||
tabs.append(tabHome);
|
||||
tabs.append(tabServer);
|
||||
tabs.append(tabReplays);
|
||||
tabs.append(tabDeckStorage);
|
||||
tabs.append(tabAdmin);
|
||||
tabs.append(tabAccount);
|
||||
tabs.append(tabLog);
|
||||
tabs.append(tabReport);
|
||||
tabs.append(tabModeration);
|
||||
tabs.append(tabCardArtRules);
|
||||
tabs.append(tabDeveloper);
|
||||
QMapIterator<int, TabRoom *> roomIterator(roomTabs);
|
||||
while (roomIterator.hasNext()) {
|
||||
tabs.append(roomIterator.next().value());
|
||||
}
|
||||
QMapIterator<int, TabGame *> gameIterator(gameTabs);
|
||||
while (gameIterator.hasNext()) {
|
||||
tabs.append(gameIterator.next().value());
|
||||
}
|
||||
QMapIterator<QString, TabPublicDecks *> publicDecksIterator(publicDecksTabs);
|
||||
while (publicDecksIterator.hasNext()) {
|
||||
tabs.append(publicDecksIterator.next().value());
|
||||
}
|
||||
QListIterator<TabGame *> replayIterator(replayTabs);
|
||||
while (replayIterator.hasNext()) {
|
||||
tabs.append(replayIterator.next());
|
||||
}
|
||||
QListIterator<AbstractTabDeckEditor *> deckEditorIterator(deckEditorTabs);
|
||||
while (deckEditorIterator.hasNext()) {
|
||||
tabs.append(deckEditorIterator.next());
|
||||
}
|
||||
QMapIterator<QString, TabMessage *> messageIterator(messageTabs);
|
||||
while (messageIterator.hasNext()) {
|
||||
tabs.append(messageIterator.next().value());
|
||||
}
|
||||
|
||||
for (auto &tab : tabs) {
|
||||
if (tab) {
|
||||
int idx = indexOf(tab);
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
if (auto *tab = qobject_cast<Tab *>(widget(i))) {
|
||||
QString tabText = tab->getTabText();
|
||||
setTabText(idx, sanitizeTabName(tabText));
|
||||
setTabToolTip(idx, sanitizeHtml(tabText));
|
||||
setTabText(i, sanitizeTabName(tabText));
|
||||
setTabToolTip(i, sanitizeHtml(tabText));
|
||||
tab->retranslateUi();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,10 @@ TabVisualDatabaseDisplay::TabVisualDatabaseDisplay(TabSupervisor *_tabSupervisor
|
||||
|
||||
void TabVisualDatabaseDisplay::retranslateUi()
|
||||
{
|
||||
visualDatabaseDisplayWidget->retranslateUi();
|
||||
}
|
||||
|
||||
void TabVisualDatabaseDisplay::openEdhrecTab(const CardInfoPtr &info, bool isCommander) const
|
||||
{
|
||||
getTabSupervisor()->addEdhrecTab(info, isCommander);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ VisualDatabaseDisplayWidget::VisualDatabaseDisplayWidget(QWidget *parent,
|
||||
setFocusProxy(searchEdit);
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
|
||||
displayModeButton = new QPushButton(tr("Visual"), this);
|
||||
displayModeButton = new QPushButton(this);
|
||||
displayModeButton->setCheckable(true); // Toggle button
|
||||
|
||||
connect(displayModeButton, &QPushButton::toggled, this, &VisualDatabaseDisplayWidget::onDisplayModeChanged);
|
||||
@@ -262,6 +262,10 @@ void VisualDatabaseDisplayWidget::retranslateUi()
|
||||
{
|
||||
databaseLoadIndicator->setText(tr("Loading database ..."));
|
||||
clearFilterWidget->setToolTip(tr("Clear all filters"));
|
||||
searchEdit->setPlaceholderText(tr("Search by card name (or search expressions)"));
|
||||
updateDisplayModeButton();
|
||||
colorFilterWidget->retranslateUi();
|
||||
filterContainer->retranslateUi();
|
||||
}
|
||||
|
||||
void VisualDatabaseDisplayWidget::highlightAllSearchEdit()
|
||||
@@ -269,6 +273,11 @@ void VisualDatabaseDisplayWidget::highlightAllSearchEdit()
|
||||
searchEdit->setSelection(0, searchEdit->text().length());
|
||||
}
|
||||
|
||||
void VisualDatabaseDisplayWidget::updateDisplayModeButton()
|
||||
{
|
||||
displayModeButton->setText(displayModeButton->isChecked() ? tr("Table") : tr("Visual"));
|
||||
}
|
||||
|
||||
void VisualDatabaseDisplayWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QWidget::resizeEvent(event);
|
||||
@@ -277,16 +286,15 @@ void VisualDatabaseDisplayWidget::resizeEvent(QResizeEvent *event)
|
||||
|
||||
void VisualDatabaseDisplayWidget::onDisplayModeChanged(bool checked)
|
||||
{
|
||||
updateDisplayModeButton();
|
||||
if (checked) {
|
||||
// Table mode
|
||||
displayModeButton->setText(tr("Table"));
|
||||
flowWidget->setVisible(false);
|
||||
cardSizeWidget->setVisible(false);
|
||||
databaseView->setItemDelegate(new QStyledItemDelegate(databaseView));
|
||||
databaseView->setVisible(true);
|
||||
} else {
|
||||
// Visual mode
|
||||
displayModeButton->setText(tr("Visual"));
|
||||
flowWidget->setVisible(true);
|
||||
cardSizeWidget->setVisible(true);
|
||||
databaseView->setVisible(false);
|
||||
|
||||
@@ -145,6 +145,7 @@ private:
|
||||
|
||||
void initializeFilters();
|
||||
void highlightAllSearchEdit();
|
||||
void updateDisplayModeButton();
|
||||
bool nearEndOfPage() const;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user