MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / sizeHint

Method sizeHint

src/plugins/core/notify/gui/itemdelegate.cpp:80–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80QSize 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
117void ItemDelegate::drawBackground(QPainter *painter, const QStyleOptionViewItem &option) const
118{

Callers 1

eventFilterMethod · 0.45

Calls 9

leftMethod · 0.80
widthMethod · 0.80
setPositionMethod · 0.80
QPointClass · 0.50
toStringMethod · 0.45
dataMethod · 0.45
replaceMethod · 0.45
isValidMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected