Krita Source Code Documentation
Loading...
Searching...
No Matches
KisQQuickWidget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hovell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#include "KisQQuickWidget.h"
7
8
9#include <QQmlEngine>
10#include <QQmlContext>
11#include <QQuickStyle>
12#include <QQuickItem>
13#include <QQmlFileSelector>
14#include <QFileSelector>
15
16#include <KLocalizedContext>
17
18#include <KoResourcePaths.h>
20#include <kis_config_notifier.h>
21
22KisQQuickWidget::KisQQuickWidget(QWidget *parent): QQuickWidget(parent)
23{
24#if !defined(Q_OS_MACOS) || QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
25 QSurfaceFormat format;
26
27 {
33 format.setRedBufferSize(8);
34 format.setGreenBufferSize(8);
35 format.setBlueBufferSize(8);
36 format.setAlphaBufferSize(8);
38 }
39
40 setFormat(format);
41#endif
42
43 engine()->rootContext()->setContextProperty("mainWindow", parent);
44 engine()->rootContext()->setContextObject(new KLocalizedContext(parent));
45
46 // Clear color is the 'default background color', which, in qwidget context is the window bg.
47 setClearColor(palette().window().color());
48 connect(KisConfigNotifier::instance(), SIGNAL(signalColorThemeChanged(QString)), this, SLOT(updatePaletteFromConfig()));
49
50 // Default to fusion style unless the user forces another style
51 const QString fusion = "Fusion";
52 if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE") && QQuickStyle::name() != fusion) {
53 QQuickStyle::setStyle(fusion);
54 }
55
56 engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");
57 engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");
58
59 engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");
60 engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");
61
62 QQmlFileSelector* selector = new QQmlFileSelector(engine());
63 QStringList extraSelectors;
64 /*
65 * This allows for Style specific components, which it'll load from
66 * a "+StyleName" folder.
67 */
68 extraSelectors << QQuickStyle::name();
69#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
70 extraSelectors << "qt6";
71#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
72 extraSelectors << "qt5";
73#endif
78 extraSelectors << "qquickwidget";
79
80 selector->setExtraSelectors(extraSelectors);
81
82
83 setResizeMode(QQuickWidget::SizeRootObjectToView);
84}
85
87{
92 setParent(nullptr);
93}
94
96{
97 if (rootObject()) {
98 connect(rootObject(), SIGNAL(implicitHeightChanged()), this, SLOT(setMinimumHeightFromRoot()));
100 }
101}
102
104{
105 if (rootObject()) {
106 connect(rootObject(), SIGNAL(implicitWidthChanged()), this, SLOT(setMinimumWidthFromRoot()));
108 }
109}
110
112{
113 setClearColor(palette().window().color());
114}
115
117{
118 if (rootObject()) {
119 setMinimumHeight(rootObject()->implicitHeight());
120 }
121}
122
124{
125 if (rootObject()) {
126 setMinimumWidth(rootObject()->implicitWidth());
127 }
128}
static KisConfigNotifier * instance()
void connectMinimumWidthToRootObject()
connectMinimumWidthToRootObject Same as for connectMinimumHeightToRootObject, but then for width.
KisQQuickWidget(QWidget *parent=nullptr)
void connectMinimumHeightToRootObject()
connectMinimumHeightToRootObject By default we scale rootObject to widget, but in some situations we ...
static constexpr KisSurfaceColorSpaceWrapper makeSRGBColorSpace()
static QString getApplicationRoot()
rgba palette[MAX_PALETTE]
Definition palette.c:35