Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion panels/notification/bubble/bubblemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
qDeleteAll(m_bubbles);
m_bubbles.clear();
endResetModel();
m_delayBubbles.clear();
m_delayRemovedBubble = -1;

updateLevel();
m_updateTimeTipTimer->stop();
Expand Down Expand Up @@ -111,8 +113,8 @@
if (m_bubbles.count() >= BubbleMaxCount) {
beginInsertRows(QModelIndex(), displayRowCount() - 1, displayRowCount() - 1);
endInsertRows();
updateLevel();
}
updateLevel();
}

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

BubbleItem *BubbleModel::removeById(qint64 id)
{
if (id == m_delayRemovedBubble) {
// Delayed remove
if (!m_delayBubbles.contains(id)) {
m_delayBubbles.append(id);
}
return nullptr;
}
for (const auto &item : m_bubbles) {
if (item->id() == id) {

Check warning on line 138 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
m_delayBubbles.removeAll(id);
remove(m_bubbles.indexOf(item));
return item;
}
Expand Down Expand Up @@ -158,6 +168,8 @@
switch (role) {
case BubbleModel::AppName:
return m_bubbles[row]->appName();
case BubbleModel::Id:
return m_bubbles[row]->id();
case BubbleModel::Body:
return m_bubbles[row]->body();
case BubbleModel::Summary:
Expand Down Expand Up @@ -190,6 +202,7 @@
{
QHash<int, QByteArray> mapRoleNames;
mapRoleNames[BubbleModel::AppName] = "appName";
mapRoleNames[BubbleModel::Id] = "id";
mapRoleNames[BubbleModel::Body] = "body";
mapRoleNames[BubbleModel::Summary] = "summary";
mapRoleNames[BubbleModel::IconName] = "iconName";
Expand Down Expand Up @@ -219,6 +232,27 @@
BubbleMaxCount = count;
}

qint64 BubbleModel::delayRemovedBubble() const

Check warning on line 235 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'delayRemovedBubble' is never used.
{
return m_delayRemovedBubble;
}

void BubbleModel::setDelayRemovedBubble(qint64 newDelayRemovedBubble)

Check warning on line 240 in panels/notification/bubble/bubblemodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setDelayRemovedBubble' is never used.
{
if (m_delayRemovedBubble == newDelayRemovedBubble)
return;
const auto oldDelayRemovedBubble = m_delayRemovedBubble;
if (m_delayBubbles.contains(oldDelayRemovedBubble)) {
// Remove last delayed bubble.
QTimer::singleShot(DelayRemovBubbleTime, this, [this, oldDelayRemovedBubble]() {
removeById(oldDelayRemovedBubble);
});
}

m_delayRemovedBubble = newDelayRemovedBubble;
emit delayRemovedBubbleChanged();
}

int BubbleModel::replaceBubbleIndex(const BubbleItem *bubble) const
{
if (bubble->replacesId() != NoReplaceId) {
Expand Down
11 changes: 11 additions & 0 deletions panels/notification/bubble/bubblemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class BubbleItem;
class BubbleModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(qint64 delayRemovedBubble READ delayRemovedBubble WRITE setDelayRemovedBubble NOTIFY delayRemovedBubbleChanged FINAL)
public:
enum {
AppName = Qt::UserRole + 1,
Id,
Body,
Summary,
IconName,
Expand Down Expand Up @@ -58,6 +60,12 @@ class BubbleModel : public QAbstractListModel
int overlayCount() const;
void setBubbleCount(int count);

qint64 delayRemovedBubble() const;
void setDelayRemovedBubble(qint64 newDelayRemovedBubble);

signals:
void delayRemovedBubbleChanged();

private:
int replaceBubbleIndex(const BubbleItem *bubble) const;
void updateLevel();
Expand All @@ -70,6 +78,9 @@ class BubbleModel : public QAbstractListModel
const int LastBubbleMaxIndex{BubbleMaxCount - 1};
const int OverlayMaxCount{2};
const int NoReplaceId{0};
QList<qint64> m_delayBubbles;
qint64 m_delayRemovedBubble{-1};
const int DelayRemovBubbleTime{1000};
};

}
7 changes: 7 additions & 0 deletions panels/notification/bubble/package/Bubble.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import org.deepin.dtk 1.0 as D
D.Control {
id: control
property var bubble
onHoveredChanged: function () {
if (control.hovered) {
Applet.bubbles.delayRemovedBubble = bubble.id
} else {
Applet.bubbles.delayRemovedBubble = -1
}
}

contentItem: Loader {
sourceComponent: bubble.level <= 1 ? normalCom : overlayCom
Expand Down
Loading