summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2016-09-08 15:31:01 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2016-09-09 07:03:45 +0000
commit78d14f1de0d7c4d025cc1d5f547f5fdbc300defd (patch)
tree0f985fa3a5c56a3f97971da326ddf22207e99362
parent25acd5501d40bc49618b1443c7951d36946a0d21 (diff)
Display world coordinates of the mouse cursor on toolbar
If not drag scaling/rotating/translating an entity, shows the coordinate on helper plane. When dragging, shows the drag handle coordinate. Change-Id: I50fd226bfb323d0d4ed4df24efc61aacb98c4fd2 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--editorlib/qml/ComponentMenu.qml3
-rw-r--r--editorlib/qml/DragHandle.qml16
-rw-r--r--editorlib/qml/EditorContent.qml24
-rw-r--r--editorlib/qml/EditorToolbar.qml12
-rw-r--r--editorlib/qml/EntityLibrary.qml3
-rw-r--r--editorlib/src/editorscene.cpp46
-rw-r--r--editorlib/src/editorscene.h4
-rw-r--r--editorlib/src/editorsceneitem.cpp9
-rw-r--r--editorlib/src/editorsceneitem.h7
9 files changed, 99 insertions, 25 deletions
diff --git a/editorlib/qml/ComponentMenu.qml b/editorlib/qml/ComponentMenu.qml
index f43bd69..2d96182 100644
--- a/editorlib/qml/ComponentMenu.qml
+++ b/editorlib/qml/ComponentMenu.qml
@@ -137,7 +137,8 @@ Menu {
}
MenuItem {
text: qsTr("Paste (Ctrl + v)") + editorScene.emptyString
- enabled: editorContent.trackMousePosition && !editorScene.multiSelection
+ enabled: editorScene.clipboardOperation !== EditorScene.ClipboardNone
+ && !editorScene.multiSelection
&& (!entityTree.treeviewPasting || (entityTree.treeviewPasting
&& editorScene.sceneModel.canReparent(
editorScene.sceneModel.editorSceneItemFromIndex(
diff --git a/editorlib/qml/DragHandle.qml b/editorlib/qml/DragHandle.qml
index e54bc1f..6a05da3 100644
--- a/editorlib/qml/DragHandle.qml
+++ b/editorlib/qml/DragHandle.qml
@@ -58,24 +58,32 @@ Item {
hoverEnabled: true
onPositionChanged: {
var scenePos = editorViewport.mapFromItem(parent, mouseX, mouseY)
- editorScene.dragHandleMove(scenePos,
- mouse.modifiers & Qt.ShiftModifier,
- mouse.modifiers & Qt.ControlModifier,
- mouse.modifiers & Qt.AltModifier)
+ if (mouse.buttons & Qt.LeftButton) {
+ editorScene.dragHandleMove(scenePos,
+ mouse.modifiers & Qt.ShiftModifier,
+ mouse.modifiers & Qt.ControlModifier,
+ mouse.modifiers & Qt.AltModifier)
+ }
+ editorScene.updateWorldPositionLabelToDragHandle(handleType, handleIndex)
}
onPressed: {
entityTree.focusTree()
var scenePos = editorViewport.mapFromItem(parent, mouseX, mouseY)
editorScene.dragHandlePress(handleType, scenePos, handleIndex)
dragHandle.dragging = true
+ editorScene.updateWorldPositionLabelToDragHandle(handleType, handleIndex)
}
onReleased: {
+ editorScene.updateWorldPositionLabelToDragHandle(handleType, handleIndex)
editorScene.dragHandleRelease()
dragHandle.dragging = false
+ var scenePos = editorViewport.mapFromItem(parent, mouseX, mouseY)
+ editorScene.updateWorldPositionLabel(scenePos.x, scenePos.y)
}
onCanceled: {
editorScene.dragHandleRelease()
dragHandle.dragging = false
+ editorScene.updateWorldPositionLabel(-1, -1)
}
}
diff --git a/editorlib/qml/EditorContent.qml b/editorlib/qml/EditorContent.qml
index e005d0a..a7b6e69 100644
--- a/editorlib/qml/EditorContent.qml
+++ b/editorlib/qml/EditorContent.qml
@@ -56,7 +56,6 @@ Item {
property int currentHelperPlane: 1
property alias selectedEntityType: generalPropertyView.entityType
- property bool trackMousePosition: false
property int mousePosY: -1
property int mousePosX: -1
@@ -185,7 +184,6 @@ Item {
var sceneItem = editorScene.sceneModel.editorSceneItemFromIndex(index)
sceneItem.entity().enabled = true
}
- trackMousePosition = true
editorScene.clipboardContent = entityName
editorScene.clipboardOperation = EditorScene.ClipboardCopy
// TODO: When to stop reading mouse movements when copy-pasting?
@@ -195,7 +193,6 @@ Item {
function cutEntity(entityName, entity) {
if (entityName !== editorScene.sceneRootName()) {
- trackMousePosition = true
editorScene.clipboardContent = entityName
editorScene.clipboardOperation = EditorScene.ClipboardCut
entity.entity().enabled = false
@@ -221,10 +218,8 @@ Item {
// When pasting to tree, world position is not used, and parent entity name is passed
editorScene.undoHandler.createPasteEntityCommand(editorScene.getWorldPosition(
mousePosX, mousePosY), parentName)
- if (editorScene.clipboardOperation === EditorScene.ClipboardCut) {
- trackMousePosition = false
+ if (editorScene.clipboardOperation === EditorScene.ClipboardCut)
editorScene.clipboardOperation = EditorScene.ClipboardNone
- }
}
}
@@ -361,9 +356,9 @@ Item {
entityTree.menu.popup()
}
- onClipboardOperationChanged: {
- if (clipboardOperation === EditorScene.ClipboardNone)
- editorContent.trackMousePosition = false
+ onWorldPositionLabelUpdate: {
+ editorToolbar.coordDisplayText =
+ editorToolbar.coordDisplayTemplate.arg(wpX).arg(wpY).arg(wpZ)
}
function restoreSelection(entity) {
@@ -505,9 +500,14 @@ Item {
mouse.accepted = false
}
onEntered: entityTree.treeviewPasting = false
- hoverEnabled: editorContent.trackMousePosition
- onMouseYChanged: editorContent.mousePosY = mouseY
- onMouseXChanged: editorContent.mousePosX = mouseX
+ hoverEnabled: true
+ onPositionChanged: {
+ editorContent.mousePosY = mouseY
+ editorContent.mousePosX = mouseX
+ editorScene.updateWorldPositionLabel(mouseX, mouseY)
+ }
+ onExited: editorScene.updateWorldPositionLabel(-1, -1)
+ onCanceled: editorScene.updateWorldPositionLabel(-1, -1)
}
DropArea {
diff --git a/editorlib/qml/EditorToolbar.qml b/editorlib/qml/EditorToolbar.qml
index 8f708fc..291b3f6 100644
--- a/editorlib/qml/EditorToolbar.qml
+++ b/editorlib/qml/EditorToolbar.qml
@@ -32,6 +32,9 @@ import QtQuick.Layouts 1.2
import QtQuick.Controls 2.0 as QQC2
Item {
+ property alias coordDisplayText: coordinateDisplayLabel.text
+ property string coordDisplayTemplate: qsTr("x:%1 y:%2 z:%3") + editorScene.emptyString
+
height: newButton.height
ToolBar {
id: mainToolBar
@@ -210,6 +213,15 @@ Item {
tooltip: qsTr("Settings") + editorScene.emptyString
onEnabledButtonClicked: settingsDialog.show()
}
+
+ ToolbarSeparator {}
+
+ // Coordinate display label size is variable, so it should be the last item
+ StyledLabel {
+ id: coordinateDisplayLabel
+ rightPadding: 8
+ leftPadding: 8
+ }
}
}
diff --git a/editorlib/qml/EntityLibrary.qml b/editorlib/qml/EntityLibrary.qml
index abcc5ae..0b96413 100644
--- a/editorlib/qml/EntityLibrary.qml
+++ b/editorlib/qml/EntityLibrary.qml
@@ -132,6 +132,7 @@ Item {
dragPositionY)
editorScene.movePlaceholderEntity("dragInsert",
editorScene.getWorldPosition(scenePos.x, scenePos.y))
+ editorScene.updateWorldPositionLabel(scenePos.x, scenePos.y)
}
onReleased: {
@@ -143,12 +144,14 @@ Item {
dragPositionX,
dragPositionY)
createNewEntity(meshType, scenePos.x, scenePos.y)
+ editorScene.updateWorldPositionLabel(scenePos.x, scenePos.y)
}
}
onCanceled: {
dragEntityItem.endDrag(false)
editorScene.hidePlaceholderEntity("dragInsert")
+ editorScene.updateWorldPositionLabel(-1, -1)
}
}
diff --git a/editorlib/src/editorscene.cpp b/editorlib/src/editorscene.cpp
index 57d200d..689306f 100644
--- a/editorlib/src/editorscene.cpp
+++ b/editorlib/src/editorscene.cpp
@@ -559,7 +559,7 @@ void EditorScene::dragHandlePress(EditorScene::DragMode dragMode, const QPoint &
* m_selectedEntityTransform->scale3D()
/ selectedItem->selectionTransform()->scale3D()
: QVector3D();
- QVector3D snapPos = (selectedItem->selectionTransform()->matrix()
+ QVector3D snapPos = (selectedItem->unadjustedSelectionBoxMatrix()
* (m_dragHandleCornerAdjustments.at(i)
* QVector3D(0.5f, 0.5f, 0.5f) + centerHandleAdj));
snapPos -= selectedItem->selectionBoxCenter();
@@ -2032,6 +2032,39 @@ QVector3D EditorScene::getMultiSelectionCenter()
return m_selectedEntityNameList.size() ? (pos / m_selectedEntityNameList.size()) : QVector3D();
}
+void EditorScene::updateWorldPositionLabel(int xPos, int yPos)
+{
+ updateWorldPositionLabel(getWorldPosition(xPos,yPos));
+}
+
+void EditorScene::updateWorldPositionLabelToDragHandle(EditorScene::DragMode dragMode,
+ int handleIndex)
+{
+ // All handles show actual handle position
+ QMatrix4x4 matrix = m_dragHandlesTransform->matrix();
+ switch (dragMode) {
+ case EditorScene::DragTranslate:
+ if (handleIndex > 0)
+ matrix *= m_dragHandleTranslateTransform->matrix();
+ break;
+ case EditorScene::DragRotate:
+ matrix *= m_dragHandleRotateTransform->matrix();
+ break;
+ case EditorScene::DragScale:
+ matrix *= m_dragHandleScaleTransforms.at(handleIndex)->matrix();
+ break;
+ }
+
+ updateWorldPositionLabel(matrix * QVector3D());
+}
+
+void EditorScene::updateWorldPositionLabel(const QVector3D &worldPos)
+{
+ emit worldPositionLabelUpdate(QString::number(qreal(worldPos.x()), 'f', 2),
+ QString::number(qreal(worldPos.y()), 'f', 2),
+ QString::number(qreal(worldPos.z()), 'f', 2));
+}
+
void EditorScene::addEntityToMultiSelection(const QString &name)
{
const int oldSize = m_selectedEntityNameList.size();
@@ -2242,7 +2275,7 @@ void EditorScene::handleSelectionTransformChange()
m_dragHandlesTransform->setTranslation(item->selectionBoxCenter());
m_dragHandlesTransform->setRotation(item->selectionTransform()->rotation());
- QVector3D translation = (item->selectionBoxExtents() / 2.0f);
+ QVector3D translation = (item->unadjustedSelectionBoxExtents() / 2.0f);
// m_dragHandleTranslateTransform indicates the mesh center position in drag handles
// coordinates, i.e. the position of the secondary translate handle.
@@ -2451,6 +2484,7 @@ bool EditorScene::handleMousePress(QMouseEvent *event)
if (m_mouseButton == Qt::LeftButton)
m_ctrlDownOnLastLeftPress = event->modifiers() & Qt::ControlModifier;
cancelDrag();
+ updateWorldPositionLabel(event->pos().x(), event->pos().y());
return false; // Never consume press event
}
@@ -2463,6 +2497,7 @@ bool EditorScene::handleMouseRelease(QMouseEvent *event)
}
m_cameraViewCenterSelected = false;
cancelDrag();
+ updateWorldPositionLabel(event->pos().x(), event->pos().y());
return false; // Never consume release event
}
@@ -2471,6 +2506,13 @@ bool EditorScene::handleMouseMove(QMouseEvent *event)
dragHandleMove(event->pos(), event->modifiers() & Qt::ShiftModifier,
event->modifiers() & Qt::ControlModifier,
event->modifiers() & Qt::AltModifier);
+
+ if (m_dragMode != DragNone) {
+ // Selection dragging updates world position label to mesh center while dragging
+ updateWorldPositionLabelToDragHandle(EditorScene::DragTranslate, 1);
+ } else {
+ updateWorldPositionLabel(event->pos().x(), event->pos().y());
+ }
return (m_dragMode != DragNone);
}
diff --git a/editorlib/src/editorscene.h b/editorlib/src/editorscene.h
index c7c750c..8c6a89a 100644
--- a/editorlib/src/editorscene.h
+++ b/editorlib/src/editorscene.h
@@ -241,6 +241,8 @@ public:
Q_INVOKABLE void toggleEntityMultiSelection(const QString &name);
Q_INVOKABLE void clearMultiSelection();
Q_INVOKABLE QVector3D getMultiSelectionCenter();
+ Q_INVOKABLE void updateWorldPositionLabel(int xPos, int yPos);
+ Q_INVOKABLE void updateWorldPositionLabelToDragHandle(DragMode dragMode, int handleIndex = 0);
void removeEntityFromMultiSelection(const QString &name);
void addEntityToMultiSelection(const QString &name);
@@ -335,6 +337,7 @@ signals:
void endDragHandlesRepositioning();
void clipboardOperationChanged(ClipboardOperation clipboardOperation);
void clipboardContentChanged(const QString &clipboardContent);
+ void worldPositionLabelUpdate(const QString &wpX, const QString &wpY, const QString &wpZ);
protected:
bool eventFilter(QObject *obj, QEvent *event);
@@ -393,6 +396,7 @@ private:
void clearSingleSelection();
Q_INVOKABLE void doUpdateGroupSelectionBoxes();
void enableHelperArrows(bool enable);
+ void updateWorldPositionLabel(const QVector3D &worldPos);
private:
Qt3DCore::QEntity *m_rootEntity;
diff --git a/editorlib/src/editorsceneitem.cpp b/editorlib/src/editorsceneitem.cpp
index ec2aea5..5e8858a 100644
--- a/editorlib/src/editorsceneitem.cpp
+++ b/editorlib/src/editorsceneitem.cpp
@@ -468,13 +468,14 @@ void EditorSceneItem::doUpdateSelectionBoxTransform()
QMatrix4x4 transformMatrix = composeSelectionBoxTransform();
transformMatrix.translate(m_entityMeshCenter);
m_selectionBoxCenter = transformMatrix * QVector3D();
- m_selectionBoxExtents = m_entityMeshExtents + selectionBoxAdjuster;
- transformMatrix.scale(m_selectionBoxExtents);
+ m_unadjustedSelectionBoxExtents = m_entityMeshExtents;
+ m_unadjustedSelectionBoxMatrix = transformMatrix;
+ transformMatrix.scale(m_unadjustedSelectionBoxExtents + selectionBoxAdjuster);
QVector3D ancestralScale = EditorUtils::totalAncestralScale(m_entity);
- m_selectionBoxExtents *= ancestralScale;
+ m_unadjustedSelectionBoxExtents *= ancestralScale;
if (m_entityTransform)
- m_selectionBoxExtents *= m_entityTransform->scale3D();
+ m_unadjustedSelectionBoxExtents *= m_entityTransform->scale3D();
m_selectionTransform->setMatrix(transformMatrix);
diff --git a/editorlib/src/editorsceneitem.h b/editorlib/src/editorsceneitem.h
index a588152..bbd3815 100644
--- a/editorlib/src/editorsceneitem.h
+++ b/editorlib/src/editorsceneitem.h
@@ -30,6 +30,7 @@
#include <QtCore/QObject>
#include <QtGui/QVector3D>
+#include <QtGui/QMatrix4x4>
#include "editorsceneitemmeshcomponentsmodel.h" // For mesh type determination
@@ -94,8 +95,9 @@ public:
const QVariant &value);
Q_INVOKABLE QVariant customProperty(QObject *component, const QString name) const;
Qt3DCore::QTransform *selectionTransform() const { return m_selectionTransform; }
+ const QMatrix4x4 &unadjustedSelectionBoxMatrix() const { return m_unadjustedSelectionBoxMatrix; }
Qt3DCore::QTransform *entityTransform() const { return m_entityTransform; }
- QVector3D selectionBoxExtents() const { return m_selectionBoxExtents; }
+ QVector3D unadjustedSelectionBoxExtents() const { return m_unadjustedSelectionBoxExtents; }
QVector3D entityMeshExtents() const { return m_entityMeshExtents; }
Q_INVOKABLE QVector3D selectionBoxCenter() const { return m_selectionBoxCenter; }
QVector3D entityMeshCenter() const { return m_entityMeshCenter; }
@@ -140,6 +142,7 @@ private:
Qt3DCore::QEntity *m_selectionBox; // Created, but not owned
Qt3DCore::QTransform *m_selectionTransform; // Created, but not owned
+ QMatrix4x4 m_unadjustedSelectionBoxMatrix;
Qt3DCore::QTransform *m_entityTransform; // Not owned
Qt3DRender::QGeometryRenderer *m_entityMesh; // Not owned
EditorSceneItemMeshComponentsModel::MeshComponentTypes m_entityMeshType;
@@ -148,7 +151,7 @@ private:
QVector3D m_entityMeshExtents;
QVector3D m_entityMeshCenter;
- QVector3D m_selectionBoxExtents;
+ QVector3D m_unadjustedSelectionBoxExtents;
QVector3D m_selectionBoxCenter;
bool m_canRotate;