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

Method sizeHint

src/plugins/builder/tasks/taskdelegate.cpp:35–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33TaskDelegate::~TaskDelegate() = default;
34
35QSize TaskDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
36{
37 QStyleOptionViewItem opt = option;
38 initStyleOption(&opt, index);
39 opt.rect.adjust(8, 0, -8, 0);
40
41 auto view = qobject_cast<const QAbstractItemView *>(opt.widget);
42 const bool selected = (view->selectionModel()->currentIndex() == index);
43 QSize s;
44 s.setWidth(opt.rect.width());
45
46 if (selected) {
47 QFontMetrics fm(option.font);
48 int fontHeight = fm.height();
49 int fontLeading = fm.leading();
50 QString description = index.data(TaskModel::Description).toString();
51 // Layout the description
52 int leading = fontLeading;
53 int height = 0;
54 int textWidth = fixButtonRect(opt.rect).left()
55 - iconRect(opt.rect).right()
56 - 2 * kItemMargin + 1;
57
58 description.replace(QLatin1Char('\n'), QChar::LineSeparator);
59 QTextLayout tl(description);
60 tl.beginLayout();
61 while (true) {
62 QTextLine line = tl.createLine();
63 if (!line.isValid())
64 break;
65 line.setLineWidth(textWidth);
66 height += leading;
67 line.setPosition(QPoint(0, height));
68 height += static_cast<int>(line.height());
69 }
70 tl.endLayout();
71
72 s.setHeight(height + leading + fontHeight + 3);
73 }
74
75 if (s.height() < kItemMinHeight)
76 s.setHeight(kItemMinHeight);
77
78 return s;
79}
80
81bool TaskDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
82{

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected