Skip to content

Commit 7c7d902

Browse files
committed
#232 Tentative suppression of qan::Navigable. WIP.
Signed-off-by: cneben <[email protected]>
1 parent 33e2cb1 commit 7c7d902

File tree

5 files changed

+195
-15
lines changed

5 files changed

+195
-15
lines changed

samples/groups/groups.qml

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ ApplicationWindow {
4545
Qan.GraphView {
4646
id: graphView
4747
anchors.fill: parent
48-
navigable: true
48+
// FIXME #232
49+
//navigable: true
4950
function centerItem(item) {
5051
if (!item)
5152
return
@@ -328,7 +329,8 @@ ApplicationWindow {
328329
Qan.GraphPreview {
329330
id: graphPreview
330331
source: graphView
331-
viewWindowColor: Material.accent
332+
// FIXME #232
333+
//viewWindowColor: Material.accent
332334
anchors.horizontalCenter: parent.horizontalCenter
333335
anchors.bottom: graphView.bottom
334336
anchors.bottomMargin: 8

src/GraphPreview.qml

+11-5
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ Control {
4444
//! Source Qan.GraphView that should be previewed.
4545
property var source: undefined
4646

47-
property alias viewWindowColor: navigablePreview.viewWindowColor
47+
// FIXME #232 nommage horrible
48+
//property alias viewWindowColor: navigablePreview.viewWindowColor
4849

4950
// Preview background panel opacity (default to 0.9).
5051
property alias previewOpactity: previewBackground.opacity
5152

5253
//! Initial (and minimum) scene rect (should usually fit your initial screen size).
53-
property alias initialRect: navigablePreview.initialRect
54+
// FIXME #232
55+
//property alias initialRect: navigablePreview.initialRect
5456

5557
// PRIVATE ////////////////////////////////////////////////////////////////
5658
padding: 0
@@ -73,7 +75,7 @@ Control {
7375
// 2. If navigable preview height (nph) < preview height (ph), then use graphRatio to
7476
// generate nph.
7577
// 3. Else compute navigable preview width using previewRatio and fix nph to ph.
76-
if (!source)
78+
if (!source || !source.containerItem)
7779
return
7880
const pw = graphPreview.width
7981
const ph = graphPreview.height
@@ -99,8 +101,9 @@ Control {
99101
nph = nph * (pw / npw)
100102

101103
// Secure with boundary Check
102-
navigablePreview.width = Math.min(npw, pw)
103-
navigablePreview.height = Math.min(nph, ph)
104+
// FIXME #232
105+
//navigablePreview.width = Math.min(npw, pw)
106+
//navigablePreview.height = Math.min(nph, ph)
104107
}
105108

106109
opacity: 0.8
@@ -133,10 +136,13 @@ Control {
133136
''
134137
font.pixelSize: 11
135138
}
139+
// FIXME #232 (and rename to Flickable Preview !)
140+
/*
136141
Qan.NavigablePreview {
137142
id: navigablePreview
138143
anchors.centerIn: parent
139144
source: graphPreview.source
140145
} // Qan.NavigablePreview
146+
*/
141147
}
142148
} // Control graph preview

src/GraphView.qml

+95-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
//-----------------------------------------------------------------------------
3434

3535
import QtQuick
36+
import QtQuick.Controls
3637

3738
import QuickQanava 2.0 as Qan
3839
import "qrc:/QuickQanava" as Qan
@@ -58,6 +59,98 @@ Qan.AbstractGraphView {
5859
property size resizeHandlerSize: "9x9"
5960

6061
// PRIVATE ////////////////////////////////////////////////////////////////
62+
Flickable {
63+
id: navigable
64+
anchors.fill: parent
65+
clip: true
66+
ScrollBar.vertical: ScrollBar { }
67+
ScrollBar.horizontal: ScrollBar { }
68+
69+
//transformOrigin:
70+
71+
//onWidthChanged: console.error('width=' + width)
72+
//onHeightChanged: console.error('height=' + height)
73+
boundsMovement: Flickable.DragAndOvershootBounds
74+
75+
DragHandler {
76+
property real _startX
77+
property real _startY
78+
acceptedButtons: Qt.RightButton
79+
dragThreshold: 0
80+
target: null
81+
onActiveChanged: {
82+
if (active) {
83+
_startX = navigable.contentX
84+
_startY = navigable.contentY
85+
}
86+
}
87+
onTranslationChanged: {
88+
navigable.contentX = _startX - translation.x
89+
navigable.contentY = _startY - translation.y
90+
}
91+
}
92+
93+
Rectangle {
94+
id: graphContainerItem
95+
width: 3000
96+
height: 2000
97+
border.width: 2
98+
border.color: 'violet'
99+
transformOrigin: Qt.TopLeftCorner
100+
101+
Component.onCompleted: {
102+
console.error('!!!setContainerItem(): graphContainerItem=' + graphContainerItem)
103+
graphView.containerItem = graphContainerItem
104+
105+
// Set initial content size
106+
//navigable.resizeContent(3000, 2000, null)
107+
// FIXME: Laisser comme cela, mais il faudra un code d'initialisation "dédié" pour
108+
// faire le centrage initial de la vue:
109+
// avec un flag sur onSizeChanged() pas le choix, ici la taille est à 0...
110+
navigable.contentWidth = 3000
111+
navigable.contentHeight = 2000
112+
/*console.error('navigable.width=' + navigable.width)
113+
console.error('navigable.contentItem.width=' + navigable.contentItem.width)
114+
// Resize view to center
115+
navigable.contentX = (3000 / 2) - (navigable.width / 2.) // FIXME simplify expression /2
116+
navigable.contentY = (2000 / 2) - (navigable.height / 2.)
117+
*/
118+
}
119+
120+
MouseArea {
121+
hoverEnabled: true
122+
anchors.fill: parent
123+
onWheel: (wheel) => {
124+
// FIXME take wheel intensity into account...
125+
const P = mapToGlobal(wheel.x, wheel.y)
126+
const scaleIncrement = wheel.angleDelta.y > 0. ? 0.5
127+
: -0.05;
128+
const preScale = graphContainerItem.scale
129+
graphContainerItem.scale += scaleIncrement
130+
const scale = graphContainerItem.scale
131+
132+
console.error(`graphContainerItem.scale=${graphContainerItem.scale}`)
133+
const preContentX = navigable.contentX
134+
const preContentY = navigable.contentY
135+
136+
console.error(`contentX=${navigable.contentX} contentY=${navigable.contentY}`)
137+
navigable.contentWidth = graphContainerItem.width * graphContainerItem.scale;
138+
navigable.contentHeight = graphContainerItem.height * graphContainerItem.scale;
139+
140+
const Pp = mapToGlobal(wheel.x, wheel.y)
141+
//const Pp = Qt.point(P.x * scale,
142+
// P.y * scale)
143+
//const Pp = Qt.point(P.x * 1. + scaleIncrement,
144+
// P.y * 1. + scaleIncrement)
145+
console.error(`P=${P} Pp=${Pp} PPp=${Qt.point((Pp.x - P.x), (Pp.y - P.y))}`)
146+
navigable.contentX = preContentX + (Pp.x - P.x)
147+
navigable.contentY = preContentY + (Pp.y - P.y)
148+
}
149+
onClicked: (mouse) => { graphView.clicked(mouse) }
150+
}
151+
}
152+
}
153+
61154
Qan.LineGrid {
62155
id: lineGrid
63156
}
@@ -171,7 +264,8 @@ Qan.AbstractGraphView {
171264
color: Qt.rgba(0, 0, 0, 0) // transparent
172265
visible: false
173266
}
174-
selectionRectItem: selectionRect
267+
// fIXME #232
268+
//selectionRectItem: selectionRect
175269

176270
// View Click management //////////////////////////////////////////////////
177271
onClicked: {

src/qanGraphView.cpp

+42-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,44 @@ GraphView::GraphView(QQuickItem* parent) :
5757
//-----------------------------------------------------------------------------
5858

5959

60-
/* raph Interactions *///------------------------------------------------------
60+
/* Grid Management *///--------------------------------------------------------
61+
void GraphView::setGrid(qan::Grid* grid) noexcept
62+
{
63+
if (grid != _grid) {
64+
if (_grid) { // Hide previous grid
65+
disconnect(_grid, nullptr,
66+
this, nullptr); // Disconnect every update signals from grid to this navigable
67+
}
68+
_grid = grid; // Configure new grid
69+
if (_grid) {
70+
_grid->setParentItem(this);
71+
_grid->setZ(-1.0);
72+
_grid->setAntialiasing(false);
73+
_grid->setScale(1.0);
74+
connect(_grid, &QQuickItem::visibleChanged, // Force updateGrid when visibility is changed to eventually
75+
this, &GraphView::updateGrid); // take into account any grid property change while grid was hidden.
76+
}
77+
if (!_grid)
78+
_grid = _defaultGrid.get(); // Do not connect default grid, it is an "empty grid"
79+
updateGrid();
80+
emit gridChanged();
81+
}
82+
}
83+
84+
void GraphView::updateGrid() noexcept
85+
{
86+
if (_grid &&
87+
_containerItem != nullptr) {
88+
// Generate a view rect to update grid
89+
QRectF viewRect{_containerItem->mapFromItem(this, {0.,0.}),
90+
_containerItem->mapFromItem(this, {width(), height()})};
91+
if (!viewRect.isEmpty())
92+
_grid->updateGrid(viewRect, *_containerItem, *this);
93+
}
94+
}
95+
//-----------------------------------------------------------------------------
96+
97+
/* Graph Interactions *///-----------------------------------------------------
6198
void GraphView::setGraph(qan::Graph* graph)
6299
{
63100
if (graph == nullptr) {
@@ -245,15 +282,18 @@ void GraphView::keyPressEvent(QKeyEvent *event)
245282
}
246283

247284
// If no selection, move the underlying graph view
285+
// FIXME #232
286+
/*
248287
if ((_graph->getSelectedNodes().size() + _graph->getSelectedGroups().size()) <= 0) {
249288
const auto p = QPointF{containerItem->x(),
250289
containerItem->y()} - delta;
251290
containerItem->setX(p.x());
252291
containerItem->setY(p.y());
253-
emit containerItemModified();
292+
//emit containerItemModified();
254293
event->accept();
255294
return;
256295
}
296+
*/
257297

258298
// Otherwise handle multiple selection (ie move selection)
259299
if (delta.manhattanLength() > 0.) {

src/qanGraphView.h

+43-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "./qanGroup.h"
4040
//#include "./qanNavigable.h"
4141
#include "./qanPortItem.h"
42+
#include "./qanGrid.h"
4243

4344
// Qt headers
4445
#include <QQuickItem>
@@ -63,8 +64,7 @@ class GraphView : public QQuickItem
6364
//@}
6465
//-------------------------------------------------------------------------
6566

66-
67-
/*! \name View Flickable Management *///---------------------------------
67+
/*! \name View Flickable Management *///-----------------------------------
6868
//@{
6969
public:
7070
/*! \brief Parent container for area child items.
@@ -91,14 +91,53 @@ class GraphView : public QQuickItem
9191
* \endcode
9292
*
9393
*/
94-
Q_PROPERTY(QQuickItem* containerItem READ getContainerItem CONSTANT FINAL)
94+
Q_PROPERTY(QQuickItem* containerItem READ getContainerItem WRITE setContainerItem NOTIFY containerItemChanged FINAL)
95+
// FIXME #232 do not inline that
9596
//! \sa containerItem
96-
inline QQuickItem* getContainerItem() noexcept { return _containerItem.data(); }
97+
QQuickItem* getContainerItem() noexcept { return _containerItem.data(); }
98+
void setContainerItem(QQuickItem* containerItem) noexcept { _containerItem = containerItem; emit containerItemChanged(); }
9799
private:
98100
QPointer<QQuickItem> _containerItem = nullptr;
101+
signals:
102+
void containerItemChanged();
103+
104+
// #323 sitck with old qan::Navigable interface...
105+
signals:
106+
//! Emitted whenever the mouse is clicked in graph view.
107+
void clicked(QVariant pos);
108+
109+
//! Emitted whenever the mouse is right clicked in graph view.
110+
// FIXME #232
111+
void rightClicked(QVariant pos);
99112
//@}
100113
//-------------------------------------------------------------------------
101114

115+
/*! \name Grid Management *///---------------------------------------------
116+
//@{
117+
public:
118+
/*! \brief User defined background grid.
119+
*
120+
* Grid is automatically updated on zoom/pan or navigable content view modification.
121+
*
122+
* \note may be nullptr (undefined in QML).
123+
*/
124+
Q_PROPERTY(qan::Grid* grid READ getGrid WRITE setGrid NOTIFY gridChanged FINAL)
125+
//! \copydoc grid
126+
qan::Grid* getGrid() noexcept { return _grid.data(); }
127+
const qan::Grid* getGrid() const noexcept { return _grid.data(); }
128+
void setGrid(qan::Grid* grid) noexcept;
129+
private:
130+
//! Force update of grid.
131+
void updateGrid() noexcept;
132+
//! \copydoc grid
133+
QPointer<qan::Grid> _grid;
134+
135+
std::unique_ptr<qan::Grid> _defaultGrid;
136+
signals:
137+
//! \copydoc grid
138+
void gridChanged();
139+
//@}
140+
//-------------------------------------------------------------------------
102141

103142
/*! \name Graph Interactions *///------------------------------------------
104143
//@{
@@ -143,7 +182,6 @@ class GraphView : public QQuickItem
143182
//@}
144183
//-------------------------------------------------------------------------
145184

146-
147185
/*! \name Selection Rectangle Management *///------------------------------
148186
//@{
149187
protected:

0 commit comments

Comments
 (0)