Skip to content

Commit 53b13a2

Browse files
committed
#232 Giving up...
Signed-off-by: cneben <[email protected]>
1 parent 4586d25 commit 53b13a2

File tree

4 files changed

+63
-33
lines changed

4 files changed

+63
-33
lines changed

src/GraphView.qml

+27-33
Original file line numberDiff line numberDiff line change
@@ -62,68 +62,62 @@ Qan.AbstractGraphView {
6262
Flickable {
6363
id: navigable
6464
anchors.fill: parent
65-
clip: true
65+
clip: false
6666
ScrollBar.vertical: ScrollBar { }
6767
ScrollBar.horizontal: ScrollBar { }
6868
// Note: keep pressDelay to 0 otherwise it broke event dispatching
6969
boundsMovement: Flickable.DragAndOvershootBounds
7070

7171
Rectangle {
72-
id: graphContainerItem
73-
width: 3000
74-
height: 2000
72+
id: graphContainer
73+
width: graphView.graphBr.width
74+
height: graphView.graphBr.height
7575
border.width: 2
7676
border.color: 'violet'
7777
transformOrigin: Qt.TopLeftCorner
78-
7978
z: 1 // Note: Do not remove, otherwise events are hidden !
8079
Component.onCompleted: {
81-
// Set initial content size
82-
//navigable.resizeContent(3000, 2000, null)
83-
// FIXME: Laisser comme cela, mais il faudra un code d'initialisation "dédié" pour
84-
// faire le centrage initial de la vue:
85-
// avec un flag sur onSizeChanged() pas le choix, ici la taille est à 0...
86-
navigable.contentWidth = 3000
87-
navigable.contentHeight = 2000
88-
/*console.error('navigable.width=' + navigable.width)
89-
console.error('navigable.contentItem.width=' + navigable.contentItem.width)
90-
// Resize view to center
91-
navigable.contentX = (3000 / 2) - (navigable.width / 2.) // FIXME simplify expression /2
92-
navigable.contentY = (2000 / 2) - (navigable.height / 2.)
93-
*/
80+
//updateGraphBr(Qt.rect(0., 0., 3000, 2000))
81+
}
82+
function updateGraphBr(graphBr) {
83+
console.error('updateGraphBr(): graphBr=' + graphBr)
84+
if (!graphBr)
85+
return;
86+
//const contentBr = graphContainer.childrenRect
87+
navigable.contentWidth = graphBr.width * graphContainer.scale;
88+
navigable.contentHeight = graphBr.height * graphContainer.scale;
89+
graphContainer.x = (-graphBr.x * graphContainer.scale);
90+
graphContainer.y = (-graphBr.y * graphContainer.scale);
9491
}
92+
9593
MouseArea {
9694
//hoverEnabled: true
9795
anchors.fill: parent
9896
onWheel: (wheel) => {
9997
// FIXME #232 take wheel intensity into account...
10098
console.error(`wheel.x=${wheel.x} wheel.y=${wheel.y}`)
10199
const P = mapToGlobal(wheel.x, wheel.y)
102-
//const P = mapToItem(contentItem, wheel.x, wheel.y)
103100
const scaleIncrement = wheel.angleDelta.y > 0. ? 0.25
104101
: -0.25;
105-
const preScale = graphContainerItem.scale
106-
graphContainerItem.scale += scaleIncrement
107-
const scale = graphContainerItem.scale
102+
const preScale = graphContainer.scale
103+
graphContainer.scale += scaleIncrement
104+
const scale = graphContainer.scale
108105

109-
//console.error(`graphContainerItem.scale=${graphContainerItem.scale}`)
106+
//console.error(`graphContainer.scale=${graphContainer.scale}`)
110107
const preContentX = navigable.contentX
111108
const preContentY = navigable.contentY
112109

113110
//console.error(`contentX=${navigable.contentX} contentY=${navigable.contentY}`)
114-
navigable.contentWidth = graphContainerItem.width * graphContainerItem.scale;
115-
navigable.contentHeight = graphContainerItem.height * graphContainerItem.scale;
111+
//const graphContainerBr = graphContainer.childrenRect
112+
navigable.contentWidth = graphView.graphBr.width * graphContainer.scale;
113+
navigable.contentHeight = graphView.graphBr.height * graphContainer.scale;
114+
//graphContainer.x = (-graphContainerBr.x * graphContainer.scale);
115+
//graphContainer.y = (-graphContainerBr.y * graphContainer.scale);
116116

117-
//const Pp = graphContainerItem.mapFromGlobal(wheel.x, wheel.y)
118117
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));
122118
console.error(`P=${P} Pp=${Pp} PPp=${Qt.point((Pp.x - P.x), (Pp.y - P.y))}`)
123119
navigable.contentX = preContentX + (Pp.x - P.x)
124120
navigable.contentY = preContentY + (Pp.y - P.y)
125-
//navigable.contentX *= graphContainerItem.scale
126-
//navigable.contentY *= graphContainerItem.scale
127121
navigable.returnToBounds();
128122
}
129123

@@ -133,8 +127,8 @@ Qan.AbstractGraphView {
133127
}
134128
onRequestDisableNavigable: navigable.interactive = false
135129
onRequestEnableNavigable: navigable.interactive = true
136-
137-
containerItem: graphContainerItem
130+
onRequestUpdateGraphBr: (graphBr) => { graphContainer.updateGraphBr(graphBr) }
131+
containerItem: graphContainer
138132
Qan.LineGrid {
139133
id: lineGrid
140134
}

src/qanDraggableCtrl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ void DraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection,
357357
const auto targetGroupPos = graphContainerItem->mapToItem(targetGroupItem, targetScenePos);
358358
_targetItem->setPosition(targetGroupPos);
359359
} else {
360+
//const auto graphContainerItem = graph->getContainerItem();
361+
//if (graphContainerItem == nullptr)
362+
// return;
363+
qWarning() << "targetScenePos=" << targetScenePos;
360364
_targetItem->setPosition(targetScenePos);
361365
}
362366

src/qanGraphView.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,42 @@ GraphView::GraphView(QQuickItem* parent) :
4848
QQuickItem{parent}
4949
{
5050
setFocus(true);
51+
_graphBr = QRectF{-1000, -750, 2000, 1500};
5152
}
5253
//-----------------------------------------------------------------------------
5354

5455

5556
/* View Flickable Management *///----------------------------------------------
5657
QQuickItem* GraphView::getContainerItem() { return _containerItem.data(); }
5758
const QQuickItem* GraphView::getContainerItem() const { return _containerItem.data(); }
59+
5860
void GraphView::setContainerItem(QQuickItem* containerItem) {
5961
_containerItem = containerItem;
6062
emit containerItemChanged();
6163
if (_graph)
6264
_graph->setContainerItem(containerItem);
65+
// FIXME 232
66+
connect(containerItem, &QQuickItem::childrenRectChanged,
67+
this, &GraphView::updateGraphBr);
68+
// Set the flickable initial size BTW...
69+
emit requestUpdateGraphBr(_graphBr);
70+
}
71+
72+
void GraphView::updateGraphBr(const QRectF& childrenRect)
73+
{
74+
qWarning() << "GraphView::updateGraphBr(): childrenRect=" << childrenRect;
75+
if (_graphBr.contains(childrenRect))
76+
return;
77+
bool growLeft = childrenRect.left() < _graphBr.left();
78+
bool growRight= childrenRect.right() > _graphBr.right();
79+
bool growTop = childrenRect.top() < _graphBr.top();
80+
bool growBottom = childrenRect.bottom() > _graphBr.bottom();
81+
_graphBr = _graphBr.united(childrenRect);
82+
_graphBr.adjust(growLeft ? -50 : 0.,
83+
growTop ? -50 : 0.,
84+
growRight ? 50 : 0.,
85+
growBottom ? 50 : 0.);
86+
emit requestUpdateGraphBr(_graphBr);
6387
}
6488
//-----------------------------------------------------------------------------
6589

src/qanGraphView.h

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ class GraphView : public QQuickItem
8383
signals:
8484
void containerItemChanged();
8585

86+
public:
87+
Q_PROPERTY(QRectF graphBr READ getGraphBr NOTIFY containerItemChanged FINAL)
88+
QRectF getGraphBr() { return _graphBr; }
89+
QRectF _graphBr;
90+
void updateGraphBr(const QRectF& childrenRect);
91+
signals:
92+
void requestUpdateGraphBr(const QRectF& childrenRect);
93+
8694
public:
8795
void disableNavigable() { emit requestDisableNavigable(); }
8896
void enableNavigable() { emit requestEnableNavigable(); }

0 commit comments

Comments
 (0)