Skip to content

Commit 4586d25

Browse files
committed
#232 WIP.
Signed-off-by: cneben <[email protected]>
1 parent 1a18e3b commit 4586d25

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

src/GraphView.qml

+38-29
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Qan.AbstractGraphView {
7575
border.width: 2
7676
border.color: 'violet'
7777
transformOrigin: Qt.TopLeftCorner
78+
7879
z: 1 // Note: Do not remove, otherwise events are hidden !
7980
Component.onCompleted: {
8081
// Set initial content size
@@ -91,35 +92,43 @@ Qan.AbstractGraphView {
9192
navigable.contentY = (2000 / 2) - (navigable.height / 2.)
9293
*/
9394
}
94-
}
95-
96-
MouseArea {
97-
//hoverEnabled: true
98-
anchors.fill: parent
99-
onWheel: (wheel) => {
100-
console.error('HOPLA')
101-
// FIXME #232 take wheel intensity into account...
102-
const P = mapToGlobal(wheel.x, wheel.y)
103-
const scaleIncrement = wheel.angleDelta.y > 0. ? 0.5
104-
: -0.05;
105-
const preScale = graphContainerItem.scale
106-
graphContainerItem.scale += scaleIncrement
107-
const scale = graphContainerItem.scale
108-
109-
console.error(`graphContainerItem.scale=${graphContainerItem.scale}`)
110-
const preContentX = navigable.contentX
111-
const preContentY = navigable.contentY
112-
113-
console.error(`contentX=${navigable.contentX} contentY=${navigable.contentY}`)
114-
navigable.contentWidth = graphContainerItem.width * graphContainerItem.scale;
115-
navigable.contentHeight = graphContainerItem.height * graphContainerItem.scale;
116-
117-
const Pp = mapToGlobal(wheel.x, wheel.y)
118-
console.error(`P=${P} Pp=${Pp} PPp=${Qt.point((Pp.x - P.x), (Pp.y - P.y))}`)
119-
navigable.contentX = preContentX + (Pp.x - P.x)
120-
navigable.contentY = preContentY + (Pp.y - P.y)
121-
}
122-
onClicked: (mouse) => { console.error('HOPLA'); graphView.clicked(mouse) }
95+
MouseArea {
96+
//hoverEnabled: true
97+
anchors.fill: parent
98+
onWheel: (wheel) => {
99+
// FIXME #232 take wheel intensity into account...
100+
console.error(`wheel.x=${wheel.x} wheel.y=${wheel.y}`)
101+
const P = mapToGlobal(wheel.x, wheel.y)
102+
//const P = mapToItem(contentItem, wheel.x, wheel.y)
103+
const scaleIncrement = wheel.angleDelta.y > 0. ? 0.25
104+
: -0.25;
105+
const preScale = graphContainerItem.scale
106+
graphContainerItem.scale += scaleIncrement
107+
const scale = graphContainerItem.scale
108+
109+
//console.error(`graphContainerItem.scale=${graphContainerItem.scale}`)
110+
const preContentX = navigable.contentX
111+
const preContentY = navigable.contentY
112+
113+
//console.error(`contentX=${navigable.contentX} contentY=${navigable.contentY}`)
114+
navigable.contentWidth = graphContainerItem.width * graphContainerItem.scale;
115+
navigable.contentHeight = graphContainerItem.height * graphContainerItem.scale;
116+
117+
//const Pp = graphContainerItem.mapFromGlobal(wheel.x, wheel.y)
118+
const Pp = mapToGlobal(wheel.x, wheel.y)
119+
//const Pp = mapToItem(contentItem, wheel.x, wheel.y)
120+
121+
//const Pp = Qt.point(P.x * (1 + scaleIncrement), P.y * (1. + scaleIncrement));
122+
console.error(`P=${P} Pp=${Pp} PPp=${Qt.point((Pp.x - P.x), (Pp.y - P.y))}`)
123+
navigable.contentX = preContentX + (Pp.x - P.x)
124+
navigable.contentY = preContentY + (Pp.y - P.y)
125+
//navigable.contentX *= graphContainerItem.scale
126+
//navigable.contentY *= graphContainerItem.scale
127+
navigable.returnToBounds();
128+
}
129+
130+
onClicked: (mouse) => { graphView.clicked(mouse) }
131+
}
123132
}
124133
}
125134
onRequestDisableNavigable: navigable.interactive = false

src/qanDraggableCtrl.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ bool DraggableCtrl::handleMouseMoveEvent(QMouseEvent* event)
131131
const auto rootItem = getGraph()->getContainerItem();
132132
if (rootItem != nullptr && // Root item exist, left button is pressed and the target item
133133
event->buttons().testFlag(Qt::LeftButton)) { // is draggable and not collapsed
134-
const auto sceneDragPos = event->scenePosition();
134+
//const auto sceneDragPos = event->scenePosition();
135+
// FIXME #232
136+
const auto sceneDragPos = graph->getContainerItem()->mapFromScene(event->scenePosition());
135137
if (!_targetItem->getDragged()) {
136138
// Project in scene rect (for example is a node is part of a group)
137139
beginDragMove(sceneDragPos, _targetItem->getSelected());

0 commit comments

Comments
 (0)