Skip to content

Commit 9861612

Browse files
committed
fix: replace ComboBox with Menu for notification actions
1. Replaced the ComboBox component with a custom NotifyActionMenu for displaying additional notification actions 2. Created new NotifyActionMenu.qml file implementing a Qt Labs Platform Menu with dynamic action items 3. Modified NotifyAction.qml to use NotifyActionButton with actionMenu property instead of ComboBox 4. Changed the "More" button behavior to open a menu instead of a dropdown combo box 5. Removed complex ComboBox width calculation logic and replaced with simpler menu implementation Log: Fixed notification action text truncation by replacing ComboBox with Menu Influence: 1. Test notification with multiple actions to ensure all actions are displayed without truncation 2. Verify that clicking the "More" button opens a menu showing all additional actions 3. Check that action menu items are properly triggered and invoke the correct actions 4. Test keyboard navigation between action buttons and menu items 5. Verify visual appearance and styling of the action menu matches system theme 6. Ensure menu positioning is correct relative to the notification action button fix: 修复通知操作文本被截断的问题 1. 将 ComboBox 组件替换为自定义的 NotifyActionMenu 用于显示额外的通知 操作 2. 创建新的 NotifyActionMenu.qml 文件,实现基于 Qt Labs Platform Menu 的 动态操作项 3. 修改 NotifyAction.qml,使用带有 actionMenu 属性的 NotifyActionButton 替代 ComboBox 4. 更改"更多"按钮行为,现在打开菜单而不是下拉组合框 5. 移除了复杂的 ComboBox 宽度计算逻辑,替换为更简单的菜单实现 Log: 通过将 ComboBox 替换为 Menu 修复通知操作文本被截断的问题 Influence: 1. 测试包含多个操作的通知,确保所有操作都能完整显示而不被截断 2. 验证点击"更多"按钮能正确打开显示所有额外操作的菜单 3. 检查菜单项是否能正确触发并调用相应的操作 4. 测试操作按钮和菜单项之间的键盘导航功能 5. 验证操作菜单的视觉外观和样式是否与系统主题匹配 6. 确保菜单位置相对于通知操作按钮的定位正确 PMS: BUG-312949
1 parent fe817da commit 9861612

3 files changed

Lines changed: 54 additions & 72 deletions

File tree

panels/notification/plugin/CMakeLists.txt

Lines changed: 2 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: GPL-3.0-or-later
44

@@ -19,6 +19,7 @@ qt_add_qml_module(notificationplugin
1919
SettingActionButton.qml
2020
OverlapIndicator.qml
2121
DropShadowText.qml
22+
NotifyActionMenu.qml
2223
OUTPUT_DIRECTORY
2324
${PROJECT_BINARY_DIR}/plugins/org/deepin/ds/notification/
2425
)

panels/notification/plugin/NotifyAction.qml

Lines changed: 19 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -149,56 +149,8 @@ Control {
149149
visible: active
150150
Layout.maximumWidth: 200
151151
Layout.alignment: Qt.AlignHCenter
152-
sourceComponent: ComboBox {
153-
id: comboBox
154-
flat: false
155-
rightPadding: 8
156-
leftPadding: 2
157-
topPadding: 0
158-
bottomPadding: 0
159-
property var expandActions: actions.slice(1)
160-
property real maxItemWidth: 0
161-
textRole: "text"
162-
implicitHeight: 30
163-
model: expandActions
164-
activeFocusOnTab: false
165-
popup.width: maxItemWidth + comboBox.padding + 28
166-
TextMetrics {
167-
id: textMetrics
168-
font: comboBox.font
169-
text: comboBox.displayText
170-
}
171-
172-
TextMetrics {
173-
id: itemTextMetrics
174-
font: comboBox.font
175-
}
176-
177-
popup.onAboutToShow: {
178-
let maxWidth = 0
179-
for (let i = 0; i < comboBox.model.length; i++) {
180-
if (comboBox.model[i] && comboBox.model[i].text) {
181-
itemTextMetrics.text = comboBox.model[i].text
182-
if (itemTextMetrics.width > maxWidth) {
183-
maxWidth = itemTextMetrics.width
184-
}
185-
}
186-
}
187-
maxItemWidth = maxWidth
188-
}
189-
190-
implicitWidth: textMetrics.width + comboBox.padding + 30
191-
background: NotifyItemBackground {
192-
leftInset: 2
193-
implicitHeight: 30
194-
implicitWidth: comboBox.width
195-
radius: 6
196-
outsideBorderColor: null
197-
insideBorderColor: null
198-
dropShadowColor: null
199-
backgroundColor: root.actionBackgroundColor
200-
anchors.fill: parent
201-
}
152+
sourceComponent: NotifyActionButton {
153+
actionData: actions.length > 2 ? actions[1] : null
202154
Keys.onBacktabPressed: function(event) {
203155
// Go back to first action button
204156
if (firstActionBtn.enabled) {
@@ -214,33 +166,23 @@ Control {
214166
root.gotoNextButton()
215167
event.accepted = true
216168
}
217-
delegate: MenuItem {
218-
required property int index
219-
text: model[index] ? model[index].text : ""
220-
221-
contentItem: Text {
222-
text: model[index] ? model[index].text : ""
223-
font: DTK.fontManager.t6
224-
color: parent.hovered ? parent.palette.highlightedText : parent.palette.text
225-
}
226-
onTriggered: {
227-
if (model[index]) {
228-
actionInvoked(model[index].id)
229-
comboBox.popup.close()
230-
}
231-
}
232-
background: Rectangle {
233-
radius: 6
234-
color: parent.hovered ? parent.palette.highlight : "transparent"
169+
actionMenu: NotifyActionMenu {
170+
onActionInvoked: function(actionId) {
171+
console.log("Action invoked from menu with ID:", actionId)
172+
root.actionInvoked(actionId)
235173
}
236174
}
175+
indicator: ButtonIndicator {
176+
color: "transparent"
177+
}
237178
}
238179
}
239180
}
240181

241182
component NotifyActionButton: Button {
242183
id: actionButton
243184
required property var actionData
185+
property var actionMenu: null
244186
text: actionData ? actionData.text : ""
245187
enabled: actionData ? actionData.enabled : false
246188
topPadding: undefined
@@ -251,9 +193,15 @@ Control {
251193
spacing: 0
252194
font: DTK.fontManager.t6
253195
onClicked: {
254-
if (actionData) {
255-
console.log("action invoked", actionData.id)
256-
actionInvoked(actionData.id)
196+
// Open the action menu when clicking the "More" button
197+
if (actionMenu) {
198+
actionMenu.actions = root.actions.slice(1)
199+
actionMenu.open(actionButton)
200+
} else {
201+
if (actionData) {
202+
console.log("action invoked", actionData.id)
203+
actionInvoked(actionData.id)
204+
}
257205
}
258206
}
259207

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import QtQuick
6+
import org.deepin.dtk 1.0
7+
import Qt.labs.platform 1.1 as LP
8+
import org.deepin.ds.notification
9+
10+
LP.Menu {
11+
id: root
12+
13+
property var actions: []
14+
15+
signal actionInvoked(var actionId)
16+
17+
Instantiator {
18+
model: root.actions
19+
delegate: LP.MenuItem {
20+
text: modelData.text
21+
onTriggered: {
22+
console.log("Action triggered: " + modelData.text + " (ID: " + modelData.id + ")")
23+
root.actionInvoked(modelData.id)
24+
}
25+
}
26+
onObjectAdded: function(index, object) {
27+
root.insertItem(index, object)
28+
}
29+
onObjectRemoved: function(index, object) {
30+
root.removeItem(object)
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)