Commit 089401fb authored by con's avatar con
Browse files

Add option to turn antialiasing on/off for text editor fonts.


Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
Task-number: 234394
parent bdf6c3d0
......@@ -37,10 +37,13 @@
static const char *fontFamilyKey = "FontFamily";
static const char *fontSizeKey = "FontSize";
static const char *antialiasKey = "FontAntialias";
static const char *trueString = "true";
static const char *falseString = "false";
namespace {
static const bool DEFAULT_ANTIALIAS = true;
#ifdef Q_WS_MAC
enum { DEFAULT_FONT_SIZE = 12 };
static const char *DEFAULT_FONT_FAMILY = "Monaco";
......@@ -135,7 +138,8 @@ bool Format::equals(const Format &f) const
// -- FontSettings
FontSettings::FontSettings(const FormatDescriptions &fd) :
m_family(defaultFixedFontFamily()),
m_fontSize(DEFAULT_FONT_SIZE)
m_fontSize(DEFAULT_FONT_SIZE),
m_antialias(DEFAULT_ANTIALIAS)
{
Q_UNUSED(fd);
}
......@@ -144,6 +148,7 @@ void FontSettings::clear()
{
m_family = defaultFixedFontFamily();
m_fontSize = DEFAULT_FONT_SIZE;
m_antialias = DEFAULT_ANTIALIAS;
qFill(m_formats.begin(), m_formats.end(), Format());
}
......@@ -160,6 +165,9 @@ void FontSettings::toSettings(const QString &category,
if (m_fontSize != DEFAULT_FONT_SIZE || s->contains(QLatin1String(fontSizeKey)))
s->setValue(QLatin1String(fontSizeKey), m_fontSize);
if (m_antialias != DEFAULT_ANTIALIAS || s->contains(QLatin1String(antialiasKey)))
s->setValue(QLatin1String(antialiasKey), m_antialias);
const Format defaultFormat;
foreach (const FormatDescription &desc, descriptions) {
......@@ -184,7 +192,8 @@ bool FontSettings::fromSettings(const QString &category,
group += QLatin1Char('/');
m_family = s->value(group + QLatin1String(fontFamilyKey), defaultFixedFontFamily()).toString();
m_fontSize = s->value(group + QLatin1String(QLatin1String(fontSizeKey)), m_fontSize).toInt();
m_fontSize = s->value(group + QLatin1String(fontSizeKey), m_fontSize).toInt();
m_antialias = s->value(group + QLatin1String(antialiasKey), DEFAULT_ANTIALIAS).toBool();
foreach (const FormatDescription &desc, descriptions) {
const QString name = desc.name();
......@@ -203,6 +212,7 @@ bool FontSettings::equals(const FontSettings &f) const
{
return m_family == f.m_family
&& m_fontSize == f.m_fontSize
&& m_antialias == f.m_antialias
&& m_formats == f.m_formats;
}
......@@ -213,6 +223,7 @@ QTextCharFormat FontSettings::toTextCharFormat(const QString &category) const
if (category == QLatin1String("Text")) {
tf.setFontFamily(m_family);
tf.setFontPointSize(m_fontSize);
tf.setFontStyleStrategy(m_antialias ? QFont::PreferAntialias : QFont::NoAntialias);
}
if (f.foreground().isValid())
......@@ -254,6 +265,17 @@ void FontSettings::setFontSize(int size)
m_fontSize = size;
}
bool FontSettings::antialias() const
{
return m_antialias;
}
void FontSettings::setAntialias(bool antialias)
{
m_antialias = antialias;
}
Format &FontSettings::formatFor(const QString &category)
{
return m_formats[category];
......
......@@ -122,6 +122,12 @@ public:
int fontSize() const;
void setFontSize(int size);
/**
* Returns the configured antialiasing behavior.
*/
bool antialias() const;
void setAntialias(bool antialias);
/**
* Returns the format for the given font category.
*/
......@@ -135,6 +141,7 @@ public:
private:
QString m_family;
int m_fontSize;
bool m_antialias;
QMap<QString, Format> m_formats;
};
......
......@@ -240,8 +240,11 @@ QWidget *FontSettingsPage::createPage(QWidget *parent)
const int idx = families.indexOf(d_ptr->m_value.family());
d_ptr->ui.familyComboBox->setCurrentIndex(idx);
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.sizeComboBox, SIGNAL(activated(int)), this, SLOT(updatePreview()));
connect(d_ptr->ui.antialias, SIGNAL(toggled(bool)), this, SLOT(updatePreview()));
connect(d_ptr->ui.itemListWidget, SIGNAL(itemSelectionChanged()),
this, SLOT(itemChanged()));
connect(d_ptr->ui.foregroundToolButton, SIGNAL(clicked()),
......@@ -389,6 +392,7 @@ void FontSettingsPage::updatePreview()
if (currentFormat.background().isValid())
format.setBackground(QBrush(currentFormat.background()));
format.setFontFamily(d_ptr->ui.familyComboBox->currentText());
format.setFontStyleStrategy(d_ptr->ui.antialias->isChecked() ? QFont::PreferAntialias : QFont::NoAntialias);
bool ok;
int size = d_ptr->ui.sizeComboBox->currentText().toInt(&ok);
if (!ok) {
......@@ -436,6 +440,7 @@ void FontSettingsPage::delayedChange()
void FontSettingsPage::apply()
{
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);
......
......@@ -11,24 +11,12 @@
</rect>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Font</string>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
......@@ -91,6 +79,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="antialias">
<property name="text">
<string>Antialias</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
......@@ -119,12 +114,6 @@
<string>Color Scheme</string>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QListWidget" name="itemListWidget">
<property name="sizePolicy">
......@@ -137,12 +126,6 @@
</item>
<item>
<layout class="QGridLayout">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="2" column="0">
<widget class="QCheckBox" name="boldCheckBox">
<property name="text">
......
Markdown is supported
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