forked from qt-creator/qt-creator
QmlPuppet: Register fonts at scene creation
Automatically register all fonts from 'fonts' folder at scene creation. Fixes: QDS-3624 Change-Id: I38728e458952ea52c941244daaca715102a93c55 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -41,6 +41,7 @@ QDebug operator <<(QDebug debug, const CreateSceneCommand &command)
|
||||
<< "imports: " << command.imports << ", "
|
||||
<< "mockupTypes: " << command.mockupTypes << ", "
|
||||
<< "fileUrl: " << command.fileUrl << ", "
|
||||
<< "resourceUrl: " << command.resourceUrl << ", "
|
||||
<< "edit3dToolStates: " << command.edit3dToolStates << ", "
|
||||
<< "language: " << command.language << ")";
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
const QVector<AddImportContainer> &importVector,
|
||||
const QVector<MockupTypeContainer> &mockupTypeVector,
|
||||
const QUrl &fileUrl,
|
||||
const QUrl &resourceUrl,
|
||||
const QHash<QString, QVariantMap> &edit3dToolStates,
|
||||
const QString &language,
|
||||
qint32 stateInstanceId)
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
, imports(importVector)
|
||||
, mockupTypes(mockupTypeVector)
|
||||
, fileUrl(fileUrl)
|
||||
, resourceUrl(resourceUrl)
|
||||
, edit3dToolStates(edit3dToolStates)
|
||||
, language(language)
|
||||
, stateInstanceId{stateInstanceId}
|
||||
@@ -80,6 +82,7 @@ public:
|
||||
out << command.imports;
|
||||
out << command.mockupTypes;
|
||||
out << command.fileUrl;
|
||||
out << command.resourceUrl;
|
||||
out << command.edit3dToolStates;
|
||||
out << command.language;
|
||||
out << command.stateInstanceId;
|
||||
@@ -98,6 +101,7 @@ public:
|
||||
in >> command.imports;
|
||||
in >> command.mockupTypes;
|
||||
in >> command.fileUrl;
|
||||
in >> command.resourceUrl;
|
||||
in >> command.edit3dToolStates;
|
||||
in >> command.language;
|
||||
in >> command.stateInstanceId;
|
||||
@@ -115,6 +119,7 @@ public:
|
||||
QVector<AddImportContainer> imports;
|
||||
QVector<MockupTypeContainer> mockupTypes;
|
||||
QUrl fileUrl;
|
||||
QUrl resourceUrl;
|
||||
QHash<QString, QVariantMap> edit3dToolStates;
|
||||
QString language;
|
||||
qint32 stateInstanceId = 0;
|
||||
|
||||
@@ -88,6 +88,9 @@
|
||||
#include <QUrl>
|
||||
#include <QVariant>
|
||||
#include <qqmllist.h>
|
||||
#include <QFontDatabase>
|
||||
#include <QFileInfo>
|
||||
#include <QDirIterator>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -322,6 +325,7 @@ void NodeInstanceServer::stopRenderTimer()
|
||||
|
||||
void NodeInstanceServer::createScene(const CreateSceneCommand &command)
|
||||
{
|
||||
registerFonts(command.resourceUrl);
|
||||
setTranslationLanguage(command.language);
|
||||
initializeView();
|
||||
|
||||
@@ -1502,4 +1506,13 @@ void NodeInstanceServer::setupState(qint32 stateInstanceId)
|
||||
}
|
||||
}
|
||||
|
||||
void NodeInstanceServer::registerFonts(const QUrl &resourceUrl) const
|
||||
{
|
||||
// Autoregister all fonts found inside the project
|
||||
QDirIterator it {QFileInfo(resourceUrl.toLocalFile()).absoluteFilePath(),
|
||||
{"*.ttf", "*.otf"}, QDir::Files, QDirIterator::Subdirectories};
|
||||
while (it.hasNext())
|
||||
QFontDatabase::addApplicationFont(it.next());
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -298,6 +298,7 @@ protected:
|
||||
|
||||
virtual void resizeCanvasToRootItem() = 0;
|
||||
void setupState(qint32 stateInstanceId);
|
||||
void registerFonts(const QUrl &resourceUrl) const;
|
||||
|
||||
private:
|
||||
void setupOnlyWorkingImports(const QStringList &workingImportStatementList);
|
||||
|
||||
@@ -46,6 +46,7 @@ Qt5PreviewNodeInstanceServer::Qt5PreviewNodeInstanceServer(NodeInstanceClientInt
|
||||
|
||||
void Qt5PreviewNodeInstanceServer::createScene(const CreateSceneCommand &command)
|
||||
{
|
||||
registerFonts(command.resourceUrl);
|
||||
setTranslationLanguage(command.language);
|
||||
initializeView();
|
||||
setupScene(command);
|
||||
|
||||
@@ -1071,6 +1071,12 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
|
||||
importVector,
|
||||
mockupTypesVector,
|
||||
model()->fileUrl(),
|
||||
#ifndef QMLDESIGNER_TEST
|
||||
QUrl::fromLocalFile(QmlDesigner::DocumentManager::currentResourcePath()
|
||||
.toFileInfo().absoluteFilePath()),
|
||||
#else
|
||||
QUrl::fromLocalFile(QFileInfo(model()->fileUrl().toLocalFile()).absolutePath()),
|
||||
#endif
|
||||
m_edit3DToolStates[model()->fileUrl()],
|
||||
lastUsedLanguage,
|
||||
stateInstanceId);
|
||||
|
||||
Reference in New Issue
Block a user