diff --git a/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml b/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml index b246eb62daf..340570ff9b2 100644 --- a/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml +++ b/share/qtcreator/qmldesigner/edit3dQmlSource/SnapConfigurationDialog.qml @@ -20,13 +20,24 @@ Rectangle { border.color: StudioTheme.Values.themeControlOutline border.width: StudioTheme.Values.border - Connections { - target: rootView + function handlePosIntChanged() { + posIntSpin.value = posInt + } - // Spinboxes lose the initial binding if the value changes so we need these connections - onPosIntChanged: posIntSpin.realValue = rootView.posInt - onRotIntChanged: rotIntSpin.realValue = rootView.rotInt - onScaleIntChanged: scaleIntSpin.realValue = rootView.scaleInt + function handleRotIntChanged() { + rotIntSpin.value = rotInt + } + + function handleScaleIntChanged() { + scaleIntSpin.value = scaleInt + } + + // Connect context object signals to our handler functions + // Spinboxes lose the initial binding if the value changes so we need these handlers + Component.onCompleted: { + onPosIntChanged.connect(handlePosIntChanged); + onRotIntChanged.connect(handleRotIntChanged); + onScaleIntChanged.connect(handleScaleIntChanged); } ColumnLayout { @@ -94,7 +105,7 @@ Rectangle { Layout.column: 0 Layout.row: 1 Layout.minimumWidth: 100 - checked: rootView.posEnabled + checked: posEnabled actionIndicatorVisible: false hoverEnabled: true @@ -102,27 +113,26 @@ Rectangle { ToolTip.text: qsTr("Snap position.") ToolTip.delay: root.toolTipDelay - onToggled: rootView.posEnabled = checked + onToggled: posEnabled = checked } - StudioControls.RealSpinBox { + HelperWidgets.DoubleSpinBox { id: posIntSpin Layout.fillWidth: true Layout.column: 1 Layout.row: 1 Layout.leftMargin: 10 - realFrom: 1 - realTo: 10000 - realValue: rootView.posInt - realStepSize: 1 - actionIndicatorVisible: false + minimumValue: 1 + maximumValue: 10000 + value: posInt + stepSize: 1 + decimals: 0 - hoverEnabled: true - ToolTip.visible: hovered + ToolTip.visible: hover ToolTip.text: qsTr("Snap interval for move gizmo.") ToolTip.delay: root.toolTipDelay - onRealValueChanged: rootView.posInt = realValue + onValueModified: posInt = value } StudioControls.CheckBox { @@ -130,7 +140,7 @@ Rectangle { Layout.column: 0 Layout.row: 2 Layout.minimumWidth: 100 - checked: rootView.rotEnabled + checked: rotEnabled actionIndicatorVisible: false hoverEnabled: true @@ -138,27 +148,26 @@ Rectangle { ToolTip.text: qsTr("Snap rotation.") ToolTip.delay: root.toolTipDelay - onToggled: rootView.rotEnabled = checked + onToggled: rotEnabled = checked } - StudioControls.RealSpinBox { + HelperWidgets.DoubleSpinBox { id: rotIntSpin Layout.fillWidth: true Layout.column: 1 Layout.row: 2 Layout.leftMargin: 10 - realFrom: 1 - realTo: 90 - realValue: rootView.rotInt - realStepSize: 1 - actionIndicatorVisible: false + minimumValue: 1 + maximumValue: 90 + value: rotInt + stepSize: 1 + decimals: 0 - hoverEnabled: true - ToolTip.visible: hovered + ToolTip.visible: hover ToolTip.text: qsTr("Snap interval in degrees for rotation gizmo.") ToolTip.delay: root.toolTipDelay - onRealValueChanged: rootView.rotInt = realValue + onValueModified: rotInt = value } StudioControls.CheckBox { @@ -166,7 +175,7 @@ Rectangle { Layout.column: 0 Layout.row: 3 Layout.minimumWidth: 100 - checked: rootView.scaleEnabled + checked: scaleEnabled actionIndicatorVisible: false hoverEnabled: true @@ -174,27 +183,26 @@ Rectangle { ToolTip.text: qsTr("Snap scale.") ToolTip.delay: root.toolTipDelay - onToggled: rootView.scaleEnabled = checked + onToggled: scaleEnabled = checked } - StudioControls.RealSpinBox { + HelperWidgets.DoubleSpinBox { id: scaleIntSpin Layout.fillWidth: true Layout.column: 1 Layout.row: 3 Layout.leftMargin: 10 - realFrom: 1 - realTo: 100 - realValue: rootView.scaleInt - realStepSize: 1 - actionIndicatorVisible: false + minimumValue: 1 + maximumValue: 100 + value: scaleInt + stepSize: 1 + decimals: 0 - hoverEnabled: true - ToolTip.visible: hovered + ToolTip.visible: hover ToolTip.text: qsTr("Snap interval for scale gizmo in percentage of original scale.") ToolTip.delay: root.toolTipDelay - onRealValueChanged: rootView.scaleInt = realValue + onValueModified: scaleInt = value } StudioControls.CheckBox { @@ -204,7 +212,7 @@ Rectangle { Layout.column: 0 Layout.row: 4 Layout.columnSpan: 3 - checked: rootView.absolute + checked: absolute actionIndicatorVisible: false hoverEnabled: true @@ -212,7 +220,7 @@ Rectangle { ToolTip.text: qsTr("Toggles if the position snaps to absolute values or relative to object position.") ToolTip.delay: root.toolTipDelay - onToggled: rootView.absolute = checked + onToggled: absolute = checked } Text { @@ -236,7 +244,7 @@ Rectangle { text: qsTr("Reset All") Layout.bottomMargin: 8 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter - onClicked: rootView.resetDefaults() + onClicked: resetDefaults() } } } diff --git a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp index 44fb7ef1322..1412588f902 100644 --- a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp +++ b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.cpp @@ -11,7 +11,8 @@ #include -#include +#include +#include #include #include #include @@ -69,6 +70,8 @@ void SnapConfiguration::apply() m_view->syncSnapAuxPropsToSettings(); } + restoreCursor(); + cancel(); } @@ -83,6 +86,45 @@ void SnapConfiguration::resetDefaults() setScaleInt(defaultScaleInt); } +void SnapConfiguration::hideCursor() +{ + if (QGuiApplication::overrideCursor()) + return; + + QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); + + if (QWindow *w = QGuiApplication::focusWindow()) + m_lastPos = QCursor::pos(w->screen()); +} + +void SnapConfiguration::restoreCursor() +{ + if (!QGuiApplication::overrideCursor()) + return; + + QGuiApplication::restoreOverrideCursor(); + + if (QWindow *w = QGuiApplication::focusWindow()) + QCursor::setPos(w->screen(), m_lastPos); +} + +void SnapConfiguration::holdCursorInPlace() +{ + if (!QGuiApplication::overrideCursor()) + return; + + if (QWindow *w = QGuiApplication::focusWindow()) + QCursor::setPos(w->screen(), m_lastPos); +} + +int SnapConfiguration::devicePixelRatio() +{ + if (QWindow *w = QGuiApplication::focusWindow()) + return w->devicePixelRatio(); + + return 1; +} + void SnapConfiguration::showConfigDialog(const QPoint &pos) { bool posEnabled = Edit3DViewConfig::load(DesignerSettingsKey::EDIT3DVIEW_SNAP_POSITION, true).toBool(); @@ -116,9 +158,7 @@ void SnapConfiguration::showConfigDialog(const QPoint &pos) m_configDialog->setModality(Qt::NonModal); m_configDialog->engine()->addImportPath(propertyEditorResourcesPath() + "/imports"); - m_configDialog->rootContext()->setContextProperties({ - {"rootView", QVariant::fromValue(this)} - }); + m_configDialog->rootContext()->setContextObject(this); m_configDialog->setSource(QUrl::fromLocalFile(path)); m_configDialog->installEventFilter(this); diff --git a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h index ae1a4a0d93b..b744e63053f 100644 --- a/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h +++ b/src/plugins/qmldesigner/components/edit3d/snapconfiguration.h @@ -5,11 +5,11 @@ #include #include +#include #include QT_BEGIN_NAMESPACE class QQuickView; -class QPoint; QT_END_NAMESPACE namespace QmlDesigner { @@ -47,6 +47,10 @@ public: ~SnapConfiguration(); Q_INVOKABLE void resetDefaults(); + Q_INVOKABLE void hideCursor(); + Q_INVOKABLE void restoreCursor(); + Q_INVOKABLE void holdCursorInPlace(); + Q_INVOKABLE int devicePixelRatio(); void cancel(); void apply(); @@ -98,6 +102,7 @@ private: double m_rotationInterval = 0.; double m_scaleInterval = 0.; bool m_changes = false; + QPoint m_lastPos; }; } // namespace QmlDesigner