[kde-doc-english] [trojita] src/Gui: GUI: use reasonable section size hints and remember the user's actual values
Jan Kundrát
jkt at flaska.net
Fri May 31 12:17:51 UTC 2013
Git commit 62e8eaa5deb0988ad1e402c5e7ab72829aba91ee by Jan Kundrát.
Committed on 29/05/2013 at 03:19.
Pushed by jkt into branch 'master'.
GUI: use reasonable section size hints and remember the user's actual values
The problems which make this non-straightforward:
- the interaction with MsgListView::slotFixSize was funny
- once the size of a section is set to 0, it cannot be resized by user
Reported by Len Nordstrom <mournblade at gmx.us> (len on IRC).
REVIEW: 110704
M +4 -3 src/Gui/MsgListView.cpp
M +1 -1 src/Gui/MsgListView.h
M +18 -0 src/Gui/Window.cpp
http://commits.kde.org/trojita/62e8eaa5deb0988ad1e402c5e7ab72829aba91ee
diff --git a/src/Gui/MsgListView.cpp b/src/Gui/MsgListView.cpp
index 31b87fd..9beaeca 100644
--- a/src/Gui/MsgListView.cpp
+++ b/src/Gui/MsgListView.cpp
@@ -225,6 +225,9 @@ void MsgListView::startDrag(Qt::DropActions supportedActions)
void MsgListView::slotFixSize()
{
+ if (!m_autoResizeSections)
+ return;
+
if (header()->visualIndex(Imap::Mailbox::MsgListModel::SEEN) == -1) {
// calling setResizeMode() would assert()
return;
@@ -246,9 +249,7 @@ void MsgListView::slotFixSize()
#else
header()->setResizeMode(i, resizeMode);
#endif
- if (m_autoResizeSections) {
- setColumnWidth(i, sizeHintForColumn(i));
- }
+ setColumnWidth(i, sizeHintForColumn(i));
}
}
diff --git a/src/Gui/MsgListView.h b/src/Gui/MsgListView.h
index 465bab8..b2d9a6c 100644
--- a/src/Gui/MsgListView.h
+++ b/src/Gui/MsgListView.h
@@ -50,10 +50,10 @@ public:
void setModel(QAbstractItemModel *model);
void setAutoActivateAfterKeyNavigation(bool enabled);
void updateActionsAfterRestoredState();
+ virtual int sizeHintForColumn(int column) const;
protected:
void keyPressEvent(QKeyEvent *ke);
void keyReleaseEvent(QKeyEvent *ke);
- virtual int sizeHintForColumn(int column) const;
virtual void startDrag(Qt::DropActions supportedActions);
private slots:
void slotFixSize();
diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp
index dea8a3f..805696f 100644
--- a/src/Gui/Window.cpp
+++ b/src/Gui/Window.cpp
@@ -2247,6 +2247,10 @@ void MainWindow::saveSizesAndState(const LayoutMode oldMode)
items << (m_mainVSplitter ? m_mainVSplitter->saveState() : QByteArray());
items << (m_mainHSplitter ? m_mainHSplitter->saveState() : QByteArray());
items << msgListWidget->tree->header()->saveState();
+ items << QByteArray::number(msgListWidget->tree->header()->count());
+ for (int i = 0; i < msgListWidget->tree->header()->count(); ++i) {
+ items << QByteArray::number(msgListWidget->tree->header()->sectionSize(i));
+ }
QByteArray buf;
QDataStream stream(&buf, QIODevice::WriteOnly);
stream << items.size();
@@ -2305,6 +2309,20 @@ void MainWindow::applySizesAndState()
// got to manually update the state of the actions which control the visibility state
msgListWidget->tree->updateActionsAfterRestoredState();
}
+
+ if (size-- && !stream.atEnd()) {
+ stream >> item;
+ bool ok;
+ int columns = item.toInt(&ok);
+ if (ok) {
+ 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));
+ }
+ }
+ }
}
void MainWindow::resizeEvent(QResizeEvent *)
More information about the kde-doc-english
mailing list