qt_demoe/tool/pngtool/frmpngtool.cpp

79 lines
2.0 KiB
C++
Raw Normal View History

2021-03-08 01:04:13 +00:00
#pragma execution_character_set("utf-8")
#include "frmpngtool.h"
2019-10-13 02:15:27 +00:00
#include "ui_frmpngtool.h"
#include "qfile.h"
#include "qfiledialog.h"
2021-03-09 01:56:41 +00:00
#include "qdatetime.h"
2019-10-13 02:15:27 +00:00
#include "qdebug.h"
2021-03-09 01:56:41 +00:00
#define TIMEMS QTime::currentTime().toString("hh:mm:ss zzz")
2019-10-13 02:15:27 +00:00
frmPngTool::frmPngTool(QWidget *parent) : QWidget(parent), ui(new Ui::frmPngTool)
{
ui->setupUi(this);
ui->progress->setRange(0, 0);
ui->progress->setValue(0);
}
frmPngTool::~frmPngTool()
{
delete ui;
}
void frmPngTool::on_btnFile_clicked()
{
QString file = QFileDialog::getOpenFileName(this, "选择png文件", qApp->applicationDirPath(), "png图片文件(*.png)");
if (!file.isEmpty()) {
ui->txtFile->setText(file);
ui->progress->setValue(0);
}
}
void frmPngTool::on_btnDir_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, "选择目录");
if (!dir.isEmpty()) {
ui->txtDir->setText(dir);
ui->progress->setValue(0);
}
}
void frmPngTool::on_btnOk_clicked()
{
files.clear();
//将单个文件加入队列
QString currentFile = ui->txtFile->text().trimmed();
2021-03-08 01:04:13 +00:00
if (!currentFile.isEmpty()) {
2019-10-13 02:15:27 +00:00
files.append(currentFile);
}
//将该目录下的所有png文件存入链表
QString currentDir = ui->txtDir->text().trimmed();
if (!currentDir.isEmpty()) {
QDir imagePath(currentDir);
QStringList filter;
filter << "*.png";
QStringList list = imagePath.entryList(filter);
foreach (QString str, list) {
files.append(currentDir + "/" + str);
}
}
ui->progress->setRange(0, files.count());
ui->progress->setValue(0);
2021-03-08 01:04:13 +00:00
ui->txtMain->clear();
2019-10-13 02:15:27 +00:00
int count = 0;
foreach (QString file, files) {
2021-03-09 01:56:41 +00:00
ui->txtMain->append(QString("%1 -> %2").arg(TIMEMS).arg(file));
2019-10-13 02:15:27 +00:00
QImage image(file);
image.save(file, "png");
count++;
ui->progress->setValue(count);
qApp->processEvents();
}
2021-03-09 01:56:41 +00:00
ui->txtMain->append(QString("%1 -> 处理完成, 共 %2 个文件").arg(TIMEMS).arg(files.count()));
2019-10-13 02:15:27 +00:00
}