From: Peter Penz Date: Sun, 5 Oct 2008 21:17:06 +0000 (+0000) Subject: Provide a zoom slider in the status bar. It is configurable whether the zoom slider... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/2a1c78d3dad73dff28e5cd5899987edc5f5d5780?ds=sidebyside Provide a zoom slider in the status bar. It is configurable whether the zoom slider and/or the space information is shown in the statusbar (the GUI in the settings dialog will be provided during the next week). svn path=/trunk/KDE/kdebase/apps/; revision=868272 --- diff --git a/src/dolphin_generalsettings.kcfg b/src/dolphin_generalsettings.kcfg index f8daf9339..2f4defa92 100644 --- a/src/dolphin_generalsettings.kcfg +++ b/src/dolphin_generalsettings.kcfg @@ -59,5 +59,13 @@ false + + + true + + + + false + diff --git a/src/dolphinstatusbar.cpp b/src/dolphinstatusbar.cpp index bd9b8bee8..84e18d3b6 100644 --- a/src/dolphinstatusbar.cpp +++ b/src/dolphinstatusbar.cpp @@ -19,9 +19,12 @@ ***************************************************************************/ #include "dolphinstatusbar.h" +#include "dolphinsettings.h" #include "dolphinview.h" +#include "dolphin_generalsettings.h" #include "statusbarmessagelabel.h" #include "statusbarspaceinfo.h" +#include "zoomlevelinfo.h" #include #include @@ -30,27 +33,58 @@ #include #include -DolphinStatusBar::DolphinStatusBar(QWidget* parent, const KUrl& url) : +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_progress(100), + m_requestedZoomLevel(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 space information m_spaceInfo = new StatusBarSpaceInfo(this); - m_spaceInfo->setUrl(url); - + 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))); + 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; @@ -59,6 +93,9 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent, const KUrl& url) : m_spaceInfo->setFixedHeight(contentHeight); m_progressBar->setFixedHeight(contentHeight); m_progressBar->setMaximumWidth(200); + m_zoomSlider->setMaximumWidth(100); + + setExtensionsVisible(true); } @@ -76,7 +113,7 @@ void DolphinStatusBar::setMessage(const QString& msg, m_progressBar->hide(); m_progressText->hide(); } - showSpaceInfo(); + assureVisibleText(); } DolphinStatusBar::Type DolphinStatusBar::type() const @@ -146,47 +183,76 @@ const QString& DolphinStatusBar::defaultText() const void DolphinStatusBar::resizeEvent(QResizeEvent* event) { QWidget::resizeEvent(event); - QMetaObject::invokeMethod(this, "showSpaceInfo", Qt::QueuedConnection); + 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 space information - m_spaceInfo->hide(); + // 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 space information + // hide the progress information and show the extensions m_progressText->hide(); m_progressBar->hide(); - showSpaceInfo(); + assureVisibleText(); } } void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url) { m_spaceInfo->setUrl(url); - showSpaceInfo(); + assureVisibleText(); } -void DolphinStatusBar::showSpaceInfo() +void DolphinStatusBar::requestZoomLevel(int zoomLevel) +{ + m_requestedZoomLevel = zoomLevel; + m_zoomTimer->start(); +} + +void DolphinStatusBar::updateZoomLevel() +{ + m_view->setZoomLevel(m_requestedZoomLevel); +} + +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 (m_spaceInfo->isVisible()) { - // The space information is shown currently. Hide it if - // the status bar text does not fit into the available width. + 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) { - m_spaceInfo->hide(); + setExtensionsVisible(false); } - } else if (!isProgressBarVisible && (widthGap + m_spaceInfo->width() <= 0)) { - m_spaceInfo->show(); + } 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/src/dolphinstatusbar.h b/src/dolphinstatusbar.h index 1a9aaa4c1..49f14357d 100644 --- a/src/dolphinstatusbar.h +++ b/src/dolphinstatusbar.h @@ -27,8 +27,10 @@ class DolphinView; class KUrl; class StatusBarMessageLabel; class StatusBarSpaceInfo; -class QProgressBar; class QLabel; +class QProgressBar; +class QSlider; +class QTimer; /** * @brief Represents the statusbar of a Dolphin view. @@ -53,8 +55,7 @@ public: Error }; - DolphinStatusBar(QWidget* parent, - const KUrl& url); + DolphinStatusBar(QWidget* parent, DolphinView* view); virtual ~DolphinStatusBar(); @@ -128,21 +129,50 @@ private slots: * 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. + */ + void requestZoomLevel(int zoomLevel); + + /** + * Updates the zoom level to m_requestedZoomLevel (see also + * DolphinStatusBar::requestZoomLevel(). + */ + void updateZoomLevel(); /** - * 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. + * 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 showSpaceInfo(); + 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 diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 4e8b565bf..25d0cc199 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -193,6 +193,7 @@ void DolphinView::setMode(Mode mode) return; // the wished mode is already set } + const int oldZoomLevel = m_controller->zoomLevel(); m_mode = mode; deleteView(); @@ -219,6 +220,7 @@ void DolphinView::setMode(Mode mode) } emit modeChanged(); + updateZoomLevel(oldZoomLevel); } DolphinView::Mode DolphinView::mode() const @@ -1102,9 +1104,13 @@ void DolphinView::applyViewProperties(const KUrl& url) const Mode mode = props.viewMode(); if (m_mode != mode) { + const int oldZoomLevel = m_controller->zoomLevel(); + m_mode = mode; createView(); emit modeChanged(); + + updateZoomLevel(oldZoomLevel); } if (itemView() == 0) { createView(); @@ -1220,7 +1226,7 @@ void DolphinView::createView() view->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_previewGenerator = new KFilePreviewGenerator(view, m_proxyModel); + m_previewGenerator = new KFilePreviewGenerator(view); m_previewGenerator->setPreviewShown(m_showPreview); if (DolphinSettings::instance().generalSettings()->showToolTips()) { diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 5ec6522e7..342aa08c7 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -144,9 +144,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)), this, SLOT(restoreView(const KUrl&))); - m_statusBar = new DolphinStatusBar(this, url); - connect(m_view, SIGNAL(urlChanged(const KUrl&)), - m_statusBar, SLOT(updateSpaceInfoContent(const KUrl&))); + m_statusBar = new DolphinStatusBar(this, m_view); m_filterBar = new FilterBar(this); m_filterBar->setVisible(settings->filterBar());