From 4e2587cc62e8da53d7377c4deb5c2e7655b80216 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Tue, 19 Jul 2022 11:11:13 +0200 Subject: [PATCH] Core: Inline generalsettings.ui Change-Id: I8811728543cd7fb161b6df21dacc0fc23c6165a4 Reviewed-by: hjk --- src/libs/utils/layoutbuilder.h | 2 +- src/plugins/coreplugin/CMakeLists.txt | 2 +- src/plugins/coreplugin/coreplugin.qbs | 1 - src/plugins/coreplugin/generalsettings.cpp | 124 ++++++++---- src/plugins/coreplugin/generalsettings.ui | 214 --------------------- 5 files changed, 87 insertions(+), 256 deletions(-) delete mode 100644 src/plugins/coreplugin/generalsettings.ui diff --git a/src/libs/utils/layoutbuilder.h b/src/libs/utils/layoutbuilder.h index 5953fa09f95..3b818956baa 100644 --- a/src/libs/utils/layoutbuilder.h +++ b/src/libs/utils/layoutbuilder.h @@ -116,7 +116,7 @@ public: class QTCREATOR_UTILS_EXPORT Space : public LayoutItem { public: - explicit Space(int space); + explicit Space(int space = 0); }; class QTCREATOR_UTILS_EXPORT Span : public LayoutItem diff --git a/src/plugins/coreplugin/CMakeLists.txt b/src/plugins/coreplugin/CMakeLists.txt index b034e777b5c..06b4242fe36 100644 --- a/src/plugins/coreplugin/CMakeLists.txt +++ b/src/plugins/coreplugin/CMakeLists.txt @@ -87,7 +87,7 @@ add_qtc_plugin(Core findplaceholder.cpp findplaceholder.h foldernavigationwidget.cpp foldernavigationwidget.h - generalsettings.cpp generalsettings.h generalsettings.ui + generalsettings.cpp generalsettings.h generatedfile.cpp generatedfile.h helpitem.cpp helpitem.h helpmanager.cpp helpmanager.h helpmanager_implementation.h diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index 39e29899d5d..59e1d9e1665 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -77,7 +77,6 @@ Project { "foldernavigationwidget.h", "generalsettings.cpp", "generalsettings.h", - "generalsettings.ui", "generatedfile.cpp", "generatedfile.h", "helpitem.cpp", diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp index abfb1c0e1e5..5769f3273d6 100644 --- a/src/plugins/coreplugin/generalsettings.cpp +++ b/src/plugins/coreplugin/generalsettings.cpp @@ -27,8 +27,7 @@ #include "coreconstants.h" #include "coreplugintr.h" #include "icore.h" - -#include "ui_generalsettings.h" +#include "themechooser.h" #include @@ -36,17 +35,24 @@ #include #include #include +#include +#include #include +#include +#include #include #include +#include #include #include +#include #include #include #include using namespace Utils; +using namespace Layouting; namespace Core { namespace Internal { @@ -58,7 +64,6 @@ const char settingsKeyCodecForLocale[] = "General/OverrideCodecForLocale"; class GeneralSettingsWidget final : public IOptionsPageWidget { Q_DECLARE_TR_FUNCTIONS(Core::Internal::GeneralSettings) - public: explicit GeneralSettingsWidget(GeneralSettings *q); @@ -77,31 +82,52 @@ public: static void setCodecForLocale(const QByteArray&); GeneralSettings *q; - Ui::GeneralSettings m_ui; + QComboBox *m_languageBox; + QComboBox *m_codecBox; + QCheckBox *m_showShortcutsInContextMenus; + QtColorButton *m_colorButton; + ThemeChooser *m_themeChooser; + QPushButton *m_resetWarningsButton; }; GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q) : q(q) + , m_languageBox(new QComboBox) + , m_codecBox(new QComboBox) + , m_showShortcutsInContextMenus(new QCheckBox) + , m_colorButton(new QtColorButton) + , m_themeChooser(new ThemeChooser) + , m_resetWarningsButton(new QPushButton) { - m_ui.setupUi(this); + m_languageBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); + m_languageBox->setMinimumContentsLength(20); - fillLanguageBox(); - fillCodecBox(); + m_codecBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); + m_codecBox->setMinimumContentsLength(20); - m_ui.colorButton->setColor(StyleHelper::requestedBaseColor()); - m_ui.resetWarningsButton->setEnabled(canResetWarnings()); + m_colorButton->setMinimumSize(QSize(64, 0)); + m_colorButton->setProperty("alphaAllowed", QVariant(false)); - m_ui.showShortcutsInContextMenus->setText( - tr("Show keyboard shortcuts in context menus (default: %1)") - .arg(q->m_defaultShowShortcutsInContextMenu ? tr("on") : tr("off"))); - m_ui.showShortcutsInContextMenus->setChecked(GeneralSettings::showShortcutsInContextMenu()); + m_resetWarningsButton->setText(tr("Reset Warnings", "Button text")); + m_resetWarningsButton->setToolTip( + tr("Re-enable warnings that were suppressed by selecting \"Do Not " + "Show Again\" (for example, missing highlighter).", + nullptr)); - if (Utils::HostOsInfo::isMacHost()) { - m_ui.dpiCheckbox->setVisible(false); - } else { + auto resetColorButton = new QPushButton(tr("Reset")); + resetColorButton->setToolTip(tr("Reset to default.", "Color")); + + Form form; + form.addRow({tr("Color:"), m_colorButton, resetColorButton, Stretch()}); + form.addRow({tr("Theme:"), m_themeChooser}); + form.addRow({tr("Language:"), m_languageBox, Stretch()}); + + if (!Utils::HostOsInfo::isMacHost()) { + auto dpiCheckbox = new QCheckBox(tr("Enable high DPI scaling")); + form.addRow({Space(), dpiCheckbox}); const bool defaultValue = Utils::HostOsInfo::isWindowsHost(); - m_ui.dpiCheckbox->setChecked(ICore::settings()->value(settingsKeyDPI, defaultValue).toBool()); - connect(m_ui.dpiCheckbox, &QCheckBox::toggled, this, [defaultValue](bool checked) { + dpiCheckbox->setChecked(ICore::settings()->value(settingsKeyDPI, defaultValue).toBool()); + connect(dpiCheckbox, &QCheckBox::toggled, this, [defaultValue](bool checked) { ICore::settings()->setValueWithDefault(settingsKeyDPI, checked, defaultValue); QMessageBox::information(ICore::dialogParent(), tr("Restart Required"), @@ -109,10 +135,30 @@ GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q) }); } - connect(m_ui.resetColorButton, &QAbstractButton::clicked, - this, &GeneralSettingsWidget::resetInterfaceColor); - connect(m_ui.resetWarningsButton, &QAbstractButton::clicked, - this, &GeneralSettingsWidget::resetWarnings); + form.addRow({Space(), m_showShortcutsInContextMenus}); + form.addRow(Row{m_resetWarningsButton, Stretch()}); + form.addRow({tr("Text codec for tools:"), m_codecBox, Stretch()}); + Column{Group{Title(tr("User Interface")), form}}.attachTo(this); + + fillLanguageBox(); + fillCodecBox(); + + m_colorButton->setColor(StyleHelper::requestedBaseColor()); + m_resetWarningsButton->setEnabled(canResetWarnings()); + + m_showShortcutsInContextMenus->setText( + tr("Show keyboard shortcuts in context menus (default: %1)") + .arg(q->m_defaultShowShortcutsInContextMenu ? Tr::tr("on") : Tr::tr("off"))); + m_showShortcutsInContextMenus->setChecked(GeneralSettings::showShortcutsInContextMenu()); + + connect(resetColorButton, + &QAbstractButton::clicked, + this, + &GeneralSettingsWidget::resetInterfaceColor); + connect(m_resetWarningsButton, + &QAbstractButton::clicked, + this, + &GeneralSettingsWidget::resetWarnings); } static bool hasQmFilesForLocale(const QString &locale, const QString &creatorTrPath) @@ -127,11 +173,11 @@ void GeneralSettingsWidget::fillLanguageBox() const { const QString currentLocale = language(); - m_ui.languageBox->addItem(tr(""), QString()); + m_languageBox->addItem(tr(""), QString()); // need to add this explicitly, since there is no qm file for English - m_ui.languageBox->addItem(QLatin1String("English"), QLatin1String("C")); + m_languageBox->addItem(QLatin1String("English"), QLatin1String("C")); if (currentLocale == QLatin1String("C")) - m_ui.languageBox->setCurrentIndex(m_ui.languageBox->count() - 1); + m_languageBox->setCurrentIndex(m_languageBox->count() - 1); const FilePath creatorTrPath = ICore::resourcePath("translations"); const QStringList languageFiles = creatorTrPath.toDir().entryList( @@ -146,23 +192,23 @@ void GeneralSettingsWidget::fillLanguageBox() const QLocale tmpLocale(locale); QString languageItem = QLocale::languageToString(tmpLocale.language()) + QLatin1String(" (") + QLocale::countryToString(tmpLocale.country()) + QLatin1Char(')'); - m_ui.languageBox->addItem(languageItem, locale); + m_languageBox->addItem(languageItem, locale); if (locale == currentLocale) - m_ui.languageBox->setCurrentIndex(m_ui.languageBox->count() - 1); + m_languageBox->setCurrentIndex(m_languageBox->count() - 1); } } } void GeneralSettingsWidget::apply() { - int currentIndex = m_ui.languageBox->currentIndex(); - setLanguage(m_ui.languageBox->itemData(currentIndex, Qt::UserRole).toString()); - currentIndex = m_ui.codecBox->currentIndex(); - setCodecForLocale(m_ui.codecBox->itemText(currentIndex).toLocal8Bit()); - q->setShowShortcutsInContextMenu(m_ui.showShortcutsInContextMenus->isChecked()); + int currentIndex = m_languageBox->currentIndex(); + setLanguage(m_languageBox->itemData(currentIndex, Qt::UserRole).toString()); + currentIndex = m_codecBox->currentIndex(); + setCodecForLocale(m_codecBox->itemText(currentIndex).toLocal8Bit()); + q->setShowShortcutsInContextMenu(m_showShortcutsInContextMenus->isChecked()); // Apply the new base color if accepted - StyleHelper::setBaseColor(m_ui.colorButton->color()); - m_ui.themeChooser->apply(); + StyleHelper::setBaseColor(m_colorButton->color()); + m_themeChooser->apply(); } bool GeneralSettings::showShortcutsInContextMenu() @@ -175,14 +221,14 @@ bool GeneralSettings::showShortcutsInContextMenu() void GeneralSettingsWidget::resetInterfaceColor() { - m_ui.colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR); + m_colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR); } void GeneralSettingsWidget::resetWarnings() { InfoBar::clearGloballySuppressed(); CheckableMessageBox::resetAllDoNotAskAgainQuestions(ICore::settings()); - m_ui.resetWarningsButton->setEnabled(false); + m_resetWarningsButton->setEnabled(false); } bool GeneralSettingsWidget::canResetWarnings() @@ -194,7 +240,7 @@ bool GeneralSettingsWidget::canResetWarnings() void GeneralSettingsWidget::resetLanguage() { // system language is default - m_ui.languageBox->setCurrentIndex(0); + m_languageBox->setCurrentIndex(0); } QString GeneralSettingsWidget::language() @@ -222,9 +268,9 @@ void GeneralSettingsWidget::fillCodecBox() const QByteArrayList codecs = QTextCodec::availableCodecs(); Utils::sort(codecs); for (const QByteArray &codec : qAsConst(codecs)) { - m_ui.codecBox->addItem(QString::fromLocal8Bit(codec)); + m_codecBox->addItem(QString::fromLocal8Bit(codec)); if (codec == currentCodec) - m_ui.codecBox->setCurrentIndex(m_ui.codecBox->count() - 1); + m_codecBox->setCurrentIndex(m_codecBox->count() - 1); } } diff --git a/src/plugins/coreplugin/generalsettings.ui b/src/plugins/coreplugin/generalsettings.ui deleted file mode 100644 index 05c97fa0a28..00000000000 --- a/src/plugins/coreplugin/generalsettings.ui +++ /dev/null @@ -1,214 +0,0 @@ - - - Core::Internal::GeneralSettings - - - - 0 - 0 - 527 - 469 - - - - - - - User Interface - - - - - - Re-enable warnings that were suppressed by selecting "Do Not Show Again" (for example, missing highlighter). - - - Reset Warnings - - - - - - - - - QComboBox::AdjustToMinimumContentsLengthWithIcon - - - 20 - - - - - - - Qt::Horizontal - - - - 285 - 20 - - - - - - - - - - Enable high DPI scaling - - - - - - - - - - 0 - 0 - - - - - 64 - 0 - - - - false - - - - - - - Reset to default. - - - Reset - - - - - - - Qt::Horizontal - - - - 285 - 20 - - - - - - - - - - Language: - - - - - - - - - - - - - - Theme: - - - - - - - - - - Color: - - - - - - - Text codec for tools: - - - - - - - - - QComboBox::AdjustToMinimumContentsLengthWithIcon - - - 20 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 30 - - - - - - - - - Utils::QtColorButton - QToolButton -
utils/qtcolorbutton.h
-
- - Core::Internal::ThemeChooser - QWidget -
coreplugin/themechooser.h
- 1 -
-
- - colorButton - resetColorButton - languageBox - resetWarningsButton - - - -