]> cloud.milkyroute.net Git - dolphin.git/commitdiff
* Increase the column-width automatically in case where the name of the file does...
authorPeter Penz <peter.penz19@gmail.com>
Sat, 9 Oct 2010 18:46:58 +0000 (18:46 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 9 Oct 2010 18:46:58 +0000 (18:46 +0000)
* When scrolling to the active column, do it with a small delay so that temporary activations of a column don't result in jittering

BUG: 214324
FIXED-IN: 4.6.0

svn path=/trunk/KDE/kdebase/apps/; revision=1184290

src/views/dolphincolumnview.cpp
src/views/dolphincolumnview.h
src/views/dolphincolumnviewcontainer.cpp
src/views/dolphincolumnviewcontainer.h

index 309674122b362843581f3f182924eefb22dc1c4e..4b3a9f582da9fae9825591c3a52936025e77326f 100644 (file)
@@ -120,6 +120,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent,
     m_dirLister->setDelayedMimeTypes(true);
     const bool showHiddenFiles = m_container->m_dolphinViewController->view()->showHiddenFiles();
     m_dirLister->setShowingDotFiles(showHiddenFiles);
+    connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
 
     m_dolphinModel = new DolphinModel(this);
     m_dolphinModel->setDirLister(m_dirLister);
@@ -496,6 +497,34 @@ void DolphinColumnView::slotShowPreviewChanged()
     updateDecorationSize(view->showPreview());
 }
 
+void DolphinColumnView::slotDirListerCompleted()
+{
+    if (!m_childUrl.isEmpty()) {
+        return;
+    }
+
+    // Try to optimize the width of the column, so that no name gets clipped
+    const int requiredWidth = sizeHintForColumn(DolphinModel::Name);
+
+    const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
+    if (requiredWidth > settings->columnWidth()) {
+        int frameAroundContents = 0;
+        if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) {
+            // TODO: Using 2 PM_DefaultFrameWidths are not sufficient. Check Qt-code
+            // for other pixelmetrics that should be added...
+            frameAroundContents = style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 4;
+        }
+
+        const int scrollBarWidth = style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, verticalScrollBar());
+
+        setMaximumWidth(requiredWidth + frameAroundContents + scrollBarWidth);
+        m_container->layoutColumns();
+        if (m_active) {
+            m_container->assureVisibleActiveColumn();
+        }
+    }
+}
+
 void DolphinColumnView::activate()
 {
     setFocus(Qt::OtherFocusReason);
index 871610d81d9f5e90db6c6c582b1a7633367b4089..c3953e25363062da35bbafd1e0b4be5a6b8aebda 100644 (file)
@@ -114,6 +114,8 @@ private slots:
 
     void slotShowPreviewChanged();
 
+    void slotDirListerCompleted();
+
 private:
     /** Used by DolphinColumnView::setActive(). */
     void activate();
@@ -161,10 +163,7 @@ inline KUrl DolphinColumnView::childUrl() const
 
 inline void DolphinColumnView::setUrl(const KUrl& url)
 {
-    if (url != m_url) {
-        m_url = url;
-        //reload();
-    }
+    m_url = url;
 }
 
 inline KUrl DolphinColumnView::url() const
index c3cab6dedff5677b634dd33e15419f28354946de..7346532a16f4274e380ccdd0e4a0093eb0080005 100644 (file)
@@ -46,7 +46,8 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
     m_emptyViewport(0),
     m_animation(0),
     m_dragSource(0),
-    m_activeUrlTimer(0)
+    m_activeUrlTimer(0),
+    m_assureVisibleActiveColumnTimer(0)
 {
     Q_ASSERT(dolphinViewController != 0);
     Q_ASSERT(viewModeController != 0);
@@ -71,6 +72,15 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
     connect(m_activeUrlTimer, SIGNAL(timeout()),
             this, SLOT(updateActiveUrl()));
 
+    // Assuring that the active column gets fully visible is done with a small delay. This
+    // prevents that for temporary activations an animation gets started (e. g. when clicking
+    // on any folder of the parent column, the child column gets activated).
+    m_assureVisibleActiveColumnTimer = new QTimer(this);
+    m_assureVisibleActiveColumnTimer->setSingleShot(true);
+    m_assureVisibleActiveColumnTimer->setInterval(200);
+    connect(m_assureVisibleActiveColumnTimer, SIGNAL(timeout()),
+            this, SLOT(slotAssureVisibleActiveColumn()));
+
     DolphinColumnView* column = new DolphinColumnView(viewport(), this, viewModeController->url());
     m_columns.append(column);
     requestActivation(column);
@@ -244,6 +254,46 @@ void DolphinColumnViewContainer::updateActiveUrl()
     m_dolphinViewController->requestUrlChange(activeUrl);
 }
 
+void DolphinColumnViewContainer::slotAssureVisibleActiveColumn()
+{
+    const int viewportWidth = viewport()->width();
+    const int x = activeColumn()->x();
+
+    // When a column that is partly visible on the left side gets activated,
+    // it is useful to also assure that the previous column is partly visible.
+    // This allows the user to scroll to the first column without using the
+    // scrollbar and drag & drop operations to invisible columns.
+    const int previousColumnGap = 3 * style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, verticalScrollBar());
+
+    const int width = activeColumn()->maximumWidth();
+    if (x + width > viewportWidth) {
+        const int newContentX = m_contentX - x - width + viewportWidth;
+        if (isRightToLeft()) {
+            m_animation->setFrameRange(m_contentX, newContentX + previousColumnGap);
+        } else {
+            m_animation->setFrameRange(-m_contentX, -newContentX);
+        }
+        if (m_animation->state() != QTimeLine::Running) {
+           m_animation->start();
+        }
+    } else if (x < 0) {
+        const int newContentX = m_contentX - x;
+        if (isRightToLeft()) {
+            m_animation->setFrameRange(m_contentX, newContentX);
+        } else {
+            m_animation->setFrameRange(-m_contentX, -newContentX - previousColumnGap);
+        }
+        if (m_animation->state() != QTimeLine::Running) {
+           m_animation->start();
+        }
+    }
+}
+
+void DolphinColumnViewContainer::assureVisibleActiveColumn()
+{
+    m_assureVisibleActiveColumnTimer->start();
+}
+
 void DolphinColumnViewContainer::layoutColumns()
 {
     // Layout the position of the columns corresponding to their maximum width
@@ -281,38 +331,15 @@ void DolphinColumnViewContainer::layoutColumns()
         contentWidth += column->maximumWidth();
     }
 
-    horizontalScrollBar()->setPageStep(contentWidth);
-    horizontalScrollBar()->setRange(0, contentWidth - viewport()->width());
-}
+    if (horizontalScrollBar()->pageStep() != contentWidth) {
+        disconnect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
+                this, SLOT(moveContentHorizontally(int)));
 
-void DolphinColumnViewContainer::assureVisibleActiveColumn()
-{
-    const int viewportWidth = viewport()->width();
-    const int x = activeColumn()->x();
+        horizontalScrollBar()->setPageStep(contentWidth);
+        horizontalScrollBar()->setRange(0, contentWidth - viewport()->width());
 
-    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-    const int width = settings->columnWidth();
-
-    if (x + width > viewportWidth) {
-        const int newContentX = m_contentX - x - width + viewportWidth;
-        if (isRightToLeft()) {
-            m_animation->setFrameRange(m_contentX, newContentX);
-        } else {
-            m_animation->setFrameRange(-m_contentX, -newContentX);
-        }
-        if (m_animation->state() != QTimeLine::Running) {
-           m_animation->start();
-        }
-    } else if (x < 0) {
-        const int newContentX = m_contentX - x;
-        if (isRightToLeft()) {
-            m_animation->setFrameRange(m_contentX, newContentX);
-        } else {
-            m_animation->setFrameRange(-m_contentX, -newContentX);
-        }
-        if (m_animation->state() != QTimeLine::Running) {
-           m_animation->start();
-        }
+        connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
+                this, SLOT(moveContentHorizontally(int)));
     }
 }
 
@@ -325,9 +352,7 @@ void DolphinColumnViewContainer::requestActivation(DolphinColumnView* column)
         setFocusProxy(column);
     }
     
-    if (column->isActive()) {
-        assureVisibleActiveColumn();
-    } else {
+    if (!column->isActive()) {
         // Deactivate the currently active column
         if (m_index >= 0) {
             m_columns[m_index]->setActive(false);
@@ -349,9 +374,10 @@ void DolphinColumnViewContainer::requestActivation(DolphinColumnView* column)
         m_index = index;
         m_columns[m_index]->setActive(true);
 
-        assureVisibleActiveColumn();
         m_activeUrlTimer->start(); // calls slot updateActiveUrl()
     }
+
+    assureVisibleActiveColumn();
 }
 
 void DolphinColumnViewContainer::removeAllColumns()
@@ -367,12 +393,6 @@ void DolphinColumnViewContainer::removeAllColumns()
     assureVisibleActiveColumn();
 }
 
-QPoint DolphinColumnViewContainer::columnPosition(DolphinColumnView* column, const QPoint& point) const
-{
-    const QPoint topLeft = column->frameGeometry().topLeft();
-    return QPoint(point.x() - topLeft.x(), point.y() - topLeft.y());
-}
-
 void DolphinColumnViewContainer::deleteColumn(DolphinColumnView* column)
 {
     if (column == 0) {
index 4b4158cbcc49f1f676ed3484ff5dcede9d6e4fba..20ae81b38921d80321ff02194988bf3f698b68e5 100644 (file)
@@ -96,15 +96,24 @@ private slots:
      */
     void updateActiveUrl();
 
-private:
-    void layoutColumns();
-
     /**
+     * Invoked when m_assureVisibleActiveColumnTimer has been exceeded.
      * Assures that the currently active column is fully visible
      * by adjusting the horizontal position of the content.
      */
+    void slotAssureVisibleActiveColumn();
+
+private:
+    /**
+     * Assures that the currently active column is fully visible
+     * by adjusting the horizontal position of the content. The
+     * adjustment is done with a small delay (see
+     * slotAssureVisibleActiveColumn();
+     */
     void assureVisibleActiveColumn();
 
+    void layoutColumns();
+
     /**
      * Request the activation for the column \a column. It is assured
      * that the columns gets fully visible by adjusting the horizontal
@@ -115,12 +124,6 @@ private:
     /** Removes all columns except of the root column. */
     void removeAllColumns();
 
-    /**
-     * Returns the position of the point \a point relative to the column
-     * \a column.
-     */
-    QPoint columnPosition(DolphinColumnView* column, const QPoint& point) const;
-
     /**
      * Deletes the column. If the itemview of the controller is set to the column,
      * the controllers itemview is set to 0.
@@ -139,6 +142,7 @@ private:
     QAbstractItemView* m_dragSource;
 
     QTimer* m_activeUrlTimer;
+    QTimer* m_assureVisibleActiveColumnTimer;
 
     friend class DolphinColumnView;
 };