diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2022-03-22 17:52:20 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2022-03-23 12:55:08 +0100 |
commit | ee2c772555736f6d6aeaafc44b449ce81a229c67 (patch) | |
tree | b3360fbfe5ca172b98f691e49e3821328457e710 | |
parent | 5180c1b627bd5c3ce976f126f7c195bc8b6fd2b1 (diff) |
Add QtQuick.Studio.StudioApplication
This class allows loading fonts into the application "in time".
This will replace the DirectoryFontLoader
Task-number: QDS-1142
Change-Id: Ibc801b8450f503af4b964740d0b009222c21b9b7
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r-- | src/imports/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/imports/application/CMakeLists.txt | 17 | ||||
-rw-r--r-- | src/imports/application/quickstudioapplication.cpp | 69 | ||||
-rw-r--r-- | src/imports/application/quickstudioapplication_p.h | 83 | ||||
-rw-r--r-- | sync.profile | 5 |
5 files changed, 175 insertions, 0 deletions
diff --git a/src/imports/CMakeLists.txt b/src/imports/CMakeLists.txt index d04b9f4..87c84b8 100644 --- a/src/imports/CMakeLists.txt +++ b/src/imports/CMakeLists.txt @@ -5,4 +5,5 @@ add_subdirectory(flowview) add_subdirectory(logichelper) add_subdirectory(multitext) add_subdirectory(tools) +add_subdirectory(application) diff --git a/src/imports/application/CMakeLists.txt b/src/imports/application/CMakeLists.txt new file mode 100644 index 0000000..175a85f --- /dev/null +++ b/src/imports/application/CMakeLists.txt @@ -0,0 +1,17 @@ +##################################################################### +## QuickStudioApplicationModule: +##################################################################### + +qt_internal_add_qml_module(QuickStudioApplication + URI "QtQuick.Studio.Application" + VERSION "${PROJECT_VERSION}" + DESIGNER_SUPPORTED + PAST_MAJOR_VERSIONS 1 + INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR} + SOURCES + quickstudioapplication.cpp quickstudioapplication_p.h + PUBLIC_LIBRARIES + Qt::Qml + Qt::Quick +) diff --git a/src/imports/application/quickstudioapplication.cpp b/src/imports/application/quickstudioapplication.cpp new file mode 100644 index 0000000..c1f3cf5 --- /dev/null +++ b/src/imports/application/quickstudioapplication.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Dialogs module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quickstudioapplication_p.h" + +#include <QDir> +#include <QDirIterator> +#include <QFontDatabase> +#include <QLoggingCategory> + +QT_BEGIN_NAMESPACE + +static Q_LOGGING_CATEGORY(texttomodelMergerDebug, "qt.Studioapplication.debug", QtDebugMsg) + +QuickStudioApplication::QuickStudioApplication(QObject *parent) : QObject(parent) {} + +static void loadFont(const QString &path) +{ + qCInfo(texttomodelMergerDebug) << Q_FUNC_INFO << "Load font: " << path; + QFontDatabase::addApplicationFont(path); +} + +void QuickStudioApplication::setFontPath(const QUrl &path) { + if (path == fontPath()) + return; + + m_fontPath = path; + + QDirIterator it(path.toLocalFile(), {QStringLiteral("*.ttf"), QStringLiteral("*.otf") }, QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) + loadFont(it.next()); + + emit fontPathChanged(); +} + +QT_END_NAMESPACE diff --git a/src/imports/application/quickstudioapplication_p.h b/src/imports/application/quickstudioapplication_p.h new file mode 100644 index 0000000..a8c46ab --- /dev/null +++ b/src/imports/application/quickstudioapplication_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Dialogs module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QUICKSTUDIOAPPLICATION_P_H +#define QUICKSTUDIOAPPLICATION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qurl.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +class QuickStudioApplication : public QObject +{ + Q_OBJECT + + QML_NAMED_ELEMENT(StudioApplication) + QML_ADDED_IN_VERSION(6, 2) + + Q_PROPERTY(QUrl fontPath READ fontPath WRITE setFontPath NOTIFY fontPathChanged) + +public: + explicit QuickStudioApplication(QObject *parent = nullptr); + + const QUrl fontPath() { return m_fontPath; } + void setFontPath(const QUrl &path); + +signals: + void fontPathChanged(); + +private: + QUrl m_fontPath; + +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QuickStudioApplication) + +#endif // QUICKSTUDIOAPPLICATION_P_H diff --git a/sync.profile b/sync.profile new file mode 100644 index 0000000..73fa0db --- /dev/null +++ b/sync.profile @@ -0,0 +1,5 @@ +%modules = ( # path to module name map + "QtQuickStudioApplication" => "$basedir/src/imports/application", +); +%moduleheaders = ( # restrict the module headers to those found in relative path +); |