presentation/GraphAreasItem.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "GraphGeometry.h" | ||
| 4 | #include "GraphPaintCache.h" | ||
| 5 | #include "QuickContactGraph.h" | ||
| 6 | |||
| 7 | #include <QPointer> | ||
| 8 | #include <QQuickItem> | ||
| 9 | #include <QTimer> | ||
| 10 | #include <QVariantList> | ||
| 11 | |||
| 12 | // Sprint 105 S105.4.2 (D-6): the families' territories (F103-48) in the | ||
| 13 | // scene graph instead of a Canvas. Per territory, once per new set of | ||
| 14 | // territories (QuickContactGraph::territoriesChanged), the outlines are | ||
| 15 | // simplified, rounded and cut into fill triangles in world coordinates; | ||
| 16 | // every frame then only transforms them to the screen and adds the glow | ||
| 17 | // along the inside of the border and the border line in pixels — a faint | ||
| 18 | // tint, a glow and a crisp border as the Canvas painted them, with the same | ||
| 19 | // emphasis for the territory under the pointer (`pointed`) and the family | ||
| 20 | // whose name is pointed at (`hovered`, the others fade). | ||
| 21 | class GraphAreasItem : public QQuickItem { | ||
| 22 | Q_OBJECT | ||
| 23 | Q_PROPERTY(QObject *graph READ graph WRITE setGraph NOTIFY changed) | ||
| 24 | // Per territory (index of graph.areas): its colour. | ||
| 25 | Q_PROPERTY(QVariantList colours READ colours WRITE setColours NOTIFY changed) | ||
| 26 | Q_PROPERTY(int pointed MEMBER m_pointed NOTIFY changed) | ||
| 27 | Q_PROPERTY(int hovered MEMBER m_hovered NOTIFY changed) | ||
| 28 | Q_PROPERTY(int vertexCount READ vertexCount NOTIFY built) | ||
| 29 | // Tests: no picture is due any more (see GraphLinesItem::settled). | ||
| 30 | Q_PROPERTY(bool settled READ settled NOTIFY built) | ||
| 31 | |||
| 32 | public: | ||
| 33 | explicit GraphAreasItem(QQuickItem *parent = nullptr); | ||
| 34 | QObject *graph() const; | ||
| 35 | void setGraph(QObject *graph); | ||
| 36 | ✗ | QVariantList colours() const { return m_coloursIn; } | |
| 37 | void setColours(const QVariantList &values); | ||
| 38 | ✗ | int vertexCount() const { return m_vertexCount; } | |
| 39 |
3/4✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 5 taken 13 times.
✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 5 not taken.
|
15 | bool settled() const { return !m_refreshPending && !m_contentChanged; } |
| 40 | |||
| 41 | signals: | ||
| 42 | void changed(); | ||
| 43 | void built(); | ||
| 44 | |||
| 45 | protected: | ||
| 46 | QSGNode *updatePaintNode(QSGNode *old, UpdatePaintNodeData *) override; | ||
| 47 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; | ||
| 48 | |||
| 49 | private: | ||
| 50 | struct Shape { | ||
| 51 | QList<QList<QPointF>> loops; // smoothed outlines (world) | ||
| 52 | QList<double> inward; // per loop: +1 when its left normal points inside, -1 otherwise | ||
| 53 | QList<QList<QPointF>> normals; // per loop point: the unit normal into the territory | ||
| 54 | QList<QList<double>> depth; // per loop point: how far (world) the territory reaches along it | ||
| 55 | QList<QPointF> fill; // triangles (world) | ||
| 56 | }; | ||
| 57 | void prepare(); | ||
| 58 | void paintTerritory(GraphGeometry::Sink *mesh, int index, int emphasis, bool faded) const; | ||
| 59 | |||
| 60 | QPointer<QuickContactGraph> m_graph; | ||
| 61 | QVariantList m_coloursIn; | ||
| 62 | QList<QColor> m_colours; | ||
| 63 | int m_pointed = -1; | ||
| 64 | int m_hovered = -1; | ||
| 65 | QList<Shape> m_shapes; | ||
| 66 | bool m_prepared = false; | ||
| 67 | double m_k = 1; | ||
| 68 | QPointF m_t; | ||
| 69 | int m_vertexCount = 0; | ||
| 70 | GraphPaintCache m_cache; | ||
| 71 | bool m_contentChanged = true; | ||
| 72 | bool m_refreshPending = false; // the last frame asked for a refresh (GraphPaintCache) | ||
| 73 | QTimer m_refresh; | ||
| 74 | }; | ||
| 75 |