Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Switch KoFontRegistery to a QObject, use signals to update.

Wolthera van Hövell tot Westerflier6b53bca05b89
diff --git a/libs/flake/text/KoFontChangeTracker.cpp b/libs/flake/text/KoFontChangeTracker.cpp
index 293ac1e1f8..66bcc62e93 100644
--- a/libs/flake/text/KoFontChangeTracker.cpp
+++ b/libs/flake/text/KoFontChangeTracker.cpp
@@ -12,25 +12,20 @@
struct KoFontChangeTracker::Private {
Private(QStringList paths = QStringList(), int refresh = 500)
- : fileSystemWatcher(paths)
- , configSignalCompressor(refresh, KisSignalCompressor::POSTPONE) {
+ : fileSystemWatcher(paths) {
}
QFileSystemWatcher fileSystemWatcher;
- KisSignalCompressor configSignalCompressor;
bool filesChanged = false;
bool configStale = false;
};
-KoFontChangeTracker::KoFontChangeTracker(QStringList paths, int configRefreshValue, QObject *parent)
+KoFontChangeTracker::KoFontChangeTracker(QStringList paths, QObject *parent)
: QObject(parent)
- , d(new Private(paths, configRefreshValue))
+ , d(new Private(paths))
{
- d->fileSystemWatcher;
-
connect(&d->fileSystemWatcher, SIGNAL(directoryChanged(QString)), SLOT(directoriesChanged(QString)));
- connect(&d->configSignalCompressor, SIGNAL(timeout()), this, SLOT(intervalElapsed()));
}
KoFontChangeTracker::~KoFontChangeTracker()
@@ -39,41 +34,14 @@ KoFontChangeTracker::~KoFontChangeTracker()
void KoFontChangeTracker::resetChangeTracker()
{
- d->configStale = false;
d->filesChanged = false;
- d->configSignalCompressor.start();
-}
-
-void KoFontChangeTracker::connectToRegistery()
-{
- connect(this, SIGNAL(sigUpdateConfig()), this, SLOT(updateFontRegistery()), Qt::UniqueConnection);
-}
-
-#include <KoFontRegistry.h>
-void KoFontChangeTracker::updateFontRegistery()
-{
- KoFontRegistry::instance()->updateConfig();
}
-void KoFontChangeTracker::intervalElapsed()
-{
- if (!d->configStale) {
- d->configStale = true;
- testUpdate();
- }
-}
void KoFontChangeTracker::directoriesChanged(QString path)
{
if (!d->filesChanged) {
d->filesChanged = true;
- testUpdate();
- }
-}
-
-void KoFontChangeTracker::testUpdate()
-{
- if (d->filesChanged && d->configStale) {
emit (sigUpdateConfig());
}
}
diff --git a/libs/flake/text/KoFontChangeTracker.h b/libs/flake/text/KoFontChangeTracker.h
index 5ceff97cdc..384018323c 100644
--- a/libs/flake/text/KoFontChangeTracker.h
+++ b/libs/flake/text/KoFontChangeTracker.h
@@ -10,30 +10,22 @@
/**
* @brief The KoFontChangeTracker class
- * This class keeps track of the FontConfig refresh value,
- * as well as the paths FontConfig is looking at,
- * and resets the
+ * This class keeps track of the paths FontConfig is looking at,
+ * and resets the font registery if they change.
*/
class KoFontChangeTracker : public QObject
{
Q_OBJECT
public:
- explicit KoFontChangeTracker(QStringList paths, int configRefreshValue = 0, QObject *parent = nullptr);
+ explicit KoFontChangeTracker(QStringList paths, QObject *parent = nullptr);
~KoFontChangeTracker();
/// This should be called after fontregistery initialization is done to start the signal compressor.
void resetChangeTracker();
-
- /// This needs to be manually connected.
- void connectToRegistery();
-public Q_SLOTS:
- void updateFontRegistery();
Q_SIGNALS:
void sigUpdateConfig();
private Q_SLOTS:
- void intervalElapsed();
void directoriesChanged(QString path);
- void testUpdate();
private:
struct Private;
QScopedPointer<Private> d;
diff --git a/libs/flake/text/KoFontRegistry.cpp b/libs/flake/text/KoFontRegistry.cpp
index 43d692148f..6dd8d89507 100644
--- a/libs/flake/text/KoFontRegistry.cpp
+++ b/libs/flake/text/KoFontRegistry.cpp
@@ -133,9 +133,7 @@ public:
path = QString::fromUtf8(reinterpret_cast<char *>(dirString));
}
FcStrListDone(list);
- int rescanInterval = FcConfigGetRescanInterval(m_config.data());
- changeTracker.reset(new KoFontChangeTracker(paths, rescanInterval * 1000));
- changeTracker->connectToRegistery();
+ changeTracker.reset(new KoFontChangeTracker(paths));
changeTracker->resetChangeTracker();
reloadConverter();
@@ -180,6 +178,10 @@ public:
return fontFamilyConverter;
}
+ QSharedPointer<KoFontChangeTracker> fontChangeTracker() const {
+ return changeTracker;
+ }
+
bool reloadConverter() {
fontFamilyConverter.reset(new KoFFWWSConverter());
FcObjectSet *objectSet = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_INDEX, FC_LANG, FC_CHARSET, nullptr);
@@ -203,11 +205,7 @@ public:
fontFamilyConverter->debugInfo();
}
-public Q_SLOTS:
void updateConfig() {
- if (!FcInitBringUptoDate()) {
- return;
- }
if (FcConfigBuildFonts(m_config.data())) {
reloadConverter();
KisResourceLocator::instance()->updateFontStorage();
@@ -216,12 +214,15 @@ public Q_SLOTS:
}
};
-KoFontRegistry::KoFontRegistry()
- : d(new Private())
+KoFontRegistry::KoFontRegistry(QObject *parent)
+ : QObject(parent)
+ , d(new Private())
{
+ connect(d->fontChangeTracker().data(), SIGNAL(sigUpdateConfig()), this, SLOT(updateConfig()), Qt::UniqueConnection);
}
-KoFontRegistry::~KoFontRegistry() = default;
+KoFontRegistry::~KoFontRegistry() {
+}
KoFontRegistry *KoFontRegistry::instance()
{
diff --git a/libs/flake/text/KoFontRegistry.h b/libs/flake/text/KoFontRegistry.h
index 50b7fef21e..40f4e05548 100644
--- a/libs/flake/text/KoFontRegistry.h
+++ b/libs/flake/text/KoFontRegistry.h
@@ -6,6 +6,7 @@
#ifndef KOFONTREGISTRY_H
#define KOFONTREGISTRY_H
+#include <QObject>
#include <QScopedPointer>
#include <QVector>
@@ -25,10 +26,11 @@
* It also provides a configuration function to handle all the
* size and variation axis values.
*/
-class KRITAFLAKE_EXPORT KoFontRegistry
+class KRITAFLAKE_EXPORT KoFontRegistry: public QObject
{
+ Q_OBJECT
public:
- KoFontRegistry();
+ KoFontRegistry(QObject *parent = nullptr);
~KoFontRegistry();
static KoFontRegistry *instance();
@@ -92,11 +94,6 @@ public:
// Get the closest font family resource name for a given font family name, used by the selectors.
QString wwsNameByFamilyName(const QString familyName, bool *found = nullptr) const;
- /**
- * Update the config and reset the FontChangeListener.
- */
- void updateConfig();
-
/**
* @brief slantMode
* testing the slant mode can be annoying, so this is a convenience function to return the slant mode.
@@ -104,7 +101,11 @@ public:
* @return the slant mode, can be normal, italic or oblique.
*/
static QFont::Style slantMode(FT_FaceSP face);
-
+private Q_SLOTS:
+ /**
+ * Update the config and reset the FontChangeListener.
+ */
+ void updateConfig();
private:
class Private;
diff --git a/libs/resources/KisResourceLocator.h b/libs/resources/KisResourceLocator.h
index 163a6397cf..8cda1cdc8b 100644
--- a/libs/resources/KisResourceLocator.h
+++ b/libs/resources/KisResourceLocator.h
@@ -118,7 +118,7 @@ public:
* separate physical representation on the disk
*/
QString filePathForResource(KoResourceSP resource);
-public Q_SLOTS:
+
/// This updates the "fontregistery" storage. Called when the font directories change;
void updateFontStorage();