File indexing completed on 2024-05-12 16:39:54
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org> 0003 0004 Contains code from kfontsettingsdata.cpp: 0005 Copyright (C) 2000, 2006 David Faure <faure@kde.org> 0006 Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org> 0007 Copyright 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0008 0009 This program is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU Library General Public 0011 License as published by the Free Software Foundation; either 0012 version 2 of the License, or (at your option) any later version. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Library General Public License for more details. 0018 0019 You should have received a copy of the GNU Library General Public License 0020 along with this program; see the file COPYING. If not, write to 0021 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0022 * Boston, MA 02110-1301, USA. 0023 */ 0024 0025 #include "FontSettings_p.h" 0026 #include <KConfigGroup> 0027 0028 FontSettingsData::FontSettingsData() 0029 { 0030 for (int i = 0; i < FontTypesCount; ++i) { 0031 m_fonts[i] = 0; 0032 } 0033 } 0034 0035 FontSettingsData::~FontSettingsData() 0036 { 0037 for (int i = 0; i < FontTypesCount; ++i) { 0038 delete m_fonts[i]; 0039 } 0040 } 0041 0042 static const char GeneralId[] = "General"; 0043 static const char DefaultFont[] = "Noto Sans"; 0044 0045 static const FontData DefaultFontData[FontSettingsData::FontTypesCount] = { 0046 { GeneralId, "font", DefaultFont, 10, -1, QFont::SansSerif }, 0047 { GeneralId, "fixed", "Oxygen Mono", 9, -1, QFont::Monospace }, 0048 { GeneralId, "toolBarFont", DefaultFont, 9, -1, QFont::SansSerif }, 0049 { GeneralId, "menuFont", DefaultFont, 10, -1, QFont::SansSerif }, 0050 { "WM", "activeFont", DefaultFont, 10, -1, QFont::SansSerif }, 0051 { GeneralId, "taskbarFont", DefaultFont, 10, -1, QFont::SansSerif }, 0052 { GeneralId, "smallestReadableFont", DefaultFont, 8, -1, QFont::SansSerif } 0053 }; 0054 0055 QFont FontSettingsData::font(FontTypes fontType) 0056 { 0057 QFont *cachedFont = m_fonts[fontType]; 0058 if (!cachedFont) { 0059 const FontData &fontData = DefaultFontData[fontType]; 0060 cachedFont = new QFont(fontData.FontName, fontData.Size, fontData.Weight); 0061 cachedFont->setStyleHint(fontData.StyleHint); 0062 if (!m_kdeGlobals) { 0063 m_kdeGlobals = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals); 0064 } 0065 const KConfigGroup configGroup(m_kdeGlobals, fontData.ConfigGroupKey); 0066 QString fontInfo = configGroup.readEntry(fontData.ConfigKey, QString()); 0067 0068 //If we have serialized information for this font, restore it 0069 //NOTE: We are not using KConfig directly because we can't call QFont::QFont from here 0070 if (!fontInfo.isEmpty()) { 0071 cachedFont->fromString(fontInfo); 0072 } 0073 m_fonts[fontType] = cachedFont; 0074 } 0075 return *cachedFont; 0076 }