qt/LedOK/player/digiclock.h
2023-04-18 14:14:46 +08:00

68 lines
2.1 KiB
C++

#ifndef DIGICLOCK_H
#define DIGICLOCK_H
#include <QWidget>
#include <QTimeZone>
#include <QPainter>
#include <QHBoxLayout>
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 DigiClock : public QWidget {
Q_OBJECT
public:
DigiClock(QString path, const QJsonObject &layer, QWidget *parent = nullptr);
void cal();
void addDate(int, QJsonObject, QHBoxLayout*);
void addYear(QJsonObject layer, QHBoxLayout* tar, 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 // DIGICLOCK_H