]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinstatusbar.cpp
Added Rafael López's item categorizer into Dolphin (it's currently deactivated in...
[dolphin.git] / src / dolphinstatusbar.cpp
index a112a1f64625f37f33aec525b002834f2fc1702b..1f6859a8f52040b7fdc705a9824c73bec9994155 100644 (file)
 #include <kvbox.h>
 
 DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
-    KHBox(parent),
-    m_messageLabel(0),
-    m_spaceInfo(0),
-    m_progressBar(0),
-    m_progress(100)
+        KHBox(parent),
+        m_messageLabel(0),
+        m_spaceInfo(0),
+        m_progressBar(0),
+        m_progress(100)
 {
     setSpacing(4);
 
@@ -52,35 +52,32 @@ DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
     m_progressBar->hide();
 
     const QSize size(m_progressBar->sizeHint());
+    const int barHeight = size.height();
+
     m_progressBar->setMaximumWidth(200);
-    setMinimumHeight(size.height());
-    m_messageLabel->setMinimumTextHeight(size.height());
+    setMinimumHeight(barHeight);
+    m_messageLabel->setMinimumTextHeight(barHeight);
+    m_spaceInfo->setFixedHeight(barHeight);
 
     connect(parent, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(updateSpaceInfo(const KUrl&)));
+            this, SLOT(updateSpaceInfoContent(const KUrl&)));
 }
 
 
 DolphinStatusBar::~DolphinStatusBar()
-{
-}
+{}
 
 void DolphinStatusBar::setMessage(const QString& msg,
                                   Type type)
 {
-    m_messageLabel->setText(msg);
-    m_messageLabel->setType(type);
+    m_messageLabel->setMessage(msg, type);
 
-    if (type == Error) {
-        // assure that enough space is available for the error message and
-        // hide the space information and progress information
-        m_spaceInfo->hide();
+    const int widthGap = m_messageLabel->widthGap();
+    if (widthGap > 0) {
         m_progressBar->hide();
         m_progressText->hide();
     }
-    else if (!m_progressBar->isVisible()) {
-        m_spaceInfo->show();
-    }
+    showSpaceInfo();
 }
 
 DolphinStatusBar::Type DolphinStatusBar::type() const
@@ -107,8 +104,7 @@ void DolphinStatusBar::setProgress(int percent)
 {
     if (percent < 0) {
         percent = 0;
-    }
-    else if (percent > 100) {
+    } else if (percent > 100) {
         percent = 100;
     }
 
@@ -124,25 +120,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()));
 }
 
 void DolphinStatusBar::updateProgressInfo()
@@ -155,20 +160,36 @@ 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();
-        if (m_messageLabel->type() != Error) {
-            m_spaceInfo->show();
-        }
+        showSpaceInfo();
     }
 }
 
-void DolphinStatusBar::updateSpaceInfo(const KUrl& url)
+void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url)
 {
     m_spaceInfo->setUrl(url);
+    showSpaceInfo();
+}
+
+void DolphinStatusBar::showSpaceInfo()
+{
+    const int widthGap = m_messageLabel->widthGap();
+    const bool isProgressBarVisible = m_progressBar->isVisible();
+
+    if (m_spaceInfo->isVisible()) {
+        // 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) {
+        m_spaceInfo->show();
+    }
 }
 
 #include "dolphinstatusbar.moc"