Skip to content
Snippets Groups Projects
Commit c5df0a1d authored by Jens Bache-Wiig's avatar Jens Bache-Wiig
Browse files

Fix text eliding on progress bars

We need this for translations.
I also added the label to the tool tip.
parent 3999651f
No related branches found
No related tags found
No related merge requests found
...@@ -149,42 +149,33 @@ void FutureProgress::cancel() ...@@ -149,42 +149,33 @@ void FutureProgress::cancel()
m_watcher.future().cancel(); m_watcher.future().cancel();
} }
void FutureProgress::updateToolTip(const QString &text)
{
setToolTip("<b>" + title() + "</b><br>" + text);
}
void FutureProgress::setStarted() void FutureProgress::setStarted()
{ {
m_progress->reset(); m_progress->reset();
m_progress->setError(false); m_progress->setError(false);
m_progress->setRange(m_watcher.progressMinimum(), m_watcher.progressMaximum()); m_progress->setRange(m_watcher.progressMinimum(), m_watcher.progressMaximum());
m_progress->setValue(m_watcher.progressValue()); m_progress->setValue(m_watcher.progressValue());
// if (m_watcher.progressMinimum() == 0 && m_watcher.progressMaximum() == 0)
// m_progress->startAnimation();
} }
void FutureProgress::setFinished() void FutureProgress::setFinished()
{ {
// m_progress->stopAnimation(); updateToolTip(m_watcher.future().progressText());
setToolTip(m_watcher.future().progressText());
if (m_watcher.future().isCanceled()) { if (m_watcher.future().isCanceled()) {
m_progress->setError(true); m_progress->setError(true);
// m_progress->execGlowOut(true);
} else { } else {
m_progress->setError(false); m_progress->setError(false);
// m_progress->execGlowOut(false);
} }
// m_progress->showToolTip();
emit finished(); emit finished();
} }
void FutureProgress::setProgressRange(int min, int max) void FutureProgress::setProgressRange(int min, int max)
{ {
m_progress->setRange(min, max); m_progress->setRange(min, max);
if (min != 0 || max != 0) {
// m_progress->setUsingAnimation(false);
} else {
// m_progress->setUsingAnimation(true);
if (m_watcher.future().isRunning()) {
//m_progress->startAnimation();
}
}
} }
void FutureProgress::setProgressValue(int val) void FutureProgress::setProgressValue(int val)
...@@ -194,7 +185,7 @@ void FutureProgress::setProgressValue(int val) ...@@ -194,7 +185,7 @@ void FutureProgress::setProgressValue(int val)
void FutureProgress::setProgressText(const QString &text) void FutureProgress::setProgressText(const QString &text)
{ {
setToolTip(text); updateToolTip(text);
} }
/*! /*!
......
...@@ -73,6 +73,7 @@ protected: ...@@ -73,6 +73,7 @@ protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
private slots: private slots:
void updateToolTip(const QString &);
void cancel(); void cancel();
void setStarted(); void setStarted();
void setFinished(); void setFinished();
......
...@@ -161,18 +161,24 @@ void ProgressBar::paintEvent(QPaintEvent *) ...@@ -161,18 +161,24 @@ void ProgressBar::paintEvent(QPaintEvent *)
textBounds.moveCenter(rect().center()); textBounds.moveCenter(rect().center());
int alignment = Qt::AlignHCenter; int alignment = Qt::AlignHCenter;
// If there is not enough room when centered, we left align the text
if (value() < maximum() && !m_error && textBounds.right() > rect().right() - CANCEL_WIDTH) int textSpace = rect().width() - CANCEL_WIDTH - 8;
// If there is not enough room when centered, we left align and
// elide the text
QString elidedtitle = m_title;
if (value() < maximum() && !m_error && textBounds.right() > textSpace) {
alignment = Qt::AlignLeft; alignment = Qt::AlignLeft;
elidedtitle = fm.elidedText(m_title, Qt::ElideRight, textSpace);
}
QRect textRect = rect().adjusted(INDENT + 1, 1, -INDENT - 1, 0); QRect textRect = rect().adjusted(INDENT + 1, 1, -INDENT - 1, 0);
textRect.setHeight(h+5); textRect.setHeight(h+5);
p.setPen(QColor(0, 0, 0, 120)); p.setPen(QColor(0, 0, 0, 120));
p.drawText(textRect, alignment | Qt::AlignBottom, m_title); p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
p.translate(0, -1); p.translate(0, -1);
p.setPen(Utils::StyleHelper::panelTextColor()); p.setPen(Utils::StyleHelper::panelTextColor());
p.drawText(textRect, alignment | Qt::AlignBottom, m_title); p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle);
p.translate(0, 1); p.translate(0, 1);
m_progressHeight = PROGRESSBAR_HEIGHT; m_progressHeight = PROGRESSBAR_HEIGHT;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment