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 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fontsettingspage.h"
|
2009-06-18 17:35:46 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fontsettings.h"
|
2020-01-27 13:52:32 +01:00
|
|
|
#include "texteditorsettings.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "ui_fontsettingspage.h"
|
|
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2015-01-10 23:40:32 +02:00
|
|
|
#include <utils/fileutils.h>
|
2021-09-10 14:59:27 +02:00
|
|
|
#include <utils/filepath.h>
|
2020-10-15 08:52:48 +02:00
|
|
|
#include <utils/stringutils.h>
|
2009-07-22 14:16:21 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2015-12-09 18:16:37 +01:00
|
|
|
#include <utils/theme/theme.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QFontDatabase>
|
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPalette>
|
2013-12-03 14:17:03 +01:00
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
using namespace TextEditor::Internal;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2009-07-16 17:16:55 +02:00
|
|
|
struct ColorSchemeEntry
|
|
|
|
|
{
|
|
|
|
|
ColorSchemeEntry(const QString &fileName,
|
|
|
|
|
bool readOnly):
|
|
|
|
|
fileName(fileName),
|
|
|
|
|
name(ColorScheme::readNameOfScheme(fileName)),
|
|
|
|
|
readOnly(readOnly)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QString fileName;
|
|
|
|
|
QString name;
|
2009-11-27 16:12:12 +01:00
|
|
|
QString id;
|
2009-07-16 17:16:55 +02:00
|
|
|
bool readOnly;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SchemeListModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-09-20 01:16:01 +03:00
|
|
|
SchemeListModel(QObject *parent = nullptr):
|
2009-07-16 17:16:55 +02:00
|
|
|
QAbstractListModel(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-20 01:16:01 +03:00
|
|
|
int rowCount(const QModelIndex &parent) const override
|
2009-07-16 17:16:55 +02:00
|
|
|
{ return parent.isValid() ? 0 : m_colorSchemes.size(); }
|
|
|
|
|
|
2018-09-20 01:16:01 +03:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override
|
2009-07-16 17:16:55 +02:00
|
|
|
{
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return m_colorSchemes.at(index.row()).name;
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removeColorScheme(int index)
|
|
|
|
|
{
|
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
|
m_colorSchemes.removeAt(index);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setColorSchemes(const QList<ColorSchemeEntry> &colorSchemes)
|
|
|
|
|
{
|
2012-09-20 10:31:34 +02:00
|
|
|
beginResetModel();
|
2009-07-16 17:16:55 +02:00
|
|
|
m_colorSchemes = colorSchemes;
|
2012-09-20 10:31:34 +02:00
|
|
|
endResetModel();
|
2009-07-16 17:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ColorSchemeEntry &colorSchemeAt(int index) const
|
|
|
|
|
{ return m_colorSchemes.at(index); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QList<ColorSchemeEntry> m_colorSchemes;
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
class FontSettingsPageWidget : public Core::IOptionsPageWidget
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-03-12 13:46:25 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(TextEditor::FontSettingsPageWidget)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
public:
|
2020-01-27 13:52:32 +01:00
|
|
|
FontSettingsPageWidget(FontSettingsPage *q, const FormatDescriptions &fd, FontSettings *fontSettings)
|
|
|
|
|
: q(q),
|
|
|
|
|
m_value(*fontSettings),
|
|
|
|
|
m_descriptions(fd)
|
|
|
|
|
{
|
|
|
|
|
m_lastValue = m_value;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
m_ui.colorSchemeGroupBox->setTitle(
|
|
|
|
|
tr("Color Scheme for Theme \"%1\"")
|
|
|
|
|
.arg(Utils::creatorTheme()->displayName()));
|
|
|
|
|
m_ui.schemeComboBox->setModel(&m_schemeListModel);
|
|
|
|
|
|
|
|
|
|
m_ui.fontComboBox->setCurrentFont(m_value.family());
|
|
|
|
|
|
|
|
|
|
m_ui.antialias->setChecked(m_value.antialias());
|
|
|
|
|
m_ui.zoomSpinBox->setValue(m_value.fontZoom());
|
|
|
|
|
|
|
|
|
|
m_ui.schemeEdit->setFormatDescriptions(fd);
|
|
|
|
|
m_ui.schemeEdit->setBaseFont(m_value.font());
|
|
|
|
|
m_ui.schemeEdit->setColorScheme(m_value.colorScheme());
|
|
|
|
|
|
|
|
|
|
auto sizeValidator = new QIntValidator(m_ui.sizeComboBox);
|
|
|
|
|
sizeValidator->setBottom(0);
|
|
|
|
|
m_ui.sizeComboBox->setValidator(sizeValidator);
|
|
|
|
|
|
|
|
|
|
connect(m_ui.fontComboBox, &QFontComboBox::currentFontChanged,
|
|
|
|
|
this, &FontSettingsPageWidget::fontSelected);
|
2020-06-19 10:14:47 +02:00
|
|
|
connect(m_ui.sizeComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2020-01-27 13:52:32 +01:00
|
|
|
this, &FontSettingsPageWidget::fontSizeSelected);
|
|
|
|
|
connect(m_ui.zoomSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
|
|
|
|
this, &FontSettingsPageWidget::fontZoomChanged);
|
|
|
|
|
connect(m_ui.antialias, &QCheckBox::toggled,
|
|
|
|
|
this, &FontSettingsPageWidget::antialiasChanged);
|
|
|
|
|
connect(m_ui.schemeComboBox,
|
|
|
|
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &FontSettingsPageWidget::colorSchemeSelected);
|
|
|
|
|
connect(m_ui.copyButton, &QPushButton::clicked,
|
|
|
|
|
this, &FontSettingsPageWidget::openCopyColorSchemeDialog);
|
|
|
|
|
connect(m_ui.schemeEdit, &ColorSchemeEdit::copyScheme,
|
|
|
|
|
this, &FontSettingsPageWidget::openCopyColorSchemeDialog);
|
|
|
|
|
connect(m_ui.deleteButton, &QPushButton::clicked,
|
|
|
|
|
this, &FontSettingsPageWidget::confirmDeleteColorScheme);
|
2021-09-10 14:59:27 +02:00
|
|
|
connect(m_ui.importButton, &QPushButton::clicked,
|
|
|
|
|
this, &FontSettingsPageWidget::importScheme);
|
|
|
|
|
connect(m_ui.exportButton, &QPushButton::clicked,
|
|
|
|
|
this, &FontSettingsPageWidget::exportScheme);
|
2020-01-27 13:52:32 +01:00
|
|
|
|
|
|
|
|
updatePointSizes();
|
|
|
|
|
refreshColorSchemeList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void apply() final;
|
|
|
|
|
void finish() final;
|
|
|
|
|
|
|
|
|
|
void saveSettings();
|
|
|
|
|
void fontSelected(const QFont &font);
|
2020-06-19 10:14:47 +02:00
|
|
|
void fontSizeSelected(int index);
|
2020-01-27 13:52:32 +01:00
|
|
|
void fontZoomChanged();
|
|
|
|
|
void antialiasChanged();
|
|
|
|
|
void colorSchemeSelected(int index);
|
|
|
|
|
void openCopyColorSchemeDialog();
|
|
|
|
|
void copyColorScheme(const QString &name);
|
|
|
|
|
void confirmDeleteColorScheme();
|
2021-09-10 14:59:27 +02:00
|
|
|
void importScheme();
|
|
|
|
|
void exportScheme();
|
2020-01-27 13:52:32 +01:00
|
|
|
void deleteColorScheme();
|
|
|
|
|
|
|
|
|
|
void maybeSaveColorScheme();
|
|
|
|
|
void updatePointSizes();
|
|
|
|
|
QList<int> pointSizesForSelectedFont() const;
|
|
|
|
|
void refreshColorSchemeList();
|
|
|
|
|
|
|
|
|
|
FontSettingsPage *q;
|
|
|
|
|
Ui::FontSettingsPage m_ui;
|
|
|
|
|
bool m_refreshingSchemeList = false;
|
|
|
|
|
FontSettings &m_value;
|
2008-12-02 12:01:29 +01:00
|
|
|
FontSettings m_lastValue;
|
2020-01-27 13:52:32 +01:00
|
|
|
SchemeListModel m_schemeListModel;
|
|
|
|
|
FormatDescriptions m_descriptions;
|
2009-07-13 14:08:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2021-07-01 10:22:34 +02:00
|
|
|
static Utils::FilePath customStylesPath()
|
2009-07-15 12:27:02 +02:00
|
|
|
{
|
2021-07-01 10:22:34 +02:00
|
|
|
return Core::ICore::userResourcePath("styles");
|
2009-07-15 12:27:02 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-01 10:22:34 +02:00
|
|
|
static Utils::FilePath createColorSchemeFileName(const QString &pattern)
|
2009-07-15 15:39:35 +02:00
|
|
|
{
|
2021-07-01 10:22:34 +02:00
|
|
|
const Utils::FilePath stylesPath = customStylesPath();
|
2009-07-15 15:39:35 +02:00
|
|
|
|
|
|
|
|
// Find an available file name
|
|
|
|
|
int i = 1;
|
2021-07-01 10:22:34 +02:00
|
|
|
Utils::FilePath filePath;
|
2009-07-15 15:39:35 +02:00
|
|
|
do {
|
2021-07-01 10:22:34 +02:00
|
|
|
filePath = stylesPath.pathAppended(pattern.arg((i == 1) ? QString() : QString::number(i)));
|
2009-07-15 15:39:35 +02:00
|
|
|
++i;
|
2021-07-01 10:22:34 +02:00
|
|
|
} while (filePath.exists());
|
2009-07-15 15:39:35 +02:00
|
|
|
|
|
|
|
|
// Create the base directory when it doesn't exist
|
2021-07-01 10:22:34 +02:00
|
|
|
if (!stylesPath.exists() && !stylesPath.createDir()) {
|
2009-07-15 15:39:35 +02:00
|
|
|
qWarning() << "Failed to create color scheme directory:" << stylesPath;
|
2021-07-01 10:22:34 +02:00
|
|
|
return {};
|
2009-07-15 15:39:35 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-01 10:22:34 +02:00
|
|
|
return filePath;
|
2009-07-15 15:39:35 +02:00
|
|
|
}
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ------- FormatDescription
|
2015-09-21 13:12:36 +02:00
|
|
|
FormatDescription::FormatDescription(TextStyle id,
|
|
|
|
|
const QString &displayName,
|
|
|
|
|
const QString &tooltipText,
|
|
|
|
|
const QColor &foreground,
|
|
|
|
|
FormatDescription::ShowControls showControls)
|
|
|
|
|
: m_id(id),
|
|
|
|
|
m_displayName(displayName),
|
|
|
|
|
m_tooltipText(tooltipText),
|
|
|
|
|
m_showControls(showControls)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-08-27 10:55:13 +02:00
|
|
|
m_format.setForeground(foreground);
|
2016-06-19 10:46:49 +03:00
|
|
|
m_format.setBackground(defaultBackground(id));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-21 13:12:36 +02:00
|
|
|
FormatDescription::FormatDescription(TextStyle id,
|
|
|
|
|
const QString &displayName,
|
|
|
|
|
const QString &tooltipText,
|
|
|
|
|
const Format &format,
|
|
|
|
|
FormatDescription::ShowControls showControls)
|
|
|
|
|
: m_id(id),
|
|
|
|
|
m_format(format),
|
|
|
|
|
m_displayName(displayName),
|
|
|
|
|
m_tooltipText(tooltipText),
|
|
|
|
|
m_showControls(showControls)
|
2011-08-16 09:47:54 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 14:18:37 +02:00
|
|
|
FormatDescription::FormatDescription(TextStyle id,
|
|
|
|
|
const QString &displayName,
|
|
|
|
|
const QString &tooltipText,
|
|
|
|
|
const QColor &underlineColor,
|
2015-09-21 13:12:36 +02:00
|
|
|
const QTextCharFormat::UnderlineStyle underlineStyle,
|
|
|
|
|
FormatDescription::ShowControls showControls)
|
2015-09-10 14:18:37 +02:00
|
|
|
: m_id(id),
|
|
|
|
|
m_displayName(displayName),
|
2015-09-21 13:12:36 +02:00
|
|
|
m_tooltipText(tooltipText),
|
|
|
|
|
m_showControls(showControls)
|
2015-09-10 14:18:37 +02:00
|
|
|
{
|
2016-06-19 10:46:49 +03:00
|
|
|
m_format.setForeground(defaultForeground(id));
|
|
|
|
|
m_format.setBackground(defaultBackground(id));
|
2015-09-10 14:18:37 +02:00
|
|
|
m_format.setUnderlineColor(underlineColor);
|
|
|
|
|
m_format.setUnderlineStyle(underlineStyle);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 13:12:36 +02:00
|
|
|
FormatDescription::FormatDescription(TextStyle id,
|
|
|
|
|
const QString &displayName,
|
|
|
|
|
const QString &tooltipText,
|
|
|
|
|
FormatDescription::ShowControls showControls)
|
|
|
|
|
: m_id(id),
|
|
|
|
|
m_displayName(displayName),
|
|
|
|
|
m_tooltipText(tooltipText),
|
|
|
|
|
m_showControls(showControls)
|
|
|
|
|
{
|
2016-06-19 10:46:49 +03:00
|
|
|
m_format.setForeground(defaultForeground(id));
|
|
|
|
|
m_format.setBackground(defaultBackground(id));
|
2015-09-21 13:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-19 10:46:49 +03:00
|
|
|
QColor FormatDescription::defaultForeground(TextStyle id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-07-15 14:57:59 +02:00
|
|
|
if (id == C_TEXT) {
|
|
|
|
|
return Qt::black;
|
|
|
|
|
} else if (id == C_LINE_NUMBER) {
|
2016-07-24 09:42:35 +03:00
|
|
|
const QPalette palette = Utils::Theme::initialPalette();
|
2019-02-11 10:17:53 +01:00
|
|
|
const QColor bg = palette.window().color();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (bg.value() < 128)
|
2019-02-11 10:17:53 +01:00
|
|
|
return palette.windowText().color();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2016-07-24 09:42:35 +03:00
|
|
|
return palette.dark().color();
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_CURRENT_LINE_NUMBER) {
|
2016-07-24 09:42:35 +03:00
|
|
|
const QPalette palette = Utils::Theme::initialPalette();
|
2019-02-11 10:17:53 +01:00
|
|
|
const QColor bg = palette.window().color();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (bg.value() < 128)
|
2019-02-11 10:17:53 +01:00
|
|
|
return palette.windowText().color();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2016-06-19 10:46:49 +03:00
|
|
|
return QColor();
|
|
|
|
|
} else if (id == C_PARENTHESES) {
|
2008-12-02 12:01:29 +01:00
|
|
|
return QColor(Qt::red);
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_AUTOCOMPLETE) {
|
2016-04-28 12:51:34 +02:00
|
|
|
return QColor(Qt::darkBlue);
|
2020-11-17 22:34:00 +01:00
|
|
|
} else if (id == C_SEARCH_RESULT_ALT1) {
|
|
|
|
|
return QColor(0x00, 0x00, 0x33);
|
|
|
|
|
} else if (id == C_SEARCH_RESULT_ALT2) {
|
|
|
|
|
return QColor(0x33, 0x00, 0x00);
|
2009-06-15 15:35:06 +02:00
|
|
|
}
|
2016-06-19 10:46:49 +03:00
|
|
|
return QColor();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-19 10:46:49 +03:00
|
|
|
QColor FormatDescription::defaultBackground(TextStyle id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-06-19 10:46:49 +03:00
|
|
|
if (id == C_TEXT) {
|
2008-12-02 12:01:29 +01:00
|
|
|
return Qt::white;
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_LINE_NUMBER) {
|
2019-02-11 10:17:53 +01:00
|
|
|
return Utils::Theme::initialPalette().window().color();
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_SEARCH_RESULT) {
|
2008-12-02 12:01:29 +01:00
|
|
|
return QColor(0xffef0b);
|
2020-11-16 19:12:26 +01:00
|
|
|
} else if (id == C_SEARCH_RESULT_ALT1) {
|
|
|
|
|
return QColor(0xb6, 0xcc, 0xff);
|
|
|
|
|
} else if (id == C_SEARCH_RESULT_ALT2) {
|
|
|
|
|
return QColor(0xff, 0xb6, 0xcc);
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_PARENTHESES) {
|
2008-12-02 12:01:29 +01:00
|
|
|
return QColor(0xb4, 0xee, 0xb4);
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_PARENTHESES_MISMATCH) {
|
2015-04-28 11:04:07 +02:00
|
|
|
return QColor(Qt::magenta);
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_AUTOCOMPLETE) {
|
2016-04-28 12:51:34 +02:00
|
|
|
return QColor(192, 192, 255);
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_CURRENT_LINE || id == C_SEARCH_SCOPE) {
|
2016-07-24 09:42:35 +03:00
|
|
|
const QPalette palette = Utils::Theme::initialPalette();
|
2008-12-02 12:01:29 +01:00
|
|
|
const QColor &fg = palette.color(QPalette::Highlight);
|
|
|
|
|
const QColor &bg = palette.color(QPalette::Base);
|
|
|
|
|
|
|
|
|
|
qreal smallRatio;
|
|
|
|
|
qreal largeRatio;
|
2016-06-19 10:46:49 +03:00
|
|
|
if (id == C_CURRENT_LINE) {
|
2010-05-20 17:00:10 +02:00
|
|
|
smallRatio = .3;
|
|
|
|
|
largeRatio = .6;
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
|
|
|
|
smallRatio = .05;
|
|
|
|
|
largeRatio = .4;
|
|
|
|
|
}
|
|
|
|
|
const qreal ratio = ((palette.color(QPalette::Text).value() < 128)
|
|
|
|
|
^ (palette.color(QPalette::HighlightedText).value() < 128)) ? smallRatio : largeRatio;
|
|
|
|
|
|
|
|
|
|
const QColor &col = QColor::fromRgbF(fg.redF() * ratio + bg.redF() * (1 - ratio),
|
|
|
|
|
fg.greenF() * ratio + bg.greenF() * (1 - ratio),
|
|
|
|
|
fg.blueF() * ratio + bg.blueF() * (1 - ratio));
|
|
|
|
|
return col;
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_SELECTION) {
|
2016-07-24 09:42:35 +03:00
|
|
|
return Utils::Theme::initialPalette().color(QPalette::Highlight);
|
2020-11-16 19:12:26 +01:00
|
|
|
} else if (id == C_OCCURRENCES) {
|
2009-11-25 15:55:45 +01:00
|
|
|
return QColor(180, 180, 180);
|
2020-11-16 19:12:26 +01:00
|
|
|
} else if (id == C_OCCURRENCES_RENAME) {
|
2009-12-01 16:38:38 +01:00
|
|
|
return QColor(255, 100, 100);
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_DISABLED_CODE) {
|
2009-10-08 12:57:26 +02:00
|
|
|
return QColor(239, 239, 239);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
return QColor(); // invalid color
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-21 13:12:36 +02:00
|
|
|
bool FormatDescription::showControl(FormatDescription::ShowControls showControl) const
|
|
|
|
|
{
|
|
|
|
|
return m_showControls & showControl;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::fontSelected(const QFont &font)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value.setFamily(font.family());
|
|
|
|
|
m_ui.schemeEdit->setBaseFont(font);
|
2009-07-17 17:24:32 +02:00
|
|
|
updatePointSizes();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-12 13:46:25 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::updatePointSizes()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-17 17:24:32 +02:00
|
|
|
// Update point sizes
|
2020-01-27 13:52:32 +01:00
|
|
|
const int oldSize = m_value.fontSize();
|
|
|
|
|
m_ui.sizeComboBox->clear();
|
2010-04-16 12:54:49 +02:00
|
|
|
const QList<int> sizeLst = pointSizesForSelectedFont();
|
2010-09-28 11:16:57 +02:00
|
|
|
int idx = -1;
|
2008-12-02 12:01:29 +01:00
|
|
|
int i = 0;
|
2009-06-18 17:35:46 +02:00
|
|
|
for (; i < sizeLst.count(); ++i) {
|
2020-01-13 15:58:31 +01:00
|
|
|
if (idx == -1 && sizeLst.at(i) >= oldSize) {
|
2008-12-02 12:01:29 +01:00
|
|
|
idx = i;
|
2020-01-13 15:58:31 +01:00
|
|
|
if (sizeLst.at(i) != oldSize)
|
2020-01-27 13:52:32 +01:00
|
|
|
m_ui.sizeComboBox->addItem(QString::number(oldSize));
|
2020-01-13 15:58:31 +01:00
|
|
|
}
|
2020-01-27 13:52:32 +01:00
|
|
|
m_ui.sizeComboBox->addItem(QString::number(sizeLst.at(i)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-09-28 11:16:57 +02:00
|
|
|
if (idx != -1)
|
2020-01-27 13:52:32 +01:00
|
|
|
m_ui.sizeComboBox->setCurrentIndex(idx);
|
2009-06-18 17:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
QList<int> FontSettingsPageWidget::pointSizesForSelectedFont() const
|
2010-04-16 12:54:49 +02:00
|
|
|
{
|
|
|
|
|
QFontDatabase db;
|
2020-01-27 13:52:32 +01:00
|
|
|
const QString familyName = m_ui.fontComboBox->currentFont().family();
|
2010-04-16 12:54:49 +02:00
|
|
|
QList<int> sizeLst = db.pointSizes(familyName);
|
|
|
|
|
if (!sizeLst.isEmpty())
|
|
|
|
|
return sizeLst;
|
|
|
|
|
|
|
|
|
|
QStringList styles = db.styles(familyName);
|
|
|
|
|
if (!styles.isEmpty())
|
|
|
|
|
sizeLst = db.pointSizes(familyName, styles.first());
|
|
|
|
|
if (sizeLst.isEmpty())
|
|
|
|
|
sizeLst = QFontDatabase::standardSizes();
|
|
|
|
|
|
|
|
|
|
return sizeLst;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 10:14:47 +02:00
|
|
|
void FontSettingsPageWidget::fontSizeSelected(int index)
|
2009-07-17 17:24:32 +02:00
|
|
|
{
|
2020-06-19 10:14:47 +02:00
|
|
|
const QString sizeString = m_ui.sizeComboBox->itemText(index);
|
2009-07-17 17:24:32 +02:00
|
|
|
bool ok = true;
|
|
|
|
|
const int size = sizeString.toInt(&ok);
|
|
|
|
|
if (ok) {
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value.setFontSize(size);
|
|
|
|
|
m_ui.schemeEdit->setBaseFont(m_value.font());
|
2009-07-17 17:24:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::fontZoomChanged()
|
2009-11-30 19:00:36 +01:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value.setFontZoom(m_ui.zoomSpinBox->value());
|
2009-11-30 19:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::antialiasChanged()
|
2014-02-04 14:11:44 +01:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value.setAntialias(m_ui.antialias->isChecked());
|
|
|
|
|
m_ui.schemeEdit->setBaseFont(m_value.font());
|
2014-02-04 14:11:44 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::colorSchemeSelected(int index)
|
2009-07-07 18:35:42 +02:00
|
|
|
{
|
2009-07-17 17:24:32 +02:00
|
|
|
bool readOnly = true;
|
2009-07-16 17:16:55 +02:00
|
|
|
if (index != -1) {
|
2009-07-17 17:24:32 +02:00
|
|
|
// Check whether we're switching away from a changed color scheme
|
2020-01-27 13:52:32 +01:00
|
|
|
if (!m_refreshingSchemeList)
|
2009-07-17 17:24:32 +02:00
|
|
|
maybeSaveColorScheme();
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
const ColorSchemeEntry &entry = m_schemeListModel.colorSchemeAt(index);
|
2009-07-17 17:24:32 +02:00
|
|
|
readOnly = entry.readOnly;
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value.loadColorScheme(entry.fileName, m_descriptions);
|
|
|
|
|
m_ui.schemeEdit->setColorScheme(m_value.colorScheme());
|
2009-07-13 14:08:14 +02:00
|
|
|
}
|
2020-01-27 13:52:32 +01:00
|
|
|
m_ui.copyButton->setEnabled(index != -1);
|
|
|
|
|
m_ui.deleteButton->setEnabled(!readOnly);
|
|
|
|
|
m_ui.schemeEdit->setReadOnly(readOnly);
|
2009-07-07 18:35:42 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::openCopyColorSchemeDialog()
|
2009-07-20 16:58:53 +02:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
QInputDialog *dialog = new QInputDialog(m_ui.copyButton->window());
|
2009-07-20 16:58:53 +02:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
dialog->setInputMode(QInputDialog::TextInput);
|
|
|
|
|
dialog->setWindowTitle(tr("Copy Color Scheme"));
|
2010-05-14 15:45:43 +02:00
|
|
|
dialog->setLabelText(tr("Color scheme name:"));
|
2020-01-27 13:52:32 +01:00
|
|
|
dialog->setTextValue(tr("%1 (copy)").arg(m_value.colorScheme().displayName()));
|
2009-07-20 16:58:53 +02:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
connect(dialog, &QInputDialog::textValueSelected, this, &FontSettingsPageWidget::copyColorScheme);
|
2009-07-20 16:58:53 +02:00
|
|
|
dialog->open();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::copyColorScheme(const QString &name)
|
2009-07-07 16:07:40 +02:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
int index = m_ui.schemeComboBox->currentIndex();
|
2009-07-16 17:16:55 +02:00
|
|
|
if (index == -1)
|
2009-07-13 14:08:14 +02:00
|
|
|
return;
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
const ColorSchemeEntry &entry = m_schemeListModel.colorSchemeAt(index);
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2009-07-15 15:39:35 +02:00
|
|
|
QString baseFileName = QFileInfo(entry.fileName).completeBaseName();
|
|
|
|
|
baseFileName += QLatin1String("_copy%1.xml");
|
2021-07-01 10:22:34 +02:00
|
|
|
Utils::FilePath fileName = createColorSchemeFileName(baseFileName);
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2009-07-15 15:39:35 +02:00
|
|
|
if (!fileName.isEmpty()) {
|
2021-09-10 14:59:27 +02:00
|
|
|
// Ask about saving any existing modifications
|
2009-07-17 17:24:32 +02:00
|
|
|
maybeSaveColorScheme();
|
|
|
|
|
|
|
|
|
|
// Make sure we're copying the current version
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value.setColorScheme(m_ui.schemeEdit->colorScheme());
|
2009-07-17 17:24:32 +02:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
ColorScheme scheme = m_value.colorScheme();
|
2010-01-07 18:17:24 +01:00
|
|
|
scheme.setDisplayName(name);
|
2021-07-01 10:22:34 +02:00
|
|
|
if (scheme.save(fileName.path(), Core::ICore::dialogParent()))
|
|
|
|
|
m_value.setColorSchemeFileName(fileName.path());
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2009-07-15 15:39:35 +02:00
|
|
|
refreshColorSchemeList();
|
2009-07-13 14:08:14 +02:00
|
|
|
}
|
2009-07-07 16:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::confirmDeleteColorScheme()
|
2009-07-07 16:07:40 +02:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
const int index = m_ui.schemeComboBox->currentIndex();
|
2009-07-16 17:16:55 +02:00
|
|
|
if (index == -1)
|
2009-07-13 14:08:14 +02:00
|
|
|
return;
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
const ColorSchemeEntry &entry = m_schemeListModel.colorSchemeAt(index);
|
2009-07-22 14:16:21 +02:00
|
|
|
if (entry.readOnly)
|
|
|
|
|
return;
|
2009-07-16 17:16:55 +02:00
|
|
|
|
2009-07-22 14:16:21 +02:00
|
|
|
QMessageBox *messageBox = new QMessageBox(QMessageBox::Warning,
|
|
|
|
|
tr("Delete Color Scheme"),
|
|
|
|
|
tr("Are you sure you want to delete this color scheme permanently?"),
|
|
|
|
|
QMessageBox::Discard | QMessageBox::Cancel,
|
2020-01-27 13:52:32 +01:00
|
|
|
m_ui.deleteButton->window());
|
2009-07-22 14:16:21 +02:00
|
|
|
|
|
|
|
|
// Change the text and role of the discard button
|
2018-09-20 01:16:01 +03:00
|
|
|
auto deleteButton = static_cast<QPushButton*>(messageBox->button(QMessageBox::Discard));
|
2009-07-22 14:16:21 +02:00
|
|
|
deleteButton->setText(tr("Delete"));
|
|
|
|
|
messageBox->addButton(deleteButton, QMessageBox::AcceptRole);
|
|
|
|
|
messageBox->setDefaultButton(deleteButton);
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
connect(messageBox, &QDialog::accepted, this, &FontSettingsPageWidget::deleteColorScheme);
|
2009-07-22 14:16:21 +02:00
|
|
|
messageBox->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
messageBox->open();
|
|
|
|
|
}
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::deleteColorScheme()
|
2009-07-22 14:16:21 +02:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
const int index = m_ui.schemeComboBox->currentIndex();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(index != -1, return);
|
2009-07-22 14:16:21 +02:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
const ColorSchemeEntry &entry = m_schemeListModel.colorSchemeAt(index);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(!entry.readOnly, return);
|
2009-07-22 14:16:21 +02:00
|
|
|
|
|
|
|
|
if (QFile::remove(entry.fileName))
|
2020-01-27 13:52:32 +01:00
|
|
|
m_schemeListModel.removeColorScheme(index);
|
2009-07-07 16:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-10 14:59:27 +02:00
|
|
|
void FontSettingsPageWidget::importScheme()
|
|
|
|
|
{
|
|
|
|
|
const Utils::FilePath importedFile
|
|
|
|
|
= Utils::FileUtils::getOpenFilePath(this,
|
|
|
|
|
tr("Import Color Scheme"),
|
|
|
|
|
{},
|
|
|
|
|
tr("Color scheme (*.xml);;All files (*)"));
|
|
|
|
|
|
|
|
|
|
if (importedFile.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Utils::FilePath fileName = createColorSchemeFileName(importedFile.baseName() + "%1."
|
|
|
|
|
+ importedFile.suffix());
|
|
|
|
|
|
|
|
|
|
// Ask about saving any existing modifications
|
|
|
|
|
maybeSaveColorScheme();
|
|
|
|
|
|
|
|
|
|
QInputDialog *dialog = new QInputDialog(m_ui.copyButton->window());
|
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
dialog->setInputMode(QInputDialog::TextInput);
|
|
|
|
|
dialog->setWindowTitle(tr("Import Color Scheme"));
|
|
|
|
|
dialog->setLabelText(tr("Color scheme name:"));
|
|
|
|
|
dialog->setTextValue(importedFile.baseName());
|
|
|
|
|
|
|
|
|
|
connect(dialog, &QInputDialog::textValueSelected, this, [this, fileName](const QString &name) {
|
|
|
|
|
m_value.setColorScheme(m_ui.schemeEdit->colorScheme());
|
|
|
|
|
|
|
|
|
|
ColorScheme scheme = m_value.colorScheme();
|
|
|
|
|
scheme.setDisplayName(name);
|
|
|
|
|
if (scheme.save(fileName.path(), Core::ICore::dialogParent()))
|
|
|
|
|
m_value.setColorSchemeFileName(fileName.path());
|
|
|
|
|
|
|
|
|
|
refreshColorSchemeList();
|
|
|
|
|
});
|
|
|
|
|
dialog->open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FontSettingsPageWidget::exportScheme()
|
|
|
|
|
{
|
|
|
|
|
int index = m_ui.schemeComboBox->currentIndex();
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const ColorSchemeEntry &entry = m_schemeListModel.colorSchemeAt(index);
|
|
|
|
|
|
|
|
|
|
const Utils::FilePath filePath
|
|
|
|
|
= Utils::FileUtils::getSaveFilePath(this,
|
|
|
|
|
tr("Export Color Scheme"),
|
|
|
|
|
Utils::FilePath::fromString(entry.fileName),
|
|
|
|
|
tr("Color scheme (*.xml);;All files (*)"));
|
|
|
|
|
|
|
|
|
|
if (!filePath.isEmpty())
|
|
|
|
|
m_value.colorScheme().save(filePath.toString(), Core::ICore::dialogParent());
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::maybeSaveColorScheme()
|
2009-06-18 17:35:46 +02:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
if (m_value.colorScheme() == m_ui.schemeEdit->colorScheme())
|
2009-07-13 14:08:14 +02:00
|
|
|
return;
|
|
|
|
|
|
2021-09-10 14:59:27 +02:00
|
|
|
QMessageBox
|
|
|
|
|
messageBox(QMessageBox::Warning,
|
|
|
|
|
tr("Color Scheme Changed"),
|
|
|
|
|
tr("The color scheme \"%1\" was modified, do you want to save the changes?")
|
|
|
|
|
.arg(m_ui.schemeEdit->colorScheme().displayName()),
|
|
|
|
|
QMessageBox::Discard | QMessageBox::Save,
|
|
|
|
|
m_ui.schemeComboBox->window());
|
2009-07-23 09:57:02 +02:00
|
|
|
|
|
|
|
|
// Change the text of the discard button
|
2018-09-20 01:16:01 +03:00
|
|
|
auto discardButton = static_cast<QPushButton*>(messageBox.button(QMessageBox::Discard));
|
2009-07-23 09:57:02 +02:00
|
|
|
discardButton->setText(tr("Discard"));
|
2017-02-21 10:04:31 +01:00
|
|
|
messageBox.addButton(discardButton, QMessageBox::DestructiveRole);
|
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Save);
|
2009-07-23 09:57:02 +02:00
|
|
|
|
2017-02-21 10:04:31 +01:00
|
|
|
if (messageBox.exec() == QMessageBox::Save) {
|
2020-01-27 13:52:32 +01:00
|
|
|
const ColorScheme &scheme = m_ui.schemeEdit->colorScheme();
|
2020-06-02 09:10:40 +02:00
|
|
|
scheme.save(m_value.colorSchemeFileName(), Core::ICore::dialogParent());
|
2009-07-13 14:08:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::refreshColorSchemeList()
|
2009-07-07 16:07:40 +02:00
|
|
|
{
|
2009-07-16 17:16:55 +02:00
|
|
|
QList<ColorSchemeEntry> colorSchemes;
|
2009-07-07 16:07:40 +02:00
|
|
|
|
2021-04-26 15:46:09 +02:00
|
|
|
QDir styleDir(Core::ICore::resourcePath("styles").toDir());
|
2009-07-07 16:07:40 +02:00
|
|
|
styleDir.setNameFilters(QStringList() << QLatin1String("*.xml"));
|
|
|
|
|
styleDir.setFilter(QDir::Files);
|
|
|
|
|
|
2009-07-07 18:35:42 +02:00
|
|
|
int selected = 0;
|
|
|
|
|
|
2010-03-22 12:41:04 +01:00
|
|
|
QStringList schemeList = styleDir.entryList();
|
2019-05-28 13:49:26 +02:00
|
|
|
QString defaultScheme = Utils::FilePath::fromString(FontSettings::defaultSchemeFileName()).fileName();
|
2010-03-22 12:41:04 +01:00
|
|
|
if (schemeList.removeAll(defaultScheme))
|
|
|
|
|
schemeList.prepend(defaultScheme);
|
2022-05-17 10:31:15 +02:00
|
|
|
for (const QString &file : qAsConst(schemeList)) {
|
2009-07-13 14:08:14 +02:00
|
|
|
const QString fileName = styleDir.absoluteFilePath(file);
|
2020-01-27 13:52:32 +01:00
|
|
|
if (m_value.colorSchemeFileName() == fileName)
|
2009-07-16 17:16:55 +02:00
|
|
|
selected = colorSchemes.size();
|
|
|
|
|
colorSchemes.append(ColorSchemeEntry(fileName, true));
|
2009-07-13 14:08:14 +02:00
|
|
|
}
|
|
|
|
|
|
2009-09-02 17:17:13 +02:00
|
|
|
if (colorSchemes.isEmpty())
|
|
|
|
|
qWarning() << "Warning: no color schemes found in path:" << styleDir.path();
|
|
|
|
|
|
2021-07-01 10:22:34 +02:00
|
|
|
styleDir.setPath(customStylesPath().path());
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2022-05-17 10:31:15 +02:00
|
|
|
const QStringList files = styleDir.entryList();
|
|
|
|
|
for (const QString &file : files) {
|
2009-07-13 14:08:14 +02:00
|
|
|
const QString fileName = styleDir.absoluteFilePath(file);
|
2020-01-27 13:52:32 +01:00
|
|
|
if (m_value.colorSchemeFileName() == fileName)
|
2009-07-16 17:16:55 +02:00
|
|
|
selected = colorSchemes.size();
|
|
|
|
|
colorSchemes.append(ColorSchemeEntry(fileName, false));
|
2009-07-07 16:07:40 +02:00
|
|
|
}
|
2009-07-07 18:35:42 +02:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
m_refreshingSchemeList = true;
|
|
|
|
|
m_schemeListModel.setColorSchemes(colorSchemes);
|
|
|
|
|
m_ui.schemeComboBox->setCurrentIndex(selected);
|
|
|
|
|
m_refreshingSchemeList = false;
|
2009-07-07 16:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::apply()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
if (m_value.colorScheme() != m_ui.schemeEdit->colorScheme()) {
|
2009-07-17 17:24:32 +02:00
|
|
|
// Update the scheme and save it under the name it already has
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value.setColorScheme(m_ui.schemeEdit->colorScheme());
|
|
|
|
|
const ColorScheme &scheme = m_value.colorScheme();
|
2020-06-02 09:10:40 +02:00
|
|
|
scheme.save(m_value.colorSchemeFileName(), Core::ICore::dialogParent());
|
2009-07-17 17:24:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-13 15:58:31 +01:00
|
|
|
bool ok;
|
2020-01-27 13:52:32 +01:00
|
|
|
int fontSize = m_ui.sizeComboBox->currentText().toInt(&ok);
|
|
|
|
|
if (ok && m_value.fontSize() != fontSize) {
|
|
|
|
|
m_value.setFontSize(fontSize);
|
|
|
|
|
m_ui.schemeEdit->setBaseFont(m_value.font());
|
2020-01-13 15:58:31 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
int index = m_ui.schemeComboBox->currentIndex();
|
2009-07-16 17:16:55 +02:00
|
|
|
if (index != -1) {
|
2020-01-27 13:52:32 +01:00
|
|
|
const ColorSchemeEntry &entry = m_schemeListModel.colorSchemeAt(index);
|
|
|
|
|
if (entry.fileName != m_value.colorSchemeFileName())
|
|
|
|
|
m_value.loadColorScheme(entry.fileName, m_descriptions);
|
2009-07-07 18:35:42 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-18 16:12:24 +02:00
|
|
|
saveSettings();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::saveSettings()
|
2009-06-18 16:12:24 +02:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
m_lastValue = m_value;
|
|
|
|
|
m_value.toSettings(Core::ICore::settings());
|
|
|
|
|
emit TextEditorSettings::instance()->fontSettingsChanged(m_value);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
void FontSettingsPageWidget::finish()
|
2009-01-13 15:41:33 +01:00
|
|
|
{
|
|
|
|
|
// If changes were applied, these are equal. Otherwise restores last value.
|
2020-01-27 13:52:32 +01:00
|
|
|
m_value = m_lastValue;
|
2009-01-13 15:41:33 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 13:46:25 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
2020-01-27 13:52:32 +01:00
|
|
|
// FontSettingsPage
|
|
|
|
|
|
|
|
|
|
FontSettingsPage::FontSettingsPage(FontSettings *fontSettings, const FormatDescriptions &fd)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-01-27 13:52:32 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
|
|
|
|
if (settings)
|
|
|
|
|
fontSettings->fromSettings(fd, settings);
|
|
|
|
|
|
|
|
|
|
if (fontSettings->colorSchemeFileName().isEmpty())
|
|
|
|
|
fontSettings->loadColorScheme(FontSettings::defaultSchemeFileName(), fd);
|
|
|
|
|
|
|
|
|
|
setId(Constants::TEXT_EDITOR_FONT_SETTINGS);
|
|
|
|
|
setDisplayName(FontSettingsPageWidget::tr("Font && Colors"));
|
|
|
|
|
setCategory(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("TextEditor", "Text Editor"));
|
|
|
|
|
setCategoryIconPath(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON_PATH);
|
|
|
|
|
setWidgetCreator([this, fontSettings, fd] { return new FontSettingsPageWidget(this, fd, fontSettings); });
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2020-01-27 13:52:32 +01:00
|
|
|
|
|
|
|
|
void FontSettingsPage::setFontZoom(int zoom)
|
|
|
|
|
{
|
2020-02-27 14:43:35 +01:00
|
|
|
if (m_widget)
|
|
|
|
|
static_cast<FontSettingsPageWidget *>(m_widget.data())->m_ui.zoomSpinBox->setValue(zoom);
|
2020-01-27 13:52:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // TextEditor
|