Skip to content

Commit 36ae417

Browse files
18202781743deepin-bot[bot]
authored andcommitted
fix: bubble closed when it's still hovering for notification
Add a list to delay remove Bubble when it's timeout. Remove bubble when delayRemoveBubble changed. pms: Bug-283823
1 parent 41e0f3c commit 36ae417

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

panels/notification/bubble/bubblemodel.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ void BubbleModel::clear()
8282
qDeleteAll(m_bubbles);
8383
m_bubbles.clear();
8484
endResetModel();
85+
m_delayBubbles.clear();
86+
m_delayRemovedBubble = -1;
8587

8688
updateLevel();
8789
m_updateTimeTipTimer->stop();
@@ -111,8 +113,8 @@ void BubbleModel::remove(int index)
111113
if (m_bubbles.count() >= BubbleMaxCount) {
112114
beginInsertRows(QModelIndex(), displayRowCount() - 1, displayRowCount() - 1);
113115
endInsertRows();
114-
updateLevel();
115116
}
117+
updateLevel();
116118
}
117119

118120
void BubbleModel::remove(const BubbleItem *bubble)
@@ -125,8 +127,16 @@ void BubbleModel::remove(const BubbleItem *bubble)
125127

126128
BubbleItem *BubbleModel::removeById(qint64 id)
127129
{
130+
if (id == m_delayRemovedBubble) {
131+
// Delayed remove
132+
if (!m_delayBubbles.contains(id)) {
133+
m_delayBubbles.append(id);
134+
}
135+
return nullptr;
136+
}
128137
for (const auto &item : m_bubbles) {
129138
if (item->id() == id) {
139+
m_delayBubbles.removeAll(id);
130140
remove(m_bubbles.indexOf(item));
131141
return item;
132142
}
@@ -158,6 +168,8 @@ QVariant BubbleModel::data(const QModelIndex &index, int role) const
158168
switch (role) {
159169
case BubbleModel::AppName:
160170
return m_bubbles[row]->appName();
171+
case BubbleModel::Id:
172+
return m_bubbles[row]->id();
161173
case BubbleModel::Body:
162174
return m_bubbles[row]->body();
163175
case BubbleModel::Summary:
@@ -190,6 +202,7 @@ QHash<int, QByteArray> BubbleModel::roleNames() const
190202
{
191203
QHash<int, QByteArray> mapRoleNames;
192204
mapRoleNames[BubbleModel::AppName] = "appName";
205+
mapRoleNames[BubbleModel::Id] = "id";
193206
mapRoleNames[BubbleModel::Body] = "body";
194207
mapRoleNames[BubbleModel::Summary] = "summary";
195208
mapRoleNames[BubbleModel::IconName] = "iconName";
@@ -219,6 +232,27 @@ void BubbleModel::setBubbleCount(int count)
219232
BubbleMaxCount = count;
220233
}
221234

235+
qint64 BubbleModel::delayRemovedBubble() const
236+
{
237+
return m_delayRemovedBubble;
238+
}
239+
240+
void BubbleModel::setDelayRemovedBubble(qint64 newDelayRemovedBubble)
241+
{
242+
if (m_delayRemovedBubble == newDelayRemovedBubble)
243+
return;
244+
const auto oldDelayRemovedBubble = m_delayRemovedBubble;
245+
if (m_delayBubbles.contains(oldDelayRemovedBubble)) {
246+
// Remove last delayed bubble.
247+
QTimer::singleShot(DelayRemovBubbleTime, this, [this, oldDelayRemovedBubble]() {
248+
removeById(oldDelayRemovedBubble);
249+
});
250+
}
251+
252+
m_delayRemovedBubble = newDelayRemovedBubble;
253+
emit delayRemovedBubbleChanged();
254+
}
255+
222256
int BubbleModel::replaceBubbleIndex(const BubbleItem *bubble) const
223257
{
224258
if (bubble->replacesId() != NoReplaceId) {

panels/notification/bubble/bubblemodel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ class BubbleItem;
1616
class BubbleModel : public QAbstractListModel
1717
{
1818
Q_OBJECT
19+
Q_PROPERTY(qint64 delayRemovedBubble READ delayRemovedBubble WRITE setDelayRemovedBubble NOTIFY delayRemovedBubbleChanged FINAL)
1920
public:
2021
enum {
2122
AppName = Qt::UserRole + 1,
23+
Id,
2224
Body,
2325
Summary,
2426
IconName,
@@ -58,6 +60,12 @@ class BubbleModel : public QAbstractListModel
5860
int overlayCount() const;
5961
void setBubbleCount(int count);
6062

63+
qint64 delayRemovedBubble() const;
64+
void setDelayRemovedBubble(qint64 newDelayRemovedBubble);
65+
66+
signals:
67+
void delayRemovedBubbleChanged();
68+
6169
private:
6270
int replaceBubbleIndex(const BubbleItem *bubble) const;
6371
void updateLevel();
@@ -70,6 +78,9 @@ class BubbleModel : public QAbstractListModel
7078
const int LastBubbleMaxIndex{BubbleMaxCount - 1};
7179
const int OverlayMaxCount{2};
7280
const int NoReplaceId{0};
81+
QList<qint64> m_delayBubbles;
82+
qint64 m_delayRemovedBubble{-1};
83+
const int DelayRemovBubbleTime{1000};
7384
};
7485

7586
}

panels/notification/bubble/package/Bubble.qml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import org.deepin.dtk 1.0 as D
1111
D.Control {
1212
id: control
1313
property var bubble
14+
onHoveredChanged: function () {
15+
if (control.hovered) {
16+
Applet.bubbles.delayRemovedBubble = bubble.id
17+
} else {
18+
Applet.bubbles.delayRemovedBubble = -1
19+
}
20+
}
1421

1522
contentItem: Loader {
1623
sourceComponent: bubble.level <= 1 ? normalCom : overlayCom

0 commit comments

Comments
 (0)