Skip to content

Commit badfa8a

Browse files
committed
[qml] Shape/Viewer: Change shape and name label in PointLayer
1 parent 9746c52 commit badfa8a

File tree

1 file changed

+66
-47
lines changed

1 file changed

+66
-47
lines changed

meshroom/ui/qml/Shapes/Viewer/Layers/PointLayer.qml

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import QtQuick
2+
import QtQuick.Shapes
3+
4+
import "Utils" as LayerUtils
25

36
/**
47
* PointLayer
@@ -15,65 +18,81 @@ import QtQuick
1518
BaseLayer {
1619
id: pointLayer
1720

18-
// Point size from scaled properties.size
19-
property real pointSize: pointLayer.getScaledPointSize()
21+
// Point size and half size
22+
property real pointSize: Math.max(1.0, 12.0 * scaleRatio)
23+
property real pointHalfSize: pointSize * 0.5
2024

2125
// Point shape
22-
Rectangle {
23-
id: draggablePoint
24-
x: pointLayer.observation.x - (pointSize * 0.5)
25-
y: pointLayer.observation.y - (pointSize * 0.5)
26-
width: pointSize
27-
height: width
28-
color: selected ? "#ffffff" : pointLayer.properties.color || pointLayer.defaultColor
29-
30-
// Selection click
31-
TapHandler {
26+
Shape {
27+
id: draggableShape
28+
29+
// Center cross path
30+
ShapePath {
31+
fillColor: "transparent"
32+
strokeColor: selected ? "#ffffff" : pointLayer.properties.color || pointLayer.defaultColor
33+
strokeWidth: getScaledStrokeWidth()
34+
35+
PathMove { x: pointLayer.observation.x - pointSize; y: pointLayer.observation.y }
36+
PathLine { x: pointLayer.observation.x + pointSize; y: pointLayer.observation.y }
37+
PathMove { x: pointLayer.observation.x; y: pointLayer.observation.y - pointSize }
38+
PathLine { x: pointLayer.observation.x; y: pointLayer.observation.y + pointSize }
39+
}
40+
41+
// Selection area
42+
MouseArea {
43+
x: handleCenter.x - pointSize
44+
y: handleCenter.y - pointSize
45+
width: pointSize * 2
46+
height: pointSize * 2
3247
acceptedButtons: Qt.LeftButton
33-
gesturePolicy: TapHandler.WithinBounds
34-
grabPermissions: PointerHandler.CanTakeOverFromAnything
35-
margin: pointSize
36-
onTapped: selectionRequested()
48+
cursorShape: pointLayer.editable ? Qt.PointingHandCursor : Qt.ArrowCursor
49+
onClicked: selectionRequested()
3750
enabled: pointLayer.editable && !pointLayer.selected
3851
}
39-
40-
// Selection hover
41-
HoverHandler {
42-
cursorShape: pointLayer.selected ? Qt.SizeAllCursor : Qt.PointingHandCursor
43-
grabPermissions: PointerHandler.CanTakeOverFromAnything
44-
margin: pointSize
45-
enabled: pointLayer.editable
46-
}
4752

48-
// Drag
49-
DragHandler {
50-
target: draggablePoint
53+
// Handle for point center
54+
LayerUtils.Handle {
55+
id: handleCenter
56+
x: pointLayer.observation.x || 0
57+
y: pointLayer.observation.y || 0
58+
size: getScaledHandleSize()
59+
target: draggableShape
5160
cursorShape: Qt.SizeAllCursor
52-
enabled: pointLayer.editable && pointLayer.selected
53-
onActiveChanged: {
54-
if (!active) {
55-
_reconstruction.setObservationFromName(pointLayer.name, _reconstruction.selectedViewId, {
56-
x: draggablePoint.x + pointSize * 0.5,
57-
y: draggablePoint.y + pointSize * 0.5
58-
})
59-
}
61+
visible: pointLayer.editable && pointLayer.selected
62+
onMoved: {
63+
_reconstruction.setObservationFromName(pointLayer.name, _reconstruction.selectedViewId, {
64+
x: handleCenter.x + draggableShape.x,
65+
y: handleCenter.y + draggableShape.y
66+
})
6067
}
6168
}
6269

6370
// Point name
64-
Text {
65-
x: pointSize
66-
y: pointSize
67-
text: {
68-
const lastDotIndex = pointLayer.name.lastIndexOf('.')
69-
if(lastDotIndex < 0)
70-
return pointLayer.name
71-
return pointLayer.name.substring(lastDotIndex + 1);
71+
Rectangle {
72+
x: (pointLayer.observation.x || 0) + pointHalfSize
73+
y: (pointLayer.observation.y || 0) + pointHalfSize
74+
width: pointName.width
75+
height: pointName.height
76+
visible: pointLayer.editable && scaleRatio > 0.2
77+
color: selected ? palette.shadow : palette.window
78+
79+
Text {
80+
id: pointName
81+
text: {
82+
if(pointLayer.properties.userName && pointLayer.properties.userName.length > 0)
83+
return pointLayer.properties.userName
84+
const lastDotIndex = pointLayer.name.lastIndexOf('.')
85+
if(lastDotIndex < 0)
86+
return pointLayer.name
87+
return pointLayer.name.substring(lastDotIndex + 1);
88+
}
89+
color: selected ? palette.highlightedText : palette.text
90+
padding: 0
91+
rightPadding: Math.max(1, 2 * scaleRatio)
92+
leftPadding: rightPadding
93+
wrapMode: Text.NoWrap
94+
font.pixelSize: getScaledFontSize()
7295
}
73-
color: draggablePoint.color
74-
wrapMode: Text.NoWrap
75-
font.pixelSize: getScaledFontSize()
76-
visible: pointLayer.editable && scaleRatio > 0.1
7796
}
7897
}
7998
}

0 commit comments

Comments
 (0)