From 705cbc682fcda24766a5d4abfb29ddd86f394432 Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:57:23 +0200 Subject: [PATCH 1/8] Group right-click menu: Colour... picks the group background colour contextMenuEvent was an empty stub, so a group's colour could only be set by editing the saved JSON. The colour is stored in r/g/b, which Group::save() already writes. Co-Authored-By: Claude Opus 5 --- src/GroupGraphicsObject.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/GroupGraphicsObject.cpp b/src/GroupGraphicsObject.cpp index facd4d782..7fdb29239 100644 --- a/src/GroupGraphicsObject.cpp +++ b/src/GroupGraphicsObject.cpp @@ -644,5 +644,18 @@ void GroupGraphicsObject:: contextMenuEvent(QGraphicsSceneContextMenuEvent* event) { - + QMenu menu; + QAction* colourAction = menu.addAction("Colour..."); + if (menu.exec(event->screenPos()) == colourAction) + { + QColor c = QColorDialog::getColor(QColor(r, g, b), nullptr, "Group colour"); + if (c.isValid()) + { + r = c.red(); + g = c.green(); + b = c.blue(); + update(); + } + } + event->accept(); } From 8c0be6a94acb5f3f12905d83d430b64dcd3c1b90 Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Mon, 21 Sep 2026 21:07:02 +0200 Subject: [PATCH 2/8] Blender-style navigation option for FlowView (node editor) FlowView::setNavigation(blender, trackpadScroll), default Blender + trackpad: middle-drag or Alt+left-drag pans, Ctrl+that zooms, left-drag on empty space box-selects, Home frames all nodes; trackpad scroll pans and Ctrl+scroll (pinch) zooms at the cursor, or the wheel zooms in mouse mode. blender=false keeps the original left-drag pan / wheel step zoom. Co-Authored-By: Claude Opus 5 --- include/nodes/internal/FlowView.hpp | 20 +++++ src/FlowView.cpp | 124 +++++++++++++++++++++++++++- 2 files changed, 140 insertions(+), 4 deletions(-) diff --git a/include/nodes/internal/FlowView.hpp b/include/nodes/internal/FlowView.hpp index 302e4bf1a..0fb836d5a 100644 --- a/include/nodes/internal/FlowView.hpp +++ b/include/nodes/internal/FlowView.hpp @@ -36,6 +36,15 @@ class NODE_EDITOR_PUBLIC FlowView void goToNode(NodeGraphicsObject *node); void goToNodeID(QUuid ID); + /// Navigation style for every FlowView (set from the app's preferences). + /// blender: middle-drag / Alt+left-drag pans, Ctrl+(that) zooms, left-drag on empty space box-selects, + /// Home frames all nodes. trackpadScroll: two-finger scroll pans and Ctrl+scroll (pinch) zooms; + /// otherwise the wheel zooms at the cursor. blender=false keeps the original behaviour. + static void setNavigation(bool blender, bool trackpadScroll); + + /// Pan and zoom so every node is visible. + void frameAll(); + public slots: @@ -65,6 +74,8 @@ public slots: void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + void drawBackground(QPainter* painter, const QRectF& r) override; void showEvent(QShowEvent *event) override; @@ -93,6 +104,15 @@ public slots: QPointF _clickPos; + enum class NavDrag { None, Pan, Zoom }; + NavDrag _navDrag = NavDrag::None; + QPoint _navLastPos; + void panByView(QPointF viewDelta); + void zoomBy(double factor); + + static bool s_blender; + static bool s_trackpadScroll; + FlowScene* _scene; }; } diff --git a/src/FlowView.cpp b/src/FlowView.cpp index 35d9f35e9..49374e973 100644 --- a/src/FlowView.cpp +++ b/src/FlowView.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "FlowScene.hpp" #include "DataModelRegistry.hpp" @@ -33,6 +34,15 @@ using QtNodes::Connection; using QtNodes::NodeConnectionInteraction; using QtNodes::NodeGraphicsObject; +bool FlowView::s_blender = true; +bool FlowView::s_trackpadScroll = true; + +void FlowView::setNavigation(bool blender, bool trackpadScroll) +{ + s_blender = blender; + s_trackpadScroll = trackpadScroll; +} + FlowView:: FlowView(QWidget *parent) : QGraphicsView(parent) @@ -40,7 +50,7 @@ FlowView(QWidget *parent) , _deleteSelectionAction(Q_NULLPTR) , _scene(Q_NULLPTR) { - setDragMode(QGraphicsView::ScrollHandDrag); + setDragMode(s_blender ? QGraphicsView::RubberBandDrag : QGraphicsView::ScrollHandDrag); setRenderHint(QPainter::Antialiasing); auto const &flowViewStyle = StyleCollection::flowViewStyle(); @@ -409,6 +419,24 @@ void FlowView:: wheelEvent(QWheelEvent *event) { + if (s_blender) + { + // Trackpads send pixelDelta on macOS; over RDP they arrive as fine-grained angleDelta. + QPointF d = !event->pixelDelta().isNull() ? QPointF(event->pixelDelta()) + : QPointF(event->angleDelta()) / 4.0; + if (d.isNull()) + { + event->ignore(); + return; + } + if (!s_trackpadScroll || (event->modifiers() & Qt::ControlModifier)) + zoomBy(std::pow(1.2, d.y() / 30.0)); // one wheel notch (120) = 1.2x, like scaleUp() + else + panByView(d); // two-finger swipe pans + event->accept(); + return; + } + QPoint delta = event->angleDelta(); if (delta.y() == 0) @@ -427,6 +455,45 @@ wheelEvent(QWheelEvent *event) } +void +FlowView:: +panByView(QPointF viewDelta) +{ + // content follows the fingers / mouse: move the visible scene rect the other way + QPointF d(-viewDelta.x() / transform().m11(), -viewDelta.y() / transform().m22()); + setSceneRect(sceneRect().translated(d.x(), d.y())); +} + + +void +FlowView:: +zoomBy(double factor) +{ + double s = transform().m11() * factor; + if (s > 2.0) factor = 2.0 / transform().m11(); // same maximum as scaleUp() + if (s < 0.05) factor = 0.05 / transform().m11(); + scale(factor, factor); // AnchorUnderMouse: zooms at the cursor +} + + +void +FlowView:: +frameAll() +{ + if (!_scene || _scene->items().isEmpty()) + return; + QRectF r = _scene->itemsBoundingRect(); + QPointF difference = r.center() - sceneRect().center(); + setSceneRect(sceneRect().translated(difference.x(), difference.y())); + double fit = 0.9 * std::min(viewport()->width() / std::max(r.width(), 1.0), + viewport()->height() / std::max(r.height(), 1.0)); + fit = std::max(0.05, std::min(fit, 2.0)); + setTransformationAnchor(QGraphicsView::AnchorViewCenter); + scale(fit / transform().m11(), fit / transform().m22()); + setTransformationAnchor(QGraphicsView::AnchorUnderMouse); +} + + void FlowView:: scaleUp() @@ -765,10 +832,18 @@ void FlowView:: keyPressEvent(QKeyEvent *event) { + if (s_blender && event->key() == Qt::Key_Home) + { + frameAll(); + event->accept(); + return; + } + switch (event->key()) { case Qt::Key_Shift: - setDragMode(QGraphicsView::RubberBandDrag); + if (!s_blender) + setDragMode(QGraphicsView::RubberBandDrag); break; default: break; @@ -785,7 +860,8 @@ keyReleaseEvent(QKeyEvent *event) switch (event->key()) { case Qt::Key_Shift: - setDragMode(QGraphicsView::ScrollHandDrag); + if (!s_blender) + setDragMode(QGraphicsView::ScrollHandDrag); break; default: @@ -799,6 +875,21 @@ void FlowView:: mousePressEvent(QMouseEvent *event) { + if (s_blender) + { + setDragMode(QGraphicsView::RubberBandDrag); // left-drag on empty space = box select + bool navButton = event->button() == Qt::MiddleButton || + (event->button() == Qt::LeftButton && (event->modifiers() & Qt::AltModifier)); + if (navButton) + { + _navDrag = (event->modifiers() & Qt::ControlModifier) ? NavDrag::Zoom : NavDrag::Pan; + _navLastPos = event->pos(); + event->accept(); + return; + } + } + if (!s_blender && dragMode() == QGraphicsView::RubberBandDrag && !(event->modifiers() & Qt::ShiftModifier)) + setDragMode(QGraphicsView::ScrollHandDrag); QGraphicsView::mousePressEvent(event); if (event->button() == Qt::LeftButton) { @@ -811,8 +902,19 @@ void FlowView:: mouseMoveEvent(QMouseEvent *event) { + if (_navDrag != NavDrag::None) + { + QPoint d = event->pos() - _navLastPos; + _navLastPos = event->pos(); + if (_navDrag == NavDrag::Pan) + panByView(d); + else + zoomBy(std::pow(1.01, -d.y())); // drag up = zoom in + event->accept(); + return; + } QGraphicsView::mouseMoveEvent(event); - if (scene()->mouseGrabberItem() == nullptr && event->buttons() == Qt::LeftButton) + if (!s_blender && scene()->mouseGrabberItem() == nullptr && event->buttons() == Qt::LeftButton) { // Make sure shift is not being pressed if ((event->modifiers() & Qt::ShiftModifier) == 0) @@ -824,6 +926,20 @@ mouseMoveEvent(QMouseEvent *event) } +void +FlowView:: +mouseReleaseEvent(QMouseEvent *event) +{ + if (_navDrag != NavDrag::None) + { + _navDrag = NavDrag::None; + event->accept(); + return; + } + QGraphicsView::mouseReleaseEvent(event); +} + + void FlowView:: drawBackground(QPainter* painter, const QRectF& r) From 818e2bce49f619e30857691e85c3bbb14339dd1b Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Mon, 21 Sep 2026 21:49:14 +0200 Subject: [PATCH 3/8] Groups: Collapse/Expand in the right-click menu, Tab toggles the group under the mouse Co-Authored-By: Claude Opus 5 --- include/nodes/internal/FlowView.hpp | 2 ++ .../nodes/internal/GroupGraphicsObject.hpp | 2 ++ src/FlowView.cpp | 33 +++++++++++++++++++ src/GroupGraphicsObject.cpp | 16 ++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/nodes/internal/FlowView.hpp b/include/nodes/internal/FlowView.hpp index 0fb836d5a..dda54bf1a 100644 --- a/include/nodes/internal/FlowView.hpp +++ b/include/nodes/internal/FlowView.hpp @@ -66,6 +66,8 @@ public slots: void wheelEvent(QWheelEvent *event) override; + bool event(QEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override; diff --git a/include/nodes/internal/GroupGraphicsObject.hpp b/include/nodes/internal/GroupGraphicsObject.hpp index a28da495c..1a89326e3 100644 --- a/include/nodes/internal/GroupGraphicsObject.hpp +++ b/include/nodes/internal/GroupGraphicsObject.hpp @@ -76,6 +76,8 @@ class GroupGraphicsObject : public QGraphicsObject void setSizeY(int size) {sizeY = size;} void Collapse(); + /// Collapse or expand (as the group's X button), keeping the button state in step. + void ToggleCollapse(); QPointF portScenePosition(int i, PortType type) const; diff --git a/src/FlowView.cpp b/src/FlowView.cpp index 49374e973..093f9e8f0 100644 --- a/src/FlowView.cpp +++ b/src/FlowView.cpp @@ -21,6 +21,7 @@ #include "DataModelRegistry.hpp" #include "Node.hpp" #include "Group.hpp" +#include "GroupGraphicsObject.hpp" #include "NodeGraphicsObject.hpp" #include "ConnectionGraphicsObject.hpp" #include "StyleCollection.hpp" @@ -33,6 +34,7 @@ using QtNodes::FlowScene; using QtNodes::Connection; using QtNodes::NodeConnectionInteraction; using QtNodes::NodeGraphicsObject; +using QtNodes::GroupGraphicsObject; bool FlowView::s_blender = true; bool FlowView::s_trackpadScroll = true; @@ -828,6 +830,37 @@ void FlowView::duplicateSelectedNode() } +bool +FlowView:: +event(QEvent *event) +{ + // Tab collapses/expands the group under the mouse. Handled here because Qt would otherwise use + // Tab to move keyboard focus before keyPressEvent sees it. + if (event->type() == QEvent::KeyPress) + { + QKeyEvent *k = static_cast(event); + if (k->key() == Qt::Key_Tab && !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) + { + QPoint vp = viewport()->mapFromGlobal(QCursor::pos()); + for (QGraphicsItem *item : items(vp)) + { + for (QGraphicsItem *it = item; it; it = it->parentItem()) + { + if (auto *g = dynamic_cast(it)) + { + g->ToggleCollapse(); + return true; + } + } + } + return true; // over empty space: swallow Tab rather than jump focus out of the editor + } + } + return QGraphicsView::event(event); +} + + + void FlowView:: keyPressEvent(QKeyEvent *event) diff --git a/src/GroupGraphicsObject.cpp b/src/GroupGraphicsObject.cpp index 7fdb29239..f881c23a7 100644 --- a/src/GroupGraphicsObject.cpp +++ b/src/GroupGraphicsObject.cpp @@ -640,13 +640,27 @@ mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) QGraphicsItem::mouseDoubleClickEvent(event); } +void +GroupGraphicsObject:: +ToggleCollapse() +{ + Collapse(); + collapseButtonWidget->setChecked(collapsed); +} + + void GroupGraphicsObject:: contextMenuEvent(QGraphicsSceneContextMenuEvent* event) { QMenu menu; + QAction* collapseAction = menu.addAction(collapsed ? "Expand" : "Collapse"); + collapseAction->setShortcut(Qt::Key_Tab); // shown only; Tab is handled by FlowView QAction* colourAction = menu.addAction("Colour..."); - if (menu.exec(event->screenPos()) == colourAction) + QAction* chosen = menu.exec(event->screenPos()); + if (chosen == collapseAction) + ToggleCollapse(); + else if (chosen == colourAction) { QColor c = QColorDialog::getColor(QColor(r, g, b), nullptr, "Group colour"); if (c.isValid()) From 4eaac0dc8caf61a2557f36fa5a9a0535921286ef Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Mon, 21 Sep 2026 21:50:14 +0200 Subject: [PATCH 4/8] FlowView: trackpad speed multiplier (default 2x) Co-Authored-By: Claude Opus 5 --- include/nodes/internal/FlowView.hpp | 3 ++- src/FlowView.cpp | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/nodes/internal/FlowView.hpp b/include/nodes/internal/FlowView.hpp index dda54bf1a..e4a54409d 100644 --- a/include/nodes/internal/FlowView.hpp +++ b/include/nodes/internal/FlowView.hpp @@ -40,7 +40,7 @@ class NODE_EDITOR_PUBLIC FlowView /// blender: middle-drag / Alt+left-drag pans, Ctrl+(that) zooms, left-drag on empty space box-selects, /// Home frames all nodes. trackpadScroll: two-finger scroll pans and Ctrl+scroll (pinch) zooms; /// otherwise the wheel zooms at the cursor. blender=false keeps the original behaviour. - static void setNavigation(bool blender, bool trackpadScroll); + static void setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed = 2.0); /// Pan and zoom so every node is visible. void frameAll(); @@ -114,6 +114,7 @@ public slots: static bool s_blender; static bool s_trackpadScroll; + static double s_trackpadSpeed; FlowScene* _scene; }; diff --git a/src/FlowView.cpp b/src/FlowView.cpp index 093f9e8f0..1bb5d7d73 100644 --- a/src/FlowView.cpp +++ b/src/FlowView.cpp @@ -38,11 +38,13 @@ using QtNodes::GroupGraphicsObject; bool FlowView::s_blender = true; bool FlowView::s_trackpadScroll = true; +double FlowView::s_trackpadSpeed = 2.0; -void FlowView::setNavigation(bool blender, bool trackpadScroll) +void FlowView::setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed) { s_blender = blender; s_trackpadScroll = trackpadScroll; + s_trackpadSpeed = trackpadSpeed; } FlowView:: @@ -426,6 +428,8 @@ wheelEvent(QWheelEvent *event) // Trackpads send pixelDelta on macOS; over RDP they arrive as fine-grained angleDelta. QPointF d = !event->pixelDelta().isNull() ? QPointF(event->pixelDelta()) : QPointF(event->angleDelta()) / 4.0; + if (s_trackpadScroll) + d *= s_trackpadSpeed; // Preferences > Navigation > Trackpad speed if (d.isNull()) { event->ignore(); From 6335e52def7aa4daf632f259ba596d7c6e89d695 Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Tue, 22 Sep 2026 09:03:03 +0200 Subject: [PATCH 5/8] Node editor performance + group button - Drawing mode: auto (software over Remote Desktop, where OpenGL falls back to slow software GL), OpenGL, or software; software repaints only what changed. - Low detail below 40% zoom: embedded widgets hidden. - Anti-aliasing off while panning/zooming, back on 150 ms after. - Optional frame-time overlay to measure (ms/frame, mode, node count). - Group collapse button: hamburger icon, always top-left; name keeps clear. Co-Authored-By: Claude Opus 5 --- include/nodes/internal/FlowView.hpp | 25 ++++ include/nodes/internal/NodeGraphicsObject.hpp | 3 + src/FlowView.cpp | 114 +++++++++++++++++- src/GroupGraphicsObject.cpp | 26 ++-- src/NodeGraphicsObject.cpp | 9 ++ 5 files changed, 162 insertions(+), 15 deletions(-) diff --git a/include/nodes/internal/FlowView.hpp b/include/nodes/internal/FlowView.hpp index e4a54409d..a02fcef07 100644 --- a/include/nodes/internal/FlowView.hpp +++ b/include/nodes/internal/FlowView.hpp @@ -1,9 +1,13 @@ #pragma once #include +#include +#include #include "Export.hpp" +class QTimer; + namespace QtNodes { @@ -45,6 +49,13 @@ class NODE_EDITOR_PUBLIC FlowView /// Pan and zoom so every node is visible. void frameAll(); + /// Drawing: 0 = auto (software over Remote Desktop, OpenGL otherwise), 1 = OpenGL, 2 = software. + static void setRenderMode(int mode); + /// Overlay the last frame's draw time (ms) in the corner, to measure optimisations. + static void setShowFrameTime(bool show); + /// Below this zoom, embedded widgets are hidden (plain node boxes). + static constexpr double lowDetailZoom = 0.4; + public slots: @@ -80,6 +91,10 @@ public slots: void drawBackground(QPainter* painter, const QRectF& r) override; + void drawForeground(QPainter* painter, const QRectF& r) override; + + void paintEvent(QPaintEvent *event) override; + void showEvent(QShowEvent *event) override; void addAnchor(int index); @@ -112,6 +127,16 @@ public slots: void panByView(QPointF viewDelta); void zoomBy(double factor); + void applyRenderMode(); + void updateLevelOfDetail(); + void beginInteraction(); // anti-aliasing off while panning/zooming, back on when idle + QTimer *_interactionTimer = nullptr; + bool _lowDetail = false; + double _lastFrameMs = 0; + static std::set s_views; + static int s_renderMode; + static bool s_showFrameTime; + static bool s_blender; static bool s_trackpadScroll; static double s_trackpadSpeed; diff --git a/include/nodes/internal/NodeGraphicsObject.hpp b/include/nodes/internal/NodeGraphicsObject.hpp index 77d7ab8a0..56a64460e 100644 --- a/include/nodes/internal/NodeGraphicsObject.hpp +++ b/include/nodes/internal/NodeGraphicsObject.hpp @@ -38,6 +38,9 @@ class NodeGraphicsObject : public QGraphicsObject FlowScene& flowScene(); + /// Zoomed-out drawing: hide the embedded widget (the most expensive thing to draw). + void setLowDetail(bool low); + QRectF boundingRect() const override; diff --git a/src/FlowView.cpp b/src/FlowView.cpp index 1bb5d7d73..e5cfa0721 100644 --- a/src/FlowView.cpp +++ b/src/FlowView.cpp @@ -15,6 +15,10 @@ #include #include #include +#ifdef _WIN32 +// Just the one call, instead of (whose min/max/near/far macros break this file). +extern "C" __declspec(dllimport) int __stdcall GetSystemMetrics(int nIndex); +#endif #include #include "FlowScene.hpp" @@ -36,6 +40,43 @@ using QtNodes::NodeConnectionInteraction; using QtNodes::NodeGraphicsObject; using QtNodes::GroupGraphicsObject; +std::set FlowView::s_views; +int FlowView::s_renderMode = 0; +bool FlowView::s_showFrameTime = false; + +static bool remoteDesktopSession() +{ +#ifdef _WIN32 + return GetSystemMetrics(0x1000 /* SM_REMOTESESSION */) != 0; +#else + return false; +#endif +} + +void FlowView::setRenderMode(int mode) +{ + s_renderMode = mode; + for (FlowView *v : s_views) + v->applyRenderMode(); +} + +void FlowView::setShowFrameTime(bool show) +{ + s_showFrameTime = show; + for (FlowView *v : s_views) + v->viewport()->update(); +} + +void FlowView::applyRenderMode() +{ + bool gl = s_renderMode == 1 || (s_renderMode == 0 && !remoteDesktopSession()); + bool isGL = qobject_cast(viewport()) != nullptr; + if (gl != isGL) + setViewport(gl ? static_cast(new QGLWidget(QGLFormat(QGL::SampleBuffers))) : new QWidget()); + // GL redraws everything anyway; the software path only repaints what changed. + setViewportUpdateMode(gl ? QGraphicsView::FullViewportUpdate : QGraphicsView::SmartViewportUpdate); +} + bool FlowView::s_blender = true; bool FlowView::s_trackpadScroll = true; double FlowView::s_trackpadSpeed = 2.0; @@ -70,9 +111,16 @@ FlowView(QWidget *parent) setCacheMode(QGraphicsView::CacheBackground); - setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); - - setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + s_views.insert(this); + connect(this, &QObject::destroyed, [this]() { s_views.erase(this); }); + applyRenderMode(); + _interactionTimer = new QTimer(this); + _interactionTimer->setSingleShot(true); + _interactionTimer->setInterval(150); + connect(_interactionTimer, &QTimer::timeout, [this]() { + setRenderHint(QPainter::Antialiasing, true); + viewport()->update(); + }); } @@ -461,10 +509,34 @@ wheelEvent(QWheelEvent *event) } +void +FlowView:: +beginInteraction() +{ + if (renderHints() & QPainter::Antialiasing) + setRenderHint(QPainter::Antialiasing, false); + _interactionTimer->start(); +} + + +void +FlowView:: +updateLevelOfDetail() +{ + if (!_scene) + return; + bool low = transform().m11() < lowDetailZoom; + _lowDetail = low; + for (auto &n : _scene->nodes()) + n.second->nodeGraphicsObject().setLowDetail(low); +} + + void FlowView:: panByView(QPointF viewDelta) { + beginInteraction(); // content follows the fingers / mouse: move the visible scene rect the other way QPointF d(-viewDelta.x() / transform().m11(), -viewDelta.y() / transform().m22()); setSceneRect(sceneRect().translated(d.x(), d.y())); @@ -478,7 +550,9 @@ zoomBy(double factor) double s = transform().m11() * factor; if (s > 2.0) factor = 2.0 / transform().m11(); // same maximum as scaleUp() if (s < 0.05) factor = 0.05 / transform().m11(); + beginInteraction(); scale(factor, factor); // AnchorUnderMouse: zooms at the cursor + updateLevelOfDetail(); } @@ -497,6 +571,7 @@ frameAll() setTransformationAnchor(QGraphicsView::AnchorViewCenter); scale(fit / transform().m11(), fit / transform().m22()); setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + updateLevelOfDetail(); } @@ -512,7 +587,9 @@ scaleUp() if (t.m11() > 2.0) return; + beginInteraction(); scale(factor, factor); + updateLevelOfDetail(); } @@ -524,7 +601,9 @@ scaleDown() double const step = 1.2; double const factor = std::pow(step, -1.0); + beginInteraction(); scale(factor, factor); + updateLevelOfDetail(); } @@ -977,6 +1056,35 @@ mouseReleaseEvent(QMouseEvent *event) } +void +FlowView:: +paintEvent(QPaintEvent *event) +{ + QElapsedTimer t; + t.start(); + QGraphicsView::paintEvent(event); + _lastFrameMs = 0.8 * _lastFrameMs + 0.2 * (t.nsecsElapsed() / 1e6); // smoothed; shown on the next frame +} + + +void +FlowView:: +drawForeground(QPainter* painter, const QRectF& r) +{ + QGraphicsView::drawForeground(painter, r); + if (!s_showFrameTime) + return; + painter->save(); + painter->resetTransform(); + QString mode = qobject_cast(viewport()) ? "OpenGL" : "software"; + QString txt = QString("%1 ms/frame (%2%3, %4 nodes)").arg(_lastFrameMs, 0, 'f', 1).arg(mode) + .arg(_lowDetail ? ", low detail" : "").arg(_scene ? (int)_scene->nodes().size() : 0); + painter->setPen(Qt::yellow); + painter->drawText(QPointF(10, 20), txt); + painter->restore(); +} + + void FlowView:: drawBackground(QPainter* painter, const QRectF& r) diff --git a/src/GroupGraphicsObject.cpp b/src/GroupGraphicsObject.cpp index f881c23a7..b1cadfdaf 100644 --- a/src/GroupGraphicsObject.cpp +++ b/src/GroupGraphicsObject.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -76,10 +77,11 @@ GroupGraphicsObject(FlowScene &scene, Group& group) _proxyWidget->setWidget(nameLineEdit); _proxyWidget->setPos(QPointF(sizeX/2 - _proxyWidget->size().width()/2, 0)); - collapseButtonWidget = new QPushButton("X"); + collapseButtonWidget = new QPushButton(QString(QChar(0x2630))); // hamburger icon (U+2630) + collapseButtonWidget->setToolTip("Collapse / expand (Tab, or right-click the group)"); collapseButtonWidget->setCheckable(true); _collapseButton->setWidget(collapseButtonWidget); - _collapseButton->setPos(QPointF(sizeX - _collapseButton->size().width(), 0)); + _collapseButton->setPos(QPointF(0, 0)); // always top-left connect(collapseButtonWidget, &QPushButton::clicked, this, [this](int state){ Collapse(); @@ -184,8 +186,8 @@ Collapse() //Do resize sizeX = 500; sizeY = numInOut * spacing; - _proxyWidget->setPos(QPointF(sizeX/2 - _proxyWidget->size().width()/2, 0)); - _collapseButton->setPos(QPointF(sizeX - _collapseButton->size().width(), 0)); + _proxyWidget->setPos(QPointF(std::max((qreal)(sizeX/2 - _proxyWidget->size().width()/2), (qreal)(_collapseButton->size().width() + 4)), 0)); + _collapseButton->setPos(QPointF(0, 0)); // always top-left //Sets the inside nodes invisible @@ -234,8 +236,8 @@ Collapse() sizeX = savedSizeX; sizeY = savedSizeY; - _proxyWidget->setPos(QPointF(sizeX/2 - _proxyWidget->size().width()/2, 0)); - _collapseButton->setPos(QPointF(sizeX - _collapseButton->size().width(), 0)); + _proxyWidget->setPos(QPointF(std::max((qreal)(sizeX/2 - _proxyWidget->size().width()/2), (qreal)(_collapseButton->size().width() + 4)), 0)); + _collapseButton->setPos(QPointF(0, 0)); // always top-left //Sets the inside nodes invisible for(int i=0; isetPos(QPointF(sizeX/2 - _proxyWidget->size().width()/2, 0)); - _collapseButton->setPos(QPointF(sizeX - _collapseButton->size().width(), 0)); + _proxyWidget->setPos(QPointF(std::max((qreal)(sizeX/2 - _proxyWidget->size().width()/2), (qreal)(_collapseButton->size().width() + 4)), 0)); + _collapseButton->setPos(QPointF(0, 0)); // always top-left event->accept(); } else if(isResizingY) { @@ -555,8 +557,8 @@ mouseMoveEvent(QGraphicsSceneMouseEvent * event) prepareGeometryChange(); sizeY += diff; update(); - _proxyWidget->setPos(QPointF(sizeX/2 - _proxyWidget->size().width()/2, 0)); - _collapseButton->setPos(QPointF(sizeX - _collapseButton->size().width(), 0)); + _proxyWidget->setPos(QPointF(std::max((qreal)(sizeX/2 - _proxyWidget->size().width()/2), (qreal)(_collapseButton->size().width() + 4)), 0)); + _collapseButton->setPos(QPointF(0, 0)); // always top-left event->accept(); } else if(isResizingXY) { auto diff = event->pos() - event->lastPos(); @@ -564,8 +566,8 @@ mouseMoveEvent(QGraphicsSceneMouseEvent * event) sizeX += diff.x(); sizeY += diff.y(); update(); - _proxyWidget->setPos(QPointF(sizeX/2 - _proxyWidget->size().width()/2, 0)); - _collapseButton->setPos(QPointF(sizeX - _collapseButton->size().width(), 0)); + _proxyWidget->setPos(QPointF(std::max((qreal)(sizeX/2 - _proxyWidget->size().width()/2), (qreal)(_collapseButton->size().width() + 4)), 0)); + _collapseButton->setPos(QPointF(0, 0)); // always top-left event->accept(); } else { _scene.groupMoved(_group, pos()); diff --git a/src/NodeGraphicsObject.cpp b/src/NodeGraphicsObject.cpp index 91703704c..df6385fe6 100644 --- a/src/NodeGraphicsObject.cpp +++ b/src/NodeGraphicsObject.cpp @@ -103,6 +103,15 @@ node() const return _node; } +void +NodeGraphicsObject:: +setLowDetail(bool low) +{ + if (_proxyWidget && _proxyWidget->isVisible() == low) + _proxyWidget->setVisible(!low); +} + + void NodeGraphicsObject:: embedQWidget() From 8d8ea1cdfd0b48b145eb1f688a09bb4878bb690c Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Tue, 22 Sep 2026 09:42:09 +0200 Subject: [PATCH 6/8] FlowView: separate pan/zoom speed, capped zoom steps, wheel readout Zoom no longer scales with the trackpad pan speed and each step is capped at one notch (1.1x at zoom speed 1), so coarse Ctrl+scroll/pinch steps over RDP don't jump. Pan speed default 4. The frame-time overlay also shows the last raw wheel event (angle/pixel delta, modifier) to tune against. Co-Authored-By: Claude Opus 5 --- include/nodes/internal/FlowView.hpp | 5 ++++- src/FlowView.cpp | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/nodes/internal/FlowView.hpp b/include/nodes/internal/FlowView.hpp index a02fcef07..1936d3b8d 100644 --- a/include/nodes/internal/FlowView.hpp +++ b/include/nodes/internal/FlowView.hpp @@ -44,7 +44,8 @@ class NODE_EDITOR_PUBLIC FlowView /// blender: middle-drag / Alt+left-drag pans, Ctrl+(that) zooms, left-drag on empty space box-selects, /// Home frames all nodes. trackpadScroll: two-finger scroll pans and Ctrl+scroll (pinch) zooms; /// otherwise the wheel zooms at the cursor. blender=false keeps the original behaviour. - static void setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed = 2.0); + /// trackpadSpeed scales trackpad pan; zoomSpeed scales zoom (wheel, Ctrl+scroll, pinch) and is capped per step. + static void setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed = 4.0, double zoomSpeed = 1.0); /// Pan and zoom so every node is visible. void frameAll(); @@ -140,6 +141,8 @@ public slots: static bool s_blender; static bool s_trackpadScroll; static double s_trackpadSpeed; + static double s_zoomSpeed; + QString _lastWheel; // raw last wheel event, shown with the frame-time overlay FlowScene* _scene; }; diff --git a/src/FlowView.cpp b/src/FlowView.cpp index e5cfa0721..3d3733583 100644 --- a/src/FlowView.cpp +++ b/src/FlowView.cpp @@ -79,13 +79,15 @@ void FlowView::applyRenderMode() bool FlowView::s_blender = true; bool FlowView::s_trackpadScroll = true; -double FlowView::s_trackpadSpeed = 2.0; +double FlowView::s_trackpadSpeed = 4.0; +double FlowView::s_zoomSpeed = 1.0; -void FlowView::setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed) +void FlowView::setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed, double zoomSpeed) { s_blender = blender; s_trackpadScroll = trackpadScroll; s_trackpadSpeed = trackpadSpeed; + s_zoomSpeed = zoomSpeed; } FlowView:: @@ -476,17 +478,22 @@ wheelEvent(QWheelEvent *event) // Trackpads send pixelDelta on macOS; over RDP they arrive as fine-grained angleDelta. QPointF d = !event->pixelDelta().isNull() ? QPointF(event->pixelDelta()) : QPointF(event->angleDelta()) / 4.0; - if (s_trackpadScroll) - d *= s_trackpadSpeed; // Preferences > Navigation > Trackpad speed + _lastWheel = QString("wheel angle %1,%2 pixel %3,%4 %5").arg(event->angleDelta().x()).arg(event->angleDelta().y()) + .arg(event->pixelDelta().x()).arg(event->pixelDelta().y()) + .arg(event->modifiers() & Qt::ControlModifier ? "ctrl" : (event->modifiers() & Qt::ShiftModifier ? "shift" : "")); if (d.isNull()) { event->ignore(); return; } if (!s_trackpadScroll || (event->modifiers() & Qt::ControlModifier)) - zoomBy(std::pow(1.2, d.y() / 30.0)); // one wheel notch (120) = 1.2x, like scaleUp() + { + // zoom: proportional to the step, capped at one wheel notch so coarse RDP steps can't jump + double steps = std::max(-1.0, std::min(1.0, d.y() / 30.0)) * s_zoomSpeed; + zoomBy(std::pow(1.1, steps)); // one notch = 1.1x at zoom speed 1 + } else - panByView(d); // two-finger swipe pans + panByView(d * s_trackpadSpeed); // two-finger swipe pans (Trackpad speed) event->accept(); return; } @@ -1081,6 +1088,8 @@ drawForeground(QPainter* painter, const QRectF& r) .arg(_lowDetail ? ", low detail" : "").arg(_scene ? (int)_scene->nodes().size() : 0); painter->setPen(Qt::yellow); painter->drawText(QPointF(10, 20), txt); + if (!_lastWheel.isEmpty()) + painter->drawText(QPointF(10, 38), _lastWheel); painter->restore(); } From c9d6c60371b01b91237f20f378cf982e7837b910 Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Tue, 22 Sep 2026 10:20:19 +0200 Subject: [PATCH 7/8] FlowView: animated zoom and cheap cache while zooming Zoom felt slow/jumpy: every step jumped to the new scale and forced every visible node to re-render its DeviceCoordinateCache at the new zoom level. Wheel/pinch zoom now accumulates a target (1.2x per notch at zoom speed 1, at most ~3 notches queued) and eases towards it at 60 fps; while zooming, nodes use ItemCoordinateCache (scaled pixmap) and return to the crisp device cache 150 ms after the last step. Co-Authored-By: Claude Opus 5 --- include/nodes/internal/FlowView.hpp | 5 ++++ src/FlowView.cpp | 42 ++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/nodes/internal/FlowView.hpp b/include/nodes/internal/FlowView.hpp index 1936d3b8d..786a48737 100644 --- a/include/nodes/internal/FlowView.hpp +++ b/include/nodes/internal/FlowView.hpp @@ -132,6 +132,11 @@ public slots: void updateLevelOfDetail(); void beginInteraction(); // anti-aliasing off while panning/zooming, back on when idle QTimer *_interactionTimer = nullptr; + QTimer *_zoomTimer = nullptr; // animates towards the accumulated zoom target + double _pendingZoomLog = 0; // log of the zoom still to apply + bool _zoomCache = false; // nodes on the cheap ItemCoordinateCache while zooming + void zoomSmooth(double factor); + void setZoomCache(bool on); bool _lowDetail = false; double _lastFrameMs = 0; static std::set s_views; diff --git a/src/FlowView.cpp b/src/FlowView.cpp index 3d3733583..b0a41c6b6 100644 --- a/src/FlowView.cpp +++ b/src/FlowView.cpp @@ -121,8 +121,20 @@ FlowView(QWidget *parent) _interactionTimer->setInterval(150); connect(_interactionTimer, &QTimer::timeout, [this]() { setRenderHint(QPainter::Antialiasing, true); + setZoomCache(false); viewport()->update(); }); + + _zoomTimer = new QTimer(this); + _zoomTimer->setInterval(16); + connect(_zoomTimer, &QTimer::timeout, [this]() { + // ease: apply 35% of what's left each frame; finish when it's negligible + double step = std::abs(_pendingZoomLog) < 0.002 ? _pendingZoomLog : 0.35 * _pendingZoomLog; + _pendingZoomLog -= step; + zoomBy(std::exp(step)); + if (_pendingZoomLog == 0.0) + _zoomTimer->stop(); + }); } @@ -490,7 +502,7 @@ wheelEvent(QWheelEvent *event) { // zoom: proportional to the step, capped at one wheel notch so coarse RDP steps can't jump double steps = std::max(-1.0, std::min(1.0, d.y() / 30.0)) * s_zoomSpeed; - zoomBy(std::pow(1.1, steps)); // one notch = 1.1x at zoom speed 1 + zoomSmooth(std::pow(1.2, steps)); // one notch = 1.2x at zoom speed 1, animated } else panByView(d * s_trackpadSpeed); // two-finger swipe pans (Trackpad speed) @@ -558,11 +570,39 @@ zoomBy(double factor) if (s > 2.0) factor = 2.0 / transform().m11(); // same maximum as scaleUp() if (s < 0.05) factor = 0.05 / transform().m11(); beginInteraction(); + setZoomCache(true); scale(factor, factor); // AnchorUnderMouse: zooms at the cursor updateLevelOfDetail(); } +void +FlowView:: +zoomSmooth(double factor) +{ + setZoomCache(true); + _pendingZoomLog += std::log(factor); + // don't queue up more than ~3 notches, so a burst of events can't run away + _pendingZoomLog = std::max(-0.55, std::min(0.55, _pendingZoomLog)); + if (!_zoomTimer->isActive()) + _zoomTimer->start(); +} + + +void +FlowView:: +setZoomCache(bool on) +{ + if (on == _zoomCache || !_scene) + return; + _zoomCache = on; + // Device cache is exact but is re-rendered at every zoom level; item cache just scales the image. + for (auto &n : _scene->nodes()) + n.second->nodeGraphicsObject().setCacheMode(on ? QGraphicsItem::ItemCoordinateCache + : QGraphicsItem::DeviceCoordinateCache); +} + + void FlowView:: frameAll() From c370b519ab6f05f0bb6d7c292d9ee34ed9470956 Mon Sep 17 00:00:00 2001 From: willcometothejungle <129651664+willcometothejungle@users.noreply.github.com> Date: Tue, 22 Sep 2026 12:57:09 +0200 Subject: [PATCH 8/8] FlowView: zoom speed default 2.0 Co-Authored-By: Claude Opus 5 --- include/nodes/internal/FlowView.hpp | 2 +- src/FlowView.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nodes/internal/FlowView.hpp b/include/nodes/internal/FlowView.hpp index 786a48737..4fc46df78 100644 --- a/include/nodes/internal/FlowView.hpp +++ b/include/nodes/internal/FlowView.hpp @@ -45,7 +45,7 @@ class NODE_EDITOR_PUBLIC FlowView /// Home frames all nodes. trackpadScroll: two-finger scroll pans and Ctrl+scroll (pinch) zooms; /// otherwise the wheel zooms at the cursor. blender=false keeps the original behaviour. /// trackpadSpeed scales trackpad pan; zoomSpeed scales zoom (wheel, Ctrl+scroll, pinch) and is capped per step. - static void setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed = 4.0, double zoomSpeed = 1.0); + static void setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed = 4.0, double zoomSpeed = 2.0); /// Pan and zoom so every node is visible. void frameAll(); diff --git a/src/FlowView.cpp b/src/FlowView.cpp index b0a41c6b6..64fad9239 100644 --- a/src/FlowView.cpp +++ b/src/FlowView.cpp @@ -80,7 +80,7 @@ void FlowView::applyRenderMode() bool FlowView::s_blender = true; bool FlowView::s_trackpadScroll = true; double FlowView::s_trackpadSpeed = 4.0; -double FlowView::s_zoomSpeed = 1.0; +double FlowView::s_zoomSpeed = 2.0; void FlowView::setNavigation(bool blender, bool trackpadScroll, double trackpadSpeed, double zoomSpeed) {