From 99eacd9f56acf4ad21994508ee824b1ce1594be1 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sat, 1 Aug 2009 20:01:51 +0000 Subject: move statusbar code into the directory "statusbar" svn path=/trunk/KDE/kdebase/apps/; revision=1005704 --- src/CMakeLists.txt | 6 +- src/dolphinmainwindow.cpp | 2 +- src/dolphinnewmenu.cpp | 2 +- src/dolphinstatusbar.cpp | 326 -------------------------------- src/dolphinstatusbar.h | 184 ------------------ src/dolphinviewcontainer.cpp | 4 +- src/statusbar/dolphinstatusbar.cpp | 326 ++++++++++++++++++++++++++++++++ src/statusbar/dolphinstatusbar.h | 184 ++++++++++++++++++ src/statusbar/statusbarmessagelabel.cpp | 305 ++++++++++++++++++++++++++++++ src/statusbar/statusbarmessagelabel.h | 168 ++++++++++++++++ src/statusbar/statusbarspaceinfo.cpp | 113 +++++++++++ src/statusbar/statusbarspaceinfo.h | 68 +++++++ src/statusbarmessagelabel.cpp | 305 ------------------------------ src/statusbarmessagelabel.h | 168 ---------------- src/statusbarspaceinfo.cpp | 113 ----------- src/statusbarspaceinfo.h | 68 ------- 16 files changed, 1171 insertions(+), 1171 deletions(-) delete mode 100644 src/dolphinstatusbar.cpp delete mode 100644 src/dolphinstatusbar.h create mode 100644 src/statusbar/dolphinstatusbar.cpp create mode 100644 src/statusbar/dolphinstatusbar.h create mode 100644 src/statusbar/statusbarmessagelabel.cpp create mode 100644 src/statusbar/statusbarmessagelabel.h create mode 100644 src/statusbar/statusbarspaceinfo.cpp create mode 100644 src/statusbar/statusbarspaceinfo.h delete mode 100644 src/statusbarmessagelabel.cpp delete mode 100644 src/statusbarmessagelabel.h delete mode 100644 src/statusbarspaceinfo.cpp delete mode 100644 src/statusbarspaceinfo.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 38489fceb..4da9a6628 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -99,7 +99,6 @@ set(dolphin_SRCS dolphinnewmenu.cpp dolphinviewcontainer.cpp dolphinsearchbox.cpp - dolphinstatusbar.cpp dolphindirlister.cpp dolphincontextmenu.cpp filterbar.cpp @@ -135,8 +134,9 @@ set(dolphin_SRCS settings/trashsettingspage.cpp settings/viewsettingspage.cpp settings/viewsettingspagebase.cpp - statusbarspaceinfo.cpp - statusbarmessagelabel.cpp + statusbar/dolphinstatusbar.cpp + statusbar/statusbarspaceinfo.cpp + statusbar/statusbarmessagelabel.cpp zoomlevelinfo.cpp ) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index a95b5a0d2..bf39db15d 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -30,13 +30,13 @@ #include "settings/dolphinsettings.h" #include "settings/dolphinsettingsdialog.h" #include "dolphinsearchbox.h" -#include "dolphinstatusbar.h" #include "dolphinviewcontainer.h" #include "panels/folders/folderspanel.h" #include "panels/places/placespanel.h" #include "panels/information/informationpanel.h" #include "panels/information/metadatawidget.h" #include "mainwindowadaptor.h" +#include "statusbar/dolphinstatusbar.h" #include "viewproperties.h" #ifndef Q_OS_WIN diff --git a/src/dolphinnewmenu.cpp b/src/dolphinnewmenu.cpp index 4b905734e..464d945d6 100644 --- a/src/dolphinnewmenu.cpp +++ b/src/dolphinnewmenu.cpp @@ -22,9 +22,9 @@ #include "dolphinmainwindow.h" #include "dolphinnewmenuobserver.h" -#include "dolphinstatusbar.h" #include "dolphinview.h" #include "dolphinviewcontainer.h" +#include "statusbar/dolphinstatusbar.h" #include #include diff --git a/src/dolphinstatusbar.cpp b/src/dolphinstatusbar.cpp deleted file mode 100644 index aaa302a15..000000000 --- a/src/dolphinstatusbar.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/*************************************************************************** - * 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 "settings/dolphinsettings.h" -#include "dolphinview.h" -#include "dolphin_generalsettings.h" -#include "statusbarmessagelabel.h" -#include "statusbarspaceinfo.h" -#include "zoomlevelinfo.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -DolphinStatusBar::DolphinStatusBar(QWidget* parent, DolphinView* view) : - KHBox(parent), - m_view(view), - m_messageLabel(0), - m_spaceInfo(0), - m_zoomWidget(0), - m_zoomOut(0), - m_zoomSlider(0), - m_zoomIn(0), - m_progressBar(0), - m_progress(100) -{ - setMargin(0); - 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 zoom slider - m_zoomWidget = new QWidget(this); - - m_zoomOut = new QToolButton(m_zoomWidget); - m_zoomOut->setIcon(KIcon("zoom-out")); - m_zoomOut->setAutoRaise(true); - - m_zoomSlider = new QSlider(Qt::Horizontal, m_zoomWidget); - m_zoomSlider->setPageStep(1); - - const int min = ZoomLevelInfo::minimumLevel(); - const int max = ZoomLevelInfo::maximumLevel(); - m_zoomSlider->setRange(min, max); - m_zoomSlider->setValue(view->zoomLevel()); - updateZoomSliderToolTip(view->zoomLevel()); - - m_zoomIn = new QToolButton(m_zoomWidget); - m_zoomIn->setIcon(KIcon("zoom-in")); - m_zoomIn->setAutoRaise(true); - - QHBoxLayout* zoomWidgetLayout = new QHBoxLayout(m_zoomWidget); - zoomWidgetLayout->setSpacing(0); - zoomWidgetLayout->setMargin(0); - zoomWidgetLayout->addWidget(m_zoomOut); - zoomWidgetLayout->addWidget(m_zoomSlider); - zoomWidgetLayout->addWidget(m_zoomIn); - - connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setZoomLevel(int))); - connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(showZoomSliderToolTip(int))); - connect(m_view, SIGNAL(zoomLevelChanged(int)), m_zoomSlider, SLOT(setValue(int))); - connect(m_zoomOut, SIGNAL(clicked()), this, SLOT(zoomOut())); - connect(m_zoomIn, SIGNAL(clicked()), this, SLOT(zoomIn())); - - // initialize space information - m_spaceInfo = new StatusBarSpaceInfo(this); - m_spaceInfo->setUrl(m_view->url()); - - // initialize progress information - m_progressText = new QLabel(this); - m_progressText->hide(); - - m_progressBar = new QProgressBar(this); - m_progressBar->hide(); - - // initialize sizes - const int fontHeight = QFontMetrics(m_messageLabel->font()).height(); - const int zoomWidgetHeight = m_zoomWidget->minimumSizeHint().height(); - const int contentHeight = (fontHeight < zoomWidgetHeight) ? zoomWidgetHeight : fontHeight; - - m_messageLabel->setMinimumTextHeight(contentHeight); - m_spaceInfo->setFixedHeight(contentHeight); - m_progressBar->setFixedSize(200, contentHeight); - m_zoomWidget->setFixedSize(150, contentHeight); - - setExtensionsVisible(true); -} - -DolphinStatusBar::~DolphinStatusBar() -{ -} - -void DolphinStatusBar::setMessage(const QString& msg, - Type type) -{ - if (msg.isEmpty()) { - // show the default text as fallback - clear(); - return; - } - - if ((msg == m_messageLabel->text()) && (type == m_messageLabel->type())) { - // the message is already shown - return; - } - - 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::refresh() -{ - setExtensionsVisible(true); - assureVisibleText(); -} - -void DolphinStatusBar::resizeEvent(QResizeEvent* event) -{ - // It is important to hide the widgets before invoking - // QWidget::resizeEvent(), otherwise it is possible that - // the dock widgets are shrinked when having a small - // statusbar width (bug #202147). - m_zoomWidget->hide(); - m_spaceInfo->hide(); - - 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::setZoomLevel(int zoomLevel) -{ - m_zoomOut->setEnabled(zoomLevel > m_zoomSlider->minimum()); - m_zoomIn->setEnabled(zoomLevel < m_zoomSlider->maximum()); - m_view->setZoomLevel(zoomLevel); - updateZoomSliderToolTip(zoomLevel); -} - -void DolphinStatusBar::assureVisibleText() -{ - const int widthGap = m_messageLabel->widthGap(); - if (m_spaceInfo->isVisible() || m_zoomWidget->isVisible()) { - // At least the space information or the zoom slider is shown. - // Hide them if the status bar text does not fit into the available width. - if (widthGap > 0) { - setExtensionsVisible(false); - } - } else if (!m_progressBar->isVisible()) { - const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); - const int spaceInfoWidth = settings->showSpaceInfo() ? m_spaceInfo->minimumWidth() : 0; - const int zoomWidgetWidth = settings->showZoomSlider() ? m_zoomWidget->minimumWidth() : 0; - const int widgetsWidth = spaceInfoWidth + zoomWidgetWidth; - - if (widthGap + widgetsWidth <= 0) { - setExtensionsVisible(true); - } - } -} - -void DolphinStatusBar::zoomOut() -{ - const int value = m_zoomSlider->value(); - m_zoomSlider->setValue(value - 1); -} - -void DolphinStatusBar::zoomIn() -{ - const int value = m_zoomSlider->value(); - m_zoomSlider->setValue(value + 1); -} - -void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel) -{ - updateZoomSliderToolTip(zoomLevel); - - QPoint global = m_zoomSlider->rect().topLeft(); - global.ry() += m_zoomSlider->height() / 2; - QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global)); - QApplication::sendEvent(m_zoomSlider, &toolTipEvent); -} - -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_zoomWidget->setVisible(zoomSliderVisible); -} - -void DolphinStatusBar::updateZoomSliderToolTip(int zoomLevel) -{ - const int size = ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel); - m_zoomSlider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); -} - -#include "dolphinstatusbar.moc" diff --git a/src/dolphinstatusbar.h b/src/dolphinstatusbar.h deleted file mode 100644 index a536ea178..000000000 --- a/src/dolphinstatusbar.h +++ /dev/null @@ -1,184 +0,0 @@ -/*************************************************************************** - * 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 QToolButton; -class QSlider; - -/** - * @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; - - /** - * Refreshes the status bar to get synchronized with the (updated) Dolphin settings. - */ - void refresh(); - -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); - - /** - * Sets the zoom level of the item view to \a zoomLevel. - */ - 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(); - - void zoomOut(); - void zoomIn(); - void showZoomSliderToolTip(int zoomLevel); - -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); - - /** - * Updates the text of the zoom slider tooltip to show - * the currently used size. - */ - void updateZoomSliderToolTip(int zoomLevel); - -private: - DolphinView* m_view; - StatusBarMessageLabel* m_messageLabel; - StatusBarSpaceInfo* m_spaceInfo; - - QWidget* m_zoomWidget; - QToolButton* m_zoomOut; - QSlider* m_zoomSlider; - QToolButton* m_zoomIn; - - QLabel* m_progressText; - QProgressBar* m_progressBar; - int m_progress; -}; - -#endif diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 475b002e2..e9417e1bc 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -44,12 +44,12 @@ #include #include #include +#include #include #include "dolphinmodel.h" #include "dolphincolumnview.h" #include "dolphincontroller.h" -#include "dolphinstatusbar.h" #include "dolphinmainwindow.h" #include "dolphindirlister.h" #include "dolphinsortfilterproxymodel.h" @@ -58,7 +58,7 @@ #include "dolphincontextmenu.h" #include "draganddrophelper.h" #include "filterbar.h" -#include "kurlnavigator.h" +#include "statusbar/dolphinstatusbar.h" #include "viewproperties.h" #include "settings/dolphinsettings.h" #include "dolphin_generalsettings.h" diff --git a/src/statusbar/dolphinstatusbar.cpp b/src/statusbar/dolphinstatusbar.cpp new file mode 100644 index 000000000..aaa302a15 --- /dev/null +++ b/src/statusbar/dolphinstatusbar.cpp @@ -0,0 +1,326 @@ +/*************************************************************************** + * 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 "settings/dolphinsettings.h" +#include "dolphinview.h" +#include "dolphin_generalsettings.h" +#include "statusbarmessagelabel.h" +#include "statusbarspaceinfo.h" +#include "zoomlevelinfo.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +DolphinStatusBar::DolphinStatusBar(QWidget* parent, DolphinView* view) : + KHBox(parent), + m_view(view), + m_messageLabel(0), + m_spaceInfo(0), + m_zoomWidget(0), + m_zoomOut(0), + m_zoomSlider(0), + m_zoomIn(0), + m_progressBar(0), + m_progress(100) +{ + setMargin(0); + 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 zoom slider + m_zoomWidget = new QWidget(this); + + m_zoomOut = new QToolButton(m_zoomWidget); + m_zoomOut->setIcon(KIcon("zoom-out")); + m_zoomOut->setAutoRaise(true); + + m_zoomSlider = new QSlider(Qt::Horizontal, m_zoomWidget); + m_zoomSlider->setPageStep(1); + + const int min = ZoomLevelInfo::minimumLevel(); + const int max = ZoomLevelInfo::maximumLevel(); + m_zoomSlider->setRange(min, max); + m_zoomSlider->setValue(view->zoomLevel()); + updateZoomSliderToolTip(view->zoomLevel()); + + m_zoomIn = new QToolButton(m_zoomWidget); + m_zoomIn->setIcon(KIcon("zoom-in")); + m_zoomIn->setAutoRaise(true); + + QHBoxLayout* zoomWidgetLayout = new QHBoxLayout(m_zoomWidget); + zoomWidgetLayout->setSpacing(0); + zoomWidgetLayout->setMargin(0); + zoomWidgetLayout->addWidget(m_zoomOut); + zoomWidgetLayout->addWidget(m_zoomSlider); + zoomWidgetLayout->addWidget(m_zoomIn); + + connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(setZoomLevel(int))); + connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(showZoomSliderToolTip(int))); + connect(m_view, SIGNAL(zoomLevelChanged(int)), m_zoomSlider, SLOT(setValue(int))); + connect(m_zoomOut, SIGNAL(clicked()), this, SLOT(zoomOut())); + connect(m_zoomIn, SIGNAL(clicked()), this, SLOT(zoomIn())); + + // initialize space information + m_spaceInfo = new StatusBarSpaceInfo(this); + m_spaceInfo->setUrl(m_view->url()); + + // initialize progress information + m_progressText = new QLabel(this); + m_progressText->hide(); + + m_progressBar = new QProgressBar(this); + m_progressBar->hide(); + + // initialize sizes + const int fontHeight = QFontMetrics(m_messageLabel->font()).height(); + const int zoomWidgetHeight = m_zoomWidget->minimumSizeHint().height(); + const int contentHeight = (fontHeight < zoomWidgetHeight) ? zoomWidgetHeight : fontHeight; + + m_messageLabel->setMinimumTextHeight(contentHeight); + m_spaceInfo->setFixedHeight(contentHeight); + m_progressBar->setFixedSize(200, contentHeight); + m_zoomWidget->setFixedSize(150, contentHeight); + + setExtensionsVisible(true); +} + +DolphinStatusBar::~DolphinStatusBar() +{ +} + +void DolphinStatusBar::setMessage(const QString& msg, + Type type) +{ + if (msg.isEmpty()) { + // show the default text as fallback + clear(); + return; + } + + if ((msg == m_messageLabel->text()) && (type == m_messageLabel->type())) { + // the message is already shown + return; + } + + 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::refresh() +{ + setExtensionsVisible(true); + assureVisibleText(); +} + +void DolphinStatusBar::resizeEvent(QResizeEvent* event) +{ + // It is important to hide the widgets before invoking + // QWidget::resizeEvent(), otherwise it is possible that + // the dock widgets are shrinked when having a small + // statusbar width (bug #202147). + m_zoomWidget->hide(); + m_spaceInfo->hide(); + + 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::setZoomLevel(int zoomLevel) +{ + m_zoomOut->setEnabled(zoomLevel > m_zoomSlider->minimum()); + m_zoomIn->setEnabled(zoomLevel < m_zoomSlider->maximum()); + m_view->setZoomLevel(zoomLevel); + updateZoomSliderToolTip(zoomLevel); +} + +void DolphinStatusBar::assureVisibleText() +{ + const int widthGap = m_messageLabel->widthGap(); + if (m_spaceInfo->isVisible() || m_zoomWidget->isVisible()) { + // At least the space information or the zoom slider is shown. + // Hide them if the status bar text does not fit into the available width. + if (widthGap > 0) { + setExtensionsVisible(false); + } + } else if (!m_progressBar->isVisible()) { + const GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + const int spaceInfoWidth = settings->showSpaceInfo() ? m_spaceInfo->minimumWidth() : 0; + const int zoomWidgetWidth = settings->showZoomSlider() ? m_zoomWidget->minimumWidth() : 0; + const int widgetsWidth = spaceInfoWidth + zoomWidgetWidth; + + if (widthGap + widgetsWidth <= 0) { + setExtensionsVisible(true); + } + } +} + +void DolphinStatusBar::zoomOut() +{ + const int value = m_zoomSlider->value(); + m_zoomSlider->setValue(value - 1); +} + +void DolphinStatusBar::zoomIn() +{ + const int value = m_zoomSlider->value(); + m_zoomSlider->setValue(value + 1); +} + +void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel) +{ + updateZoomSliderToolTip(zoomLevel); + + QPoint global = m_zoomSlider->rect().topLeft(); + global.ry() += m_zoomSlider->height() / 2; + QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global)); + QApplication::sendEvent(m_zoomSlider, &toolTipEvent); +} + +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_zoomWidget->setVisible(zoomSliderVisible); +} + +void DolphinStatusBar::updateZoomSliderToolTip(int zoomLevel) +{ + const int size = ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel); + m_zoomSlider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); +} + +#include "dolphinstatusbar.moc" diff --git a/src/statusbar/dolphinstatusbar.h b/src/statusbar/dolphinstatusbar.h new file mode 100644 index 000000000..a536ea178 --- /dev/null +++ b/src/statusbar/dolphinstatusbar.h @@ -0,0 +1,184 @@ +/*************************************************************************** + * 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 QToolButton; +class QSlider; + +/** + * @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; + + /** + * Refreshes the status bar to get synchronized with the (updated) Dolphin settings. + */ + void refresh(); + +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); + + /** + * Sets the zoom level of the item view to \a zoomLevel. + */ + 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(); + + void zoomOut(); + void zoomIn(); + void showZoomSliderToolTip(int zoomLevel); + +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); + + /** + * Updates the text of the zoom slider tooltip to show + * the currently used size. + */ + void updateZoomSliderToolTip(int zoomLevel); + +private: + DolphinView* m_view; + StatusBarMessageLabel* m_messageLabel; + StatusBarSpaceInfo* m_spaceInfo; + + QWidget* m_zoomWidget; + QToolButton* m_zoomOut; + QSlider* m_zoomSlider; + QToolButton* m_zoomIn; + + QLabel* m_progressText; + QProgressBar* m_progressBar; + int m_progress; +}; + +#endif diff --git a/src/statusbar/statusbarmessagelabel.cpp b/src/statusbar/statusbarmessagelabel.cpp new file mode 100644 index 000000000..bb7c59d6a --- /dev/null +++ b/src/statusbar/statusbarmessagelabel.cpp @@ -0,0 +1,305 @@ +/*************************************************************************** + * 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 "statusbarmessagelabel.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +StatusBarMessageLabel::StatusBarMessageLabel(QWidget* parent) : + QWidget(parent), + m_type(DolphinStatusBar::Default), + m_state(Default), + m_illumination(0), + m_minTextHeight(-1), + m_timer(0), + m_closeButton(0) +{ + setMinimumHeight(KIconLoader::SizeSmall); + + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), + this, SLOT(timerDone())); + + m_closeButton = new QPushButton(i18nc("@action:button", "Close"), this); + m_closeButton->hide(); + connect(m_closeButton, SIGNAL(clicked()), + this, SLOT(closeErrorMessage())); +} + +StatusBarMessageLabel::~StatusBarMessageLabel() +{ +} + +void StatusBarMessageLabel::setMessage(const QString& text, + DolphinStatusBar::Type type) +{ + if ((text == m_text) && (type == m_type)) { + return; + } + + if (m_type == DolphinStatusBar::Error) { + if (type == DolphinStatusBar::Error) { + m_pendingMessages.insert(0, m_text); + } else if ((m_state != Default) || !m_pendingMessages.isEmpty()) { + // a non-error message should not be shown, as there + // are other pending error messages in the queue + return; + } + } + + m_text = text; + m_type = type; + + m_timer->stop(); + m_illumination = 0; + m_state = Default; + + const char* iconName = 0; + QPixmap pixmap; + switch (type) { + case DolphinStatusBar::OperationCompleted: + iconName = "dialog-ok"; + // "ok" icon should probably be "dialog-success", but we don't have that icon in KDE 4.0 + m_closeButton->hide(); + break; + + case DolphinStatusBar::Information: + iconName = "dialog-information"; + m_closeButton->hide(); + break; + + case DolphinStatusBar::Error: + m_timer->start(100); + m_state = Illuminate; + + updateCloseButtonPosition(); + m_closeButton->show(); + break; + + case DolphinStatusBar::Default: + default: + m_closeButton->hide(); + break; + } + + m_pixmap = (iconName == 0) ? QPixmap() : SmallIcon(iconName); + QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText())); + update(); +} + +void StatusBarMessageLabel::setMinimumTextHeight(int min) +{ + if (min != m_minTextHeight) { + m_minTextHeight = min; + setMinimumHeight(min); + if (m_closeButton->height() > min) { + m_closeButton->setFixedHeight(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); + + if (m_illumination > 0) { + // at this point, a: we are a second label being drawn over the already + // painted status area, so we can be translucent, and b: our palette's + // window color (bg only) seems to be wrong (always black) + KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window); + QColor backgroundColor = scheme.background(KColorScheme::NegativeBackground).color(); + backgroundColor.setAlpha(qMin(255, m_illumination * 2)); + painter.setBrush(backgroundColor); + painter.setPen(Qt::NoPen); + painter.drawRect(QRect(0, 0, width(), height())); + } + + // draw pixmap + int x = BorderGap; + const int y = (m_minTextHeight - m_pixmap.height()) / 2; + + if (!m_pixmap.isNull()) { + painter.drawPixmap(x, y, m_pixmap); + x += m_pixmap.width() + BorderGap; + } + + // draw text + painter.setPen(palette().windowText().color()); + int flags = Qt::AlignVCenter; + if (height() > m_minTextHeight) { + flags = flags | Qt::TextWordWrap; + } + painter.drawText(QRect(x, 0, availableTextWidth(), height()), flags, m_text); + painter.end(); +} + +void StatusBarMessageLabel::resizeEvent(QResizeEvent* event) +{ + QWidget::resizeEvent(event); + updateCloseButtonPosition(); + QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText())); +} + +void StatusBarMessageLabel::timerDone() +{ + switch (m_state) { + case Illuminate: { + // increase the illumination + const int illumination_max = 128; + if (m_illumination < illumination_max) { + m_illumination += 32; + if (m_illumination > illumination_max) { + m_illumination = illumination_max; + } + update(); + } else { + m_state = Illuminated; + m_timer->start(5000); + } + break; + } + + case Illuminated: { + // start desaturation + m_state = Desaturate; + m_timer->start(100); + break; + } + + case Desaturate: { + // desaturate + if (m_illumination > 0) { + m_illumination -= 5; + update(); + } else { + m_state = Default; + m_timer->stop(); + } + break; + } + + default: + break; + } +} + +void StatusBarMessageLabel::assureVisibleText() +{ + if (m_text.isEmpty()) { + return; + } + + int requiredHeight = m_minTextHeight; + if (m_type != DolphinStatusBar::Default) { + // Calculate the required height of the widget thats + // needed for having a fully visible text. Note that for the default + // statusbar type (e. g. hover information) increasing the text height + // is not wanted, as this might rearrange the layout of items. + + QFontMetrics fontMetrics(font()); + const QRect bounds(fontMetrics.boundingRect(0, 0, availableTextWidth(), height(), + Qt::AlignVCenter | Qt::TextWordWrap, m_text)); + requiredHeight = bounds.height(); + if (requiredHeight < m_minTextHeight) { + requiredHeight = m_minTextHeight; + } + } + + // Increase/decrease the current height of the widget to the + // required height. The increasing/decreasing is done in several + // steps to have an animation if the height is modified + // (see StatusBarMessageLabel::resizeEvent()) + const int gap = m_minTextHeight / 2; + int minHeight = minimumHeight(); + if (minHeight < requiredHeight) { + minHeight += gap; + if (minHeight > requiredHeight) { + minHeight = requiredHeight; + } + setMinimumHeight(minHeight); + updateGeometry(); + } else if (minHeight > requiredHeight) { + minHeight -= gap; + if (minHeight < requiredHeight) { + minHeight = requiredHeight; + } + setMinimumHeight(minHeight); + updateGeometry(); + } + + updateCloseButtonPosition(); +} + +int StatusBarMessageLabel::availableTextWidth() const +{ + const int buttonWidth = (m_type == DolphinStatusBar::Error) ? + m_closeButton->width() + BorderGap : 0; + return width() - m_pixmap.width() - (BorderGap * 4) - buttonWidth; +} + +void StatusBarMessageLabel::updateCloseButtonPosition() +{ + const int x = width() - m_closeButton->width() - BorderGap; + const int y = (height() - m_closeButton->height()) / 2; + m_closeButton->move(x, y); +} + +void StatusBarMessageLabel::closeErrorMessage() +{ + if (!showPendingMessage()) { + reset(); + setMessage(m_defaultText, DolphinStatusBar::Default); + } +} + +bool StatusBarMessageLabel::showPendingMessage() +{ + if (!m_pendingMessages.isEmpty()) { + reset(); + setMessage(m_pendingMessages.takeFirst(), DolphinStatusBar::Error); + return true; + } + return false; +} + +void StatusBarMessageLabel::reset() +{ + m_text.clear(); + m_type = DolphinStatusBar::Default; +} + +#include "statusbarmessagelabel.moc" diff --git a/src/statusbar/statusbarmessagelabel.h b/src/statusbar/statusbarmessagelabel.h new file mode 100644 index 000000000..a5c72b403 --- /dev/null +++ b/src/statusbar/statusbarmessagelabel.h @@ -0,0 +1,168 @@ +/*************************************************************************** + * 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 STATUSBARMESSAGELABEL_H +#define STATUSBARMESSAGELABEL_H + +#include + +#include +#include + +#include + +class QPaintEvent; +class QResizeEvent; +class QPushButton; +class QTimer; + +/** + * @brief Represents a message text label as part of the status bar. + * + * Dependent from the given type automatically a corresponding icon + * 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. + */ +class StatusBarMessageLabel : public QWidget +{ + Q_OBJECT + +public: + explicit StatusBarMessageLabel(QWidget* parent); + virtual ~StatusBarMessageLabel(); + + void setMessage(const QString& text, DolphinStatusBar::Type type); + + DolphinStatusBar::Type type() const; + + const QString& text() const; + + void setDefaultText(const QString& text); + const QString& defaultText() const; + + // TODO: maybe a better approach is possible with the size hint + void setMinimumTextHeight(int min); + int minimumTextHeight() const; + + /** + * 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() */ + virtual void paintEvent(QPaintEvent* event); + + /** @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; + + /** + * Moves the close button to the upper right corner + * of the message label. + */ + void updateCloseButtonPosition(); + + /** + * Closes the currently shown error message and replaces it + * by the next pending message. + */ + void closeErrorMessage(); + +private: + /** + * Shows the next pending error message. If no pending message + * was in the queue, false is returned. + */ + bool showPendingMessage(); + + /** + * Resets the message label properties. This is useful when the + * result of invoking StatusBarMessageLabel::setMessage() should + * not rely on previous states. + */ + void reset(); + +private: + enum State + { + Default, + Illuminate, + Illuminated, + Desaturate + }; + + enum { GeometryTimeout = 100 }; + enum { BorderGap = 2 }; + + DolphinStatusBar::Type m_type; + State m_state; + int m_illumination; + int m_minTextHeight; + QTimer* m_timer; + QString m_text; + QString m_defaultText; + QList m_pendingMessages; + QPixmap m_pixmap; + QPushButton* m_closeButton; +}; + +inline DolphinStatusBar::Type StatusBarMessageLabel::type() const +{ + return m_type; +} + +inline const QString& StatusBarMessageLabel::text() const +{ + return m_text; +} + +inline void StatusBarMessageLabel::setDefaultText(const QString& text) +{ + m_defaultText = text; +} + +inline const QString& StatusBarMessageLabel::defaultText() const +{ + return m_defaultText; +} + +inline int StatusBarMessageLabel::minimumTextHeight() const +{ + return m_minTextHeight; +} + +#endif diff --git a/src/statusbar/statusbarspaceinfo.cpp b/src/statusbar/statusbarspaceinfo.cpp new file mode 100644 index 000000000..c9173b8f9 --- /dev/null +++ b/src/statusbar/statusbarspaceinfo.cpp @@ -0,0 +1,113 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * + * and Patrice Tremblay * + * * + * 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 "statusbarspaceinfo.h" + +#include +#include +#include +#include + +#include +#include + +StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) : + KCapacityBar(KCapacityBar::DrawTextInline, parent), + m_kBSize(0), + m_timer(0) +{ + setMaximumWidth(200); + setMinimumWidth(200); // something to fix on kcapacitybar (ereslibre) + + // Use a timer to update the space information. Polling is useful + // here, as files can be deleted/added outside the scope of Dolphin. + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(refresh())); +} + +StatusBarSpaceInfo::~StatusBarSpaceInfo() +{ +} + +void StatusBarSpaceInfo::setUrl(const KUrl& url) +{ + m_url = url; + refresh(); +} + +void StatusBarSpaceInfo::showEvent(QShowEvent* event) +{ + KCapacityBar::showEvent(event); + if (!event->spontaneous()) { + refresh(); + m_timer->start(10000); + } +} + +void StatusBarSpaceInfo::hideEvent(QHideEvent* event) +{ + m_timer->stop(); + KCapacityBar::hideEvent(event); +} + +void StatusBarSpaceInfo::refresh() +{ + if (!isVisible()) { + return; + } + + // KDiskFreeSpace is for local paths only + if (!m_url.isLocalFile()) { + setText(i18nc("@info:status", "Unknown size")); + setValue(0); + update(); + return; + } + + KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.toLocalFile()); + if (!mp) { + return; + } + + KDiskFreeSpaceInfo job = KDiskFreeSpaceInfo::freeSpaceInfo(mp->mountPoint()); + if (!job.isValid()) { + setText(i18nc("@info:status", "Unknown size")); + setValue(0); + update(); + return; + } + + KIO::filesize_t kBSize = job.size() / 1024; + KIO::filesize_t kBUsed = job.used() / 1024; + + const bool valuesChanged = (kBUsed != static_cast(value())) || (kBSize != m_kBSize); + if (valuesChanged) { + setText(i18nc("@info:status Free disk space", "%1 free", + KIO::convertSize(job.available()))); + + setUpdatesEnabled(false); + m_kBSize = kBSize; + setValue(kBSize > 0 ? (kBUsed * 100) / kBSize : 0); + setUpdatesEnabled(true); + update(); + } +} + +#include "statusbarspaceinfo.moc" diff --git a/src/statusbar/statusbarspaceinfo.h b/src/statusbar/statusbarspaceinfo.h new file mode 100644 index 000000000..9744548ca --- /dev/null +++ b/src/statusbar/statusbarspaceinfo.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * + * and Patrice Tremblay * + * * + * 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 STATUSBARSPACEINFO_H +#define STATUSBARSPACEINFO_H + +#include + +#include +#include +#include + +#include + +class QHideEvent; +class QShowEvent; + +/** + * @short Shows the available space for the volume represented + * by the given URL as part of the status bar. + */ +class StatusBarSpaceInfo : public KCapacityBar +{ + Q_OBJECT + +public: + explicit StatusBarSpaceInfo(QWidget* parent); + virtual ~StatusBarSpaceInfo(); + + void setUrl(const KUrl& url); + const KUrl& url() const; + +protected: + void showEvent(QShowEvent* event); + void hideEvent(QHideEvent* event); + +private slots: + /** Refreshes the space information for the current set URL. */ + void refresh(); + +private: + quint64 m_kBSize; + KUrl m_url; + QTimer* m_timer; +}; + +inline const KUrl& StatusBarSpaceInfo::url() const +{ + return m_url; +} + +#endif diff --git a/src/statusbarmessagelabel.cpp b/src/statusbarmessagelabel.cpp deleted file mode 100644 index bb7c59d6a..000000000 --- a/src/statusbarmessagelabel.cpp +++ /dev/null @@ -1,305 +0,0 @@ -/*************************************************************************** - * 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 "statusbarmessagelabel.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -StatusBarMessageLabel::StatusBarMessageLabel(QWidget* parent) : - QWidget(parent), - m_type(DolphinStatusBar::Default), - m_state(Default), - m_illumination(0), - m_minTextHeight(-1), - m_timer(0), - m_closeButton(0) -{ - setMinimumHeight(KIconLoader::SizeSmall); - - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), - this, SLOT(timerDone())); - - m_closeButton = new QPushButton(i18nc("@action:button", "Close"), this); - m_closeButton->hide(); - connect(m_closeButton, SIGNAL(clicked()), - this, SLOT(closeErrorMessage())); -} - -StatusBarMessageLabel::~StatusBarMessageLabel() -{ -} - -void StatusBarMessageLabel::setMessage(const QString& text, - DolphinStatusBar::Type type) -{ - if ((text == m_text) && (type == m_type)) { - return; - } - - if (m_type == DolphinStatusBar::Error) { - if (type == DolphinStatusBar::Error) { - m_pendingMessages.insert(0, m_text); - } else if ((m_state != Default) || !m_pendingMessages.isEmpty()) { - // a non-error message should not be shown, as there - // are other pending error messages in the queue - return; - } - } - - m_text = text; - m_type = type; - - m_timer->stop(); - m_illumination = 0; - m_state = Default; - - const char* iconName = 0; - QPixmap pixmap; - switch (type) { - case DolphinStatusBar::OperationCompleted: - iconName = "dialog-ok"; - // "ok" icon should probably be "dialog-success", but we don't have that icon in KDE 4.0 - m_closeButton->hide(); - break; - - case DolphinStatusBar::Information: - iconName = "dialog-information"; - m_closeButton->hide(); - break; - - case DolphinStatusBar::Error: - m_timer->start(100); - m_state = Illuminate; - - updateCloseButtonPosition(); - m_closeButton->show(); - break; - - case DolphinStatusBar::Default: - default: - m_closeButton->hide(); - break; - } - - m_pixmap = (iconName == 0) ? QPixmap() : SmallIcon(iconName); - QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText())); - update(); -} - -void StatusBarMessageLabel::setMinimumTextHeight(int min) -{ - if (min != m_minTextHeight) { - m_minTextHeight = min; - setMinimumHeight(min); - if (m_closeButton->height() > min) { - m_closeButton->setFixedHeight(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); - - if (m_illumination > 0) { - // at this point, a: we are a second label being drawn over the already - // painted status area, so we can be translucent, and b: our palette's - // window color (bg only) seems to be wrong (always black) - KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window); - QColor backgroundColor = scheme.background(KColorScheme::NegativeBackground).color(); - backgroundColor.setAlpha(qMin(255, m_illumination * 2)); - painter.setBrush(backgroundColor); - painter.setPen(Qt::NoPen); - painter.drawRect(QRect(0, 0, width(), height())); - } - - // draw pixmap - int x = BorderGap; - const int y = (m_minTextHeight - m_pixmap.height()) / 2; - - if (!m_pixmap.isNull()) { - painter.drawPixmap(x, y, m_pixmap); - x += m_pixmap.width() + BorderGap; - } - - // draw text - painter.setPen(palette().windowText().color()); - int flags = Qt::AlignVCenter; - if (height() > m_minTextHeight) { - flags = flags | Qt::TextWordWrap; - } - painter.drawText(QRect(x, 0, availableTextWidth(), height()), flags, m_text); - painter.end(); -} - -void StatusBarMessageLabel::resizeEvent(QResizeEvent* event) -{ - QWidget::resizeEvent(event); - updateCloseButtonPosition(); - QTimer::singleShot(GeometryTimeout, this, SLOT(assureVisibleText())); -} - -void StatusBarMessageLabel::timerDone() -{ - switch (m_state) { - case Illuminate: { - // increase the illumination - const int illumination_max = 128; - if (m_illumination < illumination_max) { - m_illumination += 32; - if (m_illumination > illumination_max) { - m_illumination = illumination_max; - } - update(); - } else { - m_state = Illuminated; - m_timer->start(5000); - } - break; - } - - case Illuminated: { - // start desaturation - m_state = Desaturate; - m_timer->start(100); - break; - } - - case Desaturate: { - // desaturate - if (m_illumination > 0) { - m_illumination -= 5; - update(); - } else { - m_state = Default; - m_timer->stop(); - } - break; - } - - default: - break; - } -} - -void StatusBarMessageLabel::assureVisibleText() -{ - if (m_text.isEmpty()) { - return; - } - - int requiredHeight = m_minTextHeight; - if (m_type != DolphinStatusBar::Default) { - // Calculate the required height of the widget thats - // needed for having a fully visible text. Note that for the default - // statusbar type (e. g. hover information) increasing the text height - // is not wanted, as this might rearrange the layout of items. - - QFontMetrics fontMetrics(font()); - const QRect bounds(fontMetrics.boundingRect(0, 0, availableTextWidth(), height(), - Qt::AlignVCenter | Qt::TextWordWrap, m_text)); - requiredHeight = bounds.height(); - if (requiredHeight < m_minTextHeight) { - requiredHeight = m_minTextHeight; - } - } - - // Increase/decrease the current height of the widget to the - // required height. The increasing/decreasing is done in several - // steps to have an animation if the height is modified - // (see StatusBarMessageLabel::resizeEvent()) - const int gap = m_minTextHeight / 2; - int minHeight = minimumHeight(); - if (minHeight < requiredHeight) { - minHeight += gap; - if (minHeight > requiredHeight) { - minHeight = requiredHeight; - } - setMinimumHeight(minHeight); - updateGeometry(); - } else if (minHeight > requiredHeight) { - minHeight -= gap; - if (minHeight < requiredHeight) { - minHeight = requiredHeight; - } - setMinimumHeight(minHeight); - updateGeometry(); - } - - updateCloseButtonPosition(); -} - -int StatusBarMessageLabel::availableTextWidth() const -{ - const int buttonWidth = (m_type == DolphinStatusBar::Error) ? - m_closeButton->width() + BorderGap : 0; - return width() - m_pixmap.width() - (BorderGap * 4) - buttonWidth; -} - -void StatusBarMessageLabel::updateCloseButtonPosition() -{ - const int x = width() - m_closeButton->width() - BorderGap; - const int y = (height() - m_closeButton->height()) / 2; - m_closeButton->move(x, y); -} - -void StatusBarMessageLabel::closeErrorMessage() -{ - if (!showPendingMessage()) { - reset(); - setMessage(m_defaultText, DolphinStatusBar::Default); - } -} - -bool StatusBarMessageLabel::showPendingMessage() -{ - if (!m_pendingMessages.isEmpty()) { - reset(); - setMessage(m_pendingMessages.takeFirst(), DolphinStatusBar::Error); - return true; - } - return false; -} - -void StatusBarMessageLabel::reset() -{ - m_text.clear(); - m_type = DolphinStatusBar::Default; -} - -#include "statusbarmessagelabel.moc" diff --git a/src/statusbarmessagelabel.h b/src/statusbarmessagelabel.h deleted file mode 100644 index 264a3538d..000000000 --- a/src/statusbarmessagelabel.h +++ /dev/null @@ -1,168 +0,0 @@ -/*************************************************************************** - * 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 STATUSBARMESSAGELABEL_H -#define STATUSBARMESSAGELABEL_H - -#include - -#include -#include - -#include - -class QPaintEvent; -class QResizeEvent; -class QPushButton; -class QTimer; - -/** - * @brief Represents a message text label as part of the status bar. - * - * Dependent from the given type automatically a corresponding icon - * 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. - */ -class StatusBarMessageLabel : public QWidget -{ - Q_OBJECT - -public: - explicit StatusBarMessageLabel(QWidget* parent); - virtual ~StatusBarMessageLabel(); - - void setMessage(const QString& text, DolphinStatusBar::Type type); - - DolphinStatusBar::Type type() const; - - const QString& text() const; - - void setDefaultText(const QString& text); - const QString& defaultText() const; - - // TODO: maybe a better approach is possible with the size hint - void setMinimumTextHeight(int min); - int minimumTextHeight() const; - - /** - * 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() */ - virtual void paintEvent(QPaintEvent* event); - - /** @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; - - /** - * Moves the close button to the upper right corner - * of the message label. - */ - void updateCloseButtonPosition(); - - /** - * Closes the currently shown error message and replaces it - * by the next pending message. - */ - void closeErrorMessage(); - -private: - /** - * Shows the next pending error message. If no pending message - * was in the queue, false is returned. - */ - bool showPendingMessage(); - - /** - * Resets the message label properties. This is useful when the - * result of invoking StatusBarMessageLabel::setMessage() should - * not rely on previous states. - */ - void reset(); - -private: - enum State - { - Default, - Illuminate, - Illuminated, - Desaturate - }; - - enum { GeometryTimeout = 100 }; - enum { BorderGap = 2 }; - - DolphinStatusBar::Type m_type; - State m_state; - int m_illumination; - int m_minTextHeight; - QTimer* m_timer; - QString m_text; - QString m_defaultText; - QList m_pendingMessages; - QPixmap m_pixmap; - QPushButton* m_closeButton; -}; - -inline DolphinStatusBar::Type StatusBarMessageLabel::type() const -{ - return m_type; -} - -inline const QString& StatusBarMessageLabel::text() const -{ - return m_text; -} - -inline void StatusBarMessageLabel::setDefaultText(const QString& text) -{ - m_defaultText = text; -} - -inline const QString& StatusBarMessageLabel::defaultText() const -{ - return m_defaultText; -} - -inline int StatusBarMessageLabel::minimumTextHeight() const -{ - return m_minTextHeight; -} - -#endif diff --git a/src/statusbarspaceinfo.cpp b/src/statusbarspaceinfo.cpp deleted file mode 100644 index c9173b8f9..000000000 --- a/src/statusbarspaceinfo.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * - * and Patrice Tremblay * - * * - * 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 "statusbarspaceinfo.h" - -#include -#include -#include -#include - -#include -#include - -StatusBarSpaceInfo::StatusBarSpaceInfo(QWidget* parent) : - KCapacityBar(KCapacityBar::DrawTextInline, parent), - m_kBSize(0), - m_timer(0) -{ - setMaximumWidth(200); - setMinimumWidth(200); // something to fix on kcapacitybar (ereslibre) - - // Use a timer to update the space information. Polling is useful - // here, as files can be deleted/added outside the scope of Dolphin. - m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(refresh())); -} - -StatusBarSpaceInfo::~StatusBarSpaceInfo() -{ -} - -void StatusBarSpaceInfo::setUrl(const KUrl& url) -{ - m_url = url; - refresh(); -} - -void StatusBarSpaceInfo::showEvent(QShowEvent* event) -{ - KCapacityBar::showEvent(event); - if (!event->spontaneous()) { - refresh(); - m_timer->start(10000); - } -} - -void StatusBarSpaceInfo::hideEvent(QHideEvent* event) -{ - m_timer->stop(); - KCapacityBar::hideEvent(event); -} - -void StatusBarSpaceInfo::refresh() -{ - if (!isVisible()) { - return; - } - - // KDiskFreeSpace is for local paths only - if (!m_url.isLocalFile()) { - setText(i18nc("@info:status", "Unknown size")); - setValue(0); - update(); - return; - } - - KMountPoint::Ptr mp = KMountPoint::currentMountPoints().findByPath(m_url.toLocalFile()); - if (!mp) { - return; - } - - KDiskFreeSpaceInfo job = KDiskFreeSpaceInfo::freeSpaceInfo(mp->mountPoint()); - if (!job.isValid()) { - setText(i18nc("@info:status", "Unknown size")); - setValue(0); - update(); - return; - } - - KIO::filesize_t kBSize = job.size() / 1024; - KIO::filesize_t kBUsed = job.used() / 1024; - - const bool valuesChanged = (kBUsed != static_cast(value())) || (kBSize != m_kBSize); - if (valuesChanged) { - setText(i18nc("@info:status Free disk space", "%1 free", - KIO::convertSize(job.available()))); - - setUpdatesEnabled(false); - m_kBSize = kBSize; - setValue(kBSize > 0 ? (kBUsed * 100) / kBSize : 0); - setUpdatesEnabled(true); - update(); - } -} - -#include "statusbarspaceinfo.moc" diff --git a/src/statusbarspaceinfo.h b/src/statusbarspaceinfo.h deleted file mode 100644 index 9744548ca..000000000 --- a/src/statusbarspaceinfo.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * - * and Patrice Tremblay * - * * - * 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 STATUSBARSPACEINFO_H -#define STATUSBARSPACEINFO_H - -#include - -#include -#include -#include - -#include - -class QHideEvent; -class QShowEvent; - -/** - * @short Shows the available space for the volume represented - * by the given URL as part of the status bar. - */ -class StatusBarSpaceInfo : public KCapacityBar -{ - Q_OBJECT - -public: - explicit StatusBarSpaceInfo(QWidget* parent); - virtual ~StatusBarSpaceInfo(); - - void setUrl(const KUrl& url); - const KUrl& url() const; - -protected: - void showEvent(QShowEvent* event); - void hideEvent(QHideEvent* event); - -private slots: - /** Refreshes the space information for the current set URL. */ - void refresh(); - -private: - quint64 m_kBSize; - KUrl m_url; - QTimer* m_timer; -}; - -inline const KUrl& StatusBarSpaceInfo::url() const -{ - return m_url; -} - -#endif -- cgit v1.3