forked from qt-creator/qt-creator
QmlDesigner: Add StudioQuickWidget
This makes it easy to share the QQmlEngine between different QQuickWidgets. All StudioQuickWidgets share the same engine. Change-Id: I2b370a45a14fdc143e161e2aca62b45aa0d91da9 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
9e2926c537
commit
f681b696e9
@@ -1,5 +1,5 @@
|
||||
add_qtc_plugin(QmlDesignerBase
|
||||
DEPENDS Qt::Core
|
||||
DEPENDS Qt::Core Qt::QuickWidgets
|
||||
PLUGIN_DEPENDS Core ProjectExplorer QtSupport
|
||||
SOURCES
|
||||
qmldesignerbase_global.h
|
||||
@@ -12,4 +12,5 @@ extend_qtc_plugin(QmlDesignerBase
|
||||
SOURCES
|
||||
designersettings.cpp designersettings.h
|
||||
qmlpuppetpaths.cpp qmlpuppetpaths.h
|
||||
studioquickwidget.cpp studioquickwidget.h
|
||||
)
|
||||
|
@@ -1,6 +1,8 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../qmldesignerbase_global.h"
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
60
src/plugins/qmldesignerbase/utils/studioquickwidget.cpp
Normal file
60
src/plugins/qmldesignerbase/utils/studioquickwidget.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "studioquickwidget.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QtQml/QQmlEngine>
|
||||
|
||||
QQmlEngine *s_engine = nullptr;
|
||||
|
||||
StudioQuickWidget::StudioQuickWidget(QWidget *parent)
|
||||
: QWidget{parent}
|
||||
{
|
||||
if (!s_engine)
|
||||
s_engine = new QQmlEngine;
|
||||
|
||||
m_quickWidget = new QQuickWidget(s_engine, this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(m_quickWidget);
|
||||
}
|
||||
|
||||
QQmlEngine *StudioQuickWidget::engine() const
|
||||
{
|
||||
return m_quickWidget->engine();
|
||||
}
|
||||
|
||||
QQmlContext *StudioQuickWidget::rootContext() const
|
||||
{
|
||||
return m_quickWidget->rootContext();
|
||||
}
|
||||
|
||||
QQuickItem *StudioQuickWidget::rootObject() const
|
||||
{
|
||||
return m_quickWidget->rootObject();
|
||||
}
|
||||
|
||||
void StudioQuickWidget::setResizeMode(QQuickWidget::ResizeMode mode)
|
||||
{
|
||||
m_quickWidget->setResizeMode(mode);
|
||||
}
|
||||
|
||||
void StudioQuickWidget::setSource(const QUrl &url)
|
||||
{
|
||||
m_quickWidget->setSource(url);
|
||||
}
|
||||
|
||||
void StudioQuickWidget::refresh() {}
|
||||
|
||||
void StudioQuickWidget::setClearColor(const QColor &color)
|
||||
{
|
||||
m_quickWidget->setClearColor(color);
|
||||
}
|
||||
|
||||
QList<QQmlError> StudioQuickWidget::errors() const
|
||||
{
|
||||
return m_quickWidget->errors();
|
||||
}
|
34
src/plugins/qmldesignerbase/utils/studioquickwidget.h
Normal file
34
src/plugins/qmldesignerbase/utils/studioquickwidget.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../qmldesignerbase_global.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQuickWidgets/QQuickWidget>
|
||||
|
||||
class QMLDESIGNERBASE_EXPORT StudioQuickWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StudioQuickWidget(QWidget *parent = nullptr);
|
||||
|
||||
QQmlEngine *engine() const;
|
||||
QQmlContext *rootContext() const;
|
||||
|
||||
QQuickItem *rootObject() const;
|
||||
|
||||
void setResizeMode(QQuickWidget::ResizeMode mode);
|
||||
|
||||
void setSource(const QUrl &url);
|
||||
|
||||
void refresh();
|
||||
|
||||
void setClearColor(const QColor &color);
|
||||
|
||||
QList<QQmlError> errors() const;
|
||||
|
||||
private:
|
||||
QQuickWidget *m_quickWidget = nullptr;
|
||||
};
|
Reference in New Issue
Block a user