180 lines
4.2 KiB
C++
180 lines
4.2 KiB
C++
#include "sparklineitem.hpp"
|
|
|
|
#include "sparklinecontent.hpp"
|
|
|
|
namespace ZShell::components {
|
|
|
|
SparklineItem::SparklineItem(QQuickItem* parent) : QQuickItem(parent) {
|
|
setClip(true);
|
|
m_content = new SparklineContent(this);
|
|
m_content->setHistoryLength(m_historyLength);
|
|
m_content->setSliding(m_sliding);
|
|
}
|
|
|
|
void SparklineItem::geometryChange(
|
|
const QRectF& newGeometry, const QRectF& oldGeometry) {
|
|
QQuickItem::geometryChange(newGeometry, oldGeometry);
|
|
m_content->setViewportSize(newGeometry.width(), newGeometry.height());
|
|
updateContentOffset();
|
|
}
|
|
|
|
void SparklineItem::updateContentOffset() {
|
|
m_content->setX(-m_content->stepX() * m_slideProgress);
|
|
}
|
|
|
|
void SparklineItem::applySmoothingRadius(
|
|
internal::CircularBuffer* buffer) const {
|
|
if (buffer) buffer->setSmoothingRadius(qRound(m_smoothing));
|
|
}
|
|
|
|
internal::CircularBuffer* SparklineItem::line1() const {
|
|
return m_line1;
|
|
}
|
|
|
|
void SparklineItem::setLine1(internal::CircularBuffer* buffer) {
|
|
if (m_line1 == buffer) return;
|
|
m_line1 = buffer;
|
|
m_content->setLine1(buffer);
|
|
applySmoothingRadius(buffer);
|
|
emit line1Changed();
|
|
}
|
|
|
|
internal::CircularBuffer* SparklineItem::line2() const {
|
|
return m_line2;
|
|
}
|
|
|
|
void SparklineItem::setLine2(internal::CircularBuffer* buffer) {
|
|
if (m_line2 == buffer) return;
|
|
m_line2 = buffer;
|
|
m_content->setLine2(buffer);
|
|
applySmoothingRadius(buffer);
|
|
emit line2Changed();
|
|
}
|
|
|
|
QColor SparklineItem::line1Color() const {
|
|
return m_line1Color;
|
|
}
|
|
|
|
void SparklineItem::setLine1Color(const QColor& color) {
|
|
if (m_line1Color == color) return;
|
|
m_line1Color = color;
|
|
m_content->setLine1Color(color);
|
|
emit line1ColorChanged();
|
|
}
|
|
|
|
QColor SparklineItem::line2Color() const {
|
|
return m_line2Color;
|
|
}
|
|
|
|
void SparklineItem::setLine2Color(const QColor& color) {
|
|
if (m_line2Color == color) return;
|
|
m_line2Color = color;
|
|
m_content->setLine2Color(color);
|
|
emit line2ColorChanged();
|
|
}
|
|
|
|
qreal SparklineItem::line1FillAlpha() const {
|
|
return m_line1FillAlpha;
|
|
}
|
|
|
|
void SparklineItem::setLine1FillAlpha(qreal alpha) {
|
|
if (qFuzzyCompare(m_line1FillAlpha, alpha)) return;
|
|
m_line1FillAlpha = alpha;
|
|
m_content->setLine1FillAlpha(alpha);
|
|
emit line1FillAlphaChanged();
|
|
}
|
|
|
|
qreal SparklineItem::line2FillAlpha() const {
|
|
return m_line2FillAlpha;
|
|
}
|
|
|
|
void SparklineItem::setLine2FillAlpha(qreal alpha) {
|
|
if (qFuzzyCompare(m_line2FillAlpha, alpha)) return;
|
|
m_line2FillAlpha = alpha;
|
|
m_content->setLine2FillAlpha(alpha);
|
|
emit line2FillAlphaChanged();
|
|
}
|
|
|
|
qreal SparklineItem::maxValue() const {
|
|
return m_maxValue;
|
|
}
|
|
|
|
void SparklineItem::setMaxValue(qreal value) {
|
|
if (qFuzzyCompare(m_maxValue, value)) return;
|
|
m_maxValue = value;
|
|
m_content->setMaxValue(value);
|
|
emit maxValueChanged();
|
|
}
|
|
|
|
qreal SparklineItem::slideProgress() const {
|
|
return m_slideProgress;
|
|
}
|
|
|
|
void SparklineItem::setSlideProgress(qreal progress) {
|
|
if (qFuzzyCompare(m_slideProgress, progress)) return;
|
|
m_slideProgress = progress;
|
|
updateContentOffset();
|
|
emit slideProgressChanged();
|
|
}
|
|
|
|
int SparklineItem::historyLength() const {
|
|
return m_historyLength;
|
|
}
|
|
|
|
void SparklineItem::setHistoryLength(int length) {
|
|
if (m_historyLength == length) return;
|
|
m_historyLength = length;
|
|
m_content->setHistoryLength(length);
|
|
updateContentOffset();
|
|
emit historyLengthChanged();
|
|
}
|
|
|
|
qreal SparklineItem::lineWidth() const {
|
|
return m_lineWidth;
|
|
}
|
|
|
|
void SparklineItem::setLineWidth(qreal width) {
|
|
if (qFuzzyCompare(m_lineWidth, width)) return;
|
|
m_lineWidth = width;
|
|
m_content->setLineWidth(width);
|
|
emit lineWidthChanged();
|
|
}
|
|
|
|
void SparklineItem::setSliding(bool sliding) {
|
|
if (m_sliding == sliding) return;
|
|
m_sliding = sliding;
|
|
m_content->setSliding(sliding);
|
|
updateContentOffset();
|
|
emit slidingChanged();
|
|
}
|
|
|
|
bool SparklineItem::sliding() const {
|
|
return m_sliding;
|
|
}
|
|
|
|
void SparklineItem::setSmoothing(qreal smoothing) {
|
|
smoothing = qMax<qreal>(0.0, smoothing);
|
|
if (qFuzzyCompare(m_smoothing, smoothing)) return;
|
|
m_smoothing = smoothing;
|
|
applySmoothingRadius(m_line1);
|
|
applySmoothingRadius(m_line2);
|
|
emit smoothingChanged();
|
|
}
|
|
|
|
qreal SparklineItem::smoothing() const {
|
|
return m_smoothing;
|
|
}
|
|
|
|
void SparklineItem::setCurveSmoothing(bool enabled) {
|
|
if (m_curveSmoothing == enabled) return;
|
|
m_curveSmoothing = enabled;
|
|
m_content->setCurveSmoothing(enabled);
|
|
emit curveSmoothingChanged();
|
|
}
|
|
|
|
bool SparklineItem::curveSmoothing() const {
|
|
return m_curveSmoothing;
|
|
}
|
|
|
|
} // namespace ZShell::components
|