Minor statusbar fixes

- Don't show information messages as KMessageWidget
- Assure that a set text in a statusbar will be shown for at least
  one second
This commit is contained in:
Peter Penz 2012-04-15 11:44:56 +02:00
parent 60b8681081
commit 1ea09b24e1
4 changed files with 64 additions and 24 deletions

View file

@ -111,8 +111,6 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
connect(m_view, SIGNAL(selectionChanged(KFileItemList)), this, SLOT(delayedStatusBarUpdate()));
connect(m_view, SIGNAL(urlAboutToBeChanged(KUrl)), this, SLOT(slotViewUrlAboutToBeChanged(KUrl)));
connect(m_view, SIGNAL(errorMessage(QString)), this, SLOT(showErrorMessage(QString)));
connect(m_view, SIGNAL(infoMessage(QString)), this, SLOT(showInfoMessage(QString)));
connect(m_view, SIGNAL(operationCompletedMessage(QString)), m_statusBar, SLOT(setText(QString)));
connect(m_urlNavigator, SIGNAL(urlAboutToBeChanged(KUrl)),
this, SLOT(slotUrlNavigatorLocationAboutToBeChanged(KUrl)));
@ -125,10 +123,12 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
m_statusBar = new DolphinStatusBar(this);
m_statusBar->setUrl(m_view->url());
m_statusBar->setZoomLevel(m_view->zoomLevel());
connect(m_view, SIGNAL(urlChanged(KUrl)), m_statusBar, SLOT(setUrl(KUrl)));
connect(m_view, SIGNAL(zoomLevelChanged(int,int)), m_statusBar, SLOT(setZoomLevel(int)));
connect(m_statusBar, SIGNAL(stopPressed()), this, SLOT(stopDirectoryLoading()));
connect(m_statusBar, SIGNAL(zoomLevelChanged(int)), this, SLOT(slotStatusBarZoomLevelChanged(int)));
connect(m_view, SIGNAL(urlChanged(KUrl)), m_statusBar, SLOT(setUrl(KUrl)));
connect(m_view, SIGNAL(zoomLevelChanged(int,int)), m_statusBar, SLOT(setZoomLevel(int)));
connect(m_view, SIGNAL(infoMessage(QString)), m_statusBar, SLOT(setText(QString)));
connect(m_view, SIGNAL(operationCompletedMessage(QString)), m_statusBar, SLOT(setText(QString)));
connect(m_statusBar, SIGNAL(stopPressed()), this, SLOT(stopDirectoryLoading()));
connect(m_statusBar, SIGNAL(zoomLevelChanged(int)), this, SLOT(slotStatusBarZoomLevelChanged(int)));
m_statusBarTimer = new QTimer(this);
m_statusBarTimer->setSingleShot(true);
@ -617,11 +617,6 @@ void DolphinViewContainer::showErrorMessage(const QString& msg)
showMessage(msg, Error);
}
void DolphinViewContainer::showInfoMessage(const QString& msg)
{
showMessage(msg, Information);
}
bool DolphinViewContainer::isSearchUrl(const KUrl& url) const
{
const QString protocol = url.protocol();

View file

@ -273,11 +273,6 @@ private slots:
*/
void showErrorMessage(const QString& msg);
/**
* Slot that calls showMessage(msg, Information).
*/
void showInfoMessage(const QString& msg);
private:
/**
* @return True if the URL protocol is a search URL (e. g. nepomuksearch:// or filenamesearch://).

View file

@ -41,6 +41,10 @@
#include <views/dolphinview.h>
#include <views/zoomlevelinfo.h>
namespace {
const int ResetToDefaultTimeout = 1000;
}
DolphinStatusBar::DolphinStatusBar(QWidget* parent) :
QWidget(parent),
m_text(),
@ -51,7 +55,9 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent) :
m_progressBar(0),
m_stopButton(0),
m_progress(100),
m_showProgressBarTimer(0)
m_showProgressBarTimer(0),
m_resetToDefaultTextTimer(0),
m_textTimestamp()
{
// Initialize text label
m_label = new QLabel(this);
@ -90,6 +96,11 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent) :
m_showProgressBarTimer->setSingleShot(true);
connect(m_showProgressBarTimer, SIGNAL(timeout()), this, SLOT(updateProgressInfo()));
m_resetToDefaultTextTimer = new QTimer(this);
m_resetToDefaultTextTimer->setInterval(ResetToDefaultTimeout);
m_resetToDefaultTextTimer->setSingleShot(true);
connect(m_resetToDefaultTextTimer, SIGNAL(timeout()), this, SLOT(slotResetToDefaultText()));
// Initialize top layout and size policies
const int fontHeight = QFontMetrics(m_label->font()).height();
const int zoomSliderHeight = m_zoomSlider->minimumSizeHint().height();
@ -123,8 +134,23 @@ DolphinStatusBar::~DolphinStatusBar()
void DolphinStatusBar::setText(const QString& text)
{
if (m_text != text) {
if (m_text == text) {
return;
}
m_textTimestamp = QTime::currentTime();
if (text.isEmpty()) {
// Assure that the previous set text won't get
// cleared immediatelly.
m_resetToDefaultTextTimer->start();
} else {
m_text = text;
if (m_resetToDefaultTextTimer->isActive()) {
m_resetToDefaultTextTimer->start();
}
updateLabelText();
}
}
@ -174,8 +200,13 @@ int DolphinStatusBar::progress() const
void DolphinStatusBar::resetToDefaultText()
{
m_text.clear();
updateLabelText();
QTime currentTime;
if (currentTime.msecsTo(m_textTimestamp) < ResetToDefaultTimeout) {
m_resetToDefaultTextTimer->start();
} else {
m_resetToDefaultTextTimer->stop();
slotResetToDefaultText();
}
}
void DolphinStatusBar::setDefaultText(const QString& text)
@ -290,6 +321,12 @@ void DolphinStatusBar::updateLabelText()
m_label->setToolTip(text == elidedText ? QString() : text);
}
void DolphinStatusBar::slotResetToDefaultText()
{
m_text.clear();
updateLabelText();
}
void DolphinStatusBar::setExtensionsVisible(bool visible)
{
bool showSpaceInfo = visible;

View file

@ -20,6 +20,7 @@
#ifndef DOLPHINSTATUSBAR_H
#define DOLPHINSTATUSBAR_H
#include <QTime>
#include <QWidget>
class KUrl;
@ -56,8 +57,8 @@ public:
/**
* Sets the progress in percent (0 - 100). The
* progress is shown delayed by 1 second:
* If the progress does reach 100 % within 1 second,
* progress is shown delayed by 500 milliseconds:
* If the progress does reach 100 % within 500 milliseconds,
* the progress is not shown at all.
*/
void setProgress(int percent);
@ -65,8 +66,9 @@ public:
/**
* Replaces the text set by setText() by the text that
* has been set by setDefaultText(). DolphinStatusBar::text()
* will return an empty string afterwards.
* has been set by setDefaultText(). It is assured that the previous
* text will be shown for at least 1 second. DolphinStatusBar::text()
* will return an empty string after the reset has been done.
*/
void resetToDefaultText();
@ -112,6 +114,14 @@ private slots:
*/
void updateLabelText();
/**
* Is invoked by m_resetToDefaultTextTimer and clears
* m_text so that the default text will be shown. This
* prevents that information-messages will be cleared
* too fast.
*/
void slotResetToDefaultText();
private:
/**
* Makes the space information widget and zoom slider widget
@ -142,6 +152,9 @@ private:
QToolButton* m_stopButton;
int m_progress;
QTimer* m_showProgressBarTimer;
QTimer* m_resetToDefaultTextTimer;
QTime m_textTimestamp;
};
#endif