26 #include <QApplication>
27 #include <QMessageBox>
30 #include <QTextStream>
32 #include <QFontDatabase>
37 #include <QDesktopServices>
47 #if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) // windows
49 #elif defined(Q_OS_MAC) || defined(Q_OS_DARWIN) // Mac OS X
51 #else // unix-like system
52 "../share/klatexformula";
57 #ifdef KLF_SHARE_DIR // defined by the build system
67 if (!__klf_share_dir_cached.
isEmpty())
68 return __klf_share_dir_cached;
80 klfDbg(
"share dir is "<<__klf_share_dir_cached) ;
125 for (k = 0; k < l.
size(); ++k)
139 #define KLFCONFIG_TEST_FIXED_FONT(found_fcode, fdb, fcode, f, fps) \
140 if (!found_fcode && fdb.isFixedPitch(f)) { \
141 fcode = QFont(f, fps); \
142 found_fcode = true; \
180 if (qApp->inherits(
"QApplication")) {
185 #if defined(Q_WS_X11)
186 double cmuffactor = 1.4;
187 double codeffactor = 1.4;
188 #elif defined(Q_WS_WIN)
189 double cmuffactor = 1.3;
190 double codeffactor = 1.3;
192 double cmuffactor = 1.25;
193 double codeffactor = 1.3;
195 int cmufpsfinal = (int)(fps*cmuffactor+0.5);
196 int codefpsfinal = (int)(fps*codeffactor+0.5);
203 QFont cmuappfont = f;
205 if (fdb.
families().contains(
"CMU Bright")) {
207 cmuappfont =
QFont(
"CMU Bright", cmufpsfinal);
210 if (fdb.
families().contains(
"CMU Sans Serif")) {
212 cmuappfont =
QFont(
"CMU Sans Serif", cmufpsfinal);
217 bool found_fcode =
false;
218 int ps = codefpsfinal;
240 QFont fcodeMain = fcode;
244 Core.thisVersionMajFirstRun =
true;
245 Core.thisVersionMajMinFirstRun =
true;
246 Core.thisVersionMajMinRelFirstRun =
true;
247 Core.thisVersionExactFirstRun =
true;
249 Core.libraryFileName =
"library.klf.db";
250 Core.libraryLibScheme =
"klf+sqlite";
257 #ifdef KLF_NO_CMU_FONT
258 UI.useSystemAppFont =
true;
261 UI.useSystemAppFont =
false;
262 UI.applicationFont = cmuappfont;
264 UI.latexEditFont = fcodeMain;
265 UI.preambleEditFont = fcode;
266 UI.previewTooltipMaxSize =
QSize(800, 600);
267 UI.labelOutputFixedSize =
QSize(280, 80);
269 UI.symbolsPerLine = 6;
271 UI.userColorList.append(
QColor(0,0,0));
272 UI.userColorList.append(
QColor(255,255,255));
273 UI.userColorList.append(
QColor(170,0,0));
274 UI.userColorList.append(
QColor(0,0,128));
275 UI.userColorList.append(
QColor(0,0,255));
276 UI.userColorList.append(
QColor(0,85,0));
277 UI.userColorList.append(
QColor(255,85,0));
278 UI.userColorList.append(
QColor(0,255,255));
279 UI.userColorList.append(
QColor(85,0,127));
280 UI.userColorList.append(
QColor(128,255,255));
283 UI.maxUserColors = 12;
284 UI.enableToolTipPreview =
false;
285 UI.enableRealTimePreview =
true;
286 UI.autosaveLibraryMin = 5;
287 UI.showHintPopups =
true;
288 UI.clearLatexOnly =
false;
289 UI.copyExportProfile =
"default";
290 UI.dragExportProfile =
"default";
291 UI.glowEffect =
false;
292 UI.glowEffectColor =
QColor(128, 255, 128, 12);
293 UI.glowEffectRadius = 4;
295 UI.showExportProfilesLabel =
true;
296 UI.menuExportProfileAffectsDrag =
true;
297 UI.menuExportProfileAffectsCopy =
true;
337 QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
354 if (neededsettings) {
357 if (neededsettings & (1<<0))
359 if (neededsettings & (1<<1))
361 if (neededsettings & (1<<2))
363 if (neededsettings & (1<<3))
365 if (neededsettings & (1<<4))
410 klfDbg(
"Testing for global config file "<<globalconfig);
412 klfDbg(
"Reading configuration from "<<globalconfig);
414 readFromConfig_v2(globalconfig);
422 return readFromConfig_v1();
430 const char * listOrMapType = NULL)
433 QVariant defVal = QVariant::fromValue<T>(*target);
438 klfDbg(
"No entry "<<baseName<<
" in config.") ;
444 *target = val.
value<T>();
451 qDebug(
"klf_config_read<QTextCharFormat>(%s)", qPrintable(baseName));
461 klf_config_read(s, baseName, &vlist, QVariant::fromValue<T>(T()).typeName());
462 *target = klfVariantListToList<T>(vlist);
469 QVariant val = QVariant::fromValue<T>(*value);
496 int KLFConfig::readFromConfig_v2(
const QString& fname)
500 QSettings s(fname, QSettings::IniFormat);
502 qDebug(
"Reading base configuration");
504 s.beginGroup(
"Core");
536 klfDbg(
"Read glow effect color from config: color="<<
UI.glowEffectColor
537 <<
", alpha="<<
UI.glowEffectColor.alpha());
541 klf_config_read(s,
"menuexportprofileaffectsdrag", &
UI.menuExportProfileAffectsDrag);
542 klf_config_read(s,
"menuexportprofileaffectscopy", &
UI.menuExportProfileAffectsCopy);
545 s.beginGroup(
"SyntaxHighlighter");
554 s.beginGroup(
"BackendSettings");
568 s.beginGroup(
"LibraryBrowser");
587 for (k = 0; k < plugindirs.size(); ++k) {
588 if (plugindirs[k] ==
"." || plugindirs[k] ==
"..")
590 qDebug(
"Reading config for plugin %s", qPrintable(plugindirs[k]));
593 qDebug(
"\tskipping plugin %s since the file %s does not exist.",
594 qPrintable(plugindirs[k]), qPrintable(fn));
597 QSettings psettings(fn, QSettings::IniFormat);
598 QVariantMap pconfmap;
600 for (j = 0; j < keys.size(); ++j) {
601 pconfmap[keys[j]] = psettings.value(keys[j]);
603 Plugins.pluginConfig[plugindirs[k]] = pconfmap;
623 bool thisVersionFirstRunFalse =
false;
660 klf_config_write(s,
"menuexportprofileaffectsdrag", &
UI.menuExportProfileAffectsDrag);
661 klf_config_write(s,
"menuexportprofileaffectscopy", &
UI.menuExportProfileAffectsCopy);
668 klf_config_write<QTextFormat>(s,
"parenmatch", &
SyntaxHighlighter.fmtParenMatch);
669 klf_config_write<QTextFormat>(s,
"parenmismatch", &
SyntaxHighlighter.fmtParenMismatch);
670 klf_config_write<QTextFormat>(s,
"lonelyparen", &
SyntaxHighlighter.fmtLonelyParen);
673 s.beginGroup(
"BackendSettings");
687 s.beginGroup(
"LibraryBrowser");
705 QSettings psettings(fn, QSettings::IniFormat);
707 QVariantMap::const_iterator it;
708 for (it = pconfmap.begin(); it != pconfmap.end(); ++it) {
709 psettings.
setValue(it.key(), it.value());
736 _pluginname = QString::null;
739 : _config(other._config), _pluginname(other._pluginname)
741 klfDbg(
"made copy. _config="<<_config<<
"; _pluginname="<<_pluginname) ;
742 if (_config != NULL) {
752 _config = configObject;
753 _pluginname = pluginName;
755 klfDbg(
"_config="<<_config<<
", _pluginname="<<_pluginname) ;
756 if (_config != NULL) {
765 if ( _config == NULL ) {
766 qWarning(
"KLFPluginConfigAccess::homeConfigDir: Invalid Config Pointer!\n");
775 if ( _config == NULL ) {
776 qWarning(
"KLFPluginConfigAccess::homeConfigDir: Invalid Config Pointer!\n");
785 if ( _config == NULL ) {
786 qWarning(
"KLFPluginConfigAccess::tempDir: Invalid Config Pointer!\n");
795 if ( _config == NULL ) {
796 qWarning(
"KLFPluginConfigAccess::homeConfigPluginDataDir: Invalid Config Pointer!\n");
803 qWarning(
"KLFPluginConfigAccess::homeConfigPluginDataDir: Can't create directory: `%s'",
812 if ( _config == NULL ) {
813 qWarning(
"KLFPluginConfigAccess::readValue: Invalid Config Pointer!\n");
825 if ( _config == NULL ) {
826 qWarning(
"KLFPluginConfigAccess::makeDefaultValue: Invalid Config Pointer!\n");
838 if ( _config == NULL ) {
839 qWarning(
"KLFPluginConfigAccess::writeValue: Invalid Config Pointer!\n");
865 int KLFConfig::readFromConfig_v1()
870 UI.locale = s.value(
"locale",
UI.locale).toString();
873 UI.latexEditFont = s.value(
"latexeditfont",
UI.latexEditFont).value<
QFont>();
874 UI.preambleEditFont = s.value(
"preambleeditfont",
UI.preambleEditFont).value<
QFont>();
875 UI.previewTooltipMaxSize = s.value(
"previewtooltipmaxsize",
UI.previewTooltipMaxSize).toSize();
876 UI.labelOutputFixedSize = s.value(
"lbloutputfixedsize",
UI.labelOutputFixedSize ).toSize();
877 UI.lastSaveDir = s.value(
"lastsavedir",
UI.lastSaveDir).toString();
878 UI.symbolsPerLine = s.value(
"symbolsperline",
UI.symbolsPerLine).toInt();
880 UI.colorChooseWidgetRecent =
settings_read_list(s,
"colorchoosewidgetrecent",
UI.colorChooseWidgetRecent);
881 UI.colorChooseWidgetCustom =
settings_read_list(s,
"colorchoosewidgetcustom",
UI.colorChooseWidgetCustom);
882 UI.maxUserColors = s.value(
"maxusercolors",
UI.maxUserColors).toInt();
883 UI.enableToolTipPreview = s.value(
"enabletooltippreview",
UI.enableToolTipPreview).toBool();
884 UI.enableRealTimePreview = s.value(
"enablerealtimepreview",
UI.enableRealTimePreview).toBool();
885 UI.autosaveLibraryMin = s.value(
"autosavelibrarymin",
UI.autosaveLibraryMin).toInt();
888 s.beginGroup(
"SyntaxHighlighter");
897 s.beginGroup(
"BackendSettings");
909 s.beginGroup(
"LibraryBrowser");
915 s.beginGroup(
"Plugins/Config");
919 for (j = 0; j < pluginList.size(); ++j) {
921 s.beginGroup(
QString(
"Plugins/Config/%1").arg(name) );
925 for (k = 0; k < plconfkeys.size(); ++k) {
926 thispluginconfig[plconfkeys[k]] = s.
value(plconfkeys[k]);
virtual QVariant readValue(const QString &key) const
read a value in the config
static QString __klf_share_dir_cached
setPointSize(int pointSize)
QString locale
When setting this, don't forget to call QLocale::setDefault().
QString homeConfigDirRCCResources
QMap< QString, QMap< QString, QVariant > > pluginConfig
#define klfDbgT(streamableItems)
virtual ~KLFPluginConfigAccess()
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
#define klfDbg(streamableItems)
virtual QString homeConfigPluginDataDir(bool createIfNeeded=true) const
#define KLF_DEBUG_BLOCK(msg)
QString homeConfigDirI18n
Utility class for plugins to access their configuration space in KLFConfig.
KLF_EXPORT QString klfPrefixedPath(const QString &path, const QString &reference)
struct KLFConfig::@0 Core
Structure that stores klatexformula's configuration in memory.
setValue(const QString &key, const QVariant &value)
static void klf_config_write(QSettings &s, const QString &baseName, const T *value)
fromLocal8Bit(const char *str, int size=-1)
static void klf_config_read_list(QSettings &s, const QString &baseName, QList< T > *target)
KLF_EXPORT QVariant klfLoadVariantFromText(const QByteArray &stringdata, const char *dataTypeName, const char *listOrMapDataTypeName)
setDefault(const QLocale &locale)
entryList(const QStringList &nameFilters, Filters filters=NoFilter, SortFlags sort=NoSort)
QString homeConfigSettingsFileIni
OLD config file.
static void klf_config_write_list(QSettings &s, const QString &baseName, const QList< T > *target)
KLF_EXPORT bool klfEnsureDir(const QString &dir)
int ensureHomeConfigDir()
KLF_EXPORT QString klf_share_dir_abspath()
#define KLF_DEBUG_TIME_BLOCK(msg)
virtual QVariant makeDefaultValue(const QString &key, const QVariant &defaultValue)
write the value if inexistant in config
struct KLFConfig::@2 SyntaxHighlighter
QList< KLFPluginInfo > klf_plugins
struct KLFConfig::@3 BackendSettings
value(const QString &key, const QVariant &defaultValue=QVariant()
static const char * __klf_fallback_share_dir
QString homeConfigDirPluginData
void detectMissingSettings()
static void klf_config_read(QSettings &s, const QString &baseName, T *target, const char *listOrMapType=NULL)
families(WritingSystem writingSystem=Any)
static QTextCharFormat settings_read_QTextCharFormat(QSettings &s, const QString &basename, const QTextCharFormat &dflt)
QVariantList klfListToVariantList(const QList< T > &list)
static const char * __klf_share_dir
static QString firstRunConfigKey(int N)
KLFPluginConfigAccess getPluginConfigAccess(const QString &name)
absoluteFilePath(const QString &fileName)
static QList< T > settings_read_list(QSettings &s, const QString &basename, const QList< T > &dflt)
KLF_EXPORT QByteArray klfSaveVariantToText(const QVariant &value, bool saveListAndMapsAsXML)
#define KLFCONFIG_TEST_FIXED_FONT(found_fcode, fdb, fcode, f, fps)
virtual QString tempDir() const
virtual void writeValue(const QString &key, const QVariant &value)
write a value to settings
virtual QString homeConfigDir() const
static bool detectSettings(klfSettings *settings, const QString &extraPath=QString())
struct KLFConfig::@4 LibraryBrowser
virtual QString globalShareDir() const
QString homeConfigSettingsFile
current (now, "new" klatexformula.conf) settings file
void klf_config_read< QTextCharFormat >(QSettings &s, const QString &baseName, QTextCharFormat *target, const char *)
struct KLFConfig::@5 Plugins
beginGroup(const QString &prefix)
QString homeConfigDirPlugins