]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Provide a zoom slider in the status bar. It is configurable whether the zoom slider...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 5 Oct 2008 21:17:06 +0000 (21:17 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 5 Oct 2008 21:17:06 +0000 (21:17 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=868272

src/dolphin_generalsettings.kcfg
src/dolphinstatusbar.cpp
src/dolphinstatusbar.h
src/dolphinview.cpp
src/dolphinviewcontainer.cpp

index f8daf93397145d643420ea5589fd72ba20a87fd9..2f4defa926a067ec27c8033acbcb6ae904c56797 100644 (file)
             <label context="@label">Use auto-expanding folders for all view types</label>
             <default>false</default>
         </entry>
             <label context="@label">Use auto-expanding folders for all view types</label>
             <default>false</default>
         </entry>
+        <entry name="ShowZoomSlider" type="Bool">
+            <label context="@label">Show zoom slider in the statusbar</label>
+            <default>true</default>
+        </entry>
+        <entry name="ShowSpaceInfo" type="Bool">
+            <label context="@label">Show the space information in the statusbar</label>
+            <default>false</default>
+        </entry>
     </group>
 </kcfg>
     </group>
 </kcfg>
index bd9b8bee8aef292c286298cf9479769e4e249c9f..84e18d3b6ead76c243b4283c11ab443006fe6cb9 100644 (file)
  ***************************************************************************/
 
 #include "dolphinstatusbar.h"
  ***************************************************************************/
 
 #include "dolphinstatusbar.h"
+#include "dolphinsettings.h"
 #include "dolphinview.h"
 #include "dolphinview.h"
+#include "dolphin_generalsettings.h"
 #include "statusbarmessagelabel.h"
 #include "statusbarspaceinfo.h"
 #include "statusbarmessagelabel.h"
 #include "statusbarspaceinfo.h"
+#include "zoomlevelinfo.h"
 
 #include <QtGui/QLabel>
 #include <QtGui/QProgressBar>
 
 #include <QtGui/QLabel>
 #include <QtGui/QProgressBar>
 #include <kiconloader.h>
 #include <kvbox.h>
 
 #include <kiconloader.h>
 #include <kvbox.h>
 
-DolphinStatusBar::DolphinStatusBar(QWidget* parent, const KUrl& url) :
+DolphinStatusBar::DolphinStatusBar(QWidget* parent, DolphinView* view) :
     KHBox(parent),
     KHBox(parent),
+    m_view(view),
     m_messageLabel(0),
     m_spaceInfo(0),
     m_messageLabel(0),
     m_spaceInfo(0),
+    m_zoomSlider(0),
+    m_zoomTimer(0),
     m_progressBar(0),
     m_progressBar(0),
-    m_progress(100)
+    m_progress(100),
+    m_requestedZoomLevel(0)
 {
     setSpacing(4);
 
 {
     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);
 
     m_messageLabel = new StatusBarMessageLabel(this);
     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
+    // initialize space information
     m_spaceInfo = new StatusBarSpaceInfo(this);
     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();
 
     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;
 
     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_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();
     }
         m_progressBar->hide();
         m_progressText->hide();
     }
-    showSpaceInfo();
+    assureVisibleText();
 }
 
 DolphinStatusBar::Type DolphinStatusBar::type() const
 }
 
 DolphinStatusBar::Type DolphinStatusBar::type() const
@@ -146,47 +183,76 @@ const QString& DolphinStatusBar::defaultText() const
 void DolphinStatusBar::resizeEvent(QResizeEvent* event)
 {
     QWidget::resizeEvent(event);
 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) {
 }
 
 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 {
         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();
         m_progressText->hide();
         m_progressBar->hide();
-        showSpaceInfo();
+        assureVisibleText();
     }
 }
 
 void DolphinStatusBar::updateSpaceInfoContent(const KUrl& url)
 {
     m_spaceInfo->setUrl(url);
     }
 }
 
 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 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) {
         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"
 }
 
 #include "dolphinstatusbar.moc"
index 1a9aaa4c172c53ccd90709d8d0f103ceeba76712..49f14357dd84c5ae20d9a2685e4e2812c2a272d6 100644 (file)
@@ -27,8 +27,10 @@ class DolphinView;
 class KUrl;
 class StatusBarMessageLabel;
 class StatusBarSpaceInfo;
 class KUrl;
 class StatusBarMessageLabel;
 class StatusBarSpaceInfo;
-class QProgressBar;
 class QLabel;
 class QLabel;
+class QProgressBar;
+class QSlider;
+class QTimer;
 
 /**
  * @brief Represents the statusbar of a Dolphin view.
 
 /**
  * @brief Represents the statusbar of a Dolphin view.
@@ -53,8 +55,7 @@ public:
         Error
     };
 
         Error
     };
 
-    DolphinStatusBar(QWidget* parent,
-                     const KUrl& url);
+    DolphinStatusBar(QWidget* parent, DolphinView* view);
 
     virtual ~DolphinStatusBar();
 
 
     virtual ~DolphinStatusBar();
 
@@ -128,21 +129,50 @@ private slots:
      * content is updated.
      */
     void updateSpaceInfoContent(const KUrl& url);
      * 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:
 
 private:
+    DolphinView* m_view;
     StatusBarMessageLabel* m_messageLabel;
     StatusBarSpaceInfo* m_spaceInfo;
     StatusBarMessageLabel* m_messageLabel;
     StatusBarSpaceInfo* m_spaceInfo;
+    QSlider* m_zoomSlider;
+    QTimer* m_zoomTimer;
 
     QLabel* m_progressText;
     QProgressBar* m_progressBar;
     int m_progress;
 
     QLabel* m_progressText;
     QProgressBar* m_progressBar;
     int m_progress;
+    
+    int m_requestedZoomLevel;
 };
 
 #endif
 };
 
 #endif
index 4e8b565bf1b663bfd5a80c30df617a9ce85df815..25d0cc1995d60a60e164b0cb6764fa6a7293998c 100644 (file)
@@ -193,6 +193,7 @@ void DolphinView::setMode(Mode mode)
         return; // the wished mode is already set
     }
 
         return; // the wished mode is already set
     }
 
+    const int oldZoomLevel = m_controller->zoomLevel();
     m_mode = mode;
 
     deleteView();
     m_mode = mode;
 
     deleteView();
@@ -219,6 +220,7 @@ void DolphinView::setMode(Mode mode)
     }
 
     emit modeChanged();
     }
 
     emit modeChanged();
+    updateZoomLevel(oldZoomLevel);
 }
 
 DolphinView::Mode DolphinView::mode() const
 }
 
 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 Mode mode = props.viewMode();
     if (m_mode != mode) {
+        const int oldZoomLevel = m_controller->zoomLevel();
+        
         m_mode = mode;
         createView();
         emit modeChanged();
         m_mode = mode;
         createView();
         emit modeChanged();
+        
+        updateZoomLevel(oldZoomLevel);
     }
     if (itemView() == 0) {
         createView();
     }
     if (itemView() == 0) {
         createView();
@@ -1220,7 +1226,7 @@ void DolphinView::createView()
 
     view->setSelectionMode(QAbstractItemView::ExtendedSelection);
 
 
     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()) {
     m_previewGenerator->setPreviewShown(m_showPreview);
 
     if (DolphinSettings::instance().generalSettings()->showToolTips()) {
index 5ec6522e770160a12d67c168112edde565c060e1..342aa08c72cfc28e0dc2b81f9d4a8428620bdb28 100644 (file)
@@ -144,9 +144,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
             this, SLOT(restoreView(const KUrl&)));
 
     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());
 
     m_filterBar = new FilterBar(this);
     m_filterBar->setVisible(settings->filterBar());