|
|
@ -325,45 +325,17 @@ void buildCheckWidget::buildForIcon(){
|
|
|
|
m_iconIndex.close();
|
|
|
|
m_iconIndex.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//处理svg转png,获取svg文件
|
|
|
|
//mimetype写入icon index.theme文件
|
|
|
|
QString m_buildAppIconPath = QDir::homePath() + "/.cache/theme-build/" + FileProcess::g_date + "/src/iconTheme/appicon/";
|
|
|
|
|
|
|
|
QString m_buildSystemIconPath = QDir::homePath() + "/.cache/theme-build/" + FileProcess::g_date + "/src/iconTheme/systemicon/";
|
|
|
|
|
|
|
|
QDir m_buildAppIconDir = m_buildAppIconPath;
|
|
|
|
|
|
|
|
QDir m_buildSystemIconDir = m_buildSystemIconPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置过滤器,仅获取 .svg 文件
|
|
|
|
|
|
|
|
QStringList m_appIconNameFilters;
|
|
|
|
|
|
|
|
m_appIconNameFilters << "*.svg";
|
|
|
|
|
|
|
|
m_buildAppIconDir.setNameFilters(m_appIconNameFilters);
|
|
|
|
|
|
|
|
QStringList m_systemIconNameFilters;
|
|
|
|
|
|
|
|
m_systemIconNameFilters << "*.svg";
|
|
|
|
|
|
|
|
m_buildSystemIconDir.setNameFilters(m_systemIconNameFilters);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 拷贝mimetypes文件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString m_iconThemeScalablePath = m_buildIconThemePath + "/scalable";
|
|
|
|
|
|
|
|
QString m_iconThemeScalableMimePath = m_iconThemeScalablePath + "/mimetypes";
|
|
|
|
|
|
|
|
QDir m_buildSystemIcondirDir = m_iconThemeScalablePath;
|
|
|
|
|
|
|
|
QDir m_iconThemeScalableMimeDir = m_iconThemeScalableMimePath;
|
|
|
|
|
|
|
|
m_buildSystemIcondirDir.mkdir(m_buildSystemIcondirDir.absolutePath());
|
|
|
|
|
|
|
|
m_iconThemeScalableMimeDir.mkdir(m_iconThemeScalableMimeDir.absolutePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList m_mimeIconNameFilters;
|
|
|
|
|
|
|
|
m_mimeIconNameFilters << "*.svg";
|
|
|
|
|
|
|
|
m_iconThemeScalableMimeDir.setNameFilters(m_systemIconNameFilters);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//写入icon index.theme文件
|
|
|
|
|
|
|
|
if (m_iconIndex.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
|
|
if (m_iconIndex.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("# Directory list");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("# Directory list");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Directories=16x16/apps,24x24/apps,32x32/apps,48x48/apps,64x64/apps,96x96/apps,128x128/apps,256x256/apps,scalable/apps,16x16/mimetypes,24x24/mimetypes,32x32/mimetypes,48x48/mimetypes,64x64/mimetypes,96x96/mimetypes,128x128/mimetypes,256x256/mimetypes,scalable/mimetypes");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Directories=16x16/apps,24x24/apps,32x32/apps,48x48/apps,"
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
"64x64/apps,96x96/apps,128x128/apps,256x256/apps,scalable/apps"
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("# Applications");
|
|
|
|
"16x16/devices,24x24/devices,32x32/devices,48x48/devices,"
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[scalable/apps]");
|
|
|
|
"64x64/devices,96x96/devices,128x128/devices,256x256/devices,scalable/devices"
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=Applications");
|
|
|
|
"16x16/places,24x24/places,32x32/places,48x48/places,"
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Size=16");
|
|
|
|
"64x64/places,96x96/places,128x128/places,256x256/places,scalable/places"
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("MinSize=16");
|
|
|
|
"16x16/mimetypes,24x24/mimetypes,32x32/mimetypes,48x48/mimetypes,"
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("MaxSize=256");
|
|
|
|
"64x64/mimetypes,96x96/mimetypes,128x128/mimetypes,256x256/mimetypes,scalable/mimetypes");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Scalable");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[scalable/mimetypes]");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[scalable/mimetypes]");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=Mimetypes");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=Mimetypes");
|
|
|
@ -373,11 +345,35 @@ void buildCheckWidget::buildForIcon(){
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Scalable");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Scalable");
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int array[] = {16, 24, 32, 48, 64, 96, 128, 256};
|
|
|
|
|
|
|
|
int length = sizeof(array) / sizeof(array[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
|
|
|
|
qDebug()<< m_iconIndex;
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[")+QString::number(array[i])+QStringLiteral("x")+QString::number(array[i])+QStringLiteral("/mimetypes]");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=Mimetypes");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Size=")+QString::number(array[i]);
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Fixed");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
m_iconIndexStream.flush();
|
|
|
|
m_iconIndexStream.flush();
|
|
|
|
m_iconIndex.close();
|
|
|
|
m_iconIndex.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建对应目录,拷贝mimetypes文件
|
|
|
|
|
|
|
|
QString m_iconThemeScalablePath = m_buildIconThemePath + "/scalable";
|
|
|
|
|
|
|
|
QString m_iconThemeScalableMimePath = m_iconThemeScalablePath + "/mimetypes";
|
|
|
|
|
|
|
|
QDir m_buildSystemIcondirDir = m_iconThemeScalablePath;
|
|
|
|
|
|
|
|
QDir m_iconThemeScalableMimeDir = m_iconThemeScalableMimePath;
|
|
|
|
|
|
|
|
m_buildSystemIcondirDir.mkdir(m_buildSystemIcondirDir.absolutePath());
|
|
|
|
|
|
|
|
m_iconThemeScalableMimeDir.mkdir(m_iconThemeScalableMimeDir.absolutePath());
|
|
|
|
QFile::copy(":/resource/mimetypes/application-x-desktop.svg",m_iconThemeScalableMimePath+"/application-x-desktop.svg");
|
|
|
|
QFile::copy(":/resource/mimetypes/application-x-desktop.svg",m_iconThemeScalableMimePath+"/application-x-desktop.svg");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历scalable/mimetype目录
|
|
|
|
|
|
|
|
QStringList m_mimeIconNameFilters;
|
|
|
|
|
|
|
|
m_mimeIconNameFilters << "*.svg";
|
|
|
|
|
|
|
|
m_iconThemeScalableMimeDir.setNameFilters(m_mimeIconNameFilters);
|
|
|
|
|
|
|
|
|
|
|
|
QFileInfoList m_svgMimeFileInfoList = m_iconThemeScalableMimeDir.entryInfoList(QDir::Files);
|
|
|
|
QFileInfoList m_svgMimeFileInfoList = m_iconThemeScalableMimeDir.entryInfoList(QDir::Files);
|
|
|
|
foreach (QFileInfo m_svgMimeFileInfo, m_svgMimeFileInfoList) {
|
|
|
|
foreach (QFileInfo m_svgMimeFileInfo, m_svgMimeFileInfoList) {
|
|
|
|
//处理svg转png
|
|
|
|
//处理svg转png
|
|
|
@ -409,127 +405,148 @@ void buildCheckWidget::buildForIcon(){
|
|
|
|
// 将 QImage 对象保存为 PNG 文件
|
|
|
|
// 将 QImage 对象保存为 PNG 文件
|
|
|
|
QString m_fileName = m_svgMimeFileInfo.baseName();
|
|
|
|
QString m_fileName = m_svgMimeFileInfo.baseName();
|
|
|
|
image.save(m_imageDirThemeMimePath+"/"+m_fileName+".png");
|
|
|
|
image.save(m_imageDirThemeMimePath+"/"+m_fileName+".png");
|
|
|
|
|
|
|
|
|
|
|
|
if (m_iconIndex.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
|
|
|
|
|
|
qDebug()<< m_iconIndex;
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[")+QString::number(array[i])+QStringLiteral("x")+QString::number(array[i])+QStringLiteral("/mimetypes]");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=Mimetypes");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Size=")+QString::number(array[i]);
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Fixed");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_iconIndexStream.flush();
|
|
|
|
|
|
|
|
m_iconIndex.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取源目录中的文件列表
|
|
|
|
// 增加图标种类目录在这里增加数组项
|
|
|
|
QStringList m_appIconfiles = m_buildAppIconDir.entryList(QDir::Files);
|
|
|
|
QStringList m_iconTypeList;
|
|
|
|
QStringList m_systemIconfiles = m_buildSystemIconDir.entryList(QDir::Files);
|
|
|
|
m_iconTypeList << "appicon" << "systemicon" << "deviceicon" << "placeicon";
|
|
|
|
|
|
|
|
|
|
|
|
if(!m_appIconfiles.isEmpty()||!m_systemIconfiles.isEmpty()){
|
|
|
|
// 遍历QStringList
|
|
|
|
|
|
|
|
foreach (const QString &m_iconType, m_iconTypeList) {
|
|
|
|
|
|
|
|
qDebug() << m_iconType;
|
|
|
|
|
|
|
|
|
|
|
|
QString m_iconThemeScalableAppsPath = m_iconThemeScalablePath + "/apps";
|
|
|
|
QString m_type;
|
|
|
|
QDir m_iconThemeScalableAppsDir = m_iconThemeScalableAppsPath;
|
|
|
|
QString m_typeContext;
|
|
|
|
m_iconThemeScalableAppsDir.mkdir(m_iconThemeScalableAppsDir.absolutePath());
|
|
|
|
if (m_iconType == "appicon" ||m_iconType == "systemicon"){
|
|
|
|
|
|
|
|
m_type = "apps";
|
|
|
|
// 遍历文件列表并拷贝到目标目录
|
|
|
|
m_typeContext = "Applications";
|
|
|
|
foreach (const QString &m_appIconFile, m_appIconfiles) {
|
|
|
|
} else if(m_iconType == "deviceicon"){
|
|
|
|
QString sourceFilePath = m_buildAppIconDir.filePath(m_appIconFile);
|
|
|
|
m_type = "devices";
|
|
|
|
QString destinationFilePath = m_iconThemeScalableAppsDir.filePath(m_appIconFile);
|
|
|
|
m_typeContext = "Devices";
|
|
|
|
|
|
|
|
} else if(m_iconType == "placeicon"){
|
|
|
|
QFile sourceFile(sourceFilePath);
|
|
|
|
m_type = "places";
|
|
|
|
QFile destinationFile(destinationFilePath);
|
|
|
|
m_typeContext = "Places";
|
|
|
|
|
|
|
|
|
|
|
|
// 如果源文件可以打开,并且目标文件可以创建
|
|
|
|
|
|
|
|
if (sourceFile.open(QIODevice::ReadOnly) && destinationFile.open(QIODevice::WriteOnly)) {
|
|
|
|
|
|
|
|
// 从源文件读取数据
|
|
|
|
|
|
|
|
QByteArray data = sourceFile.readAll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将数据写入目标文件
|
|
|
|
|
|
|
|
destinationFile.write(data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭文件
|
|
|
|
|
|
|
|
sourceFile.close();
|
|
|
|
|
|
|
|
destinationFile.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QString &m_systemIconfile, m_systemIconfiles) {
|
|
|
|
|
|
|
|
QString sourceFilePath = m_buildSystemIconDir.filePath(m_systemIconfile);
|
|
|
|
|
|
|
|
QString destinationFilePath = m_iconThemeScalableAppsDir.filePath(m_systemIconfile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile sourceFile(sourceFilePath);
|
|
|
|
|
|
|
|
QFile destinationFile(destinationFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sourceFile.open(QIODevice::ReadOnly) && destinationFile.open(QIODevice::WriteOnly)) {
|
|
|
|
|
|
|
|
QByteArray data = sourceFile.readAll();
|
|
|
|
|
|
|
|
destinationFile.write(data);
|
|
|
|
|
|
|
|
sourceFile.close();
|
|
|
|
|
|
|
|
destinationFile.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList m_svgFilters;
|
|
|
|
QString m_buildIconPath = QDir::homePath() + "/.cache/theme-build/" + FileProcess::g_date + "/src/iconTheme/"+m_iconType+"/";
|
|
|
|
m_svgFilters << "*.svg"; // 指定扩展名为 .svg
|
|
|
|
QDir m_buildIconDir = m_buildIconPath;
|
|
|
|
|
|
|
|
|
|
|
|
m_iconThemeScalableAppsDir.setNameFilters(m_svgFilters);
|
|
|
|
// 设置过滤器,仅获取 .svg 文件
|
|
|
|
m_iconThemeScalableAppsDir.setFilter(QDir::Files | QDir::NoSymLinks);
|
|
|
|
QStringList m_iconNameFilters;
|
|
|
|
|
|
|
|
m_iconNameFilters << "*.svg";
|
|
|
|
|
|
|
|
m_buildIconDir.setNameFilters(m_iconNameFilters);
|
|
|
|
|
|
|
|
|
|
|
|
QFileInfoList m_svgFileInfoList = m_iconThemeScalableAppsDir.entryInfoList();
|
|
|
|
// 获取源目录中的文件列表
|
|
|
|
|
|
|
|
QStringList m_iconfiles = m_buildIconDir.entryList(QDir::Files);
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历获取文件名
|
|
|
|
if(!m_iconfiles.isEmpty()){
|
|
|
|
foreach (QFileInfo m_svgFileInfo, m_svgFileInfoList) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//处理svg转png
|
|
|
|
//app类型写入icon index.theme文件
|
|
|
|
//遍历、创建尺寸目录,并拷贝生成png
|
|
|
|
if (m_iconIndex.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
|
|
int array[] = {16, 24, 32, 48, 64, 96, 128, 256};
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
int length = sizeof(array) / sizeof(array[0]);
|
|
|
|
// m_iconIndexStream << endl << QStringLiteral("# Applications");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("#")+m_type;
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[scalable/")+m_type+QStringLiteral("]");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=")+m_typeContext;
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Size=16");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("MinSize=16");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("MaxSize=256");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Scalable");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
int array[] = {16, 24, 32, 48, 64, 96, 128, 256};
|
|
|
|
|
|
|
|
int length = sizeof(array) / sizeof(array[0]);
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化一个 SVG 渲染器
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
QSvgRenderer svgRenderer(m_svgFileInfo.absoluteFilePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个和 SVG 同样大小的 QImage 对象,使用透明背景
|
|
|
|
|
|
|
|
QImage image(QSize(array[i],array[i]), QImage::Format_ARGB32);
|
|
|
|
|
|
|
|
image.fill(Qt::transparent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个 QPainter 对象,用于在 QImage 对象上绘图
|
|
|
|
|
|
|
|
QPainter painter(&image);
|
|
|
|
|
|
|
|
// 使用 SVG 渲染器在 QPainter 上渲染图像
|
|
|
|
|
|
|
|
svgRenderer.render(&painter, QRectF(0, 0, array[i], array[i]));
|
|
|
|
|
|
|
|
//生成尺寸目录
|
|
|
|
|
|
|
|
QString m_imageDirThemeSizePath = m_buildIconThemePath +"/" + QString::number(array[i]) + "x" + QString::number(array[i]);
|
|
|
|
|
|
|
|
QString m_imageDirThemeAppsPath = m_imageDirThemeSizePath+ "/apps";
|
|
|
|
|
|
|
|
QDir m_imageThemeSizeDir = m_imageDirThemeSizePath;
|
|
|
|
|
|
|
|
QDir m_imageDirThemeAppDir = m_imageDirThemeAppsPath;
|
|
|
|
|
|
|
|
m_imageThemeSizeDir.mkdir(m_imageThemeSizeDir.absolutePath());
|
|
|
|
|
|
|
|
m_imageDirThemeAppDir.mkdir(m_imageDirThemeAppDir.absolutePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将 QImage 对象保存为 PNG 文件
|
|
|
|
|
|
|
|
QString m_fileName = m_svgFileInfo.baseName();
|
|
|
|
|
|
|
|
image.save(m_imageDirThemeAppsPath+"/"+m_fileName+".png");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_iconIndex.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
|
|
|
|
|
|
qDebug()<< m_iconIndex;
|
|
|
|
qDebug()<< m_iconIndex;
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[")+QString::number(array[i])+QStringLiteral("x")+QString::number(array[i])+QStringLiteral("/apps]");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("[")+QString::number(array[i])+QStringLiteral("x")+
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=Applications");
|
|
|
|
QString::number(array[i])+QStringLiteral("/")+m_type+QStringLiteral("]");
|
|
|
|
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Context=")+m_typeContext;
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Size=")+QString::number(array[i]);
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Size=")+QString::number(array[i]);
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Fixed");
|
|
|
|
m_iconIndexStream << endl << QStringLiteral("Type=Fixed");
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
m_iconIndexStream << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
m_iconIndexStream.flush();
|
|
|
|
|
|
|
|
m_iconIndex.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_iconIndexStream.flush();
|
|
|
|
// 创建app目录
|
|
|
|
m_iconIndex.close();
|
|
|
|
QString m_iconThemeScalableTypePath = m_iconThemeScalablePath + "/" +m_type;
|
|
|
|
|
|
|
|
QDir m_iconThemeScalableTypeDir = m_iconThemeScalableTypePath;
|
|
|
|
|
|
|
|
m_iconThemeScalableTypeDir.mkdir(m_iconThemeScalableTypeDir.absolutePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历appicon文件列表并拷贝到目标目录apps
|
|
|
|
|
|
|
|
foreach (const QString &m_iconFile, m_iconfiles) {
|
|
|
|
|
|
|
|
QString sourceFilePath = m_buildIconDir.filePath(m_iconFile);
|
|
|
|
|
|
|
|
QString destinationFilePath = m_iconThemeScalableTypeDir.filePath(m_iconFile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile sourceFile(sourceFilePath);
|
|
|
|
|
|
|
|
QFile destinationFile(destinationFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果源文件可以打开,并且目标文件可以创建
|
|
|
|
|
|
|
|
if (sourceFile.open(QIODevice::ReadOnly) && destinationFile.open(QIODevice::WriteOnly)) {
|
|
|
|
|
|
|
|
// 从源文件读取数据
|
|
|
|
|
|
|
|
QByteArray data = sourceFile.readAll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将数据写入目标文件
|
|
|
|
|
|
|
|
destinationFile.write(data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭文件
|
|
|
|
|
|
|
|
sourceFile.close();
|
|
|
|
|
|
|
|
destinationFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList m_svgFilters;
|
|
|
|
|
|
|
|
m_svgFilters << "*.svg"; // 指定扩展名为 .svg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_iconThemeScalableTypeDir.setNameFilters(m_svgFilters);
|
|
|
|
|
|
|
|
m_iconThemeScalableTypeDir.setFilter(QDir::Files | QDir::NoSymLinks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFileInfoList m_svgFileInfoList = m_iconThemeScalableTypeDir.entryInfoList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历获取文件名
|
|
|
|
|
|
|
|
foreach (QFileInfo m_svgFileInfo, m_svgFileInfoList) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//处理svg转png
|
|
|
|
|
|
|
|
//遍历、创建尺寸目录,并拷贝生成png
|
|
|
|
|
|
|
|
int array[] = {16, 24, 32, 48, 64, 96, 128, 256};
|
|
|
|
|
|
|
|
int length = sizeof(array) / sizeof(array[0]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化一个 SVG 渲染器
|
|
|
|
|
|
|
|
QSvgRenderer svgRenderer(m_svgFileInfo.absoluteFilePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个和 SVG 同样大小的 QImage 对象,使用透明背景
|
|
|
|
|
|
|
|
QImage image(QSize(array[i],array[i]), QImage::Format_ARGB32);
|
|
|
|
|
|
|
|
image.fill(Qt::transparent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个 QPainter 对象,用于在 QImage 对象上绘图
|
|
|
|
|
|
|
|
QPainter painter(&image);
|
|
|
|
|
|
|
|
// 使用 SVG 渲染器在 QPainter 上渲染图像
|
|
|
|
|
|
|
|
svgRenderer.render(&painter, QRectF(0, 0, array[i], array[i]));
|
|
|
|
|
|
|
|
//生成尺寸目录
|
|
|
|
|
|
|
|
QString m_imageDirThemeSizePath = m_buildIconThemePath +"/" + QString::number(array[i]) + "x" + QString::number(array[i]);
|
|
|
|
|
|
|
|
QString m_imageDirThemeAppsPath = m_imageDirThemeSizePath+ "/"+m_type;
|
|
|
|
|
|
|
|
QDir m_imageThemeSizeDir = m_imageDirThemeSizePath;
|
|
|
|
|
|
|
|
QDir m_imageDirThemeAppDir = m_imageDirThemeAppsPath;
|
|
|
|
|
|
|
|
m_imageThemeSizeDir.mkdir(m_imageThemeSizeDir.absolutePath());
|
|
|
|
|
|
|
|
m_imageDirThemeAppDir.mkdir(m_imageDirThemeAppDir.absolutePath());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将 QImage 对象保存为 PNG 文件
|
|
|
|
|
|
|
|
QString m_fileName = m_svgFileInfo.baseName();
|
|
|
|
|
|
|
|
image.save(m_imageDirThemeAppsPath+"/"+m_fileName+".png");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
qDebug()<<"svg images doesn't exits!!!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
|
|
|
|
qDebug()<<"svg images doesn't exits!!!";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//光标打包
|
|
|
|
//光标打包
|
|
|
|