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; \
151 const int cutoff = 20;
153 while (ps < cutoff &&
QFontMetrics(f).size(Qt::TextSingleLine,
"MX").height() < idealMXHeightPx) {
155 klfDbg(f.
family()<<
": Will try instead with font size="<<ps) ;
179 if (qApp->inherits(
"QApplication")) {
191 QFont cmuappfont = f;
192 if (fdb.
families().contains(
"CMU Sans Serif")) {
195 cmuappfont =
QFont(
"CMU Sans Serif", fps);
199 int fIdealHeight = 17;
201 int fIdealHeight = 15;
208 bool found_fcode =
false;
222 int fcodeIdealHeight = 20;
224 int fcodeIdealHeight = 18;
231 QFont fcodeMain = fcode;
235 Core.thisVersionMajFirstRun =
true;
236 Core.thisVersionMajMinFirstRun =
true;
237 Core.thisVersionMajMinRelFirstRun =
true;
238 Core.thisVersionExactFirstRun =
true;
240 Core.libraryFileName =
"library.klf.db";
241 Core.libraryLibScheme =
"klf+sqlite";
248 #ifdef KLF_NO_CMU_FONT
249 UI.useSystemAppFont =
true;
252 UI.useSystemAppFont =
false;
253 UI.applicationFont = cmuappfont;
255 UI.latexEditFont = fcodeMain;
256 UI.preambleEditFont = fcode;
257 UI.previewTooltipMaxSize =
QSize(800, 600);
258 UI.labelOutputFixedSize =
QSize(280, 80);
260 UI.symbolsPerLine = 6;
262 UI.userColorList.append(
QColor(0,0,0));
263 UI.userColorList.append(
QColor(255,255,255));
264 UI.userColorList.append(
QColor(170,0,0));
265 UI.userColorList.append(
QColor(0,0,128));
266 UI.userColorList.append(
QColor(0,0,255));
267 UI.userColorList.append(
QColor(0,85,0));
268 UI.userColorList.append(
QColor(255,85,0));
269 UI.userColorList.append(
QColor(0,255,255));
270 UI.userColorList.append(
QColor(85,0,127));
271 UI.userColorList.append(
QColor(128,255,255));
274 UI.maxUserColors = 12;
275 UI.enableToolTipPreview =
false;
276 UI.enableRealTimePreview =
true;
277 UI.autosaveLibraryMin = 5;
278 UI.showHintPopups =
true;
279 UI.clearLatexOnly =
false;
280 UI.copyExportProfile =
"default";
281 UI.dragExportProfile =
"default";
282 UI.glowEffect =
false;
283 UI.glowEffectColor =
QColor(128, 255, 128, 12);
284 UI.glowEffectRadius = 4;
286 UI.showExportProfilesLabel =
true;
287 UI.menuExportProfileAffectsDrag =
true;
288 UI.menuExportProfileAffectsCopy =
true;
328 QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
345 if (neededsettings) {
348 if (neededsettings & (1<<0))
350 if (neededsettings & (1<<1))
352 if (neededsettings & (1<<2))
354 if (neededsettings & (1<<3))
356 if (neededsettings & (1<<4))
401 klfDbg(
"Testing for global config file "<<globalconfig);
403 klfDbg(
"Reading configuration from "<<globalconfig);
405 readFromConfig_v2(globalconfig);
413 return readFromConfig_v1();
421 const char * listOrMapType = NULL)
424 QVariant defVal = QVariant::fromValue<T>(*target);
429 klfDbg(
"No entry "<<baseName<<
" in config.") ;
435 *target = val.
value<T>();
442 qDebug(
"klf_config_read<QTextCharFormat>(%s)", qPrintable(baseName));
452 klf_config_read(s, baseName, &vlist, QVariant::fromValue<T>(T()).typeName());
453 *target = klfVariantListToList<T>(vlist);
460 QVariant val = QVariant::fromValue<T>(*value);
487 int KLFConfig::readFromConfig_v2(
const QString& fname)
491 QSettings s(fname, QSettings::IniFormat);
493 qDebug(
"Reading base configuration");
495 s.beginGroup(
"Core");
527 klfDbg(
"Read glow effect color from config: color="<<
UI.glowEffectColor
528 <<
", alpha="<<
UI.glowEffectColor.alpha());
532 klf_config_read(s,
"menuexportprofileaffectsdrag", &
UI.menuExportProfileAffectsDrag);
533 klf_config_read(s,
"menuexportprofileaffectscopy", &
UI.menuExportProfileAffectsCopy);
536 s.beginGroup(
"SyntaxHighlighter");
545 s.beginGroup(
"BackendSettings");
559 s.beginGroup(
"LibraryBrowser");
578 for (k = 0; k < plugindirs.size(); ++k) {
579 if (plugindirs[k] ==
"." || plugindirs[k] ==
"..")
581 qDebug(
"Reading config for plugin %s", qPrintable(plugindirs[k]));
584 qDebug(
"\tskipping plugin %s since the file %s does not exist.",
585 qPrintable(plugindirs[k]), qPrintable(fn));
588 QSettings psettings(fn, QSettings::IniFormat);
589 QVariantMap pconfmap;
591 for (j = 0; j < keys.size(); ++j) {
592 pconfmap[keys[j]] = psettings.value(keys[j]);
594 Plugins.pluginConfig[plugindirs[k]] = pconfmap;
614 bool thisVersionFirstRunFalse =
false;
651 klf_config_write(s,
"menuexportprofileaffectsdrag", &
UI.menuExportProfileAffectsDrag);
652 klf_config_write(s,
"menuexportprofileaffectscopy", &
UI.menuExportProfileAffectsCopy);
659 klf_config_write<QTextFormat>(s,
"parenmatch", &
SyntaxHighlighter.fmtParenMatch);
660 klf_config_write<QTextFormat>(s,
"parenmismatch", &
SyntaxHighlighter.fmtParenMismatch);
661 klf_config_write<QTextFormat>(s,
"lonelyparen", &
SyntaxHighlighter.fmtLonelyParen);
664 s.beginGroup(
"BackendSettings");
678 s.beginGroup(
"LibraryBrowser");
696 QSettings psettings(fn, QSettings::IniFormat);
698 QVariantMap::const_iterator it;
699 for (it = pconfmap.begin(); it != pconfmap.end(); ++it) {
700 psettings.
setValue(it.key(), it.value());
727 _pluginname = QString::null;
730 : _config(other._config), _pluginname(other._pluginname)
732 klfDbg(
"made copy. _config="<<_config<<
"; _pluginname="<<_pluginname) ;
733 if (_config != NULL) {
743 _config = configObject;
744 _pluginname = pluginName;
746 klfDbg(
"_config="<<_config<<
", _pluginname="<<_pluginname) ;
747 if (_config != NULL) {
756 if ( _config == NULL ) {
757 qWarning(
"KLFPluginConfigAccess::homeConfigDir: Invalid Config Pointer!\n");
766 if ( _config == NULL ) {
767 qWarning(
"KLFPluginConfigAccess::homeConfigDir: Invalid Config Pointer!\n");
776 if ( _config == NULL ) {
777 qWarning(
"KLFPluginConfigAccess::tempDir: Invalid Config Pointer!\n");
786 if ( _config == NULL ) {
787 qWarning(
"KLFPluginConfigAccess::homeConfigPluginDataDir: Invalid Config Pointer!\n");
794 qWarning(
"KLFPluginConfigAccess::homeConfigPluginDataDir: Can't create directory: `%s'",
803 if ( _config == NULL ) {
804 qWarning(
"KLFPluginConfigAccess::readValue: Invalid Config Pointer!\n");
816 if ( _config == NULL ) {
817 qWarning(
"KLFPluginConfigAccess::makeDefaultValue: Invalid Config Pointer!\n");
829 if ( _config == NULL ) {
830 qWarning(
"KLFPluginConfigAccess::writeValue: Invalid Config Pointer!\n");
856 int KLFConfig::readFromConfig_v1()
861 UI.locale = s.value(
"locale",
UI.locale).toString();
864 UI.latexEditFont = s.value(
"latexeditfont",
UI.latexEditFont).value<
QFont>();
865 UI.preambleEditFont = s.value(
"preambleeditfont",
UI.preambleEditFont).value<
QFont>();
866 UI.previewTooltipMaxSize = s.value(
"previewtooltipmaxsize",
UI.previewTooltipMaxSize).toSize();
867 UI.labelOutputFixedSize = s.value(
"lbloutputfixedsize",
UI.labelOutputFixedSize ).toSize();
868 UI.lastSaveDir = s.value(
"lastsavedir",
UI.lastSaveDir).toString();
869 UI.symbolsPerLine = s.value(
"symbolsperline",
UI.symbolsPerLine).toInt();
871 UI.colorChooseWidgetRecent =
settings_read_list(s,
"colorchoosewidgetrecent",
UI.colorChooseWidgetRecent);
872 UI.colorChooseWidgetCustom =
settings_read_list(s,
"colorchoosewidgetcustom",
UI.colorChooseWidgetCustom);
873 UI.maxUserColors = s.value(
"maxusercolors",
UI.maxUserColors).toInt();
874 UI.enableToolTipPreview = s.value(
"enabletooltippreview",
UI.enableToolTipPreview).toBool();
875 UI.enableRealTimePreview = s.value(
"enablerealtimepreview",
UI.enableRealTimePreview).toBool();
876 UI.autosaveLibraryMin = s.value(
"autosavelibrarymin",
UI.autosaveLibraryMin).toInt();
879 s.beginGroup(
"SyntaxHighlighter");
888 s.beginGroup(
"BackendSettings");
900 s.beginGroup(
"LibraryBrowser");
906 s.beginGroup(
"Plugins/Config");
910 for (j = 0; j < pluginList.size(); ++j) {
912 s.beginGroup(
QString(
"Plugins/Config/%1").arg(name) );
916 for (k = 0; k < plconfkeys.size(); ++k) {
917 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)
static int adjust_font_size(QFont f, int idealMXHeightPx)
#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