[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Patch for KDirOperator: make columns in detailled view resizable
From:       Anders Lund <anders () alweb ! dk>
Date:       2007-10-03 18:12:22
Message-ID: 200710032012.23047.anders () alweb ! dk
[Download RAW message or body]

Hi, 

I will strongly suggest the attached patch to KDirOperator. It removes the 
hokus pokus in the resizeevent of the DirOperatorDetailledView class and 
makes the columns user adjustable instead.

In Kates sidebar, the current unadjustable columns are unusable, it is simply 
impossible to see the file names when the name column is fixed at 120px. This 
may also happen in the file dialogs for long file names.

So even the initial looks after applying the patch isn't as nice as before, it 
is much more usable. Please support this change!

-- 
Anders

www: http://www.alweb.dk
jabber: anderslund@jabber.dk

["kdiroperator.patch" (text/x-diff)]

Index: kdiroperator.cpp
===================================================================
--- kdiroperator.cpp	(revision 720068)
+++ kdiroperator.cpp	(working copy)
@@ -149,6 +149,9 @@ public:
 protected:
     virtual bool event(QEvent *event);
     virtual void resizeEvent(QResizeEvent* event);
+
+private:
+    bool resizedColumns;
 };
 
 DirOperatorDetailView::DirOperatorDetailView(QWidget *parent) :
@@ -158,6 +161,8 @@ DirOperatorDetailView::DirOperatorDetail
     setSortingEnabled(true);
     setUniformRowHeights(true);
     setSelectionBehavior(QAbstractItemView::SelectRows);
+    header()->setResizeMode(QHeaderView::Interactive);
+    resizedColumns = false;
 }
 
 DirOperatorDetailView::~DirOperatorDetailView()
@@ -167,13 +172,8 @@ DirOperatorDetailView::~DirOperatorDetai
 bool DirOperatorDetailView::event(QEvent *event)
 {
     if (event->type() == QEvent::Polish) {
-        // Assure that by respecting the available width that:
-        // - the 'Name' column is stretched as large as possible
-        // - the remaining columns are as small as possible
         QHeaderView *headerView = header();
-        headerView->setStretchLastSection(false);
-        headerView->setResizeMode(QHeaderView::ResizeToContents);
-        headerView->setResizeMode(0, QHeaderView::Stretch);
+        headerView->resizeSections( QHeaderView::ResizeToContents );
 
         // hide columns
         hideColumn(KDirModel::Permissions);
@@ -188,32 +188,10 @@ void DirOperatorDetailView::resizeEvent(
 {
     QTreeView::resizeEvent(event);
 
-    // assure that the width of the name-column does not get too small
-    const int minWidth = 120;
-    QHeaderView* headerView = header();
-    bool useFixedWidth = (headerView->sectionSize(KDirModel::Name) <= minWidth)
-                          && (headerView->resizeMode(0) != QHeaderView::Fixed);
-    if (useFixedWidth) {
-        // the current width of the name-column is too small, hence
-        // use a fixed size
-        headerView->setResizeMode(QHeaderView::Fixed);
-        headerView->setResizeMode(0, QHeaderView::Fixed);
-        headerView->resizeSection(KDirModel::Name, minWidth);
-    } else if (headerView->resizeMode(0) != QHeaderView::Stretch) {
-        // check whether there is enough available viewport width
-        // to automatically resize the columns
-        const int availableWidth = viewport()->width();
-
-        int headerWidth = 0;
-        const int count = headerView->count();
-        for (int i = 0; i < count; ++i) {
-            headerWidth += headerView->sectionSize(i);
-        }
-
-        if (headerWidth < availableWidth) {
-            headerView->setResizeMode(QHeaderView::ResizeToContents);
-            headerView->setResizeMode(0, QHeaderView::Stretch);
-        }
+    if ( ! resizedColumns ) { // we do this only ONCE, otherwise we disturb the \
user. +        QHeaderView *headerView = header();
+        headerView->resizeSections( QHeaderView::ResizeToContents );
+        resizedColumns = model()->rowCount() > 0; // ### hacky, assume we have rows \
enough for a decent sizing.  }
 }
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic