Commit 4af1d095 authored by Tim Jenssen's avatar Tim Jenssen
Browse files

added possiblity to keep the progress widget

  - the Nokia Qt SDK UpdateInfo plugin progress should stay in the
    progress view till the user clicks on it
  - now the futureprogress knows the difference between:
    KeepOnFinishTillUserInteraction and KeepOnFinish

Reviewed-by: con
parent 3051fd4c
......@@ -84,20 +84,24 @@ void FadeWidgetHack::paintEvent(QPaintEvent *)
struct FutureProgressPrivate {
explicit FutureProgressPrivate(FutureProgress *q);
void tryToFadeAway();
QFutureWatcher<void> m_watcher;
Internal::ProgressBar *m_progress;
QWidget *m_widget;
QHBoxLayout *m_widgetLayout;
QString m_type;
bool m_keep;
FutureProgress::KeepOnFinishType m_keep;
bool m_waitingForUserInteraction;
Internal::FadeWidgetHack *m_faderWidget;
FutureProgress *m_q;
bool m_isFading;
};
FutureProgressPrivate::FutureProgressPrivate(FutureProgress *q) :
m_progress(new Internal::ProgressBar), m_widget(0), m_widgetLayout(new QHBoxLayout),
m_keep(false), m_waitingForUserInteraction(false),
m_faderWidget(new Internal::FadeWidgetHack(q))
m_keep(FutureProgress::DontKeepOnFinish), m_waitingForUserInteraction(false),
m_faderWidget(new Internal::FadeWidgetHack(q)), m_q(q), m_isFading(false)
{
}
......@@ -224,7 +228,7 @@ void FutureProgress::setStarted()
bool FutureProgress::eventFilter(QObject *, QEvent *e)
{
if (d->m_waitingForUserInteraction
if (d->m_keep != KeepOnFinish && d->m_waitingForUserInteraction
&& (e->type() == QEvent::MouseMove || e->type() == QEvent::KeyPress)) {
qApp->removeEventFilter(this);
QTimer::singleShot(notificationTimeout, this, SLOT(fadeAway()));
......@@ -248,14 +252,26 @@ void FutureProgress::setFinished()
d->m_progress->setError(false);
}
emit finished();
if (d->m_keep) {
d->m_waitingForUserInteraction = true;
qApp->installEventFilter(this);
} else if (!d->m_progress->hasError()) {
QTimer::singleShot(shortNotificationTimeout, this, SLOT(fadeAway()));
d->tryToFadeAway();
}
void FutureProgressPrivate::tryToFadeAway()
{
if (m_isFading)
return;
if (m_keep == FutureProgress::KeepOnFinishTillUserInteraction) {
m_waitingForUserInteraction = true;
//eventfilter is needed to get user interaction
//events to start QTimer::singleShot later
qApp->installEventFilter(m_q);
m_isFading = true;
} else if (m_keep == FutureProgress::DontKeepOnFinish && !m_progress->hasError()) {
QTimer::singleShot(shortNotificationTimeout, m_q, SLOT(fadeAway()));
m_isFading = true;
}
}
void FutureProgress::setProgressRange(int min, int max)
{
d->m_progress->setRange(min, max);
......@@ -343,9 +359,17 @@ QString FutureProgress::type() const
return d->m_type;
}
void FutureProgress::setKeepOnFinish(bool keep)
void FutureProgress::setKeepOnFinish(KeepOnFinishType keepType)
{
d->m_keep = keep;
if (d->m_keep == keepType) {
return;
}
d->m_keep = keepType;
//if it is not finished tryToFadeAway is called by setFinished at the end
if (d->m_watcher.isFinished()) {
d->tryToFadeAway();
}
}
bool FutureProgress::keepOnFinish() const
......
......@@ -46,6 +46,11 @@ class CORE_EXPORT FutureProgress : public QWidget
Q_OBJECT
public:
enum KeepOnFinishType {
DontKeepOnFinish = 0,
KeepOnFinishTillUserInteraction = 1,
KeepOnFinish = 2
};
explicit FutureProgress(QWidget *parent = 0);
virtual ~FutureProgress();
......@@ -60,7 +65,7 @@ public:
void setType(const QString &type);
QString type() const;
void setKeepOnFinish(bool keep);
void setKeepOnFinish(KeepOnFinishType keepType);
bool keepOnFinish() const;
bool hasError() const;
......
......@@ -69,7 +69,11 @@ FutureProgress *ProgressView::addTask(const QFuture<void> &future,
m_layout->insertWidget(0, progress);
m_taskList.append(progress);
progress->setType(type);
progress->setKeepOnFinish(flags & ProgressManager::KeepOnFinish);
if (flags.testFlag(ProgressManager::KeepOnFinish)) {
progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
} else {
progress->setKeepOnFinish(FutureProgress::DontKeepOnFinish);
}
connect(progress, SIGNAL(removeMe()), this, SLOT(slotRemoveTask()));
return progress;
}
......
......@@ -786,7 +786,7 @@ void DebuggerEngine::startDebugger(DebuggerRunControl *runControl)
Core::FutureProgress *fp = Core::ICore::instance()->progressManager()
->addTask(d->m_progress.future(),
tr("Launching"), _("Debugger.Launcher"));
fp->setKeepOnFinish(false);
fp->setKeepOnFinish(Core::FutureProgress::DontKeepOnFinish);
d->m_progress.reportStarted();
}
QTC_ASSERT(runControl, notifyEngineSetupFailed(); return);
......
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