| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2014-01-07 13:27:11 +01:00
										 |  |  | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Contact: http://www.qt-project.org/legal
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | ** a written agreement between you and Digia.  For licensing terms and | 
					
						
							|  |  |  | ** conditions see http://qt.digia.com/licensing.  For further information
 | 
					
						
							|  |  |  | ** use the contact form at http://qt.digia.com/contact-us.
 | 
					
						
							| 
									
										
										
										
											2008-12-02 14:17:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2009-02-25 09:15:00 +01:00
										 |  |  | ** GNU Lesser General Public License Usage | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02: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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** In addition, as a special exception, Digia gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in the Digia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											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 "fontsettings.h"
 | 
					
						
							|  |  |  | #include "fontsettingspage.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-14 11:17:37 +01:00
										 |  |  | #include <utils/hostosinfo.h>
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | #include <coreplugin/icore.h>
 | 
					
						
							| 
									
										
										
										
											2008-12-09 15:25:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-17 08:01:25 +02:00
										 |  |  | #include <QCoreApplication>
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2012-02-15 10:42:41 +01:00
										 |  |  | #include <QFile>
 | 
					
						
							|  |  |  | #include <QFileInfo>
 | 
					
						
							|  |  |  | #include <QFont>
 | 
					
						
							| 
									
										
										
										
											2012-04-17 08:01:25 +02:00
										 |  |  | #include <QSettings>
 | 
					
						
							|  |  |  | #include <QTextCharFormat>
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-10 15:19:38 +02:00
										 |  |  | static const char fontFamilyKey[] = "FontFamily"; | 
					
						
							|  |  |  | static const char fontSizeKey[] = "FontSize"; | 
					
						
							|  |  |  | static const char fontZoomKey[] = "FontZoom"; | 
					
						
							|  |  |  | static const char antialiasKey[] = "FontAntialias"; | 
					
						
							|  |  |  | static const char schemeFileNameKey[] = "ColorScheme"; | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  | static const bool DEFAULT_ANTIALIAS = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } // anonymous namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace TextEditor { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // -- FontSettings
 | 
					
						
							| 
									
										
										
										
											2009-06-17 19:12:19 +02:00
										 |  |  | FontSettings::FontSettings() : | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     m_family(defaultFixedFontFamily()), | 
					
						
							| 
									
										
										
										
											2013-03-14 11:17:37 +01:00
										 |  |  |     m_fontSize(defaultFontSize()), | 
					
						
							| 
									
										
										
										
											2009-11-30 19:00:36 +01:00
										 |  |  |     m_fontZoom(100), | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  |     m_antialias(DEFAULT_ANTIALIAS) | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontSettings::clear() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_family = defaultFixedFontFamily(); | 
					
						
							| 
									
										
										
										
											2013-03-14 11:17:37 +01:00
										 |  |  |     m_fontSize = defaultFontSize(); | 
					
						
							| 
									
										
										
										
											2009-11-30 19:00:36 +01:00
										 |  |  |     m_fontZoom = 100; | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  |     m_antialias = DEFAULT_ANTIALIAS; | 
					
						
							| 
									
										
										
										
											2009-06-18 12:28:40 +02:00
										 |  |  |     m_scheme.clear(); | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     m_formatCache.clear(); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontSettings::toSettings(const QString &category, | 
					
						
							|  |  |  |                               QSettings *s) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     s->beginGroup(category); | 
					
						
							|  |  |  |     if (m_family != defaultFixedFontFamily() || s->contains(QLatin1String(fontFamilyKey))) | 
					
						
							|  |  |  |         s->setValue(QLatin1String(fontFamilyKey), m_family); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-14 11:17:37 +01:00
										 |  |  |     if (m_fontSize != defaultFontSize() || s->contains(QLatin1String(fontSizeKey))) | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         s->setValue(QLatin1String(fontSizeKey), m_fontSize); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-30 19:00:36 +01:00
										 |  |  |     if (m_fontZoom!= 100 || s->contains(QLatin1String(fontZoomKey))) | 
					
						
							|  |  |  |         s->setValue(QLatin1String(fontZoomKey), m_fontZoom); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  |     if (m_antialias != DEFAULT_ANTIALIAS || s->contains(QLatin1String(antialiasKey))) | 
					
						
							|  |  |  |         s->setValue(QLatin1String(antialiasKey), m_antialias); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  |     if (m_schemeFileName != defaultSchemeFileName() || s->contains(QLatin1String(schemeFileNameKey))) | 
					
						
							|  |  |  |         s->setValue(QLatin1String(schemeFileNameKey), m_schemeFileName); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     s->endGroup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FontSettings::fromSettings(const QString &category, | 
					
						
							|  |  |  |                                 const FormatDescriptions &descriptions, | 
					
						
							|  |  |  |                                 const QSettings *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!s->childGroups().contains(category)) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString group = category; | 
					
						
							|  |  |  |     group += QLatin1Char('/'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_family = s->value(group + QLatin1String(fontFamilyKey), defaultFixedFontFamily()).toString(); | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  |     m_fontSize = s->value(group + QLatin1String(fontSizeKey), m_fontSize).toInt(); | 
					
						
							| 
									
										
										
										
											2009-11-30 19:00:36 +01:00
										 |  |  |     m_fontZoom= s->value(group + QLatin1String(fontZoomKey), m_fontZoom).toInt(); | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  |     m_antialias = s->value(group + QLatin1String(antialiasKey), DEFAULT_ANTIALIAS).toBool(); | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (s->contains(group + QLatin1String(schemeFileNameKey))) { | 
					
						
							|  |  |  |         // Load the selected color scheme
 | 
					
						
							| 
									
										
										
										
											2010-01-13 14:45:32 +01:00
										 |  |  |         QString scheme = s->value(group + QLatin1String(schemeFileNameKey)).toString(); | 
					
						
							|  |  |  |         if (scheme.isEmpty() || !QFile::exists(scheme)) | 
					
						
							|  |  |  |             scheme = defaultSchemeFileName(QFileInfo(scheme).fileName()); | 
					
						
							|  |  |  |         loadColorScheme(scheme, descriptions); | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         // Load color scheme from ini file
 | 
					
						
							|  |  |  |         foreach (const FormatDescription &desc, descriptions) { | 
					
						
							| 
									
										
										
										
											2012-04-26 14:17:42 +02:00
										 |  |  |             const TextStyle id = desc.id(); | 
					
						
							| 
									
										
										
										
											2012-11-21 21:47:17 +02:00
										 |  |  |             const QString fmt = s->value(group + QLatin1String(Constants::nameForStyle(id)), QString()).toString(); | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  |             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); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-01-07 18:17:24 +01:00
										 |  |  |             m_scheme.setFormatFor(id, format); | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 18:17:24 +01:00
										 |  |  |         m_scheme.setDisplayName(QCoreApplication::translate("TextEditor::Internal::FontSettings", "Customized")); | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FontSettings::equals(const FontSettings &f) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_family == f.m_family | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  |             && m_schemeFileName == f.m_schemeFileName | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |             && m_fontSize == f.m_fontSize | 
					
						
							| 
									
										
										
										
											2009-11-30 19:00:36 +01:00
										 |  |  |             && m_fontZoom == f.m_fontZoom | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  |             && m_antialias == f.m_antialias | 
					
						
							| 
									
										
										
										
											2009-06-18 12:28:40 +02:00
										 |  |  |             && m_scheme == f.m_scheme; | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the QTextCharFormat of the given format category. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-04-26 14:17:42 +02:00
										 |  |  | QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     if (m_formatCache.contains(category)) | 
					
						
							|  |  |  |         return m_formatCache.value(category); | 
					
						
							| 
									
										
										
										
											2009-06-18 12:28:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     const Format &f = m_scheme.formatFor(category); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     QTextCharFormat tf; | 
					
						
							| 
									
										
										
										
											2009-06-18 12:28:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-26 14:17:42 +02:00
										 |  |  |     if (category == C_TEXT) { | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         tf.setFontFamily(m_family); | 
					
						
							| 
									
										
										
										
											2010-10-15 17:19:36 +02:00
										 |  |  |         tf.setFontPointSize(m_fontSize * m_fontZoom / 100.); | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  |         tf.setFontStyleStrategy(m_antialias ? QFont::PreferAntialias : QFont::NoAntialias); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-21 14:29:25 +01:00
										 |  |  |     if (category == C_OCCURRENCES_UNUSED) { | 
					
						
							|  |  |  |         tf.setUnderlineStyle(QTextCharFormat::WaveUnderline); | 
					
						
							|  |  |  |         tf.setUnderlineColor(f.foreground()); | 
					
						
							|  |  |  |         tf.setToolTip(QCoreApplication::translate("FontSettings_C_OCCURRENCES_UNUSED", | 
					
						
							|  |  |  |                                                   "Unused variable")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (f.foreground().isValid() | 
					
						
							|  |  |  |             && category != C_OCCURRENCES | 
					
						
							|  |  |  |             && category != C_OCCURRENCES_RENAME | 
					
						
							|  |  |  |             && category != C_OCCURRENCES_UNUSED | 
					
						
							|  |  |  |             && category != C_SEARCH_RESULT) | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         tf.setForeground(f.foreground()); | 
					
						
							| 
									
										
										
										
											2012-04-26 14:17:42 +02:00
										 |  |  |     if (f.background().isValid() && (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background())) | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         tf.setBackground(f.background()); | 
					
						
							|  |  |  |     tf.setFontWeight(f.bold() ? QFont::Bold : QFont::Normal); | 
					
						
							|  |  |  |     tf.setFontItalic(f.italic()); | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_formatCache.insert(category, tf); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     return tf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the list of QTextCharFormats that corresponds to the list of | 
					
						
							|  |  |  |  * requested format categories. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-04-26 14:17:42 +02:00
										 |  |  | QVector<QTextCharFormat> FontSettings::toTextCharFormats(const QVector<TextStyle> &categories) const | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QVector<QTextCharFormat> rc; | 
					
						
							|  |  |  |     const int size = categories.size(); | 
					
						
							|  |  |  |     rc.reserve(size); | 
					
						
							|  |  |  |     for (int i = 0; i < size; i++) | 
					
						
							| 
									
										
										
										
											2009-07-14 08:50:27 +02:00
										 |  |  |          rc.append(toTextCharFormat(categories.at(i))); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |     return rc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the configured font family. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | QString FontSettings::family() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_family; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontSettings::setFamily(const QString &family) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_family = family; | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     m_formatCache.clear(); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the configured font size. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | int FontSettings::fontSize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_fontSize; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontSettings::setFontSize(int size) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_fontSize = size; | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     m_formatCache.clear(); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-30 19:00:36 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the configured font zoom factor in percent. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | int FontSettings::fontZoom() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_fontZoom; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontSettings::setFontZoom(int zoom) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_fontZoom = zoom; | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     m_formatCache.clear(); | 
					
						
							| 
									
										
										
										
											2009-11-30 19:00:36 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-20 14:03:07 +01:00
										 |  |  | QFont FontSettings::font() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QFont(family(), fontSize()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the configured antialiasing behavior. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  | bool FontSettings::antialias() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_antialias; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontSettings::setAntialias(bool antialias) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_antialias = antialias; | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     m_formatCache.clear(); | 
					
						
							| 
									
										
										
										
											2009-05-27 15:33:37 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the format for the given font category. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-04-26 14:17:42 +02:00
										 |  |  | Format &FontSettings::formatFor(TextStyle category) | 
					
						
							| 
									
										
										
										
											2012-10-18 08:02:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_scheme.formatFor(category); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Format FontSettings::formatFor(TextStyle category) const | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-18 12:28:40 +02:00
										 |  |  |     return m_scheme.formatFor(category); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the file name of the currently selected color scheme. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | QString FontSettings::colorSchemeFileName() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_schemeFileName; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-13 14:08:14 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Sets the file name of the color scheme. Does not load the scheme from the | 
					
						
							|  |  |  |  * given file. If you want to load a scheme, use loadColorScheme() instead. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void FontSettings::setColorSchemeFileName(const QString &fileName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_schemeFileName = fileName; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FontSettings::loadColorScheme(const QString &fileName, | 
					
						
							| 
									
										
										
										
											2009-07-07 18:35:42 +02:00
										 |  |  |                                    const FormatDescriptions &descriptions) | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     m_formatCache.clear(); | 
					
						
							| 
									
										
										
										
											2009-07-13 14:08:14 +02:00
										 |  |  |     bool loaded = true; | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  |     m_schemeFileName = fileName; | 
					
						
							| 
									
										
										
										
											2009-07-13 14:08:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!m_scheme.load(m_schemeFileName)) { | 
					
						
							|  |  |  |         loaded = false; | 
					
						
							| 
									
										
										
										
											2009-07-17 17:24:32 +02:00
										 |  |  |         m_schemeFileName.clear(); | 
					
						
							| 
									
										
										
										
											2009-07-13 14:08:14 +02:00
										 |  |  |         qWarning() << "Failed to load color scheme:" << fileName; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-07 18:35:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Apply default formats to undefined categories
 | 
					
						
							|  |  |  |     foreach (const FormatDescription &desc, descriptions) { | 
					
						
							| 
									
										
										
										
											2012-04-26 14:17:42 +02:00
										 |  |  |         const TextStyle id = desc.id(); | 
					
						
							| 
									
										
										
										
											2010-01-07 18:17:24 +01:00
										 |  |  |         if (!m_scheme.contains(id)) { | 
					
						
							| 
									
										
										
										
											2009-07-07 18:35:42 +02:00
										 |  |  |             Format format; | 
					
						
							|  |  |  |             format.setForeground(desc.foreground()); | 
					
						
							|  |  |  |             format.setBackground(desc.background()); | 
					
						
							|  |  |  |             format.setBold(desc.format().bold()); | 
					
						
							|  |  |  |             format.setItalic(desc.format().italic()); | 
					
						
							| 
									
										
										
										
											2010-01-07 18:17:24 +01:00
										 |  |  |             m_scheme.setFormatFor(id, format); | 
					
						
							| 
									
										
										
										
											2009-07-07 18:35:42 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-13 14:08:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return loaded; | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  | bool FontSettings::saveColorScheme(const QString &fileName) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-01-24 15:36:40 +01:00
										 |  |  |     const bool saved = m_scheme.save(fileName, Core::ICore::mainWindow()); | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  |     if (saved) | 
					
						
							|  |  |  |         m_schemeFileName = fileName; | 
					
						
							|  |  |  |     return saved; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the currently active color scheme. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-07-15 12:27:02 +02:00
										 |  |  | const ColorScheme &FontSettings::colorScheme() const | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_scheme; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontSettings::setColorScheme(const ColorScheme &scheme) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_scheme = scheme; | 
					
						
							| 
									
										
										
										
											2014-01-20 17:03:45 +01:00
										 |  |  |     m_formatCache.clear(); | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-14 11:17:37 +01:00
										 |  |  | static QString defaultFontFamily() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (Utils::HostOsInfo::isMacHost()) | 
					
						
							|  |  |  |         return QLatin1String("Monaco"); | 
					
						
							|  |  |  |     if (Utils::HostOsInfo::isAnyUnixHost()) | 
					
						
							|  |  |  |         return QLatin1String("Monospace"); | 
					
						
							|  |  |  |     return QLatin1String("Courier"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | QString FontSettings::defaultFixedFontFamily() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     static QString rc; | 
					
						
							|  |  |  |     if (rc.isEmpty()) { | 
					
						
							| 
									
										
										
										
											2013-03-14 11:17:37 +01:00
										 |  |  |         QFont f = QFont(defaultFontFamily()); | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  |         f.setStyleHint(QFont::TypeWriter); | 
					
						
							|  |  |  |         rc = f.family(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return rc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int FontSettings::defaultFontSize() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-14 11:17:37 +01:00
										 |  |  |     if (Utils::HostOsInfo::isMacHost()) | 
					
						
							|  |  |  |         return 12; | 
					
						
							|  |  |  |     if (Utils::HostOsInfo::isAnyUnixHost()) | 
					
						
							|  |  |  |         return 9; | 
					
						
							|  |  |  |     return 10; | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-13 14:45:32 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Returns the default scheme file name, or the path to a shipped scheme when | 
					
						
							|  |  |  |  * one exists with the given \a fileName. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | QString FontSettings::defaultSchemeFileName(const QString &fileName) | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-01-24 15:36:40 +01:00
										 |  |  |     QString defaultScheme = Core::ICore::resourcePath(); | 
					
						
							| 
									
										
										
										
											2010-01-13 14:45:32 +01:00
										 |  |  |     defaultScheme += QLatin1String("/styles/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!fileName.isEmpty() && QFile::exists(defaultScheme + fileName)) | 
					
						
							|  |  |  |         defaultScheme += fileName; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         defaultScheme += QLatin1String("default.xml"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return defaultScheme; | 
					
						
							| 
									
										
										
										
											2009-07-07 16:07:40 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-02 12:01:29 +01:00
										 |  |  | } // namespace TextEditor
 |