108 lines
2.2 KiB
C++
108 lines
2.2 KiB
C++
|
|
|
|
#pragma once
|
|
#include "lts_widgets_export.h"
|
|
|
|
#include <QObject>
|
|
#include <QWidget>
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
|
|
class LTSWIDGETS_EXPORT LtsLedWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
enum class AspectHint { WidthIsHeight, NoHint, HeightIsWidth };
|
|
Q_ENUM(AspectHint)
|
|
|
|
Q_PROPERTY(QColor oncolor READ onColor WRITE setOnColor)
|
|
Q_PROPERTY(QColor offcolor READ offColor WRITE setOffColor)
|
|
Q_PROPERTY(bool status READ status WRITE setStatus)
|
|
Q_PROPERTY(bool usesGradient READ usesGradient WRITE setUseGradient)
|
|
Q_PROPERTY(int animTime READ animTime WRITE setAnimTime)
|
|
Q_PROPERTY(AspectHint aspectHint READ aspectHint WRITE setAspectHint)
|
|
Q_PROPERTY(QColor currentcolor READ currentColor WRITE setCurrentColor DESIGNABLE false)
|
|
|
|
explicit LtsLedWidget(QWidget* parent = nullptr, const QColor& oncolor = Qt::red,
|
|
const QColor& offcolor = Qt::black, bool useGradient = true, int animtime = 0);
|
|
|
|
void paintEvent(QPaintEvent* pe);
|
|
|
|
void setAnimTime(int time)
|
|
{
|
|
m_animTime = time;
|
|
}
|
|
|
|
int animTime() const
|
|
{
|
|
return m_animTime;
|
|
}
|
|
|
|
bool status() const
|
|
{
|
|
return m_status;
|
|
}
|
|
|
|
void setUseGradient(bool useGradient);
|
|
|
|
bool usesGradient() const
|
|
{
|
|
return m_gradient;
|
|
}
|
|
|
|
void setOnColor(const QColor& oncolor);
|
|
|
|
QColor onColor() const
|
|
{
|
|
return m_oncolor;
|
|
}
|
|
|
|
void setOffColor(const QColor& offcolor);
|
|
|
|
QColor offColor() const
|
|
{
|
|
return m_offcolor;
|
|
}
|
|
|
|
void setColor(const QColor& oncolor, const QColor& offcolor = Qt::black);
|
|
|
|
QColor currentColor() const
|
|
{
|
|
return m_currentcolor;
|
|
}
|
|
|
|
void resizeEvent(QResizeEvent* event);
|
|
|
|
AspectHint aspectHint() const
|
|
{
|
|
return m_aspectHint;
|
|
}
|
|
|
|
public slots:
|
|
|
|
void setStatus(bool status);
|
|
|
|
void setAspectHint(AspectHint aspectHint)
|
|
{
|
|
m_aspectHint = aspectHint;
|
|
}
|
|
|
|
private:
|
|
void setCurrentColor(const QColor& currentcolor);
|
|
|
|
void animate();
|
|
|
|
bool m_status;
|
|
QColor m_oncolor;
|
|
QColor m_offcolor;
|
|
QColor m_currentcolor;
|
|
|
|
bool m_gradient;
|
|
int m_animTime;
|
|
AspectHint m_aspectHint = AspectHint::NoHint;
|
|
};
|
|
|
|
} // namespace LtsWidgets
|