forked from qt-creator/qt-creator
Keep notification bar clean
The patch makes notification items fade away after 5 seconds. KeepOnFinish items like the build notification are kept for 5 seconds after the user interacts with mouse or keyboard. Done-width: jbache
This commit is contained in:
@@ -35,10 +35,25 @@
|
|||||||
#include <QtGui/QMenu>
|
#include <QtGui/QMenu>
|
||||||
#include <QtGui/QProgressBar>
|
#include <QtGui/QProgressBar>
|
||||||
#include <QtGui/QHBoxLayout>
|
#include <QtGui/QHBoxLayout>
|
||||||
|
#include <QtGui/QPainter>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include <QtCore/QPropertyAnimation>
|
||||||
|
#include <utils/stylehelper.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
|
||||||
|
void FadeWidgetHack::paintEvent(QPaintEvent *)
|
||||||
|
{
|
||||||
|
if (m_opacity == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QPainter p(this);
|
||||||
|
p.setOpacity(m_opacity);
|
||||||
|
Utils::StyleHelper::verticalGradient(&p, rect(), rect());
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\mainclass
|
\mainclass
|
||||||
\class Core::FutureProgress
|
\class Core::FutureProgress
|
||||||
@@ -96,6 +111,10 @@ FutureProgress::FutureProgress(QWidget *parent)
|
|||||||
connect(&m_watcher, SIGNAL(progressTextChanged(const QString&)),
|
connect(&m_watcher, SIGNAL(progressTextChanged(const QString&)),
|
||||||
this, SLOT(setProgressText(const QString&)));
|
this, SLOT(setProgressText(const QString&)));
|
||||||
connect(m_progress, SIGNAL(clicked()), this, SLOT(cancel()));
|
connect(m_progress, SIGNAL(clicked()), this, SLOT(cancel()));
|
||||||
|
|
||||||
|
m_keep = false;
|
||||||
|
m_waitingForUserInteraction = false;
|
||||||
|
m_faderWidget = new FadeWidgetHack(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -162,6 +181,17 @@ void FutureProgress::setStarted()
|
|||||||
m_progress->setValue(m_watcher.progressValue());
|
m_progress->setValue(m_watcher.progressValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FutureProgress::eventFilter(QObject *, QEvent *e)
|
||||||
|
{
|
||||||
|
if (m_waitingForUserInteraction
|
||||||
|
&& (e->type() == QEvent::MouseMove || e->type() == QEvent::KeyPress)) {
|
||||||
|
qApp->removeEventFilter(this);
|
||||||
|
QTimer::singleShot(5000, this, SLOT(fadeAway()));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void FutureProgress::setFinished()
|
void FutureProgress::setFinished()
|
||||||
{
|
{
|
||||||
updateToolTip(m_watcher.future().progressText());
|
updateToolTip(m_watcher.future().progressText());
|
||||||
@@ -171,6 +201,12 @@ void FutureProgress::setFinished()
|
|||||||
m_progress->setError(false);
|
m_progress->setError(false);
|
||||||
}
|
}
|
||||||
emit finished();
|
emit finished();
|
||||||
|
if (m_keep) {
|
||||||
|
m_waitingForUserInteraction = true;
|
||||||
|
qApp->installEventFilter(this);
|
||||||
|
} else {
|
||||||
|
QTimer::singleShot(5000, this, SLOT(fadeAway()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FutureProgress::setProgressRange(int min, int max)
|
void FutureProgress::setProgressRange(int min, int max)
|
||||||
@@ -217,6 +253,11 @@ void FutureProgress::mousePressEvent(QMouseEvent *event)
|
|||||||
QWidget::mousePressEvent(event);
|
QWidget::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FutureProgress::resizeEvent(QResizeEvent *)
|
||||||
|
{
|
||||||
|
m_faderWidget->setGeometry(rect());
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool FutureProgress::hasError() const
|
\fn bool FutureProgress::hasError() const
|
||||||
Returns the error state of this progress indicator.
|
Returns the error state of this progress indicator.
|
||||||
@@ -225,3 +266,13 @@ bool FutureProgress::hasError() const
|
|||||||
{
|
{
|
||||||
return m_progress->hasError();
|
return m_progress->hasError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FutureProgress::fadeAway()
|
||||||
|
{
|
||||||
|
m_faderWidget->raise();
|
||||||
|
QPropertyAnimation *animation = new QPropertyAnimation(m_faderWidget, "opacity");
|
||||||
|
animation->setDuration(600);
|
||||||
|
animation->setEndValue(1.0);
|
||||||
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||||
|
connect(animation, SIGNAL(finished()), this, SIGNAL(removeMe()));
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,6 +46,23 @@ class ProgressBar;
|
|||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
class FadeWidgetHack : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(float opacity READ opacity WRITE setOpacity)
|
||||||
|
public:
|
||||||
|
FadeWidgetHack(QWidget *parent):QWidget(parent), m_opacity(0){
|
||||||
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
}
|
||||||
|
void paintEvent(QPaintEvent *);
|
||||||
|
|
||||||
|
void setOpacity(float o) { m_opacity = o; update(); }
|
||||||
|
float opacity() const { return m_opacity; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
float m_opacity;
|
||||||
|
};
|
||||||
|
|
||||||
class CORE_EXPORT FutureProgress : public QWidget
|
class CORE_EXPORT FutureProgress : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -54,12 +71,20 @@ public:
|
|||||||
FutureProgress(QWidget *parent = 0);
|
FutureProgress(QWidget *parent = 0);
|
||||||
~FutureProgress();
|
~FutureProgress();
|
||||||
|
|
||||||
|
bool eventFilter(QObject *object, QEvent *);
|
||||||
|
|
||||||
void setFuture(const QFuture<void> &future);
|
void setFuture(const QFuture<void> &future);
|
||||||
QFuture<void> future() const;
|
QFuture<void> future() const;
|
||||||
|
|
||||||
void setTitle(const QString &title);
|
void setTitle(const QString &title);
|
||||||
QString title() const;
|
QString title() const;
|
||||||
|
|
||||||
|
void setType(const QString &type) {m_type = type; }
|
||||||
|
QString type() const { return m_type; }
|
||||||
|
|
||||||
|
void setKeepOnFinish(bool keep) { m_keep = keep; }
|
||||||
|
bool keepOnFinish() const { return m_keep; }
|
||||||
|
|
||||||
bool hasError() const;
|
bool hasError() const;
|
||||||
|
|
||||||
void setWidget(QWidget *widget);
|
void setWidget(QWidget *widget);
|
||||||
@@ -68,9 +93,11 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void clicked();
|
void clicked();
|
||||||
void finished();
|
void finished();
|
||||||
|
void removeMe();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateToolTip(const QString &);
|
void updateToolTip(const QString &);
|
||||||
@@ -80,12 +107,18 @@ private slots:
|
|||||||
void setProgressRange(int min, int max);
|
void setProgressRange(int min, int max);
|
||||||
void setProgressValue(int val);
|
void setProgressValue(int val);
|
||||||
void setProgressText(const QString &text);
|
void setProgressText(const QString &text);
|
||||||
|
void fadeAway();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFutureWatcher<void> m_watcher;
|
QFutureWatcher<void> m_watcher;
|
||||||
ProgressBar *m_progress;
|
ProgressBar *m_progress;
|
||||||
QWidget *m_widget;
|
QWidget *m_widget;
|
||||||
QHBoxLayout *m_widgetLayout;
|
QHBoxLayout *m_widgetLayout;
|
||||||
|
QString m_type;
|
||||||
|
bool m_keep;
|
||||||
|
bool m_waitingForUserInteraction;
|
||||||
|
FadeWidgetHack *m_faderWidget;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ ProgressView::~ProgressView()
|
|||||||
{
|
{
|
||||||
qDeleteAll(m_taskList);
|
qDeleteAll(m_taskList);
|
||||||
m_taskList.clear();
|
m_taskList.clear();
|
||||||
m_type.clear();
|
|
||||||
m_keep.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureProgress *ProgressView::addTask(const QFuture<void> &future,
|
FutureProgress *ProgressView::addTask(const QFuture<void> &future,
|
||||||
@@ -66,11 +64,12 @@ FutureProgress *ProgressView::addTask(const QFuture<void> &future,
|
|||||||
FutureProgress *progress = new FutureProgress(this);
|
FutureProgress *progress = new FutureProgress(this);
|
||||||
progress->setTitle(title);
|
progress->setTitle(title);
|
||||||
progress->setFuture(future);
|
progress->setFuture(future);
|
||||||
|
|
||||||
m_layout->insertWidget(0, progress);
|
m_layout->insertWidget(0, progress);
|
||||||
m_taskList.append(progress);
|
m_taskList.append(progress);
|
||||||
m_type.insert(progress, type);
|
progress->setType(type);
|
||||||
m_keep.insert(progress, (flags & ProgressManager::KeepOnFinish));
|
progress->setKeepOnFinish(flags & ProgressManager::KeepOnFinish);
|
||||||
connect(progress, SIGNAL(finished()), this, SLOT(slotFinished()));
|
connect(progress, SIGNAL(removeMe()), this, SLOT(slotRemoveTask()));
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +79,7 @@ void ProgressView::removeOldTasks(const QString &type, bool keepOne)
|
|||||||
QList<FutureProgress *>::iterator i = m_taskList.end();
|
QList<FutureProgress *>::iterator i = m_taskList.end();
|
||||||
while (i != m_taskList.begin()) {
|
while (i != m_taskList.begin()) {
|
||||||
--i;
|
--i;
|
||||||
if (m_type.value(*i) == type) {
|
if ((*i)->type() == type) {
|
||||||
if (firstFound && (*i)->future().isFinished()) {
|
if (firstFound && (*i)->future().isFinished()) {
|
||||||
deleteTask(*i);
|
deleteTask(*i);
|
||||||
i = m_taskList.erase(i);
|
i = m_taskList.erase(i);
|
||||||
@@ -92,8 +91,6 @@ void ProgressView::removeOldTasks(const QString &type, bool keepOne)
|
|||||||
|
|
||||||
void ProgressView::deleteTask(FutureProgress *progress)
|
void ProgressView::deleteTask(FutureProgress *progress)
|
||||||
{
|
{
|
||||||
m_type.remove(progress);
|
|
||||||
m_keep.remove(progress);
|
|
||||||
layout()->removeWidget(progress);
|
layout()->removeWidget(progress);
|
||||||
progress->hide();
|
progress->hide();
|
||||||
progress->deleteLater();
|
progress->deleteLater();
|
||||||
@@ -113,8 +110,14 @@ void ProgressView::removeOneOldTask()
|
|||||||
}
|
}
|
||||||
// no ended process, look for a task type with multiple running tasks and remove the oldest one
|
// no ended process, look for a task type with multiple running tasks and remove the oldest one
|
||||||
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
|
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
|
||||||
QString type = m_type.value(*i);
|
QString type = (*i)->type();
|
||||||
if (m_type.keys(type).size() > 1) { // don't care for optimizations it's only a handful of entries
|
|
||||||
|
int taskCount = 0;
|
||||||
|
foreach (FutureProgress *p, m_taskList)
|
||||||
|
if (p->type() == type)
|
||||||
|
++taskCount;
|
||||||
|
|
||||||
|
if (taskCount > 1) { // don't care for optimizations it's only a handful of entries
|
||||||
deleteTask(*i);
|
deleteTask(*i);
|
||||||
i = m_taskList.erase(i);
|
i = m_taskList.erase(i);
|
||||||
return;
|
return;
|
||||||
@@ -132,11 +135,11 @@ void ProgressView::removeTask(FutureProgress *task)
|
|||||||
deleteTask(task);
|
deleteTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressView::slotFinished()
|
void ProgressView::slotRemoveTask()
|
||||||
{
|
{
|
||||||
FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
|
FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
|
||||||
QTC_ASSERT(progress, return);
|
QTC_ASSERT(progress, return);
|
||||||
if (m_keep.contains(progress) && !m_keep.value(progress) && !progress->hasError())
|
QString type = progress->type();
|
||||||
removeTask(progress);
|
removeTask(progress);
|
||||||
removeOldTasks(m_type.value(progress), true);
|
removeOldTasks(type, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
ProgressManager::ProgressFlags flags);
|
ProgressManager::ProgressFlags flags);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotFinished();
|
void slotRemoveTask();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void removeOldTasks(const QString &type, bool keepOne = false);
|
void removeOldTasks(const QString &type, bool keepOne = false);
|
||||||
@@ -68,8 +68,6 @@ private:
|
|||||||
|
|
||||||
QVBoxLayout *m_layout;
|
QVBoxLayout *m_layout;
|
||||||
QList<FutureProgress *> m_taskList;
|
QList<FutureProgress *> m_taskList;
|
||||||
QHash<FutureProgress *, QString> m_type;
|
|
||||||
QHash<FutureProgress *, bool> m_keep;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user