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++
Split out qquick widget configuration into its own KisQQuickWidget.
Wolthera van Hövell tot Westerflier6d8869de0b87
diff --git a/plugins/dockers/textproperties/CMakeLists.txt b/plugins/dockers/textproperties/CMakeLists.txtindex c1d1154aaf..2db43cf7c6 100644--- a/plugins/dockers/textproperties/CMakeLists.txt+++ b/plugins/dockers/textproperties/CMakeLists.txt@@ -18,6 +18,7 @@ qt_add_resources(KRITA_TEXTPROPERTIES_SOURCES textproperties.qrc)kis_add_library(kritatextproperties MODULE ${KRITA_TEXTPROPERTIES_SOURCES})target_link_libraries(kritatextpropertieskritaui+ kritaqmlwidgetsQt${QT_MAJOR_VERSION}::QuickQt${QT_MAJOR_VERSION}::QuickWidgetsQt${QT_MAJOR_VERSION}::QuickControls2diff --git a/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp b/plugins/dockers/textproperties/CssStylePresetEditDialog.cppindex 5e8c8e9fb6..0fe187a310 100644--- a/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp+++ b/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp@@ -28,17 +28,9 @@ CssStylePresetEditDialog::CssStylePresetEditDialog(QWidget *parent)setMinimumSize(300, 500);setModal(true);- m_quickWidget = new QQuickWidget(this);+ m_quickWidget = new KisQQuickWidget(this);this->setMainWidget(m_quickWidget);m_quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);- m_quickWidget->engine()->rootContext()->setContextProperty("mainWindow", this);- m_quickWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(this));-- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");-- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");m_quickWidget->setPalette(this->palette());this->setWindowTitle(i18nc("@title:window", "Edit Style Preset"));@@ -55,7 +47,6 @@ CssStylePresetEditDialog::CssStylePresetEditDialog(QWidget *parent)connect(m_model, SIGNAL(textPropertyChanged()),this, SLOT(slotUpdateTextProperties()));- m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);m_quickWidget->setSource(QUrl("qrc:/CssStylePresetEdit.qml"));if (!m_quickWidget->errors().empty()) {@@ -65,11 +56,6 @@ CssStylePresetEditDialog::CssStylePresetEditDialog(QWidget *parent)CssStylePresetEditDialog::~CssStylePresetEditDialog(){- /// Prevent accessing destroyed objects in QML engine- /// See:- /// * https://invent.kde.org/graphics/krita/-/commit/d8676f4e9cac1a8728e73fec3ff1df1763c713b7- /// * https://bugreports.qt.io/browse/QTBUG-81247- m_quickWidget->setParent(nullptr);delete m_quickWidget;}diff --git a/plugins/dockers/textproperties/CssStylePresetEditDialog.h b/plugins/dockers/textproperties/CssStylePresetEditDialog.hindex 31d615ab5b..c1ce49dd69 100644--- a/plugins/dockers/textproperties/CssStylePresetEditDialog.h+++ b/plugins/dockers/textproperties/CssStylePresetEditDialog.h@@ -9,7 +9,7 @@#include <QObject>#include <KoDialog.h>#include <resources/KoCssStylePreset.h>-#include <QQuickWidget>+#include <KisQQuickWidget.h>#include <lager/KoSvgTextPropertiesModel.h>class CssStylePresetEditDialog : public KoDialog@@ -32,7 +32,7 @@ public Q_SLOTS:void slotUpdateStoreDPI();private:- QQuickWidget *m_quickWidget {0};+ KisQQuickWidget *m_quickWidget {0};KoSvgTextPropertiesModel *m_model;KoCssStylePresetSP m_currentResource;bool m_blockUpdates {false};diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cppindex 8e59c3df2d..ef18834c67 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp@@ -16,13 +16,15 @@#include <QQuickStyle>#include <QColorDialog>+#include <KisQQuickWidget.h>+#include <KisViewManager.h>#include <kis_canvas_resource_provider.h>#include <KisStaticInitializer.h>#include <KLocalizedContext>-#include <KoResourcePaths.h>+#include <KisResourceModel.h>#include <KisResourceModelProvider.h>#include <KisTagModel.h>@@ -53,7 +55,6 @@#include "LocaleHandler.h"#include "CssQmlUnitConverter.h"#include "TextPropertyConfigModel.h"-#include <KisSurfaceColorSpaceWrapper.h>#include "TextPropertyConfigDialog.h"#include "CssStylePresetEditDialog.h"@@ -104,43 +105,11 @@ TextPropertiesDock::TextPropertiesDock(): QDockWidget(i18n("Text Properties")), d(new Private(this)){- m_quickWidget = new QQuickWidget(this);--#if !defined(Q_OS_MACOS) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)- QSurfaceFormat format;-- {- /**- * Our version of Qt has a special handling of the color- * space passed to the surface of the QQuickWidget. It will- * allow it to render correctly on a Rec2020PQ window.- */- format.setRedBufferSize(8);- format.setGreenBufferSize(8);- format.setBlueBufferSize(8);- format.setAlphaBufferSize(8);- format.setColorSpace(KisSurfaceColorSpaceWrapper::makeSRGBColorSpace());- }+ m_quickWidget = new KisQQuickWidget(this);- m_quickWidget->setFormat(format);-#endifsetWidget(m_quickWidget);setEnabled(true);- m_quickWidget->engine()->rootContext()->setContextProperty("mainWindow", this);- m_quickWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(this));-- // Default to fusion style unless the user forces another style- if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {- QQuickStyle::setStyle(QStringLiteral("Fusion"));- }-- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");-- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");-m_quickWidget->setMinimumHeight(100);d->textPropertyConfigModel = new TextPropertyConfigModel(this);@@ -159,7 +128,6 @@ TextPropertiesDock::TextPropertiesDock()connect(d->textModel, SIGNAL(textPropertyChanged()),&d->modelToProviderCompressor, SLOT(start()));connect(&d->modelToProviderCompressor, SIGNAL(timeout()), this, SLOT(slotTextPropertiesChanged()));- m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);m_quickWidget->setSource(QUrl("qrc:/TextProperties.qml"));m_quickWidget->setPalette(this->palette());@@ -167,11 +135,6 @@ TextPropertiesDock::TextPropertiesDock()TextPropertiesDock::~TextPropertiesDock(){- /// Prevent accessing destroyed objects in QML engine- /// See:- /// * https://invent.kde.org/graphics/krita/-/commit/d8676f4e9cac1a8728e73fec3ff1df1763c713b7- /// * https://bugreports.qt.io/browse/QTBUG-81247- m_quickWidget->setParent(nullptr);delete m_quickWidget;}diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.hindex 756de33cad..f4bfbcaf09 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.h+++ b/plugins/dockers/textproperties/TextPropertiesDock.h@@ -15,7 +15,7 @@#include <KoResource.h>class KoDialog;-class QQuickWidget;+class KisQQuickWidget;class KoSvgTextProperties;class TextPropertiesDock : public QDockWidget, public KisMainwindowObserver {@@ -46,7 +46,7 @@ public Q_SLOTS:private:QPointer<KisCanvas2> m_canvas;- QQuickWidget *m_quickWidget {0};+ KisQQuickWidget *m_quickWidget {0};struct Private;const QScopedPointer<Private> d;diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txtindex c6618883a6..393e3c74f6 100644--- a/plugins/tools/svgtexttool/CMakeLists.txt+++ b/plugins/tools/svgtexttool/CMakeLists.txt@@ -52,6 +52,7 @@ generate_export_header(krita_tool_svgtext_static BASE_NAME kritatoolsvgtext)target_link_libraries(krita_tool_svgtext_statickritaui+ kritaqmlwidgetsQt${QT_MAJOR_VERSION}::QuickQt${QT_MAJOR_VERSION}::QuickWidgetsQt${QT_MAJOR_VERSION}::QuickControls2diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cppindex cf85bd684e..7c2625236f 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cpp+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cpp@@ -17,7 +17,7 @@ GlyphPaletteAltPopup::GlyphPaletteAltPopup(QWidget *parent){setWindowFlags(Qt::Popup);setFrameStyle(QFrame::Box | QFrame::Plain);- m_quickWidget = new QQuickWidget(this);+ m_quickWidget = new KisQQuickWidget(this);QHBoxLayout *layout = new QHBoxLayout(this);m_quickWidget->setFixedSize(300, 400);@@ -29,18 +29,9 @@ GlyphPaletteAltPopup::GlyphPaletteAltPopup(QWidget *parent)layout->setSizeConstraint(QLayout::SizeConstraint::SetFixedSize);m_quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);- m_quickWidget->engine()->rootContext()->setContextProperty("mainWindow", this);- m_quickWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(this));-- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");-- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");m_quickWidget->setPalette(this->palette());- m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);m_quickWidget->setSource(QUrl("qrc:/GlyphPaletteAlts.qml"));if (!m_quickWidget->errors().empty()) {qWarning() << "Errors in " << windowTitle() << ":" << m_quickWidget->errors();diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.hindex 92747eac3c..f4824298b6 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.h+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.h@@ -7,7 +7,7 @@#define GLYPHPALETTEALTPOPUP_H#include <QFrame>-#include <QQuickWidget>+#include <KisQQuickWidget.h>#include <QAbstractItemModel>/**@@ -54,7 +54,7 @@ public Q_SLOTS:Q_SIGNALS:void sigInsertRichText(int charRow, int glyphRow, bool replace, bool useCharMap);private:- QQuickWidget *m_quickWidget {0};+ KisQQuickWidget *m_quickWidget {0};QAbstractItemModel *m_charMapModel {0};};diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cppindex 388857fbeb..e4d80ea058 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp@@ -25,23 +25,9 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent){setMinimumSize(500, 300);- m_quickWidget = new QQuickWidget(this);+ m_quickWidget = new KisQQuickWidget(this);this->setMainWidget(m_quickWidget);m_quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);- m_quickWidget->engine()->rootContext()->setContextProperty("mainWindow", this);- m_quickWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(this));-- /*- // Default to fusion style unless the user forces another style- if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {- QQuickStyle::setStyle(QStringLiteral("Fusion"));- }- */- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");-- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");- m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");m_quickWidget->setPalette(this->palette());this->setWindowTitle(i18nc("@title:window", "Glyph Palette"));@@ -53,7 +39,6 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)m_quickWidget->rootContext()->setContextProperty("glyphModel", QVariant::fromValue(m_model));m_quickWidget->rootContext()->setContextProperty("charMapProxyModel", QVariant::fromValue(m_charMapModel));- m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);m_quickWidget->setSource(QUrl("qrc:/GlyphPalette.qml"));if (!m_quickWidget->errors().empty()) {qWarning() << "Errors in " << windowTitle() << ":" << m_quickWidget->errors();@@ -63,12 +48,6 @@ GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent)GlyphPaletteDialog::~GlyphPaletteDialog(){-- /// Prevent accessing destroyed objects in QML engine- /// See:- /// * https://invent.kde.org/graphics/krita/-/commit/d8676f4e9cac1a8728e73fec3ff1df1763c713b7- /// * https://bugreports.qt.io/browse/QTBUG-81247- m_quickWidget->setParent(nullptr);delete m_quickWidget;}diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.hindex bff1a911cb..09b175821d 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h@@ -7,7 +7,7 @@#define GLYPHPALETTEDIALOG_H#include <KoDialog.h>-#include <QtQuickWidgets/QQuickWidget>+#include <KisQQuickWidget.h>#include <KoSvgTextProperties.h>#include <KoFontGlyphModel.h>@@ -49,7 +49,7 @@ public Q_SLOTS:void slotHidePopupPalette();private:- QQuickWidget *m_quickWidget {0};+ KisQQuickWidget *m_quickWidget {0};GlyphPaletteAltPopup *m_altPopup {0};QPair<KoSvgTextProperties, KoSvgTextProperties> m_lastUsedProperties;KoFontGlyphModel *m_model;diff --git a/qmlmodules/CMakeLists.txt b/qmlmodules/CMakeLists.txtindex 3c357135a2..eb472f5d40 100644--- a/qmlmodules/CMakeLists.txt+++ b/qmlmodules/CMakeLists.txt@@ -1 +1,2 @@add_subdirectory(components)+add_subdirectory(widgets)diff --git a/qmlmodules/widgets/CMakeLists.txt b/qmlmodules/widgets/CMakeLists.txtnew file mode 100644index 0000000000..4a7d7b26a7--- /dev/null+++ b/qmlmodules/widgets/CMakeLists.txt@@ -0,0 +1,22 @@+set(kritaqmlwidgets_SRCS+ KisQQuickWidget.cpp+)++kis_add_library(kritaqmlwidgets SHARED ${kritaqmlwidgets_SRCS})+generate_export_header(kritaqmlwidgets)++target_link_libraries(kritaqmlwidgets+ PRIVATE+ kritaui+ Qt::Qml+ Qt::Quick+ Qt::QuickWidgets+ Qt::QuickControls2+)++set_target_properties(kritaqmlwidgets PROPERTIES+ VERSION ${GENERIC_KRITA_LIB_VERSION}+ SOVERSION ${GENERIC_KRITA_LIB_SOVERSION}+)++install(TARGETS kritaqmlwidgets ${INSTALL_TARGETS_DEFAULT_ARGS})diff --git a/qmlmodules/widgets/KisQQuickWidget.cpp b/qmlmodules/widgets/KisQQuickWidget.cppnew file mode 100644index 0000000000..9f20c4057e--- /dev/null+++ b/qmlmodules/widgets/KisQQuickWidget.cpp@@ -0,0 +1,65 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hovell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KisQQuickWidget.h"+++#include <QQmlEngine>+#include <QQmlContext>+#include <QQuickStyle>++#include <KLocalizedContext>++#include <KoResourcePaths.h>+#include <KisSurfaceColorSpaceWrapper.h>++KisQQuickWidget::KisQQuickWidget(QWidget *parent): QQuickWidget(parent)+{+#if !defined(Q_OS_MACOS) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)+ QSurfaceFormat format;++ {+ /**+ * Our version of Qt has a special handling of the color+ * space passed to the surface of the QQuickWidget. It will+ * allow it to render correctly on a Rec2020PQ window.+ */+ format.setRedBufferSize(8);+ format.setGreenBufferSize(8);+ format.setBlueBufferSize(8);+ format.setAlphaBufferSize(8);+ format.setColorSpace(KisSurfaceColorSpaceWrapper::makeSRGBColorSpace());+ }++ setFormat(format);+#endif++ engine()->rootContext()->setContextProperty("mainWindow", parent);+ engine()->rootContext()->setContextObject(new KLocalizedContext(parent));++ // Default to fusion style unless the user forces another style+ const QString fusion = "Fusion";+ if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE") && QQuickStyle::name() != fusion) {+ QQuickStyle::setStyle(fusion);+ }++ engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");+ engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");++ engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");+ engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");+++ setResizeMode(QQuickWidget::SizeRootObjectToView);+}++KisQQuickWidget::~KisQQuickWidget()+{+ /// Prevent accessing destroyed objects in QML engine+ /// See:+ /// * https://invent.kde.org/graphics/krita/-/commit/d8676f4e9cac1a8728e73fec3ff1df1763c713b7+ /// * https://bugreports.qt.io/browse/QTBUG-81247+ setParent(nullptr);+}diff --git a/qmlmodules/widgets/KisQQuickWidget.h b/qmlmodules/widgets/KisQQuickWidget.hnew file mode 100644index 0000000000..53ac0ebec4--- /dev/null+++ b/qmlmodules/widgets/KisQQuickWidget.h@@ -0,0 +1,29 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hovell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISQQUICKWIDGET_H+#define KISQQUICKWIDGET_H++#include <QQuickWidget>+#include <kritaqmlwidgets_export.h>++/**+ * @brief The KisQQuickWidget class+ *+ * The purpose of KisQQuickWidget is to tackle a number of configuration steps+ * that need to be taken when using the QQuickWidget, amongst which the setup+ * of the engine.+ */++class KRITAQMLWIDGETS_EXPORT KisQQuickWidget : public QQuickWidget+{+ Q_OBJECT+public:+ KisQQuickWidget(QWidget *parent = nullptr);++ ~KisQQuickWidget();+};++#endif // KISQQUICKWIDGET_H