2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-06-17 00:01:27 +10:00
|
|
|
** contact the sales department at http://www.qtsoftware.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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
|
|
|
|
|
|
|
|
#include "editcolorschemedialog.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fontsettings.h"
|
|
|
|
|
#include "texteditorconstants.h"
|
|
|
|
|
#include "ui_fontsettingspage.h"
|
|
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <utils/settingsutils.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
#include <QtGui/QCheckBox>
|
|
|
|
|
#include <QtGui/QComboBox>
|
|
|
|
|
#include <QtGui/QFontDatabase>
|
2009-01-20 15:31:33 +01:00
|
|
|
#include <QtGui/QListWidget>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QPalette>
|
2009-01-20 15:31:33 +01:00
|
|
|
#include <QtGui/QPalette>
|
|
|
|
|
#include <QtGui/QTextCharFormat>
|
|
|
|
|
#include <QtGui/QTextEdit>
|
|
|
|
|
#include <QtGui/QToolButton>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class FontSettingsPagePrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FontSettingsPagePrivate(const TextEditor::FormatDescriptions &fd,
|
|
|
|
|
const QString &name,
|
|
|
|
|
const QString &category,
|
2009-01-20 15:31:33 +01:00
|
|
|
const QString &trCategory);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
public:
|
2008-12-02 12:01:29 +01:00
|
|
|
const QString m_name;
|
|
|
|
|
const QString m_settingsGroup;
|
|
|
|
|
const QString m_category;
|
|
|
|
|
const QString m_trCategory;
|
|
|
|
|
|
|
|
|
|
TextEditor::FormatDescriptions m_descriptions;
|
|
|
|
|
FontSettings m_value;
|
|
|
|
|
FontSettings m_lastValue;
|
|
|
|
|
Ui::FontSettingsPage ui;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescriptions &fd,
|
|
|
|
|
const QString &name,
|
|
|
|
|
const QString &category,
|
2009-01-20 15:31:33 +01:00
|
|
|
const QString &trCategory) :
|
2008-12-02 12:01:29 +01:00
|
|
|
m_name(name),
|
|
|
|
|
m_settingsGroup(Core::Utils::settingsKey(category)),
|
|
|
|
|
m_category(category),
|
|
|
|
|
m_trCategory(trCategory),
|
2009-06-18 17:35:46 +02:00
|
|
|
m_descriptions(fd)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
bool settingsFound = false;
|
2009-01-20 15:31:33 +01:00
|
|
|
if (const QSettings *settings = Core::ICore::instance()->settings())
|
|
|
|
|
settingsFound = m_value.fromSettings(m_settingsGroup, m_descriptions, settings);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!settingsFound) { // Apply defaults
|
|
|
|
|
foreach (const FormatDescription &f, m_descriptions) {
|
|
|
|
|
const QString name = f.name();
|
2009-06-12 15:28:51 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_lastValue.formatFor(name).setForeground(f.foreground());
|
|
|
|
|
m_lastValue.formatFor(name).setBackground(f.background());
|
2009-06-12 15:28:51 +02:00
|
|
|
m_lastValue.formatFor(name).setBold(f.format().bold());
|
|
|
|
|
m_lastValue.formatFor(name).setItalic(f.format().italic());
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_value.formatFor(name).setForeground(f.foreground());
|
|
|
|
|
m_value.formatFor(name).setBackground(f.background());
|
2009-06-12 15:28:51 +02:00
|
|
|
m_value.formatFor(name).setBold(f.format().bold());
|
|
|
|
|
m_value.formatFor(name).setItalic(f.format().italic());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_lastValue = m_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace TextEditor
|
|
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace TextEditor::Internal;
|
|
|
|
|
|
|
|
|
|
// ------- FormatDescription
|
|
|
|
|
FormatDescription::FormatDescription(const QString &name, const QString &trName, const QColor &color) :
|
|
|
|
|
m_name(name),
|
|
|
|
|
m_trName(trName)
|
|
|
|
|
{
|
|
|
|
|
m_format.setForeground(color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor FormatDescription::foreground() const
|
|
|
|
|
{
|
2009-06-15 15:35:06 +02:00
|
|
|
if (m_name == QLatin1String(Constants::C_LINE_NUMBER)) {
|
|
|
|
|
const QColor bg = QApplication::palette().background().color();
|
|
|
|
|
if (bg.value() < 128) {
|
|
|
|
|
return QApplication::palette().foreground().color();
|
|
|
|
|
} else {
|
|
|
|
|
return QApplication::palette().dark().color();
|
|
|
|
|
}
|
|
|
|
|
} else if (m_name == QLatin1String(Constants::C_CURRENT_LINE_NUMBER)) {
|
|
|
|
|
const QColor bg = QApplication::palette().background().color();
|
|
|
|
|
if (bg.value() < 128) {
|
|
|
|
|
return QApplication::palette().foreground().color();
|
|
|
|
|
} else {
|
|
|
|
|
return m_format.foreground();
|
|
|
|
|
}
|
|
|
|
|
} else if (m_name == QLatin1String(Constants::C_PARENTHESES)) {
|
2008-12-02 12:01:29 +01:00
|
|
|
return QColor(Qt::red);
|
2009-06-15 15:35:06 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
return m_format.foreground();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor FormatDescription::background() const
|
|
|
|
|
{
|
|
|
|
|
if (m_name == QLatin1String(Constants::C_TEXT))
|
|
|
|
|
return Qt::white;
|
|
|
|
|
else if (m_name == QLatin1String(Constants::C_LINE_NUMBER))
|
|
|
|
|
return QApplication::palette().background().color();
|
|
|
|
|
else if (m_name == QLatin1String(Constants::C_SEARCH_RESULT))
|
|
|
|
|
return QColor(0xffef0b);
|
|
|
|
|
else if (m_name == QLatin1String(Constants::C_PARENTHESES))
|
|
|
|
|
return QColor(0xb4, 0xee, 0xb4);
|
|
|
|
|
else if (m_name == QLatin1String(Constants::C_CURRENT_LINE)
|
|
|
|
|
|| m_name == QLatin1String(Constants::C_SEARCH_SCOPE)) {
|
|
|
|
|
const QPalette palette = QApplication::palette();
|
|
|
|
|
const QColor &fg = palette.color(QPalette::Highlight);
|
|
|
|
|
const QColor &bg = palette.color(QPalette::Base);
|
|
|
|
|
|
|
|
|
|
qreal smallRatio;
|
|
|
|
|
qreal largeRatio;
|
|
|
|
|
if (m_name == QLatin1String(Constants::C_CURRENT_LINE)) {
|
|
|
|
|
smallRatio = .15;
|
|
|
|
|
largeRatio = .3;
|
|
|
|
|
} 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;
|
|
|
|
|
} else if (m_name == QLatin1String(Constants::C_SELECTION)) {
|
|
|
|
|
const QPalette palette = QApplication::palette();
|
|
|
|
|
return palette.color(QPalette::Highlight);
|
|
|
|
|
}
|
|
|
|
|
return QColor(); // invalid color
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ------------ FontSettingsPage
|
|
|
|
|
FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd,
|
|
|
|
|
const QString &category,
|
|
|
|
|
const QString &trCategory,
|
|
|
|
|
QObject *parent) :
|
|
|
|
|
Core::IOptionsPage(parent),
|
2009-01-20 15:31:33 +01:00
|
|
|
d_ptr(new FontSettingsPagePrivate(fd, tr("Font & Colors"), category, trCategory))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FontSettingsPage::~FontSettingsPage()
|
|
|
|
|
{
|
|
|
|
|
delete d_ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
QString FontSettingsPage::id() const
|
|
|
|
|
{
|
|
|
|
|
return d_ptr->m_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FontSettingsPage::trName() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return d_ptr->m_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FontSettingsPage::category() const
|
|
|
|
|
{
|
|
|
|
|
return d_ptr->m_category;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString FontSettingsPage::trCategory() const
|
|
|
|
|
{
|
|
|
|
|
return d_ptr->m_trCategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *FontSettingsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
QWidget *w = new QWidget(parent);
|
|
|
|
|
d_ptr->ui.setupUi(w);
|
|
|
|
|
|
2009-06-18 17:35:46 +02:00
|
|
|
d_ptr->ui.schemeListWidget->addItem(tr("Default"));
|
|
|
|
|
d_ptr->ui.schemeListWidget->setCurrentIndex(d_ptr->ui.schemeListWidget->model()->index(0, 0));
|
|
|
|
|
d_ptr->ui.editButton->setEnabled(true);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QFontDatabase db;
|
|
|
|
|
const QStringList families = db.families();
|
|
|
|
|
d_ptr->ui.familyComboBox->addItems(families);
|
|
|
|
|
const int idx = families.indexOf(d_ptr->m_value.family());
|
|
|
|
|
d_ptr->ui.familyComboBox->setCurrentIndex(idx);
|
|
|
|
|
|
2009-05-27 15:33:37 +02:00
|
|
|
d_ptr->ui.antialias->setChecked(d_ptr->m_value.antialias());
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(d_ptr->ui.familyComboBox, SIGNAL(activated(int)), this, SLOT(updatePointSizes()));
|
2009-06-18 17:35:46 +02:00
|
|
|
connect(d_ptr->ui.editButton, SIGNAL(clicked()), this, SLOT(editColorScheme()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
updatePointSizes();
|
|
|
|
|
d_ptr->m_lastValue = d_ptr->m_value;
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FontSettingsPage::updatePointSizes()
|
|
|
|
|
{
|
|
|
|
|
const int oldSize = d_ptr->m_value.fontSize();
|
|
|
|
|
if (d_ptr->ui.sizeComboBox->count()) {
|
|
|
|
|
const QString curSize = d_ptr->ui.sizeComboBox->currentText();
|
|
|
|
|
bool ok = true;
|
|
|
|
|
int oldSize = curSize.toInt(&ok);
|
|
|
|
|
if (!ok)
|
|
|
|
|
oldSize = d_ptr->m_value.fontSize();
|
|
|
|
|
d_ptr->ui.sizeComboBox->clear();
|
|
|
|
|
}
|
|
|
|
|
QFontDatabase db;
|
|
|
|
|
const QList<int> sizeLst = db.pointSizes(d_ptr->ui.familyComboBox->currentText());
|
|
|
|
|
int idx = 0;
|
|
|
|
|
int i = 0;
|
2009-06-18 17:35:46 +02:00
|
|
|
for (; i < sizeLst.count(); ++i) {
|
2008-12-02 12:01:29 +01:00
|
|
|
if (idx == 0 && sizeLst.at(i) >= oldSize)
|
|
|
|
|
idx = i;
|
|
|
|
|
d_ptr->ui.sizeComboBox->addItem(QString::number(sizeLst.at(i)));
|
|
|
|
|
}
|
|
|
|
|
if (d_ptr->ui.sizeComboBox->count())
|
|
|
|
|
d_ptr->ui.sizeComboBox->setCurrentIndex(idx);
|
2009-06-18 17:35:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FontSettingsPage::editColorScheme()
|
|
|
|
|
{
|
|
|
|
|
d_ptr->m_value.setFamily(d_ptr->ui.familyComboBox->currentText());
|
|
|
|
|
d_ptr->m_value.setAntialias(d_ptr->ui.antialias->isChecked());
|
|
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
const int size = d_ptr->ui.sizeComboBox->currentText().toInt(&ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
d_ptr->m_value.setFontSize(size);
|
|
|
|
|
|
|
|
|
|
EditColorSchemeDialog dialog(d_ptr->m_descriptions,
|
|
|
|
|
d_ptr->m_value,
|
|
|
|
|
d_ptr->m_value.colorScheme(),
|
|
|
|
|
d_ptr->ui.editButton->window());
|
|
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
|
d_ptr->m_value.setColorScheme(dialog.colorScheme());
|
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
|
|
|
{
|
|
|
|
|
d_ptr->m_value.setFamily(d_ptr->ui.familyComboBox->currentText());
|
2009-05-27 15:33:37 +02:00
|
|
|
d_ptr->m_value.setAntialias(d_ptr->ui.antialias->isChecked());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
const int size = d_ptr->ui.sizeComboBox->currentText().toInt(&ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
d_ptr->m_value.setFontSize(size);
|
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-06-18 16:12:24 +02:00
|
|
|
d_ptr->m_lastValue = d_ptr->m_value;
|
|
|
|
|
if (QSettings *settings = Core::ICore::instance()->settings())
|
|
|
|
|
d_ptr->m_value.toSettings(d_ptr->m_settingsGroup, d_ptr->m_descriptions, settings);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-06-18 16:12:24 +02:00
|
|
|
QTimer::singleShot(0, this, SLOT(delayedChange()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void FontSettingsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
// If changes were applied, these are equal. Otherwise restores last value.
|
|
|
|
|
d_ptr->m_value = d_ptr->m_lastValue;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
const FontSettings &FontSettingsPage::fontSettings() const
|
|
|
|
|
{
|
|
|
|
|
return d_ptr->m_value;
|
|
|
|
|
}
|