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
74 selector->setExtraSelectors(extraSelectors);
75
76
77 setResizeMode(QQuickWidget::SizeRootObjectToView);
78}
79
81{
86 setParent(nullptr);
87}
88
90{
91 if (rootObject()) {
92 connect(rootObject(), SIGNAL(implicitHeightChanged()), this, SLOT(setMinimumHeightFromRoot()));
94 }
95}
96
98{
99 if (rootObject()) {
100 connect(rootObject(), SIGNAL(implicitWidthChanged()), this, SLOT(setMinimumWidthFromRoot()));
102 }
103}
104
106{
107 setClearColor(palette().window().color());
108}
109
111{
112 if (rootObject()) {
113 setMinimumHeight(rootObject()->implicitHeight());
114 }
115}
116
118{
119 if (rootObject()) {
120 setMinimumWidth(rootObject()->implicitWidth());
121 }
122}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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