From c5df0a1d0dadd792b939c8defaf67ad9ef6cb131 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig <jbache@trolltech.com> Date: Tue, 9 Mar 2010 19:31:06 +0100 Subject: [PATCH] Fix text eliding on progress bars We need this for translations. I also added the label to the tool tip. --- .../progressmanager/futureprogress.cpp | 23 ++++++------------- .../progressmanager/futureprogress.h | 1 + .../progressmanager/progressbar.cpp | 14 +++++++---- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/plugins/coreplugin/progressmanager/futureprogress.cpp b/src/plugins/coreplugin/progressmanager/futureprogress.cpp index e74c7e25d10..69b17c103b7 100644 --- a/src/plugins/coreplugin/progressmanager/futureprogress.cpp +++ b/src/plugins/coreplugin/progressmanager/futureprogress.cpp @@ -149,42 +149,33 @@ void FutureProgress::cancel() m_watcher.future().cancel(); } +void FutureProgress::updateToolTip(const QString &text) +{ + setToolTip("<b>" + title() + "</b><br>" + text); +} + void FutureProgress::setStarted() { m_progress->reset(); m_progress->setError(false); m_progress->setRange(m_watcher.progressMinimum(), m_watcher.progressMaximum()); m_progress->setValue(m_watcher.progressValue()); -// if (m_watcher.progressMinimum() == 0 && m_watcher.progressMaximum() == 0) -// m_progress->startAnimation(); } void FutureProgress::setFinished() { -// m_progress->stopAnimation(); - setToolTip(m_watcher.future().progressText()); + updateToolTip(m_watcher.future().progressText()); if (m_watcher.future().isCanceled()) { m_progress->setError(true); -// m_progress->execGlowOut(true); } else { m_progress->setError(false); -// m_progress->execGlowOut(false); } -// m_progress->showToolTip(); emit finished(); } void FutureProgress::setProgressRange(int min, int 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) @@ -194,7 +185,7 @@ void FutureProgress::setProgressValue(int val) void FutureProgress::setProgressText(const QString &text) { - setToolTip(text); + updateToolTip(text); } /*! diff --git a/src/plugins/coreplugin/progressmanager/futureprogress.h b/src/plugins/coreplugin/progressmanager/futureprogress.h index 75dbb6f1b77..5d2e936757f 100644 --- a/src/plugins/coreplugin/progressmanager/futureprogress.h +++ b/src/plugins/coreplugin/progressmanager/futureprogress.h @@ -73,6 +73,7 @@ protected: void mousePressEvent(QMouseEvent *event); private slots: + void updateToolTip(const QString &); void cancel(); void setStarted(); void setFinished(); diff --git a/src/plugins/coreplugin/progressmanager/progressbar.cpp b/src/plugins/coreplugin/progressmanager/progressbar.cpp index c272c5f47e9..dd4787d6fa7 100644 --- a/src/plugins/coreplugin/progressmanager/progressbar.cpp +++ b/src/plugins/coreplugin/progressmanager/progressbar.cpp @@ -161,18 +161,24 @@ void ProgressBar::paintEvent(QPaintEvent *) textBounds.moveCenter(rect().center()); 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; + elidedtitle = fm.elidedText(m_title, Qt::ElideRight, textSpace); + } QRect textRect = rect().adjusted(INDENT + 1, 1, -INDENT - 1, 0); textRect.setHeight(h+5); 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.setPen(Utils::StyleHelper::panelTextColor()); - p.drawText(textRect, alignment | Qt::AlignBottom, m_title); + p.drawText(textRect, alignment | Qt::AlignBottom, elidedtitle); p.translate(0, 1); m_progressHeight = PROGRESSBAR_HEIGHT; -- GitLab