This commit is contained in:
Gangphon 2024-08-07 18:18:37 +08:00
parent cd2f566bcd
commit 135e321e60
59 changed files with 5314 additions and 4294 deletions

View File

@ -125,7 +125,6 @@ SOURCES += \
gutil/qwaitingdlg.cpp \
basedlg.cpp \
basewin.cpp \
cfg.cpp \
device/ctrlhdmipanel.cpp \
device/ctrlnetworkpanel.cpp \
device/ctrlpowerpanel.cpp \
@ -135,7 +134,6 @@ SOURCES += \
deviceitem.cpp \
devicepanel.cpp \
ffplayer.cpp \
globaldefine.cpp \
gutil/cpp.cpp \
gutil/qgui.cpp \
gutil/qjson.cpp \
@ -154,6 +152,7 @@ SOURCES += \
player/posdlg.cpp \
player/srccopy.cpp \
progpanel.cpp \
program/etimer2.cpp \
synctimer.cpp \
tools.cpp \
device/ctrladvancedpanel.cpp \
@ -194,7 +193,6 @@ HEADERS += \
gutil/qwaitingdlg.h \
basedlg.h \
basewin.h \
cfg.h \
device/ctrlhdmipanel.h \
device/ctrlnetworkpanel.h \
device/ctrlpowerpanel.h \
@ -204,11 +202,11 @@ HEADERS += \
deviceitem.h \
devicepanel.h \
ffplayer.h \
globaldefine.h \
gutil/cpp.h \
gutil/qgui.h \
gutil/qjson.h \
gutil/qnetwork.h \
main.h \
mainwindow.h \
mguangyingpinwidget.h \
player/eleanaclock.h \
@ -222,6 +220,7 @@ HEADERS += \
player/posdlg.h \
player/srccopy.h \
progpanel.h \
program/etimer2.h \
synctimer.h \
tools.h \
device/ctrladvancedpanel.h \

View File

@ -40,7 +40,7 @@ void BaseWin::paintEvent(QPaintEvent *e) {
void BaseWin::mousePressEvent(QMouseEvent *e) {
if(e->button() != Qt::LeftButton) return;
setFrmSec(e->pos());
if(mFrmSec==Qt::TitleBarArea || mFrmSec==Qt::TopSection || mFrmSec==Qt::LeftSection || mFrmSec==Qt::TopLeftSection) mPressRel = pos() - e->globalPos();
if(mFrmSec==Qt::TitleBarArea || mFrmSec==Qt::TopSection || mFrmSec==Qt::LeftSection || mFrmSec==Qt::TopLeftSection) mPressRel = -e->pos();
else if(mFrmSec==Qt::BottomRightSection) mPressRel = QPoint(width() - e->globalX(), height() - e->globalY());
else if(mFrmSec==Qt::RightSection ) mPressRel = QPoint(width() - e->globalX(), height() );
else if(mFrmSec==Qt::BottomSection ) mPressRel = QPoint(width() , height() - e->globalY());

View File

@ -36,8 +36,8 @@ protected:
void setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor);
QPoint mPressRel{INT_MAX, INT_MAX};
Qt::WindowFrameSection mFrmSec{Qt::NoSection};
bool isActive{false};
Qt::WindowFrameSection mFrmSec = Qt::NoSection;
bool isActive = false;
};
#endif // BASEWIN_H

View File

@ -1,10 +0,0 @@
#include "cfg.h"
#include <QApplication>
#include <QStandardPaths>
const QString UpdVerUrl = "https://www.ledok.cn/download/LedOK Express Updates.json";
QString programsDir() {
static auto rtn = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/programs";
return rtn;
}

View File

@ -1,13 +0,0 @@
#ifndef CFG_H
#define CFG_H
#include <QString>
#define PAGEDEL_SUFFIX "@D$E$L&20111005&"
#define RECTF_INVALID QRectF(-9999, -9999, 0, 0)
extern const QString UpdVerUrl;
QString programsDir();
#endif // CFG_H

View File

@ -1,6 +1,6 @@
#include "ctrladvancedpanel.h"
#include "device/progressesdlg.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include "base/changepasswordform.h"
#include "tools.h"
@ -218,6 +218,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
fdRealtimeServer = new QComboBox;
fdRealtimeServer->addItem("www.ledokcloud.com/realtime");
fdRealtimeServer->addItem("192.168.8.:10010");
fdRealtimeServer->setMinimumWidth(260);
fdRealtimeServer->setEditable(true);
hBox->addWidget(fdRealtimeServer);
@ -632,36 +633,90 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
});
hBox->addWidget(btnGetLog);
hBox->addStretch();
hBox = new HBox(vBox);
auto btnLogOn = new QPushButton("Log On");
btnLogOn->setProperty("ssType", "progManageTool");
connect(btnLogOn, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
JObj json;
json.insert("_id", "SetLogSwitch");
json.insert("_type", "SetLogSwitch");
json.insert("isOn", true);
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetRealtimeServer")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetRealtimeServer"))
}
}
});
hBox->addWidget(btnLogOn);
auto btnViewProg = new QPushButton("View Prog JSON");
auto btnLogOff = new QPushButton("Log Off");
btnLogOff->setProperty("ssType", "progManageTool");
connect(btnLogOff, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
JObj json;
json.insert("_id", "SetLogSwitch");
json.insert("_type", "SetLogSwitch");
json.insert("isOn", false);
if(gSelCards.count() == 1) {
auto waitingDlg = new WaitingDlg(this, tr("SetRealtimeServer")+" ...");
Def_CtrlReqPre
connect(reply, &QNetworkReply::finished, this, [=] {
Def_CtrlSetReqAfter
});
} else {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetRealtimeServer"))
}
}
});
hBox->addWidget(btnLogOff);
hBox->addStretch();
grpPlayer = new QGroupBox;
vBox->addWidget(grpPlayer);
hBox = new HBox(grpPlayer);
hBox->setContentsMargins(6,0,6,6);
auto btnViewProg = new QPushButton("View JSON");
btnViewProg->setProperty("ssType", "progManageTool");
connect(btnViewProg, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
JObj json{{"_type", "GetFile"}, {"name", "program"}};
auto fd = new QTextEdit;
JObj json{{"_type", "GetJsonWithFileInfo"}};
auto edit = new QTextEdit;
LocalObj lll;
connect(fd, &QTextEdit::destroyed, &lll, &LocalObj::reset);
fd->setAttribute(Qt::WA_DeleteOnClose);
fd->setTabStopDistance(26);
auto ft = fd->font();
connect(edit, &QTextEdit::destroyed, &lll, &LocalObj::reset);
edit->setAttribute(Qt::WA_DeleteOnClose);
edit->setTabStopDistance(26);
auto ft = edit->font();
ft.setFamily("Consolas");
fd->setFont(ft);
fd->setWindowTitle("program");
fd->resize(600, 900);
fd->show();
edit->setFont(ft);
edit->setWindowTitle("program");
edit->resize(600, 900);
edit->show();
for(auto &card : gSelCards) {
fd->append(card.id+" Prog JSON");
edit->append(card.id+" Prog JSON");
TcpSocket tcp;
tcp.connectToHost(card.ip, 3333);
if(! tcp.waitForConnected(10000)) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitConnected\n");
edit->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitConnected\n");
continue;
}
auto resNum = tcp.write(JToBytes(json));
@ -669,84 +724,29 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at write\n");
edit->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at write\n");
continue;
}
if(! tcp.waitForReadyRead()) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead\n");
edit->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead\n");
continue;
}
fd->insertPlainText(tcp.readAll());
edit->append(tcp.readAll());
while(tcp.waitForReadyRead(1000)) {
if(lll.cnt==0) return;
fd->insertPlainText(tcp.readAll());
edit->insertPlainText(tcp.readAll());
}
tcp.close();
if(lll.cnt==0) return;
if(tcp.error()!=QAbstractSocket::SocketTimeoutError) fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead2\n");
fd->append("");
if(tcp.error()!=QAbstractSocket::SocketTimeoutError) edit->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead2\n");
edit->append("END");
}
});
hBox->addWidget(btnViewProg);
auto btnListFiles = new QPushButton("List Prog Files");
btnListFiles->setProperty("ssType", "progManageTool");
connect(btnListFiles, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
JObj json{{"_type", "ListProgFiles"}};
auto fd = new QTextEdit;
LocalObj lll;
connect(fd, &QTextEdit::destroyed, &lll, &LocalObj::reset);
fd->setAttribute(Qt::WA_DeleteOnClose);
auto ft = fd->font();
ft.setFamily("Consolas");
fd->setFont(ft);
fd->setWindowTitle("List Prog Files");
fd->resize(600, 900);
fd->show();
for(auto &card : gSelCards) {
fd->append(card.id+" Prog Files");
TcpSocket tcp;
tcp.connectToHost(card.ip, 3333);
if(! tcp.waitForConnected(10000)) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitConnected\n");
continue;
}
auto resNum = tcp.write(JToBytes(json));
tcp.flush();
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at write\n");
continue;
}
if(! tcp.waitForReadyRead()) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead\n");
continue;
}
fd->insertPlainText(tcp.readAll());
while(tcp.waitForReadyRead(1000)) {
if(lll.cnt==0) return;
fd->insertPlainText(tcp.readAll());
}
tcp.close();
if(lll.cnt==0) return;
if(tcp.error()!=QAbstractSocket::SocketTimeoutError) fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead2\n");
fd->append("");
}
});
hBox->addWidget(btnListFiles);
auto btnGetPlayerInfo = new QPushButton("Get Player Info");
auto btnGetPlayerInfo = new QPushButton("Get Info");
btnGetPlayerInfo->setProperty("ssType", "progManageTool");
connect(btnGetPlayerInfo, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
@ -788,7 +788,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead\n");
continue;
}
fd->insertPlainText(tcp.readAll());
fd->append(tcp.readAll());
while(tcp.waitForReadyRead(1000)) {
if(lll.cnt==0) return;
fd->insertPlainText(tcp.readAll());
@ -796,12 +796,12 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
tcp.close();
if(lll.cnt==0) return;
if(tcp.error()!=QAbstractSocket::SocketTimeoutError) fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead2\n");
fd->append("");
fd->append("END");
}
});
hBox->addWidget(btnGetPlayerInfo);
auto GetBuf = new QPushButton("Get Player Log");
auto GetBuf = new QPushButton("Get Log");
GetBuf->setProperty("ssType", "progManageTool");
connect(GetBuf, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
@ -843,7 +843,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead\n");
continue;
}
fd->insertPlainText(tcp.readAll());
fd->append(tcp.readAll());
while(tcp.waitForReadyRead(1000)) {
if(lll.cnt==0) return;
fd->insertPlainText(tcp.readAll());
@ -851,11 +851,66 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
tcp.close();
if(lll.cnt==0) return;
if(tcp.error()!=QAbstractSocket::SocketTimeoutError) fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead2\n");
fd->append("");
fd->append("END");
}
});
hBox->addWidget(GetBuf);
auto btnListFiles = new QPushButton("List Files");
btnListFiles->setProperty("ssType", "progManageTool");
connect(btnListFiles, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
QMessageBox::information(this, tr("Tip"), tr("NoSelectedController"));
return;
}
JObj json{{"_type", "ListProgFiles"}};
auto fd = new QTextEdit;
LocalObj lll;
connect(fd, &QTextEdit::destroyed, &lll, &LocalObj::reset);
fd->setAttribute(Qt::WA_DeleteOnClose);
auto ft = fd->font();
ft.setFamily("Consolas");
fd->setFont(ft);
fd->setWindowTitle("List Prog Files");
fd->resize(600, 900);
fd->show();
for(auto &card : gSelCards) {
fd->append(card.id+" Prog Files");
TcpSocket tcp;
tcp.connectToHost(card.ip, 3333);
if(! tcp.waitForConnected(10000)) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitConnected\n");
continue;
}
auto resNum = tcp.write(JToBytes(json));
tcp.flush();
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at write\n");
continue;
}
if(! tcp.waitForReadyRead()) {
tcp.close();
if(lll.cnt==0) return;
fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead\n");
continue;
}
fd->append(tcp.readAll());
while(tcp.waitForReadyRead(1000)) {
if(lll.cnt==0) return;
fd->insertPlainText(tcp.readAll());
}
tcp.close();
if(lll.cnt==0) return;
if(tcp.error()!=QAbstractSocket::SocketTimeoutError) fd->append(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" at WaitRead2\n");
fd->append("END");
}
});
hBox->addWidget(btnListFiles);
auto btnDownFile = new QPushButton("Down File");
btnDownFile->setProperty("ssType", "progManageTool");
connect(btnDownFile, &QPushButton::clicked, this, [this] {
@ -2054,7 +2109,7 @@ CtrlAdvancedPanel::CtrlAdvancedPanel() {
});
hBox->addWidget(btnM80Set);
btnM80Refresh = new QPushButton();
btnM80Refresh = new QPushButton;
btnM80Refresh->setProperty("ssType", "progManageTool");
connect(btnM80Refresh, &QPushButton::clicked, this, [this] {
if(gSelCards.isEmpty()) {
@ -2760,7 +2815,9 @@ void CtrlAdvancedPanel::init() {
|| card.id.startsWith("m5s", Qt::CaseInsensitive)
|| card.id.startsWith("m6s", Qt::CaseInsensitive)
|| card.id.startsWith("m7", Qt::CaseInsensitive)
|| card.id.startsWith("y0", Qt::CaseInsensitive)
|| card.id.startsWith("y1", Qt::CaseInsensitive)
|| card.id.startsWith("y3", Qt::CaseInsensitive)
|| card.id.startsWith("y4", Qt::CaseInsensitive)
|| card.id.startsWith("y5", Qt::CaseInsensitive);
grpY50->setVisible(isY50);
@ -2801,12 +2858,13 @@ void CtrlAdvancedPanel::transUi() {
btnLedSet->setText(tr("Start LedSet4"));
btnReceCardsGet->setText(tr("Get Receive Card Num"));
grpPlayer->setTitle(tr("Player Debug"));
grpM80->setTitle("M80 "+tr("Config"));
btnM80Refresh->setText(tr("Refresh"));
btnM80Restore->setText(tr("Restore to default"));
btnM80Set->setText(tr("Set"));
grpY50->setTitle("M50S / M60S / M70S / M5H / M7L / ST50 / Y1G / Y1C / Y4A / Y5A "+tr("Resolution Config"));
grpY50->setTitle("M50S / M60S / M70S / M5H / M7L / ST50 / Y1G / Y1C / Y4A / Y5A / Y08 / Y35 / Y37 "+tr("Resolution Config"));
fdDisMode->setItemText(0, tr("Full screen"));
fdDisMode->setItemText(1, tr("Part"));
btnY50Set->setText(tr("Set"));
@ -2911,15 +2969,11 @@ void PlayerBackSendThread::run() {
return;
}
QFileInfo info(file);
auto baseName = info.baseName();
auto remain = info.size();
auto req = QJsonObject();
JObj req;
req.insert("_type", "imgFileStart");
req.insert("id", baseName);
req.insert("size", remain);
req.insert("zVer","xixun1");
auto resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
auto resNum = tcp.write(JToBytes(req));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'imgFileStart'");
tcp.close();
@ -2955,27 +3009,6 @@ void PlayerBackSendThread::run() {
remain -= resNum;
}
file->close();
req = QJsonObject();
req.insert("_type", "imgFileEnd");
req.insert("id", baseName);
req.insert("zVer","xixun1");
resNum = tcp.write(QJsonDocument(req).toJson(QJsonDocument::Compact));
if(resNum == -1 || ! tcp.waitForBytesWritten()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when write 'imgFileEnd'");
tcp.close();
return;
}
if(! tcp.waitForReadyRead()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when waitForRead 'imgFileEnd'");
tcp.close();
return;
}
auto resp = tcp.readAll();
if(resp.isEmpty()) {
emit emErr(QString(socketErrKey(tcp.error()))+" ("+QString::number(tcp.error())+") "+tcp.errorString()+" when read 'imgFileEnd'");
tcp.close();
return;
}
tcp.close();
emit emErr("");
}

View File

@ -55,7 +55,7 @@ private:
QLabel *lbTimingReboot;
QGroupBox *grpM80, *grpY50;
QGroupBox *grpPlayer, *grpM80, *grpY50;
QComboBox *fdM80Resolu, *fdDisMode;
QPushButton *btnM80Set, *btnY50Set;
QPushButton *btnM80Refresh;

View File

@ -1,7 +1,7 @@
#include "ctrlbrightpanel.h"
#include "gutil/qwaitingdlg.h"
#include "gutil/qnetwork.h"
#include "globaldefine.h"
#include "main.h"
#include "tools.h"
#include "deviceitem.h"
#include "xlsxdocument.h"

View File

@ -2,7 +2,7 @@
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "tools.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include <QMessageBox>
#include <QButtonGroup>

View File

@ -1,6 +1,6 @@
#include "ctrlnetworkpanel.h"
#include "gutil/qwaitingdlg.h"
#include "globaldefine.h"
#include "main.h"
#include "tools.h"
#include "devicepanel.h"
#include "gutil/qgui.h"

View File

@ -1,5 +1,5 @@
#include "ctrlpowerpanel.h"
#include "globaldefine.h"
#include "main.h"
#include "deviceitem.h"
#include "devicepanel.h"
#include "gutil/qwaitingdlg.h"

View File

@ -5,7 +5,7 @@
#include "QFileDialog"
#include <QMessageBox>
#include <QJsonObject>
#include "globaldefine.h"
#include "main.h"
#include "tools.h"
#include "deviceitem.h"
#include "devicepanel.h"

View File

@ -7,7 +7,7 @@
#include <QLineEdit>
#include <QJsonObject>
#include <QJsonDocument>
#include "globaldefine.h"
#include "main.h"
#include <QButtonGroup>
#include <QMessageBox>
#include <QHostAddress>

View File

@ -1,7 +1,7 @@
#include "ctrlverifyclockpanel.h"
#include "gutil/qwaitingdlg.h"
#include "gutil/qnetwork.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qgui.h"
#include "tools.h"
#include <QMessageBox>

View File

@ -1,5 +1,5 @@
#include "ctrlvolumepanel.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include "gutil/qnetwork.h"
#include "tools.h"

View File

@ -2,7 +2,7 @@
#include "gutil/qcore.h"
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "globaldefine.h"
#include "main.h"
#include <QAction>
#include <QFileDialog>
#include <QLineEdit>

View File

@ -353,6 +353,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
end:
item->setText("ip", card.ip);
item->setText("alias", card.alias);
item->setText("firmware", card.firmwareVer);
item->fdOnline->setPixmap({card.isOnline ? ":/res/online.png" : ":/res/offline.png"});
item->OnCheckSoftVersions();
item->OnCheckFpgaVersions();
@ -448,7 +449,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
table->addCol("alias", tr("Alias"), 80);
table->addCol("encrypt", tr("Security"), 40);
table->addCol("progress", tr("Progress"), 100);
table->addCol("remarks", tr("State"), 200, QHeaderView::Stretch);
table->addCol("remarks", tr("State"), 200);
table->addCol("playerVer", "XixunPlayer", 70);
table->addCol("cardsystem", "cardsystem", 70);
table->addCol("starter", "starter", 70);
@ -457,6 +458,7 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
table->addCol("fpga", "FPGA", 70);
table->addCol("connection", "connection", 70);
table->addCol("update", "update", 40);
table->addCol("firmware", "Firmware", 100);
table->setDefs()->setHeaderAlignC();
table->addFd();
table->setSelectionMode(QAbstractItemView::NoSelection);
@ -472,18 +474,18 @@ UpgradeApkDialog::UpgradeApkDialog(QWidget *parent) : QDialog(parent) {
show();
emit btnRefresh->clicked();
int ccs[]{"taxiapp"**table, "fpga"**table};
for(auto cc : ccs) {
auto size = table->sizeHintForColumn(cc);
if(size==0) {
int cnt = 8;
do {
wait(50);
size = table->sizeHintForColumn(cc);
} while(size==0 && --cnt);
}
if(size>table->header()->sectionSize(cc)) table->header()->resizeSection(cc, size);
}
// int ccs[]{"playerVer"**table, "firmware"**table};
// for(auto cc : ccs) {
// auto size = table->sizeHintForColumn(cc);
// if(size==0) {
// int cnt = 8;
// do {
// wait(50);
// size = table->sizeHintForColumn(cc);
// } while(size==0 && --cnt);
// }
// if(size>table->header()->sectionSize(cc)) table->header()->resizeSection(cc, size);
// }
}
void UpgradeApkDialog::sendProgress(UpdateApkItem *item) {

View File

@ -1,6 +1,6 @@
#include "deviceitem.h"
#include "devicepanel.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"

View File

@ -2,7 +2,7 @@
#define DEVICEITEM_H
#include "base/loqtreewidget.h"
#include "globaldefine.h"
#include "main.h"
#include <QLabel>
#include <QPushButton>

View File

@ -1,5 +1,5 @@
#include "devicepanel.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "deviceitem.h"
@ -139,7 +139,7 @@ QPushButton:hover {background-color: #08b;}
hBox->addWidget(areaFlash);
mHBox = new HBox(vBox);
vBox->addWidget(splitter = new QSplitter, 1);
auto table = new LoQTreeWidget;
table->addCol("#", "", 20);
@ -169,7 +169,7 @@ QPushButton:hover {background-color: #08b;}
for(int i=0; i<cnt; i++) if(table->item(i)->checkState("check") == Qt::Checked) gSelCards.append(static_cast<DeviceItem*>(table->topLevelItem(i))->mCard);
emit sigSelectedDeviceList();
});
mHBox->addWidget(mDeviceTable = table);
splitter->addWidget(mDeviceTable = table);
connect(&mUdpTimer, &QTimer::timeout, this, &DevicePanel::sendGetInfo);
connect(&mUdpSocket, &QUdpSocket::readyRead, this, [this] {
@ -228,7 +228,7 @@ QPushButton:hover {background-color: #08b;}
msgpre.append(tr("Android OS Resolution")).append(": ").append(item->mCard.ScreenResolution).append("\n");
msgpre.append(tr("Android Version")).append(": ").append(item->mCard.androidVersion).append("\n");
msgpre.append(tr("FPGA Version")).append(": ").append(item->mCard.HardVersion).append("\n");
msgpre.append(tr("Firmware Version")).append(": ").append(item->mCard.FirmwareVersion).append("\n");
msgpre.append(tr("Firmware Version")).append(": ").append(item->mCard.firmwareVer).append("\n");
msgpre.append("IMEI: ").append(item->mCard.IMEI).append("\n");
QMessageBox msgBox(QMessageBox::Information, item->mCard.id+" "+tr("Detail Info"), msgpre + tr("Player Version")+": "+tr("Getting")+" ...");
QJsonObject json;
@ -392,7 +392,7 @@ void DevicePanel::transCtrl() {
}
}
void DevicePanel::newCtrl() {
mHBox->addWidget(mDeviceCtrlPanel = new QWidget);
splitter->addWidget(mDeviceCtrlPanel = new QWidget);
auto vBox = new QVBoxLayout(mDeviceCtrlPanel);
vBox->setContentsMargins(0,0,0,0);
vBox->setSpacing(0);
@ -494,6 +494,10 @@ void DevicePanel::newCtrl() {
mBtnGrp->button(0)->setChecked(true);
splitter->setStretchFactor(0, 0);
splitter->setStretchFactor(1, 1);
splitter->setSizes({300, 1});
transCtrl();
}
@ -507,7 +511,7 @@ void DevicePanel::init(DeviceItem *item) {
auto err = errStrWithJson(reply, &json);
if(! err.isEmpty()) return;
item->mCard.BrightnessLevel = json["BrightnessLevel"].toInt();
item->mCard.FirmwareVersion = json["FirmwareVersion"].toStr();
item->mCard.firmwareVer = json["FirmwareVersion"].toStr();
item->mCard.HardVersion = json["HardVersion"].toStr();
item->mCard.ScreenResolution = json["ScreenResolution"].toStr();
item->mCard.IMEI = json["IMEI"].toStr();

View File

@ -2,7 +2,7 @@
#define DEVICEPANEL_H
#include "base/loqtreewidget.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qgui.h"
#include <QTimer>
#include <QPushButton>
@ -34,7 +34,7 @@ public:
QLabel *label_3, *nDeviceNum;
QComboBox *bnSpecifyIP;
QPushButton *btnRefresh;
HBox *mHBox{0};
QSplitter *splitter;
QTextEdit *fdInfo;
QButtonGroup *mBtnGrp;

View File

@ -1,145 +0,0 @@
#include "globaldefine.h"
#include "devicepanel.h"
#include "deviceitem.h"
#include "gutil/qnetwork.h"
#include <QDir>
#include <QDateTime>
#include <QCoreApplication>
#include <QMessageBox>
#include <QMetaEnum>
QString gFileHome;
QString gApkHome;
QList<LedCard> gSelCards;
bool gVideoCompress = false;
bool gVideoTranscoding = false;
bool gTextAntialiasing = false;
bool gWidthSplit = false;
int gSendBatch = 5;
bool gHideDetect = false;
bool gShowAlias = false;
bool gShowLora = false;
DeviceItem *findItem(QString id) {
int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; ++i) {
auto item = (DeviceItem*) gDevicePanel->mDeviceTable->topLevelItem(i);
if(item==0) continue;
if(item->mCard.id==id) return item;
}
return 0;
}
QString checkReply(QNetworkReply *reply, QJsonDocument *outJson) {
auto err = errStr(reply);
if(! err.isEmpty()) {
auto data = reply->readAll();
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
if(outJson) {
auto data = reply->readAll();
QJsonParseError jsonErr;
*outJson = QJsonDocument::fromJson(data, &jsonErr);
if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
}
return "";
}
QString errStrWithJson(QNetworkReply *reply, JValue *outJson, QByteArray *outData) {
auto err = errStr(reply);
auto data = reply->readAll();
if(outData) *outData = data;
if(! err.isEmpty()) {
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
QString error;
auto json = JFrom(data, &error);
if(! error.isEmpty()) return "JSON Error: "+error+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+data;
if(outJson) *outJson = json;
return "";
}
QString checkReplyForJson(QNetworkReply *reply, QJsonDocument *outJson, QByteArray *outData) {
auto err = errStr(reply);
auto data = reply->readAll();
if(outData) *outData = data;
if(! err.isEmpty()) {
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
QJsonParseError jsonErr;
QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr);
if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+data;
if(outJson) outJson->swap(json);
return "";
}
QString checkReplyForJson(QNetworkReply *reply, QString errField) {
auto err = errStr(reply);
auto data = reply->readAll();
if(! err.isEmpty()) {
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
QJsonParseError jsonErr;
QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr);
if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
if(! json["success"].toBool()) {
auto errStr = json[errField].toString();
return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+(errStr.isEmpty() ? data : errStr);
}
return "";
}
quint64 dirFileSize(const QString &path) {
QDir dir(path);
quint64 size = 0;
auto infos = dir.entryInfoList(QDir::Files);
foreach(QFileInfo fileInfo, infos) size += fileInfo.size();
auto subDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QString subDir, subDirs) size += dirFileSize(path + QDir::separator() + subDir);
return size;
}
bool copyDir(const QString &source, const QString &destination, bool override) {
QDir directory(source);
if(!directory.exists()) return false;
QString srcPath = QDir::toNativeSeparators(source);
if(!srcPath.endsWith(QDir::separator())) srcPath += QDir::separator();
QString dstPath = QDir::toNativeSeparators(destination);
if (!dstPath.endsWith(QDir::separator())) dstPath += QDir::separator();
bool error = false;
QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
for (QStringList::size_type i=0; i != fileNames.size(); ++i)
{
QString fileName = fileNames.at(i);
QString srcFilePath = srcPath + fileName;
QString dstFilePath = dstPath + fileName;
QFileInfo fileInfo(srcFilePath);
if (fileInfo.isFile() || fileInfo.isSymLink())
{
if (override)
{
QFile::setPermissions(dstFilePath, QFile::WriteOwner);
}
QFile::copy(srcFilePath, dstFilePath);
}
else if (fileInfo.isDir())
{
QDir dstDir(dstFilePath);
dstDir.mkpath(dstFilePath);
if (!copyDir(srcFilePath, dstFilePath, override))
{
error = true;
}
}
}
return !error;
}
unsigned char GetCheckCodeIn8(unsigned char *str, unsigned int size) {
unsigned char checkCode = 0;
for(int i=0; i<size; i++) checkCode += str[i];
return (~checkCode) & 0xff;
}

View File

@ -235,6 +235,10 @@ public:
return this;
}
using QTreeWidget::setColumnHidden;
void setColumnHidden(const QString& column, bool hide) {
setColumnHidden(fdmap.at(column), hide);
}
using QTreeWidget::showColumn;
void showColumn(const QString& column) {
showColumn(fdmap.at(column));

View File

@ -1,13 +1,26 @@
#include "main.h"
#include "mainwindow.h"
#include "deviceitem.h"
#include "gutil/qnetwork.h"
#include <QApplication>
#include <QFile>
#include <QDir>
#include <QMessageBox>
#include <QSplashScreen>
#include <QFileInfo>
#include <QStandardPaths>
#if(QT_VERSION_MAJOR > 5)
#include <QImageReader>
#endif
const QString UpdVerUrl = "https://www.ledok.cn/download/LedOK Express Updates.json";
QString programsDir() {
static auto rtn = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/programs";
return rtn;
}
#ifdef _MSC_VER //MSVC编译器
#include <Windows.h>
#include <DbgHelp.h>
@ -76,3 +89,152 @@ int main(int argc, char *argv[]) {
return a.exec();
}
QString gFileHome;
QList<LedCard> gSelCards;
DeviceItem *findItem(QString id) {
int cnt = gDevicePanel->mDeviceTable->topLevelItemCount();
for(int i=0; i<cnt; ++i) {
auto item = (DeviceItem*) gDevicePanel->mDeviceTable->topLevelItem(i);
if(item==0) continue;
if(item->mCard.id==id) return item;
}
return 0;
}
QString checkReply(QNetworkReply *reply, QJsonDocument *outJson) {
auto err = errStr(reply);
if(! err.isEmpty()) {
auto data = reply->readAll();
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
if(outJson) {
auto data = reply->readAll();
QJsonParseError jsonErr;
*outJson = QJsonDocument::fromJson(data, &jsonErr);
if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
}
return "";
}
QString errStrWithJson(QNetworkReply *reply, JValue *outJson, QByteArray *outData) {
auto err = errStr(reply);
auto data = reply->readAll();
if(outData) *outData = data;
if(! err.isEmpty()) {
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
QString error;
auto json = JFrom(data, &error);
if(! error.isEmpty()) return "JSON Error: "+error+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+data;
if(outJson) *outJson = json;
return "";
}
QString checkReplyForJson(QNetworkReply *reply, QJsonDocument *outJson, QByteArray *outData) {
auto err = errStr(reply);
auto data = reply->readAll();
if(outData) *outData = data;
if(! err.isEmpty()) {
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
QJsonParseError jsonErr;
QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr);
if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
if(! json["success"].toBool()) return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+data;
if(outJson) outJson->swap(json);
return "";
}
QString checkReplyForJson(QNetworkReply *reply, QString errField) {
auto err = errStr(reply);
auto data = reply->readAll();
if(! err.isEmpty()) {
if(! data.isEmpty()) err = err+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
return err;
}
QJsonParseError jsonErr;
QJsonDocument json = QJsonDocument::fromJson(data, &jsonErr);
if(jsonErr.error != QJsonParseError::NoError) return "Json error: "+jsonErr.errorString()+"\n"+QCoreApplication::translate("Def","Device replied")+": "+data;
if(! json["success"].toBool()) {
auto errStr = json[errField].toString();
return QCoreApplication::translate("Def","Fail")+". "+QCoreApplication::translate("Def","Device replied")+": "+(errStr.isEmpty() ? data : errStr);
}
return "";
}
quint64 dirFileSize(const QString &path) {
QDir dir(path);
quint64 size = 0;
auto infos = dir.entryInfoList(QDir::Files);
foreach(QFileInfo fileInfo, infos) size += fileInfo.size();
auto subDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QString subDir, subDirs) size += dirFileSize(path + QDir::separator() + subDir);
return size;
}
bool copyDir(const QString &source, const QString &destination, bool override) {
QDir directory(source);
if(!directory.exists()) return false;
QString srcPath = QDir::toNativeSeparators(source);
if(!srcPath.endsWith(QDir::separator())) srcPath += QDir::separator();
QString dstPath = QDir::toNativeSeparators(destination);
if (!dstPath.endsWith(QDir::separator())) dstPath += QDir::separator();
bool error = false;
QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
for (QStringList::size_type i=0; i != fileNames.size(); ++i)
{
QString fileName = fileNames.at(i);
QString srcFilePath = srcPath + fileName;
QString dstFilePath = dstPath + fileName;
QFileInfo fileInfo(srcFilePath);
if (fileInfo.isFile() || fileInfo.isSymLink())
{
if (override)
{
QFile::setPermissions(dstFilePath, QFile::WriteOwner);
}
QFile::copy(srcFilePath, dstFilePath);
}
else if (fileInfo.isDir())
{
QDir dstDir(dstFilePath);
dstDir.mkpath(dstFilePath);
if (!copyDir(srcFilePath, dstFilePath, override))
{
error = true;
}
}
}
return !error;
}
unsigned char GetCheckCodeIn8(unsigned char *str, unsigned int size) {
unsigned char checkCode = 0;
for(int i=0; i<size; i++) checkCode += str[i];
return (~checkCode) & 0xff;
}
void MergeFmt(QTextEdit *textEdit, const QTextCharFormat &fmt) {
QTextCursor cursor = textEdit->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(fmt);
}
Tick::Tick(QWidget *parent) : QOpenGLWidget(parent) {
setGeometry(0, 0, 1, 1);
connect(this, &QOpenGLWidget::frameSwapped, this, &Tick::doFrame);
}
void Tick::doFrame() {
auto cur = QDateTime::currentDateTime();
auto secs = cur.toSecsSinceEpoch();
if(secs != Sec) {
Sec = secs;
emit secChanged(cur);
}
update();
}

View File

@ -1,9 +1,14 @@
#ifndef GLOBALDEFINE_H
#define GLOBALDEFINE_H
#ifndef MAIN_H
#define MAIN_H
#include "gutil/qjson.h"
#include <QJsonDocument>
#include <QNetworkReply>
#include <QOpenGLWidget>
#include <QTextEdit>
#define PAGEDEL_SUFFIX "@D$E$L&20111005&"
#define RECTF_INVALID QRectF(-9999, -9999, 0, 0)
struct LedCard {
QString id;
@ -12,19 +17,29 @@ struct LedCard {
int mHeight = 0;
int bright = 100;
int BrightnessLevel = 255;
QString FirmwareVersion;
QString firmwareVer;
QString HardVersion = "0000";
QString ScreenResolution;
QString androidVersion;
QString playerVer;
QString alias;
QString IMEI;
bool hasPassword{false};
bool isLocked{true};
bool isScreenOn{true};
bool isOnline{true};
bool hasPassword = false;
bool isLocked = true;
bool isScreenOn = true;
bool isOnline = true;
};
class Tick : public QOpenGLWidget {
Q_OBJECT
public:
Tick(QWidget *parent = 0);
void doFrame();
qint64 Sec;
signals:
void secChanged(const QDateTime &);
};
enum {
MainPage_DeviceManager = 0,
MainPage_ProgManager,
@ -42,6 +57,10 @@ struct ST_ANSY_PROGRAM_PACKET {
unsigned char pDataBuffer[20];
};
extern const QString UpdVerUrl;
QString programsDir();
extern Tick *gTick;
extern QString gFileHome;
extern QString gApkHome;
class DevicePanel;
@ -53,6 +72,7 @@ extern bool gTextAntialiasing;
extern bool gWidthSplit;
extern int gSendBatch;
extern bool gHideDetect;
extern bool gShowIP;
extern bool gShowAlias;
extern bool gShowLora;
@ -93,6 +113,8 @@ QString errStrWithJson(QNetworkReply *, JValue * = 0, QByteArray * = 0);
QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0, QByteArray * = 0);
QString checkReplyForJson(QNetworkReply *, QString errField);
void MergeFmt(QTextEdit *textEdit, const QTextCharFormat &fmt);
#define Def_CtrlReqPre \
waitingDlg->show();\
auto card = gSelCards[0];\
@ -132,4 +154,4 @@ public :
}
};
#endif // GLOBALDEFINE_H
#endif // MAIN_H

View File

@ -1,7 +1,6 @@
#include "mainwindow.h"
#include "gutil/qgui.h"
#include "cfg.h"
#include "globaldefine.h"
#include "main.h"
#include "devicepanel.h"
#include "gutil/qnetwork.h"
#include "device/upgradeapkdialog.h"
@ -18,9 +17,22 @@
#include <QToolButton>
#include <QDir>
#include <QCoreApplication>
#include <QOpenGLWidget>
extern QPoint gPlayPos;
QString gApkHome;
bool gVideoCompress = false;
bool gVideoTranscoding = false;
bool gTextAntialiasing = false;
bool gWidthSplit = false;
int gSendBatch = 5;
bool gHideDetect = false;
bool gShowIP = true;
bool gShowAlias = false;
bool gShowLora = false;
Tick *gTick;
class ImgBtn : public QToolButton {
public:
ImgBtn() {
@ -213,9 +225,6 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
pLayout->addWidget(m_wTitle->bn_Close);
auto menu_setting = new QMenu;
act_lang = new QAction;
act_lang->setMenu(menuLang);
menu_setting->addAction(act_lang);
actFirmware = new QAction(tr("firmware manager"));
connect(actFirmware, &QAction::triggered, this, [this] {
@ -267,6 +276,10 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
fdHideDetect->setChecked(gHideDetect);
vBox->addWidget(fdHideDetect);
auto fdShowIP = new QCheckBox(tr("Show IP in Terminal Control"));
fdShowIP->setChecked(gShowIP);
vBox->addWidget(fdShowIP);
auto fdShowAlias = new QCheckBox(tr("Show Alias in Terminal Control"));
fdShowAlias->setChecked(gShowAlias);
vBox->addWidget(fdShowAlias);
@ -286,6 +299,7 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
settings.setValue("WidthSplit", gWidthSplit = fdWidthSplit->isChecked());
settings.setValue("SendBatch", gSendBatch = fdSendBatch->value());
settings.setValue("HideDetect", gHideDetect = fdHideDetect->isChecked());
settings.setValue("ShowIP", gShowIP = fdShowIP->isChecked());
settings.setValue("ShowAlias", gShowAlias = fdShowAlias->isChecked());
settings.setValue("GuangYingPin", gShowLora = fdShowLora->isChecked());
dlg.accept();
@ -295,19 +309,18 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
dlg.exec();
fdDetectCard->setVisible(! gHideDetect);
if(mDevicePanel->mDeviceTable->isColumnHidden(mDevicePanel->mDeviceTable->columnCount()-1)) {
if(gShowAlias) {
mDevicePanel->mDeviceTable->showColumn("alias");
mDevicePanel->mDeviceTable->hideColumn("ip");
} else {
mDevicePanel->mDeviceTable->hideColumn("alias");
mDevicePanel->mDeviceTable->showColumn("ip");
}
mDevicePanel->mDeviceTable->setColumnHidden("ip", ! gShowIP);
mDevicePanel->mDeviceTable->setColumnHidden("alias", ! gShowAlias);
mDevicePanel->mDeviceTable->adjSections(-1, 0);
}
mBtnGrp->button(MainPage_LoraScreen)->setVisible(gShowLora);
});
menu_setting->addAction(actPreferences);
act_lang = new QAction;
act_lang->setMenu(menuLang);
menu_setting->addAction(act_lang);
#if !defined leyide && !defined citta
act_upd = new QAction(tr("Check for updates"));
connect(act_upd, &QAction::triggered, this, [this] {
@ -428,7 +441,7 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
});
#endif
act_help = new QAction();
act_help = new QAction;
connect(act_help, &QAction::triggered, this, [this] {
auto act = langGrp->checkedAction();
if(act==0) return;
@ -436,14 +449,11 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
});
menu_setting->addAction(act_help);
actInfo = new QAction;
connect(actInfo, &QAction::triggered, this, [this] {
QMessageBox::information(this, tr("Info"), QFileInfo("aaa.file").absoluteFilePath()
.append("\nSupportsSsl: ").append(QSslSocket::supportsSsl()?"true":"false")
.append("\nSslLibraryBuildVersion: ").append(QSslSocket::sslLibraryBuildVersionString().append(" (").append(QString::number(QSslSocket::sslLibraryBuildVersionNumber())).append(")"))
.append("\nSslLibraryVersion: ").append(QSslSocket::sslLibraryVersionString()).append(" (").append(QString::number(QSslSocket::sslLibraryVersionNumber())).append(")"));
});
menu_setting->addAction(actInfo);
// QMessageBox::information(this, tr("Info"), QFileInfo("aaa.file").absoluteFilePath()
// .append("\nSupportsSsl: ").append(QSslSocket::supportsSsl()?"true":"false")
// .append("\nSslLibraryBuildVersion: ").append(QSslSocket::sslLibraryBuildVersionString().append(" (").append(QString::number(QSslSocket::sslLibraryBuildVersionNumber())).append(")"))
// .append("\nSslLibraryVersion: ").append(QSslSocket::sslLibraryVersionString()).append(" (").append(QString::number(QSslSocket::sslLibraryVersionNumber())).append(")"));
#if !defined leyide && !defined citta
act_about = new QAction(tr("About"));
@ -544,11 +554,11 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
mDevicePanel->mDeviceTable->showColumn("check");
mDevicePanel->mDeviceTable->fdCheckAll->show();
mDevicePanel->fdCardNumInfo->show();
auto specialIdx = (gShowAlias ? "alias" : "ip")**mDevicePanel->mDeviceTable;
for(int j="id"**mDevicePanel->mDeviceTable+1; j<mDevicePanel->mDeviceTable->columnCount(); j++) if(j!=specialIdx) mDevicePanel->mDeviceTable->hideColumn(j);
auto idxIP = ! gShowIP ? -1 : "ip"**mDevicePanel->mDeviceTable;
auto idxAlias = ! gShowAlias ? -1 : "alias"**mDevicePanel->mDeviceTable;
for(int j="id"**mDevicePanel->mDeviceTable+1; j<mDevicePanel->mDeviceTable->columnCount(); j++) if(j!=idxIP && j!=idxAlias) mDevicePanel->mDeviceTable->hideColumn(j);
if(mDevicePanel->mDeviceCtrlPanel) mDevicePanel->mDeviceCtrlPanel->show();
else mDevicePanel->newCtrl();
mDevicePanel->mDeviceTable->setMaximumWidth(300);
}
});
@ -614,6 +624,7 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
gSendBatch = settings.value("SendBatch", 5).toInt();
gHideDetect = settings.value("HideDetect").toBool();
gShowAlias = settings.value("ShowAlias").toBool();
gShowIP = settings.value("ShowIP", ! gShowAlias).toBool();
gShowLora = settings.value("GuangYingPin").toBool();
if(gHideDetect) fdDetectCard->hide();
@ -658,6 +669,8 @@ MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) {
QColorDialog::setStandardColor(ci++, QColor(lows[i], mids[i], higs[i]));
QColorDialog::setStandardColor(ci++, QColor(mids[i], lows[i], higs[i]));
}
gTick = new Tick(this);
}
MainWindow::~MainWindow() {
QSettings settings;
@ -691,7 +704,6 @@ void MainWindow::transUi() {
fdDetectCard->setText(tr("Check card"));
act_lang->setText(tr("Language"));
act_help->setText(tr("Help"));
actInfo->setText(tr("Info"));
if(act_about) act_about->setText(tr("About"));
if(act_upd) act_upd->setText(tr("Check for updates"));
actFirmware->setText(tr("firmware manager"));

View File

@ -4,7 +4,7 @@
#include "base/loqtitlebar.h"
#include "basewin.h"
#include "devicepanel.h"
#include "globaldefine.h"
#include "main.h"
#include "mguangyingpinwidget.h"
#include "progpanel.h"
#include <QTranslator>
@ -25,7 +25,7 @@ private:
LoQTitleBar *m_wTitle;
QActionGroup *langGrp;
QAction *act_lang;
QAction *act_help, *actInfo;
QAction *act_help;
QAction *act_upd = 0;
QAction *actFirmware;
QAction *actPreferences;

View File

@ -1,6 +1,6 @@
#include "mguangyingpinwidget.h"
#include "gutil/qgui.h"
#include "globaldefine.h"
#include "main.h"
#include <QDateTime>
#include <QMessageBox>
#include <QSerialPortInfo>

View File

@ -1,6 +1,5 @@
#include "eletimer.h"
#include "tools.h"
#include "globaldefine.h"
#include "main.h"
#include <QPainter>
EleTimer::EleTimer(const JValue &json, QWidget *parent) : QWidget{parent} {
@ -22,11 +21,11 @@ EleTimer::EleTimer(const JValue &json, QWidget *parent) : QWidget{parent} {
textColor = json["textColor"].toString();
auto color = json["backColor"].toString();
backColor = color.isEmpty() ? QColor(0,0,0,0) : color;
connect(Tools::getInstance(), &Tools::sTick, this, [this]() {
QDateTime cDateTime = QDateTime::currentDateTime();
qint64 ofs = isDown ? cDateTime.secsTo(targetTime) : targetTime.secsTo(cDateTime);
if(ofs < 0) ofs = 0;
secs = ofs;
connect(gTick, &Tick::secChanged, this, [this](const QDateTime &cur) {
auto sss = isDown ? cur.secsTo(targetTime) : targetTime.secsTo(cur);
if(sss < 0) sss = 0;
if(secs==sss) return;
secs = sss;
update();
});
}

View File

@ -1,6 +1,6 @@
#include "progpanel.h"
#include "program/progitem.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qgui.h"
#include "cfg.h"
#include "player/playwin.h"

View File

@ -1,7 +1,7 @@
#include "eaclock.h"
#include "QtWidgets/qgraphicsscene.h"
#include "cfg.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qgui.h"
#include "tools.h"
#include "base/locolorselector.h"

View File

@ -53,8 +53,10 @@ void EBase::setBaseAttr(const JObj &json) {
mEntryDur = json["entryDur"].toInt();
mExitDur = json["exitDur"].toInt();
_rotate = json["rotate"].toInt();
_blink = json["blink"].toDouble(1.0);
_opacity = json["opacity"].toDouble(1);
_blink = json["blink"].toDouble(1);
_hasBlink = json["hasBlink"].toBool();
_hasBreathe = json["hasBreathe"].toBool();
auto geometry = json["geometry"];
setPos(geometry["x"].toInt(), geometry["y"].toInt());
setSize(geometry["w"].toInt(), geometry["h"].toInt());
@ -87,8 +89,10 @@ void EBase::addBaseAttr(JObj &obj) const {
obj.insert("entryDur", mEntryDur);
obj.insert("exitDur", mExitDur);
obj["rotate"] = _rotate;
obj["opacity"] = _opacity;
obj["blink"] = _blink;
obj["hasBlink"] = _hasBlink;
obj["hasBreathe"] = _hasBreathe;
if(bdImgIdx>-1) {
obj["border"] = borderImgs[bdImgIdx].name;
obj["borderSize"] = JArray{borderImgs[bdImgIdx].img.width(), borderImgs[bdImgIdx].img.height()};
@ -660,15 +664,31 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
hBox->addLabel(tr("Rotate")+": ");
auto fdRotate = new QSpinBox;
fdRotate->setRange(0, 359);
fdRotate->setRange(-180, 360);
fdRotate->setValue(_rotate);
fdRotate->setToolTip("Need Player 2.1.4");
fdRotate->setToolTip("Need Player 2.1.9");
connect(fdRotate, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
_rotate = value;
//setRotation(value);
});
hBox->addWidget(fdRotate);
hBox->addSpacing(-spacing+2);
hBox->addLabel("°");
hBox->addSpacing(10);
hBox->addLabel(tr("Opacity")+": ");
auto fdOpacity = new QDoubleSpinBox;
fdOpacity->setDecimals(2);
fdOpacity->setSingleStep(0.1);
fdOpacity->setRange(0, 1);
fdOpacity->setValue(_opacity);
fdOpacity->setToolTip("Need Player 2.1.9");
connect(fdOpacity, (void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged, this, [this](double value) {
_opacity = value;
setOpacity(value);
});
hBox->addWidget(fdOpacity);
hBox->addStretch();
vBox->addSpacing(-spacing);
@ -898,15 +918,28 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
}
});
ccc = 2;
hBox = new HBox;
auto fdBlink = new QCheckBox(tr("Blink"));
fdBlink->setChecked(_hasBlink);
fdBlink->setToolTip("Need Player 2.1.4");
fdBlink->setToolTip("Need Player 2.1.9");
hBox->addWidget(fdBlink);
auto fdBreathe = new QCheckBox(tr("Breathe"));
fdBreathe->setChecked(_hasBreathe);
fdBreathe->setToolTip("Need Player 2.1.9");
hBox->addWidget(fdBreathe);
connect(fdBlink, &QCheckBox::stateChanged, this, [=](int state) {
_hasBlink = state==Qt::Checked;
if(_hasBlink) fdBreathe->setChecked(false);
});
grid->addWidget(fdBlink, 2, ccc++);
connect(fdBreathe, &QCheckBox::stateChanged, this, [=](int state) {
_hasBreathe = state==Qt::Checked;
if(_hasBreathe) fdBlink->setChecked(false);
});
ccc = 2;
grid->addLayout(hBox, 2, ccc++);
ccc++;
grid->addLabel(tr("Freq"), 2, ccc++, Qt::AlignRight|Qt::AlignVCenter);

View File

@ -15,7 +15,7 @@ public:
enum ElementType {
Text = QGraphicsItem::UserType + 1,
Image, Video, Gif, Audio,
DClock, AClock, Timer, Environ, Window, Web
DClock, AClock, Timer, Timer2, Environ, Window, Web
};
Q_ENUM(ElementType)
@ -52,8 +52,8 @@ public:
int mStartTime = 0, mDuration = 10;
QString mEntryEffect, mExitEffect;
int mEntryDur = 1, mExitDur = 1;
double _blink = 1.0;
bool _hasBlink = 0;
double _opacity = 1, _blink = 1;
bool _hasBlink = false, _hasBreathe = false;
signals:
void sizeChanged();

View File

@ -1,6 +1,6 @@
#include "edclock.h"
#include "base/locolorselector.h"
#include "globaldefine.h"
#include "main.h"
#include "tools.h"
#include "gutil/qgui.h"
#include <QCheckBox>
@ -57,8 +57,8 @@ EDClock::EDClock(const JObj &json, EBase *multiWin) : EBase(multiWin) {
}
void EDClock::init() {
connect(Tools::getInstance(), &Tools::sTick, this, [this]() {
datetime = QDateTime::currentDateTime().toTimeZone(QTimeZone(m_attr.timeZoneId));
connect(gTick, &Tick::secChanged, this, [this](const QDateTime &cur) {
datetime = cur.toTimeZone(QTimeZone(m_attr.timeZoneId));
update();
});
}

View File

@ -1,6 +1,6 @@
#include "eenviron.h"
#include "base/locolorselector.h"
#include "globaldefine.h"
#include "main.h"
#include "tools.h"
#include <QButtonGroup>
#include <QCheckBox>
@ -40,7 +40,7 @@ JObj EEnviron::genProg(const JValue &json, const QString &dstDir, const QString
auto title = json["title"].toString();
if(! title.isEmpty()) Tools::saveImg(dstDir, metric, font, color, res, title, "title");
JObj values;
for(auto &str : str0_9) Tools::saveImg(dstDir, metric, font, color, values, str, str);
for(int i=0; i<=9; i++) Tools::saveImg(dstDir, metric, font, color, values, QString::number(i), QString::number(i));
Tools::saveImg(dstDir, metric, font, color, values, ".", ".");
Tools::saveImg(dstDir, metric, font, color, values, "-", "-");
Tools::saveImg(dstDir, metric, font, color, values, tr("N"), "N");

View File

@ -1,7 +1,7 @@
#include "egif.h"
#include "cfg.h"
#include "tools.h"
#include "globaldefine.h"
#include "main.h"
#include <QBoxLayout>
#include <QDir>
#include <QLabel>

View File

@ -1,5 +1,5 @@
#include "emultiwin.h"
#include "globaldefine.h"
#include "main.h"
#include "base/extendedgroupbox.h"
#include "ebase.h"
#include "etext.h"

View File

@ -1,7 +1,7 @@
#include "ephoto.h"
#include "cfg.h"
#include "tools.h"
#include "globaldefine.h"
#include "main.h"
#include <QComboBox>
#include <QFileDialog>
#include <QImageReader>

View File

@ -1,14 +1,13 @@
#include "base/locolorselector.h"
#include "etext.h"
#include "globaldefine.h"
#include "tools.h"
#include <QBoxLayout>
#include "etext.h"
#include "base/locolorselector.h"
#include "main.h"
#include "gutil/qgui.h"
#include <QButtonGroup>
#include <QFontComboBox>
#include <QJsonArray>
#include <QMessageBox>
#include <QRadioButton>
#include <QSpinBox>
#include <QFileDialog>
#include <QStackedLayout>
#include <QTextBlock>
#if(QT_VERSION_MAJOR > 5)
@ -19,7 +18,6 @@
#include <QTimeEdit>
#include <QToolButton>
#include <QPainter>
#include <QLabel>
static QColor charColors[]{"#fff","#f00","#f00","#f0f","#c0c","#ff0","#f80","#0f0","#0f0","#0a0","#0a0","#7b0","#00f","#00f","#0af","#0ef"};
QString playModes[]{"Flip", "Scroll", "Static"};
@ -80,17 +78,15 @@ QWidget* EText::attrWgt() {
addBaseAttrWgt(vBox);
auto hBox = new QHBoxLayout;
hBox->addWidget(new QLabel(tr("Basic Properties")));
auto hBox = new HBox(vBox);
hBox->addLabel(tr("Basic Properties"));
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
hBox->addWidget(line, 1);
vBox->addLayout(hBox);
hBox = new QHBoxLayout;
hBox = new HBox(vBox);
auto fdText = new TTextEdit("");
@ -121,9 +117,7 @@ QWidget* EText::attrWgt() {
});
hBox->addWidget(fdFontSize);
vBox->addLayout(hBox);
hBox = new QHBoxLayout;
hBox = new HBox(vBox);
hBox->setSpacing(3);
auto wTextAlignHL = new QPushButton(QIcon(":/res/program/TextAlignHL.png"), "");
@ -157,7 +151,7 @@ QWidget* EText::attrWgt() {
connect(fdFontBold, &QToolButton::toggled, fdText, [fdText](bool checked) {
QTextCharFormat fmt;
fmt.setFontWeight(checked ? QFont::Bold : QFont::Normal);
Tools::mergeFormat(fdText, fmt);
MergeFmt(fdText, fmt);
});
hBox->addWidget(fdFontBold);
@ -168,7 +162,7 @@ QWidget* EText::attrWgt() {
connect(fdFontItalic, &QToolButton::toggled, fdText, [fdText](bool checked) {
QTextCharFormat fmt;
fmt.setFontItalic(checked);
Tools::mergeFormat(fdText, fmt);
MergeFmt(fdText, fmt);
});
hBox->addWidget(fdFontItalic);
@ -179,7 +173,7 @@ QWidget* EText::attrWgt() {
connect(fdFontUnderline, &QToolButton::toggled, fdText, [fdText](bool checked) {
QTextCharFormat fmt;
fmt.setFontUnderline(checked);
Tools::mergeFormat(fdText, fmt);
MergeFmt(fdText, fmt);
});
hBox->addWidget(fdFontUnderline);
@ -192,7 +186,7 @@ QWidget* EText::attrWgt() {
if(! color.isValid()) return;
QTextCharFormat fmt;
fmt.setForeground(color);
Tools::mergeFormat(fdText, fmt);
MergeFmt(fdText, fmt);
});
hBox->addWidget(fdTextColor);
@ -226,9 +220,7 @@ QWidget* EText::attrWgt() {
});
hBox->addWidget(fdRandomColor);
vBox->addLayout(hBox);
hBox = new QHBoxLayout;
hBox = new HBox(vBox);
hBox->setSpacing(3);
auto wTextAlignVT = new QPushButton(QIcon(":/res/program/TextAlignVT.png"), "");
@ -258,35 +250,38 @@ QWidget* EText::attrWgt() {
lb->setToolTip(lb->text());
hBox->addWidget(lb);
auto fdLetterSpacing = new QSpinBox();
fdLetterSpacing->setMaximum(999);
connect(fdLetterSpacing, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdText](int value) {
auto edLetterSpacing = new QSpinBox;
edLetterSpacing->setMaximum(9999);
edLetterSpacing->setValue(100);
connect(edLetterSpacing, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdText](int value) {
QTextCharFormat fmt;
fmt.setFontLetterSpacing(value);
QTextCursor cursor = fdText->textCursor();
auto cursor = fdText->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(fmt);
updImg();
});
hBox->addWidget(fdLetterSpacing);
hBox->addWidget(edLetterSpacing);
lb = new QLabel(tr("Line Spacing"));
lb = new QLabel(tr("Line Height"));
lb->setToolTip(lb->text());
hBox->addWidget(lb);
auto fdLineSpacing = new QSpinBox;
fdLineSpacing->setRange(-99, 999);
connect(fdLineSpacing, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdText](int value) {
auto edLineHeight = new QSpinBox;
edLineHeight->setRange(-999, 9999);
edLineHeight->setValue(100);
connect(edLineHeight, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdText](int value) {
QTextBlockFormat fmt;
fmt.setLineHeight(value, QTextBlockFormat::LineDistanceHeight);
fmt.setLineHeight(value, QTextBlockFormat::ProportionalHeight);
auto cursor = fdText->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeBlockFormat(fmt);
updImg();
});
hBox->addWidget(fdLineSpacing);
hBox->addWidget(edLineHeight);
hBox->addSpacing(-2);
hBox->addLabel("%");
vBox->addLayout(hBox);
auto fdAlignH = new QButtonGroup(wgtAttr);
fdAlignH->addButton(wTextAlignHL, Qt::AlignLeft);
@ -342,22 +337,23 @@ QWidget* EText::attrWgt() {
fdTextColor->setColor(foreground.style()==Qt::NoBrush ? Qt::white : foreground.color());
fdTextColor->blockSignals(false);
fdLetterSpacing->blockSignals(true);
fdLetterSpacing->setValue(format.fontLetterSpacing());
fdLetterSpacing->blockSignals(false);
auto spa = format.fontLetterSpacing();
edLetterSpacing->blockSignals(true);
edLetterSpacing->setValue(spa==0 ? 100 : spa);
edLetterSpacing->blockSignals(false);
auto cursor = fdText->textCursor();
auto blockFormat = cursor.blockFormat();
auto btn = fdAlignH->button(blockFormat.alignment() & Qt::AlignHorizontal_Mask);
if(btn) btn->setChecked(true);
fdLineSpacing->blockSignals(true);
fdLineSpacing->setValue(blockFormat.lineHeightType()==QTextBlockFormat::LineDistanceHeight ? blockFormat.lineHeight() : 0);
fdLineSpacing->blockSignals(false);
edLineHeight->blockSignals(true);
edLineHeight->setValue(blockFormat.lineHeightType()==QTextBlockFormat::ProportionalHeight ? blockFormat.lineHeight() : 100);
edLineHeight->blockSignals(false);
});
vBox->addWidget(fdText);
hBox = new QHBoxLayout;
hBox = new HBox(vBox);
hBox->addStretch();
auto pageInfoWgt = new QWidget;
@ -409,9 +405,7 @@ QWidget* EText::attrWgt() {
});
hBox->addWidget(btnImport);
vBox->addLayout(hBox);
hBox = new QHBoxLayout;
hBox = new HBox(vBox);
hBox->addWidget(new QLabel(tr("Play Properties")));
line = new QFrame();
@ -419,9 +413,8 @@ QWidget* EText::attrWgt() {
line->setFrameShadow(QFrame::Sunken);
hBox->addWidget(line, 1);
vBox->addLayout(hBox);
hBox = new QHBoxLayout;
hBox = new HBox(vBox);
hBox->addStretch();
auto fdFlip = new QRadioButton(tr("Flip"));
@ -436,7 +429,6 @@ QWidget* EText::attrWgt() {
hBox->addWidget(fdStatic);
hBox->addStretch();
vBox->addLayout(hBox);
auto fdPlayStyle = new QButtonGroup(wgtAttr);
fdPlayStyle->addButton(fdFlip, 0);

View File

@ -6,8 +6,8 @@
class EText : public EBase {
Q_OBJECT
public:
explicit EText(EBase *multiWin = nullptr);
explicit EText(const JObj &json, EBase *multiWin = nullptr);
explicit EText(EBase *multiWin = 0);
explicit EText(const JObj &json, EBase *multiWin = 0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
int type() const override { return EBase::Text; }
@ -17,11 +17,11 @@ public:
QString text;
Qt::Alignment align;
QColor backColor{Qt::transparent};
QColor backColor = Qt::transparent;
QString playMode = "Flip";
QString direction = "left";
int speed = 60;
int headTailSpacing{10};
int headTailSpacing = 10;
public slots:
void updImg();

View File

@ -1,10 +1,9 @@
#include "etimer.h"
#include "tools.h"
#include "globaldefine.h"
#include "main.h"
#include "base/lodateselector.h"
#include "base/locolorselector.h"
#include "gutil/qgui.h"
#include <QLabel>
#include <QRadioButton>
#include <QCheckBox>
#include <QButtonGroup>
@ -18,74 +17,74 @@
ETimer::ETimer(EBase *multiWin) : EBase(multiWin) {
mType = EBase::Timer;
attr.isDown = true;
attr.targetTime = QDateTime::currentDateTime();
attr.hasDay = true;
attr.hasHour = true;
attr.hasMin = true;
attr.hasSec = true;
attr.isMultiline = true;
attr.font = qfont("Arial", 12);
attr.textColor = Qt::red;
attr.backColor = Qt::transparent;
isDown = true;
targetTime = QDateTime::currentDateTime();
hasDay = true;
hasHour = true;
hasMin = true;
hasSec = true;
isMultiline = true;
font = qfont("Arial", 12);
textColor = Qt::red;
backColor = Qt::transparent;
init();
}
ETimer::ETimer(const JObj &json, EBase *multiWin) : EBase(multiWin){
mType = EBase::Timer;
setBaseAttr(json);
attr.isDown = json["isDown"].toBool();
attr.targetTime = QDateTime::fromString(json["targetTime"].toString(), "yyyy-MM-dd HH:mm:ss");
attr.hasDay = json["hasDay"].toBool();
attr.hasHour = json["hasHour"].toBool();
attr.hasMin = json["hasMin"].toBool();
attr.hasSec = json["hasSec"].toBool();
attr.text = json["text"].toString();
attr.isMultiline = json["isMultiline"].toBool();
attr.font = qfont(json["font"].toString(), json["fontSize"].toInt(), json["fontBold"].toBool(), json["fontItalic"].toBool());
attr.font.setUnderline(json["fontUnderline"].toBool());
attr.textColor = json["textColor"].toString();
isDown = json["isDown"].toBool();
targetTime = QDateTime::fromString(json["targetTime"].toString(), "yyyy-MM-dd HH:mm:ss");
hasDay = json["hasDay"].toBool();
hasHour = json["hasHour"].toBool();
hasMin = json["hasMin"].toBool();
hasSec = json["hasSec"].toBool();
text = json["text"].toString();
isMultiline = json["isMultiline"].toBool();
font = qfont(json["font"].toString(), json["fontSize"].toInt(), json["fontBold"].toBool(), json["fontItalic"].toBool());
font.setUnderline(json["fontUnderline"].toBool());
textColor = json["textColor"].toString();
auto color = json["backColor"].toString();
attr.backColor = color.isEmpty() ? QColor(0,0,0,0) : color;
backColor = color.isEmpty() ? QColor(0,0,0,0) : color;
init();
}
void ETimer::init() {
connect(Tools::getInstance(), &Tools::sTick, this, [this]() {
QDateTime cDateTime = QDateTime::currentDateTime();
qint64 ofs = attr.isDown ? cDateTime.secsTo(attr.targetTime) : attr.targetTime.secsTo(cDateTime);
if(ofs < 0) ofs = 0;
secs = ofs;
connect(gTick, &Tick::secChanged, this, [this](const QDateTime &cur) {
auto sss = isDown ? cur.secsTo(targetTime) : targetTime.secsTo(cur);
if(sss < 0) sss = 0;
if(secs==sss) return;
secs = sss;
update();
});
}
void ETimer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
QString text;
if(!attr.text.isEmpty()) {
text += attr.text;
if(attr.isMultiline) text += '\n';
if(!this->text.isEmpty()) {
text += this->text;
if(this->isMultiline) text += '\n';
else text += " ";
}
int secs = this->secs;
if(attr.hasDay) {
if(this->hasDay) {
text.append(QString::number(secs/86400)).append(" ").append(tr("day")).append(" ");
secs %= 86400;
}
if(attr.hasHour) {
if(this->hasHour) {
text.append(QString::asprintf("%02d ", secs/3600)).append(tr("hour")).append(" ");
secs %= 3600;
}
if(attr.hasMin) {
if(this->hasMin) {
text.append(QString::asprintf("%02d ", secs/60)).append(tr("min")).append(" ");
secs %= 60;
}
if(attr.hasSec) text.append(QString::asprintf("%02d ", secs)).append(tr("sec")).append(" ");
if(this->hasSec) text.append(QString::asprintf("%02d ", secs)).append(tr("sec")).append(" ");
text = text.trimmed();
attr.font.setStyleStrategy(gTextAntialiasing ? QFont::PreferAntialias : QFont::NoAntialias);
if(attr.backColor.alpha() != 0) painter->fillRect(0, 0, mWidth, mHeight, attr.backColor);
painter->setFont(attr.font);
painter->setPen(attr.textColor);
this->font.setStyleStrategy(gTextAntialiasing ? QFont::PreferAntialias : QFont::NoAntialias);
if(this->backColor.alpha() != 0) painter->fillRect(0, 0, mWidth, mHeight, this->backColor);
painter->setFont(this->font);
painter->setPen(this->textColor);
painter->drawText(innerRect(), text, QTextOption(Qt::AlignCenter));
EBase::paint(painter, option, widget);
}
@ -112,13 +111,13 @@ QWidget* ETimer::attrWgt() {
hBox->addStretch();
auto fdCntDown = new QRadioButton(tr("Count Down"));
auto fdCntUp = new QRadioButton(tr("Count Up"));
if(attr.isDown) fdCntDown->setChecked(true);
if(this->isDown) fdCntDown->setChecked(true);
else fdCntUp->setChecked(true);
auto cntGroup = new QButtonGroup(wgtAttr);
cntGroup->addButton(fdCntDown);
cntGroup->addButton(fdCntUp);
connect(fdCntDown, &QRadioButton::toggled, this, [this](bool checked) {
attr.isDown = checked;
this->isDown = checked;
update();
});
hBox->addWidget(fdCntDown);
@ -132,10 +131,10 @@ QWidget* ETimer::attrWgt() {
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Time")));
auto fdTime = new QDateTimeEdit(attr.targetTime);
auto fdTime = new QDateTimeEdit(this->targetTime);
fdTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
connect(fdTime, &QTimeEdit::dateTimeChanged, this, [this](const QDateTime &dateTime) {
attr.targetTime = dateTime;
this->targetTime = dateTime;
update();
});
hBox->addWidget(fdTime);
@ -151,42 +150,42 @@ QWidget* ETimer::attrWgt() {
hBox->addSpacing(6);
auto fdHasDay = new QCheckBox(tr("Day"));
fdHasDay->setChecked(attr.hasDay);
fdHasDay->setChecked(this->hasDay);
connect(fdHasDay, &QCheckBox::toggled, this, [this](bool checked) {
attr.hasDay = checked;
this->hasDay = checked;
update();
});
hBox->addWidget(fdHasDay);
auto fdHasHour = new QCheckBox(tr("Hour"));
fdHasHour->setChecked(attr.hasHour);
fdHasHour->setChecked(this->hasHour);
connect(fdHasHour, &QCheckBox::toggled, this, [this](bool checked) {
attr.hasHour = checked;
this->hasHour = checked;
update();
});
hBox->addWidget(fdHasHour);
auto fdHasMin = new QCheckBox(tr("Min"));
fdHasMin->setChecked(attr.hasMin);
fdHasMin->setChecked(this->hasMin);
connect(fdHasMin, &QCheckBox::toggled, this, [this](bool checked) {
attr.hasMin = checked;
this->hasMin = checked;
update();
});
hBox->addWidget(fdHasMin);
auto fdHasSec = new QCheckBox(tr("Sec"));
fdHasSec->setChecked(attr.hasSec);
fdHasSec->setChecked(this->hasSec);
connect(fdHasSec, &QCheckBox::toggled, this, [this](bool checked) {
attr.hasSec = checked;
this->hasSec = checked;
update();
});
hBox->addWidget(fdHasSec);
hBox->addStretch();
auto fdIsMultiline = new QCheckBox(tr("Multiline"));
fdIsMultiline->setChecked(attr.isMultiline);
fdIsMultiline->setChecked(this->isMultiline);
connect(fdIsMultiline, &QCheckBox::toggled, this, [this](bool checked) {
attr.isMultiline = checked;
this->isMultiline = checked;
update();
});
hBox->addWidget(fdIsMultiline);
@ -197,10 +196,10 @@ QWidget* ETimer::attrWgt() {
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Text")));
auto fdText = new QTextEdit(attr.text);
auto fdText = new QTextEdit(this->text);
fdText->setMaximumHeight(50);
connect(fdText, &QTextEdit::textChanged, this, [this, fdText]() {
attr.text = fdText->toPlainText();
this->text = fdText->toPlainText();
update();
});
hBox->addWidget(fdText);
@ -211,24 +210,24 @@ QWidget* ETimer::attrWgt() {
hBox->addSpacing(6);
auto fdFont = new QFontComboBox();
fdFont->setCurrentText(attr.font.family());
fdFont->setCurrentText(this->font.family());
fdFont->setEditable(false);
connect(fdFont, &QFontComboBox::currentFontChanged, this, [this](const QFont &f) {
QFont font(f.family());
font.setPixelSize(attr.font.pixelSize());
font.setBold(attr.font.bold());
font.setItalic(attr.font.italic());
font.setUnderline(attr.font.underline());
attr.font = font;
font.setPixelSize(this->font.pixelSize());
font.setBold(this->font.bold());
font.setItalic(this->font.italic());
font.setUnderline(this->font.underline());
this->font = font;
update();
});
hBox->addWidget(fdFont);
auto fdFontSize = new QSpinBox();
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(attr.font.pixelSize());
fdFontSize->setValue(this->font.pixelSize());
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
attr.font.setPixelSize(value);
this->font.setPixelSize(value);
update();
});
hBox->addWidget(fdFontSize);
@ -243,9 +242,9 @@ QWidget* ETimer::attrWgt() {
fdFontBold->setStyleSheet("QPushButton{background: #bbb; color: #888; font-size: 20px; font-weight: bold;} QPushButton:checked{background: #29c; color: #fff;}");
fdFontBold->setFixedSize(30, 30);
fdFontBold->setCheckable(true);
fdFontBold->setChecked(attr.font.bold());
fdFontBold->setChecked(this->font.bold());
connect(fdFontBold, &QCheckBox::toggled, this, [this](bool checked) {
attr.font.setBold(checked);
this->font.setBold(checked);
update();
});
hBox->addWidget(fdFontBold);
@ -254,9 +253,9 @@ QWidget* ETimer::attrWgt() {
fdFontItalic->setStyleSheet("QPushButton{background: #bbb; color: #888; font-size: 20px; font-style: italic;} QPushButton:checked{background: #29c; color: #fff;}");
fdFontItalic->setFixedSize(30, 30);
fdFontItalic->setCheckable(true);
fdFontItalic->setChecked(attr.font.italic());
fdFontItalic->setChecked(this->font.italic());
connect(fdFontItalic, &QCheckBox::toggled, this, [this](bool checked) {
attr.font.setItalic(checked);
this->font.setItalic(checked);
update();
});
hBox->addWidget(fdFontItalic);
@ -265,28 +264,28 @@ QWidget* ETimer::attrWgt() {
fdFontUnderline->setStyleSheet("QPushButton{background: #bbb; color: #888; font-size: 20px; text-decoration: underline;} QPushButton:checked{background: #29c; color: #fff;}");
fdFontUnderline->setFixedSize(30, 30);
fdFontUnderline->setCheckable(true);
fdFontUnderline->setChecked(attr.font.underline());
fdFontUnderline->setChecked(this->font.underline());
connect(fdFontUnderline, &QCheckBox::toggled, this, [this](bool checked) {
attr.font.setUnderline(checked);
this->font.setUnderline(checked);
update();
});
hBox->addWidget(fdFontUnderline);
hBox->addStretch();
auto fdTextColor = new LoColorSelector("T", attr.textColor);
auto fdTextColor = new LoColorSelector("T", this->textColor);
fdTextColor->setFixedSize(30, 30);
fdTextColor->setFlat(true);
connect(fdTextColor, &LoColorSelector::sColorChanged, this, [this](const QColor &color) {
attr.textColor = color;
this->textColor = color;
update();
});
hBox->addWidget(fdTextColor);
auto fdBackColor = new LoColorSelector("B", attr.backColor);
auto fdBackColor = new LoColorSelector("B", this->backColor);
fdBackColor->setFixedSize(30, 30);
fdBackColor->setFlat(true);
connect(fdBackColor, &LoColorSelector::sColorChanged, this, [this](const QColor &color) {
attr.backColor = color;
this->backColor = color;
update();
});
hBox->addWidget(fdBackColor);
@ -300,20 +299,20 @@ JObj ETimer::attrJson() const {
JObj obj;
addBaseAttr(obj);
obj["elementType"] = "Timer";
obj["isDown"] = attr.isDown;
obj["targetTime"] = attr.targetTime.toString("yyyy-MM-dd HH:mm:ss");
obj["hasDay"] = attr.hasDay;
obj["hasHour"] = attr.hasHour;
obj["hasMin"] = attr.hasMin;
obj["hasSec"] = attr.hasSec;
obj["text"] = attr.text;
obj["isMultiline"] = attr.isMultiline;
obj["font"] = attr.font.family();
obj["fontSize"] = attr.font.pixelSize();
obj["fontBold"] = attr.font.bold();
obj["fontItalic"] = attr.font.italic();
obj["fontUnderline"] = attr.font.underline();
obj["textColor"] = attr.textColor.name();
obj["backColor"] = attr.backColor.alpha()==0 ? "" : attr.backColor.name();
obj["isDown"] = this->isDown;
obj["targetTime"] = this->targetTime.toString("yyyy-MM-dd HH:mm:ss");
obj["hasDay"] = this->hasDay;
obj["hasHour"] = this->hasHour;
obj["hasMin"] = this->hasMin;
obj["hasSec"] = this->hasSec;
obj["text"] = this->text;
obj["isMultiline"] = this->isMultiline;
obj["font"] = this->font.family();
obj["fontSize"] = this->font.pixelSize();
obj["fontBold"] = this->font.bold();
obj["fontItalic"] = this->font.italic();
obj["fontUnderline"] = this->font.underline();
obj["textColor"] = this->textColor.name();
obj["backColor"] = this->backColor.alpha()==0 ? "" : this->backColor.name();
return obj;
}

View File

@ -10,33 +10,28 @@
class ETimer : public EBase {
Q_OBJECT
public:
struct Data {
QDateTime targetTime;
QFont font;
QString text;
QColor textColor;
QColor backColor;
bool isDown;
bool isMultiline;
bool hasDay;
bool hasHour;
bool hasMin;
bool hasSec;
};
explicit ETimer(EBase *multiWin = nullptr);
explicit ETimer(const JObj &json, EBase *multiWin = nullptr);
void init();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
int type() const override { return EBase::Timer; }
QWidget* attrWgt() override;
JObj attrJson() const override;
Data attr;
int secs = 0;
private:
void init();
QDateTime targetTime;
QFont font;
QString text;
QColor textColor;
QColor backColor;
bool isDown;
bool isMultiline;
bool hasDay;
bool hasHour;
bool hasMin;
bool hasSec;
};
#endif // ETIMER_H

404
LedOK/program/etimer2.cpp Normal file
View File

@ -0,0 +1,404 @@
#include "etimer2.h"
#include "main.h"
#include "gutil/qgui.h"
#include "base/locolorselector.h"
#include "base/lodateselector.h"
#include <QButtonGroup>
#include <QFontComboBox>
#include <QMessageBox>
#include <QRadioButton>
#include <QSpinBox>
#include <QStackedLayout>
#include <QTextBlock>
#if(QT_VERSION_MAJOR > 5)
#include <QStringConverter>
#else
#include <QTextCodec>
#endif
#include <QTextEdit>
#include <QTimeEdit>
#include <QToolButton>
#include <QPainter>
ETimer2::ETimer2(EBase *multiWin) : EBase(multiWin) {
isUp = false;
targetTime = QDateTime::currentDateTime();
html = "<body>"+tr("There are")+" %d "+tr("Days")+" %h "+tr("Hours")+" %m "+tr("Mins")+" %s "+tr("Secs")+"</body>";
init();
}
ETimer2::ETimer2(const JObj &json, EBase *multiWin) : EBase(multiWin) {
setBaseAttr(json);
isUp = json["isUp"].toBool();
targetTime = QDateTime::fromString(json["targetTime"].toString(), "yyyy-MM-dd HH:mm:ss");
html = json["html"].toString();
backColor = json["backColor"].toString("#00000000");
init();
}
void ETimer2::init() {
mType = EBase::Timer2;
doc.setDocumentMargin(0);
QFont font;
font.setFamily("Arial");
font.setFamilies({"Arial","黑体"});
font.setPixelSize(16);
doc.setDefaultFont(font);
doc.setDefaultStyleSheet("body {color: #fff; line-height:1}");
connect(this, &ETimer2::sizeChanged, this, &ETimer2::updImg);
connect(gTick, &Tick::secChanged, this, [this](const QDateTime &cur) {
auto sss = isUp ? targetTime.secsTo(cur) : cur.secsTo(targetTime);
if(sss < 0) sss = 0;
if(secs==sss) return;
secs = sss;
updImg();
}, Qt::UniqueConnection);
updImg();
}
class TTextEdit : public QTextEdit {
public:
TTextEdit() {}
explicit TTextEdit(const QString &text) : QTextEdit(text){}
QSize minimumSizeHint() const override {
return sizeHint();
};
QSize sizeHint() const override {
auto size = QTextEdit::sizeHint();
auto minH = minimumHeight();
if(minH > 0) size.setHeight(minH+0xfff);
return size;
};
};
QWidget* ETimer2::attrWgt() {
auto wgtAttr = new QWidget;
auto vBox = new VBox(wgtAttr);
vBox->setContentsMargins(4, 0, 4, 0);
vBox->setSpacing(3);
addBaseAttrWgt(vBox);
auto hBox = new HBox(vBox);
hBox->addLabel(tr("Basic Properties"));
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
hBox->addWidget(line, 1);
hBox = new HBox(vBox);
hBox->addStretch();
auto fdCntDown = new QRadioButton(tr("Count Down"));
auto fdCntUp = new QRadioButton(tr("Count Up"));
(isUp ? fdCntUp : fdCntDown)->setChecked(true);
auto cntGroup = new QButtonGroup(wgtAttr);
cntGroup->addButton(fdCntDown);
cntGroup->addButton(fdCntUp);
connect(fdCntUp, &QRadioButton::toggled, this, [this](bool checked) {
isUp = checked;
update();
});
hBox->addWidget(fdCntDown);
hBox->addStretch();
hBox->addWidget(fdCntUp);
hBox->addStretch();
hBox = new HBox(vBox);
hBox->addSpacing(6);
hBox->addLabel(tr("Time"));
auto fdTime = new QDateTimeEdit(targetTime);
fdTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss");
connect(fdTime, &QTimeEdit::dateTimeChanged, this, [this](const QDateTime &dateTime) {
targetTime = dateTime;
update();
});
hBox->addWidget(fdTime);
auto wDateSelector = new LoDateSelector;
connect(wDateSelector, &LoDateSelector::sDateSelected, fdTime, &QDateTimeEdit::setDate);
hBox->addWidget(wDateSelector);
hBox->addStretch();
auto fdText = new TTextEdit("");
hBox = new HBox(vBox);
hBox->setSpacing(3);
hBox->addLabel(tr("Font Size")+":");
auto fdFontSize = new QSpinBox;
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(16);
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, fdText, [fdText](int value) {
if(value <= 0) return;
QTextCharFormat fmt;
fmt.setProperty(QTextFormat::FontPixelSize, value);
auto cursor = fdText->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(fmt);
});
hBox->addWidget(fdFontSize);
hBox->addLabel(tr("Line Height"));
auto edLineHeight = new QDoubleSpinBox;
edLineHeight->setDecimals(1);
edLineHeight->setRange(-999, 999);
edLineHeight->setValue(1);
connect(edLineHeight, (void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged, this, [this, fdText](double value) {
QTextBlockFormat fmt;
fmt.setLineHeight(value*100, QTextBlockFormat::ProportionalHeight);
auto cursor = fdText->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeBlockFormat(fmt);
updImg();
});
hBox->addWidget(edLineHeight);
hBox->addStretch();
hBox = new HBox(vBox);
hBox->setSpacing(3);
auto wTextAlignHL = new QPushButton(QIcon(":/res/program/TextAlignHL.png"), "");
wTextAlignHL->setStyleSheet("QPushButton{border: none; background: #bbb;} QPushButton:checked{background: #29c;}");
wTextAlignHL->setFixedSize(30, 30);
wTextAlignHL->setIconSize(QSize(30, 30));
wTextAlignHL->setCheckable(true);
wTextAlignHL->setChecked(true);
hBox->addWidget(wTextAlignHL);
auto wTextAlignHC = new QPushButton(QIcon(":/res/program/TextAlignHC.png"), "");
wTextAlignHC->setStyleSheet("QPushButton{border: none; background: #bbb;} QPushButton:checked{background: #29c;}");
wTextAlignHC->setFixedSize(30, 30);
wTextAlignHC->setIconSize(QSize(30, 30));
wTextAlignHC->setCheckable(true);
hBox->addWidget(wTextAlignHC);
auto wTextAlignHR = new QPushButton(QIcon(":/res/program/TextAlignHR.png"), "");
wTextAlignHR->setStyleSheet("QPushButton{border: none; background: #bbb;} QPushButton:checked{background: #29c;}");
wTextAlignHR->setFixedSize(30, 30);
wTextAlignHR->setIconSize(QSize(30, 30));
wTextAlignHR->setCheckable(true);
hBox->addWidget(wTextAlignHR);
hBox->addStretch();
auto fdFontBold = new QPushButton("B");
fdFontBold->setStyleSheet("QPushButton{background: #bbb; color: #888; font-size: 20px; font-weight: bold;} QPushButton:checked{background: #29c; color: #fff;}");
fdFontBold->setFixedSize(30, 30);
fdFontBold->setCheckable(true);
connect(fdFontBold, &QToolButton::toggled, fdText, [fdText](bool checked) {
QTextCharFormat fmt;
fmt.setFontWeight(checked ? QFont::Bold : QFont::Normal);
MergeFmt(fdText, fmt);
});
hBox->addWidget(fdFontBold);
auto fdFontItalic = new QPushButton("I");
fdFontItalic->setStyleSheet("QPushButton{background: #bbb; color: #888; font-size: 20px; font-style: italic;} QPushButton:checked{background: #29c; color: #fff;}");
fdFontItalic->setFixedSize(30, 30);
fdFontItalic->setCheckable(true);
connect(fdFontItalic, &QToolButton::toggled, fdText, [fdText](bool checked) {
QTextCharFormat fmt;
fmt.setFontItalic(checked);
MergeFmt(fdText, fmt);
});
hBox->addWidget(fdFontItalic);
auto fdFontUnderline = new QPushButton("U");
fdFontUnderline->setStyleSheet("QPushButton{background: #bbb; color: #888; font-size: 20px; text-decoration: underline;} QPushButton:checked{background: #29c; color: #fff;}");
fdFontUnderline->setFixedSize(30, 30);
fdFontUnderline->setCheckable(true);
connect(fdFontUnderline, &QToolButton::toggled, fdText, [fdText](bool checked) {
QTextCharFormat fmt;
fmt.setFontUnderline(checked);
MergeFmt(fdText, fmt);
});
hBox->addWidget(fdFontUnderline);
hBox->addStretch();
auto edTextColor = new LoColorSelector("F", Qt::white);
edTextColor->setToolTip(tr("Foreground Color"));
edTextColor->setFixedSize(30, 30);
connect(edTextColor, &LoColorSelector::sColorChanged, fdText, [fdText](const QColor &color) {
if(! color.isValid()) return;
QTextCharFormat fmt;
fmt.setForeground(color);
MergeFmt(fdText, fmt);
});
hBox->addWidget(edTextColor);
auto edBack = new LoColorSelector("LB", Qt::white);
edBack->setToolTip(tr("Line Background"));
edBack->setFixedSize(34, 30);
connect(edBack, &LoColorSelector::sColorChanged, fdText, [fdText](const QColor &color) {
if(! color.isValid()) return;
QTextCharFormat fmt;
fmt.setBackground(color);
MergeFmt(fdText, fmt);
});
hBox->addWidget(edBack);
auto edBackColor = new LoColorSelector("B", backColor);
edBackColor->setToolTip(tr("Background Color"));
edBackColor->setFixedSize(30, 30);
connect(edBackColor, &LoColorSelector::sColorChanged, this, [this](const QColor &color) {
if(! color.isValid()) return;
backColor = color;
updImg();
});
hBox->addWidget(edBackColor);
auto fdAlignH = new QButtonGroup(wgtAttr);
fdAlignH->addButton(wTextAlignHL, Qt::AlignLeft);
fdAlignH->addButton(wTextAlignHC, Qt::AlignHCenter);
fdAlignH->addButton(wTextAlignHR, Qt::AlignRight);
connect(fdAlignH, &QButtonGroup::idClicked, this, [this, fdText](int value) {
QTextBlockFormat fmt;
fmt.setAlignment((Qt::Alignment) value);
QTextCursor cursor = fdText->textCursor();
cursor.mergeBlockFormat(fmt);
updImg();
});
auto ll = vBox->addLabel("%d: "+tr("Days")+", %h: "+tr("Hours")+", %m: "+tr("Mins")+", %s: "+tr("Secs"));
gFont(ll, 16);
fdText->setMinimumHeight(160);
auto doc = fdText->document();
if(doc) doc->setDocumentMargin(2);
auto font = fdText->font();
font.setFamily("Arial");
font.setFamilies({"Arial","黑体"});
font.setPixelSize(16);
fdText->setFont(font);
auto pal = fdText->palette();
pal.setColor(QPalette::Base, Qt::black);
pal.setColor(QPalette::Text, Qt::white);
fdText->setPalette(pal);
fdText->document()->setDefaultStyleSheet("body {color: #fff; line-height:1}");
fdText->setFrameShape(QFrame::NoFrame);
fdText->setAcceptRichText(false);
fdText->setHtml(html);
connect(fdText, &QTextEdit::textChanged, this, [this, fdText] {
html = fdText->toHtml();
updImg();
});
connect(fdText, &QTextEdit::currentCharFormatChanged, this, [=](const QTextCharFormat &format) {
fdFontSize->blockSignals(true);
fdFontSize->setValue(format.font().pixelSize());
fdFontSize->blockSignals(false);
auto foreground = format.foreground();
edTextColor->blockSignals(true);
edTextColor->setColor(foreground.style()==Qt::NoBrush ? Qt::white : foreground.color());
edTextColor->blockSignals(false);
auto background = format.background();
edBack->blockSignals(true);
edBack->setColor(background.style()==Qt::NoBrush ? Qt::transparent : background.color());
edBack->blockSignals(false);
auto cursor = fdText->textCursor();
auto blockFormat = cursor.blockFormat();
auto btn = fdAlignH->button(blockFormat.alignment() & Qt::AlignHorizontal_Mask);
if(btn) btn->setChecked(true);
edLineHeight->blockSignals(true);
edLineHeight->setValue(blockFormat.lineHeightType()==QTextBlockFormat::ProportionalHeight ? blockFormat.lineHeight()*0.01 : 1.0);
edLineHeight->blockSignals(false);
});
vBox->addWidget(fdText);
return wgtAttr;
}
void repLineHeight(QString &html) {
QString pre;
int last = 0, idx;
while((idx = html.indexOf("line-height:", last)) > -1) {
idx += 12;
auto end = idx;
QChar ch;
while((ch = html[end])<='9' && ch>='-' && ch!='/') if(++end >= html.size()) goto end;
if(ch!='%') last = end;
else {
pre += html.mid(last, idx-last) + QString::number(html.mid(idx, end-idx).toDouble() / 100);
last = end + 1;
}
}
end:
if(! pre.isEmpty()) html = pre + html.mid(last);
}
JObj ETimer2::attrJson() const {
JObj ele{{"elementType", "Timer2"}};
addBaseAttr(ele);
ele["isUp"] = isUp;
auto hhhh = html;
auto idx = hhhh.indexOf("<html");
if(idx > -1) hhhh = hhhh.mid(idx);
idx = hhhh.indexOf("<body style=\"");
if(idx > -1 && ! hhhh.mid(idx+13, 8).contains("color:")) hhhh = hhhh.insert(idx+13, "color:#fff;");
hhhh.replace("<meta name=\"qrichtext\" content=\"1\" />", "");
hhhh.replace(" -qt-block-indent:0; text-indent:0px;", "");
repLineHeight(hhhh);
ele["html"] = hhhh.replace("margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;", "margin:0;");
ele["targetTime"] = targetTime.toString("yyyy-MM-dd HH:mm:ss");
ele["backColor"] = backColor.name(QColor::HexArgb);
return ele;
}
void ETimer2::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
painter->save();
auto rect = innerRect();
painter->drawImage(rect, img);
painter->restore();
EBase::paint(painter, option, widget);
}
void ETimer2::updImg() {
auto innerRect = this->innerRect();
int width = innerRect.width();
int height = innerRect.height();
if(width<1 || height<1) return;
auto hasDay = html.contains("%d");
auto hasHour = html.contains("%h");
auto hasMin = html.contains("%m");
auto hasSec = html.contains("%s");
auto htm = html;
if(hasDay) {
htm = htm.replace("%d", QString::number(secs/86400));
secs %= 86400;
}
if(hasHour) {
htm = htm.replace("%h", QString::asprintf("%02d", secs/3600));
secs %= 3600;
}
if(hasMin) {
htm = htm.replace("%m", QString::asprintf("%02d", secs/60));
secs %= 60;
}
if(hasSec) htm = htm.replace("%s", QString::asprintf("%02d", secs));
doc.setHtml(htm);
doc.setTextWidth(width);
width<<=1;
height<<=1;
if(img.width()!=width || img.height()!=height) img = QImage(width, height, QImage::Format_ARGB32);
img.fill(backColor);
{
QPainter painter(&img);
painter.scale(2,2);
doc.drawContents(&painter);
}
update();
}

34
LedOK/program/etimer2.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef ETIMER2_H
#define ETIMER2_H
#include "ebase.h"
#include <QDateTime>
#include <QTextDocument>
class ETimer2 : public EBase {
Q_OBJECT
public:
explicit ETimer2(EBase *multiWin = 0);
explicit ETimer2(const JObj &json, EBase *multiWin = 0);
void init();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
int type() const override { return EBase::Timer2; }
QWidget* attrWgt() override;
JObj attrJson() const override;
QDateTime targetTime;
QString html;
QColor backColor = Qt::transparent;
bool isUp;
QImage img;
int secs = 0;
QTextDocument doc;
public slots:
void updImg();
};
#endif // ETIMER2_H

View File

@ -1,7 +1,6 @@
#include "evideo.h"
#include "cfg.h"
#include "tools.h"
#include "globaldefine.h"
#include "main.h"
#include "base/ffutil.h"
#include <QLineEdit>
#include <QMessageBox>
@ -21,8 +20,8 @@ EVideo *EVideo::create(const QString &file, PageListItem *pageItem, EBase *multi
return 0;
}
QFileInfo rawInfo(file);
QString rawName = rawInfo.fileName();
QString outFile = transcoding(pageItem->listWidget(), file, rawName, pageItem->mPageDir, img.width(), img.height(), codecId);
auto rawName = rawInfo.fileName();
auto outFile = transcoding(pageItem->listWidget(), file, rawName, pageItem->mPageDir, img.width(), img.height(), codecId);
if(outFile.isEmpty()) return 0;
QFileInfo outInfo(outFile);
if(! outInfo.isFile() || outInfo.size()==0) return 0;
@ -36,7 +35,7 @@ EVideo *EVideo::create(const JObj &ele, PageListItem *pageItem, EBase *multiWin)
auto dir = widget["path"].toString();
auto name = widget["file"].toString();
if(! QFileInfo::exists(dir)) dir = pageItem->mPageDir;
QString file = dir + "/" + name;
auto file = dir + "/" + name;
if(QFileInfo::exists(file)) ;
else if(QFileInfo::exists(file = pageItem->mPageDir + "/" + name)) dir = pageItem->mPageDir;
else return 0;
@ -52,27 +51,6 @@ EVideo *EVideo::create(const JObj &ele, PageListItem *pageItem, EBase *multiWin)
ins->playTimes = (play.isNull() ? ele : play)["playTimes"].toInt(1);
return ins;
}
JObj EVideo::genProg(const JValue &ele, const QString &dstDir, ProgItem *progItem) {
auto widget = ele["widget"];
if(widget.isNull()) widget = ele;
auto path = widget["path"].toString();
auto name = widget["file"].toString();
//if(progItem->maxLen) name += "-square.mp4";
QString srcFile = path + "/" + name;
QFileInfo srcInfo(srcFile);
if(! srcInfo.isFile()) return JObj();
QString id = Tools::fileMd5(srcFile);
if(id.isEmpty()) return JObj();
QFile::copy(srcFile, dstDir+"/"+id);
JObj oRes;
oRes["_type"] = "Video";
oRes["id"] = id;
oRes["md5"] = id;
oRes["name"] = name;
auto play = ele["play"];
oRes["timeSpan"] = play.isNull() ? ele["duration"].toInt() * ele["playTimes"].toInt() : play["playDuration"].toInt() * play["playTimes"].toInt();
return oRes;
}
EVideo::EVideo(const QString &dir, const QString &name, const QString &rawDir, const QString &rawName, QImage &coverImg, PageListItem *pageItem, EBase *multiWin)
: EBase(multiWin), mDir(dir), mName(name), mRawDir(rawDir), mRawName(rawName), mCoverImg(coverImg), mPageItem(pageItem) {

View File

@ -21,7 +21,6 @@ public:
static QString transcoding(QWidget *parent, QString rawFile, QString rawName, QString dir, int rawW, int rawH, AVCodecID codec_id);
static EVideo *create(const QString &file, PageListItem *pageItem, EBase *multiWin = nullptr);
static EVideo *create(const JObj &, PageListItem *pageItem, EBase *multiWin = nullptr);
static JObj genProg(const JValue &, const QString &, ProgItem *mProgItem);
explicit EVideo(const QString &, const QString &, const QString &, const QString &, QImage &img, PageListItem *pageItem, EBase *multiWin = nullptr);

View File

@ -12,8 +12,9 @@ EWeb::EWeb(const JObj &json, EBase *multiWin) : EBase(multiWin) {
setBaseAttr(json);
url = json["url"].toString();
zoom = json["zoom"].toInt(100);
_x = json["offX"].toInt(0);
_y = json["offY"].toInt(0);
refresh = json["refreshSec"].toInt();
_x = json["offX"].toInt();
_y = json["offY"].toInt();
scaleX = json["scaleX"].toInt(100);
scaleY = json["scaleY"].toInt(100);
}
@ -73,6 +74,21 @@ QWidget* EWeb::attrWgt() {
hBox->addLabel("%");
hBox->addStretch();
hBox = new HBox(vBox);
lb = hBox->addLabel(tr("Refresh every")+":");
lb->setMinimumWidth(70);
lb->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
auto edRefresh = new QSpinBox;
edRefresh->setRange(0, 99999);
edRefresh->setValue(refresh);
connect(edRefresh, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
refresh = value;
});
hBox->addWidget(edRefresh);
hBox->addSpacing(-3);
hBox->addLabel("s");
hBox->addStretch();
hBox = new HBox(vBox);
lb = hBox->addLabel(tr("Offset")+" X:");
@ -137,6 +153,7 @@ JObj EWeb::attrJson() const {
obj["elementType"] = "Web";
obj["url"] = url;
obj["zoom"] = zoom;
obj["refreshSec"] = refresh;
obj["offX"] = _x;
obj["offY"] = _y;
obj["scaleX"] = scaleX;

View File

@ -21,7 +21,7 @@ public:
JObj attrJson() const override;
QString url;
int zoom = 100, _x = 0, _y = 0, scaleX = 100, scaleY = 100;
int zoom = 100, refresh = 0, _x = 0, _y = 0, scaleX = 100, scaleY = 100;
};
#endif // EWEB_H

View File

@ -1,6 +1,5 @@
#include "gentmpthread.h"
#include "cfg.h"
#include "globaldefine.h"
#include "main.h"
#include "tools.h"
#include "program/eenviron.h"
#include "program/evideo.h"
@ -147,6 +146,7 @@ JObj GenTmpThread::cvtPage(const JObj &pageJson) {
source["width"] = geometry["w"];
source["height"] = geometry["h"];
source["rotate"] = ele["rotate"];
source["opacity"] = ele["opacity"].toDouble(1);
source["playTime"] = startTime;
startTime += source["timeSpan"].toInt();
}
@ -167,7 +167,8 @@ JObj GenTmpThread::cvtPage(const JObj &pageJson) {
{"eff", ele["borderEff"]},
{"speed", ele["borderSpeed"]},
{"img_size", borderSize},
{"geometry", JArray{geometry["x"], geometry["y"], geometry["w"], geometry["h"]}}
{"geometry", JArray{geometry["x"], geometry["y"], geometry["w"], geometry["h"]}},
{"rotate", isWin ? 0 : ele["rotate"]}
};
}
layers.append(layer);
@ -223,13 +224,36 @@ JArray GenTmpThread::genSources(QString type, const JArray &eles) {
if(needType) type = ele["elementType"].toString();
if(type=="Text") source = genText(ele, sources);
else if(type=="Image"||type=="Photo") source = genImage(ele);
else if(type=="Video"||type=="Movie") source = EVideo::genProg(ele, dstDir, mProgItem);
else if(type=="Gif") source = convertGif(ele);
else if(type=="Video"||type=="Movie") {
//genProg(ele, dstDir, mProgItem);
auto widget = ele["widget"];
if(widget.isNull()) widget = ele;
auto path = widget["path"].toString();
auto name = widget["file"].toString();
auto srcFile = path + "/" + name;
if(! QFileInfo(srcFile).isFile() && ! QFileInfo(srcFile = srcPageDir + "/" + name).isFile()) continue;
auto id = Tools::fileMd5(srcFile);
if(id.isEmpty()) continue;
QFile::copy(srcFile, dstDir+"/"+id);
source["_type"] = "Video";
source["id"] = id;
source["md5"] = id;
source["name"] = name;
auto play = ele["play"];
source["timeSpan"] = play.isNull() ? ele["duration"].toInt() * ele["playTimes"].toInt() : play["playDuration"].toInt() * play["playTimes"].toInt();
} else if(type=="Gif") source = convertGif(ele);
else if(type=="DClock") source = convertDClock(ele);
else if(type=="AClock") source = convertAClock(ele);
else if(type=="Temp") source = EEnviron::genProg(ele, dstDir, srcPageDir);
else if(type=="Web") source = convertWeb(ele);
else if(type=="Timer") source = convertTimer(ele);
else if(type=="Timer2") {
source["_type"] = "Countdown";
source["time"] = ele["targetTime"];
source["isUp"] = ele["isUp"];
source["html"] = ele["html"];
source["backColor"] = ele["backColor"];
}
if(! source.empty()) {
if(source["timeSpan"].isNull()) source["timeSpan"] = ele["duration"];
source["entryEffect"] = ele["entryEffect"];
@ -237,6 +261,7 @@ JArray GenTmpThread::genSources(QString type, const JArray &eles) {
source["entryEffectTimeSpan"] = ele["entryDur"];
source["exitEffectTimeSpan"] = ele["exitDur"];
if(ele["hasBlink"].toBool()) source["blink"] = ele["blink"];
else if(ele["hasBreathe"].toBool()) source["breathe"] = ele["blink"];
sources.append(source);
}
}
@ -306,16 +331,16 @@ JObj GenTmpThread::genText(const JValue &ele, JArray &sources) {
source["timeSpan"] = duration;
source["entryEffect"] = ele["entryEffect"];
source["exitEffect"] = ele["exitEffect"];
if(source["entryEffect"].toStr().isEmpty()) source["entryEffect"] = "None"; //兼容旧播放器
if(source["exitEffect"].toStr().isEmpty()) source["exitEffect"] = "None"; //兼容旧播放器
source["entryEffectTimeSpan"] = ele["entryDur"];
source["exitEffectTimeSpan"] = ele["exitDur"];
if(ele["hasBlink"].toBool()) source["blink"] = ele["blink"];
else if(ele["hasBreathe"].toBool()) source["breathe"] = ele["blink"];
sources.append(source);
}
return JObj();
}
}
//转换图片
JObj GenTmpThread::genImage(const JValue &ele) {
auto widget = ele["widget"];
auto name = widget.isNull() ? ele["name"].toString() : widget["file"].toString();
@ -439,7 +464,7 @@ JObj GenTmpThread::convertDClock(const JValue &json){
oRes["spaceWidth"] = metric.horizontalAdvance(" ");
QColor color(textColor);
JArray imgs;
for(auto &str : str0_9) Tools::saveImg2(dstDir, metric, font, color, imgs, str, str);
for(int i=0; i<=9; i++) Tools::saveImg2(dstDir, metric, font, color, imgs, QString::number(i), QString::number(i));
Tools::saveImg2(dstDir, metric, font, color, imgs, tr("MON"), "MON");
Tools::saveImg2(dstDir, metric, font, color, imgs, tr("TUE"), "TUE");
Tools::saveImg2(dstDir, metric, font, color, imgs, tr("WED"), "WED");
@ -508,6 +533,7 @@ JObj GenTmpThread::convertWeb(const JValue &res) {
dst["name"] = "WebURL";
dst["url"] = res["url"];
dst["zoom"] = res["zoom"];
dst["refreshSec"] = res["refreshSec"];
dst["offX"] = res["offX"];
dst["offY"] = res["offY"];
dst["scaleX"] = res["scaleX"].toDouble(100)/100;
@ -515,38 +541,38 @@ JObj GenTmpThread::convertWeb(const JValue &res) {
return dst;
}
JObj GenTmpThread::convertTimer(const JValue &json) {
JObj oRes;
oRes["_type"] = "Timer";
oRes["name"] = "Timer";
oRes["targetTime"] = json["targetTime"];
oRes["isDown"] = json["isDown"];
oRes["hasDay"] = json["hasDay"];
oRes["hasHour"] = json["hasHour"];
oRes["hasMin"] = json["hasMin"];
oRes["hasSec"] = json["hasSec"];
JObj src;
src["_type"] = "Timer";
src["name"] = "Timer";
src["targetTime"] = json["targetTime"];
src["isDown"] = json["isDown"];
src["hasDay"] = json["hasDay"];
src["hasHour"] = json["hasHour"];
src["hasMin"] = json["hasMin"];
src["hasSec"] = json["hasSec"];
auto isMultiline = json["isMultiline"].toBool();
oRes["isMultiline"] = isMultiline;
src["isMultiline"] = isMultiline;
auto text = json["text"].toString();
oRes["text"] = text;
src["text"] = text;
QFont font(json["font"].toString());
font.setPixelSize(json["fontSize"].toInt());
font.setBold(json["fontBold"].toBool());
font.setItalic(json["fontItalic"].toBool());
font.setUnderline(json["fontUnderline"].toBool());
oRes["font"] = font.family();
oRes["fontSize"] = font.pixelSize();
oRes["fontBold"] = font.bold();
oRes["fontItalic"] = font.italic();
oRes["fontUnderline"] = font.underline();
src["font"] = font.family();
src["fontSize"] = font.pixelSize();
src["fontBold"] = font.bold();
src["fontItalic"] = font.italic();
src["fontUnderline"] = font.underline();
auto textColor = json["textColor"].toString();
oRes["textColor"] = textColor;
oRes["backColor"] = json["backColor"];
src["textColor"] = textColor;
src["backColor"] = json["backColor"];
font.setStyleStrategy(gTextAntialiasing ? QFont::PreferAntialias : QFont::NoAntialias);
QFontMetrics metric(font);
oRes["spaceWidth"] = metric.horizontalAdvance(" ");
src["spaceWidth"] = metric.horizontalAdvance(" ");
QColor color(textColor);
JObj imgs;
for(auto &str : str0_9) Tools::saveImg(dstDir, metric, font, color, imgs, str, str);
for(int i=0; i<=9; i++) Tools::saveImg(dstDir, metric, font, color, imgs, QString::number(i), QString::number(i));
Tools::saveImg(dstDir, metric, font, color, imgs, tr("day"), "day");
Tools::saveImg(dstDir, metric, font, color, imgs, tr("hour"), "hour");
Tools::saveImg(dstDir, metric, font, color, imgs, tr("min"), "min");
@ -582,6 +608,6 @@ JObj GenTmpThread::convertTimer(const JValue &json) {
} else emit onErr("convertTimer file.open false");
} else emit onErr("convertTimer img.save false");
}
oRes["imgs"] = imgs;
return oRes;
src["imgs"] = imgs;
return src;
}

View File

@ -1,5 +1,5 @@
#include "pagelistitem.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qgui.h"
#include "base/ffutil.h"
#include "base/lodateselector.h"
@ -13,6 +13,7 @@
#include "program/ephoto.h"
#include "program/etext.h"
#include "program/etimer.h"
#include "program/etimer2.h"
#include "program/evideo.h"
#include "program/eweb.h"
#include "tools.h"
@ -51,6 +52,7 @@ PageListItem::PageListItem(const JObj &attr, const QString &pageDir) : mAttr(att
else if(type=="Temp") element = new EEnviron(ele.toObj());
else if(type=="Web") element = new EWeb(ele.toObj());
else if(type=="Timer") element = new ETimer(ele.toObj());
else if(type=="Timer2") element = new ETimer2(ele.toObj());
else if(type=="Window") element = new EMultiWin(ele.toObj(), this);
if(element) mScene->addItem(element);
}

View File

@ -4,7 +4,7 @@
#include "pagelistitem.h"
#include "player/playwin.h"
#include "tools.h"
#include "globaldefine.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include "program/ebase.h"
#include "program/etext.h"
@ -16,6 +16,7 @@
#include "program/eenviron.h"
#include "program/eweb.h"
#include "program/etimer.h"
#include "program/etimer2.h"
#include "program/emultiwin.h"
#include "program/gentmpthread.h"
#include "program/sendprogramdialog.h"
@ -190,6 +191,9 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
action = new QAction(QIcon(":/res/program/Timer.png"), tr("Timer"));
action->setData(EBase::Timer);
toolBar->addAction(action);
action = new QAction(QIcon(":/res/program/Timer.png"), tr("Timer")+"2");
action->setData(EBase::Timer2);
toolBar->addAction(action);
action = new QAction(QIcon(":/res/program/demo-video.png"), tr("Demos"));
connect(action, &QAction::triggered, this, [this] {
auto file = QFileDialog::getOpenFileName(this, tr("Open Demo"), "Demos");
@ -335,19 +339,20 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
element = eVideo;
} else if(type==EBase::Text) {
if(iNewHeight > 80 && (mProgItem->mWidth >= mProgItem->mHeight)) iNewHeight = 80;
element = new EText();
element = new EText;
} else if(type==EBase::DClock) {
if(iNewHeight>80 && (mProgItem->mWidth>=mProgItem->mHeight)) iNewHeight=80;
element = new EDClock();
element = new EDClock;
} else if(type==EBase::AClock) {
if(iNewWidth > 120) iNewWidth = 120;
if(iNewHeight > 120) iNewHeight = 120;
element = new EAClock();
} else if(type==EBase::Environ) element = new EEnviron();
element = new EAClock;
} else if(type==EBase::Environ) element = new EEnviron;
else if(type==EBase::Web) {
element = new EWeb();
element = new EWeb;
element->setSize(mProgItem->mWidth, mProgItem->mHeight);
} else if(type==EBase::Timer) element = new ETimer();
} else if(type==EBase::Timer) element = new ETimer;
else if(type==EBase::Timer2) element = new ETimer2;
else if(type==EBase::Window) element = new EMultiWin(mPageItem);
if(element) {
if(element->mWidth==0) {

View File

@ -6,7 +6,7 @@
#include "gutil/qwaitingdlg.h"
#include "gutil/qwaitingdlg.h"
#include "gentmpthread.h"
#include <globaldefine.h>
#include <main.h>
#include "sendprogramdialog.h"
#include "program/progeditorwin.h"
#include <QJsonArray>

View File

@ -3,15 +3,6 @@
#include <QJsonArray>
#include <QPainter>
void Tools::timerEvent(QTimerEvent *event) {
if(timer_id==event->timerId()) emit sTick();
}
Tools* Tools::getInstance() {
static const auto ins = new Tools(qApp);
return ins;
}
QRect Tools::centerRect(qreal width, qreal height, int maxW, int maxH) {
if(maxW < width || maxH < height) {
auto rate = qMin(maxW / width, maxH / height);
@ -53,11 +44,6 @@ QString Tools::fileMd5(QString filePath) {
file.close();
return QString::fromLatin1(cryptoHash.result().toHex());
}
void Tools::mergeFormat(QTextEdit *textEdit, const QTextCharFormat &fmt) {
QTextCursor cursor = textEdit->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(fmt);
}
QString Tools::saveImg(const QString& dir, const QFontMetrics& metric, const QFont& font, const QColor& color, const QString& str) {
if(str.isEmpty()) return QString();
QImage img(metric.horizontalAdvance(str), metric.lineSpacing(), QImage::Format_ARGB32);

View File

@ -13,21 +13,18 @@
#include <QTextEdit>
#include <QNetworkAccessManager>
const QString str0_9[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
extern QTextEdit *gFdResInfo;
extern ProgItem *gProgItem;
class Tools : public QObject {
Q_OBJECT
public:
static Tools* getInstance();
static QNetworkAccessManager &netManager() {
static QNetworkAccessManager manager;
return manager;
};
static QRect centerRect(qreal, qreal, int, int);
static QString addSufix(QString);
static void mergeFormat(QTextEdit *textEdit, const QTextCharFormat &format);
static QString readErrStr(QImageReader::ImageReaderError);
static QString fileMd5(QString);
static QString saveImg(const QString&, const QFontMetrics&, const QFont&, const QColor&, const QString&);
@ -37,18 +34,6 @@ public:
static int color2Int(const QColor& color);
static QBrush getBrush(const QColor& color);
static QString selectStr(bool f, const QString &s0, const QString &s1 = "");
~Tools() {
killTimer(timer_id);
}
signals:
void sTick();
protected:
virtual void timerEvent(QTimerEvent *event);
private:
Tools(QObject *parent = 0) : QObject(parent) {
timer_id = startTimer(500, Qt::PreciseTimer);
};
int timer_id;
};
#endif // TOOLS_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff