Commit 947b719e authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Made selecting the color scheme functional

Also, defaults formats are now applied to any format that hasn't been
defined in the color scheme file. This allows a color scheme to fall
back on the default selection color, for example.
parent 06568947
<?xml version="1.0" encoding="UTF-8"?>
<style-scheme version="1.0">
<style name="AddedLine" foreground="#00aa00"/>
<style name="Comment" foreground="#008000"/>
<style name="CurrentLine" background="#fef2da"/>
<style name="CurrentLineNumber" foreground="#808080" bold="true"/>
<style name="DiffFile" foreground="#000080"/>
<style name="DiffLocation" foreground="#0000ff"/>
<style name="DisabledCode" foreground="#a0a0a4"/>
<style name="Doxygen.Comment" foreground="#000080"/>
<style name="Doxygen.Tag" foreground="#0000ff"/>
<style name="Keyword" foreground="#808000"/>
<style name="Label" foreground="#800000"/>
<style name="LineNumber" foreground="#c7c4c1" background="#efebe7"/>
<style name="Link" foreground="#0000ff"/>
<style name="Number" foreground="#000080"/>
<style name="Operator" foreground="#000000"/>
<style name="Parentheses" foreground="#ff0000" background="#b4eeb4"/>
<style name="Preprocessor" foreground="#000080"/>
<style name="RemovedLine" foreground="#ff0000"/>
<style name="SearchResult" background="#ffef0b"/>
<style name="SearchScope" background="#fdedce"/>
<style name="Selection" background="#fad184"/>
<style name="String" foreground="#008000"/>
<style name="Text" foreground="#000000" background="#ffffff"/>
<style name="Type" foreground="#800080"/>
<style-scheme version="1.0" name="Default">
<!-- Empty scheme, relying entirely on built-in defaults. -->
</style-scheme>
<?xml version="1.0" encoding="UTF-8"?>
<style-scheme version="1.0" name="Grayscale">
<style name="AddedLine" foreground="#636363"/>
<style name="Comment" foreground="#808080"/>
<style name="CurrentLine" foreground="#000000" background="#f2f2f2"/>
<style name="DiffFile"/>
<style name="DiffLocation"/>
<style name="DisabledCode" foreground="#a0a0a4"/>
<style name="Doxygen.Comment" foreground="#808080"/>
<style name="Doxygen.Tag" foreground="#808080" italic="true"/>
<style name="Keyword" bold="true"/>
<style name="Label"/>
<style name="LineNumber" foreground="#c7c4c1" background="#efebe7"/>
<style name="Link" foreground="#0000ff"/>
<style name="Number" foreground="#3f3f3f"/>
<style name="Operator"/>
<style name="Parentheses" background="#e3e3e3" bold="true"/>
<style name="Preprocessor" foreground="#5b5b5b"/>
<style name="RemovedLine" foreground="#a0a0a4"/>
<style name="String" foreground="#636363"/>
<style name="Text" foreground="#000000" background="#ffffff"/>
<style name="Type"/>
<!--
Relying on default colors for:
CurrentLineNumber
LineNumber
SearchResult
SearchScope
Selection
-->
</style-scheme>
......@@ -92,18 +92,7 @@ void FontSettings::toSettings(const QString &category,
if (m_schemeFileName != defaultSchemeFileName() || s->contains(QLatin1String(schemeFileNameKey)))
s->setValue(QLatin1String(schemeFileNameKey), m_schemeFileName);
#if 0
const Format defaultFormat;
foreach (const FormatDescription &desc, descriptions) {
const QString name = desc.name();
if (m_scheme.contains(name)) {
const Format &f = m_scheme.formatFor(name);
if (f != defaultFormat || s->contains(name))
s->setValue(name, f.toString());
}
}
#endif
s->endGroup();
}
......@@ -122,25 +111,9 @@ bool FontSettings::fromSettings(const QString &category,
m_family = s->value(group + QLatin1String(fontFamilyKey), defaultFixedFontFamily()).toString();
m_fontSize = s->value(group + QLatin1String(fontSizeKey), m_fontSize).toInt();
m_antialias = s->value(group + QLatin1String(antialiasKey), DEFAULT_ANTIALIAS).toBool();
m_schemeFileName = s->value(group + QLatin1String(schemeFileNameKey), defaultSchemeFileName()).toString();
loadColorScheme(s->value(group + QLatin1String(schemeFileNameKey), defaultSchemeFileName()).toString(),
descriptions);
m_scheme.load(m_schemeFileName);
#if 0
foreach (const FormatDescription &desc, descriptions) {
const QString name = desc.name();
const QString fmt = s->value(group + name, QString()).toString();
Format format;
if (fmt.isEmpty()) {
format.setForeground(desc.foreground());
format.setBackground(desc.background());
format.setBold(desc.format().bold());
format.setItalic(desc.format().italic());
} else {
format.fromString(fmt);
}
m_scheme.setFormatFor(name, format);
}
#endif
return true;
}
......@@ -247,9 +220,24 @@ QString FontSettings::colorSchemeFileName() const
return m_schemeFileName;
}
void FontSettings::setColorSchemeFileName(const QString &fileName)
void FontSettings::loadColorScheme(const QString &fileName,
const FormatDescriptions &descriptions)
{
m_schemeFileName = fileName;
m_scheme.load(m_schemeFileName);
// Apply default formats to undefined categories
foreach (const FormatDescription &desc, descriptions) {
const QString name = desc.name();
if (!m_scheme.contains(name)) {
Format format;
format.setForeground(desc.foreground());
format.setBackground(desc.background());
format.setBold(desc.format().bold());
format.setItalic(desc.format().italic());
m_scheme.setFormatFor(name, format);
}
}
}
/**
......
......@@ -84,7 +84,7 @@ public:
Format &formatFor(const QString &category);
QString colorSchemeFileName() const;
void setColorSchemeFileName(const QString &fileName);
void loadColorScheme(const QString &fileName, const FormatDescriptions &descriptions);
ColorScheme colorScheme() const;
void setColorScheme(const ColorScheme &scheme);
......
......@@ -235,6 +235,8 @@ QWidget *FontSettingsPage::createPage(QWidget *parent)
d_ptr->ui.antialias->setChecked(d_ptr->m_value.antialias());
connect(d_ptr->ui.familyComboBox, SIGNAL(activated(int)), this, SLOT(updatePointSizes()));
connect(d_ptr->ui.schemeListWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(colorSchemeSelected(QListWidgetItem*)));
connect(d_ptr->ui.exportButton, SIGNAL(clicked()), this, SLOT(exportColorScheme()));
connect(d_ptr->ui.editButton, SIGNAL(clicked()), this, SLOT(editColorScheme()));
......@@ -268,6 +270,11 @@ void FontSettingsPage::updatePointSizes()
d_ptr->ui.sizeComboBox->setCurrentIndex(idx);
}
void FontSettingsPage::colorSchemeSelected(QListWidgetItem *item)
{
// TODO: Enable the appropriate actions
}
void FontSettingsPage::importColorScheme()
{
QString fn = QFileDialog::getOpenFileName(d_ptr->ui.importButton->window(),
......@@ -318,12 +325,22 @@ void FontSettingsPage::refreshColorSchemeList()
styleDir.setNameFilters(QStringList() << QLatin1String("*.xml"));
styleDir.setFilter(QDir::Files);
int selected = 0;
int count = 0;
foreach (const QString &file, styleDir.entryList()) {
// TODO: Read the name of the style
QListWidgetItem *item = new QListWidgetItem(file);
item->setData(Qt::UserRole, styleDir.absoluteFilePath(file));
const QString absFileName = styleDir.absoluteFilePath(file);
item->setData(Qt::UserRole, absFileName );
d_ptr->ui.schemeListWidget->addItem(item);
if (d_ptr->m_value.colorSchemeFileName() == absFileName)
selected = count;
++count;
}
const QModelIndex s = d_ptr->ui.schemeListWidget->model()->index(selected, 0);
d_ptr->ui.schemeListWidget->setCurrentIndex(s);
}
void FontSettingsPage::delayedChange()
......@@ -336,6 +353,12 @@ void FontSettingsPage::apply()
d_ptr->m_value.setFamily(d_ptr->ui.familyComboBox->currentText());
d_ptr->m_value.setAntialias(d_ptr->ui.antialias->isChecked());
if (QListWidgetItem *item = d_ptr->ui.schemeListWidget->currentItem()) {
QString file = item->data(Qt::UserRole).toString();
if (file != d_ptr->m_value.colorSchemeFileName())
d_ptr->m_value.loadColorScheme(file, d_ptr->m_descriptions);
}
bool ok = true;
const int size = d_ptr->ui.sizeComboBox->currentText().toInt(&ok);
if (ok)
......
......@@ -42,6 +42,7 @@
#include <QtCore/QVector>
QT_BEGIN_NAMESPACE
class QListWidgetItem;
class QWidget;
QT_END_NAMESPACE
......@@ -110,6 +111,7 @@ signals:
private slots:
void delayedChange();
void updatePointSizes();
void colorSchemeSelected(QListWidgetItem *item);
void importColorScheme();
void exportColorScheme();
void editColorScheme();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment