forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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();
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user