| 73 | } |
| 74 | |
| 75 | void YACReaderFoldersViewItemDeletegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 76 | { |
| 77 | // Promote hover to selected so QIcon::Selected mode activates on mouse-over, |
| 78 | // matching the QSS which already uses the same background for hover and selected. |
| 79 | QStyleOptionViewItem opt = option; |
| 80 | if (opt.state & QStyle::State_MouseOver) |
| 81 | opt.state |= QStyle::State_Selected; |
| 82 | |
| 83 | // Get indicator colors from the theme via the owning view |
| 84 | QColor notCompletedColor(237, 197, 24); // Default fallback |
| 85 | QColor newItemDotColor(237, 197, 24); // Default fallback |
| 86 | if (auto foldersView = qobject_cast<YACReaderFoldersView *>(parent())) { |
| 87 | const auto &nt = foldersView->navigationTreeTheme(); |
| 88 | notCompletedColor = nt.folderNotCompletedColor; |
| 89 | newItemDotColor = nt.newItemColor; |
| 90 | } |
| 91 | |
| 92 | if (!index.data(FolderModel::CompletedRole).toBool()) { |
| 93 | painter->save(); |
| 94 | painter->setBrush(QBrush(notCompletedColor)); |
| 95 | painter->setPen(QPen(QBrush(), 0)); |
| 96 | painter->drawRect(0, opt.rect.y(), 2, opt.rect.height()); |
| 97 | painter->restore(); |
| 98 | } |
| 99 | |
| 100 | QStyledItemDelegate::paint(painter, opt, index); |
| 101 | |
| 102 | auto showRecent = index.data(FolderModel::ShowRecentRole).toBool(); |
| 103 | |
| 104 | if (showRecent) { |
| 105 | auto now = QDateTime::currentSecsSinceEpoch(); |
| 106 | auto added = index.data(FolderModel::AddedRole).toLongLong(); |
| 107 | auto updated = index.data(FolderModel::UpdatedRole).toLongLong(); |
| 108 | auto daysInSeconds = index.data(FolderModel::RecentRangeRole).toLongLong(); |
| 109 | |
| 110 | if (now - added < daysInSeconds || now - updated < daysInSeconds) { |
| 111 | painter->save(); |
| 112 | painter->setRenderHint(QPainter::Antialiasing); |
| 113 | painter->setBrush(QBrush(newItemDotColor)); |
| 114 | painter->setPen(QPen(QBrush(), 0)); |
| 115 | painter->drawEllipse(opt.rect.x() + 13, opt.rect.y() + 2, 7, 7); |
| 116 | painter->restore(); |
| 117 | } |
| 118 | } |
| 119 | } |