MailJD nbsp;·nbsp; Test Dashboard nbsp;·nbsp; Coverage
LCOV - code coverage report
Current view: top level - ui - StarDelegate.cpp (source / functions) Coverage Total Hit
Test: MailJD Coverage (Unit + E2E) Lines: 97.1 % 34 33
Test Date: 2026-06-21 21:10:19 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 53.2 % 94 50

             Branch data     Line data    Source code
       1                 :             : #include "StarDelegate.h"
       2                 :             : 
       3                 :             : #include <QPainter>
       4                 :             : 
       5                 :             : #include "data/Models.h"
       6                 :             : #include "ui/MailListModel.h"
       7                 :             : #include "ui/ThemeManager.h"
       8                 :             : 
       9                 :          64 : StarDelegate::StarDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
      10                 :             : 
      11                 :        3986 : void StarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
      12                 :             :                           const QModelIndex &index) const {
      13         [ +  - ]:        3986 :   QStyleOptionViewItem opt = option;
      14         [ +  - ]:        3986 :   initStyleOption(&opt, index);
      15                 :             : 
      16         [ +  - ]:        3986 :   painter->save();
      17                 :             :   
      18                 :             :   // Design Phase: Consistent Selection/Hover
      19         [ +  - ]:        3986 :   auto &tm = ThemeManager::instance();
      20         [ +  + ]:        3986 :   if (opt.state & QStyle::State_Selected) {
      21   [ +  -  +  -  :         155 :     painter->fillRect(opt.rect, QColor(tm.color("@bg_selected")));
                   +  - ]
      22         [ -  + ]:        3831 :   } else if (opt.state & QStyle::State_MouseOver) {
      23   [ #  #  #  #  :           0 :     painter->fillRect(opt.rect, QColor(tm.color("@bg_hover")));
                   #  # ]
      24                 :             :   }
      25                 :             : 
      26                 :             :   // Sprint 70: row separator removed — selection/hover backgrounds
      27                 :             :   // carry the separation alone (see SPRINT-70.md T-70.1).
      28                 :             : 
      29                 :             :   // Determine state
      30   [ +  -  +  - ]:        3986 :   quint32 flags = index.data(MailListModel::FlagsRole).toUInt();
      31                 :        3986 :   bool flagged = (flags & MailFlag::Flagged);
      32                 :        3986 :   bool unseen = !(flags & MailFlag::Seen);
      33                 :             : 
      34                 :             :   // 2. Star font + geometry
      35         [ +  - ]:        3986 :   QFont font = opt.font;
      36         [ +  - ]:        3986 :   font.setPointSize(11);
      37         [ +  - ]:        3986 :   painter->setFont(font);
      38                 :             : 
      39   [ +  -  +  -  :        4000 :   QColor starColor = flagged ? QColor(tm.color("@star_active"))
          +  +  -  -  -  
                      - ]
      40   [ +  +  +  -  :        4000 :                              : QColor(tm.color("@star_inactive"));
          +  -  +  +  +  
          +  +  +  -  -  
                   -  - ]
      41         [ +  - ]:        3986 :   painter->setPen(starColor);
      42                 :             : 
      43   [ +  +  +  +  :        7972 :   QString star = flagged ? QStringLiteral("\u2605") : QStringLiteral("\u2606");
                   +  + ]
      44                 :             : 
      45                 :             :   // Sprint 64: Always use the same horizontal offset to keep stars aligned
      46                 :             :   // regardless of whether the unread dot is shown.
      47                 :        3986 :   QRect starRect = opt.rect.adjusted(12, 0, 0, 0);
      48                 :             : 
      49                 :             :   // 1. Draw Unread Dot — rendered as a text glyph (●) with AlignCenter to
      50                 :             :   // guarantee the same vertical position as the star below. A smaller font
      51                 :             :   // keeps the dot compact (~7px) without clipping.
      52         [ +  + ]:        3986 :   if (unseen) {
      53         [ +  - ]:        1750 :     QFont dotFont = font;
      54   [ +  -  +  - ]:        1750 :     dotFont.setPointSize(qMax(6, font.pointSize() - 4));
      55         [ +  - ]:        1750 :     painter->setFont(dotFont);
      56   [ +  -  +  -  :        1750 :     painter->setPen(QColor(tm.color("@unread_dot")));
                   +  - ]
      57                 :        1750 :     QRect dotRect(opt.rect.left(), opt.rect.top(), 10, opt.rect.height());
      58         [ +  - ]:        3500 :     painter->drawText(dotRect, Qt::AlignCenter, QStringLiteral("\u25CF"));
      59         [ +  - ]:        1750 :     painter->setFont(font);
      60                 :        1750 :   }
      61                 :             : 
      62                 :             :   // 2. Draw Star (re-apply pen — the dot above changed it)
      63         [ +  - ]:        3986 :   painter->setPen(starColor);
      64         [ +  - ]:        3986 :   painter->drawText(starRect, Qt::AlignCenter, star);
      65                 :             : 
      66         [ +  - ]:        3986 :   painter->restore();
      67                 :        3986 : }
        

Generated by: LCOV version 2.0-1