| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef AREARENDERER_H |
| 5 | #define AREARENDERER_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the QtGraphs API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | |
| 17 | #include <QPainterPath> |
| 18 | #include <QQuickItem> |
| 19 | #include <QtQuickShapes/private/qquickshape_p.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | class QGraphsView; |
| 24 | class QAreaSeries; |
| 25 | class AxisRenderer; |
| 26 | class QAbstractSeries; |
| 27 | class QQuickTapHandler; |
| 28 | |
| 29 | class AreaRenderer : public QQuickItem |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | public: |
| 33 | AreaRenderer(QGraphsView *graph, bool clipPlotArea); |
| 34 | ~AreaRenderer() override; |
| 35 | |
| 36 | void resetShapePathCount(); |
| 37 | |
| 38 | void handlePolish(QAreaSeries *series); |
| 39 | void afterPolish(QList<QAbstractSeries *> &cleanupSeries); |
| 40 | void afterUpdate(QList<QAbstractSeries *> &cleanupSeries); |
| 41 | void updateSeries(QAreaSeries *series); |
| 42 | bool handleHoverMove(QHoverEvent *event); |
| 43 | |
| 44 | Q_SIGNALS: |
| 45 | |
| 46 | private: |
| 47 | struct PointGroup |
| 48 | { |
| 49 | QAreaSeries *series = nullptr; |
| 50 | QQuickShapePath *shapePath = nullptr; |
| 51 | QPainterPath painterPath; |
| 52 | qsizetype colorIndex = -1; |
| 53 | qsizetype borderColorIndex = -1; |
| 54 | bool hover = false; |
| 55 | }; |
| 56 | |
| 57 | void onSingleTapped(QEventPoint eventPoint, Qt::MouseButton button); |
| 58 | void onDoubleTapped(QEventPoint eventPoint, Qt::MouseButton button); |
| 59 | void onPressedChanged(); |
| 60 | |
| 61 | QGraphsView *m_graph = nullptr; |
| 62 | QQuickShape m_shape; |
| 63 | QMap<QAreaSeries *, PointGroup *> m_groups; |
| 64 | qsizetype m_currentShapePathIndex = 0; |
| 65 | |
| 66 | // Render area variables |
| 67 | qreal m_maxVertical = 0; |
| 68 | qreal m_maxHorizontal = 0; |
| 69 | qreal m_verticalOffset = 0; |
| 70 | qreal m_horizontalOffset = 0; |
| 71 | qreal m_areaWidth = 0; |
| 72 | qreal m_areaHeight = 0; |
| 73 | |
| 74 | QQuickTapHandler *m_tapHandler = nullptr; |
| 75 | |
| 76 | void calculateRenderCoordinates( |
| 77 | QAreaSeries *series, qreal origX, qreal origY, qreal *renderX, qreal *renderY) const; |
| 78 | void calculateAxisCoordinates( |
| 79 | QAreaSeries *series, qreal origX, qreal origY, qreal *axisX, qreal *axisY) const; |
| 80 | bool pointInArea(QPoint pt, QAreaSeries *series) const; |
| 81 | }; |
| 82 | |
| 83 | QT_END_NAMESPACE |
| 84 | |
| 85 | #endif // AREARENDERER_H |
| 86 | |