forked from qt-creator/qt-creator
Fix text eliding on progress bars
We need this for translations. I also added the label to the tool tip.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -73,6 +73,7 @@ protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
|
||||
private slots:
|
||||
void updateToolTip(const QString &);
|
||||
void cancel();
|
||||
void setStarted();
|
||||
void setFinished();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user