forked from qt-creator/qt-creator
QmlDesigner: Add onboarding text to 3D edit view when there is no 3D
Change-Id: If9513da39efcc19129de6867ea7357bc6c0e2af4 Fixes: QDS-1748 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -36,9 +36,10 @@
|
|||||||
#include <qmldesignerconstants.h>
|
#include <qmldesignerconstants.h>
|
||||||
#include <viewmanager.h>
|
#include <viewmanager.h>
|
||||||
#include <qmldesignericons.h>
|
#include <qmldesignericons.h>
|
||||||
|
#include <designmodecontext.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <designmodecontext.h>
|
#include <coreplugin/messagebox.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -62,6 +63,20 @@ void Edit3DView::createEdit3DWidget()
|
|||||||
Core::ICore::addContextObject(editor3DContext);
|
Core::ICore::addContextObject(editor3DContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Edit3DView::checkImports()
|
||||||
|
{
|
||||||
|
bool has3dImport = false;
|
||||||
|
const QList<Import> imports = model()->imports();
|
||||||
|
for (const auto &import : imports) {
|
||||||
|
if (import.url() == "QtQuick3D") {
|
||||||
|
has3dImport = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
edit3DWidget()->showCanvas(has3dImport);
|
||||||
|
}
|
||||||
|
|
||||||
WidgetInfo Edit3DView::widgetInfo()
|
WidgetInfo Edit3DView::widgetInfo()
|
||||||
{
|
{
|
||||||
if (!m_edit3DWidget)
|
if (!m_edit3DWidget)
|
||||||
@@ -130,13 +145,30 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState)
|
|||||||
m_editLightAction->action()->setChecked(false);
|
m_editLightAction->action()->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Edit3DView::modelAttached(Model *model)
|
||||||
|
{
|
||||||
|
AbstractView::modelAttached(model);
|
||||||
|
|
||||||
|
checkImports();
|
||||||
|
}
|
||||||
|
|
||||||
void Edit3DView::modelAboutToBeDetached(Model *model)
|
void Edit3DView::modelAboutToBeDetached(Model *model)
|
||||||
{
|
{
|
||||||
Q_UNUSED(model)
|
Q_UNUSED(model)
|
||||||
|
|
||||||
// Clear the image when model is detached (i.e. changing documents)
|
// Hide the canvas when model is detached (i.e. changing documents)
|
||||||
QImage emptyImage;
|
edit3DWidget()->showCanvas(false);
|
||||||
edit3DWidget()->canvas()->updateRenderImage(emptyImage);
|
|
||||||
|
AbstractView::modelAboutToBeDetached(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Edit3DView::importsChanged(const QList<Import> &addedImports,
|
||||||
|
const QList<Import> &removedImports)
|
||||||
|
{
|
||||||
|
Q_UNUSED(addedImports)
|
||||||
|
Q_UNUSED(removedImports)
|
||||||
|
|
||||||
|
checkImports();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Edit3DView::sendInputEvent(QInputEvent *e) const
|
void Edit3DView::sendInputEvent(QInputEvent *e) const
|
||||||
@@ -266,5 +298,21 @@ QVector<Edit3DAction *> Edit3DView::rightActions() const
|
|||||||
return m_rightActions;
|
return m_rightActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Edit3DView::addQuick3DImport()
|
||||||
|
{
|
||||||
|
const QList<Import> imports = model()->possibleImports();
|
||||||
|
for (const auto &import : imports) {
|
||||||
|
if (import.url() == "QtQuick3D") {
|
||||||
|
model()->changeImports({import}, {});
|
||||||
|
|
||||||
|
// Subcomponent manager update needed to make item library entries appear
|
||||||
|
QmlDesignerPlugin::instance()->currentDesignDocument()->updateSubcomponentManager();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Core::AsynchronousMessageBox::warning(tr("Failed to Add Import"),
|
||||||
|
tr("Could not add QtQuick3D import to project."));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ public:
|
|||||||
|
|
||||||
void renderImage3DChanged(const QImage &img) override;
|
void renderImage3DChanged(const QImage &img) override;
|
||||||
void updateActiveScene3D(const QVariantMap &sceneState) override;
|
void updateActiveScene3D(const QVariantMap &sceneState) override;
|
||||||
|
void modelAttached(Model *model) override;
|
||||||
void modelAboutToBeDetached(Model *model) override;
|
void modelAboutToBeDetached(Model *model) override;
|
||||||
|
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports) override;
|
||||||
|
|
||||||
void sendInputEvent(QInputEvent *e) const;
|
void sendInputEvent(QInputEvent *e) const;
|
||||||
void edit3DViewResized(const QSize &size) const;
|
void edit3DViewResized(const QSize &size) const;
|
||||||
@@ -66,10 +68,13 @@ public:
|
|||||||
QVector<Edit3DAction *> leftActions() const;
|
QVector<Edit3DAction *> leftActions() const;
|
||||||
QVector<Edit3DAction *> rightActions() const;
|
QVector<Edit3DAction *> rightActions() const;
|
||||||
|
|
||||||
|
void addQuick3DImport();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createEdit3DWidget();
|
void createEdit3DWidget();
|
||||||
|
void checkImports();
|
||||||
|
|
||||||
QPointer<Edit3DWidget> m_edit3DWidget;
|
QPointer<Edit3DWidget> m_edit3DWidget;
|
||||||
QVector<Edit3DAction *> m_leftActions;
|
QVector<Edit3DAction *> m_leftActions;
|
||||||
|
|||||||
@@ -94,9 +94,24 @@ Edit3DWidget::Edit3DWidget(Edit3DView *view) :
|
|||||||
addActionsToToolBox(view->leftActions(), true);
|
addActionsToToolBox(view->leftActions(), true);
|
||||||
addActionsToToolBox(view->rightActions(), false);
|
addActionsToToolBox(view->rightActions(), false);
|
||||||
|
|
||||||
|
// Onboarding label contains instructions for new users how to get 3D content into the project
|
||||||
|
m_onboardingLabel = new QLabel(this);
|
||||||
|
QString labelText =
|
||||||
|
"No 3D import here yet!<br><br>"
|
||||||
|
"To create a 3D View you need to add the QtQuick3D import to your file.<br>"
|
||||||
|
"You can add the import via the QML Imports tab of the Library view, or alternatively click"
|
||||||
|
" <a href=\"#add_import\"><span style=\"text-decoration:none;color:%1\">here</span></a> "
|
||||||
|
"to add it straight away.<br><br>"
|
||||||
|
"If you want to import 3D assets from another tool, click on the \"Add New Assets...\" button in the Assets tab of the Library view.";
|
||||||
|
m_onboardingLabel->setText(labelText.arg(Utils::creatorTheme()->color(Utils::Theme::TextColorLink).name()));
|
||||||
|
m_onboardingLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||||
|
connect(m_onboardingLabel, &QLabel::linkActivated, this, &Edit3DWidget::linkActivated);
|
||||||
|
fillLayout->addWidget(m_onboardingLabel.data());
|
||||||
|
|
||||||
// Canvas is used to render the actual edit 3d view
|
// Canvas is used to render the actual edit 3d view
|
||||||
m_canvas = new Edit3DCanvas(this);
|
m_canvas = new Edit3DCanvas(this);
|
||||||
fillLayout->addWidget(m_canvas.data());
|
fillLayout->addWidget(m_canvas.data());
|
||||||
|
showCanvas(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Edit3DWidget::contextHelp(const Core::IContext::HelpCallback &callback) const
|
void Edit3DWidget::contextHelp(const Core::IContext::HelpCallback &callback) const
|
||||||
@@ -107,6 +122,22 @@ void Edit3DWidget::contextHelp(const Core::IContext::HelpCallback &callback) con
|
|||||||
callback({});
|
callback({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Edit3DWidget::showCanvas(bool show)
|
||||||
|
{
|
||||||
|
if (!show) {
|
||||||
|
QImage emptyImage;
|
||||||
|
m_canvas->updateRenderImage(emptyImage);
|
||||||
|
}
|
||||||
|
m_canvas->setVisible(show);
|
||||||
|
m_onboardingLabel->setVisible(!show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Edit3DWidget::linkActivated(const QString &link)
|
||||||
|
{
|
||||||
|
if (m_view)
|
||||||
|
m_view->addQuick3DImport();
|
||||||
|
}
|
||||||
|
|
||||||
Edit3DCanvas *Edit3DWidget::canvas() const
|
Edit3DCanvas *Edit3DWidget::canvas() const
|
||||||
{
|
{
|
||||||
return m_canvas.data();
|
return m_canvas.data();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QtWidgets/qwidget.h>
|
#include <QtWidgets/qwidget.h>
|
||||||
|
#include <QtWidgets/qlabel.h>
|
||||||
#include <QtCore/qpointer.h>
|
#include <QtCore/qpointer.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
|
|
||||||
@@ -45,10 +46,15 @@ public:
|
|||||||
Edit3DView *view() const;
|
Edit3DView *view() const;
|
||||||
void contextHelp(const Core::IContext::HelpCallback &callback) const;
|
void contextHelp(const Core::IContext::HelpCallback &callback) const;
|
||||||
|
|
||||||
|
void showCanvas(bool show);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void linkActivated(const QString &link);
|
||||||
|
|
||||||
QPointer<Edit3DView> m_edit3DView;
|
QPointer<Edit3DView> m_edit3DView;
|
||||||
QPointer<Edit3DView> m_view;
|
QPointer<Edit3DView> m_view;
|
||||||
QPointer<Edit3DCanvas> m_canvas;
|
QPointer<Edit3DCanvas> m_canvas;
|
||||||
|
QPointer<QLabel> m_onboardingLabel;
|
||||||
QPointer<ToolBox> m_toolBox;
|
QPointer<ToolBox> m_toolBox;
|
||||||
Core::IContext *m_context = nullptr;
|
Core::IContext *m_context = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user