qt/LedOK/player/eledigiclock.h
2023-10-20 18:30:14 +08:00

68 lines
2.0 KiB
C++

#ifndef ELEDIGICLOCK_H
#define ELEDIGICLOCK_H
#include "gutil/qjson.h"
#include "gutil/qgui.h"
#include <QTimeZone>
#include <QPainter>
class ImgWgt : public QWidget {
public:
ImgWgt(QWidget *parent = nullptr) : QWidget{parent} {}
ImgWgt(const QPixmap &img) :img(img){
setFixedSize(this->img.size());
}
ImgWgt(QPixmap &&img) {
this->img = std::move(img);
setFixedSize(this->img.size());
}
ImgWgt &operator=(const QPixmap &img) {
this->img = img;
setFixedSize(this->img.size());
return *this;
}
ImgWgt &operator=(QPixmap &&img) {
this->img = std::move(img);
setFixedSize(this->img.size());
return *this;
}
QPixmap img;
protected:
virtual void paintEvent(QPaintEvent *) override {
if(img.isNull()) return;
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
painter.drawPixmap(0, 0, width(), height(), img);
}
};
const QString weeks[7]{"MON","TUE","WED","THU","FRI","SAT","SUN"};
class EleDigiClock : public QWidget {
Q_OBJECT
public:
EleDigiClock(QString path, const JValue &layer, QWidget *parent = nullptr);
void cal();
void addDate(int, const JValue &, HBox*);
void addYear(const JValue &layer, HBox* tar, const QPixmap &sep);
QTimeZone timeZone;
ImgWgt *yearComps[4] {new ImgWgt(), new ImgWgt(), new ImgWgt(), new ImgWgt()};
ImgWgt *monthComps[2] {new ImgWgt(), new ImgWgt()};
ImgWgt *dayComps[2] {new ImgWgt(), new ImgWgt()};
ImgWgt *weekComp = new ImgWgt(), *ampmComp = new ImgWgt();
ImgWgt *hourComps[2] {new ImgWgt(), new ImgWgt()};
ImgWgt *minComps[2] {new ImgWgt(), new ImgWgt()};
ImgWgt *secComps[2] {new ImgWgt(), new ImgWgt()};
QMap<QString, QPixmap> imgs;
QString timeptn;
bool multiline, weekly, isSingleMonth;
int timerId = 0;
protected:
void timerEvent(QTimerEvent *) override;
void showEvent(QShowEvent *) override;
};
#endif // ELEDIGICLOCK_H