initial commit
This commit is contained in:
+4
-3
@@ -9,8 +9,8 @@ set(CMAKE_AUTORCC ON)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
|
||||||
|
|
||||||
set(PROJECT_SOURCES
|
set(PROJECT_SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
@@ -24,6 +24,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
|||||||
MANUAL_FINALIZATION
|
MANUAL_FINALIZATION
|
||||||
${PROJECT_SOURCES}
|
${PROJECT_SOURCES}
|
||||||
ifontprovider.h
|
ifontprovider.h
|
||||||
|
cfontinfo.cpp cfontinfo.h
|
||||||
cfont.h cfont.cpp
|
cfont.h cfont.cpp
|
||||||
|
|
||||||
)
|
)
|
||||||
@@ -45,7 +46,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(fontManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
target_link_libraries(fontManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
|
||||||
|
|
||||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||||
# If you are developing for iOS or macOS you should consider setting an
|
# If you are developing for iOS or macOS you should consider setting an
|
||||||
|
|||||||
+33
-115
@@ -1,120 +1,38 @@
|
|||||||
#include "cfont.h"
|
#include "cfont.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QEventLoop>
|
||||||
|
|
||||||
|
#include <QFontDatabase>
|
||||||
|
|
||||||
|
|
||||||
cFont::cFont()
|
// cFont::cFont() {}
|
||||||
{
|
cFont::cFont(QUrl url) {
|
||||||
}
|
QNetworkAccessManager networkManager;
|
||||||
|
QNetworkRequest request(url);
|
||||||
void cFont::setFamily(const QString& family) {
|
|
||||||
m_family = family;
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
}
|
|
||||||
|
QNetworkReply* reply = networkManager.get(request);
|
||||||
QString cFont::family() {
|
QEventLoop loop;
|
||||||
return m_family;
|
|
||||||
}
|
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
|
loop.exec();
|
||||||
void cFont::setVariants(const QStringList& variants) {
|
|
||||||
m_variants = variants;
|
QByteArray data = reply->readAll();
|
||||||
m_variants.removeDuplicates();
|
delete reply;
|
||||||
}
|
|
||||||
|
int id = QFontDatabase::addApplicationFontFromData(data);
|
||||||
void cFont::clearVariants() {
|
|
||||||
m_variants.clear();
|
if(id < 0)
|
||||||
}
|
return;
|
||||||
|
|
||||||
void cFont::addVariants(const QStringList& variants) {
|
QStringList loaded = QFontDatabase::applicationFontFamilies(id);
|
||||||
m_variants.append(variants);
|
|
||||||
m_variants.removeDuplicates();
|
bool ret = this->fromString(loaded[0]);
|
||||||
}
|
|
||||||
|
if(!ret)
|
||||||
void cFont::addVariants(const QString& variant) {
|
return;
|
||||||
m_variants.append(variant);
|
|
||||||
m_variants.removeDuplicates();
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList cFont::variants() {
|
|
||||||
return m_variants;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::setSubsets(const QStringList& subsets) {
|
|
||||||
m_subsets = subsets;
|
|
||||||
m_subsets.removeDuplicates();
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::clearSubsets() {
|
|
||||||
m_subsets.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::addSubsets(const QStringList& subsets) {
|
|
||||||
m_subsets.append(subsets);
|
|
||||||
m_subsets.removeDuplicates();
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::addSubsets(const QString& subset) {
|
|
||||||
m_subsets.append(subset);
|
|
||||||
m_subsets.removeDuplicates();
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList cFont::subsets() {
|
|
||||||
return m_subsets;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::setVersion(const QString& version) {
|
|
||||||
m_version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString cFont::version() {
|
|
||||||
return m_version;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::setLastModified(const QDate& lastModified) {
|
|
||||||
m_lastModified = lastModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDate cFont::lastModified() {
|
|
||||||
return m_lastModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::setFiles(const QMap<QString, QString>& files) {
|
|
||||||
for (auto [key, value] : files.asKeyValueRange()) {
|
|
||||||
m_files.insert(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::clearFiles() {
|
|
||||||
m_files.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::addFiles(const QMap<QString, QString>& files) {
|
|
||||||
for (auto [key, value] : files.asKeyValueRange()) {
|
|
||||||
if (!m_files.contains(key))
|
|
||||||
m_files.insert(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::addFiles(const QString& variant, const QString& file) {
|
|
||||||
if (!m_files.contains(variant))
|
|
||||||
m_files.insert(variant, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<QString, QString> cFont::files() {
|
|
||||||
return m_files;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::setCategory(const QString& category) {
|
|
||||||
m_category = category;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString cFont::category() {
|
|
||||||
return m_category;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cFont::setKind(const QString& kind) {
|
|
||||||
m_kind = kind;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString cFont::kind() {
|
|
||||||
return m_kind;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-50
@@ -2,61 +2,16 @@
|
|||||||
#define CFONT_H
|
#define CFONT_H
|
||||||
|
|
||||||
|
|
||||||
//#include <QObject>
|
#include <QFont>
|
||||||
#include <QString>
|
#include <QUrl>
|
||||||
#include <QDate>
|
|
||||||
#include <QMap>
|
|
||||||
|
|
||||||
|
|
||||||
class cFont
|
class cFont : public QFont
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit cFont();
|
using QFont::QFont;
|
||||||
|
|
||||||
void setFamily(const QString& family);
|
cFont(QUrl url);
|
||||||
QString family();
|
|
||||||
|
|
||||||
void setVariants(const QStringList& variants);
|
|
||||||
void clearVariants();
|
|
||||||
void addVariants(const QStringList& variants);
|
|
||||||
void addVariants(const QString& variant);
|
|
||||||
QStringList variants();
|
|
||||||
|
|
||||||
void setSubsets(const QStringList& subsets);
|
|
||||||
void clearSubsets();
|
|
||||||
void addSubsets(const QStringList& subsets);
|
|
||||||
void addSubsets(const QString& subset);
|
|
||||||
QStringList subsets();
|
|
||||||
|
|
||||||
void setVersion(const QString& version);
|
|
||||||
QString version();
|
|
||||||
|
|
||||||
void setLastModified(const QDate& lastModified);
|
|
||||||
QDate lastModified();
|
|
||||||
|
|
||||||
void setFiles(const QMap<QString, QString>& files);
|
|
||||||
void clearFiles();
|
|
||||||
void addFiles(const QMap<QString, QString>& files);
|
|
||||||
void addFiles(const QString& variant, const QString& file);
|
|
||||||
QMap<QString, QString> files();
|
|
||||||
|
|
||||||
void setCategory(const QString& category);
|
|
||||||
QString category();
|
|
||||||
|
|
||||||
void setKind(const QString& kind);
|
|
||||||
QString kind();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_family;
|
|
||||||
QStringList m_variants;
|
|
||||||
QStringList m_subsets;
|
|
||||||
QString m_version;
|
|
||||||
QDate m_lastModified;
|
|
||||||
QMap<QString, QString> m_files;
|
|
||||||
QString m_category;
|
|
||||||
QString m_kind;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CFONT_H
|
#endif // CFONT_H
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
#include "cfontinfo.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
|
||||||
|
cFontInfo::cFontInfo()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setFamily(const QString& family) {
|
||||||
|
m_family = family;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString cFontInfo::family() {
|
||||||
|
return m_family;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setVariants(const QStringList& variants) {
|
||||||
|
m_variants = variants;
|
||||||
|
m_variants.removeDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::clearVariants() {
|
||||||
|
m_variants.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::addVariants(const QStringList& variants) {
|
||||||
|
m_variants.append(variants);
|
||||||
|
m_variants.removeDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::addVariants(const QString& variant) {
|
||||||
|
m_variants.append(variant);
|
||||||
|
m_variants.removeDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList cFontInfo::variants() {
|
||||||
|
return m_variants;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setSubsets(const QStringList& subsets) {
|
||||||
|
m_subsets = subsets;
|
||||||
|
m_subsets.removeDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::clearSubsets() {
|
||||||
|
m_subsets.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::addSubsets(const QStringList& subsets) {
|
||||||
|
m_subsets.append(subsets);
|
||||||
|
m_subsets.removeDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::addSubsets(const QString& subset) {
|
||||||
|
m_subsets.append(subset);
|
||||||
|
m_subsets.removeDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList cFontInfo::subsets() {
|
||||||
|
return m_subsets;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setVersion(const QString& version) {
|
||||||
|
m_version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString cFontInfo::version() {
|
||||||
|
return m_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setLastModified(const QDate& lastModified) {
|
||||||
|
m_lastModified = lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate cFontInfo::lastModified() {
|
||||||
|
return m_lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setFiles(const QMap<QString, QString>& files) {
|
||||||
|
for (auto [key, value] : files.asKeyValueRange()) {
|
||||||
|
m_files.insert(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::clearFiles() {
|
||||||
|
m_files.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::addFiles(const QMap<QString, QString>& files) {
|
||||||
|
for (auto [key, value] : files.asKeyValueRange()) {
|
||||||
|
if (!m_files.contains(key))
|
||||||
|
m_files.insert(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::addFiles(const QString& variant, const QString& file) {
|
||||||
|
if (!m_files.contains(variant))
|
||||||
|
m_files.insert(variant, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QString, QString> cFontInfo::files() {
|
||||||
|
return m_files;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setCategory(const QString& category) {
|
||||||
|
m_category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString cFontInfo::category() {
|
||||||
|
return m_category;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cFontInfo::setKind(const QString& kind) {
|
||||||
|
m_kind = kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString cFontInfo::kind() {
|
||||||
|
return m_kind;
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#ifndef CFONTINFO_H
|
||||||
|
#define CFONTINFO_H
|
||||||
|
|
||||||
|
|
||||||
|
//#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
|
||||||
|
class cFontInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit cFontInfo();
|
||||||
|
|
||||||
|
void setFamily(const QString& family);
|
||||||
|
QString family();
|
||||||
|
|
||||||
|
void setVariants(const QStringList& variants);
|
||||||
|
void clearVariants();
|
||||||
|
void addVariants(const QStringList& variants);
|
||||||
|
void addVariants(const QString& variant);
|
||||||
|
QStringList variants();
|
||||||
|
|
||||||
|
void setSubsets(const QStringList& subsets);
|
||||||
|
void clearSubsets();
|
||||||
|
void addSubsets(const QStringList& subsets);
|
||||||
|
void addSubsets(const QString& subset);
|
||||||
|
QStringList subsets();
|
||||||
|
|
||||||
|
void setVersion(const QString& version);
|
||||||
|
QString version();
|
||||||
|
|
||||||
|
void setLastModified(const QDate& lastModified);
|
||||||
|
QDate lastModified();
|
||||||
|
|
||||||
|
void setFiles(const QMap<QString, QString>& files);
|
||||||
|
void clearFiles();
|
||||||
|
void addFiles(const QMap<QString, QString>& files);
|
||||||
|
void addFiles(const QString& variant, const QString& file);
|
||||||
|
QMap<QString, QString> files();
|
||||||
|
|
||||||
|
void setCategory(const QString& category);
|
||||||
|
QString category();
|
||||||
|
|
||||||
|
void setKind(const QString& kind);
|
||||||
|
QString kind();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_family;
|
||||||
|
QStringList m_variants;
|
||||||
|
QStringList m_subsets;
|
||||||
|
QString m_version;
|
||||||
|
QDate m_lastModified;
|
||||||
|
QMap<QString, QString> m_files;
|
||||||
|
QString m_category;
|
||||||
|
QString m_kind;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CFONTINFO_H
|
||||||
+36
-24
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "ifontprovider.h"
|
#include "ifontprovider.h"
|
||||||
|
#include "cfont.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
@@ -14,34 +15,45 @@ cMainWindow::cMainWindow(QWidget *parent)
|
|||||||
, ui(new Ui::cMainWindow) {
|
, ui(new Ui::cMainWindow) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
QList<cFont> fonts;
|
ui->m_label1->setText("blabla");
|
||||||
|
|
||||||
QDir pluginsDir = QDir(QApplication::applicationDirPath());
|
cFont font2(QUrl("https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf"));
|
||||||
|
ui->m_label2->setFont(font2);
|
||||||
|
ui->m_label2->setText("blabla");
|
||||||
|
|
||||||
const auto entryList = pluginsDir.entryList(QDir::Files);
|
cFont font3(QUrl("https://fonts.gstatic.com/s/akshar/v9/Yq6I-LyHWTfz9rGoqDaUbHvhkAUsSZECy9CY94XsnPc.ttf"));
|
||||||
for (const QString &fileName : entryList) {
|
ui->m_label3->setFont(font3);
|
||||||
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
ui->m_label3->setText("blabla");
|
||||||
QObject *plugin = loader.instance();
|
|
||||||
if (plugin) {
|
|
||||||
auto *interface = qobject_cast<IFontProvider *>(plugin);
|
|
||||||
if (!interface)
|
|
||||||
return;
|
|
||||||
qDebug() << "API Version: " << interface->pluginAPIVersion();
|
|
||||||
qDebug() << "Name: " << interface->name();
|
|
||||||
qDebug() << "Version: " << interface->version();
|
|
||||||
|
|
||||||
fonts = interface->search("");
|
// QList<cFontInfo> fonts;
|
||||||
qDebug() << fonts.count();
|
|
||||||
|
|
||||||
fonts.clear();
|
// QDir pluginsDir = QDir(QApplication::applicationDirPath());
|
||||||
fonts = interface->search("Roboto");
|
|
||||||
qDebug() << fonts.count();
|
// const auto entryList = pluginsDir.entryList(QDir::Files);
|
||||||
}
|
// for (const QString &fileName : entryList) {
|
||||||
#if 0
|
// QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
||||||
else
|
// QObject *plugin = loader.instance();
|
||||||
qDebug() << loader.errorString();
|
// if (plugin) {
|
||||||
#endif
|
// auto *interface = qobject_cast<IFontProvider *>(plugin);
|
||||||
}
|
// if (!interface)
|
||||||
|
// return;
|
||||||
|
// qDebug() << "API Version: " << interface->pluginAPIVersion();
|
||||||
|
// qDebug() << "Name: " << interface->name();
|
||||||
|
// qDebug() << "Version: " << interface->version();
|
||||||
|
|
||||||
|
// // fonts = interface->search("");
|
||||||
|
// // qDebug() << fonts.count();
|
||||||
|
|
||||||
|
// // fonts.clear();
|
||||||
|
// fonts = interface->search("Roboto");
|
||||||
|
// qDebug() << fonts.count();
|
||||||
|
|
||||||
|
// }
|
||||||
|
// #if 0
|
||||||
|
// else
|
||||||
|
// qDebug() << loader.errorString();
|
||||||
|
// #endif
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
cMainWindow::~cMainWindow() {
|
cMainWindow::~cMainWindow() {
|
||||||
|
|||||||
+25
-1
@@ -13,7 +13,31 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>cMainWindow</string>
|
<string>cMainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget"/>
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="m_label1">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="m_label2">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="m_label3">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
|||||||
+6
-6
@@ -6,7 +6,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
#include "cfont.h"
|
#include "cfontinfo.h"
|
||||||
|
|
||||||
|
|
||||||
class IFontProvider
|
class IFontProvider
|
||||||
@@ -19,11 +19,11 @@ public:
|
|||||||
style
|
style
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~IFontProvider() = default;
|
virtual ~IFontProvider() = default;
|
||||||
virtual QString pluginAPIVersion() = 0;
|
virtual QString pluginAPIVersion() = 0;
|
||||||
virtual QString name() = 0;
|
virtual QString name() = 0;
|
||||||
virtual QString version() = 0;
|
virtual QString version() = 0;
|
||||||
virtual QList<cFont> search(const QString& family, const QString& subset = QString(), const Sort& sort = Sort::popularity) = 0;
|
virtual QList<cFontInfo> search(const QString& family, const QString& subset = QString(), const Sort& sort = Sort::popularity) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
qt_add_plugin(googlefonts
|
qt_add_plugin(googlefonts
|
||||||
CLASS_NAME GoogleFonts
|
CLASS_NAME GoogleFonts
|
||||||
cgooglefonts.cpp cgooglefonts.h ../../app/cfont.cpp ../../app/cfont.h
|
cgooglefonts.cpp cgooglefonts.h ../../app/cfontinfo.cpp ../../app/cfontinfo.h
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Network)
|
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Network)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ QString cGoogleFonts::version() {
|
|||||||
return tr("0.1");
|
return tr("0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<cFont> cGoogleFonts::search(const QString& family, const QString& subset, const Sort& sort) {
|
QList<cFontInfo> cGoogleFonts::search(const QString& family, const QString& subset, const Sort& sort) {
|
||||||
QNetworkAccessManager networkManager;
|
QNetworkAccessManager networkManager;
|
||||||
QString urlString = "https://www.googleapis.com/webfonts/v1/webfonts";
|
QString urlString = "https://www.googleapis.com/webfonts/v1/webfonts";
|
||||||
QUrlQuery query;
|
QUrlQuery query;
|
||||||
@@ -107,37 +107,37 @@ QList<cFont> cGoogleFonts::search(const QString& family, const QString& subset,
|
|||||||
QJsonDocument doc = QJsonDocument::fromJson(data);
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||||||
if(doc.isNull()) {
|
if(doc.isNull()) {
|
||||||
qDebug() << "Error: JSON return is empty";
|
qDebug() << "Error: JSON return is empty";
|
||||||
return QList<cFont>();
|
return QList<cFontInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!doc.isObject()) {
|
if(!doc.isObject()) {
|
||||||
qDebug() << "Error: invalid JSON";
|
qDebug() << "Error: invalid JSON";
|
||||||
return QList<cFont>();
|
return QList<cFontInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject root = doc.object();
|
QJsonObject root = doc.object();
|
||||||
|
|
||||||
if(!root.contains("items")) {
|
if(!root.contains("items")) {
|
||||||
qDebug() << "Error: no fonts found";
|
qDebug() << "Error: no fonts found";
|
||||||
return QList<cFont>();
|
return QList<cFontInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonValue itemsV = root.value("items");
|
QJsonValue itemsV = root.value("items");
|
||||||
if(!itemsV.isArray()) {
|
if(!itemsV.isArray()) {
|
||||||
qDebug() << "Error: no fonts found";
|
qDebug() << "Error: no fonts found";
|
||||||
return QList<cFont>();
|
return QList<cFontInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray items = itemsV.toArray();
|
QJsonArray items = itemsV.toArray();
|
||||||
|
|
||||||
if(!items.count())
|
if(!items.count())
|
||||||
return QList<cFont>();
|
return QList<cFontInfo>();
|
||||||
|
|
||||||
QList<cFont> fontList;
|
QList<cFontInfo> fontList;
|
||||||
|
|
||||||
foreach (const QJsonValue& item, items) {
|
foreach (const QJsonValue& item, items) {
|
||||||
if (item.isObject()) {
|
if (item.isObject()) {
|
||||||
cFont font;
|
cFontInfo font;
|
||||||
QJsonObject obj = item.toObject();
|
QJsonObject obj = item.toObject();
|
||||||
|
|
||||||
if(obj.contains("family"))
|
if(obj.contains("family"))
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ public:
|
|||||||
cGoogleFonts();
|
cGoogleFonts();
|
||||||
~cGoogleFonts() override;
|
~cGoogleFonts() override;
|
||||||
|
|
||||||
QString pluginAPIVersion() override;
|
QString pluginAPIVersion() override;
|
||||||
QString name() override;
|
QString name() override;
|
||||||
QString version() override;
|
QString version() override;
|
||||||
|
|
||||||
QList<cFont> search(const QString& family, const QString& subset = QString(), const Sort& sort = Sort::popularity) override;
|
QList<cFontInfo> search(const QString& family, const QString& subset = QString(), const Sort& sort = Sort::popularity) override;
|
||||||
private:
|
private:
|
||||||
QString m_key;
|
QString m_key;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CGOOGLEFONTS_H
|
#endif //CGOOGLEFONTS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user