From 94238a02c8a947593d69a6271b3fd1cf5e264be2 Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Tue, 30 May 2023 00:06:16 +0100 Subject: Add some more parameters to the heartrate graph --- qmlplugin/hrGraph.cpp | 25 ++++++++++++++++++++++++- qmlplugin/hrGraph.h | 16 +++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'qmlplugin') diff --git a/qmlplugin/hrGraph.cpp b/qmlplugin/hrGraph.cpp index 7540083..625300e 100644 --- a/qmlplugin/hrGraph.cpp +++ b/qmlplugin/hrGraph.cpp @@ -59,8 +59,13 @@ void HrGraph::paint(QPainter *painter) for(int i = 0; i < j; i++) { calculatedTimeSeconds = (m_filedata.at(i).time - minTime)/timeDelta; calculatedValue = 1 - (m_filedata.at(i).value - minHrValue)/valueDelta; - points[i] = QPointF(1 + calculatedTimeSeconds*(height()-2), 1 + calculatedValue*(width()-2)); //these +2 -1 are here to make sure that the graph fits within the drawn area, as it will be clipped by qt if it doesn't. + points[i] = QPointF(m_lineWidth + calculatedTimeSeconds*(height()-2*m_lineWidth), m_lineWidth + calculatedValue*(width()-2*m_lineWidth)); //these +2 -1 are here to make sure that the graph fits within the drawn area, as it will be clipped by qt if it doesn't. } + QPen pen; + pen.setWidthF(m_lineWidth); + pen.setColor(m_color); + painter->setRenderHints(QPainter::Antialiasing); + painter->setPen(pen); painter->drawPolyline(points,j); } @@ -100,3 +105,21 @@ void HrGraph::loadGraphData(QDate date) { qDebug() << "heartrate graph file loading done"; file.close(); } + +void HrGraph::setLineColor(QColor color) { + m_color = color; + update(); +} + +QColor HrGraph::lineColor() { + return m_color; +} + +void HrGraph::setLineWidth(float width) { + m_lineWidth = width; + update(); +} + +float HrGraph::lineWidth() { + return m_lineWidth; +} diff --git a/qmlplugin/hrGraph.h b/qmlplugin/hrGraph.h index 3e25311..55f4219 100644 --- a/qmlplugin/hrGraph.h +++ b/qmlplugin/hrGraph.h @@ -39,8 +39,8 @@ class HrGraph : public QQuickPaintedItem { Q_OBJECT - // Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - // Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(float lineWidth READ lineWidth WRITE setLineWidth) + Q_PROPERTY(QColor lineColor READ lineColor WRITE setLineColor NOTIFY lineColorChanged) struct HrDatapoint { qint64 time; @@ -53,14 +53,20 @@ public: signals: void loadingDone(); + void lineColorChanged(); + +public slots: + float lineWidth(); + void setLineWidth(float width); + QColor lineColor(); + void setLineColor(QColor color); private: void updateBasePixmap(); void loadGraphData(QDate date = QDate::currentDate()); - float m_size; - QString m_name; - QColor m_color; + float m_lineWidth = 0; + QColor m_color = QColor(255,255,255); QPixmap m_pixmap; QList m_filedata; bool m_fileLoadStatus; -- cgit v1.2.3-54-g00ecf