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"
|
|
|
|
|
#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>
|
2009-11-25 12:34:56 +01: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
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
class FontSettingsPagePrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-02-03 23:46:35 +02:00
|
|
|
FontSettingsPagePrivate(const FormatDescriptions &fd,
|
2013-01-16 15:22:58 +01:00
|
|
|
Core::Id id,
|
2010-04-12 15:53:17 +02:00
|
|
|
const QString &displayName,
|
|
|
|
|
const QString &category);
|
2009-07-16 17:16:55 +02:00
|
|
|
~FontSettingsPagePrivate();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
public:
|
2013-01-16 15:22:58 +01:00
|
|
|
const Core::Id m_id;
|
2010-01-07 18:17:24 +01:00
|
|
|
const QString m_displayName;
|
2008-12-02 12:01:29 +01:00
|
|
|
const QString m_settingsGroup;
|
|
|
|
|
|
2015-02-03 23:46:35 +02:00
|
|
|
FormatDescriptions m_descriptions;
|
2008-12-02 12:01:29 +01:00
|
|
|
FontSettings m_value;
|
|
|
|
|
FontSettings m_lastValue;
|
2013-12-03 14:17:03 +01:00
|
|
|
QPointer<QWidget> m_widget;
|
2010-12-02 18:28:16 +01:00
|
|
|
Ui::FontSettingsPage *m_ui;
|
2009-07-16 17:16:55 +02:00
|
|
|
SchemeListModel *m_schemeListModel;
|
2009-07-17 17:24:32 +02:00
|
|
|
bool m_refreshingSchemeList;
|
2009-07-13 14:08:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace TextEditor
|
|
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace TextEditor::Internal;
|
|
|
|
|
|
2009-07-15 12:27:02 +02:00
|
|
|
static QString customStylesPath()
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QString path = Core::ICore::userResourcePath();
|
2010-08-25 18:16:04 +02:00
|
|
|
path.append(QLatin1String("/styles/"));
|
2009-07-15 12:27:02 +02:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-15 15:39:35 +02:00
|
|
|
static QString createColorSchemeFileName(const QString &pattern)
|
|
|
|
|
{
|
|
|
|
|
const QString stylesPath = customStylesPath();
|
|
|
|
|
QString baseFileName = stylesPath;
|
|
|
|
|
baseFileName += pattern;
|
|
|
|
|
|
|
|
|
|
// Find an available file name
|
|
|
|
|
int i = 1;
|
|
|
|
|
QString fileName;
|
|
|
|
|
do {
|
|
|
|
|
fileName = baseFileName.arg((i == 1) ? QString() : QString::number(i));
|
|
|
|
|
++i;
|
|
|
|
|
} while (QFile::exists(fileName));
|
|
|
|
|
|
|
|
|
|
// Create the base directory when it doesn't exist
|
|
|
|
|
if (!QFile::exists(stylesPath) && !QDir().mkpath(stylesPath)) {
|
|
|
|
|
qWarning() << "Failed to create color scheme directory:" << stylesPath;
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fileName;
|
|
|
|
|
}
|
2009-07-13 14:08:14 +02:00
|
|
|
|
|
|
|
|
// ------- FontSettingsPagePrivate
|
2015-02-03 23:46:35 +02:00
|
|
|
FontSettingsPagePrivate::FontSettingsPagePrivate(const FormatDescriptions &fd,
|
2013-01-16 15:22:58 +01:00
|
|
|
Core::Id id,
|
2010-01-07 18:17:24 +01:00
|
|
|
const QString &displayName,
|
2010-04-12 15:53:17 +02:00
|
|
|
const QString &category) :
|
2009-11-27 16:12:12 +01:00
|
|
|
m_id(id),
|
2010-01-07 18:17:24 +01:00
|
|
|
m_displayName(displayName),
|
2009-10-05 11:06:05 +02:00
|
|
|
m_settingsGroup(Utils::settingsKey(category)),
|
2009-07-16 17:16:55 +02:00
|
|
|
m_descriptions(fd),
|
2017-02-20 16:31:35 +01:00
|
|
|
m_ui(nullptr),
|
2009-07-17 17:24:32 +02:00
|
|
|
m_schemeListModel(new SchemeListModel),
|
|
|
|
|
m_refreshingSchemeList(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2009-07-15 12:27:02 +02:00
|
|
|
if (settings)
|
2016-01-21 17:44:09 +01:00
|
|
|
m_value.fromSettings(m_settingsGroup, m_descriptions, settings);
|
|
|
|
|
|
|
|
|
|
if (m_value.colorSchemeFileName().isEmpty())
|
|
|
|
|
m_value.loadColorScheme(FontSettings::defaultSchemeFileName(), m_descriptions);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_lastValue = m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 17:16:55 +02:00
|
|
|
FontSettingsPagePrivate::~FontSettingsPagePrivate()
|
|
|
|
|
{
|
|
|
|
|
delete m_schemeListModel;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2016-06-19 10:46:49 +03:00
|
|
|
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);
|
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);
|
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);
|
2016-06-19 10:46:49 +03:00
|
|
|
} else if (id == C_OCCURRENCES) {
|
2009-11-25 15:55:45 +01:00
|
|
|
return QColor(180, 180, 180);
|
2016-06-19 10:46:49 +03: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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ------------ FontSettingsPage
|
|
|
|
|
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd,
|
2013-01-16 15:22:58 +01:00
|
|
|
Core::Id id,
|
2008-12-02 12:01:29 +01:00
|
|
|
QObject *parent) :
|
2020-01-15 15:00:57 +01:00
|
|
|
Core::IOptionsPage(parent),
|
2020-01-20 09:35:51 +01:00
|
|
|
d_ptr(new FontSettingsPagePrivate(fd, id, tr("Font && Colors"), TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-05-22 11:17:13 +02:00
|
|
|
setId(d_ptr->m_id);
|
|
|
|
|
setDisplayName(d_ptr->m_displayName);
|
2020-01-15 15:00:57 +01:00
|
|
|
setCategory(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("TextEditor", "Text Editor"));
|
|
|
|
|
setCategoryIconPath(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON_PATH);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FontSettingsPage::~FontSettingsPage()
|
|
|
|
|
{
|
|
|
|
|
delete d_ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *FontSettingsPage::widget()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!d_ptr->m_widget){
|
|
|
|
|
d_ptr->m_widget = new QWidget;
|
|
|
|
|
d_ptr->m_ui = new Ui::FontSettingsPage;
|
|
|
|
|
d_ptr->m_ui->setupUi(d_ptr->m_widget);
|
2015-12-09 18:16:37 +01:00
|
|
|
d_ptr->m_ui->colorSchemeGroupBox->setTitle(
|
2017-08-29 11:48:48 +02:00
|
|
|
tr("Color Scheme for Theme \"%1\"")
|
2015-12-09 18:16:37 +01:00
|
|
|
.arg(Utils::creatorTheme()->displayName()));
|
2013-12-03 14:17:03 +01:00
|
|
|
d_ptr->m_ui->schemeComboBox->setModel(d_ptr->m_schemeListModel);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-04-22 15:09:42 +02:00
|
|
|
d_ptr->m_ui->fontComboBox->setCurrentFont(d_ptr->m_value.family());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
d_ptr->m_ui->antialias->setChecked(d_ptr->m_value.antialias());
|
|
|
|
|
d_ptr->m_ui->zoomSpinBox->setValue(d_ptr->m_value.fontZoom());
|
2009-05-27 15:33:37 +02:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
d_ptr->m_ui->schemeEdit->setFormatDescriptions(d_ptr->m_descriptions);
|
|
|
|
|
d_ptr->m_ui->schemeEdit->setBaseFont(d_ptr->m_value.font());
|
|
|
|
|
d_ptr->m_ui->schemeEdit->setColorScheme(d_ptr->m_value.colorScheme());
|
2009-07-17 17:24:32 +02:00
|
|
|
|
2020-01-13 15:58:31 +01:00
|
|
|
auto sizeValidator = new QIntValidator(d_ptr->m_ui->sizeComboBox);
|
|
|
|
|
sizeValidator->setBottom(0);
|
|
|
|
|
d_ptr->m_ui->sizeComboBox->setValidator(sizeValidator);
|
|
|
|
|
|
2015-04-22 15:09:42 +02:00
|
|
|
connect(d_ptr->m_ui->fontComboBox, &QFontComboBox::currentFontChanged,
|
|
|
|
|
this, &FontSettingsPage::fontSelected);
|
2019-07-16 13:03:51 +00:00
|
|
|
connect(d_ptr->m_ui->sizeComboBox,
|
|
|
|
|
QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
|
2015-04-22 15:09:42 +02:00
|
|
|
this, &FontSettingsPage::fontSizeSelected);
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(d_ptr->m_ui->zoomSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
|
2015-04-22 15:09:42 +02:00
|
|
|
this, &FontSettingsPage::fontZoomChanged);
|
|
|
|
|
connect(d_ptr->m_ui->antialias, &QCheckBox::toggled,
|
|
|
|
|
this, &FontSettingsPage::antialiasChanged);
|
|
|
|
|
connect(d_ptr->m_ui->schemeComboBox,
|
2019-02-26 09:40:49 +01:00
|
|
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2015-04-22 15:09:42 +02:00
|
|
|
this, &FontSettingsPage::colorSchemeSelected);
|
|
|
|
|
connect(d_ptr->m_ui->copyButton, &QPushButton::clicked,
|
|
|
|
|
this, &FontSettingsPage::openCopyColorSchemeDialog);
|
2019-02-21 13:25:17 +01:00
|
|
|
connect(d_ptr->m_ui->schemeEdit, &ColorSchemeEdit::copyScheme,
|
|
|
|
|
this, &FontSettingsPage::openCopyColorSchemeDialog);
|
2015-04-22 15:09:42 +02:00
|
|
|
connect(d_ptr->m_ui->deleteButton, &QPushButton::clicked,
|
|
|
|
|
this, &FontSettingsPage::confirmDeleteColorScheme);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-30 19:00:36 +01:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
updatePointSizes();
|
|
|
|
|
refreshColorSchemeList();
|
|
|
|
|
d_ptr->m_lastValue = d_ptr->m_value;
|
2010-12-01 14:35:36 +01:00
|
|
|
}
|
2013-12-03 14:17:03 +01:00
|
|
|
return d_ptr->m_widget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-22 15:09:42 +02:00
|
|
|
void FontSettingsPage::fontSelected(const QFont &font)
|
2009-07-17 17:24:32 +02:00
|
|
|
{
|
2015-04-22 15:09:42 +02:00
|
|
|
d_ptr->m_value.setFamily(font.family());
|
|
|
|
|
d_ptr->m_ui->schemeEdit->setBaseFont(font);
|
2009-07-17 17:24:32 +02:00
|
|
|
updatePointSizes();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FontSettingsPage::updatePointSizes()
|
|
|
|
|
{
|
2009-07-17 17:24:32 +02:00
|
|
|
// Update point sizes
|
2008-12-02 12:01:29 +01:00
|
|
|
const int oldSize = d_ptr->m_value.fontSize();
|
2011-10-20 18:54:07 +02:00
|
|
|
d_ptr->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)
|
|
|
|
|
d_ptr->m_ui->sizeComboBox->addItem(QString::number(oldSize));
|
|
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->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)
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_ui->sizeComboBox->setCurrentIndex(idx);
|
2009-06-18 17:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-16 12:54:49 +02:00
|
|
|
QList<int> FontSettingsPage::pointSizesForSelectedFont() const
|
|
|
|
|
{
|
|
|
|
|
QFontDatabase db;
|
2015-04-22 15:09:42 +02:00
|
|
|
const QString familyName = d_ptr->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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-17 17:24:32 +02:00
|
|
|
void FontSettingsPage::fontSizeSelected(const QString &sizeString)
|
|
|
|
|
{
|
|
|
|
|
bool ok = true;
|
|
|
|
|
const int size = sizeString.toInt(&ok);
|
|
|
|
|
if (ok) {
|
|
|
|
|
d_ptr->m_value.setFontSize(size);
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_ui->schemeEdit->setBaseFont(d_ptr->m_value.font());
|
2009-07-17 17:24:32 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-30 19:00:36 +01:00
|
|
|
void FontSettingsPage::fontZoomChanged()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_value.setFontZoom(d_ptr->m_ui->zoomSpinBox->value());
|
2009-11-30 19:00:36 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 14:11:44 +01:00
|
|
|
void FontSettingsPage::antialiasChanged()
|
|
|
|
|
{
|
|
|
|
|
d_ptr->m_value.setAntialias(d_ptr->m_ui->antialias->isChecked());
|
|
|
|
|
d_ptr->m_ui->schemeEdit->setBaseFont(d_ptr->m_value.font());
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 17:16:55 +02:00
|
|
|
void FontSettingsPage::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
|
|
|
|
|
if (!d_ptr->m_refreshingSchemeList)
|
|
|
|
|
maybeSaveColorScheme();
|
|
|
|
|
|
2009-07-16 17:16:55 +02:00
|
|
|
const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index);
|
2009-07-17 17:24:32 +02:00
|
|
|
readOnly = entry.readOnly;
|
|
|
|
|
d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->m_descriptions);
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_ui->schemeEdit->setColorScheme(d_ptr->m_value.colorScheme());
|
2009-07-13 14:08:14 +02:00
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_ui->copyButton->setEnabled(index != -1);
|
|
|
|
|
d_ptr->m_ui->deleteButton->setEnabled(!readOnly);
|
|
|
|
|
d_ptr->m_ui->schemeEdit->setReadOnly(readOnly);
|
2009-07-07 18:35:42 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-22 15:09:42 +02:00
|
|
|
void FontSettingsPage::openCopyColorSchemeDialog()
|
2009-07-20 16:58:53 +02:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
QInputDialog *dialog = new QInputDialog(d_ptr->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:"));
|
2010-01-07 18:17:24 +01:00
|
|
|
dialog->setTextValue(tr("%1 (copy)").arg(d_ptr->m_value.colorScheme().displayName()));
|
2009-07-20 16:58:53 +02:00
|
|
|
|
2015-12-13 01:18:33 +02:00
|
|
|
connect(dialog, &QInputDialog::textValueSelected, this, &FontSettingsPage::copyColorScheme);
|
2009-07-20 16:58:53 +02:00
|
|
|
dialog->open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FontSettingsPage::copyColorScheme(const QString &name)
|
2009-07-07 16:07:40 +02:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
int index = d_ptr->m_ui->schemeComboBox->currentIndex();
|
2009-07-16 17:16:55 +02:00
|
|
|
if (index == -1)
|
2009-07-13 14:08:14 +02:00
|
|
|
return;
|
|
|
|
|
|
2009-07-16 17:16:55 +02:00
|
|
|
const ColorSchemeEntry &entry = d_ptr->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");
|
|
|
|
|
QString fileName = createColorSchemeFileName(baseFileName);
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2009-07-15 15:39:35 +02:00
|
|
|
if (!fileName.isEmpty()) {
|
2009-07-17 17:24:32 +02:00
|
|
|
// Ask about saving any existing modifactions
|
|
|
|
|
maybeSaveColorScheme();
|
|
|
|
|
|
|
|
|
|
// Make sure we're copying the current version
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_value.setColorScheme(d_ptr->m_ui->schemeEdit->colorScheme());
|
2009-07-17 17:24:32 +02:00
|
|
|
|
2009-07-15 15:39:35 +02:00
|
|
|
ColorScheme scheme = d_ptr->m_value.colorScheme();
|
2010-01-07 18:17:24 +01:00
|
|
|
scheme.setDisplayName(name);
|
2012-01-24 15:36:40 +01:00
|
|
|
if (scheme.save(fileName, Core::ICore::mainWindow()))
|
2011-03-30 15:15:15 +02:00
|
|
|
d_ptr->m_value.setColorSchemeFileName(fileName);
|
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
|
|
|
}
|
|
|
|
|
|
2009-07-22 14:16:21 +02:00
|
|
|
void FontSettingsPage::confirmDeleteColorScheme()
|
2009-07-07 16:07:40 +02:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
const int index = d_ptr->m_ui->schemeComboBox->currentIndex();
|
2009-07-16 17:16:55 +02:00
|
|
|
if (index == -1)
|
2009-07-13 14:08:14 +02:00
|
|
|
return;
|
|
|
|
|
|
2009-07-16 17:16:55 +02:00
|
|
|
const ColorSchemeEntry &entry = d_ptr->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,
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->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);
|
|
|
|
|
|
2015-12-13 01:18:33 +02:00
|
|
|
connect(deleteButton, &QAbstractButton::clicked, messageBox, &QDialog::accept);
|
|
|
|
|
connect(messageBox, &QDialog::accepted, this, &FontSettingsPage::deleteColorScheme);
|
2009-07-22 14:16:21 +02:00
|
|
|
messageBox->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
messageBox->open();
|
|
|
|
|
}
|
2009-07-13 14:08:14 +02:00
|
|
|
|
2009-07-22 14:16:21 +02:00
|
|
|
void FontSettingsPage::deleteColorScheme()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
const int index = d_ptr->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
|
|
|
|
|
|
|
|
const ColorSchemeEntry &entry = d_ptr->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))
|
|
|
|
|
d_ptr->m_schemeListModel->removeColorScheme(index);
|
2009-07-07 16:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
2009-07-17 17:24:32 +02:00
|
|
|
void FontSettingsPage::maybeSaveColorScheme()
|
2009-06-18 17:35:46 +02:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
if (d_ptr->m_value.colorScheme() == d_ptr->m_ui->schemeEdit->colorScheme())
|
2009-07-13 14:08:14 +02:00
|
|
|
return;
|
|
|
|
|
|
2017-02-21 10:04:31 +01:00
|
|
|
QMessageBox messageBox(QMessageBox::Warning,
|
2009-07-23 09:57:02 +02:00
|
|
|
tr("Color Scheme Changed"),
|
|
|
|
|
tr("The color scheme \"%1\" was modified, do you want to save the changes?")
|
2010-12-02 18:28:16 +01:00
|
|
|
.arg(d_ptr->m_ui->schemeEdit->colorScheme().displayName()),
|
2009-07-23 09:57:02 +02:00
|
|
|
QMessageBox::Discard | QMessageBox::Save,
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->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) {
|
2010-12-02 18:28:16 +01:00
|
|
|
const ColorScheme &scheme = d_ptr->m_ui->schemeEdit->colorScheme();
|
2012-01-24 15:36:40 +01:00
|
|
|
scheme.save(d_ptr->m_value.colorSchemeFileName(), Core::ICore::mainWindow());
|
2009-07-13 14:08:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-07 16:07:40 +02:00
|
|
|
void FontSettingsPage::refreshColorSchemeList()
|
|
|
|
|
{
|
2009-07-16 17:16:55 +02:00
|
|
|
QList<ColorSchemeEntry> colorSchemes;
|
2009-07-07 16:07:40 +02:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QString resourcePath = Core::ICore::resourcePath();
|
2009-07-07 16:07:40 +02:00
|
|
|
QDir styleDir(resourcePath + QLatin1String("/styles"));
|
|
|
|
|
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);
|
|
|
|
|
foreach (const QString &file, schemeList) {
|
2009-07-13 14:08:14 +02:00
|
|
|
const QString fileName = styleDir.absoluteFilePath(file);
|
|
|
|
|
if (d_ptr->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();
|
|
|
|
|
|
2009-07-13 14:08:14 +02:00
|
|
|
styleDir.setPath(customStylesPath());
|
|
|
|
|
|
|
|
|
|
foreach (const QString &file, styleDir.entryList()) {
|
|
|
|
|
const QString fileName = styleDir.absoluteFilePath(file);
|
|
|
|
|
if (d_ptr->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
|
|
|
|
2009-07-17 17:24:32 +02:00
|
|
|
d_ptr->m_refreshingSchemeList = true;
|
2009-07-16 17:16:55 +02:00
|
|
|
d_ptr->m_schemeListModel->setColorSchemes(colorSchemes);
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_ui->schemeComboBox->setCurrentIndex(selected);
|
2009-07-17 17:24:32 +02:00
|
|
|
d_ptr->m_refreshingSchemeList = false;
|
2009-07-07 16:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FontSettingsPage::delayedChange()
|
|
|
|
|
{
|
|
|
|
|
emit changed(d_ptr->m_value);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void FontSettingsPage::apply()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!d_ptr->m_ui) // page was never shown
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
if (d_ptr->m_value.colorScheme() != d_ptr->m_ui->schemeEdit->colorScheme()) {
|
2009-07-17 17:24:32 +02:00
|
|
|
// Update the scheme and save it under the name it already has
|
2010-12-02 18:28:16 +01:00
|
|
|
d_ptr->m_value.setColorScheme(d_ptr->m_ui->schemeEdit->colorScheme());
|
2009-07-17 17:24:32 +02:00
|
|
|
const ColorScheme &scheme = d_ptr->m_value.colorScheme();
|
2012-01-24 15:36:40 +01:00
|
|
|
scheme.save(d_ptr->m_value.colorSchemeFileName(), Core::ICore::mainWindow());
|
2009-07-17 17:24:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-13 15:58:31 +01:00
|
|
|
bool ok;
|
|
|
|
|
int fontSize = d_ptr->m_ui->sizeComboBox->currentText().toInt(&ok);
|
|
|
|
|
if (ok && d_ptr->m_value.fontSize() != fontSize) {
|
|
|
|
|
d_ptr->m_value.setFontSize(fontSize);
|
|
|
|
|
d_ptr->m_ui->schemeEdit->setBaseFont(d_ptr->m_value.font());
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
int index = d_ptr->m_ui->schemeComboBox->currentIndex();
|
2009-07-16 17:16:55 +02:00
|
|
|
if (index != -1) {
|
|
|
|
|
const ColorSchemeEntry &entry = d_ptr->m_schemeListModel->colorSchemeAt(index);
|
2009-07-13 14:08:14 +02:00
|
|
|
if (entry.fileName != d_ptr->m_value.colorSchemeFileName())
|
|
|
|
|
d_ptr->m_value.loadColorScheme(entry.fileName, d_ptr->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
|
|
|
|
2009-06-18 16:12:24 +02:00
|
|
|
void FontSettingsPage::saveSettings()
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
if (d_ptr->m_value != d_ptr->m_lastValue) {
|
2009-09-23 18:06:59 +02:00
|
|
|
d_ptr->m_lastValue = d_ptr->m_value;
|
2012-08-09 12:58:51 +03:00
|
|
|
d_ptr->m_value.toSettings(d_ptr->m_settingsGroup, Core::ICore::settings());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-12-13 01:18:33 +02:00
|
|
|
QTimer::singleShot(0, this, &FontSettingsPage::delayedChange);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void FontSettingsPage::finish()
|
|
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
delete d_ptr->m_widget;
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!d_ptr->m_ui) // page was never shown
|
|
|
|
|
return;
|
2009-01-13 15:41:33 +01:00
|
|
|
// If changes were applied, these are equal. Otherwise restores last value.
|
|
|
|
|
d_ptr->m_value = d_ptr->m_lastValue;
|
2010-12-02 18:28:16 +01:00
|
|
|
delete d_ptr->m_ui;
|
2018-09-20 01:16:01 +03:00
|
|
|
d_ptr->m_ui = nullptr;
|
2009-01-13 15:41:33 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
const FontSettings &FontSettingsPage::fontSettings() const
|
|
|
|
|
{
|
|
|
|
|
return d_ptr->m_value;
|
|
|
|
|
}
|