Skip to content

Commit d481287

Browse files
committed
fix(quick-panel): adjust icon and text color opacity with hover effects
1. Add kNormalOpacity (0.7) and kHoverOpacity (1.0) constants in CommonIconButton, controlling icon/text transparency via parentHovered state 2. Add HoverEventFilter to QuickPluginItem, forwarding enter/leave events to child widgets for hover state tracking 3. Add QGraphicsOpacityEffect to PluginItemWidget for icon/label/connect button with enterEvent/leaveEvent overrides 4. Update SliderContainer to read _dtl_plugin_hovered property and adjust progress track opacity accordingly 5. Backport identical opacity logic to wireless-casting plugin's CommonIconButton copy Log: Adjust colors and hover effects for quick panel icons and text fix(快捷面板): 调整快捷面板图标和文字颜色及hover效果 1. CommonIconButton 增加 kNormalOpacity(0.7) 和 kHoverOpacity(1.0) 常量,通过 parentHovered 状态控制图标/文字透明度 2. QuickPluginItem 增加 HoverEventFilter,将 enter/leave 事件转发到子控件实现 hover 状态跟踪 3. PluginItemWidget 增加 icon/label/connect button 的 QGraphicsOpacityEffect,重写 enterEvent/leaveEvent 4. SliderContainer 读取 _dtl_plugin_hovered 属性,根据 hover 状态调整进度条透明度 5. 无线投屏插件中的 CommonIconButton 同步相同的透明度逻辑 Log: 调整快捷面板图标和文字颜色及hover效果 PMS: BUG-314503
1 parent 5f6b140 commit d481287

9 files changed

Lines changed: 181 additions & 10 deletions

File tree

plugins/dde-dock/common/commoniconbutton.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44
#include "commoniconbutton.h"
@@ -11,6 +11,9 @@
1111

1212
DGUI_USE_NAMESPACE
1313

14+
static constexpr qreal kNormalOpacity = 0.7;
15+
static constexpr qreal kHoverOpacity = 1.0;
16+
1417
CommonIconButton::CommonIconButton(QWidget *parent)
1518
: QWidget(parent)
1619
, m_refreshTimer(nullptr)
@@ -21,6 +24,7 @@ CommonIconButton::CommonIconButton(QWidget *parent)
2124
, m_darkThemeColor(Qt::white)
2225
, m_activeState(false)
2326
, m_hoverEnable(true)
27+
, m_parentHovered(false)
2428
, m_iconSize(QSize())
2529
, m_rotation(0)
2630
{
@@ -87,6 +91,8 @@ void CommonIconButton::updatePalette()
8791
if (m_lightThemeColor.isValid() && m_darkThemeColor.isValid()) {
8892
if (!m_activeState) {
8993
QColor color = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? m_lightThemeColor : m_darkThemeColor;
94+
qreal alpha = m_parentHovered ? kHoverOpacity : kNormalOpacity;
95+
color.setAlphaF(alpha);
9096
auto pa = palette();
9197
pa.setColor(QPalette::WindowText, color);
9298
setPalette(pa);
@@ -113,6 +119,15 @@ void CommonIconButton::setHoverEnable(bool enable)
113119
m_hoverEnable = enable;
114120
}
115121

122+
void CommonIconButton::setParentHovered(bool hovered)
123+
{
124+
if (m_parentHovered == hovered)
125+
return;
126+
127+
m_parentHovered = hovered;
128+
updatePalette();
129+
}
130+
116131
void CommonIconButton::setIcon(const QString &icon, const QString &fallback, const QString &suffix)
117132
{
118133
if (!m_fileMapping.contains(Default)) {

plugins/dde-dock/common/commoniconbutton.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44
#ifndef ICONBUTTON_H
@@ -43,6 +43,8 @@ public Q_SLOTS:
4343
void setHoverIcon(const QIcon &icon);
4444

4545
void setClickable(bool clickable);
46+
void setParentHovered(bool hovered);
47+
bool isParentHovered() const { return m_parentHovered; }
4648

4749
signals:
4850
void clicked();
@@ -70,6 +72,7 @@ public Q_SLOTS:
7072
QColor m_darkThemeColor;
7173
bool m_activeState;
7274
bool m_hoverEnable;
75+
bool m_parentHovered;
7376
QSize m_iconSize;
7477
qreal m_rotation;
7578
QPalette m_defaultPalette;

plugins/dde-dock/common/pluginitemdelegate.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <QPalette>
1515
#include <QIcon>
1616
#include <QListView>
17+
#include <QEnterEvent>
18+
#include <QGraphicsOpacityEffect>
1719

1820
PluginItemDelegate::PluginItemDelegate(QAbstractItemView *parent)
1921
: QStyledItemDelegate(parent)
@@ -191,6 +193,9 @@ PluginItemWidget::PluginItemWidget(PluginStandardItem *item, QWidget *parent)
191193
, m_connBtn(nullptr)
192194
, m_spinner(nullptr)
193195
, m_rightIconSpacerItem(new QSpacerItem(0, 0))
196+
, m_iconOpacity(nullptr)
197+
, m_labelOpacity(nullptr)
198+
, m_connOpacity(nullptr)
194199
{
195200
if (!m_item) {
196201
QLabel *err = new QLabel(this);
@@ -223,6 +228,14 @@ PluginItemWidget::PluginItemWidget(PluginStandardItem *item, QWidget *parent)
223228
m_spinner->hide();
224229
m_spinner->stop();
225230

231+
m_iconOpacity = new QGraphicsOpacityEffect(m_iconBtn);
232+
m_iconBtn->setGraphicsEffect(m_iconOpacity);
233+
m_labelOpacity = new QGraphicsOpacityEffect(m_nameLabel);
234+
m_nameLabel->setGraphicsEffect(m_labelOpacity);
235+
m_connOpacity = new QGraphicsOpacityEffect(m_connBtn);
236+
m_connBtn->setGraphicsEffect(m_connOpacity);
237+
updateHoverOpacity(false);
238+
226239
m_mainLayout->setContentsMargins(10, 0, 10, 0);
227240
m_mainLayout->setSpacing(0);
228241
m_mainLayout->addWidget(m_iconBtn, 0);
@@ -298,6 +311,32 @@ void PluginItemWidget::updateState(const PluginItemState state)
298311
m_mainLayout->invalidate();
299312
}
300313

314+
void PluginItemWidget::enterEvent(QEnterEvent *event)
315+
{
316+
updateHoverOpacity(true);
317+
QWidget::enterEvent(event);
318+
}
319+
320+
void PluginItemWidget::leaveEvent(QEvent *event)
321+
{
322+
updateHoverOpacity(false);
323+
QWidget::leaveEvent(event);
324+
}
325+
326+
void PluginItemWidget::updateHoverOpacity(bool hovered)
327+
{
328+
static constexpr qreal kNormalAlpha = 0.7;
329+
static constexpr qreal kHoverAlpha = 1.0;
330+
qreal alpha = hovered ? kHoverAlpha : kNormalAlpha;
331+
332+
if (m_iconOpacity)
333+
m_iconOpacity->setOpacity(alpha);
334+
if (m_labelOpacity)
335+
m_labelOpacity->setOpacity(alpha);
336+
if (m_connOpacity)
337+
m_connOpacity->setOpacity(alpha);
338+
}
339+
301340
bool PluginItemWidget::event(QEvent *e)
302341
{
303342
switch (e->type()) {

plugins/dde-dock/common/pluginitemdelegate.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2016 - 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -8,6 +8,7 @@
88

99
#include <DLabel>
1010
#include <DSpinner>
11+
#include <QGraphicsOpacityEffect>
1112

1213
#include <QObject>
1314
#include <QStyledItemDelegate>
@@ -116,8 +117,11 @@ public Q_SLOTS:
116117

117118
protected:
118119
bool event(QEvent *e) override;
120+
void enterEvent(QEnterEvent *event) override;
121+
void leaveEvent(QEvent *event) override;
119122

120123
private:
124+
void updateHoverOpacity(bool hovered);
121125
PluginStandardItem *m_item;
122126

123127
QHBoxLayout *m_mainLayout;
@@ -126,4 +130,7 @@ public Q_SLOTS:
126130
CommonIconButton *m_connBtn;
127131
DSpinner *m_spinner;
128132
QSpacerItem *m_rightIconSpacerItem;
133+
QGraphicsOpacityEffect *m_iconOpacity;
134+
QGraphicsOpacityEffect *m_labelOpacity;
135+
QGraphicsOpacityEffect *m_connOpacity;
129136
};

plugins/dde-dock/common/slidercontainer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
1+
// Copyright (C) 2022 ~ 2026 Deepin Technology Co., Ltd.
22
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
33
//
44
// SPDX-License-Identifier: LGPL-3.0-or-later
@@ -323,6 +323,12 @@ void SliderProxyStyle::drawNormalSlider(QPainter *painter, QRect rectGroove, QRe
323323
// 绘制设计师定义的那种圆形滑块,黑色的滑条
324324
void SliderProxyStyle::drawRoundSlider(QPainter *painter, QRect rectGroove, QRect rectHandle, const QWidget *widget) const
325325
{
326+
static constexpr qreal kNormalProgressAlpha = 0.7;
327+
static constexpr qreal kHoveredProgressAlpha = 1.0;
328+
329+
bool pluginHovered = widget->property("_dtl_plugin_hovered").toBool();
330+
qreal progressAlpha = pluginHovered ? kHoveredProgressAlpha : kNormalProgressAlpha;
331+
326332
// 深色背景下,滑块和滑动条白色,浅色背景下,滑块和滑动条黑色
327333
QColor color = widget->isEnabled() ? (DGuiApplicationHelper::DarkType == DGuiApplicationHelper::instance()->themeType() ? Qt::white : Qt::black) : Qt::gray;
328334

@@ -338,7 +344,9 @@ void SliderProxyStyle::drawRoundSlider(QPainter *painter, QRect rectGroove, QRec
338344
painter->fillPath(allPathGroove, allBrush);
339345

340346
// 已经滑动过的区域
341-
QBrush brush(color);
347+
QColor progressColor = color;
348+
progressColor.setAlphaF(progressAlpha);
349+
QBrush brush(progressColor);
342350
QPainterPath pathGroove;
343351
int handleSize = qMin(rectHandle.width(), rectHandle.height());
344352
rectGroove.setWidth(rectHandle.x() + (rectHandle.width() - handleSize) / 2);

plugins/dde-network-display-ui/plugins/dock-wirelesscasting-plugin/src/widget/commoniconbutton.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44
#include "commoniconbutton.h"
@@ -11,6 +11,9 @@
1111

1212
DGUI_USE_NAMESPACE
1313

14+
static constexpr qreal kNormalOpacity = 0.7;
15+
static constexpr qreal kHoverOpacity = 1.0;
16+
1417
CommonIconButton::CommonIconButton(QWidget *parent)
1518
: QWidget(parent)
1619
, m_refreshTimer(nullptr)
@@ -23,6 +26,7 @@ CommonIconButton::CommonIconButton(QWidget *parent)
2326
, m_darkThemeColor(Qt::white)
2427
, m_activeState(false)
2528
, m_hoverEnable(true)
29+
, m_parentHovered(false)
2630
{
2731
setAccessibleName("IconButton");
2832
setFixedSize(24, 24);
@@ -64,8 +68,12 @@ void CommonIconButton::updatePalette()
6468
{
6569
if (m_lightThemeColor.isValid() && m_darkThemeColor.isValid()) {
6670
QColor color = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? m_lightThemeColor : m_darkThemeColor;
67-
if (m_activeState)
71+
if (m_activeState) {
6872
color = palette().color(QPalette::Highlight);
73+
} else {
74+
qreal alpha = m_parentHovered ? kHoverOpacity : kNormalOpacity;
75+
color.setAlphaF(alpha);
76+
}
6977
auto pa = palette();
7078
pa.setColor(QPalette::WindowText, color);
7179
setPalette(pa);
@@ -89,6 +97,15 @@ void CommonIconButton::setHoverEnable(bool enable)
8997
m_hoverEnable = enable;
9098
}
9199

100+
void CommonIconButton::setParentHovered(bool hovered)
101+
{
102+
if (m_parentHovered == hovered)
103+
return;
104+
105+
m_parentHovered = hovered;
106+
updatePalette();
107+
}
108+
92109
void CommonIconButton::setIcon(const QString &icon, const QString &fallback, const QString &suffix)
93110
{
94111
if (!m_fileMapping.contains(Default)) {

plugins/dde-network-display-ui/plugins/dock-wirelesscasting-plugin/src/widget/commoniconbutton.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44
#ifndef ICONBUTTON_H
@@ -34,6 +34,8 @@ public Q_SLOTS:
3434

3535
void setClickable(bool clickable);
3636
void setRotatable(bool rotatable);
37+
void setParentHovered(bool hovered);
38+
bool isParentHovered() const { return m_parentHovered; }
3739

3840
signals:
3941
void clicked();
@@ -66,6 +68,7 @@ public Q_SLOTS:
6668
QColor m_darkThemeColor;
6769
bool m_activeState;
6870
bool m_hoverEnable;
71+
bool m_parentHovered;
6972
};
7073

7174
#endif // DOCKICONBUTTON_H

src/loader/quickpluginitem.cpp

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -9,6 +9,10 @@
99

1010
#include <QMouseEvent>
1111
#include <QMenu>
12+
#include <QLabel>
13+
#include <QSlider>
14+
#include <QAbstractButton>
15+
#include <QGraphicsOpacityEffect>
1216

1317
namespace {
1418
class Q_DECL_HIDDEN EventFilter : public QObject
@@ -96,13 +100,42 @@ class Q_DECL_HIDDEN ItemWidgetEventFilter : public QObject
96100

97101
QuickPluginItem *m_target = nullptr;
98102
};
103+
104+
class Q_DECL_HIDDEN HoverEventFilter : public QObject
105+
{
106+
public:
107+
explicit HoverEventFilter(QuickPluginItem *target)
108+
: QObject(target)
109+
, m_target(target)
110+
{
111+
}
112+
113+
bool eventFilter(QObject *watched, QEvent *event) override
114+
{
115+
if (event->type() != QEvent::Enter && event->type() != QEvent::Leave)
116+
return false;
117+
118+
// underMouse() is updated before event filter runs in Qt's event delivery;
119+
// centralWidget()->window() => the quick panel's top-level window
120+
bool isUnder = false;
121+
if (auto *w = m_target->centralWidget()) {
122+
if (auto *win = w->window())
123+
isUnder = win->underMouse();
124+
}
125+
m_target->updatePluginHoverState(isUnder);
126+
return false;
127+
}
128+
129+
QuickPluginItem *m_target = nullptr;
130+
};
99131
}
100132

101133
QuickPluginItem::QuickPluginItem(PluginsItemInterface *pluginInterface, const QString &itemKey, QWidget *parent)
102134
: PluginItem(pluginInterface, itemKey, parent)
103135
, m_onDockAction(nullptr)
104136
{
105137
qApp->installEventFilter(new EventFilter(this));
138+
installEventFilter(new HoverEventFilter(this));
106139
}
107140

108141
void QuickPluginItem::init()
@@ -111,6 +144,7 @@ void QuickPluginItem::init()
111144
if (auto widget = centralWidget()) {
112145
widget->installEventFilter(new ItemWidgetEventFilter(this));
113146
}
147+
updatePluginHoverState(false);
114148
}
115149

116150
QWidget *QuickPluginItem::centralWidget()
@@ -215,3 +249,45 @@ void QuickPluginItem::requestActiveState()
215249
}
216250
}
217251
}
252+
253+
void QuickPluginItem::updatePluginHoverState(bool hovered)
254+
{
255+
if (m_hoverStateApplied && m_pluginHovered == hovered)
256+
return;
257+
258+
m_pluginHovered = hovered;
259+
m_hoverStateApplied = true;
260+
261+
static constexpr qreal kNormalAlpha = 0.7;
262+
static constexpr qreal kHoverAlpha = 1.0;
263+
const qreal targetAlpha = hovered ? kHoverAlpha : kNormalAlpha;
264+
265+
// Single pass: no redundant findChildren calls.
266+
// CommonIconButton → invokeMethod (fallback to QGraphicsOpacityEffect)
267+
// QSlider → property + update()
268+
// QLabel / QAbstractButton → QGraphicsOpacityEffect
269+
// These branches are mutually exclusive in the widget hierarchy.
270+
for (auto *child : findChildren<QWidget *>()) {
271+
if (child->inherits("CommonIconButton")) {
272+
bool invoked = QMetaObject::invokeMethod(child, "setParentHovered", Q_ARG(bool, hovered));
273+
if (!invoked) {
274+
auto *effect = qobject_cast<QGraphicsOpacityEffect *>(child->graphicsEffect());
275+
if (!effect) {
276+
effect = new QGraphicsOpacityEffect(child);
277+
child->setGraphicsEffect(effect);
278+
}
279+
effect->setOpacity(targetAlpha);
280+
}
281+
} else if (qobject_cast<QSlider *>(child)) {
282+
child->setProperty("_dtl_plugin_hovered", hovered);
283+
child->update();
284+
} else if (qobject_cast<QLabel *>(child) || qobject_cast<QAbstractButton *>(child)) {
285+
auto *effect = qobject_cast<QGraphicsOpacityEffect *>(child->graphicsEffect());
286+
if (!effect) {
287+
effect = new QGraphicsOpacityEffect(child);
288+
child->setGraphicsEffect(effect);
289+
}
290+
effect->setOpacity(targetAlpha);
291+
}
292+
}
293+
}

0 commit comments

Comments
 (0)