mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Style] Confirm broken Windows styles with a dialog offering Fusion (#7507)
* [Style] Confirm broken Windows styles with a dialog offering Fusion * [Style] Address review nits on broken style dialog Extract Fusion index lookup into findFusionIndex helper and add all message box buttons before choosing the default button. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
fec693ca2a
commit
bbf0425655
2 changed files with 90 additions and 10 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
@ -84,10 +85,9 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
const QString currentStyle = cfg.styleName;
|
const QString currentStyle = cfg.styleName;
|
||||||
const int styleSeedIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle);
|
const int styleSeedIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle);
|
||||||
styleCombo.setCurrentIndex(styleSeedIdx >= 0 ? styleSeedIdx : 0);
|
styleCombo.setCurrentIndex(styleSeedIdx >= 0 ? styleSeedIdx : 0);
|
||||||
|
previousStyle = styleCombo.currentData().toString();
|
||||||
|
|
||||||
connect(&styleCombo, &QComboBox::currentIndexChanged, this,
|
connect(&styleCombo, &QComboBox::currentIndexChanged, this, &AppearanceSettingsPage::styleComboChanged);
|
||||||
[this] { themeManager->setStyleName(styleCombo.currentData().toString()); });
|
|
||||||
connect(&styleCombo, &QComboBox::currentIndexChanged, this, &AppearanceSettingsPage::updateStyleWarning);
|
|
||||||
|
|
||||||
connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] {
|
connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] {
|
||||||
const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
||||||
|
|
@ -104,6 +104,7 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
const int styleIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle);
|
const int styleIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle);
|
||||||
styleCombo.setCurrentIndex(styleIdx >= 0 ? styleIdx : 0);
|
styleCombo.setCurrentIndex(styleIdx >= 0 ? styleIdx : 0);
|
||||||
styleCombo.blockSignals(false);
|
styleCombo.blockSignals(false);
|
||||||
|
previousStyle = styleCombo.currentData().toString();
|
||||||
|
|
||||||
updateStyleWarning();
|
updateStyleWarning();
|
||||||
});
|
});
|
||||||
|
|
@ -467,12 +468,88 @@ void AppearanceSettingsPage::updateHomeTabSettingsVisibility()
|
||||||
homeTabDisplayCardNameCheckBox.setVisible(visible);
|
homeTabDisplayCardNameCheckBox.setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isBrokenStyle(const QString &style)
|
||||||
|
{
|
||||||
|
return style.compare("windows11", Qt::CaseInsensitive) == 0 ||
|
||||||
|
style.compare("windowsvista", Qt::CaseInsensitive) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int findFusionIndex(const QComboBox &combo)
|
||||||
|
{
|
||||||
|
int fusionIdx = combo.findData(QStringLiteral("Fusion"));
|
||||||
|
if (fusionIdx >= 0) {
|
||||||
|
return fusionIdx;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < combo.count(); ++i) {
|
||||||
|
if (combo.itemData(i).toString().compare(QStringLiteral("Fusion"), Qt::CaseInsensitive) == 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void AppearanceSettingsPage::updateStyleWarning()
|
void AppearanceSettingsPage::updateStyleWarning()
|
||||||
{
|
{
|
||||||
const QString style = styleCombo.currentData().toString();
|
styleWarningLabel.setVisible(isBrokenStyle(styleCombo.currentData().toString()));
|
||||||
const bool broken =
|
}
|
||||||
style.compare("windows11", Qt::CaseInsensitive) == 0 || style.compare("windowsvista", Qt::CaseInsensitive) == 0;
|
|
||||||
styleWarningLabel.setVisible(broken);
|
void AppearanceSettingsPage::styleComboChanged(int index)
|
||||||
|
{
|
||||||
|
if (index < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString newStyle = styleCombo.itemData(index).toString();
|
||||||
|
if (!isBrokenStyle(newStyle)) {
|
||||||
|
themeManager->setStyleName(newStyle);
|
||||||
|
previousStyle = newStyle;
|
||||||
|
updateStyleWarning();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox msgBox(this);
|
||||||
|
msgBox.setWindowTitle(tr("Broken style"));
|
||||||
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
|
msgBox.setText(tr("The \"%1\" style is broken and can break the game view: dragging cards across zones can "
|
||||||
|
"shrink the board to a tiny grey window that can only be fixed by rejoining the game.")
|
||||||
|
.arg(newStyle));
|
||||||
|
msgBox.setInformativeText(
|
||||||
|
tr("It can also render controls such as combo boxes unreadable, especially in dark mode.\n\n"
|
||||||
|
"Fusion is the recommended style on every platform. Switch to Fusion instead?"));
|
||||||
|
|
||||||
|
int fusionIdx = findFusionIndex(styleCombo);
|
||||||
|
QPushButton *fusionButton = nullptr;
|
||||||
|
if (fusionIdx >= 0) {
|
||||||
|
fusionButton = msgBox.addButton(tr("Use Fusion instead"), QMessageBox::AcceptRole);
|
||||||
|
}
|
||||||
|
QPushButton *keepButton = msgBox.addButton(tr("Use %1 anyway").arg(newStyle), QMessageBox::DestructiveRole);
|
||||||
|
msgBox.addButton(QMessageBox::Cancel);
|
||||||
|
if (fusionButton != nullptr) {
|
||||||
|
msgBox.setDefaultButton(fusionButton);
|
||||||
|
} else {
|
||||||
|
msgBox.setDefaultButton(keepButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
msgBox.exec();
|
||||||
|
|
||||||
|
const QAbstractButton *clicked = msgBox.clickedButton();
|
||||||
|
if (fusionButton != nullptr && clicked == fusionButton) {
|
||||||
|
styleCombo.setCurrentIndex(fusionIdx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (clicked == keepButton) {
|
||||||
|
themeManager->setStyleName(newStyle);
|
||||||
|
previousStyle = newStyle;
|
||||||
|
updateStyleWarning();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel: revert to the previously applied style without re-prompting
|
||||||
|
styleCombo.blockSignals(true);
|
||||||
|
const int previousIdx = styleCombo.findData(previousStyle);
|
||||||
|
styleCombo.setCurrentIndex(previousIdx >= 0 ? previousIdx : 0);
|
||||||
|
styleCombo.blockSignals(false);
|
||||||
|
updateStyleWarning();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppearanceSettingsPage::showShortcutsChanged(QT_STATE_CHANGED_T value)
|
void AppearanceSettingsPage::showShortcutsChanged(QT_STATE_CHANGED_T value)
|
||||||
|
|
@ -538,9 +615,10 @@ void AppearanceSettingsPage::retranslateUi()
|
||||||
styleComboLabel.setText(tr("Active theme style:"));
|
styleComboLabel.setText(tr("Active theme style:"));
|
||||||
styleCombo.setToolTip(tr("Qt widget style saved to this theme (\"System\" lets the application decide)"));
|
styleCombo.setToolTip(tr("Qt widget style saved to this theme (\"System\" lets the application decide)"));
|
||||||
styleWarningLabel.setText(
|
styleWarningLabel.setText(
|
||||||
tr("Warning: the Windows 11 and Windows Vista styles are buggy and can render controls such as combo boxes "
|
tr("Warning: the Windows 11 and Windows Vista styles are broken and can break the game view (dragging "
|
||||||
"unreadable, especially in dark mode. Fusion is the recommended style on every platform: it is Qt's "
|
"cards can shrink the board to a tiny grey window that requires rejoining to fix), and can render "
|
||||||
"cross-platform style and the one Cockatrice is developed against."));
|
"controls such as combo boxes unreadable, especially in dark mode. Fusion is the recommended style on "
|
||||||
|
"every platform: it is Qt's cross-platform style and the one Cockatrice is developed against."));
|
||||||
updateStyleWarning();
|
updateStyleWarning();
|
||||||
editPaletteButton.setText(tr("Edit theme palette"));
|
editPaletteButton.setText(tr("Edit theme palette"));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ private slots:
|
||||||
void editPalette();
|
void editPalette();
|
||||||
void updateHomeTabSettingsVisibility();
|
void updateHomeTabSettingsVisibility();
|
||||||
void updateStyleWarning();
|
void updateStyleWarning();
|
||||||
|
void styleComboChanged(int index);
|
||||||
void showShortcutsChanged(QT_STATE_CHANGED_T enabled);
|
void showShortcutsChanged(QT_STATE_CHANGED_T enabled);
|
||||||
void overrideAllCardArtWithPersonalPreferenceToggled(QT_STATE_CHANGED_T enabled);
|
void overrideAllCardArtWithPersonalPreferenceToggled(QT_STATE_CHANGED_T enabled);
|
||||||
|
|
||||||
|
|
@ -40,6 +41,7 @@ private:
|
||||||
QComboBox styleCombo;
|
QComboBox styleCombo;
|
||||||
QLabel styleWarningLabel;
|
QLabel styleWarningLabel;
|
||||||
QPushButton editPaletteButton;
|
QPushButton editPaletteButton;
|
||||||
|
QString previousStyle;
|
||||||
|
|
||||||
QLabel homeTabBackgroundSourceLabel;
|
QLabel homeTabBackgroundSourceLabel;
|
||||||
QComboBox homeTabBackgroundSourceBox;
|
QComboBox homeTabBackgroundSourceBox;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue