summaryrefslogtreecommitdiffstats
path: root/stats/chartitem.h
diff options
context:
space:
mode:
Diffstat (limited to 'stats/chartitem.h')
-rw-r--r--stats/chartitem.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/stats/chartitem.h b/stats/chartitem.h
new file mode 100644
index 000000000..fb4b67dff
--- /dev/null
+++ b/stats/chartitem.h
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+// Wrappers around QSGImageNode that allow painting onto an image
+// and then turning that into a texture to be displayed in a QQuickItem.
+#ifndef CHART_ITEM_H
+#define CHART_ITEM_H
+
+#include <memory>
+#include <QPainter>
+
+class QSGImageNode;
+class QSGTexture;
+class StatsView;
+
+class ChartItem {
+public:
+ ChartItem(StatsView &v);
+ ~ChartItem();
+ // Attention: The children are responsible for updating the item. None of these calls will.
+ void resize(QSizeF size); // Resets the canvas. Attention: image is *unitialized*.
+ void setPos(QPointF pos);
+ void render(); // Only call on render thread!
+ QRectF getRect() const;
+ bool dirty; // If true, call render() when rebuilding the scene
+protected:
+ std::unique_ptr<QPainter> painter;
+ std::unique_ptr<QImage> img;
+ QSizeF sceneSize() const;
+ void setTextureDirty();
+ void setPositionDirty();
+private:
+ StatsView &view;
+ QRectF rect;
+ bool positionDirty;
+ bool textureDirty;
+ std::unique_ptr<QSGImageNode> node;
+ std::unique_ptr<QSGTexture> texture;
+};
+
+// Draw a rectangular background after resize. Children are responsible for calling update().
+class ChartRectItem : public ChartItem {
+public:
+ ChartRectItem(StatsView &v, const QPen &pen, const QBrush &brush, double radius);
+ ~ChartRectItem();
+ void resize(QSizeF size);
+private:
+ QPen pen;
+ QBrush brush;
+ double radius;
+};
+
+#endif