Commit d450bcd7 authored by mae's avatar mae

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
parent 907e0e7f
......@@ -35,10 +35,25 @@
#include <QtGui/QMenu>
#include <QtGui/QProgressBar>
#include <QtGui/QHBoxLayout>
#include <QtGui/QPainter>
#include <QtCore/QTimer>
#include <QtCore/QCoreApplication>
#include <QtCore/QPropertyAnimation>
#include <utils/stylehelper.h>
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
\class Core::FutureProgress
......@@ -96,6 +111,10 @@ FutureProgress::FutureProgress(QWidget *parent)
connect(&m_watcher, SIGNAL(progressTextChanged(const QString&)),
this, SLOT(setProgressText(const QString&)));
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());
}
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()
{
updateToolTip(m_watcher.future().progressText());
......@@ -171,6 +201,12 @@ void FutureProgress::setFinished()
m_progress->setError(false);
}
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)
......@@ -217,6 +253,11 @@ void FutureProgress::mousePressEvent(QMouseEvent *event)
QWidget::mousePressEvent(event);
}
void FutureProgress::resizeEvent(QResizeEvent *)
{
m_faderWidget->setGeometry(rect());
}
/*!
\fn bool FutureProgress::hasError() const
Returns the error state of this progress indicator.
......@@ -225,3 +266,13 @@ bool FutureProgress::hasError() const
{
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 {
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
{
Q_OBJECT
......@@ -54,12 +71,20 @@ public:
FutureProgress(QWidget *parent = 0);
~FutureProgress();
bool eventFilter(QObject *object, QEvent *);
void setFuture(const QFuture<void> &future);
QFuture<void> future() const;
void setTitle(const QString &title);
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;
void setWidget(QWidget *widget);
......@@ -68,9 +93,11 @@ public:
signals:
void clicked();
void finished();
void removeMe();
protected:
void mousePressEvent(QMouseEvent *event);
void resizeEvent(QResizeEvent *);
private slots:
void updateToolTip(const QString &);
......@@ -80,12 +107,18 @@ private slots:
void setProgressRange(int min, int max);
void setProgressValue(int val);
void setProgressText(const QString &text);
void fadeAway();
private:
QFutureWatcher<void> m_watcher;
ProgressBar *m_progress;
QWidget *m_widget;
QHBoxLayout *m_widgetLayout;
QString m_type;
bool m_keep;
bool m_waitingForUserInteraction;
FadeWidgetHack *m_faderWidget;
};
} // namespace Core
......
......@@ -51,8 +51,6 @@ ProgressView::~ProgressView()
{
qDeleteAll(m_taskList);
m_taskList.clear();
m_type.clear();
m_keep.clear();
}
FutureProgress *ProgressView::addTask(const QFuture<void> &future,
......@@ -66,11 +64,12 @@ FutureProgress *ProgressView::addTask(const QFuture<void> &future,
FutureProgress *progress = new FutureProgress(this);
progress->setTitle(title);
progress->setFuture(future);
m_layout->insertWidget(0, progress);
m_taskList.append(progress);
m_type.insert(progress, type);
m_keep.insert(progress, (flags & ProgressManager::KeepOnFinish));
connect(progress, SIGNAL(finished()), this, SLOT(slotFinished()));
progress->setType(type);
progress->setKeepOnFinish(flags & ProgressManager::KeepOnFinish);
connect(progress, SIGNAL(removeMe()), this, SLOT(slotRemoveTask()));
return progress;
}
......@@ -80,7 +79,7 @@ void ProgressView::removeOldTasks(const QString &type, bool keepOne)
QList<FutureProgress *>::iterator i = m_taskList.end();
while (i != m_taskList.begin()) {
--i;
if (m_type.value(*i) == type) {
if ((*i)->type() == type) {
if (firstFound && (*i)->future().isFinished()) {
deleteTask(*i);
i = m_taskList.erase(i);
......@@ -92,8 +91,6 @@ void ProgressView::removeOldTasks(const QString &type, bool keepOne)
void ProgressView::deleteTask(FutureProgress *progress)
{
m_type.remove(progress);
m_keep.remove(progress);
layout()->removeWidget(progress);
progress->hide();
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
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
QString type = m_type.value(*i);
if (m_type.keys(type).size() > 1) { // don't care for optimizations it's only a handful of entries
QString type = (*i)->type();
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);
i = m_taskList.erase(i);
return;
......@@ -132,11 +135,11 @@ void ProgressView::removeTask(FutureProgress *task)
deleteTask(task);
}
void ProgressView::slotFinished()
void ProgressView::slotRemoveTask()
{
FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
QTC_ASSERT(progress, return);
if (m_keep.contains(progress) && !m_keep.value(progress) && !progress->hasError())
removeTask(progress);
removeOldTasks(m_type.value(progress), true);
QString type = progress->type();
removeTask(progress);
removeOldTasks(type, true);
}
......@@ -58,7 +58,7 @@ public:
ProgressManager::ProgressFlags flags);
private slots:
void slotFinished();
void slotRemoveTask();
private:
void removeOldTasks(const QString &type, bool keepOne = false);
......@@ -68,8 +68,6 @@ private:
QVBoxLayout *m_layout;
QList<FutureProgress *> m_taskList;
QHash<FutureProgress *, QString> m_type;
QHash<FutureProgress *, bool> m_keep;
};
} // namespace Internal
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment