[kde-doc-english] [trojita] src/Gui: GUI: respect the ResizeMode when restoring the user's preference

Jan Kundrát jkt at flaska.net
Thu Jun 20 12:28:48 UTC 2013


Git commit 483d9967a9125404841c01b30e2246edfbeca79c by Jan Kundrát.
Committed on 17/06/2013 at 16:57.
Pushed by jkt into branch 'master'.

GUI: respect the ResizeMode when restoring the user's preference

Turns out that restoring sizes of sections which are not supposed to be
resizeable by user makes hte sizes very, very messy and makes the QHeaderView
forge the desired resizing mode as well.

REVIEW: 111076

M  +14   -10   src/Gui/MsgListView.cpp
M  +2    -0    src/Gui/MsgListView.h
M  +13   -2    src/Gui/Window.cpp

http://commits.kde.org/trojita/483d9967a9125404841c01b30e2246edfbeca79c

diff --git a/src/Gui/MsgListView.cpp b/src/Gui/MsgListView.cpp
index 9beaeca..074e311 100644
--- a/src/Gui/MsgListView.cpp
+++ b/src/Gui/MsgListView.cpp
@@ -232,18 +232,10 @@ void MsgListView::slotFixSize()
         // calling setResizeMode() would assert()
         return;
     }
-    header()->setStretchLastSection(false);
 
+    header()->setStretchLastSection(false);
     for (int i = 0; i < Imap::Mailbox::MsgListModel::COLUMN_COUNT; ++i) {
-        QHeaderView::ResizeMode resizeMode = QHeaderView::Interactive;
-        switch (i) {
-        case Imap::Mailbox::MsgListModel::SUBJECT:
-            resizeMode = QHeaderView::Stretch;
-            break;
-        case Imap::Mailbox::MsgListModel::SEEN:
-            resizeMode = QHeaderView::Fixed;
-            break;
-        }
+        QHeaderView::ResizeMode resizeMode = resizeModeForColumn(i);
 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
         header()->setSectionResizeMode(i, resizeMode);
 #else
@@ -253,6 +245,18 @@ void MsgListView::slotFixSize()
     }
 }
 
+QHeaderView::ResizeMode MsgListView::resizeModeForColumn(const int column) const
+{
+    switch (column) {
+    case Imap::Mailbox::MsgListModel::SUBJECT:
+        return QHeaderView::Stretch;
+    case Imap::Mailbox::MsgListModel::SEEN:
+        return QHeaderView::Fixed;
+    default:
+        return QHeaderView::Interactive;
+    }
+}
+
 void MsgListView::slotExpandWholeSubtree(const QModelIndex &rootIndex)
 {
     if (rootIndex.parent().isValid())
diff --git a/src/Gui/MsgListView.h b/src/Gui/MsgListView.h
index b2d9a6c..b875374 100644
--- a/src/Gui/MsgListView.h
+++ b/src/Gui/MsgListView.h
@@ -22,6 +22,7 @@
 #ifndef MSGLISTVIEW_H
 #define MSGLISTVIEW_H
 
+#include <QHeaderView>
 #include <QTreeView>
 
 class QSignalMapper;
@@ -51,6 +52,7 @@ public:
     void setAutoActivateAfterKeyNavigation(bool enabled);
     void updateActionsAfterRestoredState();
     virtual int sizeHintForColumn(int column) const;
+    QHeaderView::ResizeMode resizeModeForColumn(const int column) const;
 protected:
     void keyPressEvent(QKeyEvent *ke);
     void keyReleaseEvent(QKeyEvent *ke);
diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp
index bb42d61..009c0d4 100644
--- a/src/Gui/Window.cpp
+++ b/src/Gui/Window.cpp
@@ -2299,11 +2299,22 @@ void MainWindow::applySizesAndState()
         bool ok;
         int columns = item.toInt(&ok);
         if (ok) {
+            msgListWidget->tree->header()->setStretchLastSection(false);
             for (int i = 0; i < columns && size-- && !stream.atEnd(); ++i) {
                 stream >> item;
                 int sectionSize = item.toInt();
-                // fun fact: user cannot resize by mouse when size <= 0
-                msgListWidget->tree->setColumnWidth(i, sectionSize > 0 ? sectionSize : msgListWidget->tree->sizeHintForColumn(i));
+                QHeaderView::ResizeMode resizeMode = msgListWidget->tree->resizeModeForColumn(i);
+                if (sectionSize > 0 && resizeMode == QHeaderView::Interactive) {
+                    // fun fact: user cannot resize by mouse when size <= 0
+                    msgListWidget->tree->setColumnWidth(i, sectionSize);
+                } else {
+                    msgListWidget->tree->setColumnWidth(i, msgListWidget->tree->sizeHintForColumn(i));
+                }
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+                msgListWidget->tree->header()->setSectionResizeMode(i, resizeMode);
+#else
+                msgListWidget->tree->header()->setResizeMode(i, resizeMode);
+#endif
             }
         }
     }



More information about the kde-doc-english mailing list