From 63e73b1e5d30452e877b8832d5975562bd7785a4 Mon Sep 17 00:00:00 2001 From: likehomedream Date: Tue, 7 Nov 2023 16:39:38 +0800 Subject: [PATCH] add windowRadiu and Transparency UI --- kylin-theme-builder.pro | 2 +- resource/config/theme.conf | 1 + src/fileProcess/bridge.cpp | 5 +++ src/fileProcess/bridge.h | 2 + src/fileProcess/configfilemanager.cpp | 28 ++++++++++++ src/fileProcess/configfilemanager.h | 2 +- src/fileProcess/historyinfoload.cpp | 40 ++++++++++++++++- src/fileProcess/historyinfoload.h | 2 + src/maininterface.cpp | 3 ++ src/maininterface.h | 1 + src/mainwindow.cpp | 3 +- src/module/globalthemefeature.cpp | 64 +++++++++++++++++++++++++-- src/module/globalthemefeature.h | 19 +++++++- src/module/globalthemewidget.cpp | 34 +++++++++++--- src/module/globalthemewidget.h | 2 + 15 files changed, 195 insertions(+), 13 deletions(-) diff --git a/kylin-theme-builder.pro b/kylin-theme-builder.pro index 70cf06f..9b16e91 100644 --- a/kylin-theme-builder.pro +++ b/kylin-theme-builder.pro @@ -1,4 +1,4 @@ -QT += core gui svg +QT += core gui svg KWindowSystem greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/resource/config/theme.conf b/resource/config/theme.conf index 55a6aef..3be6999 100644 --- a/resource/config/theme.conf +++ b/resource/config/theme.conf @@ -35,3 +35,4 @@ transparencyBlur=65 transparencyNoBlur=90 supportAnimation=true animationDuration=150 +windowRadius=6 diff --git a/src/fileProcess/bridge.cpp b/src/fileProcess/bridge.cpp index 3c54316..8015322 100644 --- a/src/fileProcess/bridge.cpp +++ b/src/fileProcess/bridge.cpp @@ -47,6 +47,11 @@ void Bridge::transparencyChanged(int transparency) m_configfilemanager->modifyTransparencyConf(transparency); } +void Bridge::windowRadiusChanged(int windowradius) +{ + m_configfilemanager->modifywindowRadiusConf(windowradius); +} + void Bridge::appIconsMapChanged(QMap *appiconsmaps) { QMap::const_iterator it; diff --git a/src/fileProcess/bridge.h b/src/fileProcess/bridge.h index fb6f7eb..e26feb3 100644 --- a/src/fileProcess/bridge.h +++ b/src/fileProcess/bridge.h @@ -21,10 +21,12 @@ public: void accentColorChanged(QColor accentcolor); void exteriorChanged(QColor accentcolor); void transparencyChanged(int transparency); + void windowRadiusChanged(int windowradius); void appIconsMapChanged(QMap *appiconsmaps); void systemIconsMapChanged(QMap *systemiconsmaps); void cursorMapChanged(QMap *cursormap); void timeCursorMapChanged(QMap *timecursormap); + void startCopy(); void updateIconCache(QMap *appiconsmaps,QString icontype); signals: diff --git a/src/fileProcess/configfilemanager.cpp b/src/fileProcess/configfilemanager.cpp index 59c52df..cfc3b51 100644 --- a/src/fileProcess/configfilemanager.cpp +++ b/src/fileProcess/configfilemanager.cpp @@ -208,6 +208,34 @@ bool ConfigFileManager::modifyTransparencyConf(int transparency) } } +bool ConfigFileManager::modifywindowRadiusConf(int windowradius) +{ + QFile file(confFilePath); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "Failed to open file: " << confFilePath; + return false; + } + + QTextStream in(&file); + QString content = in.readAll(); + file.close(); + + QString oldValue = "windowRadius="; + QString newValue = QString("windowRadius=%1").arg(windowradius); + content.replace(QRegExp(oldValue + "\\d+"), newValue); + qDebug()< *map,QDir cachedir); diff --git a/src/fileProcess/historyinfoload.cpp b/src/fileProcess/historyinfoload.cpp index 3ee8149..a93f3a1 100644 --- a/src/fileProcess/historyinfoload.cpp +++ b/src/fileProcess/historyinfoload.cpp @@ -14,6 +14,7 @@ HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent) getAccentColor(); getRadius(); getTransparency(); + getWindowRadius(); } QString HistoryInfoLoad::getCover() @@ -207,9 +208,45 @@ void HistoryInfoLoad::getTransparency() } } +void HistoryInfoLoad::getWindowRadius() +{ + 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("windowRadius="); + 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("windowRadius="); + + bool conversionSuccess = false; + int windowRadiusValue = lineContent.toInt(&conversionSuccess); + if (conversionSuccess) { + m_historyInfo.windowradius = windowRadiusValue; + qDebug() << "m_historyInfo.windowradius" << windowRadiusValue; + } else { + qDebug() << "无法将字符串转换为整数:" << lineContent; + } + } +} + HistoryInfo HistoryInfoLoad::getInfoData() { - qDebug()< *appiconsmaps) { emit appIconsMapChanged(appiconsmaps); }); diff --git a/src/maininterface.h b/src/maininterface.h index 971747f..9663176 100644 --- a/src/maininterface.h +++ b/src/maininterface.h @@ -48,6 +48,7 @@ signals: void coverPathChanged(QString path); void radiusChanged(int radius); void transparencyChanged(int transparency); + void windowRadiusChanged(int windowRadius); void accentColorChanged(QColor accentcolor); void exteriorChanged(QColor exteriorcolor); void appIconsMapChanged(QMap *appiconsmap); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 453786d..01b5ac8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,6 +25,7 @@ MainWindow::MainWindow(QWidget *parent) 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::windowRadiusChanged, m_bridge, &Bridge::windowRadiusChanged); // connect(m_maininterface, &MainInterface::appIconsMapChanged, this,[=]{ // m_bridge->updateIconCache(m_maininterface->getAppIconsMap(),"appicon"); // }); @@ -32,7 +33,7 @@ MainWindow::MainWindow(QWidget *parent) connect(m_maininterface, &MainInterface::systemIconsMapChanged, m_bridge, &Bridge::systemIconsMapChanged); connect(m_maininterface, &MainInterface::cursorMapChanged, m_bridge, &Bridge::cursorMapChanged); connect(m_maininterface, &MainInterface::timeCursorMapChanged, m_bridge, &Bridge::timeCursorMapChanged); - connect(m_maininterface, &MainInterface::startCopy, m_bridge, &Bridge::startCopy); +// connect(m_maininterface, &MainInterface::startCopy, m_bridge, &Bridge::startCopy); connect(m_bridge,&Bridge::updateInfo,m_historywidget,&HistoryWidget::updateInfo); } diff --git a/src/module/globalthemefeature.cpp b/src/module/globalthemefeature.cpp index 6d74095..f646736 100644 --- a/src/module/globalthemefeature.cpp +++ b/src/module/globalthemefeature.cpp @@ -1,6 +1,10 @@ -#include "globalthemefeature.h" +#include "globalthemefeature.h" #include "globalthemewidget.h" #include +#include +#include +#include + CustomGraphicsView::CustomGraphicsView(QGraphicsScene* scene) : QGraphicsView(scene) { setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setDragMode(QGraphicsView::ScrollHandDrag); @@ -85,6 +89,17 @@ void GlobalImageWidget::updatescale() graphicsView->scale(1, 1); } +void GlobalImageWidget::updateControlRadius(int Value) +{ + m_showbtn->setRadius(Value); +} + +void GlobalImageWidget::updateTransparency(int transparency) +{ + m_showwidget->setTransparency(transparency); + m_showwidget->update(); +} + GlobalImageWidget::GlobalImageWidget(QWidget *parent, const QString& coverFilePath) : QWidget(parent), m_coverFilePath(coverFilePath) { @@ -131,7 +146,7 @@ GlobalImageWidget::GlobalImageWidget(QWidget *parent, const QString& coverFilePa m_showwidget->setPalette(widgetpalette); QHBoxLayout *buttonlayout = new QHBoxLayout(); - m_showbtn = new QPushButton(m_showwidget); + m_showbtn = new RoundedButton(m_showwidget); m_showbtn->setFixedWidth(120); m_showbtn->setParent(m_showwidget); @@ -155,6 +170,10 @@ GlobalImageWidget::GlobalImageWidget(QWidget *parent, const QString& coverFilePa // 设置初始缩放倍数为0.9倍 qreal initialScale = 0.9; graphicsView->scale(initialScale, initialScale); + +// QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect(this); +// blurEffect->setBlurRadius(1); +// m_showwidget->setGraphicsEffect(blurEffect); } Globalthemefeature::Globalthemefeature(QWidget *parent, const QString& coverFilePath) @@ -167,6 +186,8 @@ RoundedWidget::RoundedWidget(QWidget *parent) { setAttribute(Qt::WA_TranslucentBackground); setRadius(6); + setTransparency(65); + } void RoundedWidget::setRadius(int radius) @@ -174,6 +195,13 @@ void RoundedWidget::setRadius(int radius) m_radius = radius; } +void RoundedWidget::setTransparency(int transparency) +{ + m_transparency = transparency / 100.0; + qDebug()<setCover(m_info.coverpath); this->setWallpaper(m_info.wallpaperpath); this->setTransparency(m_info.transparency); + this->setWindowRadius(m_info.windowradius); // this->update(); } @@ -254,8 +255,9 @@ void GlobalThemeWidget::initFilletWidget() QObject::connect(m_filletslider, &QSlider::valueChanged, [=](int value) { showButton->setText(QString::number(value)+"px"); - m_preview->updatescale(); - m_preview->updateWidgetRadius(value); + + m_preview->updateControlRadius(value); + emit newRadius(value); }); @@ -327,6 +329,7 @@ void GlobalThemeWidget::initTransparencyWidget() QObject::connect(m_transparencyslider, &QSlider::valueChanged, [=](int value) { showButton->setText(QString::number(value)+"%"); newTransparency(value); + m_preview->updateTransparency(value); }); layout->addWidget(title); layout->addWidget(m_transparencyslider); @@ -343,10 +346,18 @@ void GlobalThemeWidget::initWindowFilletWidget() QLabel *title = new QLabel(tr("Window fillet")); m_filletcombobox = new QComboBox(m_windowfilletwidget); - m_filletcombobox->addItem(tr("Large"),QColor(55, 144, 250)); - m_filletcombobox->addItem(tr("Medium"), QColor(120, 115, 245)); - m_filletcombobox->addItem(tr("Small"), QColor(120, 115, 245)); + m_filletcombobox->addItem(tr("Large"), int(12)); + m_filletcombobox->addItem(tr("Medium"), int(6)); + m_filletcombobox->addItem(tr("Small"), int(0)); + m_filletcombobox->setCurrentIndex(1); + connect(m_filletcombobox, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index){ + int selectedSize = m_filletcombobox->itemData(index).value(); + m_preview->updatescale(); + m_preview->updateWidgetRadius(selectedSize); + + emit newWindowRadius(selectedSize); + }); layout->addWidget(title); layout->addWidget(m_filletcombobox); m_windowfilletwidget->setLayout(layout); @@ -412,3 +423,16 @@ void GlobalThemeWidget::setWallpaper(QString wallpaperpath) { wallpaperbtn->setIcon(QIcon(wallpaperpath)); } + +void GlobalThemeWidget::setWindowRadius(int windowradius) +{ + QMap radiusIndexMap; + radiusIndexMap.insert(0, 2); + radiusIndexMap.insert(6, 1); + radiusIndexMap.insert(12, 0); + + if (radiusIndexMap.contains(windowradius)) { + int index = radiusIndexMap.value(windowradius); + m_filletcombobox->setCurrentIndex(index); + } +} diff --git a/src/module/globalthemewidget.h b/src/module/globalthemewidget.h index bbfc8d6..81d8603 100644 --- a/src/module/globalthemewidget.h +++ b/src/module/globalthemewidget.h @@ -31,6 +31,7 @@ signals: void newAccentColor(const QColor selectedColor); void newExterior(const QColor selectedColor); void newTransparency(const int transparency); + void newWindowRadius(const int radius); private: void initPreviewWidget(); void initRightWidget(); @@ -50,6 +51,7 @@ private: void setTransparency(int transparency); void setCover(QString coverpath); void setWallpaper(QString wallpaperpath); + void setWindowRadius(int windowradius); QWidget *m_globalthemewidget; QWidget *m_coverwidget; QWidget *m_wallpaperwidget;