Changeset View
Changeset View
Standalone View
Standalone View
src/part/KgvGlobal.cpp
Show All 20 Lines | 19 | /* This file was part of the KDE project | |||
---|---|---|---|---|---|
21 | 21 | | |||
22 | This program is free software; you can redistribute it and/or | 22 | This program is free software; you can redistribute it and/or | ||
23 | modify it under the terms of the GNU Library General Public | 23 | modify it under the terms of the GNU Library General Public | ||
24 | License as published by the Free Software Foundation; either | 24 | License as published by the Free Software Foundation; either | ||
25 | version 2 of the License, or (at your option) any later version. | 25 | version 2 of the License, or (at your option) any later version. | ||
26 | */ | 26 | */ | ||
27 | 27 | | |||
28 | #include "kgraphviewerlib_debug.h" | 28 | #include "kgraphviewerlib_debug.h" | ||
29 | #include <KSharedConfig> | ||||
29 | #include <KgvGlobal.h> | 30 | #include <KgvGlobal.h> | ||
31 | #include <QApplication> | ||||
30 | #include <QDebug> | 32 | #include <QDebug> | ||
31 | #include <QDesktopWidget> | 33 | #include <QDesktopWidget> | ||
32 | #include <qfont.h> | | |||
33 | #include <qfontinfo.h> | | |||
34 | #include <QPaintDevice> | 34 | #include <QPaintDevice> | ||
35 | #include <QApplication> | | |||
36 | #include <KSharedConfig> | | |||
37 | #include <QStandardPaths> | 35 | #include <QStandardPaths> | ||
36 | #include <qfont.h> | ||||
37 | #include <qfontinfo.h> | ||||
38 | // #include <k3staticdeleter.h> | 38 | // #include <k3staticdeleter.h> | ||
39 | #include <QImage> | | |||
40 | #include <QIcon> | 39 | #include <QIcon> | ||
41 | 40 | #include <QImage> | |||
42 | 41 | | |||
43 | KgvGlobal* KgvGlobal::s_global = nullptr; | 42 | KgvGlobal *KgvGlobal::s_global = nullptr; | ||
44 | // static K3StaticDeleter<KgvGlobal> sdg; | 43 | // static K3StaticDeleter<KgvGlobal> sdg; | ||
45 | 44 | | |||
46 | KgvGlobal* KgvGlobal::self() | 45 | KgvGlobal *KgvGlobal::self() | ||
47 | { | 46 | { | ||
48 | if ( !s_global ) | 47 | if (!s_global) | ||
49 | s_global = new KgvGlobal ; | 48 | s_global = new KgvGlobal; | ||
50 | // sdg.setObject( s_global, new KgvGlobal ); | 49 | // sdg.setObject( s_global, new KgvGlobal ); | ||
51 | return s_global; | 50 | return s_global; | ||
52 | } | 51 | } | ||
53 | 52 | | |||
54 | KgvGlobal::KgvGlobal() | 53 | KgvGlobal::KgvGlobal() | ||
55 | : m_pointSize( -1 ), m_kofficeConfig(nullptr) | 54 | : m_pointSize(-1) | ||
55 | , m_kofficeConfig(nullptr) | ||||
56 | { | 56 | { | ||
57 | // Install the libkoffice* translations | 57 | // Install the libkoffice* translations | ||
58 | // KGlobal::locale()->insertCatalogue("koffice"); | 58 | // KGlobal::locale()->insertCatalogue("koffice"); | ||
59 | 59 | | |||
60 | // Tell the iconloader about share/apps/koffice/icons | 60 | // Tell the iconloader about share/apps/koffice/icons | ||
61 | // KGlobal::iconLoader()->addAppDir("koffice"); | 61 | // KGlobal::iconLoader()->addAppDir("koffice"); | ||
62 | 62 | | |||
63 | // Another way to get the DPI of the display would be QPaintDeviceMetrics, | 63 | // Another way to get the DPI of the display would be QPaintDeviceMetrics, | ||
64 | // but we have no widget here (and moving this to KgvView wouldn't allow | 64 | // but we have no widget here (and moving this to KgvView wouldn't allow | ||
65 | // using this from the document easily). | 65 | // using this from the document easily). | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | KgvGlobal::~KgvGlobal() | 68 | KgvGlobal::~KgvGlobal() | ||
69 | { | 69 | { | ||
70 | delete m_kofficeConfig; | 70 | delete m_kofficeConfig; | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | QFont KgvGlobal::_defaultFont() | 73 | QFont KgvGlobal::_defaultFont() | ||
74 | { | 74 | { | ||
75 | QFont font = qApp->font(); | 75 | QFont font = qApp->font(); | ||
76 | // we have to use QFontInfo, in case the font was specified with a pixel size | 76 | // we have to use QFontInfo, in case the font was specified with a pixel size | ||
77 | if ( font.pointSize() == -1 ) | 77 | if (font.pointSize() == -1) { | ||
78 | { | | |||
79 | // cache size into m_pointSize, since QFontInfo loads the font -> slow | 78 | // cache size into m_pointSize, since QFontInfo loads the font -> slow | ||
80 | if ( m_pointSize == -1 ) | 79 | if (m_pointSize == -1) | ||
81 | m_pointSize = QFontInfo(font).pointSize(); | 80 | m_pointSize = QFontInfo(font).pointSize(); | ||
82 | Q_ASSERT( m_pointSize != -1 ); | 81 | Q_ASSERT(m_pointSize != -1); | ||
83 | font.setPointSize( m_pointSize ); | 82 | font.setPointSize(m_pointSize); | ||
84 | } | 83 | } | ||
85 | //qCDebug(KGRAPHVIEWERLIB_LOG)<<"QFontInfo(font).pointSize() :"<<QFontInfo(font).pointSize(); | 84 | // qCDebug(KGRAPHVIEWERLIB_LOG)<<"QFontInfo(font).pointSize() :"<<QFontInfo(font).pointSize(); | ||
86 | //qCDebug(KGRAPHVIEWERLIB_LOG)<<"font.name() :"<<font.family (); | 85 | // qCDebug(KGRAPHVIEWERLIB_LOG)<<"font.name() :"<<font.family (); | ||
87 | return font; | 86 | return font; | ||
88 | } | 87 | } | ||
89 | 88 | | |||
90 | // QStringList KgvGlobal::_listOfLanguageTags() | 89 | // QStringList KgvGlobal::_listOfLanguageTags() | ||
91 | // { | 90 | // { | ||
92 | // if ( m_langMap.isEmpty() ) | 91 | // if ( m_langMap.isEmpty() ) | ||
93 | // createListOfLanguages(); | 92 | // createListOfLanguages(); | ||
94 | // return m_langMap.values(); | 93 | // return m_langMap.values(); | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
154 | // | 153 | // | ||
155 | // } | 154 | // } | ||
156 | // | 155 | // | ||
157 | // // #### We also might not have an entry for a language where spellchecking is supported, | 156 | // // #### We also might not have an entry for a language where spellchecking is supported, | ||
158 | // // but no KDE translation is available, like fr_CA. | 157 | // // but no KDE translation is available, like fr_CA. | ||
159 | // // How to add them? | 158 | // // How to add them? | ||
160 | // } | 159 | // } | ||
161 | 160 | | |||
162 | QString KgvGlobal::tagOfLanguage( const QString & _lang) | 161 | QString KgvGlobal::tagOfLanguage(const QString &_lang) | ||
163 | { | 162 | { | ||
164 | const LanguageMap& map = self()->m_langMap; | 163 | const LanguageMap &map = self()->m_langMap; | ||
165 | QMap<QString,QString>::ConstIterator it = map.find( _lang ); | 164 | QMap<QString, QString>::ConstIterator it = map.find(_lang); | ||
166 | if ( it != map.end() ) | 165 | if (it != map.end()) | ||
167 | return *it; | 166 | return *it; | ||
168 | return QString(); | 167 | return QString(); | ||
169 | } | 168 | } | ||
170 | 169 | | |||
171 | QString KgvGlobal::languageFromTag( const QString &langTag ) | 170 | QString KgvGlobal::languageFromTag(const QString &langTag) | ||
172 | { | 171 | { | ||
173 | const LanguageMap& map = self()->m_langMap; | 172 | const LanguageMap &map = self()->m_langMap; | ||
174 | QMap<QString,QString>::ConstIterator it = map.begin(); | 173 | QMap<QString, QString>::ConstIterator it = map.begin(); | ||
175 | const QMap<QString,QString>::ConstIterator end = map.end(); | 174 | const QMap<QString, QString>::ConstIterator end = map.end(); | ||
176 | for ( ; it != end; ++it ) | 175 | for (; it != end; ++it) | ||
177 | if ( it.value() == langTag ) | 176 | if (it.value() == langTag) | ||
178 | return it.key(); | 177 | return it.key(); | ||
179 | 178 | | |||
180 | // Language code not found. Better return the code (tag) than nothing. | 179 | // Language code not found. Better return the code (tag) than nothing. | ||
181 | return langTag; | 180 | return langTag; | ||
182 | } | 181 | } | ||
183 | 182 | | |||
184 | KConfig* KgvGlobal::_kofficeConfig() | 183 | KConfig *KgvGlobal::_kofficeConfig() | ||
185 | { | 184 | { | ||
186 | if ( !m_kofficeConfig ) { | 185 | if (!m_kofficeConfig) { | ||
187 | m_kofficeConfig = new KConfig( "kofficerc" ); | 186 | m_kofficeConfig = new KConfig("kofficerc"); | ||
188 | } | 187 | } | ||
189 | return m_kofficeConfig; | 188 | return m_kofficeConfig; | ||
190 | } | 189 | } |