| 33 | TaskDelegate::~TaskDelegate() = default; |
| 34 | |
| 35 | QSize 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 | |
| 81 | bool TaskDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) |
| 82 | { |
nothing calls this directly
no test coverage detected