X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/9877bef7c56b07e715d1f7a6dddc8529387b689b..d6488887ecf69d7f192b94de8dce34fae0b7eb76:/src/dolphinstatusbar.cpp diff --git a/src/dolphinstatusbar.cpp b/src/dolphinstatusbar.cpp index c81a01c70..df67ac28f 100644 --- a/src/dolphinstatusbar.cpp +++ b/src/dolphinstatusbar.cpp @@ -23,14 +23,14 @@ #include "statusbarmessagelabel.h" #include "statusbarspaceinfo.h" -#include -#include -#include +#include +#include +#include #include #include -DolphinStatusBar::DolphinStatusBar(DolphinView* parent) : +DolphinStatusBar::DolphinStatusBar(QWidget* parent, const KUrl& url) : KHBox(parent), m_messageLabel(0), m_spaceInfo(0), @@ -43,7 +43,7 @@ DolphinStatusBar::DolphinStatusBar(DolphinView* parent) : m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_spaceInfo = new StatusBarSpaceInfo(this); - m_spaceInfo->setUrl(parent->url()); + m_spaceInfo->setUrl(url); m_progressText = new QLabel(this); m_progressText->hide(); @@ -51,13 +51,14 @@ DolphinStatusBar::DolphinStatusBar(DolphinView* parent) : m_progressBar = new QProgressBar(this); m_progressBar->hide(); - const QSize size(m_progressBar->sizeHint()); - m_progressBar->setMaximumWidth(200); - setMinimumHeight(size.height()); - m_messageLabel->setMinimumTextHeight(size.height()); + const int contentHeight = QFontMetrics(m_messageLabel->font()).height(); + const int barHeight = contentHeight + 8; - connect(parent, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(updateSpaceInfoContent(const KUrl&))); + setMinimumHeight(barHeight); + m_messageLabel->setMinimumTextHeight(barHeight); + m_spaceInfo->setFixedHeight(contentHeight); + m_progressBar->setFixedHeight(contentHeight); + m_progressBar->setMaximumWidth(200); } @@ -68,8 +69,7 @@ DolphinStatusBar::~DolphinStatusBar() void DolphinStatusBar::setMessage(const QString& msg, Type type) { - m_messageLabel->setText(msg); - m_messageLabel->setType(type); + m_messageLabel->setMessage(msg, type); const int widthGap = m_messageLabel->widthGap(); if (widthGap > 0) { @@ -103,8 +103,7 @@ void DolphinStatusBar::setProgress(int percent) { if (percent < 0) { percent = 0; - } - else if (percent > 100) { + } else if (percent > 100) { percent = 100; } @@ -120,31 +119,34 @@ void DolphinStatusBar::setProgress(int percent) QTimer::singleShot(500, this, SLOT(updateProgressInfo())); } + const QString& defaultText = m_messageLabel->defaultText(); const QString msg(m_messageLabel->text()); if ((percent == 0) && !msg.isEmpty()) { - setMessage(QString::null, Default); - } - else if ((percent == 100) && (msg != m_defaultText)) { - setMessage(m_defaultText, Default); + setMessage(QString(), Default); + } else if ((percent == 100) && (msg != defaultText)) { + setMessage(defaultText, Default); } } void DolphinStatusBar::clear() { - // TODO: check for timeout, so that it's prevented that - // a message is cleared too early. - setMessage(m_defaultText, Default); + setMessage(m_messageLabel->defaultText(), Default); } void DolphinStatusBar::setDefaultText(const QString& text) { - m_defaultText = text; + m_messageLabel->setDefaultText(text); +} + +const QString& DolphinStatusBar::defaultText() const +{ + return m_messageLabel->defaultText(); } void DolphinStatusBar::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); - QTimer::singleShot(0, this, SLOT(showSpaceInfo())); + QMetaObject::invokeMethod(this, "showSpaceInfo", Qt::QueuedConnection); } void DolphinStatusBar::updateProgressInfo() @@ -157,8 +159,7 @@ void DolphinStatusBar::updateProgressInfo() m_progressText->show(); m_progressBar->show(); } - } - else { + } else { // hide the progress information and show the space information m_progressText->hide(); m_progressBar->hide(); @@ -181,12 +182,10 @@ void DolphinStatusBar::showSpaceInfo() // The space information is shown currently. Hide it // if the progress bar is visible or if the status bar // text does not fit into the available width. - const QSize size(m_progressBar->sizeHint()); if (isProgressBarVisible || (widthGap > 0)) { m_spaceInfo->hide(); } - } - else if (widthGap + m_spaceInfo->width() <= 0) { + } else if (widthGap + m_spaceInfo->width() <= 0) { m_spaceInfo->show(); } }