qt/LedOK/program/eenviron.h

72 lines
2.1 KiB
C
Raw Normal View History

2022-08-25 18:37:24 +08:00
#ifndef EENVIRON_H
#define EENVIRON_H
#include "ebase.h"
2023-04-27 15:06:24 +08:00
#include "gutil/qgui.h"
2022-08-25 18:37:24 +08:00
2023-10-23 14:58:29 +08:00
struct EnvironItem {
QString text;
QString unit;
QString label;
bool has = true;
};
2022-08-25 18:37:24 +08:00
class EEnviron : public EBase {
Q_OBJECT
public:
2024-02-21 18:08:50 +08:00
static LinkedMap<QString, EnvironItem> genItemMap() {
return LinkedMap<QString, EnvironItem> {
{"temperature", {tr("Temperature"), ""}},
{"humidity", {tr("Humidity"), "%"}},
{"noise", {tr("Noise"), "dB"}},
{"windSpeed", {tr("Wind Speed"), "m/s"}},
{"windDirection", {tr("Wind Direction")}},
{"pm2.5", {"PM2.5", "μg/m³"}},
{"pm10", {"PM10", "μg/m³"}},
{"SO2", {"SO₂", "ppb"}},
{"NO2", {"NO₂", "ppb"}},
{"CO", {"CO", "ppb"}},
{"O3", {"O₃", "ppb"}},
{"pressure", {tr("Pressure"), "hPa"}},
{"rainfall", {tr("Rainfall"), "mm"}},
{"radiation", {tr("Radiation"), "W/m²"}},
{"beam", {tr("Beam"), "lux"}},
{"CO2", {"CO₂", "ppm"}}
};
}
LinkedMap<QString, EnvironItem> itemMap = genItemMap();
2023-10-23 14:58:29 +08:00
QString title;
QColor textColor = Qt::red;
QColor backColor = Qt::transparent;
QFont font = qfont("Arial", 12);
int tempCompen = 0;
int align = 0;
2024-02-21 18:08:50 +08:00
int scrollSpeed = 30;
2023-10-23 14:58:29 +08:00
bool useFahrenheit = false;
bool isSingleLine = false;
2022-08-25 18:37:24 +08:00
2024-02-21 18:08:50 +08:00
static JObj genProg(const JValue &, const QString &, const QString &);
2022-08-25 18:37:24 +08:00
explicit EEnviron(EBase *multiWin = nullptr);
2023-10-23 14:58:29 +08:00
explicit EEnviron(const JObj &json, EBase *multiWin = nullptr);
2022-08-25 18:37:24 +08:00
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
void timerEvent(QTimerEvent *) override;
int type() const override { return EBase::Environ; }
QWidget* attrWgt() override;
bool save(const QString &pRoot) override;
2023-10-23 14:58:29 +08:00
JObj attrJson() const override;
2022-08-25 18:37:24 +08:00
private:
void init();
void drawText(QPainter*, QRectF&);
void calAttr();
int scroll_width;
QString scroll_txt;
int item_cnt = 0;
int timer_id = 0;
int scroll_off = 0;
};
#endif // EENVIRON_H