#pragma once #include #include #include #include #include "internal/circularbuffer.hpp" namespace ZShell::components { class SparklineContent : public QQuickPaintedItem { Q_OBJECT public: explicit SparklineContent(QQuickItem* parent = nullptr); void paint(QPainter* painter) override; void setLine1(internal::CircularBuffer* buffer); void setLine2(internal::CircularBuffer* buffer); void setLine1Color(const QColor& color); void setLine2Color(const QColor& color); void setLine1FillAlpha(qreal alpha); void setLine2FillAlpha(qreal alpha); void setMaxValue(qreal value); void setLineWidth(qreal width); void setCurveSmoothing(bool enabled); void setHistoryLength(int length); void setSliding(bool sliding); void setViewportSize(qreal viewportWidth, qreal viewportHeight); void setSlideInterval(qreal intervalMs); void setSlideProgress(qreal progress); [[nodiscard]] qreal stepX() const; [[nodiscard]] bool slideActive() const; protected: void itemChange(ItemChange change, const ItemChangeData& value) override; private: struct LineGeometry { QPainterPath stroke; QPainterPath fill; bool hasData = false; }; [[nodiscard]] qreal slidePhase(qreal progress) const; void invalidate(); void rebuildIfNeeded(); [[nodiscard]] LineGeometry buildGeometry( internal::CircularBuffer* buffer) const; void connectBuffer(internal::CircularBuffer* buffer); void applyGeometry(); void onSampleArrived(); internal::CircularBuffer* m_line1 = nullptr; internal::CircularBuffer* m_line2 = nullptr; QColor m_line1Color; QColor m_line2Color; qreal m_line1FillAlpha = 0.15; qreal m_line2FillAlpha = 0.2; qreal m_maxValue = 1024.0; qreal m_lineWidth = 2.0; bool m_curveSmoothing = false; int m_historyLength = 30; bool m_sliding = true; qreal m_viewportW = 0.0; qreal m_viewportH = 0.0; qreal m_paintedH = 0.0; qreal m_dpr = 1.0; qreal m_slideIntervalMs = 0.0; QElapsedTimer m_sampleClock; LineGeometry m_geom1; LineGeometry m_geom2; bool m_dirty = true; }; } // namespace ZShell::components