diff --git a/dolphin/src/dolphinstatusbar.cpp b/dolphin/src/dolphinstatusbar.cpp index 84e18d3b6..eabbc77b1 100644 --- a/dolphin/src/dolphinstatusbar.cpp +++ b/dolphin/src/dolphinstatusbar.cpp @@ -1,258 +1,244 @@ /*************************************************************************** * Copyright (C) 2006 by Peter Penz * * peter.penz@gmx.at * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * 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 * ***************************************************************************/ #include "dolphinstatusbar.h" #include "dolphinsettings.h" #include "dolphinview.h" #include "dolphin_generalsettings.h" #include "statusbarmessagelabel.h" #include "statusbarspaceinfo.h" #include "zoomlevelinfo.h" #include #include #include #include #include DolphinStatusBar::DolphinStatusBar(QWidget* parent, DolphinView* view) : KHBox(parent), m_view(view), m_messageLabel(0), m_spaceInfo(0), m_zoomSlider(0), - m_zoomTimer(0), m_progressBar(0), - m_progress(100), - m_requestedZoomLevel(0) + m_progress(100) { setSpacing(4); connect(m_view, SIGNAL(urlChanged(const KUrl&)), this, SLOT(updateSpaceInfoContent(const KUrl&))); // initialize message label m_messageLabel = new StatusBarMessageLabel(this); m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // initialize space information m_spaceInfo = new StatusBarSpaceInfo(this); m_spaceInfo->setUrl(m_view->url()); // initialize zoom slider m_zoomSlider = new QSlider(Qt::Horizontal, this); m_zoomSlider->setPageStep(1); const int min = ZoomLevelInfo::minimumLevel(); const int max = ZoomLevelInfo::maximumLevel(); m_zoomSlider->setRange(min, max); m_zoomSlider->setValue(view->zoomLevel()); connect(m_zoomSlider, SIGNAL(sliderMoved(int)), - this, SLOT(requestZoomLevel(int))); + this, SLOT(setZoomLevel(int))); connect(m_view, SIGNAL(zoomLevelChanged(int)), m_zoomSlider, SLOT(setValue(int))); - m_zoomTimer = new QTimer(this); - m_zoomTimer->setSingleShot(true); - m_zoomTimer->setInterval(50); - connect(m_zoomTimer, SIGNAL(timeout()), - this, SLOT(updateZoomLevel())); - // initialize progress informatino m_progressText = new QLabel(this); m_progressText->hide(); m_progressBar = new QProgressBar(this); m_progressBar->hide(); // initialize sizes const int contentHeight = QFontMetrics(m_messageLabel->font()).height() + 4; const int barHeight = contentHeight + 4; setMinimumHeight(barHeight); m_messageLabel->setMinimumTextHeight(barHeight); m_spaceInfo->setFixedHeight(contentHeight); m_progressBar->setFixedHeight(contentHeight); m_progressBar->setMaximumWidth(200); m_zoomSlider->setMaximumWidth(100); setExtensionsVisible(true); } DolphinStatusBar::~DolphinStatusBar() { } void DolphinStatusBar::setMessage(const QString& msg, Type type) { m_messageLabel->setMessage(msg, type); const int widthGap = m_messageLabel->widthGap(); if (widthGap > 0) { m_progressBar->hide(); m_progressText->hide(); } assureVisibleText(); } DolphinStatusBar::Type DolphinStatusBar::type() const { return m_messageLabel->type(); } QString DolphinStatusBar::message() const { return m_messageLabel->text(); } void DolphinStatusBar::setProgressText(const QString& text) { m_progressText->setText(text); } QString DolphinStatusBar::progressText() const { return m_progressText->text(); } void DolphinStatusBar::setProgress(int percent) { if (percent < 0) { percent = 0; } else if (percent > 100) { percent = 100; } m_progress = percent; if (m_messageLabel->type() == Error) { // don't update any widget or status bar text if an // error message is shown return; } m_progressBar->setValue(m_progress); if (!m_progressBar->isVisible() || (percent == 100)) { QTimer::singleShot(300, this, SLOT(updateProgressInfo())); } const QString& defaultText = m_messageLabel->defaultText(); const QString msg(m_messageLabel->text()); if ((percent == 0) && !msg.isEmpty()) { setMessage(QString(), Default); } else if ((percent == 100) && (msg != defaultText)) { setMessage(defaultText, Default); } } void DolphinStatusBar::clear() { setMessage(m_messageLabel->defaultText(), Default); } void DolphinStatusBar::setDefaultText(const QString& text) { m_messageLabel->setDefaultText(text); } const QString& DolphinStatusBar::defaultText() const { return m_messageLabel->defaultText(); } void DolphinStatusBar::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); QMetaObject::invokeMethod(this, "assureVisibleText", Qt::QueuedConnection); } void DolphinStatusBar::updateProgressInfo() { const bool isErrorShown = (m_messageLabel->type() == Error); if (m_progress < 100) { // show the progress information and hide the extensions setExtensionsVisible(false); if (!isErrorShown) { m_progressText->show(); m_progressBar->show(); } } else { // hide the progress information and show the extensions m_progressText->hide(); m_progressBar->hide(); assureVisibleText(); } } void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url) { m_spaceInfo->setUrl(url); assureVisibleText(); } -void DolphinStatusBar::requestZoomLevel(int zoomLevel) -{ - m_requestedZoomLevel = zoomLevel; - m_zoomTimer->start(); -} - -void DolphinStatusBar::updateZoomLevel() +void DolphinStatusBar::setZoomLevel(int zoomLevel) { - m_view->setZoomLevel(m_requestedZoomLevel); + m_view->setZoomLevel(zoomLevel); } void DolphinStatusBar::assureVisibleText() { const int widthGap = m_messageLabel->widthGap(); const bool isProgressBarVisible = m_progressBar->isVisible(); const int spaceInfoWidth = m_spaceInfo->isVisible() ? m_spaceInfo->width() : 0; const int zoomSliderWidth = m_zoomSlider->isVisible() ? m_zoomSlider->width() : 0; const int widgetsWidth = spaceInfoWidth + zoomSliderWidth; if (widgetsWidth > 0) { // The space information and (or) the zoom slider are (is) shown. // Hide them if the status bar text does not fit into the available width. if (widthGap > 0) { setExtensionsVisible(false); } } else if (!isProgressBarVisible && (widthGap + widgetsWidth <= 0)) { setExtensionsVisible(true); } } void DolphinStatusBar::setExtensionsVisible(bool visible) { bool spaceInfoVisible = visible; bool zoomSliderVisible = visible; if (visible) { const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); spaceInfoVisible = settings->showSpaceInfo(); zoomSliderVisible = settings->showZoomSlider(); } m_spaceInfo->setVisible(spaceInfoVisible); m_zoomSlider->setVisible(zoomSliderVisible); } #include "dolphinstatusbar.moc" diff --git a/dolphin/src/dolphinstatusbar.h b/dolphin/src/dolphinstatusbar.h index 49f14357d..3cee1ed53 100644 --- a/dolphin/src/dolphinstatusbar.h +++ b/dolphin/src/dolphinstatusbar.h @@ -1,178 +1,165 @@ /*************************************************************************** * Copyright (C) 2006 by Peter Penz * * peter.penz@gmx.at * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * 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 * ***************************************************************************/ #ifndef DOLPHINSTATUSBAR_H #define DOLPHINSTATUSBAR_H #include class DolphinView; class KUrl; class StatusBarMessageLabel; class StatusBarSpaceInfo; class QLabel; class QProgressBar; class QSlider; class QTimer; /** * @brief Represents the statusbar of a Dolphin view. * * The statusbar allows to show messages and progress * information. */ class DolphinStatusBar : public KHBox { Q_OBJECT public: /** * Describes the type of the message text. Dependent * from the type a corresponding icon and color is * used for the message text. */ enum Type { Default, OperationCompleted, Information, Error }; DolphinStatusBar(QWidget* parent, DolphinView* view); virtual ~DolphinStatusBar(); /** * Sets the message text to \a msg. Dependant * from the given type \a type an icon is shown and * the color of the text is adjusted. The height of * the statusbar is automatically adjusted in a way, * that the full text fits into the available width. * * If a progress is ongoing and a message * with the type Type::Error is set, the progress * is cleared automatically. */ void setMessage(const QString& msg, Type type); QString message() const; Type type() const; /** * Sets the text for the progress information. * The text is shown with a delay of 300 milliseconds: * if the progress set by DolphinStatusBar::setProgress() * does reach 100 % within 300 milliseconds, * the progress text is not shown at all. This assures that * no flickering occurs for showing a progress of fast * operations. */ void setProgressText(const QString& text); QString progressText() const; /** * Sets the progress in percent (0 - 100). The * progress is shown with a delay of 300 milliseconds: * if the progress does reach 100 % within 300 milliseconds, * the progress is not shown at all. This assures that * no flickering occurs for showing a progress of fast * operations. */ void setProgress(int percent); int progress() const { return m_progress; } /** * Clears the message text of the status bar by replacing * the message with the default text, which can be set * by DolphinStatusBar::setDefaultText(). The progress * information is not cleared. */ void clear(); /** * Sets the default text, which is shown if the status bar * is cleared by DolphinStatusBar::clear(). */ void setDefaultText(const QString& text); const QString& defaultText() const; 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 * content is updated. */ void updateSpaceInfoContent(const KUrl& url); /** - * Requests setting the zoom level to \a zoomLevel by applying it - * to m_requestedZoomLevel and triggering a short timer, which will - * invoke DolphinStatusBar::updateZoomLevel(). This assures no blocking - * of the zoom slider when zooming views having a huge number of - * items. + * Sets the zoom level of the item view to \a zoomLevel. */ - void requestZoomLevel(int zoomLevel); - - /** - * Updates the zoom level to m_requestedZoomLevel (see also - * DolphinStatusBar::requestZoomLevel(). - */ - void updateZoomLevel(); + void setZoomLevel(int zoomLevel); /** * Assures that the text of the statusbar stays visible by hiding * the space information widget or the zoom slider widget if not * enough width is available. */ void assureVisibleText(); private: /** * Makes the space information widget and zoom slider widget * visible, if \a visible is true and the settings allow to show * the widgets. If \a visible is false, it is assured that both * widgets are hidden. */ void setExtensionsVisible(bool visible); private: DolphinView* m_view; StatusBarMessageLabel* m_messageLabel; StatusBarSpaceInfo* m_spaceInfo; QSlider* m_zoomSlider; - QTimer* m_zoomTimer; QLabel* m_progressText; QProgressBar* m_progressBar; int m_progress; - - int m_requestedZoomLevel; }; #endif