104 lines
3.9 KiB
Diff
104 lines
3.9 KiB
Diff
From: =?utf-8?b?5p2o5pWP?= <yangmin@kylinos.cn>
|
|
Date: Thu, 15 Aug 2024 05:43:46 +0000
|
|
Subject: =?utf-8?q?!99_fixbug_Merge_pull_request_!99_from_=E6=9D=A8?=
|
|
=?utf-8?q?=E6=95=8F/openkylin/nile?=
|
|
|
|
---
|
|
src/CMakeLists.txt | 2 +-
|
|
src/widgets/networkbutton.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++-
|
|
2 files changed, 54 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
|
index 7094827..f76501d 100644
|
|
--- a/src/CMakeLists.txt
|
|
+++ b/src/CMakeLists.txt
|
|
@@ -118,7 +118,7 @@ add_executable(ukui-screensaver-dialog ${dialog_SRC})
|
|
add_definitions(-DAPP_API_MAJOR=0
|
|
-DAPP_API_MINOR=11
|
|
-DAPP_API_FUNC=0
|
|
-# -DSUPPORT_MEDIA_CONTROL
|
|
+ -DSUPPORT_MEDIA_CONTROL
|
|
)
|
|
target_include_directories(ukui-screensaver-dialog PRIVATE ${KYSDKSYSTIME_INCLUDE_DIRS} ${KYSDKWAYLANDHELPER_INCLUDE_DIRS})
|
|
target_link_directories(ukui-screensaver-dialog PRIVATE ${KYSDKSYSTIME_LIBRARY_DIRS} ${KYSDKWAYLANDHELPER_LIBRARY_DIRS})
|
|
diff --git a/src/widgets/networkbutton.cpp b/src/widgets/networkbutton.cpp
|
|
index b64b2ec..9d5972b 100644
|
|
--- a/src/widgets/networkbutton.cpp
|
|
+++ b/src/widgets/networkbutton.cpp
|
|
@@ -18,7 +18,9 @@
|
|
#include "networkbutton.h"
|
|
#include <QStylePainter>
|
|
#include <QStyleOption>
|
|
+#include <QApplication>
|
|
#include <QMouseEvent>
|
|
+#include "commonfunc.h"
|
|
|
|
NetWorkButton::NetWorkButton(QWidget *parent) : KyNetworkIcon(parent)
|
|
{
|
|
@@ -58,6 +60,14 @@ void NetWorkButton::paintEvent(QPaintEvent *e)
|
|
// painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
|
|
// painter.restore();
|
|
// }
|
|
+ if (option.state & QStyle::State_MouseOver) {
|
|
+ painter.save();
|
|
+ painter.setPen(Qt::NoPen);
|
|
+ painter.setBrush(Qt::white);
|
|
+ painter.setOpacity(0.15);
|
|
+ painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
|
|
+ painter.restore();
|
|
+ }
|
|
|
|
if (curStatus == CLICKED) {
|
|
painter.save();
|
|
@@ -84,7 +94,49 @@ void NetWorkButton::paintEvent(QPaintEvent *e)
|
|
painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
|
|
painter.restore();
|
|
}
|
|
- QPushButton::paintEvent(e);
|
|
+
|
|
+ if (option.state & QStyle::State_HasFocus) {
|
|
+ painter.save();
|
|
+ painter.setPen(Qt::NoPen);
|
|
+ painter.setBrush(Qt::white);
|
|
+ painter.setOpacity(0.25);
|
|
+ painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
|
|
+ painter.restore();
|
|
+ painter.save();
|
|
+ QStyleOption opt;
|
|
+ QColor color = opt.palette.color(QPalette::Highlight);
|
|
+ painter.setPen(QPen(color, 2));
|
|
+ painter.setBrush(Qt::NoBrush);
|
|
+ painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), 6, 6);
|
|
+ painter.restore();
|
|
+ }
|
|
+ // 绘制图片
|
|
+ int buttonWidget = this->width();
|
|
+ int buttonHeight = this->height();
|
|
+ QRect buttonRect(0, 0, buttonWidget, buttonHeight);
|
|
+
|
|
+ QPixmap pixmap = option.icon.pixmap(option.iconSize, QIcon::Active);
|
|
+ pixmap = drawSymbolicColoredPixmap(pixmap, "white");
|
|
+ int pixmapWidth = static_cast<int>(pixmap.width() / qApp->devicePixelRatio());
|
|
+ int pixmapHeight = static_cast<int>(pixmap.height() / qApp->devicePixelRatio());
|
|
+ QRect pixmapRect(0, 0, pixmapWidth, pixmapHeight);
|
|
+
|
|
+ int deltaX = 0;
|
|
+ int deltaY = 0;
|
|
+ if (pixmapRect.width() < buttonRect.width())
|
|
+ deltaX = buttonRect.width() - pixmapRect.width();
|
|
+ else
|
|
+ deltaX = pixmapRect.width() - buttonRect.width();
|
|
+ if (pixmapRect.height() < buttonRect.height())
|
|
+ deltaY = buttonRect.height() - pixmapRect.height();
|
|
+ else
|
|
+ deltaY = pixmapRect.height() - buttonRect.height();
|
|
+
|
|
+ painter.save();
|
|
+ painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
|
+ painter.translate(deltaX / 2, deltaY / 2);
|
|
+ painter.drawPixmap(pixmapRect, pixmap);
|
|
+ painter.restore();
|
|
}
|
|
|
|
void NetWorkButton::mouseReleaseEvent(QMouseEvent *e)
|