彻底改版2.0
This commit is contained in:
78
tool/pngtool/frmpngtool.cpp
Normal file
78
tool/pngtool/frmpngtool.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#pragma execution_character_set("utf-8")
|
||||
#include "frmpngtool.h"
|
||||
#include "ui_frmpngtool.h"
|
||||
#include "qfile.h"
|
||||
#include "qfiledialog.h"
|
||||
#include "qdatetime.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
#define TIMEMS QTime::currentTime().toString("hh:mm:ss zzz")
|
||||
|
||||
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();
|
||||
if (!currentFile.isEmpty()) {
|
||||
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);
|
||||
|
||||
ui->txtMain->clear();
|
||||
int count = 0;
|
||||
foreach (QString file, files) {
|
||||
ui->txtMain->append(QString("%1 -> %2").arg(TIMEMS).arg(file));
|
||||
QImage image(file);
|
||||
image.save(file, "png");
|
||||
count++;
|
||||
ui->progress->setValue(count);
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
ui->txtMain->append(QString("%1 -> 处理完成, 共 %2 个文件").arg(TIMEMS).arg(files.count()));
|
||||
}
|
||||
28
tool/pngtool/frmpngtool.h
Normal file
28
tool/pngtool/frmpngtool.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef FRMPNGTOOL_H
|
||||
#define FRMPNGTOOL_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class frmPngTool;
|
||||
}
|
||||
|
||||
class frmPngTool : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmPngTool(QWidget *parent = 0);
|
||||
~frmPngTool();
|
||||
|
||||
private slots:
|
||||
void on_btnFile_clicked();
|
||||
void on_btnDir_clicked();
|
||||
void on_btnOk_clicked();
|
||||
|
||||
private:
|
||||
Ui::frmPngTool *ui;
|
||||
QStringList files;
|
||||
};
|
||||
|
||||
#endif // FRMPNGTOOL_H
|
||||
61
tool/pngtool/frmpngtool.ui
Normal file
61
tool/pngtool/frmpngtool.ui
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmPngTool</class>
|
||||
<widget class="QWidget" name="frmPngTool">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="txtFile"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="btnOk">
|
||||
<property name="text">
|
||||
<string>执行转换</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="txtDir"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="btnDir">
|
||||
<property name="text">
|
||||
<string>选择目录</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="btnFile">
|
||||
<property name="text">
|
||||
<string>选择文件</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QProgressBar" name="progress">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QTextEdit" name="txtMain"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
31
tool/pngtool/main.cpp
Normal file
31
tool/pngtool/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
#include "frmpngtool.h"
|
||||
#include <QApplication>
|
||||
#include <QTextCodec>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setFont(QFont("Microsoft Yahei", 9));
|
||||
|
||||
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
|
||||
#if _MSC_VER
|
||||
QTextCodec *codec = QTextCodec::codecForName("gbk");
|
||||
#else
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
#endif
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
QTextCodec::setCodecForCStrings(codec);
|
||||
QTextCodec::setCodecForTr(codec);
|
||||
#else
|
||||
QTextCodec *codec = QTextCodec::codecForName("utf-8");
|
||||
QTextCodec::setCodecForLocale(codec);
|
||||
#endif
|
||||
|
||||
frmPngTool w;
|
||||
w.setWindowTitle("PNG图片警告去除工具");
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
14
tool/pngtool/pngtool.pro
Normal file
14
tool/pngtool/pngtool.pro
Normal file
@@ -0,0 +1,14 @@
|
||||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
|
||||
|
||||
TARGET = pngtool
|
||||
TEMPLATE = app
|
||||
DESTDIR = $$PWD/../bin
|
||||
CONFIG += warn_off
|
||||
|
||||
SOURCES += main.cpp
|
||||
SOURCES += frmpngtool.cpp
|
||||
HEADERS += frmpngtool.h
|
||||
FORMS += frmpngtool.ui
|
||||
|
||||
Reference in New Issue
Block a user