aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2019-10-30 10:52:51 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-11-01 08:49:12 +0000
commit97788c457eed2bb7e97eadf87900f9bef9329e78 (patch)
treedd124e00e52168b36d9d19a23e465e1526a6a3fa /share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp
parentd4797587b12944ccb0880115dc550127e2a1470e (diff)
QmlDesigner: MoveGizmo improvements in 3D edit view
Mouse press and release are now properly handled by MouseArea3D. This fixes various issues: - No need to move the mouse after release for release to register. - Drag is no longer limited to the 3D edit window, though it is still limited to the screen. - Drag arrows no longer register start of drag if you click outside the arrow and then move the cursor over the arrow while holding the mouse button down. Also added the missing center ball to the MoveGizmo to allow free dragging along the camera plane. Change-Id: Iab55ae79f8af024534510e5fd29379532ac74025 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp')
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp143
1 files changed, 109 insertions, 34 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp
index e3ec5c704b..4c1fdcc78e 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/mousearea3d.cpp
@@ -80,6 +80,11 @@ qreal MouseArea3D::height() const
return m_height;
}
+int MouseArea3D::priority() const
+{
+ return m_priority;
+}
+
void MouseArea3D::setView3D(QQuick3DViewport *view3D)
{
if (m_view3D == view3D)
@@ -134,6 +139,15 @@ void MouseArea3D::setHeight(qreal height)
emit heightChanged(height);
}
+void MouseArea3D::setPriority(int level)
+{
+ if (m_priority == level)
+ return;
+
+ m_priority = level;
+ emit priorityChanged(level);
+}
+
void MouseArea3D::componentComplete()
{
if (!m_view3D) {
@@ -193,51 +207,94 @@ QVector3D MouseArea3D::getMousePosInPlane(const QPointF &mousePosInView) const
bool MouseArea3D::eventFilter(QObject *, QEvent *event)
{
+ if (m_grabsMouse && s_mouseGrab && s_mouseGrab != this
+ && (m_priority <= s_mouseGrab->m_priority || s_mouseGrab->m_dragging)) {
+ return false;
+ }
+
+ auto mouseOnTopOfMouseArea = [this](const QVector3D &mousePosInPlane) -> bool {
+ return !qFuzzyCompare(mousePosInPlane.z(), -1)
+ && mousePosInPlane.x() >= float(m_x)
+ && mousePosInPlane.x() <= float(m_x + m_width)
+ && mousePosInPlane.y() >= float(m_y)
+ && mousePosInPlane.y() <= float(m_y + m_height);
+ };
+
switch (event->type()) {
+ case QEvent::MouseButtonPress: {
+ auto const mouseEvent = static_cast<QMouseEvent *>(event);
+ if (mouseEvent->button() == Qt::LeftButton) {
+ m_mousePosInPlane = getMousePosInPlane(mouseEvent->pos());
+ if (mouseOnTopOfMouseArea(m_mousePosInPlane)) {
+ setDragging(true);
+ emit pressed(m_mousePosInPlane);
+ if (m_grabsMouse) {
+ if (s_mouseGrab && s_mouseGrab != this) {
+ s_mouseGrab->setDragging(false);
+ s_mouseGrab->setHovering(false);
+ }
+ s_mouseGrab = this;
+ setHovering(true);
+ }
+ event->accept();
+ return true;
+ }
+ }
+ break;
+ }
+ case QEvent::MouseButtonRelease: {
+ auto const mouseEvent = static_cast<QMouseEvent *>(event);
+ if (mouseEvent->button() == Qt::LeftButton) {
+ if (m_dragging) {
+ QVector3D mousePosInPlane = getMousePosInPlane(mouseEvent->pos());
+ if (qFuzzyCompare(mousePosInPlane.z(), -1))
+ mousePosInPlane = m_mousePosInPlane;
+ setDragging(false);
+ emit released(mousePosInPlane);
+ if (m_grabsMouse) {
+ if (s_mouseGrab && s_mouseGrab != this) {
+ s_mouseGrab->setDragging(false);
+ s_mouseGrab->setHovering(false);
+ }
+ if (mouseOnTopOfMouseArea(mousePosInPlane)) {
+ s_mouseGrab = this;
+ setHovering(true);
+ } else {
+ s_mouseGrab = nullptr;
+ setHovering(false);
+ }
+ }
+ event->accept();
+ return true;
+ }
+ }
+ break;
+ }
+ case QEvent::MouseMove:
case QEvent::HoverMove: {
- if (m_grabsMouse && s_mouseGrab && s_mouseGrab != this)
- break;
-
auto const mouseEvent = static_cast<QMouseEvent *>(event);
const QVector3D mousePosInPlane = getMousePosInPlane(mouseEvent->pos());
- if (qFuzzyCompare(mousePosInPlane.z(), -1))
- break;
-
- const bool mouseOnTopOfMouseArea =
- mousePosInPlane.x() >= float(m_x) &&
- mousePosInPlane.x() <= float(m_x + m_width) &&
- mousePosInPlane.y() >= float(m_y) &&
- mousePosInPlane.y() <= float(m_y + m_height);
+ const bool hasMouse = mouseOnTopOfMouseArea(mousePosInPlane);
- const bool buttonPressed = QGuiApplication::mouseButtons().testFlag(Qt::LeftButton);
+ setHovering(hasMouse);
- // The filter will detect a mouse press on the view, but not a mouse release, since the
- // former is not accepted by the view, which means that the release will end up being
- // sent elsewhere. So we need this extra logic inside HoverMove, rather than in
- // MouseButtonRelease, which would otherwise be more elegant.
+ if (m_grabsMouse) {
+ if (m_hovering && s_mouseGrab && s_mouseGrab != this)
+ s_mouseGrab->setHovering(false);
- if (m_hovering != mouseOnTopOfMouseArea) {
- m_hovering = mouseOnTopOfMouseArea;
- emit hoveringChanged();
+ if (m_hovering || m_dragging)
+ s_mouseGrab = this;
+ else if (s_mouseGrab == this)
+ s_mouseGrab = nullptr;
}
- if (!m_dragging && m_hovering && buttonPressed) {
- m_dragging = true;
- emit pressed(mousePosInPlane);
- emit draggingChanged();
- } else if (m_dragging && !buttonPressed) {
- m_dragging = false;
- emit released(mousePosInPlane);
- emit draggingChanged();
- }
-
- if (m_grabsMouse)
- s_mouseGrab = m_hovering || m_dragging ? this : nullptr;
-
- if (m_dragging)
+ if (m_dragging && !qFuzzyCompare(mousePosInPlane.z(), -1)) {
+ m_mousePosInPlane = mousePosInPlane;
emit dragged(mousePosInPlane);
+ }
- break; }
+ break;
+ }
default:
break;
}
@@ -245,6 +302,24 @@ bool MouseArea3D::eventFilter(QObject *, QEvent *event)
return false;
}
+void MouseArea3D::setDragging(bool enable)
+{
+ if (m_dragging == enable)
+ return;
+
+ m_dragging = enable;
+ emit draggingChanged();
+}
+
+void MouseArea3D::setHovering(bool enable)
+{
+ if (m_hovering == enable)
+ return;
+
+ m_hovering = enable;
+ emit hoveringChanged();
+}
+
}
}