!40 add windowRadiu and Transparency UI

Merge pull request !40 from likehomedream/my-devel
This commit is contained in:
KevinDuan 2023-11-07 09:00:25 +00:00 committed by Gitee
commit 99689b6d95
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
19 changed files with 317 additions and 16 deletions

View File

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

View File

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

View File

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

View File

@ -20,10 +20,13 @@ public:
void radiusChanged(int radius);
void accentColorChanged(QColor accentcolor);
void exteriorChanged(QColor accentcolor);
void transparencyChanged(int transparency);
void windowRadiusChanged(int windowradius);
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();
void updateIconCache(QMap<QString, QString> *appiconsmaps,QString icontype);
signals:

View File

@ -177,6 +177,65 @@ 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::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)
{
QFile sourceFile(sourceFilePath);

View File

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

View File

@ -13,6 +13,8 @@ HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent)
getWallpaper();
getAccentColor();
getRadius();
getTransparency();
getWindowRadius();
}
QString HistoryInfoLoad::getCover()
@ -154,7 +156,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,9 +172,81 @@ 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;
}
}
}
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()<<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;
}
@ -185,5 +258,7 @@ void HistoryInfoLoad::updateHistoryInfo()
getRadius();
getWallpaper();
getAccentColor();
getTransparency();
getWindowRadius();
}

View File

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

View File

@ -29,6 +29,12 @@ 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_globalthemewidget, &GlobalThemeWidget::newWindowRadius, this, [&](const int windowFilletSize) {
emit windowRadiusChanged(windowFilletSize);
});
connect(m_iconthemewidget, &IconThemeWidget::newAppIconsMap, this, [&]( QMap<QString, QString> *appiconsmaps) {
emit appIconsMapChanged(appiconsmaps);
});

View File

@ -47,6 +47,8 @@ signals:
void wallpaperPathChanged(QString path);
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<QString, QString> *appiconsmap);

View File

@ -24,6 +24,8 @@ 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::windowRadiusChanged, m_bridge, &Bridge::windowRadiusChanged);
// connect(m_maininterface, &MainInterface::appIconsMapChanged, this,[=]{
// m_bridge->updateIconCache(m_maininterface->getAppIconsMap(),"appicon");
// });
@ -31,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);
}
@ -200,10 +202,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);

View File

@ -17,6 +17,11 @@ void CursorThemeWidget::initPreviewWidget()
{
m_previewwidget = new QWidget(this);
m_previewwidget->setMinimumSize(495,620);
QPalette palette;
QColor bgColor("#F5F5F5");
palette.setColor(QPalette::Window, bgColor);
m_previewwidget->setPalette(palette);
m_previewwidget->setAutoFillBackground(true);
m_preview = new CursorImageWidget(m_previewwidget,m_iconpathmap);
m_preview2 = new CursorImageWidget(m_previewwidget,m_timeiconpathmap);
m_previewlayout = new QVBoxLayout(m_previewwidget);

View File

@ -1,6 +1,10 @@
#include "globalthemefeature.h"
#include "globalthemefeature.h"
#include "globalthemewidget.h"
#include <QGraphicsDropShadowEffect>
#include <KWindowEffects>
#include <QPainterPath>
#include <QGraphicsBlurEffect>
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()<<m_transparency;
update();
}
void RoundedWidget::setBackgroundColor(const QColor &color)
{
backgroundColor = color;
@ -189,6 +217,7 @@ void RoundedWidget::paintEvent(QPaintEvent *event)
QRectF rect = contentsRect().adjusted(borderWidth, borderWidth, -borderWidth, -borderWidth);
int r = std::min(rect.width(), rect.height()) / 2; // 计算圆角半径
int actualRadius = std::min(m_radius, r); // 取实际圆角半径和计算半径的较小值
backgroundColor.setAlphaF(m_transparency);
// 绘制背景
painter.setPen(Qt::NoPen);
@ -201,3 +230,32 @@ void RoundedWidget::paintEvent(QPaintEvent *event)
// 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);
void setRadius(int radius);
void setTransparency(int transparency);
void setBackgroundColor(const QColor& color);
protected:
@ -29,11 +30,25 @@ protected:
private:
int m_radius;
double m_transparency;
QColor backgroundColor = Qt::white; // 背景颜色
QColor borderColor = Qt::white; // 边框颜色
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 {
public:
explicit CustomGraphicsView(QGraphicsScene* scene);
@ -51,11 +66,13 @@ public:
void update(const QString& coverFilePath);
void updateOverlayImage(const QString& overlayImagePath);
void updatescale();
void updateControlRadius(int Value);
void updateTransparency(int transparency);
private:
CustomGraphicsView* graphicsView;
QString m_coverFilePath;
RoundedWidget *m_showwidget;
QPushButton *m_showbtn;
RoundedButton *m_showbtn;
QGraphicsScene* m_scene;
QPixmap m_mergedImage;
QPixmap m_image;

View File

@ -24,6 +24,8 @@ 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->setWindowRadius(m_info.windowradius);
// this->update();
}
@ -32,7 +34,11 @@ void GlobalThemeWidget::initPreviewWidget()
m_previewwidget = new QWidget(this);
m_previewwidget->setMinimumSize(495,620);
m_previewwidget->setBackgroundRole(QPalette::Window);
QPalette palette;
QColor bgColor("#F5F5F5");
palette.setColor(QPalette::Window, bgColor);
m_previewwidget->setPalette(palette);
m_previewwidget->setAutoFillBackground(true);
m_preview = new GlobalImageWidget(m_previewwidget,m_wallpaperpath);
@ -249,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);
});
@ -321,6 +328,8 @@ 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);
m_preview->updateTransparency(value);
});
layout->addWidget(title);
layout->addWidget(m_transparencyslider);
@ -337,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<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(m_filletcombobox);
m_windowfilletwidget->setLayout(layout);
@ -392,6 +409,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));
@ -401,3 +423,16 @@ void GlobalThemeWidget::setWallpaper(QString 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

@ -30,6 +30,8 @@ signals:
void newRadius(const int radius);
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();
@ -46,8 +48,10 @@ private:
void setRadiusSetting(int radius);
void setAccentColor(QString accentcolor);
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;

View File

@ -17,6 +17,12 @@ void GrubThemeWidget::initPreviewWidget()
m_previewwidget->setBackgroundRole(QPalette::Window);
QPalette palette;
QColor bgColor("#F5F5F5");
palette.setColor(QPalette::Window, bgColor);
m_previewwidget->setPalette(palette);
m_previewwidget->setAutoFillBackground(true);
m_preview = new GrubImageWidget(m_previewwidget);
m_previewlayout = new QVBoxLayout(m_previewwidget);

View File

@ -19,6 +19,12 @@ void IconThemeWidget::initPreviewWidget()
m_previewwidget = new QWidget(this);
m_previewwidget->setMinimumSize(550,620);
QPalette palette;
QColor bgColor("#F5F5F5");
palette.setColor(QPalette::Window, bgColor);
m_previewwidget->setPalette(palette);
m_previewwidget->setAutoFillBackground(true);
m_previewstack = new QStackedWidget(m_previewwidget);
m_preview = new ImageWidget(m_previewwidget,m_iconpathmap);

View File

@ -18,6 +18,12 @@ void PlymouthThemeWidget::initPreviewWidget()
m_previewwidget->setBackgroundRole(QPalette::Window);
QPalette palette;
QColor bgColor("#F5F5F5");
palette.setColor(QPalette::Window, bgColor);
m_previewwidget->setPalette(palette);
m_previewwidget->setAutoFillBackground(true);
m_preview = new PlymouthImageWidget(m_previewwidget);
m_previewlayout = new QVBoxLayout(m_previewwidget);