forked from qt-creator/qt-creator
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:
@@ -10,10 +10,16 @@ namespace QmlDesigner {
|
|||||||
|
|
||||||
InputEventCommand::InputEventCommand() = default;
|
InputEventCommand::InputEventCommand() = default;
|
||||||
|
|
||||||
InputEventCommand::InputEventCommand(QInputEvent *e)
|
InputEventCommand::InputEventCommand(QEvent *e)
|
||||||
: m_type(e->type()),
|
: m_type(e->type())
|
||||||
m_modifiers(e->modifiers())
|
|
||||||
{
|
{
|
||||||
|
// 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) {
|
if (m_type == QEvent::Wheel) {
|
||||||
auto we = static_cast<QWheelEvent *>(e);
|
auto we = static_cast<QWheelEvent *>(e);
|
||||||
#if QT_VERSION <= QT_VERSION_CHECK(5, 15, 0)
|
#if QT_VERSION <= QT_VERSION_CHECK(5, 15, 0)
|
||||||
@@ -28,6 +34,11 @@ InputEventCommand::InputEventCommand(QInputEvent *e)
|
|||||||
m_key = ke->key();
|
m_key = ke->key();
|
||||||
m_count = ke->count();
|
m_count = ke->count();
|
||||||
m_autoRepeat = ke->isAutoRepeat();
|
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 {
|
} else {
|
||||||
auto me = static_cast<QMouseEvent *>(e);
|
auto me = static_cast<QMouseEvent *>(e);
|
||||||
m_pos = me->pos();
|
m_pos = me->pos();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class InputEventCommand
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
InputEventCommand();
|
InputEventCommand();
|
||||||
explicit InputEventCommand(QInputEvent *e);
|
explicit InputEventCommand(QEvent *e);
|
||||||
|
|
||||||
QEvent::Type type() const { return m_type; }
|
QEvent::Type type() const { return m_type; }
|
||||||
QPoint pos() const { return m_pos; }
|
QPoint pos() const { return m_pos; }
|
||||||
|
|||||||
@@ -155,6 +155,18 @@ void Edit3DCanvas::focusInEvent(QFocusEvent *focusEvent)
|
|||||||
QWidget::focusInEvent(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()
|
void Edit3DCanvas::positionBusyInidicator()
|
||||||
{
|
{
|
||||||
m_busyIndicator->move(width() / 2 - 32, height() / 2 - 32);
|
m_busyIndicator->move(width() / 2 - 32, height() / 2 - 32);
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ protected:
|
|||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
void focusOutEvent(QFocusEvent *focusEvent) override;
|
void focusOutEvent(QFocusEvent *focusEvent) override;
|
||||||
void focusInEvent(QFocusEvent *focusEvent) override;
|
void focusInEvent(QFocusEvent *focusEvent) override;
|
||||||
|
void enterEvent(QEnterEvent *e) override;
|
||||||
|
void leaveEvent(QEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void positionBusyInidicator();
|
void positionBusyInidicator();
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ void Edit3DView::nodeRemoved(const ModelNode &,
|
|||||||
updateAlignActionStates();
|
updateAlignActionStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Edit3DView::sendInputEvent(QInputEvent *e) const
|
void Edit3DView::sendInputEvent(QEvent *e) const
|
||||||
{
|
{
|
||||||
if (nodeInstanceView())
|
if (nodeInstanceView())
|
||||||
nodeInstanceView()->sendInputEvent(e);
|
nodeInstanceView()->sendInputEvent(e);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty,
|
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty,
|
||||||
PropertyChangeFlags propertyChange) override;
|
PropertyChangeFlags propertyChange) override;
|
||||||
|
|
||||||
void sendInputEvent(QInputEvent *e) const;
|
void sendInputEvent(QEvent *e) const;
|
||||||
void edit3DViewResized(const QSize &size) const;
|
void edit3DViewResized(const QSize &size) const;
|
||||||
|
|
||||||
QSize canvasSize() const;
|
QSize canvasSize() const;
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public:
|
|||||||
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
|
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
|
||||||
const QList<ModelNode> &lastSelectedNodeList) override;
|
const QList<ModelNode> &lastSelectedNodeList) override;
|
||||||
|
|
||||||
void sendInputEvent(QInputEvent *e) const;
|
void sendInputEvent(QEvent *e) const;
|
||||||
void view3DAction(View3DActionType type, const QVariant &value) override;
|
void view3DAction(View3DActionType type, const QVariant &value) override;
|
||||||
void requestModelNodePreviewImage(const ModelNode &node, const ModelNode &renderNode) const;
|
void requestModelNodePreviewImage(const ModelNode &node, const ModelNode &renderNode) const;
|
||||||
void edit3DViewResized(const QSize &size) const;
|
void edit3DViewResized(const QSize &size) const;
|
||||||
|
|||||||
@@ -1764,7 +1764,7 @@ void NodeInstanceView::selectedNodesChanged(const QList<ModelNode> &selectedNode
|
|||||||
m_rotBlockTimer.start();
|
m_rotBlockTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeInstanceView::sendInputEvent(QInputEvent *e) const
|
void NodeInstanceView::sendInputEvent(QEvent *e) const
|
||||||
{
|
{
|
||||||
m_nodeInstanceServer->inputEvent(InputEventCommand(e));
|
m_nodeInstanceServer->inputEvent(InputEventCommand(e));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ void Qt5InformationNodeInstanceServer::handleInputEvents()
|
|||||||
// Peek at next command. If that is also a wheel with same button/modifiers
|
// 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.
|
// state, skip this event and add the angle delta to the next one.
|
||||||
auto nextCommand = m_pendingInputEventCommands[i + 1];
|
auto nextCommand = m_pendingInputEventCommands[i + 1];
|
||||||
if (nextCommand.type() == QEvent::MouseMove
|
if (nextCommand.type() == QEvent::Wheel
|
||||||
&& nextCommand.button() == command.button()
|
&& nextCommand.button() == command.button()
|
||||||
&& nextCommand.buttons() == command.buttons()
|
&& nextCommand.buttons() == command.buttons()
|
||||||
&& nextCommand.modifiers() == command.modifiers()) {
|
&& nextCommand.modifiers() == command.modifiers()) {
|
||||||
@@ -232,6 +232,12 @@ void Qt5InformationNodeInstanceServer::handleInputEvents()
|
|||||||
QKeyEvent *ke = new QKeyEvent(command.type(), command.key(), command.modifiers(),
|
QKeyEvent *ke = new QKeyEvent(command.type(), command.key(), command.modifiers(),
|
||||||
QString(), command.autoRepeat(), command.count());
|
QString(), command.autoRepeat(), command.count());
|
||||||
QGuiApplication::sendEvent(m_editView3DData.window, ke);
|
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 {
|
} else {
|
||||||
if (command.type() == QEvent::MouseMove && i < m_pendingInputEventCommands.size() - 1) {
|
if (command.type() == QEvent::MouseMove && i < m_pendingInputEventCommands.size() - 1) {
|
||||||
// Peek at next command. If that is also a move with only difference being
|
// Peek at next command. If that is also a move with only difference being
|
||||||
|
|||||||
Reference in New Issue
Block a user