1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00

Further optimizations for the status bar: hide the space information if the status bar text does not fit into the remaining width.

svn path=/trunk/playground/utils/dolphin/; revision=627486
This commit is contained in:
Peter Penz 2007-01-26 19:38:32 +00:00
parent dcc41b4ad4
commit 9877bef7c5
6 changed files with 83 additions and 32 deletions

View File

@ -57,7 +57,7 @@ DolphinStatusBar::DolphinStatusBar(DolphinView* parent) :
m_messageLabel->setMinimumTextHeight(size.height());
connect(parent, SIGNAL(urlChanged(const KUrl&)),
this, SLOT(updateSpaceInfo(const KUrl&)));
this, SLOT(updateSpaceInfoContent(const KUrl&)));
}
@ -71,16 +71,12 @@ void DolphinStatusBar::setMessage(const QString& msg,
m_messageLabel->setText(msg);
m_messageLabel->setType(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
@ -145,6 +141,12 @@ void DolphinStatusBar::setDefaultText(const QString& text)
m_defaultText = text;
}
void DolphinStatusBar::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
QTimer::singleShot(0, this, SLOT(showSpaceInfo()));
}
void DolphinStatusBar::updateProgressInfo()
{
const bool isErrorShown = (m_messageLabel->type() == Error);
@ -160,15 +162,33 @@ void DolphinStatusBar::updateProgressInfo()
// 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"

View File

@ -110,15 +110,26 @@ public:
void setDefaultText(const QString& text);
const QString& defaultText() const { return m_defaultText; }
protected:
/** @see QWidget::resizeEvent() */
virtual void resizeEvent(QResizeEvent* event);
private slots:
void updateProgressInfo();
/**
* Is invoked, when the URL of the DolphinView, where the
* statusbar belongs too, has been changed. The space information
* is updated.
* content is updated.
*/
void updateSpaceInfo(const KUrl& url);
void updateSpaceInfoContent(const KUrl& url);
/**
* Shows the space information if there is enough room to show it
* without the need to clip the status bar text. If the progress
* bar is shown, the space information won't be shown.
*/
void showSpaceInfo();
private:
StatusBarMessageLabel* m_messageLabel;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "statusbarmessagelabel.h"
@ -106,6 +106,13 @@ void StatusBarMessageLabel::setMinimumTextHeight(int min)
}
}
int StatusBarMessageLabel::widthGap() const
{
QFontMetrics fontMetrics(font());
const int defaultGap = 10;
return fontMetrics.width(m_text) - availableTextWidth() + defaultGap;
}
void StatusBarMessageLabel::paintEvent(QPaintEvent* /* event */)
{
QPainter painter(this);
@ -189,13 +196,10 @@ void StatusBarMessageLabel::assureVisibleText()
return;
}
int availableWidth = width() - m_pixmap.width() - pixmapGap() * 2;
QFontMetrics fontMetrics(font());
QRect bounds(fontMetrics.boundingRect(0, 0, availableWidth, height(),
Qt::AlignVCenter | Qt::TextWordWrap,
m_text));
const QRect bounds(fontMetrics.boundingRect(0, 0, availableTextWidth(), height(),
Qt::AlignVCenter | Qt::TextWordWrap,
m_text));
int requiredHeight = bounds.height();
if (requiredHeight < m_minTextHeight) {
requiredHeight = m_minTextHeight;
@ -204,6 +208,11 @@ void StatusBarMessageLabel::assureVisibleText()
updateGeometry();
}
int StatusBarMessageLabel::availableTextWidth() const
{
return width() - m_pixmap.width() - pixmapGap() * 2;
}
QColor StatusBarMessageLabel::mixColors(const QColor& c1,
const QColor& c2,
int percent) const

View File

@ -37,8 +37,6 @@ class QTimer;
* is shown in front of the text. For message texts having the type
* DolphinStatusBar::Error a dynamic color blending is done to get the
* attention from the user.
*
* @author Peter Penz
*/
class StatusBarMessageLabel : public QWidget
{
@ -58,17 +56,34 @@ public:
void setMinimumTextHeight(int min);
int minimumTextHeight() const { return m_minTextHeight; }
/**
* Returns the gap of the width of the current set text to the
* width of the message label. A gap <= 0 means that the text
* fits into the available width.
*/
int widthGap() const;
protected:
/** @see QWidget::paintEvent */
/** @see QWidget::paintEvent() */
virtual void paintEvent(QPaintEvent* event);
/** @see QWidget::resizeEvent */
/** @see QWidget::resizeEvent() */
virtual void resizeEvent(QResizeEvent* event);
private slots:
void timerDone();
/**
* Increases the height of the message label so that
* the given text fits into given area.
*/
void assureVisibleText();
/**
* Returns the available width in pixels for the text.
*/
int availableTextWidth() const;
private:
enum State {
Default,

View File

@ -132,13 +132,9 @@ void StatusBarSpaceInfo::slotFoundMountPoint(const unsigned long& kBSize,
update();
}
void StatusBarSpaceInfo::slotDone()
void StatusBarSpaceInfo::showResult()
{
m_gettingSize = false;
if ((m_kBSize > 0) && (m_kBAvailable > 0)) {
show();
}
update();
}
@ -160,7 +156,7 @@ void StatusBarSpaceInfo::refresh()
const unsigned long&,
const QString& )));
connect(job, SIGNAL(done()),
this, SLOT(slotDone()));
this, SLOT(showResult()));
job->readDF(mountPoint);
}

View File

@ -58,7 +58,7 @@ private slots:
const unsigned long& kBUsed,
const unsigned long& kBAvailable,
const QString& mountPoint);
void slotDone();
void showResult();
/** Refreshs the space information for the current set Url. */
void refresh();