diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-03 15:41:16 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-04 12:53:28 +0200 |
| commit | 0dacb5c4c61818088efb5bf513f15d2b715491e3 (patch) | |
| tree | 2f9994867f07b62d80e01a8256d3ee2acb5d62a9 /src/tagchip.h | |
| parent | 702568b65a9e8322b646ce7ae03303f85076d47c (diff) | |
| download | qtmaildir-0dacb5c4c61818088efb5bf513f15d2b715491e3.tar.gz qtmaildir-0dacb5c4c61818088efb5bf513f15d2b715491e3.zip | |
feat: render tags as chips instead of a text column
Spelled out per row, tags ran to 500 pixels of largely repeated text and
took most of the thread list's width. The column is gone; tags render as
coloured chips split by what they actually mean.
An account tag says which mailbox a thread arrived in, and draws as a
chip in front of the subject. A functional tag says what state a thread
is in, and those fill one row under the message pane. One row keeps the
message area from shifting between threads with different tag counts, so
whatever does not fit collapses into a +N chip that names the rest in its
tooltip.
TagColors resolves a colour by exact tag first, then by top-level prefix,
so a single "shopping" entry covers shopping/amazon and shopping/nike
while shopping/amazon can still override its own. That matters at 96
tags. Built-in defaults cover the usual state tags, and anything left
unconfigured falls back to a hash of the name, stable so a chip does not
change colour as the list scrolls.
Diffstat (limited to 'src/tagchip.h')
| -rw-r--r-- | src/tagchip.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/tagchip.h b/src/tagchip.h new file mode 100644 index 0000000..9bd4e78 --- /dev/null +++ b/src/tagchip.h @@ -0,0 +1,62 @@ +/* + * qtmaildir - a Qt6 mail client for notmuch-indexed Maildirs + * Copyright (C) 2026 Danilo M. <danix@danix.xyz> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include <QColor> +#include <QRect> +#include <QSize> +#include <QString> +#include <QStyledItemDelegate> + +class QPainter; +class QFontMetrics; + +/// Draws one rounded, filled tag chip. Shared so the account chip in the +/// thread list and the strip under the message pane cannot drift apart. +namespace TagChip { + +/// Padding inside a chip and the gap between two of them. +constexpr int kPaddingX = 6; +constexpr int kPaddingY = 1; +constexpr int kSpacing = 4; +constexpr int kRadius = 3; + +QSize sizeFor(const QFontMetrics &metrics, const QString &text); + +/// Paints the chip into `rect`, using `text` and `background`. The text colour +/// is derived from the fill so it stays legible. +void paint(QPainter *painter, const QRect &rect, const QString &text, + const QColor &background); + +} // namespace TagChip + +/// Item delegate for the subject column: draws the account chip in front of +/// the subject text, so which mailbox a thread came from reads at a glance +/// without a tags column spelling it out. +class SubjectDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + using QStyledItemDelegate::QStyledItemDelegate; + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +}; |
