File indexing completed on 2024-05-12 17:24:09

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: MIT
0003 
0004 #pragma once
0005 
0006 #include <QObject>
0007 #include <QColor>
0008 #include <QVariantAnimation>
0009 
0010 class ColorGradientInterpolator : public QObject
0011 {
0012     Q_OBJECT
0013     Q_PROPERTY(QColor color READ color NOTIFY colorChanged)
0014     Q_PROPERTY(double progress READ progress WRITE setProgress NOTIFY progressChanged)
0015     Q_PROPERTY(QVariantList gradientStops READ gradientStops WRITE setGradientStops NOTIFY gradientStopsChanged)
0016 
0017 public:
0018     explicit ColorGradientInterpolator(QObject *parent = nullptr);
0019 
0020     QColor color() const;
0021 
0022     double progress() const;
0023     void setProgress(const double progress);
0024 
0025     QVariantList gradientStops() const;
0026     void setGradientStops(const QVariantList &gradientStops);
0027 
0028 Q_SIGNALS:
0029     void progressChanged();
0030     void gradientStopsChanged();
0031     void colorChanged();
0032 
0033 private:
0034     double m_progress = 0.0;
0035     QVariantAnimation m_gradient;
0036 };