!35 打包功能 目录结构调整

Merge pull request !35 from KevinDuan/2.0
This commit is contained in:
likehomedream 2023-10-19 08:11:17 +00:00 committed by Gitee
commit 1179a6e30b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
39 changed files with 284 additions and 3108 deletions

View File

@ -16,13 +16,14 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
src/build/buildWidget.cpp \
src/build/buildcheck.cpp \
src/build/buildcheckwidget.cpp \
src/fileProcess/bridge.cpp \
src/fileProcess/diroperation.cpp \
src/fileProcess/filecheck.cpp \
src/fileProcess/fileprocess.cpp \
src/fileProcess/configfilemanager.cpp \
src/build/buildcheckwidget.cpp \
src/fileProcess/historyinfoload.cpp \
src/module/cacheconfirmedwidget.cpp \
src/module/cursorthemefeature.cpp \
@ -40,13 +41,14 @@ SOURCES += \
src/titlebar.cpp
HEADERS += \
src/build/buildcheck.h \
src/build/build.h \
src/build/buildWidget.h \
src/build/buildcheckwidget.h \
src/fileProcess/bridge.h \
src/fileProcess/diroperation.h \
src/fileProcess/filecheck.h \
src/fileProcess/fileprocess.h \
src/fileProcess/configfilemanager.h \
src/build/buildcheckwidget.h \
src/fileProcess/historyinfoload.h \
src/module/cacheconfirmedwidget.h \
src/module/cursorthemefeature.h \

View File

@ -127,5 +127,8 @@
<file>resource/systemicons/kylin-settings-commoninfo.png</file>
<file>resource/config/defualt.json</file>
<file>resource/config/theme.conf</file>
<file>resource/debian/rules</file>
<file>resource/debian/copyright</file>
<file>resource/debian/source/format</file>
</qresource>
</RCC>

View File

@ -1,122 +0,0 @@
#include "bridge.h"
Bridge* Bridge::m_instance = nullptr;
QMutex Bridge::m_mutex;
Bridge::Bridge(QObject *parent) : QObject(parent)
{
}
Bridge *Bridge::getInstance(QObject *parent)
{
if (m_instance == nullptr) {
QMutexLocker locker(&m_mutex);
if (m_instance == nullptr) {
m_instance = new Bridge(parent);
}
}
return m_instance;
}
void Bridge::wallpaperPathChanged(QString path)
{
m_configfilemanager->modifyWallPaperConf(path);
}
void Bridge::coverPathChanged(QString path)
{
m_coverpath = path;
}
void Bridge::radiusChanged(int radius)
{
m_configfilemanager->modifyRadiusJson(radius);
}
void Bridge::accentColorChanged(QColor accentcolor)
{
m_configfilemanager->modifyAccentColorConf(accentcolor);
}
void Bridge::exteriorChanged(QColor accentcolor)
{
}
void Bridge::appIconsMapChanged(QMap<QString, QString> *appiconsmaps)
{
QMap<QString, QString>::const_iterator it;
for (it = appiconsmaps->begin(); it != appiconsmaps->end(); ++it) {
qDebug() << "Key:" << it.key() << "Value:" << it.value();
}
m_appsiconpathmap = appiconsmaps;
}
void Bridge::systemIconsMapChanged(QMap<QString, QString> *systemiconsmaps)
{
QMap<QString, QString>::const_iterator it;
for (it = systemiconsmaps->begin(); it != systemiconsmaps->end(); ++it) {
qDebug() << "Key:" << it.key() << "Value:" << it.value();
}
m_systemiconpathmap = systemiconsmaps;
}
void Bridge::cursorMapChanged(QMap<QString, QString> *cursormap)
{
QMap<QString, QString>::const_iterator it;
for (it = cursormap->begin(); it != cursormap->end(); ++it) {
qDebug() << "Key:" << it.key() << "Value:" << it.value();
}
m_cursorpathmap = cursormap;
qDebug()<< "cursorMapChanged";
}
void Bridge::timeCursorMapChanged(QMap<QString, QString> *timecursormap)
{
QMap<QString, QString>::const_iterator it;
for (it = timecursormap->begin(); it != timecursormap->end(); ++it) {
qDebug() << "Key:" << it.key() << "Value:" << it.value();
}
m_timecursorpathmap = timecursormap;
qDebug()<< "timeCursorMapChanged";
}
void Bridge::startCopy()
{
if(m_appsiconpathmap){
m_configfilemanager->copyIcontoCacheDir(m_appsiconpathmap,m_builderappicon);
}
if(m_systemiconpathmap){
m_configfilemanager->copyIcontoCacheDir(m_systemiconpathmap,m_buildersystemicon);
}
if(m_cursorpathmap){
m_configfilemanager->copyIcontoCacheDir(m_cursorpathmap,m_buildercursor);
}
if(m_timecursorpathmap){
m_configfilemanager->copyIcontoCacheDir(m_timecursorpathmap,m_buildertimecursor);
}
m_configfilemanager->copyCovertoCacheDir(m_coverpath,m_builderConfig);
}
void Bridge::createFileManager(QString time)
{
m_time = time;
m_configfilemanager = new ConfigFileManager(time);
createDir();
}
void Bridge::createDir()
{
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" +m_time;
m_builderConfig = m_themePath + "/config";
m_builderappicon = m_themePath + "/iconTheme" + "/appicon";
m_buildersystemicon = m_themePath + "/iconTheme" + "/systemicon";
m_buildercursor = m_themePath + "/cursorTheme" + "/cursor";
m_buildertimecursor = m_themePath + "/cursorTheme" + "/timecursor";
m_builderConfig.mkdir(m_builderConfig.absolutePath());
m_buildericons.mkdir(m_buildericons.absolutePath());
m_builderappicon.mkdir(m_builderappicon.absolutePath());
m_buildersystemicon.mkdir(m_buildersystemicon.absolutePath());
m_buildercursors.mkdir(m_buildercursors.absolutePath());
m_buildercursor.mkdir(m_buildercursor.absolutePath());
m_buildertimecursor.mkdir(m_buildertimecursor.absolutePath());
}

View File

@ -1,55 +0,0 @@
#ifndef BRIDGE_H
#define BRIDGE_H
#include "globalthemewidget.h"
#include "iconthemewidget.h"
#include "cursorthemewidget.h"
#include <QObject>
#include "configfilemanager.h"
#include <QMutex>
class Bridge : public QObject
{
Q_OBJECT
public:
static Bridge* getInstance(QObject *parent = nullptr);
void createFileManager(QString time);
void createDir();
void wallpaperPathChanged(QString path);
void coverPathChanged(QString path);
void radiusChanged(int radius);
void accentColorChanged(QColor accentcolor);
void exteriorChanged(QColor accentcolor);
void appIconsMapChanged(QMap<QString, QString> *appiconsmaps);
void systemIconsMapChanged(QMap<QString, QString> *systemiconsmaps);
void cursorMapChanged(QMap<QString, QString> *cursormap);
void timeCursorMapChanged(QMap<QString, QString> *timecursormap);
void startCopy();
signals:
private:
Bridge(QObject *parent = nullptr);
QString m_time;
static Bridge* m_instance;
static QMutex m_mutex;
ConfigFileManager *m_configfilemanager;
QMap<QString, QString> *m_appsiconpathmap = nullptr;
QMap<QString, QString> *m_systemiconpathmap = nullptr;
QMap<QString, QString> *m_cursorpathmap = nullptr;
QMap<QString, QString> *m_timecursorpathmap = nullptr;
QString m_wallpaperpath = ":/resource/background/1-warty-final-ubuntukylin.jpg";
QString m_coverpath = ":/resource/background/1-warty-final-ubuntukylin.jpg";
QDir m_builderConfig;
QDir m_buildericons;
QDir m_builderappicon;
QDir m_buildersystemicon;
QDir m_buildercursors;
QDir m_buildercursor;
QDir m_buildertimecursor;
};
#endif // BRIDGE_H

80
src/build/build.h Normal file
View File

@ -0,0 +1,80 @@
#ifndef BUILD_H
#define BUILD_H
#include "../fileProcess/fileprocess.h"
#include "../module/infocreatewidget.h"
#include <QProgressBar>
#include <QObject>
#include <QCoreApplication>
#include <QThread>
#include <QProcess>
#include <QDebug>
#include <QDir>
class build: public QThread
{
Q_OBJECT
public:
explicit build(QObject *parent = nullptr) : QThread(parent){}
protected:
void run() override
{
//生成源码orig文件
QProcess process1;
QString dir1 = QDir::homePath() + "/.cache/theme-build/"+FileProcess::g_date;
qDebug() << dir1;
QString command1 = "tar";
QStringList arguments1;
arguments1 << "-zcvf" << FileProcess::g_themeENName+"_1.0.orig.tar.xz"
<< "--exclude=.git" << "--exclude=debian" << FileProcess::g_date;
process1.setWorkingDirectory(dir1);
process1.start(command1, arguments1);
QObject::connect(&process1, &QProcess::readyReadStandardOutput, [&]() {
QString output = process1.readAllStandardOutput();
qDebug() << "Output from tar: " << output;
});
process1.waitForFinished(-1);
emit progressChanged(10);
//编译
QProcess process2;
QString dir2 = QDir::homePath() + "/.cache/theme-build/" + FileProcess::g_date + "/src/";
qDebug() << dir2;
QString command2 = "debuild";
QStringList arguments2;
arguments2 << "-us"<<"-uc";
process2.setWorkingDirectory(dir2);
process2.start(command2, arguments2);
// 连接debuild进程的输出信号和槽
QObject::connect(&process2, &QProcess::readyReadStandardOutput, [&]() {
QString output = process2.readAllStandardOutput();
qDebug() << "Output from debuild: " << output;
if(output=="dh clean\n"){
emit progressChanged(20);
}else if(output==" dh_installdocs\n"){
emit progressChanged(80);
}else if(output==" dh_builddeb\n"){
emit progressChanged(90);
}
});
// 等待debuild进程完成
process2.waitForFinished(-1);
// 完成后更新进度条的值为100
emit progressChanged(100);
}
signals:
void progressChanged(int value);
};
#endif // BUILD_H

34
src/build/buildWidget.cpp Normal file
View File

@ -0,0 +1,34 @@
#include "buildWidget.h"
buildWidget::buildWidget(QWidget *parent)
: QWidget(parent)
{
this->setFixedSize(384,110);
this->setWindowModality(Qt::ApplicationModal);
this->setWindowFlags(Qt::FramelessWindowHint);
m_buildLayout = new QVBoxLayout;
m_buildMessage = new QLabel;
m_buildMessage->setText("正在制作主题...");
m_buildProgressBar = new QProgressBar();
m_buildLayout->addWidget(m_buildMessage);
m_buildLayout->addWidget(m_buildProgressBar);
m_buildProgressBar->setMinimum(0);
m_buildProgressBar->setMaximum(100);
m_buildProgressBar->setValue(0);
this->setLayout(m_buildLayout);
build *thread = new build();
connect(thread, &build::progressChanged, m_buildProgressBar, &QProgressBar::setValue);
thread->start();
connect(thread, &build::progressChanged, this, [=](){
if(m_buildProgressBar->value()==100){
this->close();
//清空日期缓存
FileProcess::g_date = nullptr;
FileProcess::g_themeENName = nullptr;
}
});
}

28
src/build/buildWidget.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef BUILDWIDGET_H
#define BUILDWIDGET_H
#include "build.h"
#include <QObject>
#include <QWidget>
#include <QLabel>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QProcess>
#include <QDebug>
#include <QDir>
#include <QThread>
class buildWidget : public QWidget
{
Q_OBJECT
public:
explicit buildWidget(QWidget *parent = nullptr);
private:
QVBoxLayout *m_buildLayout;
QLabel *m_buildMessage;
QProgressBar *m_buildProgressBar;
};
#endif // BUILDWIDGET_H

View File

@ -3,6 +3,88 @@
buildCheckWidget::buildCheckWidget(QWidget *parent)
: QWidget(parent)
{
this->setFixedSize(424,480);
this->setWindowModality(Qt::ApplicationModal);
}
void buildCheckWidget::buildCopy(){
m_debSourceFormat = ":/resource/debian/source/format";
m_debRules = ":/resource/debian/rules";
m_debCopyRight = ":/resource/debian/copyright";
QString m_debPath = QDir::homePath() + "/.cache/theme-build/" + FileProcess::g_date + "/src";
QDir m_debSource = m_debPath +"/debian/source";
qDebug()<<m_debSource;
m_debSource.mkdir(m_debSource.absolutePath());
if (QFile::copy(m_debSourceFormat,m_debPath+"/debian/source/format") &&
QFile::copy(m_debRules,m_debPath+"/debian/rules") &&
QFile::copy(m_debCopyRight,m_debPath+"/debian/copyright")){
qDebug()<<"COPY SUCCESS";
} else {
qDebug()<<"COPY Failed";
qDebug()<<QFile::copy(m_debSourceFormat,m_debPath+"/debian/source/format") ;
qDebug()<<QFile::copy(m_debRules,m_debPath+"/debian/rules") ;
qDebug()<<QFile::copy(m_debCopyRight,m_debPath+"/debian/copyright");
}
}
void buildCheckWidget::buildCheck(QDir m_buildIconPath){
bool buildCheckState = true;
// // 设置过滤器,只获取文件和目录
// m_buildIconPath.setFilter(QDir::Files|QDir::Dirs| QDir::NoDotAndDotDot);
// // 获取目录下的所有文件和目录
// QFileInfoList fileList = m_buildIconPath.entryInfoList();
// qDebug()<<fileList;
// // 遍历文件和目录
// foreach(const QFileInfo& fileInfo, fileList)
// {
// qDebug()<<fileInfo;
// if (fileInfo.isFile()){
// if(FileCheck::isLegalIconFile(fileInfo.absoluteFilePath())){
// qDebug() << fileInfo.absoluteFilePath();
// } else {
// qDebug() << "warning:" << fileInfo.absoluteFilePath();
// buildCheckState = false;
// }
// } else if (fileInfo.isDir()){
// qDebug() << fileInfo.absoluteFilePath();
// buildCheck(QDir(fileInfo.absoluteFilePath()));
// } else {
// qDebug() << "warning:" << fileInfo.absoluteFilePath();
// buildCheckState = false;
// }
// }
if(buildCheckState){
buildCopy();
buildWidget *m_buildWidget = new buildWidget();
m_buildWidget->show();
} else {
this->setFixedSize(424,480);
this->setWindowModality(Qt::ApplicationModal);
m_buildCheckWidget = new QVBoxLayout();
m_buildWarningMessage = new QLabel();
m_buildWarningMessage->setText("导出时检测到以下问题,请调整后重新导出:");
m_warningMessageList = new QLabel();
m_warningMessageList->setText("以下内容有错误");
m_buildCheckBtnWidget = new QHBoxLayout();
m_buildBtn = new QPushButton();
m_buildBtn->setText("继续导出");
m_exitBuildBtn = new QPushButton();
m_exitBuildBtn->setText("返回");
m_buildCheckBtnWidget->addWidget(m_buildBtn);
m_buildCheckBtnWidget->addWidget(m_exitBuildBtn);
m_buildCheckWidget->addWidget(m_buildWarningMessage);
m_buildCheckWidget->addWidget(m_warningMessageList);
m_buildCheckWidget->addLayout(m_buildCheckBtnWidget);
this->setLayout(m_buildCheckWidget);
this->show();
}
}

View File

@ -1,6 +1,10 @@
#ifndef BUILDCHECKWIDGET_H
#define BUILDCHECKWIDGET_H
#include "../fileProcess/fileprocess.h"
#include "../fileProcess/filecheck.h"
#include "buildWidget.h"
#include <QObject>
#include <QWidget>
#include <QLabel>
@ -8,23 +12,26 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "../fileProcess/fileprocess.h"
#include "../fileProcess/filecheck.h"
class buildCheckWidget : public QWidget
{
Q_OBJECT
public:
explicit buildCheckWidget(QWidget *parent = nullptr);
bool buildCheck();
void buildCheck(QDir m_buildIconPath);
private:
QVBoxLayout *m_buildCheckWidget;
QLabel *m_buildWarningMessage;
QLabel *m_warningMessageList;
QHBoxLayout *m_buildCheckBtnWidget;
QPushButton *m_buildBtn;
QPushButton *m_exitBuildBtn;
QString m_debSourceFormat;
QString m_debRules;
QString m_debCopyRight;
void buildCopy();
};
#endif // BUILDCHECKWIDGET_H

View File

@ -1,35 +0,0 @@
#include "cacheconfirmedwidget.h"
cacheConfirmedWidget::cacheConfirmedWidget(QWidget *parent)
: QWidget(parent)
{
this->setFixedSize(424,172);
this->setWindowModality(Qt::ApplicationModal);
m_cacheConfirmedWidget = new QVBoxLayout;
m_questionMessage = new QLabel();
m_questionMessage->setText("是否保存?");
m_saveCache = new QPushButton();
m_cleanCache = new QPushButton();
m_saveCache->setText("保存");
m_cleanCache->setText("清除");
m_cacheConfirmedBtn = new QHBoxLayout();
m_cacheConfirmedBtn->addWidget(m_saveCache);
m_cacheConfirmedBtn->addWidget(m_cleanCache);
m_cacheConfirmedWidget->addWidget(m_questionMessage);
m_cacheConfirmedWidget->addLayout(m_cacheConfirmedBtn);
this->setLayout(m_cacheConfirmedWidget);
QObject::connect(m_saveCache,&QPushButton::clicked,this,[=](){
emit cacheSave();
this->close();
});
QObject::connect(m_cleanCache,&QPushButton::clicked,this,[=](){
FileProcess m_fileClean;
m_fileClean.FileClean(FileProcess::g_date);
emit cacheClean();
this->close();
});
}

View File

@ -1,31 +0,0 @@
#ifndef CACHECONFIRMEDWIDGET_H
#define CACHECONFIRMEDWIDGET_H
#include <QObject>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "fileprocess.h"
class cacheConfirmedWidget : public QWidget
{
Q_OBJECT
public:
explicit cacheConfirmedWidget(QWidget *parent = nullptr);
signals:
void cacheSave();
void cacheClean();
private:
QVBoxLayout *m_cacheConfirmedWidget;
QLabel *m_questionMessage;
QHBoxLayout *m_cacheConfirmedBtn;
QPushButton *m_saveCache;
QPushButton *m_cleanCache;
};
#endif // CACHECONFIRMEDWIDGET_H

View File

@ -1,247 +0,0 @@
#include "configfilemanager.h"
#include <QDebug>
#include <QFile>
#include <QDir>
#include <QCoreApplication>
#include <QResource>
ConfigFileManager::ConfigFileManager(const QString& time,QObject *parent) : QObject(parent)
{
//创建json、conf文件到指定目录在这个类里进行修改。
m_time = time;
createConf();
createJson();
}
bool ConfigFileManager::createJson()
{
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/";
QString filePath = m_themePath + "default.json";
jsonFilePath = filePath;
QDir dir;
if (!dir.exists(m_themePath)) {
dir.mkpath(m_themePath);
}
if (copyFileContent(":/resource/config/defualt.json", filePath)) {
// 成功将文件内容写入目标文件中
return true;
} else {
// 写入文件内容失败
return false;
}
}
bool ConfigFileManager::createConf()
{
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/";
QString filePath = m_themePath + "theme.conf";
confFilePath = filePath;
QDir dir;
if (!dir.exists(m_themePath)) {
dir.mkpath(m_themePath);
}
if (copyFileContent(":/resource/config/theme.conf", filePath)) {
// 成功将文件内容写入目标文件中
return true;
} else {
// 写入文件内容失败
return false;
}
}
bool ConfigFileManager::modifyRadiusJson(int radius)
{
QString confFilePath = jsonFilePath; // 替换为实际的文件路径
// 读取配置文件
QFile configFile(confFilePath);
if (!configFile.open(QIODevice::ReadWrite | QIODevice::Text))
{
qDebug() << "Failed to open config file";
return false;
}
QByteArray data = configFile.readAll();
configFile.close();
// 解析JSON
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
if (error.error != QJsonParseError::NoError)
{
qDebug() << "Failed to parse JSON:" << error.errorString();
return false;
}
// 修改"value"字段的值为18
QJsonObject jsonObj = jsonDoc.object();
QJsonObject radiusObj = jsonObj["Radius"].toObject();
for (auto it = radiusObj.begin(); it != radiusObj.end(); ++it)
{
QJsonObject valueObj = it.value().toObject();
valueObj["value"] = QString::number(radius);
radiusObj[it.key()] = valueObj;
}
jsonObj["Radius"] = radiusObj;
// 保存修改后的配置文件
configFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
configFile.write(QJsonDocument(jsonObj).toJson());
configFile.close();
qDebug() << "Config file updated successfully";
}
bool ConfigFileManager::modifyAccentColorConf(QColor accentcolor)
{
QString colorString = accentcolor.name().toUpper();
while (colorString.length() < 6) {
colorString.prepend('0');
}
// 读取文件内容
QFile file(confFilePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "无法打开文件:" << confFilePath;
return false;
}
QTextStream in(&file);
QString content = in.readAll();
file.close();
// 修改内容
int startIndex = content.indexOf("accent=") + QString("accent=").size();
content.remove(startIndex, 7);
content.insert(startIndex, colorString);
// 写入文件
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << content;
file.close();
return true;
} else {
qDebug() << "无法写入文件:" << confFilePath;
return false;
}
}
bool ConfigFileManager::modifyWallPaperConf(QString wallpaperpath)
{
// 读取文件内容
QFile file(confFilePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "无法打开文件:" << confFilePath;
return false;
}
QTextStream in(&file);
QString content = in.readAll();
file.close();
// 修改内容
int startIndex = content.indexOf("wallPaperPath=");
if (startIndex != -1) {
QString substr = "wallPaperPath="+wallpaperpath;
content.replace(startIndex, content.indexOf('\n', startIndex) - startIndex, substr);
}
qDebug() << content;
// 写入文件
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << content;
file.close();
return true;
} else {
qDebug() << "无法写入文件:" << confFilePath;
return false;
}
}
bool ConfigFileManager::copyFileContent(const QString &sourceFilePath, const QString &destinationFilePath)
{
QFile sourceFile(sourceFilePath);
if (!sourceFile.open(QIODevice::ReadOnly)) {
qDebug() << "Failed to open source file:" << sourceFilePath;
return false;
}
QFile destinationFile(destinationFilePath);
if (!destinationFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Failed to open destination file:" << destinationFilePath;
sourceFile.close();
return false;
}
QTextStream in(&sourceFile);
QTextStream out(&destinationFile);
while (!in.atEnd()) {
QString line = in.readLine();
out << line << "\n";
}
sourceFile.close();
destinationFile.close();
return true;
}
bool ConfigFileManager::copyIcontoCacheDir(QMap<QString, QString> *map, QDir cachedir)
{
bool success = true;
for (auto it = map->begin(); it != map->end(); ++it)
{
QString key = it.key();
QString value = it.value();
if (value.startsWith(":/resource")){
continue;
}
QFile inputFile(value);
QFileInfo fileInfo(inputFile.fileName());
QString destinationPath = cachedir.filePath(key + "." + fileInfo.completeSuffix());
if (!inputFile.exists()){
success = false;
continue;
}
if (!inputFile.copy(destinationPath)){
success = false;
}
}
return success;
}
void ConfigFileManager::copyCovertoCacheDir(const QString &destinationFilePath, QDir cachedir)
{
QString sourceFilePath = destinationFilePath;
QString sourceFileExt = QFileInfo(sourceFilePath).suffix();
QString targetFileName = "preview." + sourceFileExt;
QString targetFilePath = cachedir.filePath(targetFileName);
if (!QFile::copy(sourceFilePath, targetFilePath))
{
qDebug() << "Failed to copy file";
return;
}
qDebug() << "File copied successfully";
}

View File

@ -1,36 +0,0 @@
#ifndef CONFIGFILEMANAGER_H
#define CONFIGFILEMANAGER_H
#include <QObject>
#include <QColor>
#include <QJsonDocument>
#include <QJsonObject>
#include <QDir>
class ConfigFileManager : public QObject
{
Q_OBJECT
public:
explicit ConfigFileManager(const QString& time,QObject *parent = nullptr);
bool createJson();
bool createConf();
bool modifyRadiusJson(int radius);
bool modifyAccentColorConf(QColor accentcolor);
bool modifyWallPaperConf(QString wallpaperpath);
bool copyFileContent(const QString& sourceFilePath, const QString& destinationFilePath);
bool copyIcontoCacheDir(QMap<QString, QString> *map,QDir cachedir);
void copyCovertoCacheDir(const QString& destinationFilePath,QDir cachedir);
signals:
private:
QString m_time;
QString jsonFilePath;
QString confFilePath;
};
#endif // CONFIGFILEMANAGER_H

View File

@ -1,270 +0,0 @@
#include "cursorthemefeature.h"
#include "cursorthemewidget.h"
#include <QGraphicsPixmapItem>
#include <QVBoxLayout>
#include <QPixmap>
#include <QGraphicsBlurEffect>
CursorThemeFeature::CursorThemeFeature(QWidget *parent, const QMap<QString, QString> *iconMap) : QWidget(parent)
{
CursorImageWidget* cursorImageWidget = new CursorImageWidget(this, iconMap);
}
CursorGraphicsView::CursorGraphicsView(QGraphicsScene* scene) : QGraphicsView(scene)
{
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setDragMode(QGraphicsView::ScrollHandDrag);
setRenderHint(QPainter::Antialiasing, true);
setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing |QGraphicsView::DontSavePainterState);
this->setStyleSheet("background-color: transparent;");
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void CursorGraphicsView::wheelEvent(QWheelEvent* event)
{
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
qreal scaleFactor = std::pow(qreal(2), event->delta() / 240.0);
qreal currentScale = transform().m11(); // 获取当前的缩放倍数
// 限制最大为1.1倍
qreal targetScale = currentScale * scaleFactor;
if (targetScale > 1.1) {
scaleFactor = 1.1 / currentScale;
}else if (targetScale < 0.3) {
scaleFactor = 0.3 / currentScale;
}
scale(scaleFactor, scaleFactor);
scale(scaleFactor, scaleFactor);
} else {
QGraphicsView::wheelEvent(event);
}
}
void CursorImageWidget::updateImage(const QString& imagePath)
{
// 删除场景中的所有图像项
graphicsView->scene()->clear();
// 创建新的背景图像项并添加到场景中
QPixmap image(imagePath);
if (image.isNull()) {
qDebug() << "Failed to load new image.";
return;
}
QGraphicsPixmapItem* backgroundItem = graphicsView->scene()->addPixmap(image);
// 创建 QGraphicsBlurEffect 并设置模糊半径
QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect;
blurEffect->setBlurRadius(10);
// 将模糊效果应用到 QGraphicsPixmapItem 上
backgroundItem->setGraphicsEffect(blurEffect);
// 根据需要重新布局图像项
int columnCount = 15;
int row = 1;
int col = 0;
for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
// 添加新的图像项到场景中
const QString& widgetName = it.key();
const QString& filePath = it.value();
QPixmap pixmap(filePath);
if (!pixmap.isNull()) {
QGraphicsPixmapItem* item = graphicsView->scene()->addPixmap(pixmap.scaled(128, 128));
item->setPos(col * 128, row * 128);
item->setScale(1.0);
item->setData(0, widgetName);
item->setData(1, filePath);
col++;
if (col >= columnCount) {
col = 0;
row++;
}
} else {
qDebug() << "Failed to load image:" << filePath;
}
}
graphicsView->fitInView(graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio);
QTransform currentTransform = graphicsView->transform();
QPointF sceneCenter = graphicsView->mapToScene(graphicsView->viewport()->rect().center());
currentTransform.translate(sceneCenter.x(), sceneCenter.y());
graphicsView->setTransform(currentTransform);
QPointF viewCenter = graphicsView->mapFromScene(graphicsView->scene()->sceneRect().center());
graphicsView->centerOn(viewCenter);
graphicsView->viewport()->update();
}
CursorImageWidget::CursorImageWidget(QWidget *parent, const QMap<QString, QString>* iconMap)
: QWidget(parent), m_iconMap(iconMap)
{
QGraphicsScene* scene = new QGraphicsScene(this);
graphicsView = new CursorGraphicsView(scene);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(graphicsView);
setLayout(layout);
QPixmap image(":/resource/background/background-light.png");
if (image.isNull()) {
qDebug() << "Failed to load image.";
}
// 创建 QGraphicsPixmapItem 并添加到 QGraphicsScene
QGraphicsPixmapItem* backgroundItem = scene->addPixmap(image);
// 创建 QGraphicsBlurEffect 并设置模糊半径
QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect;
blurEffect->setBlurRadius(10); // 设置模糊半径,可以根据需要调整
// 将模糊效果应用到 QGraphicsPixmapItem 上
backgroundItem->setGraphicsEffect(blurEffect);
graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
graphicsView->setScene(scene);
graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
graphicsView->show();
int columnCount = 15;
int row = 1;
int col = 0;
for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
QPixmap pixmap(filePath);
if (!pixmap.isNull()) {
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128));
item->setPos(col * 128, row * 128);
item->setScale(1.0);
item->setData(0, widgetName);
item->setData(1, filePath);
col++;
if (col >= columnCount) {
col = 0;
row++;
}
} else {
qDebug() << "Failed to load image:" << filePath;
}
}
// 设置初始缩放倍数为0.9倍
// qreal initialScale = 0.8;
// graphicsView->scale(initialScale, initialScale);
qreal initialScale = 0.3;
QTransform transform;
transform.scale(initialScale, initialScale);
graphicsView->setTransform(transform);
}
void CursorImageWidget::updateIcon(const QString& widgetName, const QString& newFilePath)
{
QGraphicsScene* scene = graphicsView->scene();
QList<QGraphicsItem*> items = scene->items();
for (QGraphicsItem* item : items) {
QGraphicsPixmapItem* pixmapItem = dynamic_cast<QGraphicsPixmapItem*>(item);
if (pixmapItem && pixmapItem->data(0).toString() == widgetName) {
QPointF oldPosition = pixmapItem->pos();
scene->removeItem(pixmapItem);
delete pixmapItem;
QPixmap newPixmap(newFilePath);
if (!newPixmap.isNull()) {
QGraphicsPixmapItem* newPixmapItem = scene->addPixmap(newPixmap.scaled(256, 256));
newPixmapItem->setData(0, widgetName);
newPixmapItem->setData(1, newFilePath);
newPixmapItem->setPos(oldPosition);
qDebug()<<"-----------------";
} else {
qDebug() << "Failed to load image:" << newFilePath;
}
return;
}
}
}
void CursorImageWidget::setIconMap(QMap<QString, QString> *iconmap)
{
m_iconMap = iconmap;
}
CursorEditWidget::CursorEditWidget(QWidget *parent)
{
this->setFixedHeight(110);
m_iconwidgetlayout = new QHBoxLayout();
m_icondefaultlabel = new QLabel();
m_icondefaultlabel->setFixedSize(48,48);
m_icondecustomlabel = new CursorCustomLabel();
m_addiconbutton = new QPushButton();
m_addiconbutton->setIcon(QIcon::fromTheme("list-add-symbolic"));
m_addiconbutton->setFixedSize(36,36);
m_tiplabel = new QLabel();
m_tiplabel->setWordWrap(true);
m_tiplabel->setText("<html>格式svg<br>尺寸96*96</html>");
m_iconwidgetlayout->addWidget(m_icondefaultlabel);
m_iconwidgetlayout->addWidget(m_icondecustomlabel);
m_iconwidgetlayout->addWidget(m_addiconbutton);
m_iconwidgetlayout->addWidget(m_tiplabel);
this->setLayout(m_iconwidgetlayout);
}
void CursorEditWidget::setdefaulticon(QString iconname)
{
m_icondefaultlabel->setPixmap(QIcon::fromTheme(iconname).pixmap(48,48));
}
void CursorEditWidget::setcustomicon(QString iconFilePath)
{
QPixmap pixmap(iconFilePath);
m_icondecustomlabel->setPixmap(pixmap.scaled(48, 48));
}
CursorCustomLabel::CursorCustomLabel(QWidget *parent): QLabel(parent), pixmap()
{
this->setFixedSize(48,48);
}
void CursorCustomLabel::paintEvent(QPaintEvent *event)
{
QLabel::paintEvent(event); // 调用父类的 paintEvent 函数,绘制文本
QPainter painter(this);
QPen pen(Qt::blue);
pen.setStyle(Qt::DashLine);
painter.setPen(pen);
QBrush brush(QColor("#F5F5F5"));
painter.setBrush(brush);
QRect roundedRect = rect().adjusted(1, 1, -1, -1);
QPainterPath path;
int radius = 6;
path.addRoundedRect(roundedRect, radius, radius);
painter.drawPath(path);
if (!pixmap.isNull()) {
painter.drawPixmap(rect(), pixmap);
}
}
void CursorCustomLabel::setPixmap(const QPixmap &pixmap)
{
this->pixmap = pixmap; // 使用赋值操作来更新 pixmap
update();
}

View File

@ -1,92 +0,0 @@
#ifndef CURSORTHEMEFEATURE_H
#define CURSORTHEMEFEATURE_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QPainter>
#include <QScrollArea>
#include <QLabel>
#include <QMap>
#include <QDebug>
#include <QFileDialog>
#include <QStackedWidget>
#include <QWheelEvent>
#include <QDir>
#include <QFileInfo>
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QDebug>
#include <QKeyEvent>
#include <QWheelEvent>
#include <QtMath>
#include <QGraphicsPixmapItem>
class CursorCustomLabel : public QLabel {
public:
explicit CursorCustomLabel(QWidget* parent = nullptr);
void setPixmap(const QPixmap& pixmap);
protected:
void paintEvent(QPaintEvent* event) override;
private:
QPixmap pixmap;
};
class CursorEditWidget : public QWidget
{
Q_OBJECT
public:
CursorEditWidget(QWidget *parent = nullptr);
void setdefaulticon(QString iconname);
void setcustomicon(QString iconFilePath);
QPushButton *m_addiconbutton;
private:
QHBoxLayout *m_iconwidgetlayout;
QLabel *m_icondefaultlabel;
CursorCustomLabel *m_icondecustomlabel;
QLabel *m_tiplabel;
};
class CursorGraphicsView : public QGraphicsView {
public:
explicit CursorGraphicsView(QGraphicsScene* scene);
protected:
void wheelEvent(QWheelEvent* event) override;
};
class CursorImageWidget : public QWidget {
public:
CursorImageWidget(QWidget *parent = nullptr, const QMap<QString,QString>* iconMap = nullptr);
void updateIcon(const QString& widgetName, const QString& newFilePath);
void updateImage(const QString& imagePath);
void setIconMap(QMap<QString,QString>*);
private:
const QMap<QString,QString>* m_iconMap;
CursorGraphicsView* graphicsView;
QString m_coverFilePath;
};
class CursorThemeFeature : public QWidget
{
Q_OBJECT
public:
explicit CursorThemeFeature(QWidget *parent = nullptr, const QMap<QString,QString>* iconMap = nullptr);
signals:
};
#endif // CURSORTHEMEFEATURE_H

View File

@ -1,144 +0,0 @@
#include "cursorthemewidget.h"
CursorThemeWidget::CursorThemeWidget(QWidget *parent) : QWidget(parent)
{
initMaps();
initTimeMaps();
initPreviewWidget();
initRightWidget();
m_cursorthemelayout = new QHBoxLayout();
m_cursorthemelayout->addWidget(m_previewwidget);
m_cursorthemelayout->addWidget(m_rightwidget);
this->setLayout(m_cursorthemelayout);
}
void CursorThemeWidget::initPreviewWidget()
{
m_previewwidget = new QWidget(this);
m_previewwidget->setMinimumSize(495,620);
m_preview = new CursorImageWidget(m_previewwidget,m_iconpathmap);
m_preview2 = new CursorImageWidget(m_previewwidget,m_timeiconpathmap);
m_previewlayout = new QVBoxLayout(m_previewwidget);
m_preview->setIconMap(m_iconpathmap);
connect(this,&CursorThemeWidget::wallpaperupdate, m_preview,[=](const QString& filePath){
m_preview->updateImage(filePath);
m_preview2->updateImage(filePath);
});
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
QSpacerItem *spacer2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
spacer->changeSize(m_previewwidget->width(), 155, QSizePolicy::Maximum, QSizePolicy::Maximum);
spacer2->changeSize(m_previewwidget->width(), 159, QSizePolicy::Maximum, QSizePolicy::Maximum);
m_previewlayout->addItem(spacer);
m_previewlayout->addWidget(m_preview);
m_previewlayout->addWidget(m_preview2);
m_previewlayout->addItem(spacer2);
}
QStringList CursorThemeWidget::getWidgetNamesFromFilesInDirectory(const QString& directoryPath) {
QStringList widgetNames;
QDir dir(directoryPath);
QStringList fileNames = dir.entryList(QDir::Files);
foreach (const QString& fileName, fileNames) {
QFileInfo fileInfo(fileName);
QString widgetName = fileInfo.baseName();
widgetNames.append(widgetName);
}
return widgetNames;
}
void CursorThemeWidget::initMaps()
{
m_iconpathmap = new QMap<QString, QString>;
QString directoryPath = ":/resource/cursor/";
QStringList widgetNames = getWidgetNamesFromFilesInDirectory(directoryPath);
for (int i = 0; i < widgetNames.size(); ++i) {
qDebug() << widgetNames[i];
QString cursorFileName = directoryPath + widgetNames[i] + ".png";
m_iconpathmap->insert(widgetNames[i], cursorFileName);
}
m_customiconpathmap= new QMap<QString, QString>;
m_pathWidgetMap = new QMap<QString, CursorEditWidget*>;
}
void CursorThemeWidget::initTimeMaps()
{
m_timeiconpathmap = new QMap<QString, QString>;
QString directoryPath = ":/resource/time-cursor/";
QStringList widgetNames = getWidgetNamesFromFilesInDirectory(directoryPath);
for (int i = 0; i < widgetNames.size(); ++i) {
qDebug() << widgetNames[i];
QString cursorFileName = directoryPath + widgetNames[i] + ".png";
m_timeiconpathmap->insert(widgetNames[i], cursorFileName);
}
m_timecustomiconpathmap= new QMap<QString, QString>;
m_pathWidgetMap = new QMap<QString, CursorEditWidget*>;
}
void CursorThemeWidget::initRightWidget()
{
m_rightwidget = new QWidget(this);
m_rightwidget->setMinimumSize(400,620);
m_rightwidget->setMaximumWidth(400);
QScrollArea *m_scrollArea = new QScrollArea(m_rightwidget);
m_scrollArea->setMinimumSize(m_rightwidget->size());
m_scrollArea->setMaximumWidth(this->width());
m_scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_scrollArea->setWidgetResizable(true);
QWidget *viewportWidget = new QWidget(m_scrollArea);
m_scrollArea->setWidget(viewportWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(viewportWidget);
viewportWidget->setLayout(mainLayout);
QMap<QString, QString> *combinedMap = m_iconpathmap;
combinedMap->unite(*m_timeiconpathmap);
for (auto it = combinedMap->begin(); it != combinedMap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
CursorEditWidget* widget = new CursorEditWidget(viewportWidget);
widget->setdefaulticon(filePath);
mainLayout->addWidget(widget);
m_pathWidgetMap->insert(widgetName, widget);
connect(widget->m_addiconbutton, &QPushButton::clicked, this, [=]() {
QPushButton* clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton) {
CursorEditWidget* clickedWidget = qobject_cast<CursorEditWidget*>(clickedButton->parentWidget());
if (clickedWidget) {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择SVG文件"), "", tr("SVG 文件 (*.svg)"));
if (!newFilePath.isEmpty()) {
if (m_iconpathmap->contains(widgetName)) {
m_customiconpathmap->insert(widgetName, newFilePath);
emit newCursorMap(m_customiconpathmap);
} else if (m_timeiconpathmap->contains(widgetName)) {
m_timecustomiconpathmap->insert(widgetName, newFilePath);
emit newCursorMap(m_timecustomiconpathmap);
}
m_preview->updateIcon(widgetName, newFilePath);
m_preview2->updateIcon(widgetName, newFilePath);
clickedWidget->setcustomicon(newFilePath);
}
}
}
});
}
QVBoxLayout *mainWidgetLayout = new QVBoxLayout();
mainWidgetLayout->addWidget(m_scrollArea);
m_rightwidget->setLayout(mainWidgetLayout);
}

View File

@ -1,60 +0,0 @@
#ifndef CURSORTHEMEWIDGET_H
#define CURSORTHEMEWIDGET_H
#include "cursorthemefeature.h"
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QPainter>
#include <QScrollArea>
#include <QLabel>
#include <QMap>
#include <QDebug>
#include <QFileDialog>
#include <QStackedWidget>
#include <QObject>
#include <QWidget>
class CursorThemeWidget : public QWidget
{
Q_OBJECT
public:
explicit CursorThemeWidget(QWidget *parent = nullptr);
signals:
void wallpaperupdate(const QString& filePath);
void newCursorMap(QMap<QString, QString> *cursormap);
void newTimeCursorMap(QMap<QString, QString> *timecursormap);
private:
void initPreviewWidget();
void initMaps();
void initTimeMaps();
void initRightWidget();
QStringList getWidgetNamesFromFilesInDirectory(const QString& directoryPath);
QHBoxLayout *m_cursorthemelayout;
QWidget *m_rightwidget;
QVBoxLayout *m_rightwidgetlayout;
QMap<QString, CursorEditWidget*> *m_pathWidgetMap;
QVBoxLayout *m_previewlayout;
QString m_coverfilepath = ":/resource/background/background-glazing.png";
QMap<QString, QString> *m_iconpathmap;
QMap<QString, QString> *m_customiconpathmap;
QMap<QString, QString> *m_timeiconpathmap;
QMap<QString, QString> *m_timecustomiconpathmap;
QWidget *m_previewwidget;
CursorImageWidget *m_preview;
CursorImageWidget *m_preview2;
QWidget *m_editwidget;
};
#endif // CURSORTHEMEWIDGET_H

View File

@ -108,12 +108,15 @@ void Bridge::createFileManager(bool ishistory,QString time)
void Bridge::createDir()
{
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" +m_time;
m_builderConfig = m_themePath + "/config";
m_builderappicon = m_themePath + "/iconTheme" + "/appicon";
m_buildersystemicon = m_themePath + "/iconTheme" + "/systemicon";
m_buildercursor = m_themePath + "/cursorTheme" + "/cursor";
m_buildertimecursor = m_themePath + "/cursorTheme" + "/timecursor";
QString m_themePathSrc = m_themePath + "/src";
QDir m_themePathSrcDir = m_themePathSrc;
m_builderConfig = m_themePathSrc + "/config";
m_builderappicon = m_themePathSrc + "/iconTheme" + "/appicon";
m_buildersystemicon = m_themePathSrc + "/iconTheme" + "/systemicon";
m_buildercursor = m_themePathSrc + "/cursorTheme" + "/cursor";
m_buildertimecursor = m_themePathSrc + "/cursorTheme" + "/timecursor";
m_themePathSrcDir.mkdir(m_themePathSrcDir.absolutePath());
m_builderConfig.mkdir(m_builderConfig.absolutePath());
m_buildericons.mkdir(m_buildericons.absolutePath());
m_builderappicon.mkdir(m_builderappicon.absolutePath());

View File

@ -10,8 +10,8 @@ ConfigFileManager::ConfigFileManager(bool ishistory, const QString& time, QObjec
createJson();
}else{
m_time = time;
jsonFilePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/"+ "default.json";
confFilePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/"+ "theme.conf";
jsonFilePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/scr/config/"+ "default.json";
confFilePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/scr/config/"+ "theme.conf";
qDebug()<<"have";
}
@ -20,7 +20,7 @@ ConfigFileManager::ConfigFileManager(bool ishistory, const QString& time, QObjec
bool ConfigFileManager::createJson()
{
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/";
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/src/config/";
QString filePath = m_themePath + "default.json";
jsonFilePath = filePath;
@ -41,7 +41,7 @@ bool ConfigFileManager::createJson()
bool ConfigFileManager::createConf()
{
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/config/";
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + m_time + "/src/config/";
QString filePath = m_themePath + "theme.conf";
confFilePath = filePath;

View File

@ -1,6 +1,7 @@
#include "fileprocess.h"
QString FileProcess::g_date;
QString FileProcess::g_themeENName;
FileProcess::FileProcess()
{
//创建缓存目录
@ -16,7 +17,7 @@ FileProcess::FileProcess()
}
QMap<QString, QVariant> FileProcess::FileSearch(const QString &m_date){
QString m_getInfoFIlePath = QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control";
QString m_getInfoFIlePath = QDir::homePath() + "/.cache/theme-build/" + m_date + "/src/debian/control";
QMap<QString, QVariant> emptyMap;
// 处理文件不存在的情况
if (m_getInfoFIlePath.isEmpty()){
@ -60,15 +61,18 @@ QString FileProcess::FileCreate(const QString &m_themeType){
//创建新的记录文件目录
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + g_date;
QDir m_builderTime = m_themePath;
QDir m_builderDeb = m_themePath + "/debian";
QDir m_themeTypePath = m_themePath + "/" + m_themeType;
QString m_builderPathSrc = m_themePath + "/src";
QDir m_builderSrc = m_builderPathSrc;
QDir m_builderDeb = m_builderPathSrc + "/debian";
QDir m_themeTypePath = m_builderPathSrc + "/" + m_themeType;
m_builderTime.mkdir(m_builderTime.absolutePath());
m_builderSrc.mkdir(m_builderSrc.absolutePath());
m_builderDeb.mkdir(m_builderDeb.absolutePath());
if(m_themeType == "globalTheme"){
QDir iconPath = m_themePath+ "/iconTheme";
QDir cursorPath = m_themePath+ "/cursorTheme";
QDir iconPath = m_builderPathSrc+ "/iconTheme";
QDir cursorPath = m_builderPathSrc+ "/cursorTheme";
iconPath.mkdir(iconPath.absolutePath());
cursorPath.mkdir(cursorPath.absolutePath());
}

View File

@ -19,6 +19,7 @@ public:
void FileClean(const QString &m_date);
static QString g_date;
static QString g_themeENName;
private:
QDir m_builder;

View File

@ -1,57 +0,0 @@
#include "filecheck.h"
#include <QSvgRenderer>
#include <QFileInfo>
#include <QImage>
#include <QMessageBox>
FileCheck::FileCheck(QObject *parent) : QObject(parent)
{
}
bool FileCheck::isLegalIconFile(const QString &filePath)
{
QSvgRenderer renderer(filePath);
if (renderer.isValid()){
QSize svgSize = renderer.defaultSize();
if (svgSize.width() >= 96 && svgSize.height() >= 96 && svgSize.width() == svgSize.height()){
return true;
}
}
return false;
}
bool FileCheck::isLegalWallPaperFile(const QString& filePath, const QString& type)
{
QFileInfo fileInfo(filePath);
QImage image(filePath);
QSize imageSize = image.size();
qint64 fileSize = fileInfo.size();
if (type == "wallpaper") {
if (imageSize.width() != 3840 || imageSize.height() != 2160){
QMessageBox::information(nullptr, tr("错误"), tr("壁纸尺寸必须为3840x2160"));
return false;
}
qint64 maxSize = 10 * 1024 * 1024; // 10 MB
if (fileSize > maxSize){
QMessageBox::information(nullptr, tr("错误"), tr("文件大小不能超过10MB"));
return false;
}
} else if (type == "cover") {
if (imageSize.width() != 1640 || imageSize.height() != 1080){
QMessageBox::information(nullptr, tr("错误"), tr("封面尺寸必须为1640x1080"));
return false;
}
qint64 maxSize = 5 * 1024 * 1024; // 5 MB
if (fileSize > maxSize){
QMessageBox::information(nullptr, tr("错误"), tr("文件大小不能超过5MB"));
return false;
}
}
return true;
}

View File

@ -1,18 +0,0 @@
#ifndef FILECHECK_H
#define FILECHECK_H
#include <QObject>
#include <QDebug>
class FileCheck : public QObject
{
Q_OBJECT
public:
explicit FileCheck(QObject *parent = nullptr);
static bool isLegalIconFile(const QString& filePath);
static bool isLegalWallPaperFile(const QString& filePath, const QString& type);
signals:
};
#endif // FILECHECK_H

View File

@ -1,83 +0,0 @@
#include "fileprocess.h"
QString FileProcess::g_date;
FileProcess::FileProcess()
{
//创建缓存目录
m_builder = QDir::homePath()+"/.cache/theme-build/";
if (m_builder.exists()){
qDebug()<<"thmem-build cache Dir exists";
} else {
m_builder.mkdir(m_builder.absolutePath());
qDebug()<<"thmem-build cache Dir create";
}
return;
}
QMap<QString, QVariant> FileProcess::FileSearch(const QString &m_date){
QString m_getInfoFIlePath = QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control";
QMap<QString, QVariant> emptyMap;
// 处理文件不存在的情况
if (m_getInfoFIlePath.isEmpty()){
qDebug() << m_getInfoFIlePath << "文件不存在!";
return emptyMap;
} else {
QFile m_getInfoFIle(m_getInfoFIlePath);
if (!m_getInfoFIle.open(QIODevice::ReadOnly | QIODevice::Text)){
// 处理文件打开失败的情况
qDebug() << m_getInfoFIlePath << "文件无法打开!";
return emptyMap;
} else {
QTextStream in(&m_getInfoFIle);
int currentLine = 1;
QString line;
QMap<QString, QVariant> m_packageInfo;
while (!in.atEnd()){
line = in.readLine();
if (currentLine == 1){
m_packageInfo.insert("key1",line.mid(8));
} else if(currentLine == 4){
m_packageInfo.insert("key2",line.mid(12, line.indexOf('<')-12).trimmed());
m_packageInfo.insert("key3",line.mid(line.indexOf('<') + 1, line.indexOf('>') - line.indexOf('<') - 1).trimmed());
}
currentLine++;
}
m_getInfoFIle.close();
return m_packageInfo;
}
return emptyMap;
}
}
QString FileProcess::FileCreate(const QString &m_themeType){
QDateTime currentDateTime = QDateTime::currentDateTime();
g_date = currentDateTime.toString("yyyyMMddhhmmss");
qDebug()<< g_date;
//创建新的记录文件目录
QString m_themePath = QDir::homePath() + "/.cache/theme-build/" + g_date;
QDir m_builderTime = m_themePath;
QDir m_builderDeb = m_themePath + "/debian";
QDir m_themeTypePath = m_themePath + "/" + m_themeType;
m_builderTime.mkdir(m_builderTime.absolutePath());
m_builderDeb.mkdir(m_builderDeb.absolutePath());
if(m_themeType == "globalTheme"){
QDir iconPath = m_themePath+ "/iconTheme";
QDir cursorPath = m_themePath+ "/cursorTheme";
iconPath.mkdir(iconPath.absolutePath());
cursorPath.mkdir(cursorPath.absolutePath());
}
m_themeTypePath.mkdir(m_themeTypePath.absolutePath());
return g_date;
}
void FileProcess::FileClean(const QString &m_date){
QDir m_datePath = QDir::homePath() + "/.cache/theme-build/" + m_date;
m_datePath.removeRecursively();
}

View File

@ -1,27 +0,0 @@
#ifndef FILEPROCESS_H
#define FILEPROCESS_H
#include <QObject>
#include <QDir>
#include <QDateTime>
#include <QDebug>
#include <QStandardPaths>
#include <QMap>
class FileProcess
{
public:
FileProcess();
QMap<QString, QVariant> FileSearch(const QString &m_date);
QString FileCreate(const QString &themes);
void FileClean(const QString &m_date);
static QString g_date;
private:
QDir m_builder;
};
#endif // FILEPROCESS_H

View File

@ -1,203 +0,0 @@
#include "globalthemefeature.h"
#include "globalthemewidget.h"
#include <QGraphicsDropShadowEffect>
CustomGraphicsView::CustomGraphicsView(QGraphicsScene* scene) : QGraphicsView(scene) {
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setDragMode(QGraphicsView::ScrollHandDrag);
setRenderHint(QPainter::Antialiasing, true);
setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing |
QGraphicsView::DontSavePainterState);
this->setStyleSheet("background-color: transparent;");
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void CustomGraphicsView::wheelEvent(QWheelEvent* event) {
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
qreal scaleFactor = std::pow(qreal(2), event->delta() / 240.0);
qreal currentScale = transform().m11(); // 获取当前的缩放倍数
// 限制最大为1.1倍
qreal targetScale = currentScale * scaleFactor;
if (targetScale > 1.1) {
scaleFactor = 1.1 / currentScale;
}else if (targetScale < 0.3) {
scaleFactor = 0.3 / currentScale;
}
scale(scaleFactor, scaleFactor);
} else {
QGraphicsView::wheelEvent(event);
}
}
void GlobalImageWidget::updateWidgetRadius(int sliderValue) {
int radius = sliderValue;
m_showwidget->setRadius(radius);
m_showwidget->update();
}
void GlobalImageWidget::updateButtonColor(const QColor& color) {
QPalette palette = m_showbtn->palette();
palette.setColor(QPalette::Button, color);
m_showbtn->setPalette(palette);
m_showbtn->update();
}
void GlobalImageWidget::updateWidgetBackgroundColor(const QColor& color)
{
m_showwidget->setBackgroundColor(color);
}
void GlobalImageWidget::updateOverlayImage(const QString& overlayImagePath) {
QPixmap overlayImage(overlayImagePath);
if (!overlayImage.isNull()) {
m_mergedImage = QPixmap(m_image.size());
m_mergedImage.fill(Qt::transparent);
QPainter painter(&m_mergedImage);
painter.drawPixmap(0, 0, m_image);
int x = (m_image.width() - overlayImage.width()) / 2;
int y = m_image.height() - overlayImage.height();
painter.drawPixmap(x, y, overlayImage);
painter.end();
QGraphicsProxyWidget* newproxy = m_proxy;
m_scene->removeItem(m_proxy);
m_scene->clear();
m_scene->addPixmap(m_mergedImage);
m_scene->setSceneRect(m_mergedImage.rect());
graphicsView->fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio);
m_scene->addItem(newproxy);
} else {
qDebug() << "Failed to load overlay image.";
}
}
void GlobalImageWidget::updatescale()
{
graphicsView->resetTransform();
QPointF centerPoint(1500, 600);
graphicsView->centerOn(centerPoint);
graphicsView->scale(1, 1);
}
GlobalImageWidget::GlobalImageWidget(QWidget *parent, const QString& coverFilePath)
: QWidget(parent), m_coverFilePath(coverFilePath) {
m_scene = new QGraphicsScene(this);
graphicsView = new CustomGraphicsView(m_scene);
m_proxy = new QGraphicsProxyWidget();
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(graphicsView);
setLayout(layout);
m_image = QPixmap(m_coverFilePath);
if (m_image.isNull()) {
qDebug() << "Failed to load image.";
}
m_mergedImage = QPixmap(m_image.size());
m_mergedImage.fill(Qt::transparent);
QPainter painter(&m_mergedImage);
painter.drawPixmap(0, 0, m_image);
QPixmap overlayImage(":/resource/background/panel-light.png");
if (!overlayImage.isNull()) {
int x = (m_image.width() - overlayImage.width()) / 2;
int y = m_image.height() - overlayImage.height();
painter.drawPixmap(x, y, overlayImage);
} else {
qDebug() << "Failed to load overlay image.";
}
painter.end();
m_scene->addPixmap(m_mergedImage);
m_scene->setSceneRect(m_image.rect());
graphicsView->fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio);
graphicsView->show();
m_showwidget = new RoundedWidget();
m_showwidget->setFixedSize(700,320);
m_showwidget->setRadius(6);
QPalette widgetpalette = m_showwidget->palette();
widgetpalette.setColor(QPalette::Background, QColor(255, 255, 255));
m_showwidget->setAutoFillBackground(true);
m_showwidget->setPalette(widgetpalette);
QHBoxLayout *buttonlayout = new QHBoxLayout();
m_showbtn = new QPushButton(m_showwidget);
m_showbtn->setFixedWidth(120);
m_showbtn->setParent(m_showwidget);
QPalette palette = m_showbtn->palette();
palette.setColor(QPalette::Button, QColor(55, 144, 250));
m_showbtn->setPalette(palette);
QPushButton *disablebtn = new QPushButton(m_showwidget);
disablebtn->setFixedWidth(120);
buttonlayout->addStretch(1);
buttonlayout->addWidget(m_showbtn);
buttonlayout->addWidget(disablebtn);
m_showwidget->setLayout(buttonlayout);
m_proxy->setWidget(m_showwidget);
m_proxy->setPos(800, 400);
m_scene->addItem(m_proxy);
// 设置初始缩放倍数为0.9倍
qreal initialScale = 0.9;
graphicsView->scale(initialScale, initialScale);
}
Globalthemefeature::Globalthemefeature(QWidget *parent, const QString& coverFilePath)
: QWidget(parent) {
GlobalImageWidget* globalImageWidget = new GlobalImageWidget(this, coverFilePath);
}
RoundedWidget::RoundedWidget(QWidget *parent)
: QWidget(parent), m_radius(0)
{
setAttribute(Qt::WA_TranslucentBackground);
setRadius(6);
}
void RoundedWidget::setRadius(int radius)
{
m_radius = radius;
}
void RoundedWidget::setBackgroundColor(const QColor &color)
{
backgroundColor = color;
update();
}
void RoundedWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true); // 开启抗锯齿
QRectF rect = contentsRect().adjusted(borderWidth, borderWidth, -borderWidth, -borderWidth);
int r = std::min(rect.width(), rect.height()) / 2; // 计算圆角半径
int actualRadius = std::min(m_radius, r); // 取实际圆角半径和计算半径的较小值
// 绘制背景
painter.setPen(Qt::NoPen);
painter.setBrush(backgroundColor);
painter.drawRoundedRect(rect, actualRadius, actualRadius);
// 绘制边框
// painter.setPen(QPen(borderColor, borderWidth));
// painter.setBrush(Qt::NoBrush);
// painter.drawRoundedRect(rect, actualRadius, actualRadius);
}

View File

@ -1,74 +0,0 @@
#ifndef GLOBALTHEMEFEATURE_H
#define GLOBALTHEMEFEATURE_H
#include <QObject>
#include <QWidget>
#include <QVBoxLayout>
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QDebug>
#include <QKeyEvent>
#include <QWheelEvent>
#include <QtMath>
#include <QGraphicsProxyWidget>
#include <QPushButton>
class RoundedWidget : public QWidget
{
Q_OBJECT
public:
RoundedWidget(QWidget *parent = nullptr);
void setRadius(int radius);
void setBackgroundColor(const QColor& color);
protected:
void paintEvent(QPaintEvent *event) override;
private:
int m_radius;
QColor backgroundColor = Qt::white; // 背景颜色
QColor borderColor = Qt::white; // 边框颜色
int borderWidth = 1; // 边框宽度
};
class CustomGraphicsView : public QGraphicsView {
public:
explicit CustomGraphicsView(QGraphicsScene* scene);
protected:
void wheelEvent(QWheelEvent* event) override;
};
class GlobalImageWidget : public QWidget {
public:
GlobalImageWidget(QWidget *parent = nullptr, const QString& coverFilePath = "");
void updateWidgetRadius(int sliderValue);
void updateButtonColor(const QColor& color);
void updateWidgetBackgroundColor(const QColor& color);
void update(const QString& coverFilePath);
void updateOverlayImage(const QString& overlayImagePath);
void updatescale();
private:
CustomGraphicsView* graphicsView;
QString m_coverFilePath;
RoundedWidget *m_showwidget;
QPushButton *m_showbtn;
QGraphicsScene* m_scene;
QPixmap m_mergedImage;
QPixmap m_image;
QGraphicsProxyWidget* m_proxy;
};
class Globalthemefeature : public QWidget {
Q_OBJECT
public:
explicit Globalthemefeature(QWidget *parent = nullptr, const QString& coverFilePath = "");
signals:
};
#endif // GLOBALTHEMEFEATURE_H

View File

@ -1,302 +0,0 @@
#include "globalthemewidget.h"
#include "filecheck.h"
GlobalThemeWidget::GlobalThemeWidget(QWidget *parent) : QWidget(parent)
{
initPreviewWidget();
initRightWidget();
m_globalthemelayout = new QHBoxLayout();
m_globalthemelayout->addWidget(m_previewwidget);
m_globalthemelayout->addWidget(m_rightwidget);
this->setLayout(m_globalthemelayout);
}
QString GlobalThemeWidget::getWallpaperPath()
{
return m_wallpaperpath;
}
void GlobalThemeWidget::initPreviewWidget()
{
m_previewwidget = new QWidget(this);
m_previewwidget->setMinimumSize(495,620);
m_previewwidget->setBackgroundRole(QPalette::Window);
m_preview = new GlobalImageWidget(m_previewwidget,m_wallpaperpath);
m_previewlayout = new QVBoxLayout(m_previewwidget);
addspaceritem();
m_previewwidget->setLayout(m_previewlayout);
}
void GlobalThemeWidget::initRightWidget()
{
m_rightwidget = new QWidget(this);
m_rightwidget->setMinimumSize(400,620);
m_rightwidget->setMaximumWidth(400);
m_rightwidget->setBackgroundRole(QPalette::Base);
m_scrollArea = new QScrollArea(m_rightwidget);
m_scrollArea->setMinimumSize(m_rightwidget->size());
m_scrollArea->setWidgetResizable(true);
m_viewportwidget = new QWidget(m_scrollArea);
m_scrollArea->setWidget(m_viewportwidget);
QVBoxLayout *mainLayout = new QVBoxLayout(m_viewportwidget);
initCoverWidget();
initWallPaperWidget();
initExteriorWidget();
initFilletWidget();
AccentColorWidget();
mainLayout->addWidget(m_coverwidget);
mainLayout->addStretch(1);
mainLayout->addWidget(m_wallpaperwidget);
mainLayout->addStretch(1);
mainLayout->addWidget(m_exteriorwidget);
mainLayout->addStretch(1);
mainLayout->addWidget(m_filletwidget);
mainLayout->addStretch(1);
mainLayout->addWidget(m_accentcolorwidget);
mainLayout->addStretch(1);
m_viewportwidget->setLayout(mainLayout);
QVBoxLayout *mainWidgetLayout = new QVBoxLayout(m_rightwidget);
mainWidgetLayout->addWidget(m_scrollArea);
m_rightwidget->setLayout(mainWidgetLayout);
}
void GlobalThemeWidget::initCoverWidget()
{
m_coverwidget = new QWidget(m_viewportwidget);
m_coverwidget->setFixedHeight(182);
QLabel *title = new QLabel(m_coverwidget);
title->setText("全局主题效果图");
QVBoxLayout *layout = new QVBoxLayout();
QWidget *cover = new QWidget(m_coverwidget);
cover->setFixedHeight(160);
QHBoxLayout *coverlayout = new QHBoxLayout(cover);
QPushButton *coverbtn = new QPushButton(cover);
coverbtn->setFixedSize(160,100);
QLabel *tip = new QLabel(cover);
tip->setText("<html>尺寸1640*1080<br>大小:不超过 5 MB<br>格式PNG</html>");
coverlayout->addWidget(coverbtn);
coverlayout->addWidget(tip);
cover->setLayout(coverlayout);
connect(coverbtn, &QPushButton::clicked, this, [=]() {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
bool legalFile = FileCheck::isLegalWallPaperFile(newFilePath,"cover");
if (newFilePath.isEmpty() || !legalFile) {
newFilePath = m_coverpath;
}
m_coverpath = newFilePath;
coverbtn->setIcon(QIcon(m_coverpath));
coverbtn->setIconSize(coverbtn->size());
emit newCoverFilePath(newFilePath);
});
layout->addStretch(1);
layout->addWidget(title);
layout->addWidget(cover);
m_coverwidget->setLayout(layout);
}
void GlobalThemeWidget::initWallPaperWidget()
{
m_wallpaperwidget = new QWidget(m_viewportwidget);
m_wallpaperwidget->setFixedHeight(182);
QLabel *title = new QLabel(m_wallpaperwidget);
title->setText("全局主题效果图");
QVBoxLayout *layout = new QVBoxLayout();
QWidget *cover = new QWidget(m_wallpaperwidget);
cover->setFixedHeight(160);
QHBoxLayout *coverlayout = new QHBoxLayout(cover);
QPushButton *coverbtn = new QPushButton(cover);
coverbtn->setFixedSize(160,100);
QLabel *tip = new QLabel(cover);
tip->setText("<html>尺寸3840*2160<br>大小:不超过 10 MB<br>格式PNG</html>");
coverlayout->addWidget(coverbtn);
coverlayout->addWidget(tip);
cover->setLayout(coverlayout);
QPixmap pixmap(m_wallpaperpath);
coverbtn->setIcon(QIcon(pixmap));
coverbtn->setIconSize(coverbtn->size());
connect(coverbtn, &QPushButton::clicked, this, [=]() {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择图片文件"), "", tr("图片文件 (*.png *.jpg)"));
if (!newFilePath.isEmpty() && FileCheck::isLegalWallPaperFile(newFilePath,"wallpaper")) {
updateWallpaperFilePath(newFilePath);
emit wallpaperupdate(newFilePath);
emit newWallpaperFilePath(newFilePath);
QPixmap pixmap(newFilePath);
coverbtn->setIcon(QIcon(pixmap));
coverbtn->setIconSize(coverbtn->size());
} else {
qDebug() << "Selected file path:" << newFilePath;
updateWallpaperFilePath(m_wallpaperpath);
}
});
layout->addStretch(1);
layout->addWidget(title);
layout->addWidget(cover);
m_wallpaperwidget->setLayout(layout);
}
void GlobalThemeWidget::initExteriorWidget()
{
m_exteriorwidget = new QWidget(m_viewportwidget);
m_exteriorwidget->setFixedHeight(65);
QLabel *title = new QLabel(m_exteriorwidget);
title->setFixedWidth(m_exteriorwidget->width());
title->setText("窗口外观");
QHBoxLayout *layout = new QHBoxLayout();
QComboBox *combobox = new QComboBox(m_exteriorwidget);
combobox->addItem("浅色",QColor(255, 255, 255));
combobox->addItem("深色", QColor(29, 29, 29));
connect(combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index){
QColor selectedColor = combobox->itemData(index).value<QColor>();
QString overlayImage;
if (index == 0) {
overlayImage = ":/resource/background/panel-light.png";
} else if (index == 1) {
overlayImage = ":/resource/background/panel-dark.png";
}
m_preview->updateWidgetBackgroundColor(selectedColor);
m_preview->updateOverlayImage(overlayImage);
m_preview->updatescale();
emit newExterior(selectedColor);
});
layout->addWidget(title);
layout->addWidget(combobox);
m_exteriorwidget->setLayout(layout);
}
void GlobalThemeWidget::initFilletWidget()
{
m_filletwidget = new QWidget(m_viewportwidget);
m_filletwidget->setFixedHeight(65);
QLabel *title = new QLabel(m_filletwidget);
title->setFixedWidth(m_filletwidget->width());
title->setText("控件圆角");
QHBoxLayout *layout = new QHBoxLayout();
QSlider *filletslider = new QSlider(m_filletwidget);
filletslider->setOrientation(Qt::Horizontal);
filletslider->setFixedWidth(210);
filletslider->setRange(0,18);
filletslider->setSingleStep(1);
filletslider->setTickInterval(1);
filletslider->setFixedWidth(120);
filletslider->setValue(6);
QPushButton *showButton = new QPushButton(m_filletwidget);
showButton->setDisabled(true);
showButton->setFixedSize(60,36);
int value = 0;
value = filletslider->value();
showButton->setText(QString::number(filletslider->value())+"px");
QObject::connect(filletslider, &QSlider::valueChanged, [=](int value) {
showButton->setText(QString::number(value)+"px");
m_preview->updatescale();
m_preview->updateWidgetRadius(value);
emit newRadius(value);
});
layout->addWidget(title);
layout->addStretch(1);
layout->addWidget(filletslider);
layout->addWidget(showButton);
m_filletwidget->setLayout(layout);
}
void GlobalThemeWidget::AccentColorWidget()
{
m_accentcolorwidget = new QWidget(m_viewportwidget);
m_accentcolorwidget = new QWidget(m_viewportwidget);
m_accentcolorwidget->setFixedHeight(65);
QLabel *title = new QLabel(m_accentcolorwidget);
title->setFixedWidth(m_accentcolorwidget->width());
title->setText("强调色");
QHBoxLayout *layout = new QHBoxLayout();
QComboBox *combobox = new QComboBox(m_accentcolorwidget);
combobox->addItem("daybreakBlue",QColor(55, 144, 250));
combobox->addItem("jamPurple", QColor(120, 115, 245));
combobox->addItem("magenta", QColor(235, 48, 150));
combobox->addItem("sunRed", QColor(243, 34, 45));
combobox->addItem("sunsetOrange", QColor(246, 140, 39));
combobox->addItem("dustGold", QColor(249, 197, 61));
combobox->addItem("polarGreen", QColor(82, 196, 41));
connect(combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index){
QColor selectedColor = combobox->itemData(index).value<QColor>();
qDebug() << "Selected color:" << selectedColor;
qDebug() << "RGB values:" << selectedColor.red() << selectedColor.green() << selectedColor.blue();
m_preview->updatescale();
m_preview->updateButtonColor(selectedColor);
emit newAccentColor(selectedColor);
});
layout->addWidget(title);
layout->addWidget(combobox);
m_accentcolorwidget->setLayout(layout);
}
void GlobalThemeWidget::updateWallpaperFilePath(const QString& coverFilePath) {
m_wallpaperpath = coverFilePath;
if (m_preview != nullptr) {
delete m_preview;
delete m_previewlayout;
m_previewwidget->setMinimumSize(495,620);
m_previewwidget->setBackgroundRole(QPalette::Window);
m_preview = new GlobalImageWidget(m_previewwidget,m_wallpaperpath);
m_previewlayout = new QVBoxLayout(m_previewwidget);
addspaceritem();
m_previewwidget->setLayout(m_previewlayout);
}
}
void GlobalThemeWidget::addspaceritem()
{
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
QSpacerItem *spacer2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
spacer->changeSize(m_previewwidget->width(), 155, QSizePolicy::Maximum, QSizePolicy::Maximum);
spacer2->changeSize(m_previewwidget->width(), 159, QSizePolicy::Maximum, QSizePolicy::Maximum);
m_previewlayout->addItem(spacer);
m_previewlayout->addWidget(m_preview);
m_previewlayout->addItem(spacer2);
}

View File

@ -1,63 +0,0 @@
#ifndef GLOBALTHEMEWIDGET_H
#define GLOBALTHEMEWIDGET_H
#include "globalthemefeature.h"
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QPainter>
#include <QScrollArea>
#include <QLabel>
#include <QMap>
#include <QFileDialog>
#include <QStackedWidget>
#include <QComboBox>
class GlobalThemeWidget : public QWidget
{
Q_OBJECT
public:
explicit GlobalThemeWidget(QWidget *parent = nullptr);
QString getWallpaperPath();
signals:
void wallpaperupdate(const QString& filePath);
void newWallpaperFilePath(const QString& path);
void newCoverFilePath(const QString& path);
void newRadius(const int radius);
void newAccentColor(const QColor selectedColor);
void newExterior(const QColor selectedColor);
private:
void initPreviewWidget();
void initRightWidget();
void initCoverWidget();
void initWallPaperWidget();
void initExteriorWidget();
void initFilletWidget();
void AccentColorWidget();
void updateWallpaperFilePath(const QString& coverFilePath);
void addspaceritem();
QWidget *m_globalthemewidget;
QWidget *m_coverwidget;
QWidget *m_wallpaperwidget;
QWidget *m_exteriorwidget;
QWidget *m_filletwidget;
QWidget *m_accentcolorwidget;
QVBoxLayout *m_previewlayout;
QString m_wallpaperpath = ":/resource/background/background-light.png";
QString m_coverpath = ":/resource/background/background-light.png";
QWidget *m_viewportwidget;
QScrollArea *m_scrollArea;
QHBoxLayout *m_globalthemelayout;
QWidget *m_rightwidget;
QWidget *m_previewwidget;
GlobalImageWidget *m_preview;
};
#endif // GLOBALTHEMEWIDGET_H

View File

@ -1,257 +0,0 @@
#include "iconthemewidget.h"
#include "filecheck.h"
IconThemeWidget::IconThemeWidget(QWidget *parent) : QWidget(parent)
{
initMaps();
initSystemMaps();
initPreviewWidget();
initRightWidget();
QHBoxLayout * m_iconthemelayout = new QHBoxLayout();
m_iconthemelayout->addWidget(m_previewwidget);
m_iconthemelayout->addWidget(m_rightwidget);
this->setLayout(m_iconthemelayout);
}
void IconThemeWidget::initPreviewWidget()
{
m_previewwidget = new QWidget(this);
m_previewwidget->setMinimumSize(550,620);
m_previewstack = new QStackedWidget(m_previewwidget);
m_preview = new ImageWidget(m_previewwidget,m_iconpathmap);
m_systempreview = new ImageWidget(m_previewwidget,m_systemiconpathmap);
m_previewstack->addWidget(m_preview);
m_previewstack->addWidget(m_systempreview);
QVBoxLayout *layout = new QVBoxLayout(m_previewwidget);
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
QSpacerItem *spacer2 = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
spacer->changeSize(m_previewwidget->width(), 155, QSizePolicy::Maximum, QSizePolicy::Maximum);
spacer2->changeSize(m_previewwidget->width(), 159, QSizePolicy::Maximum, QSizePolicy::Maximum);
connect(this,&IconThemeWidget::wallpaperupdate, m_preview,[=](const QString& filePath){
m_preview->updateImage(filePath);
});
layout->addItem(spacer);
layout->addWidget(m_previewstack);
layout->addItem(spacer2);
m_previewwidget->setLayout(layout);
}
void IconThemeWidget::initEditWidget()
{
m_editwidget = new QWidget(m_stackedwidget);
QScrollArea *m_scrollArea = new QScrollArea(m_rightwidget);
m_scrollArea->setMinimumSize(m_editwidget->size());
m_scrollArea->setWidgetResizable(true);
QWidget *viewportWidget = new QWidget(m_scrollArea);
m_scrollArea->setWidget(viewportWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(viewportWidget);
viewportWidget->setLayout(mainLayout);
for (auto it = m_iconpathmap->begin(); it != m_iconpathmap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
IconEditWidget* widget = new IconEditWidget(viewportWidget);
widget->setdefaulticon(filePath);
widget->setdefaulticonname(widgetName);
mainLayout->addWidget(widget);
m_pathWidgetMap->insert(widgetName, widget);
connect(widget->m_addiconbutton, &QPushButton::clicked, this, [=]() {
QPushButton* clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton) {
IconEditWidget* clickedWidget = nullptr;
QWidget *widget = clickedButton->parentWidget();
while (widget && !widget->inherits("IconEditWidget")) {
widget = widget->parentWidget();
}
clickedWidget = qobject_cast<IconEditWidget*>(widget);
if (clickedWidget) {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择SVG文件"), "", tr("SVG 文件 (*.svg)"));
if (!newFilePath.isEmpty()) {
m_customiconpathmap->insert(widgetName, newFilePath);
clickedWidget->setcustomicon(newFilePath);
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
m_preview->updateIcon(widgetName, newFilePath);
}
emit newAppIconsMap(m_customiconpathmap);
}
}
});
}
QVBoxLayout *mainWidgetLayout = new QVBoxLayout(m_editwidget);
mainWidgetLayout->addWidget(m_scrollArea);
m_editwidget->setLayout(mainWidgetLayout);
}
void IconThemeWidget::initSystemEditWidget()
{
m_systemeditwidget = new QWidget(m_stackedwidget);
QScrollArea *m_systemscrollArea = new QScrollArea(m_rightwidget);
m_systemscrollArea->setWidgetResizable(true);
QWidget *viewportWidget = new QWidget(m_systemscrollArea);
m_systemscrollArea->setWidget(viewportWidget);
QVBoxLayout *mainLayout = new QVBoxLayout(viewportWidget);
viewportWidget->setLayout(mainLayout);
for (auto it = m_systemiconpathmap->begin(); it != m_systemiconpathmap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
qDebug() <<"key----------" <<widgetName <<"value-----------" <<it.value();
IconEditWidget* widget = new IconEditWidget(viewportWidget);
widget->setdefaulticon(filePath);
widget->setdefaulticonname(widgetName);
mainLayout->addWidget(widget);
m_systempathWidgetMap->insert(widgetName, widget);
connect(widget->m_addiconbutton, &QPushButton::clicked, this, [=]() {
QPushButton* clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton) {
IconEditWidget* clickedWidget = nullptr;
QWidget *widget = clickedButton->parentWidget();
while (widget && !widget->inherits("IconEditWidget")) {
widget = widget->parentWidget();
}
clickedWidget = qobject_cast<IconEditWidget*>(widget);
if (clickedWidget) {
QString newFilePath = QFileDialog::getOpenFileName(this, tr("选择SVG文件"), "", tr("SVG 文件 (*.svg)"));
if (!newFilePath.isEmpty()) {
//check
if(FileCheck::isLegalIconFile(newFilePath)){
m_systemcustomiconpathmap->insert(widgetName, newFilePath);
clickedWidget->setcustomicon(newFilePath);
qDebug() << "Selected file path:" << newFilePath<< "Corresponding widgetName:" << widgetName;
m_systempreview->updateIcon(widgetName, newFilePath);
}
}
emit newSystemIconsMap(m_systemcustomiconpathmap);
}
}
});
}
QVBoxLayout *mainWidgetLayout = new QVBoxLayout(m_systemeditwidget);
mainWidgetLayout->addWidget(m_systemscrollArea);
m_systemeditwidget->setLayout(mainWidgetLayout);
}
QStringList IconThemeWidget::getWidgetNamesFromFilesInDirectory(const QString& directoryPath) {
QStringList widgetNames;
QDir dir(directoryPath);
QStringList fileNames = dir.entryList(QDir::Files);
foreach (const QString& fileName, fileNames) {
QFileInfo fileInfo(fileName);
QString widgetName = fileInfo.baseName();
widgetNames.append(widgetName);
}
return widgetNames;
}
void IconThemeWidget::initMaps()
{
m_iconpathmap = new QMap<QString, QString>;
QString directoryPath = ":/resource/appicons/";
QStringList widgetNames = getWidgetNamesFromFilesInDirectory(directoryPath);
for (int i = 0; i < widgetNames.size(); ++i) {
qDebug() << widgetNames[i];
QString cursorFileName = directoryPath + widgetNames[i] + ".png";
m_iconpathmap->insert(widgetNames[i], cursorFileName);
}
m_customiconpathmap = m_iconpathmap;
m_pathWidgetMap = new QMap<QString, IconEditWidget*>;
}
void IconThemeWidget::initSystemMaps()
{
m_systemiconpathmap = new QMap<QString, QString> ;
QString directoryPath = ":/resource/systemicons/";
QStringList widgetNames = getWidgetNamesFromFilesInDirectory(directoryPath);
for (int i = 0; i < widgetNames.size(); ++i) {
qDebug() << widgetNames[i];
QString cursorFileName = directoryPath + widgetNames[i] + ".png";
m_systemiconpathmap->insert(widgetNames[i], cursorFileName);
for (const auto& key : m_systemiconpathmap->keys()) {
const QString& value = m_systemiconpathmap->value(key);
qDebug() <<"key----------" <<m_systemiconpathmap->keys() <<"value-----------" <<value;
}
}
m_systemcustomiconpathmap= m_systemiconpathmap;
m_systempathWidgetMap = new QMap<QString, IconEditWidget*>;
}
void IconThemeWidget::initRightWidget()
{
m_rightwidget = new QWidget(this);
m_rightwidget->setMinimumSize(400,620);
m_rightwidget->setMaximumWidth(400);
m_rightwidgetlayout = new QVBoxLayout(m_rightwidget);
QWidget *m_changebuttonwidget = new QWidget(m_rightwidget);
m_changebuttonwidget->setMinimumSize(400,70);
QHBoxLayout *layout = new QHBoxLayout();
QButtonGroup *group = new QButtonGroup(m_changebuttonwidget);
m_appiconbtn = new QPushButton();
m_systemiconbtn = new QPushButton();
group->setExclusive(true);
group->addButton(m_appiconbtn);
group->addButton(m_systemiconbtn);
m_appiconbtn->setCheckable(true);
m_systemiconbtn->setCheckable(true);
m_appiconbtn->setChecked(true);
layout->addWidget(m_appiconbtn);
layout->addWidget(m_systemiconbtn);
m_changebuttonwidget->setLayout(layout);
m_stackedwidget = new QStackedWidget(m_rightwidget);
initEditWidget();
initSystemEditWidget();
m_stackedwidget->addWidget(m_editwidget);
m_stackedwidget->addWidget(m_systemeditwidget);
m_stackedwidget->setCurrentIndex(0);
QObject::connect(m_appiconbtn, &QPushButton::clicked,m_stackedwidget, [=]() {
m_stackedwidget->setCurrentIndex(0);
m_previewstack->setCurrentIndex(0);
});
QObject::connect(m_systemiconbtn, &QPushButton::clicked,m_stackedwidget, [=](){
m_stackedwidget->setCurrentIndex(1);
m_previewstack->setCurrentIndex(1);
});
m_rightwidgetlayout->addWidget(m_changebuttonwidget);
m_rightwidgetlayout->addWidget(m_stackedwidget);
m_rightwidget->setLayout(m_rightwidgetlayout);
}

View File

@ -1,62 +0,0 @@
#ifndef ICONTHEMEWIDGET_H
#define ICONTHEMEWIDGET_H
#include "iconwidgetfeature.h"
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QPainter>
#include <QScrollArea>
#include <QLabel>
#include <QMap>
#include <QDebug>
#include <QFileDialog>
#include <QStackedWidget>
#include <QObject>
#include <QWidget>
class IconThemeWidget : public QWidget
{
Q_OBJECT
public:
explicit IconThemeWidget(QWidget *parent = nullptr);
void initPreviewWidget();
void initEditWidget();
void initSystemEditWidget();
void initMaps();
void initSystemMaps();
void initRightWidget();
signals:
void wallpaperupdate(const QString& filePath);
void newAppIconsMap(QMap<QString, QString> *appiconsmap);
void newSystemIconsMap(QMap<QString, QString> *systemiconsmap);
private:
QStringList getWidgetNamesFromFilesInDirectory(const QString& directoryPath);
QStackedWidget *m_themestackedwidget;
QWidget *m_rightwidget;
QVBoxLayout *m_rightwidgetlayout;
QStackedWidget *m_stackedwidget;
QPushButton *m_appiconbtn;
QPushButton *m_systemiconbtn;
QMap<QString, QString> *m_iconpathmap;
QMap<QString, QString> *m_customiconpathmap;
QMap<QString, IconEditWidget*> *m_pathWidgetMap;
QMap<QString, QString> *m_systemiconpathmap;
QMap<QString, QString> *m_systemcustomiconpathmap;
QMap<QString, IconEditWidget*> *m_systempathWidgetMap;
QWidget *m_previewwidget;
ImageWidget *m_preview;
ImageWidget *m_systempreview;
QStackedWidget *m_previewstack;
QWidget *m_editwidget;
QWidget *m_systemeditwidget;
};
#endif // ICONTHEMEWIDGET_H

View File

@ -1,336 +0,0 @@
#include "iconwidgetfeature.h"
MainInterFaceFeature::MainInterFaceFeature(QWidget *parent) : QWidget(parent)
{
}
TypeButton::TypeButton(QWidget *parent): QPushButton(parent)
{
setCheckable(true);
}
void TypeButton::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
if (isChecked()) {
QPainter painter(this);
QIcon icon = QIcon::fromTheme("kylin-settings-account");
QPixmap pixmap = icon.pixmap(QSize(16, 16));
QRect pixmapRect(rect().right() - pixmap.width(), (rect().height() - pixmap.height()) / 2, pixmap.width(), pixmap.height());
painter.drawPixmap(pixmapRect, pixmap);
}
}
IconGraphicsView::IconGraphicsView(QGraphicsScene* scene) : QGraphicsView(scene)
{
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setDragMode(QGraphicsView::ScrollHandDrag);
setRenderHint(QPainter::Antialiasing, true);
setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing |QGraphicsView::DontSavePainterState);
this->setStyleSheet("background-color: transparent;");
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void IconGraphicsView::wheelEvent(QWheelEvent* event)
{
// if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
// qreal scaleFactor = std::pow(qreal(2), event->delta() / 240.0);
// scale(scaleFactor, scaleFactor);
// } else {
// QGraphicsView::wheelEvent(event);
// }
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
qreal scaleFactor = std::pow(qreal(2), event->delta() / 240.0);
qreal currentScale = transform().m11(); // 获取当前的缩放倍数
// 限制最大为1.1倍
qreal targetScale = currentScale * scaleFactor;
if (targetScale > 1.1) {
scaleFactor = 1.1 / currentScale;
}else if (targetScale < 0.3) {
scaleFactor = 0.3 / currentScale;
}
scale(scaleFactor, scaleFactor);
} else {
QGraphicsView::wheelEvent(event);
}
}
ImageWidget::ImageWidget(QWidget *parent, const QMap<QString, QString>* iconMap)
: QWidget(parent), m_iconMap(iconMap)
{
QGraphicsScene* scene = new QGraphicsScene(this);
scene->setBackgroundBrush(Qt::transparent);
graphicsView = new IconGraphicsView(scene);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(graphicsView);
setLayout(layout);
int count = m_iconMap->size();
if(count == 11){
image = new QPixmap(":/resource/background/controlcenter-light.png");
if (image->isNull()) {
qDebug() << "Failed to load image.";
}
}else{
image = new QPixmap(":/resource/background/background-light.png");
if (image->isNull()) {
qDebug() << "Failed to load image.";
}
}
scene->addPixmap(*image);
graphicsView->setScene(scene);
graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
graphicsView->show();
if (count == 11) {
QList<QString> keys = m_iconMap->keys();
QString positions[11] = { keys[0], keys[9], keys[4], keys[5], keys[6],
keys[3], keys[10], keys[8], keys[1], keys[7], keys[2] };
int posX[3] = { 208, 879, 1550 };
int posY[4] = { 275, 535, 795, 1055 };
int index = 0;
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 3; ++j) {
if (index >= 11) {
break; // 处理超出索引范围的情况
}
QString pixmapPath = m_iconMap->value(positions[index]);
QPixmap pixmap(pixmapPath);
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(100, 100));
item->setFlag(QGraphicsItem::ItemIsSelectable); // 启用选择事件
item->setFlag(QGraphicsItem::ItemIsFocusable); // 启用焦点事件
item->setData(0, keys[index]);
item->setData(1, pixmapPath);
item->setPos(posX[j], posY[i]);
++index;
}
}
}
else{
int columnCount = 10;
int row = 1;
int col = 2;
for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
QPixmap pixmap(filePath);
if (!pixmap.isNull()) {
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128));
item->setFlag(QGraphicsItem::ItemIsSelectable); // 启用选择事件
item->setFlag(QGraphicsItem::ItemIsFocusable); // 启用焦点事件
item->setPos(col * 160, row * 160);
item->setScale(1.0);
item->setData(0, widgetName);
item->setData(1, filePath);
qDebug()<<"widgetName"<<widgetName<<"filePath"<<filePath;
col++;
if (col >= columnCount) {
col = 2;
row++;
}
} else {
qDebug() << "Failed to load image:" << filePath;
}
}
}
// 设置初始缩放倍数为0.9倍
qreal initialScale = 0.9;
graphicsView->scale(initialScale, initialScale);
}
void ImageWidget::updateImage(const QString& imagePath)
{
if (image != nullptr) {
delete image;
image = nullptr;
}
image = new QPixmap(imagePath);
if (image->isNull()) {
qDebug() << "Failed to load image.";
}
QGraphicsScene* scene = graphicsView->scene();
scene->clear();
scene->addPixmap(*image);
int columnCount = 10;
int row = 1;
int col = 2;
for (auto it = m_iconMap->begin(); it != m_iconMap->end(); ++it) {
const QString& widgetName = it.key();
const QString& filePath = it.value();
QPixmap pixmap(filePath);
if (!pixmap.isNull()) {
QGraphicsPixmapItem* item = scene->addPixmap(pixmap.scaled(128, 128));
item->setPos(col * 160, row * 160);
item->setScale(1.0);
item->setData(0, widgetName);
item->setData(1, filePath);
col++;
if (col >= columnCount) {
col = 2;
row++;
}
} else {
qDebug() << "Failed to load image:" << filePath;
}
}
graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
}
void ImageWidget::updateIcon(const QString& widgetName, const QString& newFilePath)
{
QGraphicsScene* scene = graphicsView->scene();
QList<QGraphicsItem*> items = scene->items();
for (int i = 0; i < items.size(); ++i) {
QGraphicsItem* item = items.at(i);
// 输出item的内容例如位置和类型等信息
qDebug() << "Item" << i << ":"
<< "Position:" << item->pos()
<< "Type:" << item->type();
}
for (QGraphicsItem* item : items) {
QGraphicsPixmapItem* pixmapItem = dynamic_cast<QGraphicsPixmapItem*>(item);
qDebug()<<widgetName<<"!!!!!!!!!!!";
if (pixmapItem && pixmapItem->data(0).toString() == widgetName) {
qDebug()<<"!!!!!sss!!!!!!";
QPointF oldPosition = pixmapItem->pos();
scene->removeItem(pixmapItem);
delete pixmapItem;
QPixmap newPixmap(newFilePath);
if (!newPixmap.isNull()) {
if(widgetName.contains("kylin-setting")){
QGraphicsPixmapItem* newPixmapItem = scene->addPixmap(newPixmap.scaled(100, 100));
newPixmapItem->setData(0, widgetName);
newPixmapItem->setData(1, newFilePath);
newPixmapItem->setPos(oldPosition);
}else{
QGraphicsPixmapItem* newPixmapItem = scene->addPixmap(newPixmap.scaled(128, 128));
newPixmapItem->setData(0, widgetName);
newPixmapItem->setData(1, newFilePath);
newPixmapItem->setPos(oldPosition);
}
} else {
qDebug() << "Failed to load image:" << newFilePath;
}
return;
}
}
}
IconEditWidget::IconEditWidget(QWidget *parent)
{
QVBoxLayout *widgetLayout = new QVBoxLayout(this);
// 创建一个 QFrame 作为边框容器
QFrame *frame = new QFrame(this);
frame->setFrameShape(QFrame::Box); // 设置边框样式
frame->setLineWidth(1); // 设置边框宽度为 2 像素
QVBoxLayout *innerLayout = new QVBoxLayout();
m_label = new QLabel();
QWidget *editwidget = new QWidget();
QHBoxLayout *m_iconwidgetlayout = new QHBoxLayout();
m_icondefaultlabel = new QLabel();
m_icondefaultlabel->setFixedSize(48,48);
m_icondecustomlabel = new CustomLabel();
m_addiconbutton = new QPushButton();
m_addiconbutton->setIcon(QIcon::fromTheme("list-add-symbolic"));
m_addiconbutton->setFixedSize(36,36);
QLabel *m_tiplabel = new QLabel();
m_tiplabel->setWordWrap(true);
m_tiplabel->setText("<html>格式svg<br>尺寸96*96</html>");
m_iconwidgetlayout->addWidget(m_icondefaultlabel);
m_iconwidgetlayout->addWidget(m_icondecustomlabel);
m_iconwidgetlayout->addWidget(m_addiconbutton);
m_iconwidgetlayout->addWidget(m_tiplabel);
editwidget->setLayout(m_iconwidgetlayout);
innerLayout->addWidget(m_label);
innerLayout->addWidget(editwidget);
frame->setLayout(innerLayout);
widgetLayout->addWidget(frame);
}
void IconEditWidget::setdefaulticon(QString iconname)
{
m_icondefaultlabel->setPixmap(QIcon::fromTheme(iconname).pixmap(48,48));
}
void IconEditWidget::setdefaulticonname(QString iconname)
{
m_label->setText(iconname);
}
void IconEditWidget::setcustomicon(QString iconFilePath)
{
QPixmap pixmap(iconFilePath);
m_icondecustomlabel->setPixmap(pixmap.scaled(48, 48));
}
CustomLabel::CustomLabel(QWidget *parent): QLabel(parent), pixmap()
{
this->setFixedSize(48,48);
}
void CustomLabel::paintEvent(QPaintEvent *event)
{
QLabel::paintEvent(event);
QPainter painter(this);
QPen pen(Qt::blue);
pen.setStyle(Qt::DashLine);
painter.setPen(pen);
QBrush brush(QColor("#F5F5F5"));
painter.setBrush(brush);
QRect roundedRect = rect().adjusted(1, 1, -1, -1);
QPainterPath path;
int radius = 6;
path.addRoundedRect(roundedRect, radius, radius);
painter.drawPath(path);
if (!pixmap.isNull()) {
painter.drawPixmap(rect(), pixmap);
}
}
void CustomLabel::setPixmap(const QPixmap &pixmap)
{
this->pixmap = pixmap;
update();
}

View File

@ -1,95 +0,0 @@
#ifndef MAININTERFACEFEATURE_H
#define MAININTERFACEFEATURE_H
#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QButtonGroup>
#include <QPainter>
#include <QScrollArea>
#include <QLabel>
#include <QMap>
#include <QDebug>
#include <QFileDialog>
#include <QStackedWidget>
#include <QWheelEvent>
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QDebug>
#include <QKeyEvent>
#include <QWheelEvent>
#include <QtMath>
#include <QGraphicsPixmapItem>
class MainInterFaceFeature : public QWidget
{
Q_OBJECT
public:
explicit MainInterFaceFeature(QWidget *parent = nullptr);
};
class TypeButton : public QPushButton
{
public:
TypeButton(QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *event) override;
};
class IconGraphicsView : public QGraphicsView {
public:
explicit IconGraphicsView(QGraphicsScene* scene);
protected:
void wheelEvent(QWheelEvent* event) override;
};
class ImageWidget : public QWidget {
public:
ImageWidget(QWidget *parent = nullptr, const QMap<QString,QString>* iconMap = nullptr);
void setIconMap(QMap<QString,QString>*);
void updateIcon(const QString& widgetName, const QString& newFilePath);
void updateImage(const QString& imagePath);
private:
const QMap<QString,QString>* m_iconMap;
QPixmap* image;
IconGraphicsView* graphicsView;
QString m_coverFilePath;
};
class CustomLabel : public QLabel {
public:
explicit CustomLabel(QWidget* parent = nullptr);
void setPixmap(const QPixmap& pixmap);
protected:
void paintEvent(QPaintEvent* event) override;
private:
QPixmap pixmap;
};
class IconEditWidget : public QWidget
{
Q_OBJECT
public:
IconEditWidget(QWidget *parent = nullptr);
void setdefaulticon(QString iconname);
void setdefaulticonname(QString iconname);
void setcustomicon(QString iconFilePath);
QLabel *m_label;
QPushButton *m_addiconbutton;
private:
QLabel *m_icondefaultlabel;
CustomLabel *m_icondecustomlabel;
};
#endif // MAININTERFACEFEATURE_H

View File

@ -1,7 +0,0 @@
#include "infocreatefeature.h"
//theme info proecessing
InfoCreateFeature::InfoCreateFeature()
{
}

View File

@ -1,20 +0,0 @@
#ifndef INFOCREATEFEATURE_H
#define INFOCREATEFEATURE_H
#include <QObject>
#include <QDir>
#include <QDateTime>
#include <QDebug>
#include "infocreatewidget.h"
class InfoCreateFeature
{
public:
InfoCreateFeature();
private:
};
#endif // INFOCREATEFEATURE_H

View File

@ -1,295 +0,0 @@
#include "infocreatewidget.h"
//create theme info graphical interface
InfoCreateWidget::InfoCreateWidget(QWidget *parent, const QString &m_date,
const QString &m_state) : QWidget(parent)
{
this->setFixedSize(424,404);
this->setWindowModality(Qt::ApplicationModal);
InitThemeName();
InitBuilderInfo();
InitInfoBtn(m_state);
InfoProcess(m_date);
m_warningMessage = new QLabel();
m_warningMessage->setText("");
m_warningMessage2 = new QLabel();
m_warningMessage2->setText("");
m_warningMessage3 = new QLabel();
m_warningMessage3->setText("");
m_warningMessage4 = new QLabel();
m_warningMessage4->setText("");
QVBoxLayout *m_infoCreateLayout = new QVBoxLayout(this);
m_infoCreateLayout->addLayout(m_themeNameCNLayout);
m_infoCreateLayout->addWidget(m_warningMessage);
m_infoCreateLayout->addLayout(m_themeNameENLayout);
m_infoCreateLayout->addWidget(m_warningMessage2);
m_infoCreateLayout->addLayout(m_builderNameLayout);
m_infoCreateLayout->addWidget(m_warningMessage3);
m_infoCreateLayout->addLayout(m_builderMailLayout);
m_infoCreateLayout->addWidget(m_warningMessage4);
m_infoCreateLayout->addLayout(m_infoBtnLayout);
this->setLayout(m_infoCreateLayout);
}
void InfoCreateWidget::InitThemeName(){
m_themeNameCNLayout = new QHBoxLayout();
m_themeNameCNLabel = new QLabel();
m_themeNameCNLineEdit = new QLineEdit();
m_themeNameCNLabel->setText("ThemeName-CN");
m_themeNameCNLineEdit->setEchoMode(QLineEdit::Normal);
m_themeNameCNLayout->addWidget(m_themeNameCNLabel);
m_themeNameCNLayout->addWidget(m_themeNameCNLineEdit);
m_themeNameENLayout = new QHBoxLayout();
m_themeNameENLabel = new QLabel();
m_themeNameENLineEdit = new QLineEdit();
m_themeNameENLabel->setText("ThemeName-EN");
m_themeNameENLineEdit->setEchoMode(QLineEdit::Normal);
m_themeNameENLayout->addWidget(m_themeNameENLabel);
m_themeNameENLayout->addWidget(m_themeNameENLineEdit);
}
void InfoCreateWidget::InitBuilderInfo(){
m_builderNameLayout = new QHBoxLayout();
m_builderNameLabel = new QLabel();
m_builderNameLineEdit = new QLineEdit();
m_builderNameLabel->setText("Builder Name");
m_builderNameLineEdit->setEchoMode(QLineEdit::Normal);
m_builderNameLayout->addWidget(m_builderNameLabel);
m_builderNameLayout->addWidget(m_builderNameLineEdit);
m_builderMailLayout = new QHBoxLayout();
m_builderMailLabel = new QLabel();
m_builderMailLineEdit = new QLineEdit();
m_builderMailLabel->setText("Builder Mail");
m_builderMailLineEdit->setEchoMode(QLineEdit::Normal);
m_builderMailLayout->addWidget(m_builderMailLabel);
m_builderMailLayout->addWidget(m_builderMailLineEdit);
}
void InfoCreateWidget::InitInfoBtn(const QString &m_state){
m_infoBtnLayout = new QHBoxLayout();
m_exitBtn = new QPushButton();
m_recogniseBtn = new QPushButton();
m_createDebBtn = new QPushButton();
m_exitBtn->setText("Back");
m_recogniseBtn->setText("OK");
m_createDebBtn->setText("Create");
m_infoBtnLayout->addWidget(m_exitBtn);
m_infoBtnLayout->addWidget(m_recogniseBtn);
m_infoBtnLayout->addWidget(m_createDebBtn);
if(m_state == "recognise"){
m_recogniseBtn->setHidden(false);
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setHidden(true);
} else if(m_state == "create"){
if (m_builderNameLineEdit->text() != nullptr && m_themeNameENLineEdit->text() != nullptr
&& m_builderMailLineEdit->text() != nullptr ){
m_recogniseBtn->setHidden(true);
m_createDebBtn->setHidden(false);
m_createDebBtn->setEnabled(true);
} else {
m_recogniseBtn->setHidden(true);
m_createDebBtn->setHidden(false);
m_createDebBtn->setEnabled(false);
}
} else {
qDebug() << m_state;
}
}
void InfoCreateWidget::InfoProcess(const QString &m_date){
m_themeENNameState = false;
m_builderMailState = false;
m_builderNameState = false;
// 监听文本变化
QObject::connect(m_themeNameCNLineEdit, &QLineEdit::textChanged, [this]() {
m_warningMessage->setText("11111111111");
});
QObject::connect(m_themeNameENLineEdit, &QLineEdit::textChanged, [this]() {
m_themeENName = m_themeNameENLineEdit->text();
QRegExp englishRegexp("[A-Za-z0-9]+$");
if(m_themeNameENLineEdit != nullptr){
if (englishRegexp.exactMatch(m_themeENName)){
m_warningMessage2->setText("");
m_themeENNameState = true;
if (m_themeENNameState && m_builderMailState && m_builderNameState){
m_recogniseBtn->setEnabled(true);
m_createDebBtn->setEnabled(true);
} else {
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
m_fontqpe.setColor(QPalette::WindowText,Qt::red);
m_warningMessage2->setPalette(m_fontqpe);
m_warningMessage2->setText("输入格式错误!");
m_themeENNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
m_fontqpe.setColor(QPalette::WindowText,Qt::red);
m_warningMessage2->setPalette(m_fontqpe);
m_warningMessage2->setText("输入为空!");
m_themeENNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
});
QObject::connect(m_builderNameLineEdit, &QLineEdit::textChanged, [this]() {
m_builderName = m_builderNameLineEdit->text();
QRegExp englishRegexp("[A-Za-z0-9]+$");
if(m_themeNameENLineEdit != nullptr){
if (englishRegexp.exactMatch(m_builderName)){
m_warningMessage3->setText("");
m_builderNameState = true;
if (m_themeENNameState && m_builderMailState && m_builderNameState){
m_recogniseBtn->setEnabled(true);
m_createDebBtn->setEnabled(true);
} else {
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
m_fontqpe.setColor(QPalette::WindowText,Qt::red);
m_warningMessage3->setPalette(m_fontqpe);
m_warningMessage3->setText("输入格式错误!");
m_builderNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
m_fontqpe.setColor(QPalette::WindowText,Qt::red);
m_warningMessage3->setPalette(m_fontqpe);
m_warningMessage3->setText("输入为空!");
m_builderNameState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
});
QObject::connect(m_builderMailLineEdit, &QLineEdit::textChanged, [this]() {
m_builderMail = m_builderMailLineEdit->text();
QRegExp mailRegexp("\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}\\b");
if(m_themeNameENLineEdit != nullptr){
if (mailRegexp.exactMatch(m_builderMail)){
m_warningMessage4->setText("");
m_builderMailState = true;
if (m_themeENNameState && m_builderNameState && m_builderMailState){
m_recogniseBtn->setEnabled(true);
m_createDebBtn->setEnabled(true);
} else {
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
m_fontqpe.setColor(QPalette::WindowText,Qt::red);
m_warningMessage4->setPalette(m_fontqpe);
m_warningMessage4->setText("输入格式错误!");
m_builderMailState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
} else {
QPalette m_fontqpe;
m_fontqpe.setColor(QPalette::WindowText,Qt::red);
m_warningMessage4->setPalette(m_fontqpe);
m_warningMessage4->setText("输入为空!");
m_builderMailState = false;
m_recogniseBtn->setEnabled(false);
m_createDebBtn->setEnabled(false);
}
});
//退出信息收集页面
connect(m_exitBtn, &QPushButton::clicked,this,[=](){
this->close();
});
//创建control/changelog文件
connect(m_recogniseBtn, &QPushButton::clicked,this,[=](){
createControlChangelog(m_date);
});
//获取已输入信息,再次确认后开始编译
connect(m_createDebBtn,&QPushButton::clicked,this,[=](){
createControlChangelog(FileProcess::g_date);
//清空日期缓存
FileProcess::g_date = nullptr;
//发送文件复制信号
emit readytoBuild();
});
}
void InfoCreateWidget::createControlChangelog(const QString &m_date){
//点击生成制作主题包按钮时m_date将设为空
qDebug()<<m_date;
if(m_date != nullptr){
QFile m_control(QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control");
if (m_control.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
qDebug()<< m_control;
QTextStream m_controlStream(&m_control);
m_controlStream << QStringLiteral("Source: ") + m_themeENName;
m_controlStream << endl << QStringLiteral("Section: misc");
m_controlStream << endl << QStringLiteral("Priority: optional");
m_controlStream << endl << QStringLiteral("Maintainer: ") + m_builderName + QStringLiteral(" <") + m_builderMail + QStringLiteral(">");
m_controlStream << endl << QStringLiteral("Build-Depends: debhelper-compat (= 13), dh-python, python3-setuptools, python3-all");
m_controlStream << endl << QStringLiteral("Standards-Version: 4.6.0");
m_controlStream << endl << QStringLiteral("Rules-Requires-Root: no");
m_controlStream << endl;
m_controlStream << endl << QStringLiteral("Package: ") + m_themeENName;
m_controlStream << endl << QStringLiteral("Architecture: all");
m_controlStream << endl << QStringLiteral("Depends: ${python3:Depends}, ${misc:Depends}");
m_controlStream << endl << QStringLiteral("Description: Theme Package ") + m_themeENName;
}
QFile m_changelog(QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/changelog");
if (m_changelog.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)){
QTextStream m_changelogStream(&m_changelog);
m_changelogStream << m_themeENName + QStringLiteral(" (1.0-1) UNRELEASED; urgency=medium");
m_changelogStream << endl;
m_changelogStream << endl << QStringLiteral(" * Initial release");
m_changelogStream << endl;
m_changelogStream << endl << QStringLiteral(" -- ") + m_builderName + QStringLiteral(" <") + m_builderMail
+ QStringLiteral("> Wed, 30 Aug 2023 14:42:06 +0800");
}
this->close();
}
}
void InfoCreateWidget::getFileInfo(const QMap<QString, QVariant> &m_packageInfo){
m_themeNameENLineEdit->setText(m_packageInfo.value("key1").toString());
m_builderNameLineEdit->setText(m_packageInfo.value("key2").toString());
m_builderMailLineEdit->setText(m_packageInfo.value("key3").toString());
}

View File

@ -1,77 +0,0 @@
#ifndef INFOCREATEWIDGET_H
#define INFOCREATEWIDGET_H
#include "fileprocess.h"
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QButtonGroup>
#include <QPainter>
#include <QScrollArea>
#include <QLabel>
#include <QMap>
#include <QDebug>
#include <QFileDialog>
#include <QStackedWidget>
#include <QObject>
#include <QWidget>
#include <QLineEdit>
#include <QRegExp>
#include <QRegularExpressionValidator>
class InfoCreateWidget : public QWidget
{
Q_OBJECT
public:
explicit InfoCreateWidget(QWidget *parent = nullptr);
explicit InfoCreateWidget(QWidget *parent, const QString &m_date, const QString &m_state);
void InitThemeName();
void InitBuilderInfo();
void InitInfoBtn(const QString &m_state);
void InfoProcess(const QString &m_date);
void InfoCreateBtn();
QString m_themeENName;
QString m_builderMail;
QString m_builderName;
void createControlChangelog(const QString &m_date);
void getFileInfo(const QMap<QString, QVariant> &m_packageInfo);
signals:
void readytoBuild();
private:
QLabel *m_warningMessage;
QLabel *m_warningMessage2;
QLabel *m_warningMessage3;
QLabel *m_warningMessage4;
QHBoxLayout *m_themeNameCNLayout;
QLabel *m_themeNameCNLabel;
QLineEdit *m_themeNameCNLineEdit;
QHBoxLayout *m_themeNameENLayout;
QLabel *m_themeNameENLabel;
QLineEdit *m_themeNameENLineEdit;
QHBoxLayout *m_builderNameLayout;
QLabel *m_builderNameLabel;
QLineEdit *m_builderNameLineEdit;
QHBoxLayout *m_builderMailLayout;
QLabel *m_builderMailLabel;
QLineEdit *m_builderMailLineEdit;
QHBoxLayout *m_infoBtnLayout;
QPushButton *m_exitBtn;
QPushButton *m_recogniseBtn;
QPushButton *m_createDebBtn;
bool m_themeENNameState;
bool m_builderNameState;
bool m_builderMailState;
};
#endif // INFOCREATEWIDGET_H

View File

@ -124,10 +124,10 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
});
QObject::connect(m_themeNameENLineEdit, &QLineEdit::textChanged, [this]() {
m_themeENName = m_themeNameENLineEdit->text();
FileProcess::g_themeENName = m_themeNameENLineEdit->text();
QRegExp englishRegexp("[A-Za-z0-9]+$");
if(m_themeNameENLineEdit != nullptr){
if (englishRegexp.exactMatch(m_themeENName)){
if (englishRegexp.exactMatch(FileProcess::g_themeENName)){
m_warningMessage2->setText("");
m_themeENNameState = true;
if (m_themeENNameState && m_builderMailState && m_builderNameState){
@ -240,13 +240,14 @@ void InfoCreateWidget::InfoProcess(const QString &m_date){
//获取已输入信息,再次确认后开始编译
connect(m_createDebBtn,&QPushButton::clicked,this,[=](){
createControlChangelog(FileProcess::g_date);
//清空日期缓存
FileProcess::g_date = nullptr;
//发送文件复制信号
emit readytoBuild();
// buildCheckWidget *m_buildCheckWidget = new buildCheckWidget();
// m_buildCheckWidget->show();
//编包前检查
buildCheckWidget *m_buildCheckWidget = new buildCheckWidget();
m_buildCheckWidget->buildCheck(QDir::homePath() + "/.cache/theme-build/" + FileProcess::g_date + "/src");
//清空日期缓存
// FileProcess::g_date = nullptr;
// FileProcess::g_themeENName = nullptr;
//发送返回主界面信号
emit backtoHome();
});
@ -256,31 +257,31 @@ void InfoCreateWidget::createControlChangelog(const QString &m_date){
//点击生成制作主题包按钮时m_date将设为空
qDebug()<<m_date;
if(m_date != nullptr){
QFile m_control(QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/control");
QFile m_control(QDir::homePath() + "/.cache/theme-build/" + m_date + "/src/debian/control");
if (m_control.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
qDebug()<< m_control;
QTextStream m_controlStream(&m_control);
m_controlStream << QStringLiteral("Source: ") + m_themeENName;
m_controlStream << QStringLiteral("Source: ") + FileProcess::g_themeENName;
m_controlStream << endl << QStringLiteral("Section: misc");
m_controlStream << endl << QStringLiteral("Priority: optional");
m_controlStream << endl << QStringLiteral("Maintainer: ") + m_builderName + QStringLiteral(" <") + m_builderMail + QStringLiteral(">");
m_controlStream << endl << QStringLiteral("Build-Depends: debhelper-compat (= 13), dh-python, python3-setuptools, python3-all");
m_controlStream << endl << QStringLiteral("Build-Depends: debhelper-compat (= 13)");
m_controlStream << endl << QStringLiteral("Standards-Version: 4.6.0");
m_controlStream << endl << QStringLiteral("Rules-Requires-Root: no");
m_controlStream << endl;
m_controlStream << endl << QStringLiteral("Package: ") + m_themeENName;
m_controlStream << endl << QStringLiteral("Package: ") + FileProcess::g_themeENName;
m_controlStream << endl << QStringLiteral("Architecture: all");
m_controlStream << endl << QStringLiteral("Depends: ${python3:Depends}, ${misc:Depends}");
m_controlStream << endl << QStringLiteral("Description: Theme Package ") + m_themeENName;
m_controlStream << endl << QStringLiteral("Depends: ${misc:Depends},${shlibs:Depends}");
m_controlStream << endl << QStringLiteral("Description: Theme Package ") + FileProcess::g_themeENName;
}
QFile m_changelog(QDir::homePath() + "/.cache/theme-build/" + m_date + "/debian/changelog");
QFile m_changelog(QDir::homePath() + "/.cache/theme-build/" + m_date + "/src/debian/changelog");
if (m_changelog.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)){
QTextStream m_changelogStream(&m_changelog);
m_changelogStream << m_themeENName + QStringLiteral(" (1.0-1) UNRELEASED; urgency=medium");
m_changelogStream << FileProcess::g_themeENName + QStringLiteral(" (1.0-1) UNRELEASED; urgency=medium");
m_changelogStream << endl;
m_changelogStream << endl << QStringLiteral(" * Initial release");
m_changelogStream << endl;

View File

@ -35,7 +35,6 @@ public:
void InfoProcess(const QString &m_date);
void InfoCreateBtn();
QString m_themeENName;
QString m_builderMail;
QString m_builderName;