QmlDesigner: Add enter and leave event support to 3D view

Fixes: QDS-10917
Change-Id: Iefcf92bd4a747d35f44e47c438548338fccfc4a2
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Miikka Heikkinen
2023-10-06 17:46:25 +03:00
parent 55039d6975
commit 32b68b296a
9 changed files with 40 additions and 9 deletions

View File

@@ -10,10 +10,16 @@ namespace QmlDesigner {
InputEventCommand::InputEventCommand() = default;
InputEventCommand::InputEventCommand(QInputEvent *e)
: m_type(e->type()),
m_modifiers(e->modifiers())
InputEventCommand::InputEventCommand(QEvent *e)
: m_type(e->type())
{
// Leave events are not actual input events
if (m_type == QEvent::Leave)
return;
auto ie = static_cast<QInputEvent *>(e);
m_modifiers = ie->modifiers();
if (m_type == QEvent::Wheel) {
auto we = static_cast<QWheelEvent *>(e);
#if QT_VERSION <= QT_VERSION_CHECK(5, 15, 0)
@@ -28,6 +34,11 @@ InputEventCommand::InputEventCommand(QInputEvent *e)
m_key = ke->key();
m_count = ke->count();
m_autoRepeat = ke->isAutoRepeat();
} else if (m_type == QEvent::Enter) {
auto spe = static_cast<QSinglePointEvent *>(e);
m_pos = spe->position().toPoint();
m_button = spe->button();
m_buttons = spe->buttons();
} else {
auto me = static_cast<QMouseEvent *>(e);
m_pos = me->pos();

View File

@@ -18,7 +18,7 @@ class InputEventCommand
public:
InputEventCommand();
explicit InputEventCommand(QInputEvent *e);
explicit InputEventCommand(QEvent *e);
QEvent::Type type() const { return m_type; }
QPoint pos() const { return m_pos; }

View File

@@ -155,6 +155,18 @@ void Edit3DCanvas::focusInEvent(QFocusEvent *focusEvent)
QWidget::focusInEvent(focusEvent);
}
void Edit3DCanvas::enterEvent(QEnterEvent *e)
{
m_parent->view()->sendInputEvent(e);
QWidget::enterEvent(e);
}
void Edit3DCanvas::leaveEvent(QEvent *e)
{
m_parent->view()->sendInputEvent(e);
QWidget::leaveEvent(e);
}
void Edit3DCanvas::positionBusyInidicator()
{
m_busyIndicator->move(width() / 2 - 32, height() / 2 - 32);

View File

@@ -38,6 +38,8 @@ protected:
void resizeEvent(QResizeEvent *e) override;
void focusOutEvent(QFocusEvent *focusEvent) override;
void focusInEvent(QFocusEvent *focusEvent) override;
void enterEvent(QEnterEvent *e) override;
void leaveEvent(QEvent *e) override;
private:
void positionBusyInidicator();

View File

@@ -431,7 +431,7 @@ void Edit3DView::nodeRemoved(const ModelNode &,
updateAlignActionStates();
}
void Edit3DView::sendInputEvent(QInputEvent *e) const
void Edit3DView::sendInputEvent(QEvent *e) const
{
if (nodeInstanceView())
nodeInstanceView()->sendInputEvent(e);

View File

@@ -52,7 +52,7 @@ public:
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty,
PropertyChangeFlags propertyChange) override;
void sendInputEvent(QInputEvent *e) const;
void sendInputEvent(QEvent *e) const;
void edit3DViewResized(const QSize &size) const;
QSize canvasSize() const;

View File

@@ -132,7 +132,7 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList) override;
void sendInputEvent(QInputEvent *e) const;
void sendInputEvent(QEvent *e) const;
void view3DAction(View3DActionType type, const QVariant &value) override;
void requestModelNodePreviewImage(const ModelNode &node, const ModelNode &renderNode) const;
void edit3DViewResized(const QSize &size) const;

View File

@@ -1764,7 +1764,7 @@ void NodeInstanceView::selectedNodesChanged(const QList<ModelNode> &selectedNode
m_rotBlockTimer.start();
}
void NodeInstanceView::sendInputEvent(QInputEvent *e) const
void NodeInstanceView::sendInputEvent(QEvent *e) const
{
m_nodeInstanceServer->inputEvent(InputEventCommand(e));
}

View File

@@ -213,7 +213,7 @@ void Qt5InformationNodeInstanceServer::handleInputEvents()
// Peek at next command. If that is also a wheel with same button/modifiers
// state, skip this event and add the angle delta to the next one.
auto nextCommand = m_pendingInputEventCommands[i + 1];
if (nextCommand.type() == QEvent::MouseMove
if (nextCommand.type() == QEvent::Wheel
&& nextCommand.button() == command.button()
&& nextCommand.buttons() == command.buttons()
&& nextCommand.modifiers() == command.modifiers()) {
@@ -232,6 +232,12 @@ void Qt5InformationNodeInstanceServer::handleInputEvents()
QKeyEvent *ke = new QKeyEvent(command.type(), command.key(), command.modifiers(),
QString(), command.autoRepeat(), command.count());
QGuiApplication::sendEvent(m_editView3DData.window, ke);
} else if (command.type() == QEvent::Enter) {
QEnterEvent *ee = new QEnterEvent(command.pos(), {}, {});
QGuiApplication::sendEvent(m_editView3DData.window, ee);
} else if (command.type() == QEvent::Leave) {
QEvent *e = new QEvent(command.type());
QGuiApplication::sendEvent(m_editView3DData.window, e);
} else {
if (command.type() == QEvent::MouseMove && i < m_pendingInputEventCommands.size() - 1) {
// Peek at next command. If that is also a move with only difference being