add Transparency function
This commit is contained in:
parent
fd9c99390a
commit
b7974a5a96
|
@ -42,6 +42,11 @@ void Bridge::exteriorChanged(QColor accentcolor)
|
|||
|
||||
}
|
||||
|
||||
void Bridge::transparencyChanged(int transparency)
|
||||
{
|
||||
m_configfilemanager->modifyTransparencyConf(transparency);
|
||||
}
|
||||
|
||||
void Bridge::appIconsMapChanged(QMap<QString, QString> *appiconsmaps)
|
||||
{
|
||||
QMap<QString, QString>::const_iterator it;
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
void radiusChanged(int radius);
|
||||
void accentColorChanged(QColor accentcolor);
|
||||
void exteriorChanged(QColor accentcolor);
|
||||
void transparencyChanged(int transparency);
|
||||
void appIconsMapChanged(QMap<QString, QString> *appiconsmaps);
|
||||
void systemIconsMapChanged(QMap<QString, QString> *systemiconsmaps);
|
||||
void cursorMapChanged(QMap<QString, QString> *cursormap);
|
||||
|
|
|
@ -177,6 +177,37 @@ bool ConfigFileManager::modifyWallPaperConf(QString wallpaperpath)
|
|||
}
|
||||
}
|
||||
|
||||
bool ConfigFileManager::modifyTransparencyConf(int transparency)
|
||||
{
|
||||
// 读取文件内容
|
||||
QFile file(confFilePath);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug() << "无法打开文件:" << confFilePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QString content = in.readAll();
|
||||
file.close();
|
||||
|
||||
// 修改内容
|
||||
QString oldValue = "transparencyBlur=";
|
||||
QString newValue = QString("transparencyBlur=%1").arg(transparency);
|
||||
content.replace(QRegExp(oldValue + "\\d+"), newValue);
|
||||
|
||||
// 写入文件
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream out(&file);
|
||||
out << content;
|
||||
file.close();
|
||||
emit updateInfo();
|
||||
return true;
|
||||
} else {
|
||||
qDebug() << "无法写入文件:" << confFilePath;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigFileManager::copyFileContent(const QString &sourceFilePath, const QString &destinationFilePath)
|
||||
{
|
||||
QFile sourceFile(sourceFilePath);
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
bool modifyAccentColorConf(QColor accentcolor);
|
||||
bool modifyWallPaperConf(QString wallpaperpath);
|
||||
|
||||
bool modifyTransparencyConf(int transparency);
|
||||
|
||||
bool copyFileContent(const QString& sourceFilePath, const QString& destinationFilePath);
|
||||
bool copyIcontoCacheDir(QMap<QString, QString> *map,QDir cachedir);
|
||||
|
|
|
@ -13,6 +13,7 @@ HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent)
|
|||
getWallpaper();
|
||||
getAccentColor();
|
||||
getRadius();
|
||||
getTransparency();
|
||||
}
|
||||
|
||||
QString HistoryInfoLoad::getCover()
|
||||
|
@ -154,7 +155,6 @@ void HistoryInfoLoad::getAccentColor()
|
|||
QString content = in.readAll();
|
||||
file.close();
|
||||
|
||||
// 查找 wallPaperPath= 所在行的位置
|
||||
int startIndex = content.indexOf("accent=");
|
||||
if (startIndex != -1) {
|
||||
int lineStartIndex = content.lastIndexOf('\n', startIndex) + 1;
|
||||
|
@ -171,6 +171,42 @@ void HistoryInfoLoad::getAccentColor()
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryInfoLoad::getTransparency()
|
||||
{
|
||||
QString filePath = m_historyInfo.filepath + "/src/config/theme.conf";
|
||||
// 读取文件内容
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
|
||||
qDebug() << "无法打开文件:" << filePath;
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
QString content = in.readAll();
|
||||
file.close();
|
||||
|
||||
int startIndex = content.indexOf("transparencyBlur=");
|
||||
if (startIndex != -1) {
|
||||
int lineStartIndex = content.lastIndexOf('\n', startIndex) + 1;
|
||||
int lineEndIndex = content.indexOf('\n', startIndex);
|
||||
|
||||
if (lineEndIndex == -1) {
|
||||
lineEndIndex = content.size();
|
||||
}
|
||||
|
||||
QString lineContent = content.mid(lineStartIndex, lineEndIndex - lineStartIndex).trimmed();
|
||||
lineContent.remove("transparencyBlur=");
|
||||
|
||||
bool conversionSuccess = false;
|
||||
int transparencyBlurValue = lineContent.toInt(&conversionSuccess);
|
||||
if (conversionSuccess) {
|
||||
m_historyInfo.transparency = transparencyBlurValue;
|
||||
} else {
|
||||
qDebug() << "无法将字符串转换为整数:" << lineContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HistoryInfo HistoryInfoLoad::getInfoData()
|
||||
{
|
||||
qDebug()<<m_historyInfo.accentcolor<<m_historyInfo.wallpaperpath<<m_historyInfo.filepath;
|
||||
|
@ -185,5 +221,6 @@ void HistoryInfoLoad::updateHistoryInfo()
|
|||
getRadius();
|
||||
getWallpaper();
|
||||
getAccentColor();
|
||||
getTransparency();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ struct HistoryInfo {
|
|||
QString wallpaperpath = "";
|
||||
QString accentcolor = "";
|
||||
int radius = 6;
|
||||
int transparency = 65;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(HistoryInfo)
|
||||
|
@ -30,6 +31,7 @@ public:
|
|||
void getRadius();
|
||||
void getWallpaper();
|
||||
void getAccentColor();
|
||||
void getTransparency();
|
||||
HistoryInfo getInfoData();
|
||||
void updateHistoryInfo();
|
||||
signals:
|
||||
|
|
|
@ -29,6 +29,9 @@ MainInterface::MainInterface(QWidget *parent) : QWidget(parent)
|
|||
connect(m_globalthemewidget, &GlobalThemeWidget::newExterior, this, [&](const QColor selectedColor) {
|
||||
emit exteriorChanged(selectedColor);
|
||||
});
|
||||
connect(m_globalthemewidget, &GlobalThemeWidget::newTransparency, this, [&](const int transparency) {
|
||||
emit transparencyChanged(transparency);
|
||||
});
|
||||
connect(m_iconthemewidget, &IconThemeWidget::newAppIconsMap, this, [&]( QMap<QString, QString> *appiconsmaps) {
|
||||
emit appIconsMapChanged(appiconsmaps);
|
||||
});
|
||||
|
|
|
@ -47,6 +47,7 @@ signals:
|
|||
void wallpaperPathChanged(QString path);
|
||||
void coverPathChanged(QString path);
|
||||
void radiusChanged(int radius);
|
||||
void transparencyChanged(int transparency);
|
||||
void accentColorChanged(QColor accentcolor);
|
||||
void exteriorChanged(QColor exteriorcolor);
|
||||
void appIconsMapChanged(QMap<QString, QString> *appiconsmap);
|
||||
|
|
|
@ -24,6 +24,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(m_maininterface, &MainInterface::radiusChanged, m_bridge, &Bridge::radiusChanged);
|
||||
connect(m_maininterface, &MainInterface::accentColorChanged, m_bridge, &Bridge::accentColorChanged);
|
||||
connect(m_maininterface, &MainInterface::exteriorChanged, m_bridge, &Bridge::exteriorChanged);
|
||||
connect(m_maininterface, &MainInterface::transparencyChanged, m_bridge, &Bridge::transparencyChanged);
|
||||
// connect(m_maininterface, &MainInterface::appIconsMapChanged, this,[=]{
|
||||
// m_bridge->updateIconCache(m_maininterface->getAppIconsMap(),"appicon");
|
||||
// });
|
||||
|
@ -200,10 +201,12 @@ void MainWindow::onGoHomeClicked()
|
|||
m_cacheConfirmedWidget->show();
|
||||
connect(m_cacheConfirmedWidget, &cacheConfirmedWidget::cacheClean, this, [=](){
|
||||
m_stackedWidget->setCurrentIndex(0);
|
||||
//添加一个reflesh功能,清除所有界面上的改动
|
||||
});
|
||||
connect(m_cacheConfirmedWidget, &cacheConfirmedWidget::cacheSave, this, [=](){
|
||||
m_historywidget->updateHistoryDir();
|
||||
m_stackedWidget->setCurrentIndex(0);
|
||||
//添加一个reflesh功能,清除所有界面上的改动
|
||||
});
|
||||
} else {
|
||||
m_stackedWidget->setCurrentIndex(0);
|
||||
|
|
|
@ -24,6 +24,7 @@ void GlobalThemeWidget::eidtInitWidget(const HistoryInfo &InfoData)
|
|||
this->setAccentColor(m_info.accentcolor);
|
||||
this->setCover(m_info.coverpath);
|
||||
this->setWallpaper(m_info.wallpaperpath);
|
||||
this->setTransparency(m_info.transparency);
|
||||
// this->update();
|
||||
}
|
||||
|
||||
|
@ -321,6 +322,7 @@ void GlobalThemeWidget::initTransparencyWidget()
|
|||
showButton->setText(QString::number(m_transparencyslider->value())+"%");
|
||||
QObject::connect(m_transparencyslider, &QSlider::valueChanged, [=](int value) {
|
||||
showButton->setText(QString::number(value)+"%");
|
||||
newTransparency(value);
|
||||
});
|
||||
layout->addWidget(title);
|
||||
layout->addWidget(m_transparencyslider);
|
||||
|
@ -392,6 +394,11 @@ void GlobalThemeWidget::setAccentColor(QString accentcolor)
|
|||
}
|
||||
}
|
||||
|
||||
void GlobalThemeWidget::setTransparency(int transparency)
|
||||
{
|
||||
m_transparencyslider->setValue(transparency);
|
||||
}
|
||||
|
||||
void GlobalThemeWidget::setCover(QString coverpath)
|
||||
{
|
||||
m_coverbtn->setIcon(QIcon(coverpath));
|
||||
|
|
|
@ -30,6 +30,7 @@ signals:
|
|||
void newRadius(const int radius);
|
||||
void newAccentColor(const QColor selectedColor);
|
||||
void newExterior(const QColor selectedColor);
|
||||
void newTransparency(const int transparency);
|
||||
private:
|
||||
void initPreviewWidget();
|
||||
void initRightWidget();
|
||||
|
@ -46,6 +47,7 @@ private:
|
|||
|
||||
void setRadiusSetting(int radius);
|
||||
void setAccentColor(QString accentcolor);
|
||||
void setTransparency(int transparency);
|
||||
void setCover(QString coverpath);
|
||||
void setWallpaper(QString wallpaperpath);
|
||||
QWidget *m_globalthemewidget;
|
||||
|
|
Loading…
Reference in New Issue