aboutsummaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-03 17:17:25 +0200
committerDanilo M. <danix@danix.xyz>2026-08-04 12:53:44 +0200
commit055132af18cc0a4f66e01eb77a94941cb66c0020 (patch)
treec1ae898e2c946cc120b0dde5b52488e18b6b0d23 /src/mainwindow.cpp
parent420cbbb8a5de9d3a4a99a35059395d4be3843f4f (diff)
downloadqtmaildir-055132af18cc0a4f66e01eb77a94941cb66c0020.tar.gz
qtmaildir-055132af18cc0a4f66e01eb77a94941cb66c0020.zip
feat: show a paperclip for threads with attachments
An attachment was only discoverable by opening the thread. A narrow leftmost column now marks the threads that carry one. No new worker query is involved: notmuch applies the "attachment" tag while indexing, so ThreadSummary already holds what this needs. The marker is a glyph rather than an icon resource, which ships no new asset and inherits the row font, so it strikes through with a doomed thread like every other cell. It falls back to "*" where the system font cannot draw U+1F4CE, since an unrenderable codepoint reads as breakage rather than as a marker. Two silent Qt behaviours had to be handled, both found by probe: QHeaderView::restoreState() returns true for a blob saved against fewer columns and applies the old widths shifted one place right. Adding a column in front would therefore have mangled every existing saved layout with no error to detect it by. The column count is now stored beside the blob and a mismatch discards it, so the widths reset once on upgrade instead of landing on the wrong columns. QHeaderView's default minimumSectionSize is 58px on this platform, and setColumnWidth() clamps to it without reporting the smaller value back, so the column could not be narrow at all until it was lowered. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 2a79988..1385f01 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -100,9 +100,18 @@ void MainWindow::restoreUiState()
m_splitter->restoreState(splitter);
}
+ // A header blob saved against a different set of columns must be
+ // discarded, not restored. QHeaderView::restoreState() returns TRUE for a
+ // blob with fewer sections than the model and applies the old widths to
+ // the wrong columns: adding the attachment column in front shifted every
+ // saved width one place right, silently mangling the layout with no error
+ // to detect it by (verified on Qt 6.11). The column count is stored
+ // alongside and the blob is only used when it still matches.
const QByteArray header = state.value(QStringLiteral("threadlist/header"))
.toByteArray();
- if (!header.isEmpty()) {
+ const int savedColumns =
+ state.value(QStringLiteral("threadlist/columns")).toInt();
+ if (!header.isEmpty() && savedColumns == ThreadListModel::ColumnCount) {
m_threadView->horizontalHeader()->restoreState(header);
}
@@ -123,6 +132,9 @@ void MainWindow::saveUiState() const
state.setValue(QStringLiteral("window/splitter"), m_splitter->saveState());
state.setValue(QStringLiteral("threadlist/header"),
m_threadView->horizontalHeader()->saveState());
+ // Guards the blob above: see restoreUiState().
+ state.setValue(QStringLiteral("threadlist/columns"),
+ int(ThreadListModel::ColumnCount));
state.setValue(QStringLiteral("message/zoom"), m_messageView->zoomFactor());
}
@@ -275,6 +287,11 @@ void MainWindow::buildUi()
// Starting widths only; a drag overrides them, and they are what the
// saved-widths item will persist.
+ // Without this the attachment column cannot be narrow at all: the default
+ // minimum section size is 58px on this platform, and setColumnWidth()
+ // clamps to it silently rather than reporting the smaller value back.
+ m_threadView->horizontalHeader()->setMinimumSectionSize(24);
+ m_threadView->setColumnWidth(ThreadListModel::AttachmentColumn, 28);
m_threadView->setColumnWidth(ThreadListModel::DateColumn, 130);
m_threadView->setColumnWidth(ThreadListModel::AuthorsColumn, 180);
m_threadView->setColumnWidth(ThreadListModel::SubjectColumn, 520);