diff options
author | Eike Ziller <eike.ziller@qt.io> | 2019-03-27 16:48:28 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2019-04-04 10:43:25 +0000 |
commit | d2242babeb4f34187073dbcb051afadd285ad216 (patch) | |
tree | aaa424e8f43a86cf063357482bc966697a782a62 /src | |
parent | a78655e52112e32b87b871b2b4ea907554039ab1 (diff) | |
download | qt-creator-d2242babeb4f34187073dbcb051afadd285ad216.tar.gz |
Add API for another info string for progress bars
Adds a "subtitle" text that is shown below the progress
bar if it is set, similar to how it is done manually for
the search result "Found 123." counter.
Optionally also shown in the status bar if the details are
not open (like for the search result counter).
Task-number: QTCREATORBUG-21584
Change-Id: I0b3bf52567227f7c07de51520079c0b12a265be3
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src')
6 files changed, 99 insertions, 20 deletions
diff --git a/src/plugins/coreplugin/progressmanager/futureprogress.cpp b/src/plugins/coreplugin/progressmanager/futureprogress.cpp index d7eeec9ff4..32193fd08b 100644 --- a/src/plugins/coreplugin/progressmanager/futureprogress.cpp +++ b/src/plugins/coreplugin/progressmanager/futureprogress.cpp @@ -71,6 +71,7 @@ public: FutureProgress *m_q; bool m_fadeStarting; bool m_isFading; + bool m_isSubtitleVisibleInStatusBar = false; }; FutureProgressPrivate::FutureProgressPrivate(FutureProgress *q) : @@ -188,6 +189,33 @@ QString FutureProgress::title() const return d->m_progress->title(); } +void FutureProgress::setSubtitle(const QString &subtitle) +{ + if (subtitle != d->m_progress->subtitle()) { + d->m_progress->setSubtitle(subtitle); + if (d->m_isSubtitleVisibleInStatusBar) + emit subtitleInStatusBarChanged(); + } +} + +QString FutureProgress::subtitle() const +{ + return d->m_progress->subtitle(); +} + +void FutureProgress::setSubtitleVisibleInStatusBar(bool visible) +{ + if (visible != d->m_isSubtitleVisibleInStatusBar) { + d->m_isSubtitleVisibleInStatusBar = visible; + emit subtitleInStatusBarChanged(); + } +} + +bool FutureProgress::isSubtitleVisibleInStatusBar() const +{ + return d->m_isSubtitleVisibleInStatusBar; +} + void FutureProgress::cancel() { d->m_watcher.future().cancel(); diff --git a/src/plugins/coreplugin/progressmanager/futureprogress.h b/src/plugins/coreplugin/progressmanager/futureprogress.h index 3f591b2b94..09b178dff2 100644 --- a/src/plugins/coreplugin/progressmanager/futureprogress.h +++ b/src/plugins/coreplugin/progressmanager/futureprogress.h @@ -56,6 +56,12 @@ public: void setTitle(const QString &title); QString title() const; + void setSubtitle(const QString &subtitle); + QString subtitle() const; + + void setSubtitleVisibleInStatusBar(bool visible); + bool isSubtitleVisibleInStatusBar() const; + void setType(Id type); Id type() const; @@ -83,6 +89,7 @@ signals: void fadeStarted(); void statusBarWidgetChanged(); + void subtitleInStatusBarChanged(); protected: void mousePressEvent(QMouseEvent *event) override; diff --git a/src/plugins/coreplugin/progressmanager/progressbar.cpp b/src/plugins/coreplugin/progressmanager/progressbar.cpp index 5a97a282d7..bf6f7d8e19 100644 --- a/src/plugins/coreplugin/progressmanager/progressbar.cpp +++ b/src/plugins/coreplugin/progressmanager/progressbar.cpp @@ -139,6 +139,18 @@ bool ProgressBar::isTitleVisible() const return m_titleVisible; } +void ProgressBar::setSubtitle(const QString &subtitle) +{ + m_subtitle = subtitle; + updateGeometry(); + update(); +} + +QString ProgressBar::subtitle() const +{ + return m_subtitle; +} + void ProgressBar::setSeparatorVisible(bool visible) { if (m_separatorVisible == visible) @@ -176,9 +188,13 @@ QSize ProgressBar::sizeHint() const int width = 50; int height = PROGRESSBAR_HEIGHT + 5; if (m_titleVisible) { - QFontMetrics fm(titleFont()); + const QFontMetrics fm(titleFont()); width = qMax(width, fm.horizontalAdvance(m_title) + 16); height += fm.height() + 5; + if (!m_subtitle.isEmpty()) { + width = qMax(width, fm.horizontalAdvance(m_subtitle) + 16); + height += fm.height() + 5; + } } if (m_separatorVisible) height += SEPARATOR_HEIGHT; @@ -227,14 +243,13 @@ void ProgressBar::paintEvent(QPaintEvent *) percent = 1; QPainter p(this); - QFont fnt(titleFont()); - p.setFont(fnt); - QFontMetrics fm(fnt); + const QFont fnt(titleFont()); + const QFontMetrics fm(fnt); - int titleHeight = m_titleVisible ? fm.height() : 0; + const int titleHeight = m_titleVisible ? fm.height() + 5 : 4; // Draw separator - int separatorHeight = m_separatorVisible ? SEPARATOR_HEIGHT : 0; + const int separatorHeight = m_separatorVisible ? SEPARATOR_HEIGHT : 0; if (m_separatorVisible) { QRectF innerRect = QRectF(this->rect()).adjusted(0.5, 0.5, -0.5, -0.5); p.setPen(StyleHelper::sidebarShadow()); @@ -246,28 +261,37 @@ void ProgressBar::paintEvent(QPaintEvent *) } } - if (m_titleVisible) { - QRect textBounds = fm.boundingRect(m_title); - textBounds.moveCenter(rect().center()); - int alignment = Qt::AlignHCenter; + const int progressHeight = PROGRESSBAR_HEIGHT + ((PROGRESSBAR_HEIGHT % 2) + 1) % 2; // make odd + const int progressY = titleHeight + separatorHeight; - int textSpace = rect().width() - 8; + if (m_titleVisible) { + const int alignment = Qt::AlignHCenter; + const int textSpace = rect().width() - 8; // If there is not enough room when centered, we left align and // elide the text - QString elidedtitle = fm.elidedText(m_title, Qt::ElideRight, textSpace); + const QString elidedtitle = fm.elidedText(m_title, Qt::ElideRight, textSpace); QRect textRect = rect().adjusted(3, separatorHeight - 1, -3, 0); - textRect.setHeight(titleHeight + 4); + textRect.setHeight(fm.height() + 4); + p.setFont(fnt); p.setPen(creatorTheme()->color(Theme::ProgressBarTitleColor)); p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle); + + if (!m_subtitle.isEmpty()) { + const QString elidedsubtitle = fm.elidedText(m_subtitle, Qt::ElideRight, textSpace); + + QRect subtextRect = textRect; + subtextRect.moveTop(progressY + progressHeight); + + p.setFont(fnt); + p.setPen(creatorTheme()->color(Theme::ProgressBarTitleColor)); + p.drawText(subtextRect, alignment | Qt::AlignBottom, elidedsubtitle); + } } - m_progressHeight = PROGRESSBAR_HEIGHT; - m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd // draw outer rect - const QRect rect(INDENT - 1, titleHeight + separatorHeight + (m_titleVisible ? 5 : 4), - size().width() - 2 * INDENT + 1, m_progressHeight); + const QRect rect(INDENT - 1, progressY, size().width() - 2 * INDENT + 1, progressHeight); QRectF inner = rect.adjusted(2, 2, -2, -2); inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0); diff --git a/src/plugins/coreplugin/progressmanager/progressbar.h b/src/plugins/coreplugin/progressmanager/progressbar.h index 9ff599adbb..108181f54b 100644 --- a/src/plugins/coreplugin/progressmanager/progressbar.h +++ b/src/plugins/coreplugin/progressmanager/progressbar.h @@ -44,6 +44,8 @@ public: void setTitle(const QString &title); void setTitleVisible(bool visible); bool isTitleVisible() const; + void setSubtitle(const QString &subtitle); + QString subtitle() const; void setSeparatorVisible(bool visible); bool isSeparatorVisible() const; void setCancelEnabled(bool enabled); @@ -73,16 +75,17 @@ protected: private: QFont titleFont() const; + QFont subtitleFont() const; QString m_text; QString m_title; + QString m_subtitle; bool m_titleVisible = true; bool m_separatorVisible = true; bool m_cancelEnabled = true; bool m_finished = false; bool m_error = false; float m_cancelButtonFader = 0.0; - int m_progressHeight = 0; int m_minimum = 1; int m_maximum = 100; int m_value = 1; diff --git a/src/plugins/coreplugin/progressmanager/progressmanager.cpp b/src/plugins/coreplugin/progressmanager/progressmanager.cpp index 725721852f..318f84163c 100644 --- a/src/plugins/coreplugin/progressmanager/progressmanager.cpp +++ b/src/plugins/coreplugin/progressmanager/progressmanager.cpp @@ -457,6 +457,8 @@ FutureProgress *ProgressManagerPrivate::doAddTask(const QFuture<void> &future, c this, &ProgressManagerPrivate::updateSummaryProgressBar); connect(progress, &FutureProgress::statusBarWidgetChanged, this, &ProgressManagerPrivate::updateStatusDetailsWidget); + connect(progress, &FutureProgress::subtitleInStatusBarChanged, + this, &ProgressManagerPrivate::updateStatusDetailsWidget); updateStatusDetailsWidget(); emit taskStarted(type); @@ -657,9 +659,22 @@ void ProgressManagerPrivate::updateStatusDetailsWidget() QList<FutureProgress *>::iterator i = m_taskList.end(); while (i != m_taskList.begin()) { --i; - candidateWidget = (*i)->statusBarWidget(); + FutureProgress *progress = *i; + candidateWidget = progress->statusBarWidget(); if (candidateWidget) { - m_currentStatusDetailsProgress = *i; + m_currentStatusDetailsProgress = progress; + break; + } else if (progress->isSubtitleVisibleInStatusBar() && !progress->subtitle().isEmpty()) { + if (!m_statusDetailsLabel) { + m_statusDetailsLabel = new QLabel(m_summaryProgressWidget); + QFont font(m_statusDetailsLabel->font()); + font.setPointSizeF(StyleHelper::sidebarFontSize()); + font.setBold(true); + m_statusDetailsLabel->setFont(font); + } + m_statusDetailsLabel->setText(progress->subtitle()); + candidateWidget = m_statusDetailsLabel; + m_currentStatusDetailsProgress = progress; break; } } diff --git a/src/plugins/coreplugin/progressmanager/progressmanager_p.h b/src/plugins/coreplugin/progressmanager/progressmanager_p.h index 85bf378159..c3509c1ce4 100644 --- a/src/plugins/coreplugin/progressmanager/progressmanager_p.h +++ b/src/plugins/coreplugin/progressmanager/progressmanager_p.h @@ -31,6 +31,7 @@ #include <QList> #include <QGraphicsOpacityEffect> #include <QHBoxLayout> +#include <QLabel> #include <QPointer> #include <QPropertyAnimation> #include <QToolButton> @@ -103,6 +104,7 @@ private: QHBoxLayout *m_summaryProgressLayout; QWidget *m_currentStatusDetailsWidget = nullptr; QPointer<FutureProgress> m_currentStatusDetailsProgress; + QLabel *m_statusDetailsLabel = nullptr; ProgressBar *m_summaryProgressBar; QGraphicsOpacityEffect *m_opacityEffect; QPointer<QPropertyAnimation> m_opacityAnimation; |