forked from qt-creator/qt-creator
QmlDesigner: Remove remaining separate edit 3D window code
Change-Id: I3d745b54ae3aa5c3c05c859239934125b9ca828d Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -43,7 +43,6 @@
|
||||
#include <QtQuick/qquickwindow.h>
|
||||
#include <QtQuick/qquickitem.h>
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtGui/qscreen.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
@@ -259,61 +258,6 @@ void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &to
|
||||
m_toolStates[sceneId] = toolStates;
|
||||
}
|
||||
|
||||
void GeneralHelper::storeWindowState()
|
||||
{
|
||||
if (!m_edit3DWindow)
|
||||
return;
|
||||
|
||||
QVariantMap windowState;
|
||||
const QRect geometry = m_edit3DWindow->geometry();
|
||||
const bool maximized = m_edit3DWindow->windowState() == Qt::WindowMaximized;
|
||||
windowState.insert("maximized", maximized);
|
||||
windowState.insert("geometry", geometry);
|
||||
|
||||
storeToolState(globalStateId(), "windowState", windowState, 500);
|
||||
}
|
||||
|
||||
void GeneralHelper::restoreWindowState()
|
||||
{
|
||||
if (!m_edit3DWindow)
|
||||
return;
|
||||
|
||||
if (m_toolStates.contains(globalStateId())) {
|
||||
const QVariantMap &globalStateMap = m_toolStates[globalStateId()];
|
||||
const QString stateKey = QStringLiteral("windowState");
|
||||
if (globalStateMap.contains(stateKey)) {
|
||||
QVariantMap windowState = globalStateMap[stateKey].value<QVariantMap>();
|
||||
|
||||
doRestoreWindowState(windowState);
|
||||
|
||||
// If the mouse cursor at puppet launch time is in a different screen than the one where the
|
||||
// view geometry was saved on, the initial position and size can be incorrect, but if
|
||||
// we reset the geometry again asynchronously, it should end up with correct geometry.
|
||||
QTimer::singleShot(0, [this, windowState]() {
|
||||
doRestoreWindowState(windowState);
|
||||
QTimer::singleShot(0, [this]() {
|
||||
// Make sure that the window is at least partially visible on the screen
|
||||
QRect geo = m_edit3DWindow->geometry();
|
||||
QRect sRect = m_edit3DWindow->screen()->geometry();
|
||||
if (geo.left() > sRect.right() - 150)
|
||||
geo.moveRight(sRect.right());
|
||||
if (geo.right() < sRect.left() + 150)
|
||||
geo.moveLeft(sRect.left());
|
||||
if (geo.top() > sRect.bottom() - 150)
|
||||
geo.moveBottom(sRect.bottom());
|
||||
if (geo.bottom() < sRect.top() + 150)
|
||||
geo.moveTop(sRect.top());
|
||||
if (geo.width() > sRect.width())
|
||||
geo.setWidth(sRect.width());
|
||||
if (geo.height() > sRect.height())
|
||||
geo.setHeight(sRect.height());
|
||||
m_edit3DWindow->setGeometry(geo);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralHelper::enableItemUpdate(QQuickItem *item, bool enable)
|
||||
{
|
||||
if (item)
|
||||
@@ -328,33 +272,11 @@ QVariantMap GeneralHelper::getToolStates(const QString &sceneId)
|
||||
return {};
|
||||
}
|
||||
|
||||
void GeneralHelper::setEdit3DWindow(QQuickWindow *w)
|
||||
{
|
||||
m_edit3DWindow = w;
|
||||
}
|
||||
|
||||
QString GeneralHelper::globalStateId() const
|
||||
{
|
||||
return _globalStateId;
|
||||
}
|
||||
|
||||
void GeneralHelper::doRestoreWindowState(const QVariantMap &windowState)
|
||||
{
|
||||
const QString geoKey = QStringLiteral("geometry");
|
||||
if (windowState.contains(geoKey)) {
|
||||
bool maximized = false;
|
||||
const QString maxKey = QStringLiteral("maximized");
|
||||
if (windowState.contains(maxKey))
|
||||
maximized = windowState[maxKey].toBool();
|
||||
|
||||
QRect rect = windowState[geoKey].value<QRect>();
|
||||
|
||||
m_edit3DWindow->setGeometry(rect);
|
||||
if (maximized)
|
||||
m_edit3DWindow->showMaximized();
|
||||
}
|
||||
}
|
||||
|
||||
bool GeneralHelper::isMacOS() const
|
||||
{
|
||||
#ifdef Q_OS_MACOS
|
||||
|
||||
@@ -38,7 +38,6 @@ QT_BEGIN_NAMESPACE
|
||||
class QQuick3DCamera;
|
||||
class QQuick3DNode;
|
||||
class QQuick3DViewport;
|
||||
class QQuickWindow;
|
||||
class QQuickItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@@ -75,11 +74,8 @@ public:
|
||||
Q_INVOKABLE void storeToolState(const QString &sceneId, const QString &tool,
|
||||
const QVariant &state, int delayEmit = 0);
|
||||
void initToolStates(const QString &sceneId, const QVariantMap &toolStates);
|
||||
Q_INVOKABLE void storeWindowState();
|
||||
void restoreWindowState();
|
||||
Q_INVOKABLE void enableItemUpdate(QQuickItem *item, bool enable);
|
||||
Q_INVOKABLE QVariantMap getToolStates(const QString &sceneId);
|
||||
void setEdit3DWindow(QQuickWindow *w);
|
||||
QString globalStateId() const;
|
||||
|
||||
bool isMacOS() const;
|
||||
@@ -88,9 +84,6 @@ signals:
|
||||
void overlayUpdateNeeded();
|
||||
void toolStateChanged(const QString &sceneId, const QString &tool, const QVariant &toolState);
|
||||
|
||||
private slots:
|
||||
void doRestoreWindowState(const QVariantMap &windowState);
|
||||
|
||||
private:
|
||||
void handlePendingToolStateUpdate();
|
||||
|
||||
@@ -98,7 +91,6 @@ private:
|
||||
QTimer m_toolStateUpdateTimer;
|
||||
QHash<QString, QVariantMap> m_toolStates;
|
||||
QHash<QString, QVariantMap> m_toolStatesPending;
|
||||
QPointer<QQuickWindow> m_edit3DWindow;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user