Apparently, the gap lies into the QML code that uses property bindings. when an element is rotated, I tried to also change its position, but if I do so all elements become jammed, so I tried to use a bool to prevent X and Y OnChanged to fire during such updates, but without any effect. I also tried to add a C++ member to change at the same time X, Y and Rotation, but it still doesn't work. Maybe do I need to momentarily disable the property binding (thing that I'm not sure can be done).
here's my QML Code
MouseArea { // DRAG pour déplacer la vue
anchors.fill : parent
acceptedButtons: Qt.LeftButton
drag.target: vue2D
cursorShape: Qt.ArrowCursor
}
Repeater { // UNE PIECE COMPLETE
model: pieces
delegate : Shape { id : pieceRoot
containsMode: Shape.FillContains
DragHandler {cursorShape: Qt.ClosedHandCursor}
states: [
State {
name: ""
PropertyChanges { pieceSP.strokeWidth: -1 }
},
State {
name: "selected"
PropertyChanges { pieceSP.strokeWidth: 2 }
}
]
ShapePath { id: pieceSP // POLYGONE FORMANT LA PIECE
fillRule: ShapePath.WindingFill
fillColor: iToC[coul]
strokeColor:"yellow"
PathSvg { path: contour }
}
property real tmpPosX : posX
property real tmpPosY : posY
property real tmpAngle : angle
property bool rotEnCours : false
x: tmpPosX
y: tmpPosY
rotation: tmpAngle
onXChanged: {
if (!rotEnCours)
pieces.setPosX(index, x);
}
onYChanged: {
if (!rotEnCours)
pieces.setPosY(index, y);
}
onRotationChanged: {
rotEnCours = true;
pieces.setAngle(index, rotation);
rotEnCours = false;
// pieces.setPosX(index, x);
// pieces.setPosY(index, y);
}
Text { // NUMERO DE LA PIECE (aka n° de sa première facette)
font.pointSize: 10
color: "black"
text: num
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
x: centre.x - (contentWidth /2)
y: centre.y - (contentHeight /2)
}
Repeater { // CHAQUE NUMERO D'ARETE (ENTRE 2 FACETTES)
model: ListModel {id: tliste}
Text {
text: model.txt
font.pointSize: 6
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
color: "#1500ff"
transform: [
Translate { x: 0; y: -7 },
Rotation { angle: 180+model.a },
Translate { x: model.x; y: model.y }
]
}
}
Component.onCompleted: creeNums(tliste, nTxt)
Repeater { // CHAQUE LIGNE DE CONTOUR
model: ListModel {id: cliste}
Shape {
containsMode: Shape.FillContains
HoverHandler { id: mouseCont
cursorShape: Qt.CrossCursor
}
property int f1: model.f1
property int f2: model.f2
property var c: mouseCont.hovered ? "yellow" : "black"
ShapePath {
strokeWidth: 0.25
strokeColor: c
fillColor: c
startX: model.x1
startY: model.y1
PathPolyline {
path: [
Qt.point(model.x2, model.y2),
Qt.point(model.x3, model.y3),
Qt.point(model.x4, model.y4),
Qt.point(model.x1, model.y1),
]
}
pathHints: ShapePath.PathSolid || ShapePath.PathLinear || ShapePath.PathConvex;
}
TapHandler {
onTapped: {
faces.attache(num, f1, f2);
}
}
}
Component.onCompleted: creeLignes(lcont, cliste)
}
Repeater { // CHAQUE LIGNE DE PLI
model: ListModel {id: pliste}
Shape {
containsMode: Shape.FillContains
HoverHandler { id: mousePlis
cursorShape: Qt.CrossCursor
}
property int f1: model.f1
property int f2: model.f2
property var c: mousePlis.hovered ? "red" : "white"
ShapePath {
strokeWidth: 0.25
strokeColor: c
fillColor: c
startX: model.x1
startY: model.y1
PathPolyline {
path: [
Qt.point(model.x2, model.y2),
Qt.point(model.x3, model.y3),
Qt.point(model.x4, model.y4),
Qt.point(model.x1, model.y1),
]
}
pathHints: ShapePath.PathSolid || ShapePath.PathLinear || ShapePath.PathConvex;
}
TapHandler {
onTapped: {
faces.detache(num, f1, f2);
}
}
}
Component.onCompleted: creeLignes(plis, pliste)
}
WheelHandler { // ALT + roulette pour tourner la pièce
acceptedModifiers: Qt.AltModifier
property: "rotation"
//rotationScale: 0.25
}
/*MouseArea { // clic gauche sur une pièce -> selection / déselection
anchors.fill: pieceRoot
acceptedButtons: Qt.LeftButton
onClicked: {
pieceRoot.state = pieceRoot.state === "" ? "selected" : "";
}
}*/
}
}