Files
z-bar-qt/Plugins/ZShell/Components/sparklinecontent.hpp
T
zach 11e7aac195
C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 11s
C++ / clang-tidy (pull_request) Failing after 10s
JS/TS / fmt (pull_request) Successful in 12s
JS/TS / lint (pull_request) Successful in 10s
Python / static (pull_request) Failing after 27s
Rust / build (pull_request) Successful in 54s
Python / verify (pull_request) Failing after 1m26s
Rust / fmt (pull_request) Successful in 46s
Rust / clippy (pull_request) Successful in 1m6s
feat: better notification storage and image caching + blobs
2026-11-02 19:00:43 +01:00

76 lines
1.9 KiB
C++

#pragma once
#include <qcolor.h>
#include <qpainterpath.h>
#include <qquickpainteditem.h>
#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);
[[nodiscard]] qreal stepX() const;
protected:
// The stroke width, sample spacing and plot bounds are quantized in device
// pixels, so they have to be built with the ratio the window actually has.
void itemChange(ItemChange change, const ItemChangeData& value) override;
private:
struct LineGeometry {
QPainterPath stroke;
QPainterPath fill;
bool hasData = false;
};
void invalidate();
void rebuildIfNeeded();
[[nodiscard]] LineGeometry buildGeometry(
internal::CircularBuffer* buffer) const;
void connectBuffer(internal::CircularBuffer* buffer);
void applyGeometry();
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_dpr = 1.0;
LineGeometry m_geom1;
LineGeometry m_geom2;
bool m_dirty = true;
};
} // namespace ZShell::components