| 78 | } |
| 79 | |
| 80 | QSize ItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 81 | { |
| 82 | int height = kNotificationSpacing * 2; |
| 83 | QString message = index.data(Qt::DisplayRole).toString(); |
| 84 | QFontMetrics fm(option.font); |
| 85 | int fontLeading = fm.leading(); |
| 86 | // Layout the message |
| 87 | int textWidth = closeButtonRect(option.rect).left() |
| 88 | - view->iconSize().width() - kNotificationSpacing; |
| 89 | |
| 90 | message.replace(QLatin1Char('\n'), QChar::LineSeparator); |
| 91 | QTextLayout tl(message); |
| 92 | tl.beginLayout(); |
| 93 | while (true) { |
| 94 | QTextLine line = tl.createLine(); |
| 95 | if (!line.isValid()) |
| 96 | break; |
| 97 | line.setLineWidth(textWidth); |
| 98 | height += fontLeading; |
| 99 | line.setPosition(QPoint(0, height)); |
| 100 | height += static_cast<int>(line.height()); |
| 101 | } |
| 102 | tl.endLayout(); |
| 103 | |
| 104 | QString source = index.data(kSourceRole).toString(); |
| 105 | if (!source.isEmpty()) { |
| 106 | height += kNotificationSourceHeight + kNotificationSpacing; |
| 107 | } |
| 108 | |
| 109 | auto actList = index.data(kActionsRole).toStringList(); |
| 110 | if (!actList.isEmpty()) { |
| 111 | height += kNotificationActionHeight; |
| 112 | } |
| 113 | |
| 114 | return { option.rect.width(), height }; |
| 115 | } |
| 116 | |
| 117 | void ItemDelegate::drawBackground(QPainter *painter, const QStyleOptionViewItem &option) const |
| 118 | { |
no test coverage detected