Merge branch 'master-webassembly' of https://gitlab.com/portfolio91/namecreater into master-webassembly

# Conflicts:
#	NameCreater/NameCreater.pro.user
#	NameCreater/customlogo2.cpp
This commit is contained in:
shouchih_chen 2024-09-20 12:54:50 +08:00
commit 1405d54f33
10 changed files with 89 additions and 134 deletions

View File

@ -35,21 +35,30 @@ void INameCreater::saveToImage(const QString& filename, QGraphicsScene* scene)
QPainter painter(&image); QPainter painter(&image);
scene->render(&painter); scene->render(&painter);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QString folder_name = QCoreApplication::applicationDirPath() + "/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd"); QString folder_name = QCoreApplication::applicationDirPath() + "/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
qDebug() << "app director path" <<QCoreApplication::applicationDirPath();
#else #else
QString folder_name = QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd"); QString folder_name = "./";//QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#endif #endif
image.save(filename, "JPEG"); QString savePath = folder_name.append(filename);
#ifdef Q_OS_WASM
QByteArray imageData; QByteArray imageData;
QBuffer buffer(&imageData); QBuffer buffer(&imageData);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
QPixmap pixmap = QPixmap::fromImage(image); QPixmap pixmap = QPixmap::fromImage(image);
pixmap.save(&buffer, "JPEG", 100); // You can also use other formats like "JPEG" or "BMP" pixmap.save(&buffer, "JPEG", 100); // You can also use other formats like "JPEG" or "BMP"
QFileDialog::saveFileContent(imageData, filename); QFileDialog::saveFileContent(imageData, savePath);
#else
qDebug()<<"image save path:" << savePath;
image.save(savePath, "JPEG");
#endif
} }

View File

@ -34,9 +34,9 @@ public:
QFont EnglisthFont() const { QFont EnglisthFont() const {
return eng_Font; return eng_Font;
} }
protected:
void saveToImage(const QString& filename, QGraphicsScene* scene); void saveToImage(const QString& filename, QGraphicsScene* scene);
protected:
QList<NameInfo_t> getNameByFile(Name_Type_e type, const QString& filename); QList<NameInfo_t> getNameByFile(Name_Type_e type, const QString& filename);
QList<NameInfo_t> getNameByFileContent(Name_Type_e type, const QByteArray& conetent); QList<NameInfo_t> getNameByFileContent(Name_Type_e type, const QByteArray& conetent);

View File

@ -122,11 +122,29 @@ void NameCreater::loadFont(const QByteArray& fontdata){
void NameCreater::OnClickedReadBtn() { void NameCreater::OnClickedReadBtn() {
auto sender =(QPushButton*) QObject::sender(); auto sender =(QPushButton*) QObject::sender();
#ifdef Q_OS_WASM
auto fileContentReady = [this, sender](const QString &fileName, const QByteArray &fileContent) { auto fileContentReady = [this, sender](const QString &fileName, const QByteArray &fileContent) {
if (fileName.isEmpty()) { if (!fileName.isEmpty()) {
// No file was selected this->execCreater(sender, fileName, fileContent);
} }
else {
};
QFileDialog::getOpenFileContent("CSV (*.csv)", fileContentReady);
#else
QString filename = QFileDialog::getOpenFileName(nullptr,"Open Name File", QDir::currentPath(),"CSV file(*.csv)");
if(!filename.isEmpty()){
QFile _f(filename);
if(_f.open(QIODevice::ReadOnly)){
execCreater(sender, filename, _f.readAll());
}
}
#endif
}
void NameCreater::execCreater(QObject* sender, const QString& fileName, const QByteArray& fileContent) {
// Use fileName and fileContent // Use fileName and fileContent
if(sender == ui.fivesingle_btn) FiveToSingle().generaImageFromCSV(Name_Type_e::Name_zh,fileName, fileContent, this->font, this->font_color); if(sender == ui.fivesingle_btn) FiveToSingle().generaImageFromCSV(Name_Type_e::Name_zh,fileName, fileContent, this->font, this->font_color);
@ -156,9 +174,6 @@ void NameCreater::OnClickedReadBtn() {
return; return;
} }
}
};
QFileDialog::getOpenFileContent("CSV (*.csv)", fileContentReady);
} }
void NameCreater::OnClickedCustomLogoBtn() { void NameCreater::OnClickedCustomLogoBtn() {

View File

@ -25,6 +25,7 @@ private:
QNetworkAccessManager network_mgr; QNetworkAccessManager network_mgr;
void loadFont(const QByteArray& fontdata); void loadFont(const QByteArray& fontdata);
void execCreater(QObject*sender, const QString&fileName, const QByteArray &fileContent);
private Q_SLOTS: private Q_SLOTS:
void OnClickedReadBtn(); void OnClickedReadBtn();

View File

@ -21,6 +21,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
wasm-emscripten{ wasm-emscripten{
QMAKE_LFLAGS+= -s TOTAL_MEMORY=67108864 QMAKE_LFLAGS+= -s TOTAL_MEMORY=67108864
QMAKE_LFLAGS += -s ALLOW_MEMORY_GROWTH=1
} }
#QMAKE_LFLAGS += -s ALLOW_MEMORY_GROWTH=1

View File

@ -2,6 +2,7 @@
#include "ui_customlogo.h" #include "ui_customlogo.h"
#include "QFileDialog" #include "QFileDialog"
#include <QMessageBox> #include <QMessageBox>
#include <QDateTime> #include <QDateTime>
#include <QTextCodec> #include <QTextCodec>
@ -55,10 +56,7 @@ void CustomLogo::loadBGFromFile()
}else{ }else{
qDebug()<<"Data content not image format"; qDebug()<<"Data content not image format";
} }
} }
}; };
QFileDialog::getOpenFileContent("Image (*.jpg)", fileContentReady); QFileDialog::getOpenFileContent("Image (*.jpg)", fileContentReady);
@ -125,7 +123,6 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
QString name = name_info.name1; QString name = name_info.name1;
int name_len = name.length(); int name_len = name.length();
for (int j = 0; j < 1; j++) { // never reverse for (int j = 0; j < 1; j++) { // never reverse
int pos_idx = idx * 2 + j;
qreal xscale, yscale; qreal xscale, yscale;
xscale = yscale = (j == 1) ? -1 : 1; xscale = yscale = (j == 1) ? -1 : 1;
@ -155,7 +152,8 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
if (is_export_page || n == nameList.count() - 1) { if (is_export_page || n == nameList.count() - 1) {
QString date_str = QDateTime::currentDateTime().toString("MMddhhmm"); QString date_str = QDateTime::currentDateTime().toString("MMddhhmm");
QString file_name = QString("Signal_%2_%1.jpg").arg(QString::number(export_times + 1), date_str); QString file_name = QString("Signal_%2_%1.jpg").arg(QString::number(export_times + 1), date_str);
saveToImage(file_name, &scene); //saveToImage(file_name, &scene);
INameCreater().saveToImage(file_name, &scene);
export_times++; export_times++;
scene.clear(); scene.clear();
@ -231,35 +229,3 @@ void CustomLogo::onClickedBtn() {
} }
void CustomLogo::saveToImage(const QString& filename, QGraphicsScene* scene)
{
scene->clearSelection(); // Selections would also render to the file
scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
image.fill(Qt::transparent); // Start all pixels transparent
int dpm = 300 / 0.0254; // ~300 DPI
image.setDotsPerMeterX(dpm);
image.setDotsPerMeterY(dpm);
QPainter painter(&image);
scene->render(&painter);
#ifdef Q_OS_MAC
QString folder_name = QCoreApplication::applicationDirPath() + "/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#else
QString folder_name = QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#endif
image.save(filename, "JPEG");
QByteArray imageData;
QBuffer buffer(&imageData);
buffer.open(QIODevice::WriteOnly);
QPixmap pixmap = QPixmap::fromImage(image);
pixmap.save(&buffer, "JPEG", 100); // You can also use other formats like "JPEG" or "BMP"
QFileDialog::saveFileContent(imageData, filename);
}

View File

@ -2,8 +2,8 @@
#define CUSTOMLOGO_H #define CUSTOMLOGO_H
#include <QDialog> #include <QDialog>
#include "INameCreater.h"
#include "QFont" #include "QFont"
#include "INameCreater.h"
namespace Ui { namespace Ui {
class CustomLogo; class CustomLogo;
@ -24,7 +24,6 @@ private:
void loadBGFromFile(); void loadBGFromFile();
void loadListFromFile(); void loadListFromFile();
void gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Type_e type); void gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Type_e type);
void saveToImage(const QString& filename, QGraphicsScene* scene);
protected: protected:
QList<NameInfo_t> getNameByFileContent(Name_Type_e type, const QByteArray& conetent); QList<NameInfo_t> getNameByFileContent(Name_Type_e type, const QByteArray& conetent);

View File

@ -215,7 +215,7 @@ void customlogo2::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_T
if (is_export_page || n == nameList.count() - 1) { if (is_export_page || n == nameList.count() - 1) {
QString date_str = QDateTime::currentDateTime().toString("MMddhhmm"); QString date_str = QDateTime::currentDateTime().toString("MMddhhmm");
QString file_name = QString("Signal_%2_%1.jpg").arg(QString::number(export_times + 1), date_str); QString file_name = QString("Signal_%2_%1.jpg").arg(QString::number(export_times + 1), date_str);
saveToImage(file_name, &scene); INameCreater().saveToImage(file_name, &scene);
export_times++; export_times++;
scene.clear(); scene.clear();
@ -233,39 +233,3 @@ void customlogo2::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_T
msgBox.exec(); msgBox.exec();
} }
void customlogo2::saveToImage(const QString& filename, QGraphicsScene* scene)
{
scene->clearSelection(); // Selections would also render to the file
scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
image.fill(Qt::transparent); // Start all pixels transparent
int dpm = 300 / 0.0254; // ~300 DPI
image.setDotsPerMeterX(dpm);
image.setDotsPerMeterY(dpm);
QPainter painter(&image);
scene->render(&painter);
#ifdef Q_OS_MAC
QString folder_name = QCoreApplication::applicationDirPath() + "/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
qDebug() << "app director path" <<QCoreApplication::applicationDirPath();
#else
QString folder_name = QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#endif
image.save(folder_name.append(filename), "JPEG");
QByteArray imageData;
QBuffer buffer(&imageData);
buffer.open(QIODevice::WriteOnly);
QPixmap pixmap = QPixmap::fromImage(image);
pixmap.save(&buffer, "JPEG", 100); // You can also use other formats like "JPEG" or "BMP"
QFileDialog::saveFileContent(imageData, filename);
}

View File

@ -24,7 +24,7 @@ private:
void loadListFromFile(); void loadListFromFile();
void gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Type_e type); void gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Type_e type);
void saveToImage(const QString& filename, QGraphicsScene* scene);
protected: protected:
QList<NameInfo_t> getNameByFileContent(Name_Type_e type, const QByteArray& conetent); QList<NameInfo_t> getNameByFileContent(Name_Type_e type, const QByteArray& conetent);

View File

@ -1,6 +1,6 @@
#ifndef DEF_H #ifndef DEF_H
#define DEF_H #define DEF_H
#define VERSION "v2.8.0" #define VERSION "v2.8.1"
#endif // DEF_H #endif // DEF_H