合并 Gif and Image

This commit is contained in:
Gangphon 2025-05-23 18:35:00 +08:00
parent 5390821976
commit 76ba7bc5e5
47 changed files with 491 additions and 672 deletions

View File

@ -11,6 +11,7 @@ greaterThan(QT_MAJOR_VERSION, 5) {
} else {
QMAKE_CFLAGS += /utf-8
QMAKE_CXXFLAGS += /utf-8
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=QT_VERSION_CHECK(5,15,0)
}
CONFIG += c++17
@ -151,6 +152,7 @@ SOURCES += \
player/posdlg.cpp \
player/srccopy.cpp \
progpanel.cpp \
program/etable.cpp \
program/etimer2.cpp \
synctimer.cpp \
tools.cpp \
@ -163,7 +165,6 @@ SOURCES += \
program/ebase.cpp \
program/edclock.cpp \
program/eenviron.cpp \
program/egif.cpp \
program/emultiwin.cpp \
program/ephoto.cpp \
program/etext.cpp \
@ -219,6 +220,7 @@ HEADERS += \
player/posdlg.h \
player/srccopy.h \
progpanel.h \
program/etable.h \
program/etimer2.h \
synctimer.h \
tools.h \
@ -231,7 +233,6 @@ HEADERS += \
program/ebase.h \
program/edclock.h \
program/eenviron.h \
program/egif.h \
program/emultiwin.h \
program/ephoto.h \
program/etext.h \

View File

@ -2,7 +2,7 @@
#include "gutil/qwaitingdlg.h"
#include "gutil/qnetwork.h"
#include "main.h"
#include "tools.h"
#include <QFileDialog>
#include "deviceitem.h"
#include "xlsxdocument.h"
#include "xlsxworkbook.h"
@ -101,7 +101,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetBrightnessSensitivity"))
}
}
@ -187,7 +187,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
if(isAdaptToOld) json.insert("brightness", (brightPercent * card.BrightnessLevel + 50) / 100);
Def_CtrlSetMulti(tr("SetMinBrightness"));
}
@ -277,7 +277,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
QMessageBox::information(this, translate("","Tip"), tr("NeedSelectSensorTypeTip"));
return;
}
QString xlsxFile = QFileDialog::getOpenFileName(this, tr("Open file dialog"), "/", "brightness files(*.xlsx)");
auto xlsxFile = QFileDialog::getOpenFileName(this, tr("Open file dialog"), "/", "brightness files(*.xlsx)");
if(xlsxFile.isEmpty() || ! QFileInfo::exists(xlsxFile)) return;
QXlsx::Document xlsx(xlsxFile);
auto workbook = xlsx.workbook();
@ -290,7 +290,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
}
} else {
auto names = sensorName.split("/");
foreach(auto name, names) {
for(auto &name : names) {
auto idx = xlsx.sheetNames().indexOf(name);
if(idx > -1) {
workbook->setActiveSheet(idx);
@ -323,7 +323,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
Def_CtrlSetReqAfter;
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SensorBrightnessTable"));
}
}
@ -371,7 +371,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
tempQFile.copy(savingFile);
QXlsx::Document xlsx(savingFile);
xlsx.selectSheet(strSensorType);
for(int m=0; m<values.size(); m++) xlsx.write(3, m+3, values[m].toInt());
for(int m=0; m<(int)values.size(); m++) xlsx.write(3, m+3, values[m].toInt());
xlsx.save();
});
}
@ -648,7 +648,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
connect(btnScheImport, &QPushButton::clicked, this, [this] {
auto dir = QSettings().value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("BrightnessSchedule (*.bjs)"));
auto scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("BrightnessSchedule (*.bjs)"));
if(scheFile.isEmpty()) return;
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::ReadOnly)) return;
@ -698,7 +698,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
QSettings settings;
auto dir = settings.value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("BrightnessSchedule (*.bjs)"));
auto scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("BrightnessSchedule (*.bjs)"));
if(scheFile.isEmpty()) return;
settings.setValue("CtrlScheduleDir", QFileInfo(scheFile).absolutePath());
QFile scheQFile(scheFile);
@ -752,7 +752,7 @@ CtrlBrightPanel::CtrlBrightPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
if(isAdaptToOld) getScheduleJson(json, card.BrightnessLevel);
Def_CtrlSetMulti(tr("SetAutoBrightnessTask"))
}
@ -913,7 +913,7 @@ bool CtrlBrightPanel::restoreScheduleJson(JValue &json, int max) {
fdDefBright->setValue(brightness);
auto jsitems = taskBrightness["items"].toArray();
auto brightnesses = json["brightnessPercentageList"].toArray();
for(int i=0; i<jsitems.size(); i++) {
for(int i=0; i<(int)jsitems.size(); i++) {
auto schedule = jsitems[i]["schedules"][0];
int row = tableSche->rowCount();
tableSche->insertRow(row);
@ -923,7 +923,7 @@ bool CtrlBrightPanel::restoreScheduleJson(JValue &json, int max) {
auto slider = new QSlider(Qt::Horizontal);
slider->setRange(1, 100);
if(brightnesses.size() > i) slider->setValue(brightnesses[i].toInt());
if((int)brightnesses.size() > i) slider->setValue(brightnesses[i].toInt());
else slider->setValue(qRound(jsitems[i]["brightness"].toInt() * 100.0 / max));
hBox->addWidget(slider);

View File

@ -1,15 +1,15 @@
#include "ctrlhdmipanel.h"
#include "devicepanel.h"
#include "gutil/qgui.h"
#include "gutil/qnetwork.h"
#include "tools.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include "main.h"
#include <QMessageBox>
#include <QButtonGroup>
#include <QTimeEdit>
#include <QJsonArray>
#include <QSettings>
#include "devicepanel.h"
#include <QFileDialog>
CtrlHdmiPanel::CtrlHdmiPanel() {
auto vBox = new QVBoxLayout(this);
@ -234,7 +234,7 @@ CtrlHdmiPanel::CtrlHdmiPanel() {
connect(btnScheImport, &QPushButton::clicked, this, [this] {
auto dir = QSettings().value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("Sync Schedule")+" (*.syncs)");
auto scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("Sync Schedule")+" (*.syncs)");
if(scheFile.isEmpty()) return;
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::ReadOnly)) return;
@ -251,7 +251,7 @@ CtrlHdmiPanel::CtrlHdmiPanel() {
QSettings settings;
auto dir = settings.value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("Sync Schedule")+" (*.syncs)");
auto scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("Sync Schedule")+" (*.syncs)");
if(scheFile.isEmpty()) return;
settings.setValue("CtrlScheduleDir", QFileInfo(scheFile).absolutePath());
QFile scheQFile(scheFile);
@ -289,7 +289,7 @@ CtrlHdmiPanel::CtrlHdmiPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto card : gSelCards) {
json.insert("HdmiInTask", getScheduleJson());
Def_CtrlSetMulti(tr("SetTimingHdmiInTask"))
}

View File

@ -600,7 +600,7 @@ CtrlNetworkPanel::CtrlNetworkPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetSwitchSimData"))
}
}
@ -825,7 +825,7 @@ CtrlNetworkPanel::CtrlNetworkPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetAPN"))
}
}

View File

@ -4,7 +4,7 @@
#include "devicepanel.h"
#include "gutil/qwaitingdlg.h"
#include "gutil/qnetwork.h"
#include "tools.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QTimeEdit>
#include <QJsonArray>
@ -66,10 +66,10 @@ CtrlPowerPanel::CtrlPowerPanel() {
Def_CtrlSetReqAfter
});
} else {
if(checked) foreach(auto card, gSelCards) {
if(checked) for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetScreenOn"))
}
else foreach(auto card, gSelCards) {
else for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetScreenOff"))
}
}
@ -103,7 +103,7 @@ CtrlPowerPanel::CtrlPowerPanel() {
}
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
@ -188,7 +188,7 @@ CtrlPowerPanel::CtrlPowerPanel() {
connect(pushButtonImport, &QPushButton::clicked, this, [this] {
auto dir = QSettings().value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("PowerSchedule (*.pjs)"));
auto scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("PowerSchedule (*.pjs)"));
if(scheFile.isEmpty()) return;
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::ReadOnly)) return;
@ -205,7 +205,7 @@ CtrlPowerPanel::CtrlPowerPanel() {
QSettings settings;
auto dir = settings.value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("PowerSchedule (*.pjs)"));
auto scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("PowerSchedule (*.pjs)"));
if(scheFile.isEmpty()) return;
settings.setValue("CtrlScheduleDir", QFileInfo(scheFile).absolutePath());
QFile scheQFile(scheFile);
@ -245,7 +245,7 @@ CtrlPowerPanel::CtrlPowerPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetTimingScreenTask"))
}
}
@ -428,7 +428,7 @@ void CtrlPowerPanel::clearSche() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("CleanTimingScreenTask"))
}
}

View File

@ -118,7 +118,7 @@ CtrlPwdPanel::CtrlPwdPanel() {
fdOldPwd->clear();
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;
@ -193,7 +193,7 @@ CtrlPwdPanel::CtrlPwdPanel() {
fdOldPwd->clear();
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [=] {
JValue json;

View File

@ -316,7 +316,7 @@ CtrlTestPanel::CtrlTestPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("StartTest"))
}
}
@ -352,7 +352,7 @@ CtrlTestPanel::CtrlTestPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("StartTest"))
}
}
@ -388,7 +388,7 @@ CtrlTestPanel::CtrlTestPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("StartTest"))
}
}
@ -409,7 +409,7 @@ CtrlTestPanel::CtrlTestPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("StopTest"))
}
}

View File

@ -39,7 +39,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetTimezone"))
}
}
@ -73,7 +73,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti("设置语言")
}
}
@ -145,7 +145,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SyncTime"))
}
}
@ -309,7 +309,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetingSyncMethod"))
}
}
@ -421,7 +421,7 @@ CtrlVerifyClockPanel::CtrlVerifyClockPanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
auto reply = NetReq("http://"+card.ip+":2016/settings").timeout(120000).post(json);
connect(reply, &QNetworkReply::finished, this, [reply, card, isMaster] {
QString err = errStrWithJson(reply);

View File

@ -1,13 +1,13 @@
#include "ctrlvolumepanel.h"
#include "devicepanel.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include "gutil/qnetwork.h"
#include "tools.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QJsonArray>
#include <QTimeEdit>
#include <QSettings>
#include "devicepanel.h"
CtrlVolumePanel::CtrlVolumePanel() {
auto vBox = new VBox(this);
@ -80,7 +80,7 @@ CtrlVolumePanel::CtrlVolumePanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetVolume"))
}
}
@ -212,7 +212,7 @@ CtrlVolumePanel::CtrlVolumePanel() {
connect(btnScheImport, &QPushButton::clicked, this, [this] {
auto dir = QSettings().value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("Volume Schedule (*.vols)"));
auto scheFile = QFileDialog::getOpenFileName(this, tr("Import File"), dir, tr("Volume Schedule (*.vols)"));
if(scheFile.isEmpty()) return;
QFile scheQFile(scheFile);
if(! scheQFile.open(QIODevice::ReadOnly)) return;
@ -229,7 +229,7 @@ CtrlVolumePanel::CtrlVolumePanel() {
QSettings settings;
auto dir = settings.value("CtrlScheduleDir").toString();
if(dir.isEmpty()) dir = "/";
QString scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("Volume Schedule (*.vols)"));
auto scheFile = QFileDialog::getSaveFileName(this, tr("Save File"), dir, tr("Volume Schedule (*.vols)"));
if(scheFile.isEmpty()) return;
settings.setValue("CtrlScheduleDir", QFileInfo(scheFile).absolutePath());
QFile scheQFile(scheFile);
@ -277,7 +277,7 @@ CtrlVolumePanel::CtrlVolumePanel() {
Def_CtrlSetReqAfter
});
} else {
foreach(auto card, gSelCards) {
for(auto &card : gSelCards) {
Def_CtrlSetMulti(tr("SetAutoVolumeTask"))
}
}

View File

@ -2,18 +2,12 @@
#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() {
@ -61,25 +55,26 @@ int main(int argc, char *argv[]) {
QApplication::setOrganizationDomain("ledok.cn");
QApplication::setApplicationName("LedOK Express");
QApplication::setStyle("Fusion");
QApplication a(argc, argv);
QApplication app(argc, argv);
QSplashScreen splash(QPixmap(":/res/splash.png"));
splash.show();
splash.showMessage(QObject::tr("Setting up the LedOK Express..."), Qt::AlignRight | Qt::AlignTop, Qt::white);
app.processEvents();
QFile file(":/css.css");
if(file.exists() && file.open(QFile::ReadOnly)) {
a.setStyleSheet(file.readAll());
app.setStyleSheet(file.readAll());
file.close();
}
QFont font;
font.setFamilies(QStringList{"Arial","PingFang SC","Hiragino Sans GB","STHeiti","Microsoft YaHei","WenQuanYi Micro Hei","sans-serif"});
a.setFont(font);
auto plt = a.palette();
app.setFont(font);
auto plt = app.palette();
plt.setBrush(QPalette::AlternateBase, plt.brush(QPalette::Active, QPalette::Window));
plt.setBrush(QPalette::Inactive, QPalette::Highlight, plt.brush(QPalette::Active, QPalette::Highlight));
plt.setBrush(QPalette::Inactive, QPalette::HighlightedText, plt.brush(QPalette::Active, QPalette::HighlightedText));
a.setPalette(plt);
app.setPalette(plt);
QTranslator qtTrans;
if(qtTrans.load(QLocale(), "qt", "_", "translations")) QCoreApplication::installTranslator(&qtTrans);
@ -89,11 +84,10 @@ int main(int argc, char *argv[]) {
#ifdef _MSC_VER
SetUnhandledExceptionFilter(handleException);
#endif
MainWindow w;
w.show();
splash.finish(&w);
return a.exec();
MainWindow win;
win.show();
splash.finish(&win);
return app.exec();
}
@ -176,9 +170,9 @@ quint64 dirFileSize(const QString &path) {
QDir dir(path);
quint64 size = 0;
auto infos = dir.entryInfoList(QDir::Files);
foreach(QFileInfo fileInfo, infos) size += fileInfo.size();
for(auto &fileInfo : infos) size += fileInfo.size();
auto subDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QString subDir, subDirs) size += dirFileSize(path + QDir::separator() + subDir);
for(auto &subDir : subDirs) size += dirFileSize(path + QDir::separator() + subDir);
return size;
}
@ -225,7 +219,7 @@ unsigned char GetCheckCodeIn8(unsigned char *str, unsigned int size) {
}
void MergeFmt(QTextEdit *textEdit, const QTextCharFormat &fmt) {
QTextCursor cursor = textEdit->textCursor();
auto cursor = textEdit->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(fmt);
}

View File

@ -3,11 +3,13 @@
#include "gutil/qjson.h"
#include "program/progitem.h"
#include <QCoreApplication>
#include <QApplication>
#include <QJsonDocument>
#include <QNetworkReply>
#include <QOpenGLWidget>
#include <QTextEdit>
#include <QFileInfo>
#include <QImageReader>
#define PAGEDEL_SUFFIX "~temp~temp~temp"
#define RECTF_INVALID QRectF(-9999, -9999, 0, 0)
@ -117,7 +119,33 @@ inline int verCompare(const QString& a, const QString& b) {
if(aparts.count() == bparts.count()) return 0;
return aparts.count() > bparts.count() ? aparts[cnt].toInt() : bparts[cnt].toInt();
}
inline QString AddSufix(QString path) {
int i = path.lastIndexOf('.');
QString prefix = path, sufix;
if(i > 0 && i > path.lastIndexOf('/')+1 && i >= path.length()-9) {
prefix = path.left(i);
sufix = path.mid(i);
}
i = 1;
while(QFileInfo::exists(path = prefix+QString::number(i)+sufix)) i++;
return path;
}
inline QString ImgErrStr(QImageReader::ImageReaderError err) {
if(err==QImageReader::UnknownError) return "UnknownError";
if(err==QImageReader::FileNotFoundError) return "FileNotFoundError";
if(err==QImageReader::DeviceError) return "DeviceError";
if(err==QImageReader::UnsupportedFormatError) return "UnsupportedFormatError";
if(err==QImageReader::InvalidDataError) return "InvalidDataError";
return QString::number(err);
}
inline QRect CenterRect(qreal width, qreal height, int maxW, int maxH) {
if(maxW < width || maxH < height) {
auto rate = qMin(maxW / width, maxH / height);
width *= rate;
height *= rate;
}
return QRect((maxW - width) / 2, (maxH - height) / 2, width, height);
}
QString checkReply(QNetworkReply *, QJsonDocument * = 0);
QString errStrWithJson(QNetworkReply *, JValue * = 0, QByteArray * = 0);
QString errStrWithJson(QNetworkReply *, QString errField);

View File

@ -1147,40 +1147,33 @@ void mGuangYingPinWidget::mymidelay(int imlsec)
} while(dwStop-imlsec<dwStart);
}
void mGuangYingPinWidget::MWSendCmdByUdp(unsigned char cmd,unsigned char *pUcValue,unsigned int iLength,int iCountCmd)
{
void mGuangYingPinWidget::MWSendCmdByUdp(unsigned char cmd,unsigned char *pUcValue,unsigned int iLength,int iCountCmd) {
ST_ANSY_PROGRAM_PACKET tempStreadPakcet;
tempStreadPakcet.ucCommType=cmd;
tempStreadPakcet.iBaoLiu=iCountCmd;
tempStreadPakcet.iLength=iLength;
memcpy(tempStreadPakcet.pDataBuffer,pUcValue,iLength);
tempStreadPakcet.pDataBuffer[tempStreadPakcet.iLength]=GetCheckCodeIn8(&tempStreadPakcet.ucCommType,tempStreadPakcet.iLength+sizeof(tempStreadPakcet.iBaoLiu)+sizeof(tempStreadPakcet.ucCommType)+sizeof(tempStreadPakcet.iLength));
int iLenPacket=3*sizeof(unsigned char)+sizeof(char)+sizeof(int)+sizeof(int)+tempStreadPakcet.iLength+sizeof(char);/////除正文外的协议结构大小;
QByteArray databuf = QByteArray(reinterpret_cast<char*>(&tempStreadPakcet), iLenPacket);
int iLenPacket = 3*sizeof(unsigned char)+sizeof(char)+sizeof(int)+sizeof(int)+tempStreadPakcet.iLength+sizeof(char);/////除正文外的协议结构大小;
auto databuf = QByteArray(reinterpret_cast<char*>(&tempStreadPakcet), iLenPacket);
//sPortThread->SendDataBuf(iComIndex,databuf);
QList<QNetworkInterface> networkinterfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interfaces, networkinterfaces) //networkinterfaces负责提供主机的IP地址和网络接口的列表
{
foreach (QNetworkAddressEntry entry, interfaces.addressEntries())//QNetworkAddressEntry存储了一个IP地址子网掩码和广播地址
{
for(auto &interfaces : networkinterfaces) { //networkinterfaces负责提供主机的IP地址和网络接口的列表
for(auto &entry : interfaces.addressEntries()) { //QNetworkAddressEntry存储了一个IP地址子网掩码和广播地址
QHostAddress broadcastAddress("255.255.255.255");
entry.setBroadcast(QHostAddress::Broadcast);
QUdpSocket *tempUdpSocket= new QUdpSocket(this);
if(!tempUdpSocket->bind(entry.ip()))
break;
auto tempUdpSocket = new QUdpSocket(this);
if(!tempUdpSocket->bind(entry.ip())) break;
int iSendLength=tempUdpSocket->writeDatagram((char *)&tempStreadPakcet,iLenPacket,broadcastAddress,31296);
if(iSendLength != iLenPacket) {
char *aa=reinterpret_cast<char*>(&tempStreadPakcet);
auto aa = reinterpret_cast<char*>(&tempStreadPakcet);
tempUdpSocket->writeDatagram(&aa[iSendLength],iLenPacket-iSendLength,broadcastAddress,31296);
}
delete tempUdpSocket;
}
}
if(checkBoxDebug->isChecked()) {
textEditReadBuf->append("udp:"+tr(databuf.toHex()));
}
if(checkBoxDebug->isChecked()) textEditReadBuf->append("udp:"+tr(databuf.toHex()));
}
void mGuangYingPinWidget::MWSendCmd(uint8_t iComIndex,unsigned char cmd,unsigned char *pUcValue,unsigned int iLength,int iCountCmd)
{
@ -1273,12 +1266,11 @@ TA_SerialThread::TA_SerialThread() {
void TA_SerialThread::SearchPort(void) {
portNewCnt=0;
//查找可用的串口
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
for(auto &info : QSerialPortInfo::availablePorts()) {
if(portNewCnt > 9) break;
m_arrNewSerial[portNewCnt]=info;
portNewCnt++;
}
for (int i=0;i<portNewCnt;i++) {
bool iHaveFlag=false;
for(int j=0;j<portCnt;j++)

View File

@ -42,8 +42,8 @@ void CopyDirThread::move() {
bool CopyDirThread::moveDir(const QString &fromDir, const QString &toDir) {
QDir targetDir(toDir);
if(! targetDir.exists() && ! targetDir.mkdir(toDir)) return false;
QFileInfoList fileInfos = QDir(fromDir).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
foreach(QFileInfo fileInfo, fileInfos) {
auto fileInfos = QDir(fromDir).entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
for(auto &fileInfo : fileInfos) {
if(fileInfo.isDir()) { //< 当为目录时递归的进行copy
if(! moveDir(fileInfo.filePath(), targetDir.filePath(fileInfo.fileName()))) return false;
} else { //当允许覆盖操作时,将旧文件进行删除操作

View File

@ -4,11 +4,10 @@
#include "tools.h"
#include "base/locolorselector.h"
#include <QtMath>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPainter>
#include <QSpinBox>
#include <QFileDialog>
#include <QFontComboBox>
#include <QToolButton>
@ -192,8 +191,7 @@ void EAClock::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
}
QWidget* EAClock::attrWgt() {
auto wgtAttr = new QWidget();
auto wgtAttr = new QWidget;
auto vBox = new VBox(wgtAttr);
vBox->setContentsMargins(6, 0, 6, 0);
if(mMultiWin) vBox->setSpacing(3);
@ -201,7 +199,7 @@ QWidget* EAClock::attrWgt() {
addBaseAttrWgt(vBox);
auto hBox = new HBox(vBox);
hBox->addWidget(new QLabel(translate("","Basic Properties")));
hBox->addLabel(translate("","Basic Properties"));
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
@ -211,7 +209,7 @@ QWidget* EAClock::attrWgt() {
hBox = new HBox(vBox);
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Time Zone")));
hBox->addLabel(tr("Time Zone"));
auto edTimeZone = new QComboBox;
auto zoneIds = QTimeZone::availableTimeZoneIds();
@ -230,18 +228,18 @@ QWidget* EAClock::attrWgt() {
fdHasDialImg->setChecked(m_attr.hasDialImg);
hBox->addWidget(fdHasDialImg);
line = new QFrame();
line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
hBox->addWidget(line, 1);
auto wgtDial = new QWidget();
auto wgtDial = new QWidget;
if(! m_attr.hasDialImg) wgtDial->setVisible(false);
hBox = new HBox(wgtDial);
hBox->setContentsMargins(0, 0, 0, 0);
hBox->addSpacing(6);
auto fdDialImg = new QLineEdit();
auto fdDialImg = new QLineEdit;
fdDialImg->setReadOnly(true);
if(! m_attr.path.isEmpty() && ! m_attr.name.isEmpty()) fdDialImg->setText(m_attr.path+"/"+m_attr.name);
hBox->addWidget(fdDialImg);
@ -249,7 +247,7 @@ QWidget* EAClock::attrWgt() {
auto btnSelImg = new QPushButton(tr("Select"));
btnSelImg->setProperty("ssType", "progManageTool");
connect(btnSelImg, &QPushButton::clicked, wgtAttr, [=] {
QString fileName = QFileDialog::getOpenFileName(wgtAttr, tr("Select Dail file"), QApplication::applicationDirPath()+"/AClock/", "Dail files(*.png)");
auto fileName = QFileDialog::getOpenFileName(wgtAttr, tr("Select Dail file"), QApplication::applicationDirPath()+"/AClock/", "Dail files(*.png)");
if(fileName.isEmpty()) return;
fdDialImg->setText(fileName);
QFileInfo info(fileName);
@ -264,7 +262,7 @@ QWidget* EAClock::attrWgt() {
vBox->addWidget(wgtDial);
auto wgtMarks = new QWidget();
auto wgtMarks = new QWidget;
if(m_attr.hasDialImg) wgtMarks->setVisible(false);
connect(fdHasDialImg, &QCheckBox::toggled, this, [this, wgtDial, wgtMarks, fdDialImg](bool checked) {
@ -290,9 +288,9 @@ QWidget* EAClock::attrWgt() {
hBox = new HBox(vbMarks);
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Hour Mark")));
hBox->addLabel(tr("Hour Mark"));
auto fdHourMark = new QComboBox();
auto fdHourMark = new QComboBox;
fdHourMark->addItem(tr("Circular"));
fdHourMark->addItem(tr("Rectangle"));
fdHourMark->addItem(tr("Number"));
@ -303,10 +301,10 @@ QWidget* EAClock::attrWgt() {
});
hBox->addWidget(fdHourMark);
auto fdHourMarkSize = new QSpinBox();
auto fdHourMarkSize = new QSpinBox;
fdHourMarkSize->setMaximum(9999);
fdHourMarkSize->setValue(m_attr.hourMarkSize);
connect(fdHourMarkSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdHourMarkSize, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.hourMarkSize = value;
update();
});
@ -324,9 +322,9 @@ QWidget* EAClock::attrWgt() {
hBox = new HBox(vbMarks);
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Min Mark")));
hBox->addLabel(tr("Min Mark"));
auto fdMinMark = new QComboBox();
auto fdMinMark = new QComboBox;
fdMinMark->addItem(tr("Circular"));
fdMinMark->addItem(tr("Rectangle"));
fdMinMark->setCurrentIndex(m_attr.minMark);
@ -336,10 +334,10 @@ QWidget* EAClock::attrWgt() {
});
hBox->addWidget(fdMinMark);
auto fdMinMarkSize = new QSpinBox();
auto fdMinMarkSize = new QSpinBox;
fdMinMarkSize->setMaximum(9999);
fdMinMarkSize->setValue(m_attr.minMarkSize);
connect(fdMinMarkSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdMinMarkSize, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.minMarkSize = value;
update();
});
@ -377,7 +375,7 @@ QWidget* EAClock::attrWgt() {
auto hhLen = new QSpinBox;
hhLen->setRange(0, 999);
hhLen->setValue(m_attr.hhLen);
connect(hhLen, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(hhLen, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.hhLen = value;
update();
});
@ -386,7 +384,7 @@ QWidget* EAClock::attrWgt() {
auto hhWidth = new QSpinBox;
hhWidth->setRange(0, 999);
hhWidth->setValue(m_attr.hhWidth);
connect(hhWidth, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(hhWidth, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.hhWidth = value;
update();
});
@ -405,7 +403,7 @@ QWidget* EAClock::attrWgt() {
auto mhLen = new QSpinBox;
mhLen->setRange(0, 999);
mhLen->setValue(m_attr.mhLen);
connect(mhLen, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(mhLen, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.mhLen = value;
update();
});
@ -414,7 +412,7 @@ QWidget* EAClock::attrWgt() {
auto mhWidth = new QSpinBox;
mhWidth->setRange(0, 999);
mhWidth->setValue(m_attr.mhWidth);
connect(mhWidth, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(mhWidth, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.mhWidth = value;
update();
});
@ -433,7 +431,7 @@ QWidget* EAClock::attrWgt() {
auto shLen = new QSpinBox;
shLen->setRange(0, 999);
shLen->setValue(m_attr.shLen);
connect(shLen, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(shLen, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.shLen = value;
update();
});
@ -442,7 +440,7 @@ QWidget* EAClock::attrWgt() {
auto shWidth = new QSpinBox;
shWidth->setRange(0, 999);
shWidth->setValue(m_attr.shWidth);
connect(shWidth, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(shWidth, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.shWidth = value;
update();
});
@ -457,7 +455,7 @@ QWidget* EAClock::attrWgt() {
grid->addWidget(fdShowSecHand, 3, 4);
line = new QFrame();
line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
vBox->addWidget(line);
@ -473,7 +471,7 @@ QWidget* EAClock::attrWgt() {
hBox = new HBox(vBox);
hBox->addSpacing(6);
auto fdFontFamily = new QFontComboBox();
auto fdFontFamily = new QFontComboBox;
fdFontFamily->setEditable(false);
fdFontFamily->setCurrentText(m_attr.textFont.family());
connect(fdFontFamily, &QFontComboBox::currentFontChanged, this, [this](const QFont &font) {
@ -487,10 +485,10 @@ QWidget* EAClock::attrWgt() {
});
hBox->addWidget(fdFontFamily);
auto fdFontSize = new QSpinBox();
auto fdFontSize = new QSpinBox;
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(m_attr.textFont.pixelSize());
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdFontSize, &QSpinBox::valueChanged, this, [this](int value) {
m_attr.textFont.setPixelSize(value);
update();
});
@ -559,7 +557,7 @@ bool EAClock::save(const QString &pRoot){
} else {
auto filename = QString("%1-%2-%3-%4-%5.png").arg((int)zValue()).arg((int)x()).arg((int)y()).arg((int)mWidth).arg((int)mHeight);
m_attr.path = pRoot;
QRectF inner = innerRect();
auto inner = innerRect();
QImage img(inner.width(), inner.height(), QImage::Format_ARGB32);
img.fill(Qt::transparent);
{

View File

@ -564,7 +564,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
auto fdX = new QSpinBox;
fdX->setRange(-99999, 999999);
fdX->setValue(x());
connect(fdX, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdX](int value) {
connect(fdX, &QSpinBox::valueChanged, this, [this, fdX](int value) {
if(type()!=Web) {
int max = gProgItem->mWidth - mWidth;
if(value < 0 || value > max) {
@ -584,7 +584,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
auto fdY = new QSpinBox;
fdY->setRange(-99999, 999999);
fdY->setValue(y());
connect(fdY, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdY](int value) {
connect(fdY, &QSpinBox::valueChanged, this, [this, fdY](int value) {
if(type()!=Web) {
int max = gProgItem->mHeight - mHeight;
if(value < 0 || value > max) {
@ -606,7 +606,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
auto fdW = new QSpinBox;
fdW->setRange(6, 999999);
fdW->setValue(mWidth);
connect(fdW, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdW](int value) {
connect(fdW, &QSpinBox::valueChanged, this, [this, fdW](int value) {
if(type()!=Web) {
int max = gProgItem->mWidth - x();
if(value > max) {
@ -625,7 +625,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
auto fdH = new QSpinBox;
fdH->setRange(6, 999999);
fdH->setValue(mHeight);
connect(fdH, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdH](int value) {
connect(fdH, &QSpinBox::valueChanged, this, [this, fdH](int value) {
if(type()!=Web) {
int max = gProgItem->mHeight - y();
if(value > max) {
@ -667,7 +667,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
fdRotate->setRange(-180, 360);
fdRotate->setValue(_rotate);
fdRotate->setToolTip("Need Player 2.1.9");
connect(fdRotate, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdRotate, &QSpinBox::valueChanged, this, [this](int value) {
_rotate = value;
//setRotation(value);
});
@ -785,7 +785,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
auto fdStart = new QSpinBox;
fdStart->setRange(0, 9999);
fdStart->setValue(_startTime);
connect(fdStart, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdStart, &QSpinBox::valueChanged, this, [=](int value) {
_startTime = value;
});
hBox->addWidget(fdStart);
@ -852,7 +852,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
auto fdEntryDur = new QSpinBox;
fdEntryDur->setRange(1, 99);
fdEntryDur->setValue(mEntryDur);
connect(fdEntryDur, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdEntryDur, &QSpinBox::valueChanged, this, [=](int value) {
mEntryDur = value;
if(_duration < value) {
_duration = value;
@ -899,7 +899,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
auto fdExitDur = new QSpinBox;
fdExitDur->setRange(1, 99);
fdExitDur->setValue(mExitDur);
connect(fdExitDur, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdExitDur, &QSpinBox::valueChanged, this, [=](int value) {
mExitDur = value;
if(_duration < value) {
_duration = value;
@ -909,7 +909,7 @@ void EBase::addBaseAttrWgt(QBoxLayout *vBox) {
grid->addWidget(fdExitDur, 1, ccc++);
grid->addLabel(tr("s"), 1, ccc++);
connect(edDuration, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(edDuration, &QSpinBox::valueChanged, this, [=](int value) {
_duration = value;
if(mEntryDur > value) {
mEntryDur = value;

View File

@ -14,8 +14,7 @@ class EBase : public QGraphicsObject {
public:
enum ElementType {
Text = QGraphicsItem::UserType + 1,
Image, Video, Gif, Audio,
DClock, AClock, Timer, Timer2, Environ, Window, Web
Image, Video, Audio, DClock, AClock, Timer, TimerHtml, Environ, Window, Web, Table
};
Q_ENUM(ElementType)
@ -28,8 +27,6 @@ public:
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
virtual JObj attrJson() const = 0;
virtual void loadFiles() {}
virtual void freeFiles() {}
virtual bool save(const QString &) {return true;}
virtual QWidget* attrWgt() = 0;

View File

@ -141,26 +141,24 @@ void EDClock::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
}
QWidget* EDClock::attrWgt() {
auto wgtAttr = new QWidget();
auto vBox = new QVBoxLayout(wgtAttr);
auto wgtAttr = new QWidget;
auto vBox = new VBox(wgtAttr);
vBox->setContentsMargins(6, 0, 6, 0);
if(mMultiWin) vBox->setSpacing(3);
addBaseAttrWgt(vBox);
auto hBox = new QHBoxLayout();
hBox->addWidget(new QLabel(translate("","Basic Properties")));
auto hBox = new HBox(vBox);
hBox->addLabel(translate("","Basic Properties"));
auto line = new QFrame();
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);
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Time Zone")));
hBox->addLabel(tr("Time Zone"));
auto edTimeZone = new QComboBox;
auto zoneIds = QTimeZone::availableTimeZoneIds();
@ -173,15 +171,12 @@ QWidget* EDClock::attrWgt() {
hBox->addWidget(edTimeZone);
hBox->addStretch();
vBox->addLayout(hBox);
line = new QFrame();
line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
vBox->addWidget(line);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
auto fdYear = new QCheckBox(tr("Year"));
@ -208,9 +203,7 @@ QWidget* EDClock::attrWgt() {
});
hBox->addWidget(fdDay);
vBox->addLayout(hBox);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
auto fdHour = new QCheckBox(tr("Hour"));
@ -237,9 +230,7 @@ QWidget* EDClock::attrWgt() {
});
hBox->addWidget(fdSec);
vBox->addLayout(hBox);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
auto fdHasWeek = new QCheckBox(tr("Weekly"));
fdHasWeek->setChecked(hasWeek);
@ -257,9 +248,7 @@ QWidget* EDClock::attrWgt() {
});
hBox->addWidget(fdFullYear);
vBox->addLayout(hBox);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
auto fdIs12Hour = new QCheckBox(tr("12-Hour"));
@ -280,16 +269,14 @@ QWidget* EDClock::attrWgt() {
});
hBox->addWidget(fdAmPm);
vBox->addLayout(hBox);
line = new QFrame();
line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
vBox->addWidget(line);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Date Style")));
hBox->addLabel(tr("Date Style"));
auto fdDateFmt = new QComboBox;
fdDateFmt->addItem("1970-02-24", 13);
@ -315,11 +302,9 @@ QWidget* EDClock::attrWgt() {
hBox->addWidget(fdDateFmt);
hBox->addStretch();
vBox->addLayout(hBox);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Time Style")));
hBox->addLabel(tr("Time Style"));
auto fdTimeFmt = new QComboBox;
fdTimeFmt->addItem("HH:MM:SS");
@ -332,11 +317,9 @@ QWidget* EDClock::attrWgt() {
hBox->addWidget(fdTimeFmt);
hBox->addStretch();
vBox->addLayout(hBox);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
hBox->addWidget(new QLabel(tr("Display Style")));
hBox->addLabel(tr("Display Style"));
auto fdIsMultiline = new QCheckBox(tr("Multiline"));
fdIsMultiline->setChecked(isMultiline);
@ -347,14 +330,12 @@ QWidget* EDClock::attrWgt() {
hBox->addWidget(fdIsMultiline);
hBox->addStretch();
vBox->addLayout(hBox);
line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
vBox->addWidget(line);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
auto fdFontFamily = new QFontComboBox();
@ -374,16 +355,14 @@ QWidget* EDClock::attrWgt() {
auto fdFontSize = new QSpinBox();
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(font.pixelSize());
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdFontSize, &QSpinBox::valueChanged, this, [this](int value) {
font.setPixelSize(value);
update();
});
hBox->addWidget(fdFontSize);
hBox->addStretch();
vBox->addLayout(hBox);
hBox = new QHBoxLayout();
hBox = new HBox(vBox);
hBox->addSpacing(6);
auto fdBold = new QPushButton("B");
@ -427,7 +406,6 @@ QWidget* EDClock::attrWgt() {
});
hBox->addWidget(fdColor);
hBox->addStretch();
vBox->addLayout(hBox);
vBox->addStretch();
return wgtAttr;

View File

@ -312,7 +312,7 @@ QWidget* EEnviron::attrWgt() {
auto fdCompen = new QSpinBox;
fdCompen->setRange(-99, 999);
fdCompen->setValue(tempCompen);
connect(fdCompen, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdCompen, &QSpinBox::valueChanged, this, [=](int value) {
tempCompen = value;
calAttr();
update();
@ -385,7 +385,7 @@ QWidget* EEnviron::attrWgt() {
auto fdSpeed = new QSpinBox();
fdSpeed->setRange(1, 999);
fdSpeed->setValue(scrollSpeed);
connect(fdSpeed, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdSpeed, &QSpinBox::valueChanged, this, [this](int value) {
scrollSpeed = value;
if(timer_id!=0) {
killTimer(timer_id);
@ -422,7 +422,7 @@ QWidget* EEnviron::attrWgt() {
auto fdFontSize = new QSpinBox();
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(font.pixelSize());
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdFontSize, &QSpinBox::valueChanged, this, [this](int value) {
font.setPixelSize(value);
calAttr();
update();

View File

@ -1,166 +0,0 @@
#include "egif.h"
#include "tools.h"
#include "main.h"
#include <QBoxLayout>
#include <QDir>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QMovie>
#include <QPainter>
#include <QPushButton>
#include <QSpinBox>
EGif *EGif::create(const QString &file, PageListItem *pageItem, EBase *multiWin) {
auto movie = new QMovie(file);
if(! movie->isValid()) {
QMessageBox::critical(pageItem->listWidget(), "Gif Error", Tools::readErrStr(movie->lastError())+": "+movie->lastErrorString()+"\n"+file);
delete movie;
return 0;
}
movie->setCacheMode(QMovie::CacheAll);
movie->jumpToFrame(0);
QFileInfo info(file);
return new EGif(movie, info.absolutePath(), info.fileName(), pageItem, multiWin);
}
EGif *EGif::create(const JObj &json, PageListItem *pageItem, EBase *multiWin) {
auto widget = json["widget"];
auto dir = widget["path"].toString();
auto name = widget["file"].toString();
if(! QFileInfo::exists(dir)) dir = pageItem->mPageDir;
QString file = dir + "/" + name;
if(QFileInfo::exists(file)) ;
else if(QFileInfo::exists(file = pageItem->mPageDir + "/" + name)) dir = pageItem->mPageDir;
else return nullptr;
auto movie = new QMovie(file);
if(! movie->isValid()) {
delete movie;
return 0;
}
movie->setCacheMode(QMovie::CacheAll);
movie->jumpToFrame(0);
auto ins = new EGif(movie, dir, name, pageItem, multiWin);
ins->setBaseAttr(json);
return ins;
}
EGif::EGif(QMovie *movie, const QString &dir, const QString &name, PageListItem *pageItem, EBase *multiWin) : EBase(multiWin), mMovie(movie), mDir(dir), mName(name), mPageItem(pageItem) {
mType = EBase::Gif;
}
EGif::~EGif() {
if(mMovie) delete mMovie;
}
void EGif::paint(QPainter *painter, const QStyleOptionGraphicsItem *a, QWidget *b) {
if(mMovie) {
painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
painter->drawPixmap(innerRect(), mMovie->currentPixmap(), QRectF());
if(timer==0) {
auto delay = mMovie->nextFrameDelay();
if(delay) {
timer = new SyncTimer(delay);
connect(timer, &SyncTimer::timeout, this, &EGif::sltNext, Qt::BlockingQueuedConnection);
timer->start();
}
}
}
EBase::paint(painter, a, b);
}
void EGif::sltNext() {
if(isVisible() && mMovie) {
mMovie->jumpToNextFrame();
timer->inter = mMovie->nextFrameDelay();
update();
} else if(timer) {
timer->stop();
timer = 0;
}
}
void EGif::loadFiles() {
if(mMovie) return;
if(! QFileInfo::exists(mDir + "/" + mName)) return;
mMovie = new QMovie(mDir + "/" + mName, QByteArray());
mMovie->setCacheMode(QMovie::CacheAll);
mMovie->jumpToFrame(0);
}
void EGif::freeFiles() {
if(mMovie==0) return;
delete mMovie;
mMovie = 0;
}
QWidget* EGif::attrWgt() {
auto wgtAttr = new QWidget;
auto vBox = new QVBoxLayout(wgtAttr);
vBox->setContentsMargins(6, 0, 6, 0);
if(mMultiWin) vBox->setSpacing(3);
addBaseAttrWgt(vBox);
auto hBox = new QHBoxLayout();
hBox->addWidget(new QLabel(translate("","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->addSpacing(6);
hBox->addWidget(new QLabel(tr("File")));
auto wFile = new QLineEdit(mName);
wFile->setReadOnly(true);
hBox->addWidget(wFile);
auto bnSelectFile = new QPushButton("...");
bnSelectFile->setFixedWidth(30);
bnSelectFile->setObjectName("bnSelectFile");
connect(bnSelectFile, &QPushButton::clicked, wgtAttr, [=] {
auto file = QFileDialog::getOpenFileName(wgtAttr, translate("","Select File"), gFileHome, EGif::filters());
if(file.isEmpty()) return;
auto movie = new QMovie(file);
if(! movie->isValid()) {
QMessageBox::critical(wgtAttr, "Gif Error", Tools::readErrStr(movie->lastError())+": "+movie->lastErrorString()+"\n"+file);
delete movie;
return;
}
movie->setCacheMode(QMovie::CacheAll);
movie->jumpToFrame(0);
QFileInfo fileInfo(file);
mName = fileInfo.fileName();
wFile->setText(mName);
mDir = fileInfo.absolutePath();
gFileHome = mDir;
if(mMovie) delete mMovie;
mMovie = movie;
});
hBox->addWidget(bnSelectFile);
vBox->addLayout(hBox);
vBox->addStretch();
return wgtAttr;
}
bool EGif::save(const QString &pageDir) {
QString oldFile = mDir + PAGEDEL_SUFFIX + "/" + mName;
if(QFileInfo::exists(oldFile)) ;
else if(QFileInfo::exists(oldFile = mDir + "/" + mName)) ;
else return false;
QFile::copy(oldFile, pageDir + "/" + mName);
mDir = pageDir;
return true;
}
JObj EGif::attrJson() const {
JObj oRoot;
addBaseAttr(oRoot);
oRoot["elementType"] = "Gif";
oRoot["widget"] = JObj{
{"file", mName},
{"path", mDir}
};
return oRoot;
}

View File

@ -1,35 +0,0 @@
#ifndef EGIF_H
#define EGIF_H
#include "ebase.h"
#include "pagelistitem.h"
#include "synctimer.h"
class EGif : public EBase {
Q_OBJECT
public:
static QString filters() { return "Gif(*.gif)"; }
static EGif *create(const QString &file, PageListItem *pageItem, EBase *multiWin = nullptr);
static EGif *create(const JObj &, PageListItem *pageItem, EBase *multiWin = nullptr);
explicit EGif(QMovie*, const QString &dir, const QString &name, PageListItem *pageItem, EBase *multiWin = nullptr);
~EGif();
virtual int type() const override { return EBase::Gif; }
void paint(QPainter*, const QStyleOptionGraphicsItem *, QWidget *) override;
QWidget* attrWgt() override;
bool save(const QString &pRoot) override;
JObj attrJson() const override;
void loadFiles() override;
void freeFiles() override;
QMovie *mMovie;
QString mDir;
QString mName;
public slots:
void sltNext();
protected:
PageListItem *mPageItem;
SyncTimer* timer = 0;
};
#endif // EGIF_H

View File

@ -5,14 +5,11 @@
#include "etext.h"
#include "ephoto.h"
#include "evideo.h"
#include "egif.h"
#include "edclock.h"
#include "eaclock.h"
#include "etimer.h"
#include "eenviron.h"
#include "eweb.h"
#include <QJsonArray>
#include <QBoxLayout>
#include <QMenu>
#include <QMessageBox>
#include <QGraphicsScene>
@ -29,10 +26,9 @@ EMultiWin::EMultiWin(const JObj &json, PageListItem *pageItem) : mPageItem(pageI
index = json["index"].toInt();
for(auto &element : elements) {
QString type = element["elementType"].toString();
EBase *inner = nullptr;
EBase *inner = 0;
if(type=="Text") inner = new EText(element.toObj(), this);
else if(type=="Image"||type=="Photo") inner = EPhoto::create(element.toObj(), pageItem, this);
else if(type=="Gif") inner = EGif::create(element.toObj(), pageItem, this);
else if(type=="Image" || type=="Photo" || type=="Gif") inner = EPhoto::create(element.toObj(), pageItem, this);
else if(type=="Video"||type=="Movie") inner = EVideo::create(element.toObj(), pageItem, this);
else if(type=="DClock") inner = new EDClock(element.toObj(), this);
else if(type=="AClock") inner = new EAClock(element.toObj(), this);
@ -42,7 +38,6 @@ EMultiWin::EMultiWin(const JObj &json, PageListItem *pageItem) : mPageItem(pageI
if(inner==0) continue;
inner->setPos(0, 0);
inner->setFlag(QGraphicsItem::ItemStacksBehindParent);
if(index != inners.size()) inner->freeFiles();
inners.emplace_back(inner);
}
if(inners.empty()) return;
@ -50,7 +45,7 @@ EMultiWin::EMultiWin(const JObj &json, PageListItem *pageItem) : mPageItem(pageI
setCur(inners[index]);
}
EMultiWin::~EMultiWin() {
foreach(auto inner, inners) delete inner;
for(auto inner : inners) delete inner;
}
void EMultiWin::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
@ -67,7 +62,7 @@ void EMultiWin::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
}
bool EMultiWin::save(const QString &pageDir) {
foreach(auto inner, inners) inner->save(pageDir);
for(auto inner : inners) inner->save(pageDir);
return true;
}
@ -85,10 +80,9 @@ JObj EMultiWin::attrJson() const{
void EMultiWin::setCur(EBase *cur) {
cur->setSize(mWidth, mHeight);
connect(this, &EMultiWin::sizeChanged, cur, [cur] {
if(cur->mMultiWin!=nullptr) cur->setSize(cur->mMultiWin->mWidth, cur->mMultiWin->mHeight);
if(cur->mMultiWin) cur->setSize(cur->mMultiWin->mWidth, cur->mMultiWin->mHeight);
});
cur->setParentItem(this);
cur->loadFiles();
}
class MListWidget : public QListWidget {
@ -119,20 +113,19 @@ QWidget* EMultiWin::attrWgt() {
vBoxGroup->setContentsMargins(0,0,0,0);
vBoxGroup->setSpacing(2);
auto hBox = new QHBoxLayout();
auto hBox = new QHBoxLayout;
auto btnAdd = new QPushButton();
auto btnAdd = new QPushButton;
btnAdd->setIcon(QIcon(":/res/program/Add.png"));
btnAdd->setProperty("style","multiTool");
auto menu = new QMenu();
auto menu = new QMenu;
menu->addAction(QIcon(":/res/program/Text.png"), tr("Text"))->setData(EBase::Text);
menu->addAction(QIcon(":/res/program/Photo.png"), tr("Photo"))->setData(EBase::Image);
menu->addAction(QIcon(":/res/program/Movie.png"), tr("Video"))->setData(EBase::Video);
menu->addAction(QIcon(":/res/program/Gif.png"), tr("Gif"))->setData(EBase::Gif);
menu->addAction(QIcon(":/res/program/DClock.png"), tr("DClock"))->setData(EBase::DClock);
menu->addAction(QIcon(":/res/program/AClock.png"), tr("AClock"))->setData(EBase::AClock);
auto listWgt = new MListWidget();
auto listWgt = new MListWidget;
connect(menu, &QMenu::triggered, this, [=](QAction *act) {
int type = act->data().toInt();
int order = listWgt->count();
@ -141,8 +134,15 @@ QWidget* EMultiWin::attrWgt() {
if(type==EBase::Image) {
auto files = QFileDialog::getOpenFileNames(wgtAttr, translate("","Select File"), gFileHome, EPhoto::filters());
for(int i=0; i<files.count(); i++) {
auto ePhoto = EPhoto::create(files[i], mPageItem, this);
if(ePhoto==0) continue;
QImageReader reader(files[i]);
reader.setAutoTransform(true);
auto img = reader.read();
if(img.isNull()) {
QMessageBox::critical(wgtAttr, "Image Error", ImgErrStr(reader.error())+": "+reader.errorString()+"\n"+files[i]);
continue;
}
QFileInfo info(files[i]);
auto ePhoto = new EPhoto(reader, img, info.absolutePath(), info.fileName(), JObj(), this);
ePhoto->setSize(mWidth, mHeight);
ePhoto->setZValue(order++);
ePhoto->setFlag(QGraphicsItem::ItemStacksBehindParent);
@ -155,23 +155,6 @@ QWidget* EMultiWin::attrWgt() {
gFileHome = ePhoto->mDir;
}
}
} else if(type==EBase::Gif) {
auto files = QFileDialog::getOpenFileNames(wgtAttr, translate("","Select File"), gFileHome, EGif::filters());
for(int i=0; i<files.count(); i++) {
auto eGif = EGif::create(files[i], mPageItem, this);
if(eGif==0) continue;
eGif->setSize(mWidth, mHeight);
eGif->setZValue(order++);
eGif->setFlag(QGraphicsItem::ItemStacksBehindParent);
inners.emplace_back(eGif);
auto item = new QListWidgetItem(QIcon(":/res/program/Gif.png"), tr("Gif")+" "+eGif->mName);
item->setData(Qt::UserRole, QVariant::fromValue((void*) eGif));
listWgt->addItem(item);
if(i == files.count()-1) {
listWgt->setCurrentItem(item);
gFileHome = eGif->mDir;
}
}
} else if(type==EBase::Video) {
auto file = QFileDialog::getOpenFileName(wgtAttr, translate("","Select File"), gFileHome, EVideo::filters());
if(! file.isEmpty()) {
@ -232,7 +215,7 @@ QWidget* EMultiWin::attrWgt() {
btnClean->setProperty("style","multiTool");
connect(btnClean, &QPushButton::clicked, this, [this, listWgt] {
listWgt->clear();
foreach(auto inner, inners) delete inner;
for(auto inner : inners) delete inner;
inners.clear();
});
hBox->addWidget(btnClean);
@ -272,19 +255,18 @@ QWidget* EMultiWin::attrWgt() {
vBoxGroup->addLayout(hBox);
listWgt->setMinimumHeight(120);
listWgt->setIconSize(QSize(20, 20));
foreach(auto inner, inners) {
listWgt->setIconSize({20, 20});
for(auto inner : inners) {
QListWidgetItem *item = 0;
int type = inner->type();
auto type = inner->type();
if(type==EBase::Text) item = new QListWidgetItem(QIcon(":/res/program/Text.png"), tr("Text"));
else if(type==EBase::Image) item = new QListWidgetItem(QIcon(":/res/program/Photo.png"), tr("Photo")+" "+static_cast<EPhoto*>(inner)->mName);
else if(type==EBase::Video) item = new QListWidgetItem(QIcon(":/res/program/Movie.png"), tr("Video")+" "+static_cast<EVideo*>(inner)->mRawName);
else if(type==EBase::Gif) item = new QListWidgetItem(QIcon(":/res/program/Gif.png"), tr("Gif")+" "+static_cast<EGif*>(inner)->mName);
else if(type==EBase::Image) item = new QListWidgetItem(QIcon(":/res/program/Photo.png"), tr("Photo")+" "+((EPhoto*)inner)->mName);
else if(type==EBase::Video) item = new QListWidgetItem(QIcon(":/res/program/Movie.png"), tr("Video")+" "+((EVideo*)inner)->mRawName);
else if(type==EBase::DClock) item = new QListWidgetItem(QIcon(":/res/program/DClock.png"), tr("DClock"));
else if(type==EBase::AClock) item = new QListWidgetItem(QIcon(":/res/program/AClock.png"), tr("AClock"));
else if(type==EBase::Environ) item = new QListWidgetItem(QIcon(":/res/program/Temp.png"), tr("Environment"));
else if(type==EBase::Timer) item = new QListWidgetItem(QIcon(":/res/program/Timer.png"), tr("Timer"));
if(item != nullptr) {
if(item) {
item->setData(Qt::UserRole, QVariant::fromValue((void*) inner));
listWgt->addItem(item);
}
@ -295,7 +277,6 @@ QWidget* EMultiWin::attrWgt() {
if(eLast) {
if(scene()) scene()->removeItem(eLast);
disconnect(this, &EMultiWin::sizeChanged, eLast, 0);
eLast->freeFiles();
}
auto itemLast = vBox->itemAt(vBox->count()-1);
if(itemLast && itemLast->widget() != groupBox) {

View File

@ -1,60 +1,44 @@
#include "ephoto.h"
#include "tools.h"
#include "main.h"
#include <QComboBox>
#include <QFileDialog>
#include <QImageReader>
#include <QLineEdit>
#include <QMessageBox>
#include <QPainter>
#include <QSpinBox>
EPhoto *EPhoto::create(const QString &file, PageListItem *pageItem, EBase *multiWin) {
QImageReader reader(file);
reader.setAutoTransform(true);
auto img = reader.read();
if(img.isNull()) {
QMessageBox::critical(pageItem->listWidget(), "Image Error", Tools::readErrStr(reader.error())+": "+reader.errorString()+"\n"+file);
return 0;
}
QFileInfo info(file);
return new EPhoto(img, info.absolutePath(), info.fileName(), JObj(), pageItem, multiWin);
}
EPhoto *EPhoto::create(const JObj &json, PageListItem *pageItem, EBase *multiWin) {
auto widget = json["widget"];
auto dir = (widget.isNull() ? json["dir"] : widget["path"]).toString();
auto name = (widget.isNull() ? json["name"] : widget["file"]).toString();
if(! QFileInfo(dir).isDir()) dir = pageItem->mPageDir;
QString file = dir + "/" + name;
QFileInfo fileInfo(file);
if(! fileInfo.isFile()) {
QString file2 = dir + "/" + widget["yuanshi_file"].toString();
if(QFileInfo(file2).isFile()) QFile::rename(file2, file);
else if(QFileInfo(file2 = widget["computer_pic_file"].toString()).isFile()) QFile::copy(file2, file);
else if(QFileInfo(file2 = dir + "/card_"+name).isFile()) QFile::rename(file2, file);
else return nullptr;
}
auto file = pageItem->mPageDir + "/" + name;
QImageReader reader(file);
reader.setAutoTransform(true);
auto img = reader.read();
if(img.isNull()) return 0;
auto ins = new EPhoto(img, dir, name, json, pageItem, multiWin);
auto ins = new EPhoto(reader, img, pageItem->mPageDir, name, json, multiWin);
ins->setBaseAttr(json);
return ins;
}
EPhoto::EPhoto(const QImage &img, const QString &dir, const QString &name, const JObj &json, PageListItem *pageItem, EBase *multiWin) : EBase(multiWin), img(img), mDir(dir), mName(name), mPageItem(pageItem) {
EPhoto::EPhoto(QImageReader &reader, const QImage &img, const QString &dir, const QString &name, const JObj &json, EBase *multiWin) : EBase(multiWin), mDir(dir), mName(name) {
mType = EBase::Image;
auto cnt = reader.imageCount();
if(cnt<=1) this->img = img;
else {
frames.push_back({QPixmap::fromImage(img), reader.nextImageDelay()});
while((int)frames.size() < cnt) {
reader.jumpToNextImage();
frames.push_back({QPixmap::fromImage(reader.read()), reader.nextImageDelay()});
}
}
direct = json["direct"].toString();
speed = json["speed"].toInt();
tailSpacing = json["tailSpacing"].toInt();
scaleImgIfNeed();
}
JObj EPhoto::attrJson() const {
JObj json;
addBaseAttr(json);
json["elementType"] = "Image";
json["dir"] = mDir;
json["elementType"] = frames.empty() ? "Image" : "Gif";
json["name"] = mName;
json["direct"] = direct;
json["speed"] = speed;
@ -62,31 +46,45 @@ JObj EPhoto::attrJson() const {
return json;
}
void EPhoto::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter->drawImage(innerRect(), img);
if(frames.empty()) painter->drawImage(innerRect(), img);
else {
painter->drawPixmap(innerRect(), frames[fi].img, QRectF());
if(timer==0) {
auto delay = frames[fi].dur;
if(delay) {
timer = new SyncTimer(delay);
connect(timer, &SyncTimer::timeout, this, &EPhoto::sltNext, Qt::BlockingQueuedConnection);
timer->start();
}
}
}
EBase::paint(painter, option, widget);
}
void EPhoto::freeFiles() {
if(img.isNull()) return;
img = QImage();
}
void EPhoto::loadFiles() {
if(! img.isNull()) return;
if(! QFileInfo::exists(mDir + "/" + mName)) return;
img = QImage(mDir + "/" + mName);
void EPhoto::sltNext() {
if(isVisible() && ! frames.empty()) {
if(++fi==frames.size()) fi = 0;
timer->inter = frames[fi].dur;
update();
} else if(timer) {
timer->stop();
timer = 0;
}
}
bool EPhoto::save(const QString &pageDir) {
QString newName = mName;
QString newFile = pageDir + "/" + newName;
auto oldFile = mDir + PAGEDEL_SUFFIX + "/" + mName;
auto newName = mName;
auto newFile = pageDir + "/" + newName;
if(QFileInfo::exists(newFile)) {
newFile = Tools::addSufix(newFile);
newFile = AddSufix(newFile);
newName = QFileInfo(newFile).fileName();
}
QString oldFile = mDir + PAGEDEL_SUFFIX + "/" + mName;
if(QFileInfo::exists(oldFile)) QFile(oldFile).copy(newFile);
else if(pageDir!=mDir && QFileInfo::exists(oldFile = mDir + "/" + mName)) QFile(oldFile).copy(newFile);
else if(QFileInfo::exists(pageDir + "/" + mName)) newName = mName;
mDir = pageDir;
else return false;
mName = newName;
mDir = pageDir;
return true;
}
@ -99,7 +97,7 @@ QWidget* EPhoto::attrWgt() {
addBaseAttrWgt(vBox);
auto hBox = new HBox(vBox);
hBox->addWidget(new QLabel(translate("","Basic Properties")));
hBox->addLabel(translate("","Basic Properties"));
auto line = new QFrame();
line->setFrameShape(QFrame::HLine);
@ -117,29 +115,45 @@ QWidget* EPhoto::attrWgt() {
auto bnSelectFile = new QPushButton("...");
bnSelectFile->setFixedWidth(30);
bnSelectFile->setObjectName("bnSelectFile");
auto wgtScroll = new QWidget;
connect(bnSelectFile, &QPushButton::clicked, wgtAttr, [=] {
QString home = mDir.startsWith(gProgItem->mProgDir) ? gFileHome : mDir;
QString file = QFileDialog::getOpenFileName(wgtAttr, translate("","Select File"), home, EPhoto::filters());
auto home = mDir.startsWith(gProgItem->mProgDir) ? gFileHome : mDir;
auto file = QFileDialog::getOpenFileName(wgtAttr, translate("","Select File"), home, EPhoto::filters());
if(file.isEmpty()) return;
QImageReader reader(file);
reader.setAutoTransform(true);
auto aimg = reader.read();
if(aimg.isNull()) {
QMessageBox::critical(wgtAttr, tr("Image Read Error"), Tools::readErrStr(reader.error())+": "+reader.errorString()+"\n"+file);
QMessageBox::critical(wgtAttr, tr("Image Read Error"), ImgErrStr(reader.error())+": "+reader.errorString()+"\n"+file);
return;
}
img = aimg;
QFileInfo info(file);
mDir = info.absolutePath();
gFileHome = mDir;
mName = info.fileName();
scaleImgIfNeed();
fdFile->setText(mName);
gFileHome = mDir = info.absolutePath();
fdFile->setText(mName = info.fileName());
frames.clear();
fi = 0;
auto cnt = reader.imageCount();
if(cnt<=1) {
img = aimg;
wgtScroll->show();
} else {
img = QImage();
frames.push_back({QPixmap::fromImage(img), reader.nextImageDelay()});
while((int)frames.size() < cnt) {
reader.jumpToNextImage();
frames.push_back({QPixmap::fromImage(reader.read()), reader.nextImageDelay()});
}
wgtScroll->hide();
}
});
hBox->addWidget(bnSelectFile);
vBox->addWidget(wgtScroll);
wgtScroll->setVisible(frames.empty());
hBox = new HBox(wgtScroll);
hBox->setContentsMargins(0,0,0,0);
hBox = new HBox(vBox);
auto label = hBox->addLabel(tr("Scroll")+": "+tr("Direction"));
label->setMinimumWidth(80);
label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
@ -197,7 +211,7 @@ QWidget* EPhoto::attrWgt() {
// auto edTailSpacing = new QSpinBox;
// edTailSpacing->setRange(0, 9999);
// edTailSpacing->setValue(tailSpacing);
// connect(edTailSpacing, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
// connect(edTailSpacing, &QSpinBox::valueChanged, this, [this](int value) {
// tailSpacing = value;
// });
// hBox->addWidget(edTailSpacing);
@ -243,7 +257,7 @@ QWidget* EPhoto::attrWgt() {
// auto fdEntryDur = new QSpinBox;
// fdEntryDur->setRange(1, 99);
// fdEntryDur->setValue(mEntryDur);
// connect(fdEntryDur, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
// connect(fdEntryDur, &QSpinBox::valueChanged, this, [=](int value) {
// mEntryDur = value;
// if(mDuration < value) {
// mDuration = value;
@ -285,7 +299,7 @@ QWidget* EPhoto::attrWgt() {
// auto fdExitDur = new QSpinBox;
// fdExitDur->setRange(1, 99);
// fdExitDur->setValue(mExitDur);
// connect(fdExitDur, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
// connect(fdExitDur, &QSpinBox::valueChanged, this, [=](int value) {
// mExitDur = value;
// if(mDuration < value) {
// mDuration = value;
@ -298,19 +312,3 @@ QWidget* EPhoto::attrWgt() {
vBox->addStretch();
return wgtAttr;
}
void EPhoto::scaleImgIfNeed() {
if(img.width() > 4096 || img.height() > 4096) {
if(img.width() > img.height()) img = img.scaledToWidth(3840, Qt::SmoothTransformation);
else img = img.scaledToHeight(3840, Qt::SmoothTransformation);
if(mName.endsWith(".jpg", Qt::CaseInsensitive)) mName = mName.chopped(3)+"png";
else if(mName.endsWith(".jpeg", Qt::CaseInsensitive)) mName = mName.chopped(4)+"png";
mDir = mPageItem->mPageDir;
QString save = mDir + "/" + mName;
if(QFileInfo::exists(save)) {
save = Tools::addSufix(save);
mName = QFileInfo(save).fileName();
}
img.save(save);
}
}

View File

@ -3,31 +3,35 @@
#include "ebase.h"
#include "pagelistitem.h"
#include "synctimer.h"
struct Frame {
QPixmap img;
int dur = 100;
};
class EPhoto : public EBase {
Q_OBJECT
public:
static QString filters() { return tr("Images (*.png *.jpg *.jpeg *.bmp)"); }
static EPhoto *create(const QString &file, PageListItem *pageItem, EBase *multiWin = nullptr);
static EPhoto *create(const JObj &, PageListItem *pageItem, EBase *multiWin = nullptr);
static QString filters() { return tr("Images (*.png *.jpg *.jpeg *.bmp *.gif)"); }
static EPhoto *create(const JObj &, PageListItem *pageItem, EBase *multiWin = 0);
explicit EPhoto(const QImage&, const QString &dir, const QString &name, const JObj &json, PageListItem *pageItem, EBase *multiWin = nullptr);
void scaleImgIfNeed();
explicit EPhoto(QImageReader &reader, const QImage &, const QString &dir, const QString &name, const JObj &json, EBase *multiWin = 0);
int type() const override { return EBase::Image; }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
JObj attrJson() const override;
void freeFiles() override;
void loadFiles() override;
bool save(const QString &pageDir) override;
QWidget* attrWgt() override;
QImage img;
std::vector<Frame> frames;
QString mDir, mName, direct;
int speed = 0, tailSpacing = 0;
int fi = 0, speed = 0, tailSpacing = 0;
public slots:
void sltNext();
protected:
PageListItem *mPageItem;
SyncTimer* timer = 0;
};
#endif // EPHOTO_H

82
LedOK/program/etable.cpp Normal file
View File

@ -0,0 +1,82 @@
#include "etable.h"
#include "gutil/qgui.h"
#include "main.h"
#include <QSpinBox>
#include <QLineEdit>
#include <QPainter>
ETable::ETable(EBase *multiWin) : EBase(multiWin) {
mType = EBase::Table;
}
ETable::ETable(const JObj &json, EBase *multiWin) : EBase(multiWin) {
mType = EBase::Table;
setBaseAttr(json);
url = json["url"].toString();
}
void ETable::paint(QPainter *painter, const QStyleOptionGraphicsItem *a, QWidget *b) {
auto inner = innerRect();
painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
//painter->drawImage(QRectF(inner.width()/2, inner.height()/2, maskW, maskH), holder());
EBase::paint(painter, a, b);
}
QWidget* ETable::attrWgt() {
auto wgtAttr = new QWidget;
auto vBox = new VBox(wgtAttr);
vBox->setContentsMargins(6, 0, 6, 0);
if(mMultiWin) vBox->setSpacing(3);
addBaseAttrWgt(vBox);
auto hBox = new HBox(vBox);
hBox->addLabel(translate("","Basic Properties"));
auto line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
hBox->addWidget(line, 1);
hBox = new HBox(vBox);
hBox->addSpacing(6);
hBox->addLabel("URL:");
auto url_fd = new QLineEdit(url);
hBox->addWidget(url_fd);
connect(url_fd, &QLineEdit::textChanged, this, [this](const QString &text) {
url = text;
});
hBox = new HBox(vBox);
auto 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, &QSpinBox::valueChanged, this, [=](int value) {
refresh = value;
});
hBox->addWidget(edRefresh);
hBox->addSpacing(-3);
hBox->addLabel("s");
hBox->addStretch();
vBox->addStretch();
return wgtAttr;
}
JObj ETable::attrJson() const {
JObj obj;
addBaseAttr(obj);
obj["elementType"] = "Table";
obj["url"] = url;
obj["zoom"] = zoom;
obj["refreshSec"] = refresh;
obj["offX"] = _x;
obj["offY"] = _y;
obj["scaleX"] = scaleX;
obj["scaleY"] = scaleY;
return obj;
}

22
LedOK/program/etable.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef ETABLE_H
#define ETABLE_H
#include "ebase.h"
class ETable : public EBase {
Q_OBJECT
public:
explicit ETable(EBase *multiWin = 0);
explicit ETable(const JObj &json, EBase *multiWin = 0);
int type() const override {return EBase::Table;}
void paint(QPainter*, const QStyleOptionGraphicsItem *, QWidget *) override;
QWidget* attrWgt() override;
bool save(const QString &) override {return true;};
JObj attrJson() const override;
QString url;
int zoom = 100, refresh = 0, _x = 0, _y = 0, scaleX = 100, scaleY = 100;
};
#endif // ETABLE_H

View File

@ -111,7 +111,7 @@ QWidget* EText::attrWgt() {
auto fdFontSize = new QSpinBox;
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(16);
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, fdText, [=](int value) {
connect(fdFontSize, &QSpinBox::valueChanged, fdText, [=](int value) {
if(value <= 0) return;
QTextCharFormat fmt;
fmt.setProperty(QTextFormat::FontPixelSize, value);
@ -250,20 +250,16 @@ QWidget* EText::attrWgt() {
hBox->addStretch();
auto lb = new QLabel(tr("Kerning"));
auto lb = hBox->addLabel(tr("Kerning"));
lb->setToolTip(lb->text());
hBox->addWidget(lb);
auto edLetterSpacing = new QSpinBox;
edLetterSpacing->setMaximum(9999);
edLetterSpacing->setValue(100);
connect(edLetterSpacing, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdText](int value) {
connect(edLetterSpacing, &QSpinBox::valueChanged, this, [=](int value) {
QTextCharFormat fmt;
fmt.setFontLetterSpacing(value);
auto cursor = fdText->textCursor();
if(! cursor.hasSelection()) cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(fmt);
updImg();
MergeFmt(fdText, fmt);
});
hBox->addWidget(edLetterSpacing);
@ -274,7 +270,7 @@ QWidget* EText::attrWgt() {
auto edLineHeight = new QSpinBox;
edLineHeight->setRange(-999, 9999);
edLineHeight->setValue(100);
connect(edLineHeight, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this, fdText](int value) {
connect(edLineHeight, &QSpinBox::valueChanged, this, [=](int value) {
QTextBlockFormat fmt;
fmt.setLineHeight(value, QTextBlockFormat::ProportionalHeight);
auto cursor = fdText->textCursor();
@ -291,7 +287,7 @@ QWidget* EText::attrWgt() {
fdAlignH->addButton(wTextAlignHL, Qt::AlignLeft);
fdAlignH->addButton(wTextAlignHC, Qt::AlignHCenter);
fdAlignH->addButton(wTextAlignHR, Qt::AlignRight);
connect(fdAlignH, &QButtonGroup::idClicked, this, [this, fdText](int value) {
connect(fdAlignH, &QButtonGroup::idClicked, this, [=](int value) {
QTextBlockFormat fmt;
fmt.setAlignment((Qt::Alignment) value);
QTextCursor cursor = fdText->textCursor();
@ -328,7 +324,7 @@ QWidget* EText::attrWgt() {
fdText->setFrameShape(QFrame::NoFrame);
fdText->setAcceptRichText(false);
fdText->setHtml(text);
connect(fdText, &QTextEdit::textChanged, this, [this, fdText] {
connect(fdText, &QTextEdit::textChanged, this, [=] {
text = fdText->toHtml();
updImg();
});
@ -382,7 +378,7 @@ QWidget* EText::attrWgt() {
auto fdPageIdx = new QSpinBox();
fdPageIdx->setRange(1, mImgs.size());
connect(fdPageIdx, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int idx) {
connect(fdPageIdx, &QSpinBox::valueChanged, this, [this](int idx) {
curIdx = idx - 1;
update();
});
@ -515,7 +511,7 @@ QWidget* EText::attrWgt() {
auto edTailSpacing = new QSpinBox;
edTailSpacing->setRange(0, 9999);
edTailSpacing->setValue(tailSpacing);
connect(edTailSpacing, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(edTailSpacing, &QSpinBox::valueChanged, this, [this](int value) {
tailSpacing = value;
updImg();
});

View File

@ -214,7 +214,7 @@ QWidget* ETimer::attrWgt() {
auto fdFontSize = new QSpinBox();
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(this->font.pixelSize());
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdFontSize, &QSpinBox::valueChanged, this, [this](int value) {
this->font.setPixelSize(value);
update();
});

View File

@ -37,7 +37,7 @@ ETimer2::ETimer2(const JObj &json, EBase *multiWin) : EBase(multiWin) {
}
void ETimer2::init() {
mType = EBase::Timer2;
mType = EBase::TimerHtml;
doc.setDocumentMargin(0);
QFont font;
font.setFamily("Arial");
@ -133,7 +133,7 @@ QWidget* ETimer2::attrWgt() {
auto fdFontSize = new QSpinBox;
fdFontSize->setRange(4, 9999);
fdFontSize->setValue(16);
connect(fdFontSize, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, fdText, [fdText](int value) {
connect(fdFontSize, &QSpinBox::valueChanged, fdText, [fdText](int value) {
if(value <= 0) return;
QTextCharFormat fmt;
fmt.setProperty(QTextFormat::FontPixelSize, value);

View File

@ -13,7 +13,7 @@ public:
void init();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
int type() const override { return EBase::Timer2; }
int type() const override { return EBase::TimerHtml; }
QWidget* attrWgt() override;
JObj attrJson() const override;

View File

@ -11,6 +11,7 @@
#include <QSettings>
#include <QSpinBox>
#include <QPainter>
#include <QFileDialog>
EVideo *EVideo::create(const QString &file, PageListItem *pageItem, EBase *multiWin) {
int64_t dur;
@ -159,7 +160,7 @@ QWidget* EVideo::attrWgt() {
auto edPlayTimes = new QSpinBox;
edPlayTimes->setRange(1, 99999);
edPlayTimes->setValue(playTimes);
connect(edPlayTimes, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(edPlayTimes, &QSpinBox::valueChanged, this, [this](int value) {
playTimes = value;
});
hBox->addWidget(edPlayTimes);

View File

@ -67,7 +67,7 @@ QWidget* EWeb::attrWgt() {
auto fdZoom = new QSpinBox;
fdZoom->setRange(1, 99999);
fdZoom->setValue(zoom);
connect(fdZoom, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdZoom, &QSpinBox::valueChanged, this, [=](int value) {
zoom = value;
});
hBox->addWidget(fdZoom);
@ -83,7 +83,7 @@ QWidget* EWeb::attrWgt() {
auto edRefresh = new QSpinBox;
edRefresh->setRange(0, 99999);
edRefresh->setValue(refresh);
connect(edRefresh, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(edRefresh, &QSpinBox::valueChanged, this, [=](int value) {
refresh = value;
});
hBox->addWidget(edRefresh);
@ -99,7 +99,7 @@ QWidget* EWeb::attrWgt() {
auto fdX = new QSpinBox;
fdX->setRange(0, 99999);
fdX->setValue(_x);
connect(fdX, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdX, &QSpinBox::valueChanged, this, [=](int value) {
_x = value;
});
hBox->addWidget(fdX);
@ -110,7 +110,7 @@ QWidget* EWeb::attrWgt() {
auto fdY = new QSpinBox;
fdY->setRange(0, 99999);
fdY->setValue(_y);
connect(fdY, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdY, &QSpinBox::valueChanged, this, [=](int value) {
_y = value;
});
hBox->addWidget(fdY);
@ -125,7 +125,7 @@ QWidget* EWeb::attrWgt() {
auto fdScaleX = new QSpinBox;
fdScaleX->setRange(-9999, 99999);
fdScaleX->setValue(scaleX);
connect(fdScaleX, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdScaleX, &QSpinBox::valueChanged, this, [=](int value) {
scaleX = value;
});
hBox->addWidget(fdScaleX);
@ -136,7 +136,7 @@ QWidget* EWeb::attrWgt() {
auto fdScaleY = new QSpinBox;
fdScaleY->setRange(-9999, 99999);
fdScaleY->setValue(scaleY);
connect(fdScaleY, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
connect(fdScaleY, &QSpinBox::valueChanged, this, [=](int value) {
scaleY = value;
});
hBox->addWidget(fdScaleY);

View File

@ -11,8 +11,8 @@ public:
return holder;
}
explicit EWeb(EBase *multiWin = nullptr);
explicit EWeb(const JObj &json, EBase *multiWin = nullptr);
explicit EWeb(EBase *multiWin = 0);
explicit EWeb(const JObj &json, EBase *multiWin = 0);
int type() const override {return EBase::Web;}
void paint(QPainter*, const QStyleOptionGraphicsItem *, QWidget *) override;

View File

@ -4,6 +4,7 @@
#include "program/eenviron.h"
#include "program/evideo.h"
#include <QBuffer>
#include <QDir>
#include <QProcess>
#include <QMessageBox>
#include <QPainter>
@ -252,7 +253,7 @@ JArray GenTmpThread::genSources(QString type, const JArray &eles) {
source["isPreSplit"] = ele["isPreSplit"];
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=="Gif") source = genGif(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);
@ -374,7 +375,7 @@ JObj GenTmpThread::genText(const JValue &ele, JArray &sources) {
JObj GenTmpThread::genImage(const JValue &ele) {
auto widget = ele["widget"];
auto name = widget.isNull() ? ele["name"].toString() : widget["file"].toString();
auto srcFile = (widget.isNull() ? ele["dir"] : widget["path"]).toString() + "/" + name;
auto srcFile = srcPageDir + "/" + name;
QFileInfo srcInfo(srcFile);
JObj source;
if(! srcInfo.isFile()) return source;
@ -450,25 +451,23 @@ JObj GenTmpThread::genImage(const JValue &ele) {
source["timeSpan"] = play.isNull() ? ele["duration"] : play["playDuration"];
return source;
}
//转换图片
JObj GenTmpThread::convertGif(const JValue &json) {
auto widget = json["widget"];
auto path = widget["path"].toString();
auto name = widget["file"].toString();
QString srcFile = path + "/" + name;
JObj GenTmpThread::genGif(const JValue &ele) {
auto widget = ele["widget"];
auto name = widget.isNull() ? ele["name"].toString() : widget["file"].toString();
auto srcFile = srcPageDir + "/" + name;
QFileInfo srcInfo(srcFile);
if(! srcInfo.isFile()) return JObj();
auto id = Tools::fileMd5(srcFile);
if(id.isEmpty()) return JObj();
QFile::copy(srcFile, dstDir+"/"+id);
JObj oRes;
oRes["_type"] = "Image";
oRes["id"] = id;
oRes["md5"] = id;
oRes["fileExt"] = srcInfo.suffix().toLower();
auto play = json["play"];
oRes["timeSpan"] = (play.isNull() ? json["duration"] : play["playDuration"]).toInt() * play["playTimes"].toInt(1);
return oRes;
JObj source;
source["_type"] = "Image";
source["id"] = id;
source["md5"] = id;
source["fileExt"] = srcInfo.suffix().toLower();
auto play = ele["play"];
source["timeSpan"] = (play.isNull() ? ele["duration"] : play["playDuration"]).toInt() * play["playTimes"].toInt(1);
return source;
}
JObj GenTmpThread::convertDClock(const JValue &json){
JObj source;

View File

@ -18,7 +18,7 @@ protected:
JArray genSources(QString type, const JArray &eles);
JObj genText(const JValue &json, JArray &);
JObj genImage(const JValue &json);
JObj convertGif(const JValue &json);
JObj genGif(const JValue &json);
JObj convertDClock(const JValue &json);
JObj convertAClock(const JValue &json);
JObj convertWeb(const JValue &json);

View File

@ -122,21 +122,21 @@ void PageEditor::keyReleaseEvent(QKeyEvent *event) {
QList<EBase*> PageEditor::sortedEles() {
QList<EBase*> eles;
auto scene = graphicsView->scene();
if(nullptr == scene) return eles;
if(0 == scene) return eles;
auto items = scene->items(Qt::AscendingOrder);
foreach(auto item, items) {
auto ele = static_cast<EBase*>(item);
if(ele->mMultiWin == nullptr) eles.append(ele);
for(auto item : items) {
auto ele = (EBase*) item;
if(ele->mMultiWin == 0) eles.append(ele);
}
return eles;
}
EBase* PageEditor::getElementSelected(){
auto scene = graphicsView->scene();
if(nullptr == scene) return nullptr;
if(0 == scene) return 0;
auto selectedItems = scene->selectedItems();
if(selectedItems.count() != 1) return nullptr;
return static_cast<EBase*>(selectedItems.at(0));
if(selectedItems.count() != 1) return 0;
return (EBase*) selectedItems.at(0);
}
void PageEditor::onScale(int angle) {
@ -153,10 +153,9 @@ void PageEditor::onDelete() {
auto scene = graphicsView->scene();
if(0==scene) return;
auto selectedItems = scene->selectedItems();
if(selectedItems.count() == 0) return;
foreach(QGraphicsItem *selectedItem, selectedItems) if(selectedItem->type() >= QGraphicsItem::UserType) {
if(selectedItems.empty()) return;
for(auto selectedItem : selectedItems) if(selectedItem->type() >= QGraphicsItem::UserType) {
scene->removeItem(selectedItem);
static_cast<EBase*>(selectedItem)->freeFiles();
delete selectedItem;
}
auto eles = sortedEles();
@ -167,15 +166,15 @@ void PageEditor::onClean() {
auto res = QMessageBox::information(this, translate("","Tip"),tr("Clear all medias?"), QMessageBox::Ok, QMessageBox::Cancel);
if(res == QMessageBox::Ok) {
auto eles = sortedEles();
foreach(auto ele, eles) {
for(auto ele : eles) {
graphicsView->scene()->removeItem(ele);
delete ele;
}
}
}
void PageEditor::onLayerUp(){
EBase *element = getElementSelected();
if(nullptr == element) return;
auto element = getElementSelected();
if(0 == element) return;
QList<EBase*> list = sortedEles();
int n = list.count();
int o = static_cast<int>(element->zValue());

View File

@ -7,7 +7,6 @@
#include "program/ebase.h"
#include "program/edclock.h"
#include "program/eenviron.h"
#include "program/egif.h"
#include "program/emultiwin.h"
#include "program/ephoto.h"
#include "program/etext.h"
@ -43,8 +42,7 @@ PageListItem::PageListItem(const JObj &attr, const QString &pageDir) : mAttr(att
auto type = ele["elementType"].toStr();
EBase *element = 0;
if(type=="Text") element = new EText(ele.toObj());
else if(type=="Image"||type=="Photo") element = EPhoto::create(ele.toObj(), this);
else if(type=="Gif") element = EGif::create(ele.toObj(), this);
else if(type=="Image"||type=="Photo"||type=="Gif") element = EPhoto::create(ele.toObj(), this);
else if(type=="Video"||type=="Movie") element = EVideo::create(ele.toObj(), this);
else if(type=="DClock") element = new EDClock(ele.toObj());
else if(type=="AClock") element = new EAClock(ele.toObj());
@ -245,7 +243,7 @@ QPushButton[ssName="weeklySelector"]:checked {
auto fdPlayTimes = new QSpinBox();
fdPlayTimes->setRange(1, 9999);
fdPlayTimes->setValue(mAttr["repeat"].toInt());
connect(fdPlayTimes, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [this](int value) {
connect(fdPlayTimes, &QSpinBox::valueChanged, this, [this](int value) {
mAttr["repeat"] = value;
this->fdPlayTimes->setText(QString::number(value));
});

View File

@ -1,21 +1,20 @@
#include "progeditorwin.h"
#include "ebase.h"
#include "main.h"
#include "pagelistitem.h"
#include "player/playwin.h"
#include "tools.h"
#include "main.h"
#include "gutil/qwaitingdlg.h"
#include "program/ebase.h"
#include "program/etext.h"
#include "program/ephoto.h"
#include "program/evideo.h"
#include "program/egif.h"
#include "program/edclock.h"
#include "program/eaclock.h"
#include "program/eenviron.h"
#include "program/eweb.h"
#include "program/etimer.h"
#include "program/etimer2.h"
#include "program/etable.h"
#include "program/emultiwin.h"
#include "program/gentmpthread.h"
#include "program/sendprogramdialog.h"
@ -26,7 +25,7 @@
#include <QSettings>
#include <QToolBar>
#include <QUdpSocket>
#include <QMovie>
#include <QFileDialog>
ProgItem *gProgItem = 0;
@ -159,7 +158,7 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
toolBar->addSeparator();
if(progItem->partLens.empty()) {
action = new QAction(QIcon(":/res/program/Window.png"), tr("MuliContentWindow"));
action = new QAction(QIcon(":/res/program/Window.png"), tr("General Window"));
action->setToolTip(tr("In this window, a plurality of different program materials can be added and played according to the order of joining the list;"));
action->setData(EBase::Window);
toolBar->addAction(action);
@ -174,9 +173,6 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
action = new QAction(QIcon(":/res/program/Movie.png"), tr("Video"));
action->setData(EBase::Video);
toolBar->addAction(action);
action = new QAction(QIcon(":/res/program/Gif.png"), tr("Gif"));
action->setData(EBase::Gif);
toolBar->addAction(action);
action = new QAction(QIcon(":/res/program/DClock.png"), tr("Clock"));
action->setData(EBase::DClock);
toolBar->addAction(action);
@ -191,10 +187,21 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
toolBar->addAction(action);
action = new QAction(QIcon(":/res/program/Timer.png"), tr("Timer"));
action->setData(EBase::Timer);
auto menu = new QMenu;
action->setMenu(menu);
toolBar->addAction(action);
action = new QAction(QIcon(":/res/program/Timer.png"), tr("Timer")+"2");
action->setData(EBase::Timer2);
action = new QAction(QIcon(":/res/program/Timer.png"), tr("Timer")+" (HTML)");
action->setData(EBase::TimerHtml);
menu->addAction(action);
action = new QAction(QIcon(":/res/program/Table.png"), tr("Table"));
action->setData(EBase::Table);
menu = new QMenu;
action->setMenu(menu);
toolBar->addAction(action);
action = new QAction(QIcon(":/res/program/Table.png"), tr("Import"));
action->setData(EBase::Table);
menu->addAction(action);
#ifndef leyide
action = new QAction(QIcon(":/res/program/demo-video.png"), tr("Demos"));
connect(action, &QAction::triggered, this, [this] {
@ -203,9 +210,16 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
auto scene = mPageEditor->graphicsView->scene();
if(scene==0) return;
if(file.endsWith("png", Qt::CaseInsensitive)) {
auto ePhoto = EPhoto::create(file, mPageItem);
if(ePhoto==0) return;
auto rect = Tools::centerRect(ePhoto->img.width(), ePhoto->img.height(), mProgItem->mWidth, mProgItem->mHeight);
QImageReader reader(file);
reader.setAutoTransform(true);
auto img = reader.read();
if(img.isNull()) {
QMessageBox::critical(this, "Image Error", ImgErrStr(reader.error())+": "+reader.errorString()+"\n"+file);
return;
}
QFileInfo info(file);
auto ePhoto = new EPhoto(reader, img, info.absolutePath(), info.fileName(), JObj());
auto rect = CenterRect(img.width(), img.height(), mProgItem->mWidth, mProgItem->mHeight);
ePhoto->setPos(rect.topLeft());
ePhoto->setSize(rect.width(), rect.height());
ePhoto->setZValue(mPageEditor->sortedEles().count());
@ -216,7 +230,7 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
} else {
auto eVideo = EVideo::create(file, mPageItem);
if(eVideo==0) return;
auto rect = Tools::centerRect(eVideo->mCoverImg.width(), eVideo->mCoverImg.height(), mProgItem->mWidth, mProgItem->mHeight);
auto rect = CenterRect(eVideo->mCoverImg.width(), eVideo->mCoverImg.height(), mProgItem->mWidth, mProgItem->mHeight);
eVideo->setPos(rect.topLeft());
eVideo->setSize(rect.width(), rect.height());
eVideo->setZValue(mPageEditor->sortedEles().count());
@ -297,44 +311,34 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
if(type==EBase::Image) {
auto files = QFileDialog::getOpenFileNames(this, translate("","Select File"), gFileHome, EPhoto::filters());
for(int i=0; i<files.count(); i++) {
auto ePhoto = EPhoto::create(files[i], mPageItem);
if(ePhoto==0) continue;
auto rect = Tools::centerRect(ePhoto->img.width(), ePhoto->img.height(), mProgItem->mWidth, mProgItem->mHeight);
ePhoto->setPos(rect.topLeft());
QImageReader reader(files[i]);
reader.setAutoTransform(true);
auto img = reader.read();
if(img.isNull()) {
QMessageBox::critical(this, "Image Error", ImgErrStr(reader.error())+": "+reader.errorString()+"\n"+files[i]);
continue;
}
QFileInfo info(files[i]);
auto path = info.absolutePath();
auto rect = CenterRect(img.width(), img.height(), mProgItem->mWidth, mProgItem->mHeight);
auto ePhoto = new EPhoto(reader, img, path, info.fileName(), JObj());
ePhoto->setSize(rect.width(), rect.height());
ePhoto->setPos(rect.topLeft());
ePhoto->setZValue(order++);
scene->addItem(ePhoto);
if(i==files.count()-1) {
auto sels = scene->selectedItems();
if(sels.count() == 1) sels.at(0)->setSelected(false);
ePhoto->setSelected(true);
gFileHome = ePhoto->mDir;
}
}
} else if(type==EBase::Gif) {
auto files = QFileDialog::getOpenFileNames(this, translate("","Select File"), gFileHome, EGif::filters());
for(int i=0; i<files.count(); i++) {
auto eGif = EGif::create(files[i], mPageItem);
if(eGif==0) continue;
auto img = eGif->mMovie->currentPixmap();
auto rect = Tools::centerRect(img.width(), img.height(), mProgItem->mWidth, mProgItem->mHeight);
eGif->setPos(rect.topLeft());
eGif->setSize(rect.width(), rect.height());
eGif->setZValue(order++);
scene->addItem(eGif);
if(i == files.count()-1) {
auto sels = scene->selectedItems();
if(sels.count() == 1) sels.at(0)->setSelected(false);
eGif->setSelected(true);
gFileHome = eGif->mDir;
ePhoto->setSelected(true);
gFileHome = path;
}
}
} else if(type==EBase::Video) {
auto file = QFileDialog::getOpenFileName(this, translate("","Select File"), gFileHome, EVideo::filters());
if(file.isEmpty()) return;
auto eVideo = EVideo::create(file, mPageItem);
if(eVideo==nullptr) return;
auto rect = Tools::centerRect(eVideo->mCoverImg.width(), eVideo->mCoverImg.height(), mProgItem->mWidth, mProgItem->mHeight);
if(eVideo==0) return;
auto rect = CenterRect(eVideo->mCoverImg.width(), eVideo->mCoverImg.height(), mProgItem->mWidth, mProgItem->mHeight);
eVideo->setPos(rect.topLeft());
eVideo->setSize(rect.width(), rect.height());
gFileHome = eVideo->mRawDir;
@ -354,8 +358,9 @@ ProgEditorWin::ProgEditorWin(ProgItem *progItem, QWidget *parent) : QWidget(pare
element = new EWeb;
element->setSize(mProgItem->mWidth, mProgItem->mHeight);
} else if(type==EBase::Timer) element = new ETimer;
else if(type==EBase::Timer2) element = new ETimer2;
else if(type==EBase::TimerHtml) element = new ETimer2;
else if(type==EBase::Window) element = new EMultiWin(mPageItem);
else if(type==EBase::Table) element = new ETable;
if(element) {
if(element->mWidth==0) {
element->setPos(mNewEleX, mNewEleY);
@ -590,12 +595,6 @@ void ProgEditorWin::closeEvent(QCloseEvent *event) {
//停止每个页面元素的播放,将节目目录下的每个页面的文件夹另命名
bool ProgEditorWin::save() {
auto rtn = true;
//停止每个幻灯片的元素
int cnt = listPage->count();
for(int i=0; i<cnt; i++) {
auto items = ((PageListItem*) listPage->item(i))->mScene->items();
for(auto item : items) ((EBase*) item)->freeFiles();
}
QDir progDir(mProgItem->mProgDir);
if(! progDir.exists() && ! progDir.mkdir(mProgItem->mProgDir)) {
QMessageBox::critical(this, translate("","Error"), tr("Failed to Create Forder")+": "+mProgItem->mProgDir);
@ -608,7 +607,7 @@ bool ProgEditorWin::save() {
}
//保存每个页面的元素和页面属性到page.json文档
mPageJsons.clear();
for(int i=0; i<cnt; i++) {
for(int i=0; i<listPage->count(); i++) {
auto page = (PageListItem*) listPage->item(i);
page->mAttr["order"] = i;
if(page->saveFiles()) {
@ -624,10 +623,6 @@ bool ProgEditorWin::save() {
QMessageBox::critical(this, translate("","Error"), tr("Failed to Remove Recursively")+" "+pageName);
}
}
for(int i=0; i<cnt; i++) {
auto items = static_cast<PageListItem*>(listPage->item(i))->mScene->items();
for(auto item : items) static_cast<EBase*>(item)->loadFiles();
}
return rtn;
}

View File

@ -88,7 +88,7 @@ QPushButton:hover{background-color: #cccccc;}
QObject::connect(btnBox, &QDialogButtonBox::accepted, &dlg, [=, &dlg] {
auto selects = fdDrives->selectedItems();
if(selects.count() > 0) {
foreach(auto select, selects) {
for(auto select : selects) {
auto strPath = select->data(Qt::UserRole).toString();
auto waitingDlg = new WaitingDlg(&dlg, QObject::tr("Convertering")+" ...");
auto gen = new GenTmpThread(this, mName, strPath + (strPath.endsWith('/') ? "program.zip" : "/program.zip"), fdPassword->text());
@ -109,7 +109,7 @@ QPushButton:hover{background-color: #cccccc;}
fdDrives->clear();
auto volumes = QStorageInfo::mountedVolumes();
foreach(auto volume, volumes) {
for(auto &volume : volumes) {
auto text = volume.displayName();
auto rootPath = volume.rootPath();
if(text!=rootPath) text += " ("+rootPath+")";

View File

@ -60,7 +60,6 @@
<file>res/program/Cut.png</file>
<file>res/program/DClock.png</file>
<file>res/program/Delete.png</file>
<file>res/program/Gif.png</file>
<file>res/program/GoDown.png</file>
<file>res/program/GoUp.png</file>
<file>res/program/LayerBottom.png</file>
@ -78,6 +77,7 @@
<file>res/program/ScaleUp.png</file>
<file>res/program/Send.png</file>
<file>res/program/Setting.png</file>
<file>res/program/Table.png</file>
<file>res/program/Temp.png</file>
<file>res/program/Text.png</file>
<file>res/program/TextAlignHC.png</file>

View File

Before

Width:  |  Height:  |  Size: 887 B

After

Width:  |  Height:  |  Size: 887 B

View File

@ -1,38 +1,8 @@
#include "tools.h"
#include <QBuffer>
#include <QJsonArray>
#include <QFile>
#include <QPainter>
QRect Tools::centerRect(qreal width, qreal height, int maxW, int maxH) {
if(maxW < width || maxH < height) {
auto rate = qMin(maxW / width, maxH / height);
width *= rate;
height *= rate;
}
return QRect((maxW - width) / 2, (maxH - height) / 2, width, height);
}
QString Tools::addSufix(QString path) {
int i = path.lastIndexOf('.');
QString prefix = path, sufix;
if(i > 0 && i > path.lastIndexOf('/')+1 && i >= path.length()-9) {
prefix = path.left(i);
sufix = path.mid(i);
}
i = 1;
while(QFileInfo::exists(path = prefix+QString::number(i)+sufix)) i++;
return path;
}
QString Tools::readErrStr(QImageReader::ImageReaderError err) {
if(err==QImageReader::UnknownError) return "UnknownError";
if(err==QImageReader::FileNotFoundError) return "FileNotFoundError";
if(err==QImageReader::DeviceError) return "DeviceError";
if(err==QImageReader::UnsupportedFormatError) return "UnsupportedFormatError";
if(err==QImageReader::InvalidDataError) return "InvalidDataError";
return QString::number(err);
}
QString Tools::fileMd5(QString filePath) {
QFile file(filePath);
if(! file.open(QFile::ReadOnly)) return QString();
@ -132,10 +102,6 @@ void Tools::saveImg2(const QString& dir, const QFontMetrics& metric, const QFont
QBrush Tools::getBrush(const QColor& color) {
return color.alpha()==0 ? Qt::NoBrush : QBrush(color);
}
int Tools::color2Int(const QColor& color) {
return color.red() << 24 | color.green() << 16 | color.blue() << 8 | color.alpha();
}
QColor Tools::int2Color(int value) {
return QColor((value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff);
}

View File

@ -5,11 +5,6 @@
#include <QApplication>
#include <QBrush>
#include <QColor>
#include <QTimer>
#include <QPushButton>
#include <QFileDialog>
#include <QImageReader>
#include <QTextEdit>
#include <QNetworkAccessManager>
class Tools : public QObject {
@ -19,15 +14,11 @@ public:
static QNetworkAccessManager manager;
return manager;
};
static QRect centerRect(qreal, qreal, int, int);
static QString addSufix(QString);
static QString readErrStr(QImageReader::ImageReaderError);
static QString fileMd5(QString);
static QString saveImg(const QString&, const QFontMetrics&, const QFont&, const QColor&, const QString&);
static void saveImg(const QString&, const QFontMetrics&, const QFont&, const QColor&, JObj&, const QString&, const QString&);
static void saveImg2(const QString&, const QFontMetrics&, const QFont&, const QColor&, JArray&, const QString&, const QString&, int = 0);
static QColor int2Color(int value);
static int color2Int(const QColor& color);
static QBrush getBrush(const QColor& color);
static QString selectStr(bool f, const QString &s0, const QString &s1 = "");
};

View File

@ -5169,8 +5169,8 @@
</message>
<message>
<location filename="../program/progeditorwin.cpp" line="162"/>
<source>MuliContentWindow</source>
<translation>Multi material window</translation>
<source>General Window</source>
<translation></translation>
</message>
<message>
<location filename="../program/progeditorwin.cpp" line="163"/>

View File

@ -5172,7 +5172,7 @@
</message>
<message>
<location filename="../program/progeditorwin.cpp" line="162"/>
<source>MuliContentWindow</source>
<source>General Window</source>
<translation></translation>
</message>
<message>

View File

@ -5173,8 +5173,8 @@
</message>
<message>
<location filename="../program/progeditorwin.cpp" line="162"/>
<source>MuliContentWindow</source>
<translation>Janela para varias midias</translation>
<source>General Window</source>
<translation></translation>
</message>
<message>
<location filename="../program/progeditorwin.cpp" line="163"/>

View File

@ -5169,7 +5169,7 @@
</message>
<message>
<location filename="../program/progeditorwin.cpp" line="162"/>
<source>MuliContentWindow</source>
<source>General Window</source>
<translation></translation>
</message>
<message>

View File

@ -5173,7 +5173,7 @@
</message>
<message>
<location filename="../program/progeditorwin.cpp" line="162"/>
<source>MuliContentWindow</source>
<source>General Window</source>
<translation></translation>
</message>
<message>