Skip to content

Commit a824da9

Browse files
committed
fix(plugin-item): adjust opacity and hover animation
1. Added QGraphicsOpacityEffect with default 0.7 opacity to PluginItemWidget and PluginItem 2. Added hover animation that transitions opacity from 0.7 to 1.0 on mouse enter 3. Added leave animation that transitions opacity back to 0.7 on mouse leave 4. Exported animation constants (opacity values, duration) as public static members Log: Adjust icon/text opacity and add hover animation for quick panel plugin items fix(plugin-item): 调整透明度与悬停动画 1. 为 PluginItemWidget 和 PluginItem 添加 QGraphicsOpacityEffect,默认透明度 0.7 2. 添加悬停动画:鼠标进入时透明度从 0.7 过渡到 1.0 3. 添加离开动画:鼠标离开时透明度恢复为 0.7 4. 将动画常量(透明度值、持续时间)导出为公共静态成员 Log: 调整快捷面板插件项的图标文字透明度并添加悬停动画效果 PMS: BUG-314503
1 parent 5f6b140 commit a824da9

4 files changed

Lines changed: 59 additions & 3 deletions

File tree

plugins/dde-dock/common/pluginitemdelegate.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ PluginItemWidget::PluginItemWidget(PluginStandardItem *item, QWidget *parent)
192192
, m_spinner(nullptr)
193193
, m_rightIconSpacerItem(new QSpacerItem(0, 0))
194194
{
195+
m_opacityEffect = new QGraphicsOpacityEffect(this);
196+
m_opacityEffect->setOpacity(kNormalOpacity);
197+
setGraphicsEffect(m_opacityEffect);
198+
199+
m_opacityAnim = new QPropertyAnimation(m_opacityEffect, "opacity", this);
200+
m_opacityAnim->setDuration(kOpacityAnimDuration);
201+
m_opacityAnim->setEasingCurve(QEasingCurve::OutCubic);
202+
195203
if (!m_item) {
196204
QLabel *err = new QLabel(this);
197205
err->setText("Unknown Item");
@@ -298,9 +306,24 @@ void PluginItemWidget::updateState(const PluginItemState state)
298306
m_mainLayout->invalidate();
299307
}
300308

309+
void PluginItemWidget::startHoverAnim()
310+
{
311+
m_opacityAnim->stop();
312+
m_opacityAnim->setEndValue(kHoverOpacity);
313+
m_opacityAnim->start();
314+
}
315+
301316
bool PluginItemWidget::event(QEvent *e)
302317
{
303318
switch (e->type()) {
319+
case QEvent::Enter:
320+
startHoverAnim();
321+
break;
322+
case QEvent::Leave:
323+
m_opacityAnim->stop();
324+
m_opacityAnim->setEndValue(kNormalOpacity);
325+
m_opacityAnim->start();
326+
break;
304327
case QEvent::PaletteChange: {
305328
QLayout *layout = this->layout();
306329
for (int i = 0; i < layout->count(); i++) {

plugins/dde-dock/common/pluginitemdelegate.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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

55
#pragma once
66

77
#include "commoniconbutton.h"
88

9+
#include <QGraphicsOpacityEffect>
10+
#include <QPropertyAnimation>
911
#include <DLabel>
1012
#include <DSpinner>
1113

@@ -118,6 +120,14 @@ public Q_SLOTS:
118120
bool event(QEvent *e) override;
119121

120122
private:
123+
void startHoverAnim();
124+
125+
QGraphicsOpacityEffect *m_opacityEffect;
126+
QPropertyAnimation *m_opacityAnim;
127+
static constexpr qreal kNormalOpacity = 0.7;
128+
static constexpr qreal kHoverOpacity = 1.0;
129+
static constexpr int kOpacityAnimDuration = 150;
130+
121131
PluginStandardItem *m_item;
122132

123133
QHBoxLayout *m_mainLayout;

src/loader/pluginitem.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ PluginItem::PluginItem(PluginsItemInterface *pluginItemInterface, const QString
3030
m_tooltipTimer->setSingleShot(true);
3131
m_tooltipTimer->setInterval(200);
3232

33+
m_opacityEffect = new QGraphicsOpacityEffect(this);
34+
m_opacityEffect->setOpacity(kNormalOpacity);
35+
setGraphicsEffect(m_opacityEffect);
36+
37+
m_opacityAnim = new QPropertyAnimation(m_opacityEffect, "opacity", this);
38+
m_opacityAnim->setDuration(kOpacityAnimDuration);
39+
m_opacityAnim->setEasingCurve(QEasingCurve::OutCubic);
3340
if (m_dbusProxy.isNull())
3441
m_dbusProxy.reset(new DockDBusProxy);
3542

@@ -176,6 +183,10 @@ void PluginItem::mouseReleaseEvent(QMouseEvent *e)
176183

177184
void PluginItem::enterEvent(QEnterEvent *event)
178185
{
186+
m_opacityAnim->stop();
187+
m_opacityAnim->setEndValue(kHoverOpacity);
188+
m_opacityAnim->start();
189+
179190
// panel popup existed, not show tooltip
180191
if (panelPopupExisted()) {
181192
return QWidget::enterEvent(event);
@@ -218,6 +229,10 @@ void PluginItem::leaveEvent(QEvent *event)
218229
{
219230
Q_UNUSED(event)
220231
closeToolTip();
232+
233+
m_opacityAnim->stop();
234+
m_opacityAnim->setEndValue(kNormalOpacity);
235+
m_opacityAnim->start();
221236
}
222237

223238
// TODO: The reason we add this is because on openSUSE we can see render residue for those

src/loader/pluginitem.h

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

@@ -8,6 +8,8 @@
88
#include "pluginsiteminterface_v2.h"
99
#include "dockdbusproxy.h"
1010

11+
#include <QGraphicsOpacityEffect>
12+
#include <QPropertyAnimation>
1113
#include <QWidget>
1214

1315
const int Attribute_ForceUnDock = 0x800000;
@@ -73,10 +75,16 @@ class PluginItem : public QWidget
7375
QMenu *m_menu;
7476
QScopedPointer<DockDBusProxy> m_dbusProxy;
7577

78+
public:
79+
static constexpr qreal kNormalOpacity = 0.7;
80+
static constexpr qreal kHoverOpacity = 1.0;
81+
static constexpr int kOpacityAnimDuration = 150;
82+
7683
private:
7784
QTimer* m_tooltipTimer;
7885
QPointer<QWidget> m_tipsWidget;
79-
86+
QGraphicsOpacityEffect *m_opacityEffect;
87+
QPropertyAnimation *m_opacityAnim;
8088
QAction *m_unDockAction = nullptr;
8189
int m_pluginFlags = 0;
8290
int m_spacing = 0;

0 commit comments

Comments
 (0)