forked from qt-creator/qt-creator
QmlDesigner: Cache last image in 3D view and add busy indicator
This patch caches the last image from a document/model. The result ist that when reopening a file in the 3D editor the user sees immediately something. Since the view is not interactive, yet, we show a busy indicator until the view is fully initialized. Change-Id: I26c8b0ea69f98ceb41580624c51d48d1e633ab80 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -30,21 +30,43 @@
|
||||
#include "nodehints.h"
|
||||
#include "qmlvisualnode.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <qmldesignerplugin.h>
|
||||
#include <qmldesignerconstants.h>
|
||||
|
||||
#include <QtCore/qmimedata.h>
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QQuickWidget>
|
||||
#include <QtCore/qmimedata.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
static QQuickWidget *createBusyIndicator(QWidget *p)
|
||||
{
|
||||
auto widget = new QQuickWidget(p);
|
||||
|
||||
const QString source = Core::ICore::resourcePath("qmldesigner/misc/BusyIndicator.qml").toString();
|
||||
QTC_ASSERT(QFileInfo::exists(source), return widget);
|
||||
widget->setSource(QUrl::fromLocalFile(source));
|
||||
widget->setFixedSize(64, 64);
|
||||
widget->setAttribute(Qt::WA_AlwaysStackOnTop);
|
||||
widget->setClearColor(Qt::transparent);
|
||||
widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
return widget;
|
||||
}
|
||||
|
||||
Edit3DCanvas::Edit3DCanvas(Edit3DWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_parent(parent)
|
||||
: QWidget(parent)
|
||||
, m_parent(parent)
|
||||
, m_busyIndicator(createBusyIndicator(this))
|
||||
{
|
||||
setMouseTracking(true);
|
||||
setAcceptDrops(true);
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
m_busyIndicator->show();
|
||||
}
|
||||
|
||||
void Edit3DCanvas::updateRenderImage(const QImage &img)
|
||||
@@ -58,6 +80,21 @@ void Edit3DCanvas::updateActiveScene(qint32 activeScene)
|
||||
m_activeScene = activeScene;
|
||||
}
|
||||
|
||||
QImage QmlDesigner::Edit3DCanvas::renderImage() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void Edit3DCanvas::setOpacity(qreal opacity)
|
||||
{
|
||||
m_opacity = opacity;
|
||||
}
|
||||
|
||||
QWidget *Edit3DCanvas::busyIndicator() const
|
||||
{
|
||||
return m_busyIndicator;
|
||||
}
|
||||
|
||||
void Edit3DCanvas::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
m_parent->view()->sendInputEvent(e);
|
||||
@@ -108,11 +145,17 @@ void Edit3DCanvas::paintEvent(QPaintEvent *e)
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
if (m_opacity < 1.0) {
|
||||
painter.fillRect(rect(), Qt::black);
|
||||
painter.setOpacity(m_opacity);
|
||||
}
|
||||
|
||||
painter.drawImage(rect(), m_image, QRect(0, 0, m_image.width(), m_image.height()));
|
||||
}
|
||||
|
||||
void Edit3DCanvas::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
positionBusyInidicator();
|
||||
m_parent->view()->edit3DViewResized(e->size());
|
||||
}
|
||||
|
||||
@@ -161,4 +204,9 @@ void Edit3DCanvas::focusInEvent(QFocusEvent *focusEvent)
|
||||
QWidget::focusInEvent(focusEvent);
|
||||
}
|
||||
|
||||
void Edit3DCanvas::positionBusyInidicator()
|
||||
{
|
||||
m_busyIndicator->move(width() / 2 - 32, height() / 2 - 32);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user