add windowRadiu and Transparency UI

This commit is contained in:
likehomedream 2023-11-07 16:39:38 +08:00
parent b5e8627281
commit 63e73b1e5d
15 changed files with 195 additions and 13 deletions

View File

@ -1,4 +1,4 @@
QT += core gui svg QT += core gui svg KWindowSystem
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View File

@ -35,3 +35,4 @@ transparencyBlur=65
transparencyNoBlur=90 transparencyNoBlur=90
supportAnimation=true supportAnimation=true
animationDuration=150 animationDuration=150
windowRadius=6

View File

@ -47,6 +47,11 @@ void Bridge::transparencyChanged(int transparency)
m_configfilemanager->modifyTransparencyConf(transparency); m_configfilemanager->modifyTransparencyConf(transparency);
} }
void Bridge::windowRadiusChanged(int windowradius)
{
m_configfilemanager->modifywindowRadiusConf(windowradius);
}
void Bridge::appIconsMapChanged(QMap<QString, QString> *appiconsmaps) void Bridge::appIconsMapChanged(QMap<QString, QString> *appiconsmaps)
{ {
QMap<QString, QString>::const_iterator it; QMap<QString, QString>::const_iterator it;

View File

@ -21,10 +21,12 @@ public:
void accentColorChanged(QColor accentcolor); void accentColorChanged(QColor accentcolor);
void exteriorChanged(QColor accentcolor); void exteriorChanged(QColor accentcolor);
void transparencyChanged(int transparency); void transparencyChanged(int transparency);
void windowRadiusChanged(int windowradius);
void appIconsMapChanged(QMap<QString, QString> *appiconsmaps); void appIconsMapChanged(QMap<QString, QString> *appiconsmaps);
void systemIconsMapChanged(QMap<QString, QString> *systemiconsmaps); void systemIconsMapChanged(QMap<QString, QString> *systemiconsmaps);
void cursorMapChanged(QMap<QString, QString> *cursormap); void cursorMapChanged(QMap<QString, QString> *cursormap);
void timeCursorMapChanged(QMap<QString, QString> *timecursormap); void timeCursorMapChanged(QMap<QString, QString> *timecursormap);
void startCopy(); void startCopy();
void updateIconCache(QMap<QString, QString> *appiconsmaps,QString icontype); void updateIconCache(QMap<QString, QString> *appiconsmaps,QString icontype);
signals: signals:

View File

@ -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()<<content;
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << content;
file.close();
emit updateInfo();
return true;
} else {
qDebug() << "Failed to write file: " << confFilePath;
return false;
}
}
bool ConfigFileManager::copyFileContent(const QString &sourceFilePath, const QString &destinationFilePath) bool ConfigFileManager::copyFileContent(const QString &sourceFilePath, const QString &destinationFilePath)
{ {
QFile sourceFile(sourceFilePath); QFile sourceFile(sourceFilePath);

View File

@ -24,7 +24,7 @@ public:
bool modifyAccentColorConf(QColor accentcolor); bool modifyAccentColorConf(QColor accentcolor);
bool modifyWallPaperConf(QString wallpaperpath); bool modifyWallPaperConf(QString wallpaperpath);
bool modifyTransparencyConf(int transparency); bool modifyTransparencyConf(int transparency);
bool modifywindowRadiusConf(int windowradius);
bool copyFileContent(const QString& sourceFilePath, const QString& destinationFilePath); bool copyFileContent(const QString& sourceFilePath, const QString& destinationFilePath);
bool copyIcontoCacheDir(QMap<QString, QString> *map,QDir cachedir); bool copyIcontoCacheDir(QMap<QString, QString> *map,QDir cachedir);

View File

@ -14,6 +14,7 @@ HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent)
getAccentColor(); getAccentColor();
getRadius(); getRadius();
getTransparency(); getTransparency();
getWindowRadius();
} }
QString HistoryInfoLoad::getCover() 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() HistoryInfo HistoryInfoLoad::getInfoData()
{ {
qDebug()<<m_historyInfo.accentcolor<<m_historyInfo.wallpaperpath<<m_historyInfo.filepath; qDebug()<<m_historyInfo.accentcolor<<m_historyInfo.wallpaperpath<<m_historyInfo.filepath<<m_historyInfo.windowradius<<"+++++++++++++++++++++++++++++++++++++++++";
return m_historyInfo; return m_historyInfo;
} }
@ -222,5 +259,6 @@ void HistoryInfoLoad::updateHistoryInfo()
getWallpaper(); getWallpaper();
getAccentColor(); getAccentColor();
getTransparency(); getTransparency();
getWindowRadius();
} }

View File

@ -16,6 +16,7 @@ struct HistoryInfo {
QString accentcolor = ""; QString accentcolor = "";
int radius = 6; int radius = 6;
int transparency = 65; int transparency = 65;
int windowradius = 6;
}; };
Q_DECLARE_METATYPE(HistoryInfo) Q_DECLARE_METATYPE(HistoryInfo)
@ -32,6 +33,7 @@ public:
void getWallpaper(); void getWallpaper();
void getAccentColor(); void getAccentColor();
void getTransparency(); void getTransparency();
void getWindowRadius();
HistoryInfo getInfoData(); HistoryInfo getInfoData();
void updateHistoryInfo(); void updateHistoryInfo();
signals: signals:

View File

@ -32,6 +32,9 @@ MainInterface::MainInterface(QWidget *parent) : QWidget(parent)
connect(m_globalthemewidget, &GlobalThemeWidget::newTransparency, this, [&](const int transparency) { connect(m_globalthemewidget, &GlobalThemeWidget::newTransparency, this, [&](const int transparency) {
emit transparencyChanged(transparency); emit transparencyChanged(transparency);
}); });
connect(m_globalthemewidget, &GlobalThemeWidget::newWindowRadius, this, [&](const int windowFilletSize) {
emit windowRadiusChanged(windowFilletSize);
});
connect(m_iconthemewidget, &IconThemeWidget::newAppIconsMap, this, [&]( QMap<QString, QString> *appiconsmaps) { connect(m_iconthemewidget, &IconThemeWidget::newAppIconsMap, this, [&]( QMap<QString, QString> *appiconsmaps) {
emit appIconsMapChanged(appiconsmaps); emit appIconsMapChanged(appiconsmaps);
}); });

View File

@ -48,6 +48,7 @@ signals:
void coverPathChanged(QString path); void coverPathChanged(QString path);
void radiusChanged(int radius); void radiusChanged(int radius);
void transparencyChanged(int transparency); void transparencyChanged(int transparency);
void windowRadiusChanged(int windowRadius);
void accentColorChanged(QColor accentcolor); void accentColorChanged(QColor accentcolor);
void exteriorChanged(QColor exteriorcolor); void exteriorChanged(QColor exteriorcolor);
void appIconsMapChanged(QMap<QString, QString> *appiconsmap); void appIconsMapChanged(QMap<QString, QString> *appiconsmap);

View File

@ -25,6 +25,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_maininterface, &MainInterface::accentColorChanged, m_bridge, &Bridge::accentColorChanged); connect(m_maininterface, &MainInterface::accentColorChanged, m_bridge, &Bridge::accentColorChanged);
connect(m_maininterface, &MainInterface::exteriorChanged, m_bridge, &Bridge::exteriorChanged); connect(m_maininterface, &MainInterface::exteriorChanged, m_bridge, &Bridge::exteriorChanged);
connect(m_maininterface, &MainInterface::transparencyChanged, m_bridge, &Bridge::transparencyChanged); connect(m_maininterface, &MainInterface::transparencyChanged, m_bridge, &Bridge::transparencyChanged);
connect(m_maininterface, &MainInterface::windowRadiusChanged, m_bridge, &Bridge::windowRadiusChanged);
// connect(m_maininterface, &MainInterface::appIconsMapChanged, this,[=]{ // connect(m_maininterface, &MainInterface::appIconsMapChanged, this,[=]{
// m_bridge->updateIconCache(m_maininterface->getAppIconsMap(),"appicon"); // 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::systemIconsMapChanged, m_bridge, &Bridge::systemIconsMapChanged);
connect(m_maininterface, &MainInterface::cursorMapChanged, m_bridge, &Bridge::cursorMapChanged); connect(m_maininterface, &MainInterface::cursorMapChanged, m_bridge, &Bridge::cursorMapChanged);
connect(m_maininterface, &MainInterface::timeCursorMapChanged, m_bridge, &Bridge::timeCursorMapChanged); 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); connect(m_bridge,&Bridge::updateInfo,m_historywidget,&HistoryWidget::updateInfo);
} }

View File

@ -1,6 +1,10 @@
#include "globalthemefeature.h" #include "globalthemefeature.h"
#include "globalthemewidget.h" #include "globalthemewidget.h"
#include <QGraphicsDropShadowEffect> #include <QGraphicsDropShadowEffect>
#include <KWindowEffects>
#include <QPainterPath>
#include <QGraphicsBlurEffect>
CustomGraphicsView::CustomGraphicsView(QGraphicsScene* scene) : QGraphicsView(scene) { CustomGraphicsView::CustomGraphicsView(QGraphicsScene* scene) : QGraphicsView(scene) {
setTransformationAnchor(QGraphicsView::AnchorUnderMouse); setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setDragMode(QGraphicsView::ScrollHandDrag); setDragMode(QGraphicsView::ScrollHandDrag);
@ -85,6 +89,17 @@ void GlobalImageWidget::updatescale()
graphicsView->scale(1, 1); 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) GlobalImageWidget::GlobalImageWidget(QWidget *parent, const QString& coverFilePath)
: QWidget(parent), m_coverFilePath(coverFilePath) { : QWidget(parent), m_coverFilePath(coverFilePath) {
@ -131,7 +146,7 @@ GlobalImageWidget::GlobalImageWidget(QWidget *parent, const QString& coverFilePa
m_showwidget->setPalette(widgetpalette); m_showwidget->setPalette(widgetpalette);
QHBoxLayout *buttonlayout = new QHBoxLayout(); QHBoxLayout *buttonlayout = new QHBoxLayout();
m_showbtn = new QPushButton(m_showwidget); m_showbtn = new RoundedButton(m_showwidget);
m_showbtn->setFixedWidth(120); m_showbtn->setFixedWidth(120);
m_showbtn->setParent(m_showwidget); m_showbtn->setParent(m_showwidget);
@ -155,6 +170,10 @@ GlobalImageWidget::GlobalImageWidget(QWidget *parent, const QString& coverFilePa
// 设置初始缩放倍数为0.9倍 // 设置初始缩放倍数为0.9倍
qreal initialScale = 0.9; qreal initialScale = 0.9;
graphicsView->scale(initialScale, initialScale); graphicsView->scale(initialScale, initialScale);
// QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect(this);
// blurEffect->setBlurRadius(1);
// m_showwidget->setGraphicsEffect(blurEffect);
} }
Globalthemefeature::Globalthemefeature(QWidget *parent, const QString& coverFilePath) Globalthemefeature::Globalthemefeature(QWidget *parent, const QString& coverFilePath)
@ -167,6 +186,8 @@ RoundedWidget::RoundedWidget(QWidget *parent)
{ {
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);
setRadius(6); setRadius(6);
setTransparency(65);
} }
void RoundedWidget::setRadius(int radius) void RoundedWidget::setRadius(int radius)
@ -174,6 +195,13 @@ void RoundedWidget::setRadius(int radius)
m_radius = radius; m_radius = radius;
} }
void RoundedWidget::setTransparency(int transparency)
{
m_transparency = transparency / 100.0;
qDebug()<<m_transparency;
update();
}
void RoundedWidget::setBackgroundColor(const QColor &color) void RoundedWidget::setBackgroundColor(const QColor &color)
{ {
backgroundColor = color; backgroundColor = color;
@ -189,6 +217,7 @@ void RoundedWidget::paintEvent(QPaintEvent *event)
QRectF rect = contentsRect().adjusted(borderWidth, borderWidth, -borderWidth, -borderWidth); QRectF rect = contentsRect().adjusted(borderWidth, borderWidth, -borderWidth, -borderWidth);
int r = std::min(rect.width(), rect.height()) / 2; // 计算圆角半径 int r = std::min(rect.width(), rect.height()) / 2; // 计算圆角半径
int actualRadius = std::min(m_radius, r); // 取实际圆角半径和计算半径的较小值 int actualRadius = std::min(m_radius, r); // 取实际圆角半径和计算半径的较小值
backgroundColor.setAlphaF(m_transparency);
// 绘制背景 // 绘制背景
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
@ -201,3 +230,32 @@ void RoundedWidget::paintEvent(QPaintEvent *event)
// painter.drawRoundedRect(rect, actualRadius, actualRadius); // painter.drawRoundedRect(rect, actualRadius, actualRadius);
} }
RoundedButton::RoundedButton(QWidget *parent): QPushButton(parent)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
setFixedHeight(40);
setFlat(true);
setFocusPolicy(Qt::NoFocus);
}
void RoundedButton::setRadius(int radius)
{
m_radius = radius;
update();
}
void RoundedButton::paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
// 绘制圆角矩形背景
QRectF rect(0, 0, width(), height());
QBrush backgroundBrush(palette().color(QPalette::Button));
painter.setBrush(backgroundBrush);
painter.setPen(Qt::NoPen);
painter.drawRoundedRect(rect, m_radius, m_radius);
// 使用按钮原本的样式绘制文本和图标
QPushButton::paintEvent(event);
}

View File

@ -22,6 +22,7 @@ public:
RoundedWidget(QWidget *parent = nullptr); RoundedWidget(QWidget *parent = nullptr);
void setRadius(int radius); void setRadius(int radius);
void setTransparency(int transparency);
void setBackgroundColor(const QColor& color); void setBackgroundColor(const QColor& color);
protected: protected:
@ -29,11 +30,25 @@ protected:
private: private:
int m_radius; int m_radius;
double m_transparency;
QColor backgroundColor = Qt::white; // 背景颜色 QColor backgroundColor = Qt::white; // 背景颜色
QColor borderColor = Qt::white; // 边框颜色 QColor borderColor = Qt::white; // 边框颜色
int borderWidth = 1; // 边框宽度 int borderWidth = 1; // 边框宽度
}; };
class RoundedButton : public QPushButton {
public:
RoundedButton(QWidget *parent = nullptr);
void setRadius(int radius);
protected:
void paintEvent(QPaintEvent *event) override;
private:
int m_radius;
};
class CustomGraphicsView : public QGraphicsView { class CustomGraphicsView : public QGraphicsView {
public: public:
explicit CustomGraphicsView(QGraphicsScene* scene); explicit CustomGraphicsView(QGraphicsScene* scene);
@ -51,11 +66,13 @@ public:
void update(const QString& coverFilePath); void update(const QString& coverFilePath);
void updateOverlayImage(const QString& overlayImagePath); void updateOverlayImage(const QString& overlayImagePath);
void updatescale(); void updatescale();
void updateControlRadius(int Value);
void updateTransparency(int transparency);
private: private:
CustomGraphicsView* graphicsView; CustomGraphicsView* graphicsView;
QString m_coverFilePath; QString m_coverFilePath;
RoundedWidget *m_showwidget; RoundedWidget *m_showwidget;
QPushButton *m_showbtn; RoundedButton *m_showbtn;
QGraphicsScene* m_scene; QGraphicsScene* m_scene;
QPixmap m_mergedImage; QPixmap m_mergedImage;
QPixmap m_image; QPixmap m_image;

View File

@ -25,6 +25,7 @@ void GlobalThemeWidget::eidtInitWidget(const HistoryInfo &InfoData)
this->setCover(m_info.coverpath); this->setCover(m_info.coverpath);
this->setWallpaper(m_info.wallpaperpath); this->setWallpaper(m_info.wallpaperpath);
this->setTransparency(m_info.transparency); this->setTransparency(m_info.transparency);
this->setWindowRadius(m_info.windowradius);
// this->update(); // this->update();
} }
@ -254,8 +255,9 @@ void GlobalThemeWidget::initFilletWidget()
QObject::connect(m_filletslider, &QSlider::valueChanged, [=](int value) { QObject::connect(m_filletslider, &QSlider::valueChanged, [=](int value) {
showButton->setText(QString::number(value)+"px"); showButton->setText(QString::number(value)+"px");
m_preview->updatescale();
m_preview->updateWidgetRadius(value); m_preview->updateControlRadius(value);
emit newRadius(value); emit newRadius(value);
}); });
@ -327,6 +329,7 @@ void GlobalThemeWidget::initTransparencyWidget()
QObject::connect(m_transparencyslider, &QSlider::valueChanged, [=](int value) { QObject::connect(m_transparencyslider, &QSlider::valueChanged, [=](int value) {
showButton->setText(QString::number(value)+"%"); showButton->setText(QString::number(value)+"%");
newTransparency(value); newTransparency(value);
m_preview->updateTransparency(value);
}); });
layout->addWidget(title); layout->addWidget(title);
layout->addWidget(m_transparencyslider); layout->addWidget(m_transparencyslider);
@ -343,10 +346,18 @@ void GlobalThemeWidget::initWindowFilletWidget()
QLabel *title = new QLabel(tr("Window fillet")); QLabel *title = new QLabel(tr("Window fillet"));
m_filletcombobox = new QComboBox(m_windowfilletwidget); m_filletcombobox = new QComboBox(m_windowfilletwidget);
m_filletcombobox->addItem(tr("Large"),QColor(55, 144, 250)); m_filletcombobox->addItem(tr("Large"), int(12));
m_filletcombobox->addItem(tr("Medium"), QColor(120, 115, 245)); m_filletcombobox->addItem(tr("Medium"), int(6));
m_filletcombobox->addItem(tr("Small"), QColor(120, 115, 245)); m_filletcombobox->addItem(tr("Small"), int(0));
m_filletcombobox->setCurrentIndex(1);
connect(m_filletcombobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index){
int selectedSize = m_filletcombobox->itemData(index).value<int>();
m_preview->updatescale();
m_preview->updateWidgetRadius(selectedSize);
emit newWindowRadius(selectedSize);
});
layout->addWidget(title); layout->addWidget(title);
layout->addWidget(m_filletcombobox); layout->addWidget(m_filletcombobox);
m_windowfilletwidget->setLayout(layout); m_windowfilletwidget->setLayout(layout);
@ -412,3 +423,16 @@ void GlobalThemeWidget::setWallpaper(QString wallpaperpath)
{ {
wallpaperbtn->setIcon(QIcon(wallpaperpath)); wallpaperbtn->setIcon(QIcon(wallpaperpath));
} }
void GlobalThemeWidget::setWindowRadius(int windowradius)
{
QMap<int, int> 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);
}
}

View File

@ -31,6 +31,7 @@ signals:
void newAccentColor(const QColor selectedColor); void newAccentColor(const QColor selectedColor);
void newExterior(const QColor selectedColor); void newExterior(const QColor selectedColor);
void newTransparency(const int transparency); void newTransparency(const int transparency);
void newWindowRadius(const int radius);
private: private:
void initPreviewWidget(); void initPreviewWidget();
void initRightWidget(); void initRightWidget();
@ -50,6 +51,7 @@ private:
void setTransparency(int transparency); void setTransparency(int transparency);
void setCover(QString coverpath); void setCover(QString coverpath);
void setWallpaper(QString wallpaperpath); void setWallpaper(QString wallpaperpath);
void setWindowRadius(int windowradius);
QWidget *m_globalthemewidget; QWidget *m_globalthemewidget;
QWidget *m_coverwidget; QWidget *m_coverwidget;
QWidget *m_wallpaperwidget; QWidget *m_wallpaperwidget;