forked from qt-creator/qt-creator
Core: Inline generalsettings.ui
Change-Id: I8811728543cd7fb161b6df21dacc0fc23c6165a4 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -27,8 +27,7 @@
|
||||
#include "coreconstants.h"
|
||||
#include "coreplugintr.h"
|
||||
#include "icore.h"
|
||||
|
||||
#include "ui_generalsettings.h"
|
||||
#include "themechooser.h"
|
||||
|
||||
#include <coreplugin/dialogs/restartdialog.h>
|
||||
|
||||
@@ -36,17 +35,24 @@
|
||||
#include <utils/checkablemessagebox.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/qtcolorbutton.h>
|
||||
#include <utils/stylehelper.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QGuiApplication>
|
||||
#include <QLibraryInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QStyleHints>
|
||||
#include <QTextCodec>
|
||||
|
||||
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("<System Language>"), QString());
|
||||
m_languageBox->addItem(tr("<System Language>"), 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user