!122 处理制作过程窗口 处理图标编译前准备工作

Merge pull request !122 from KevinDuan/dev
This commit is contained in:
likehomedream 2024-04-26 02:57:03 +00:00 committed by Gitee
commit b12ad664eb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 162 additions and 143 deletions

View File

@ -1,16 +1,17 @@
#include "buildWidget.h"
buildWidget::buildWidget(QWidget *parent)
: QWidget(parent)
buildWidget::buildWidget(QWidget *parent):
kdk::KDialog(parent)
{
this->setFixedSize(384,110);
this->setWindowModality(Qt::ApplicationModal);
this->setWindowFlags(Qt::FramelessWindowHint);
this->closeButton()->setVisible(false);
m_buildLayout = new QVBoxLayout;
m_buildMessage = new QLabel;
QWidget*mainwindow = mainWidget();
m_buildLayout = new QVBoxLayout(mainwindow);
m_buildMessage = new QLabel(mainwindow);
m_buildMessage->setText("正在制作主题...");
m_buildProgressBar = new QProgressBar();
m_buildProgressBar = new QProgressBar(mainwindow);
m_buildLayout->addWidget(m_buildMessage);
m_buildLayout->addWidget(m_buildProgressBar);
m_buildProgressBar->setMinimum(0);

View File

@ -15,7 +15,7 @@
#include <QDir>
#include <QThread>
class buildWidget : public QWidget
class buildWidget : public kdk::KDialog
{
Q_OBJECT
public:

View File

@ -325,45 +325,17 @@ void buildCheckWidget::buildForIcon(){
m_iconIndex.close();
}
//处理svg转png获取svg文件
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文件
//mimetype写入icon index.theme文件
if (m_iconIndex.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
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;
m_iconIndexStream << endl << QStringLiteral("# Applications");
m_iconIndexStream << endl << QStringLiteral("[scalable/apps]");
m_iconIndexStream << endl << QStringLiteral("Context=Applications");
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 << QStringLiteral("Directories=16x16/apps,24x24/apps,32x32/apps,48x48/apps,"
"64x64/apps,96x96/apps,128x128/apps,256x256/apps,scalable/apps"
"16x16/devices,24x24/devices,32x32/devices,48x48/devices,"
"64x64/devices,96x96/devices,128x128/devices,256x256/devices,scalable/devices"
"16x16/places,24x24/places,32x32/places,48x48/places,"
"64x64/places,96x96/places,128x128/places,256x256/places,scalable/places"
"16x16/mimetypes,24x24/mimetypes,32x32/mimetypes,48x48/mimetypes,"
"64x64/mimetypes,96x96/mimetypes,128x128/mimetypes,256x256/mimetypes,scalable/mimetypes");
m_iconIndexStream << endl;
m_iconIndexStream << endl << QStringLiteral("[scalable/mimetypes]");
m_iconIndexStream << endl << QStringLiteral("Context=Mimetypes");
@ -373,11 +345,35 @@ void buildCheckWidget::buildForIcon(){
m_iconIndexStream << endl << QStringLiteral("Type=Scalable");
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_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");
// 遍历scalable/mimetype目录
QStringList m_mimeIconNameFilters;
m_mimeIconNameFilters << "*.svg";
m_iconThemeScalableMimeDir.setNameFilters(m_mimeIconNameFilters);
QFileInfoList m_svgMimeFileInfoList = m_iconThemeScalableMimeDir.entryInfoList(QDir::Files);
foreach (QFileInfo m_svgMimeFileInfo, m_svgMimeFileInfoList) {
//处理svg转png
@ -409,127 +405,148 @@ void buildCheckWidget::buildForIcon(){
// 将 QImage 对象保存为 PNG 文件
QString m_fileName = m_svgMimeFileInfo.baseName();
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_systemIconfiles = m_buildSystemIconDir.entryList(QDir::Files);
// 增加图标种类目录在这里增加数组项
QStringList m_iconTypeList;
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";
QDir m_iconThemeScalableAppsDir = m_iconThemeScalableAppsPath;
m_iconThemeScalableAppsDir.mkdir(m_iconThemeScalableAppsDir.absolutePath());
// 遍历文件列表并拷贝到目标目录
foreach (const QString &m_appIconFile, m_appIconfiles) {
QString sourceFilePath = m_buildAppIconDir.filePath(m_appIconFile);
QString destinationFilePath = m_iconThemeScalableAppsDir.filePath(m_appIconFile);
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();
}
}
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();
}
QString m_type;
QString m_typeContext;
if (m_iconType == "appicon" ||m_iconType == "systemicon"){
m_type = "apps";
m_typeContext = "Applications";
} else if(m_iconType == "deviceicon"){
m_type = "devices";
m_typeContext = "Devices";
} else if(m_iconType == "placeicon"){
m_type = "places";
m_typeContext = "Places";
}
QStringList m_svgFilters;
m_svgFilters << "*.svg"; // 指定扩展名为 .svg
QString m_buildIconPath = QDir::homePath() + "/.cache/theme-build/" + FileProcess::g_date + "/src/iconTheme/"+m_iconType+"/";
QDir m_buildIconDir = m_buildIconPath;
m_iconThemeScalableAppsDir.setNameFilters(m_svgFilters);
m_iconThemeScalableAppsDir.setFilter(QDir::Files | QDir::NoSymLinks);
// 设置过滤器,仅获取 .svg 文件
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);
// 遍历获取文件名
foreach (QFileInfo m_svgFileInfo, m_svgFileInfoList) {
if(!m_iconfiles.isEmpty()){
//处理svg转png
//遍历、创建尺寸目录并拷贝生成png
int array[] = {16, 24, 32, 48, 64, 96, 128, 256};
int length = sizeof(array) / sizeof(array[0]);
//app类型写入icon index.theme文件
if (m_iconIndex.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
m_iconIndexStream << endl;
// 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 渲染器
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)) {
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("/apps]");
m_iconIndexStream << endl << QStringLiteral("Context=Applications");
m_iconIndexStream << endl << QStringLiteral("[")+QString::number(array[i])+QStringLiteral("x")+
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("Type=Fixed");
m_iconIndexStream << endl;
}
m_iconIndexStream.flush();
m_iconIndex.close();
}
m_iconIndexStream.flush();
m_iconIndex.close();
// 创建app目录
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!!!";
}
}
//光标打包

View File

@ -8,6 +8,7 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
initUkuiLog4qt("kylin-theme-builder");
//防止多开
QSharedMemory fixsharedmemory("kylin-theme-builder");
if (fixsharedmemory.attach())
{

View File

@ -452,7 +452,7 @@ void InfoCreateWidget::createControlChangelog(const QString &m_date){
if (m_changelog.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)){
QTextStream m_changelogStream(&m_changelog);
m_changelogStream << FileProcess::g_themeENName + QStringLiteral(" (1.0-1) UNRELEASED; urgency=medium");
m_changelogStream << FileProcess::g_themeENName + QStringLiteral(" (1.0) UNRELEASED; urgency=medium");
m_changelogStream << endl;
m_changelogStream << endl << QStringLiteral(" * Initial release");
m_changelogStream << endl;