2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "generalsettings.h"
|
2009-11-27 16:12:12 +01:00
|
|
|
#include "coreconstants.h"
|
2013-01-10 20:46:06 +02:00
|
|
|
#include "icore.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
#include "ui_generalsettings.h"
|
|
|
|
|
|
2020-01-03 16:47:15 +01:00
|
|
|
#include <coreplugin/dialogs/restartdialog.h>
|
|
|
|
|
|
2013-10-31 15:39:49 +01:00
|
|
|
#include <utils/checkablemessagebox.h>
|
2018-04-09 14:50:10 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <utils/infobar.h>
|
2009-07-15 12:38:45 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QLibraryInfo>
|
2014-06-05 13:18:35 +02:00
|
|
|
#include <QMessageBox>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2019-09-09 16:50:16 +02:00
|
|
|
#include <QStyleHints>
|
2009-11-20 16:55:23 +01:00
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
2010-01-04 15:19:29 +01:00
|
|
|
|
2018-04-09 14:50:10 +02:00
|
|
|
const char settingsKeyDPI[] = "Core/EnableHighDpiScaling";
|
2019-09-09 16:50:16 +02:00
|
|
|
const char settingsKeyShortcutsInContextMenu[] = "General/ShowShortcutsInContextMenu";
|
2018-04-09 14:50:10 +02:00
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
class GeneralSettingsWidget final : public IOptionsPageWidget
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-02-10 09:52:21 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Core::Internal::GeneralSettings)
|
2020-01-10 09:33:24 +01:00
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
public:
|
|
|
|
|
explicit GeneralSettingsWidget(GeneralSettings *q);
|
|
|
|
|
|
|
|
|
|
void apply() final;
|
|
|
|
|
|
|
|
|
|
void resetInterfaceColor();
|
|
|
|
|
void resetWarnings();
|
|
|
|
|
void resetLanguage();
|
|
|
|
|
|
2020-12-10 00:59:50 +01:00
|
|
|
static bool canResetWarnings();
|
2020-02-10 09:52:21 +01:00
|
|
|
void fillLanguageBox() const;
|
2020-12-10 00:59:50 +01:00
|
|
|
static QString language();
|
|
|
|
|
static void setLanguage(const QString&);
|
2020-02-10 09:52:21 +01:00
|
|
|
|
|
|
|
|
GeneralSettings *q;
|
|
|
|
|
Ui::GeneralSettings m_ui;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q)
|
|
|
|
|
: q(q)
|
|
|
|
|
{
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
fillLanguageBox();
|
|
|
|
|
|
|
|
|
|
m_ui.colorButton->setColor(StyleHelper::requestedBaseColor());
|
|
|
|
|
m_ui.resetWarningsButton->setEnabled(canResetWarnings());
|
|
|
|
|
|
|
|
|
|
m_ui.showShortcutsInContextMenus->setText(
|
|
|
|
|
tr("Show keyboard shortcuts in context menus (default: %1)")
|
2020-03-03 12:40:17 +01:00
|
|
|
.arg(q->m_defaultShowShortcutsInContextMenu ? tr("on") : tr("off")));
|
2020-12-10 00:59:50 +01:00
|
|
|
m_ui.showShortcutsInContextMenus->setChecked(GeneralSettings::showShortcutsInContextMenu());
|
2020-02-10 09:52:21 +01:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
|
|
|
|
|
m_ui.showShortcutsInContextMenus->setVisible(false);
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-18 18:42:27 +01:00
|
|
|
if (Utils::HostOsInfo::isMacHost()) {
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.dpiCheckbox->setVisible(false);
|
|
|
|
|
} else {
|
2020-11-18 18:42:27 +01:00
|
|
|
const bool defaultValue = Utils::HostOsInfo::isWindowsHost();
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.dpiCheckbox->setChecked(ICore::settings()->value(settingsKeyDPI, defaultValue).toBool());
|
2020-12-10 11:24:27 +01:00
|
|
|
connect(m_ui.dpiCheckbox, &QCheckBox::toggled, this, [defaultValue](bool checked) {
|
|
|
|
|
ICore::settings()->setValueWithDefault(settingsKeyDPI, checked, defaultValue);
|
2020-06-02 09:10:40 +02:00
|
|
|
QMessageBox::information(ICore::dialogParent(),
|
|
|
|
|
tr("Restart Required"),
|
2020-02-10 09:52:21 +01:00
|
|
|
tr("The high DPI settings will take effect after restart."));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(m_ui.resetColorButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &GeneralSettingsWidget::resetInterfaceColor);
|
|
|
|
|
connect(m_ui.resetWarningsButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &GeneralSettingsWidget::resetWarnings);
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-05 16:33:30 +01:00
|
|
|
static bool hasQmFilesForLocale(const QString &locale, const QString &creatorTrPath)
|
|
|
|
|
{
|
|
|
|
|
static const QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
|
|
|
|
2013-01-16 15:30:21 +01:00
|
|
|
const QString trFile = QLatin1String("/qt_") + locale + QLatin1String(".qm");
|
|
|
|
|
return QFile::exists(qtTrPath + trFile) || QFile::exists(creatorTrPath + trFile);
|
2010-01-05 16:33:30 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
void GeneralSettingsWidget::fillLanguageBox() const
|
2010-01-05 16:33:30 +01:00
|
|
|
{
|
2010-03-15 18:52:04 +01:00
|
|
|
const QString currentLocale = language();
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.languageBox->addItem(tr("<System Language>"), QString());
|
2010-01-06 14:55:14 +01:00
|
|
|
// need to add this explicitly, since there is no qm file for English
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.languageBox->addItem(QLatin1String("English"), QLatin1String("C"));
|
2010-03-15 18:52:04 +01:00
|
|
|
if (currentLocale == QLatin1String("C"))
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.languageBox->setCurrentIndex(m_ui.languageBox->count() - 1);
|
2010-01-05 16:33:30 +01:00
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
const QString creatorTrPath = ICore::resourcePath() + QLatin1String("/translations");
|
2010-04-12 11:29:38 +02:00
|
|
|
const QStringList languageFiles = QDir(creatorTrPath).entryList(QStringList(QLatin1String("qtcreator*.qm")));
|
2010-01-05 16:33:30 +01:00
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
for (const QString &languageFile : languageFiles) {
|
|
|
|
|
int start = languageFile.indexOf('_') + 1;
|
|
|
|
|
int end = languageFile.lastIndexOf('.');
|
2010-01-05 16:33:30 +01:00
|
|
|
const QString locale = languageFile.mid(start, end-start);
|
|
|
|
|
// no need to show a language that creator will not load anyway
|
|
|
|
|
if (hasQmFilesForLocale(locale, creatorTrPath)) {
|
2012-11-14 17:26:16 +01:00
|
|
|
QLocale tmpLocale(locale);
|
|
|
|
|
QString languageItem = QLocale::languageToString(tmpLocale.language()) + QLatin1String(" (")
|
|
|
|
|
+ QLocale::countryToString(tmpLocale.country()) + QLatin1Char(')');
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.languageBox->addItem(languageItem, locale);
|
2010-01-05 16:33:30 +01:00
|
|
|
if (locale == currentLocale)
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.languageBox->setCurrentIndex(m_ui.languageBox->count() - 1);
|
2010-01-05 16:33:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
void GeneralSettingsWidget::apply()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-02-10 09:52:21 +01:00
|
|
|
int currentIndex = m_ui.languageBox->currentIndex();
|
|
|
|
|
setLanguage(m_ui.languageBox->itemData(currentIndex, Qt::UserRole).toString());
|
|
|
|
|
q->setShowShortcutsInContextMenu(m_ui.showShortcutsInContextMenus->isChecked());
|
2008-12-02 12:01:29 +01:00
|
|
|
// Apply the new base color if accepted
|
2020-02-10 09:52:21 +01:00
|
|
|
StyleHelper::setBaseColor(m_ui.colorButton->color());
|
|
|
|
|
m_ui.themeChooser->apply();
|
2009-02-02 12:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-10 00:59:50 +01:00
|
|
|
bool GeneralSettings::showShortcutsInContextMenu()
|
2019-09-09 16:50:16 +02:00
|
|
|
{
|
|
|
|
|
return ICore::settings()
|
|
|
|
|
->value(settingsKeyShortcutsInContextMenu,
|
|
|
|
|
QGuiApplication::styleHints()->showShortcutsInContextMenus())
|
|
|
|
|
.toBool();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
void GeneralSettingsWidget::resetInterfaceColor()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
void GeneralSettingsWidget::resetWarnings()
|
2013-01-10 20:46:06 +02:00
|
|
|
{
|
2014-06-05 13:18:35 +02:00
|
|
|
InfoBar::clearGloballySuppressed();
|
|
|
|
|
CheckableMessageBox::resetAllDoNotAskAgainQuestions(ICore::settings());
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.resetWarningsButton->setEnabled(false);
|
2013-01-10 20:46:06 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-10 00:59:50 +01:00
|
|
|
bool GeneralSettingsWidget::canResetWarnings()
|
2015-05-12 15:18:26 +02:00
|
|
|
{
|
|
|
|
|
return InfoBar::anyGloballySuppressed()
|
2015-09-01 11:39:39 +02:00
|
|
|
|| CheckableMessageBox::hasSuppressedQuestions(ICore::settings());
|
2015-05-12 15:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
void GeneralSettingsWidget::resetLanguage()
|
2010-01-05 16:33:30 +01:00
|
|
|
{
|
|
|
|
|
// system language is default
|
2020-02-10 09:52:21 +01:00
|
|
|
m_ui.languageBox->setCurrentIndex(0);
|
2010-01-05 16:33:30 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-10 00:59:50 +01:00
|
|
|
QString GeneralSettingsWidget::language()
|
2010-01-05 16:33:30 +01:00
|
|
|
{
|
2014-06-05 13:18:35 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
2010-01-05 16:33:30 +01:00
|
|
|
return settings->value(QLatin1String("General/OverrideLanguage")).toString();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
void GeneralSettingsWidget::setLanguage(const QString &locale)
|
2010-01-05 16:33:30 +01:00
|
|
|
{
|
2020-11-19 15:34:59 +01:00
|
|
|
QtcSettings *settings = ICore::settings();
|
2020-01-03 16:47:15 +01:00
|
|
|
if (settings->value(QLatin1String("General/OverrideLanguage")).toString() != locale) {
|
|
|
|
|
RestartDialog dialog(ICore::dialogParent(),
|
|
|
|
|
tr("The language change will take effect after restart."));
|
|
|
|
|
dialog.exec();
|
|
|
|
|
}
|
2014-06-05 13:18:35 +02:00
|
|
|
|
2020-11-19 15:34:59 +01:00
|
|
|
settings->setValueWithDefault(QLatin1String("General/OverrideLanguage"), locale, {});
|
2010-01-05 16:33:30 +01:00
|
|
|
}
|
2014-06-05 13:18:35 +02:00
|
|
|
|
2019-09-09 16:50:16 +02:00
|
|
|
void GeneralSettings::setShowShortcutsInContextMenu(bool show)
|
|
|
|
|
{
|
2020-11-19 15:34:59 +01:00
|
|
|
ICore::settings()->setValueWithDefault(settingsKeyShortcutsInContextMenu,
|
|
|
|
|
show,
|
|
|
|
|
m_defaultShowShortcutsInContextMenu);
|
2019-09-09 16:50:16 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
|
|
|
|
QGuiApplication::styleHints()->setShowShortcutsInContextMenus(show);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:52:21 +01:00
|
|
|
GeneralSettings::GeneralSettings()
|
|
|
|
|
{
|
|
|
|
|
setId(Constants::SETTINGS_ID_INTERFACE);
|
|
|
|
|
setDisplayName(GeneralSettingsWidget::tr("Interface"));
|
|
|
|
|
setCategory(Constants::SETTINGS_CATEGORY_CORE);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("Core", "Environment"));
|
|
|
|
|
setCategoryIconPath(":/core/images/settingscategory_core.png");
|
|
|
|
|
setWidgetCreator([this] { return new GeneralSettingsWidget(this); });
|
|
|
|
|
|
|
|
|
|
m_defaultShowShortcutsInContextMenu = QGuiApplication::styleHints()
|
|
|
|
|
->showShortcutsInContextMenus();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|