Skip to content

Commit 5251c44

Browse files
committed
refactor: move dock context menu implementation to loader module
1. Deleted old dock context menu files from plugins/dde-dock/common 2. Created new simplified DockContextMenu class in src/loader 3. Simplified menu implementation by removing width calculation and Wayland specific code 4. Changed PluginItem to use new DockContextMenu class 5. Moved reminder dot painting logic directly into paintEvent 6. Updated CMakeLists.txt to include new files The change was made to: 1. Reduce complexity by removing unused features 2. Move menu implementation closer to where it's actually used 3. Simplify maintenance by having a single implementation 4. Remove dependency on Wayland-specific code in common module refactor: 将停靠栏上下文菜单实现移至加载器模块 1. 从 plugins/dde-dock/common 删除旧的停靠栏上下文菜单文件 2. 在 src/loader 中创建新的简化版 DockContextMenu 类 3. 通过移除宽度计算和Wayland特定代码简化菜单实现 4. 修改 PluginItem 使用新的 DockContextMenu 类 5. 将提醒点绘制逻辑直接移到 paintEvent 中 6. 更新 CMakeLists.txt 包含新文件 这些修改的目的: 1. 通过移除未使用功能降低复杂性 2. 将菜单实现移到实际使用的位置 3. 通过单一实现简化维护 4. 移除公共模块中对Wayland特定代码的依赖 pms: TASK-377199
1 parent 2c0ab4e commit 5251c44

7 files changed

Lines changed: 60 additions & 193 deletions

File tree

plugins/dde-dock/common/dockcontextmenu.cpp

Lines changed: 0 additions & 129 deletions
This file was deleted.

plugins/dde-dock/common/dockcontextmenu.h

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/loader/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ add_executable(trayplugin-loader
2828
loader.qrc
2929
dqwaylandplatform.h
3030
dqwaylandplatform.cpp
31+
dockcontextmenu.h
32+
dockcontextmenu.cpp
3133
)
3234

3335
target_include_directories(trayplugin-loader PUBLIC

src/loader/dockcontextmenu.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
2+
//
3+
//SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "dockcontextmenu.h"
6+
7+
#include <QPainter>
8+
#include <QWindow>
9+
10+
static const bool IS_WAYLAND_DISPLAY = !qgetenv("WAYLAND_DISPLAY").isEmpty();
11+
12+
DockContextMenu::DockContextMenu(QWidget *parent)
13+
: QMenu(parent)
14+
{
15+
// 解决键盘上下键不能操作右键菜单
16+
if (IS_WAYLAND_DISPLAY) {
17+
setAttribute(Qt::WA_NativeWindow);
18+
windowHandle()->setProperty("_d_dwayland_window-type", "focusmenu");
19+
}
20+
}
21+
22+
void DockContextMenu::paintEvent(QPaintEvent* e)
23+
{
24+
QMenu::paintEvent(e);
25+
26+
QPainter p(this);
27+
p.setRenderHint(QPainter::Antialiasing, true);
28+
for (auto action : actions()) {
29+
if (action->property("showReminder").toBool()) {
30+
auto geo = actionGeometry(action);
31+
QColor color("#FF3B30");
32+
p.setPen(color);
33+
p.setBrush(color);
34+
p.drawEllipse(geo.x() + geo.width() - 26, geo.y() + (geo.height() - 6) / 2, 6, 6);
35+
}
36+
}
37+
38+
p.end();
39+
}

src/loader/dockcontextmenu.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
2+
//
3+
//SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include <QMenu>
6+
7+
class DockContextMenu : public QMenu
8+
{
9+
public:
10+
explicit DockContextMenu(QWidget *parent = nullptr);
11+
12+
protected:
13+
void paintEvent(QPaintEvent* e) override;
14+
};

src/loader/pluginitem.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "pluginitem.h"
77
#include "plugin.h"
88
#include "widgetplugin.h"
9+
#include "dockcontextmenu.h"
910

1011
#include <QHBoxLayout>
1112
#include <QMouseEvent>
@@ -17,7 +18,7 @@ PluginItem::PluginItem(PluginsItemInterface *pluginItemInterface, const QString
1718
: QWidget(parent)
1819
, m_pluginsItemInterface(pluginItemInterface)
1920
, m_itemKey(itemKey)
20-
, m_menu(new QMenu)
21+
, m_menu(new DockContextMenu(this))
2122
, m_tooltipTimer(new QTimer(this))
2223
, m_tipsWidget(nullptr)
2324
{
@@ -291,6 +292,8 @@ void PluginItem::initPluginMenu()
291292
action->setChecked(itemObj.value("checked").toBool());
292293
action->setData(itemObj.value("itemId").toString());
293294
action->setEnabled(itemObj.value("isActive").toBool());
295+
auto showReminder = itemObj.value("showReminder").toBool();
296+
action->setProperty("showReminder", showReminder);
294297
m_menu->addAction(action);
295298
}
296299
}

src/loader/pluginitem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
const int Attribute_ForceUnDock = 0x800000;
1414

15-
class QMenu;
15+
class DockContextMenu;
1616
class PluginItem : public QWidget
1717
{
1818
Q_OBJECT

0 commit comments

Comments
 (0)