Ilya Ashikhmin b257c1a7cf feat(scene): add interactive graphics scene with grid, ports and styled edges
- SVG node items with snap-to-grid dragging; ports appear on focus/hover
  and highlight compatible targets during a connection drag
- Orthogonally routed edge items with line styles, head/tail decorations
  (arrow, circle, diamond, bar), selection halo and title labels; later
  edges jump crossings with arcs when enabled
- Grid background view with cursor-anchored zoom, middle-button pan,
  rubber-band selection and palette drag-and-drop
- Undoable commands: add/move/delete/connect/property/paste with
  clipboard fragments; light/dark/high-contrast themes
- Flow overlay: animated dashes, direction and density follow flow rate

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 23:25:06 +02:00

54 lines
1.5 KiB
C++

#pragma once
#include <QGraphicsView>
class QMimeData;
namespace diag {
class DiagramScene;
// Canvas view: draws the rectangular grid, zooms with Ctrl+wheel (anchored
// under the cursor), pans with the middle mouse button, rubber-band selects,
// and accepts node-type drops from the palette.
class GridView : public QGraphicsView {
Q_OBJECT
public:
static constexpr const char* kNodeTypeMime = "application/x-diag-nodetype";
explicit GridView(DiagramScene* scene, QWidget* parent = nullptr);
void zoomIn();
void zoomOut();
void zoomReset();
void zoomToFit();
double zoomFactor() const;
// Decodes a node-type mime payload and drops it at the viewport position;
// returns true when a node was created. Called from dropEvent.
bool handleNodeTypeDrop(const QMimeData* mime, QPoint viewportPos);
signals:
void zoomChanged(double factor);
void cursorMoved(QPointF scenePos);
protected:
void drawBackground(QPainter* painter, const QRectF& rect) override;
void wheelEvent(QWheelEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
void dropEvent(QDropEvent* event) override;
private:
void applyZoom(double factor);
DiagramScene* m_scene;
bool m_panning = false;
QPoint m_panStart;
};
} // namespace diag