代码拉取完成,页面将自动刷新
同步操作将从 终端组/qt-notify 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <QDesktopWidget>
#include <QPropertyAnimation>
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include "notifymanager.h"
const int RIGHT = 10;
const int BOTTOM = 10;
const int HEIGHT = 60;
const int WIDTH = 300;
const int SPACE = 20;
NotifyManager::NotifyManager(QObject *parent): QObject(parent),
maxCount(6),
displayTime(10 * 1000)
{
}
void NotifyManager::notify(const QString &title, const QString &body, const QString &icon, const QString url)
{
dataQueue.enqueue(NotifyData(icon, title, body, url));
showNext();
}
void NotifyManager::setMaxCount(int count)
{
maxCount = count;
}
void NotifyManager::setDisplayTime(int ms)
{
displayTime = ms;
}
// 调整所有提醒框的位置
void NotifyManager::rearrange()
{
QDesktopWidget *desktop = QApplication::desktop();
QRect desktopRect = desktop->availableGeometry();
QPoint bottomRignt = desktopRect.bottomRight();
QList<Notify*>::iterator i;
for (i = notifyList.begin(); i != notifyList.end(); ++i) {
int index = notifyList.indexOf((*i));
QPoint pos = bottomRignt - QPoint(WIDTH + RIGHT, (HEIGHT + SPACE) * (index + 1) - SPACE + BOTTOM);
QPropertyAnimation *animation = new QPropertyAnimation((*i), "pos", this);
animation->setStartValue((*i)->pos());
animation->setEndValue(pos);
animation->setDuration(300);
animation->start();
connect(animation, &QPropertyAnimation::finished, this, [animation, this](){
animation->deleteLater();
});
}
}
void NotifyManager::showNext()
{
if(notifyList.size() >= maxCount || dataQueue.isEmpty()) {
return;
}
NotifyData data = dataQueue.dequeue();
Notify *notify = new Notify(this->displayTime);
notify->setIcon(data.icon);
notify->setTitle(data.title);
notify->setBody(data.body);
notify->setUrl(data.url);
notify->setFixedSize(WIDTH, HEIGHT);
QDesktopWidget *desktop = QApplication::desktop();
QRect desktopRect = desktop->availableGeometry();
// 计算提醒框的位置
QPoint bottomRignt = desktopRect.bottomRight();
QPoint pos = bottomRignt - QPoint(notify->width() + RIGHT, (HEIGHT + SPACE) * (notifyList.size() + 1) - SPACE + BOTTOM);
notify->move(pos);
notify->showGriant();
notifyList.append(notify);
connect(notify, &Notify::disappeared, this, [notify, this](){
this->notifyList.removeAll(notify);
this->rearrange();
// 如果列表是满的,重排完成后显示
if(this->notifyList.size() == this->maxCount - 1){
QTimer::singleShot(300, this, [this]{
this->showNext();
});
} else {
this->showNext();
}
notify->deleteLater();
});
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。