| 688 | } |
| 689 | |
| 690 | QSize TaskDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 691 | { |
| 692 | QStyleOptionViewItem opt = option; |
| 693 | initStyleOption(&opt, index); |
| 694 | |
| 695 | const QAbstractItemView * view = qobject_cast<const QAbstractItemView *>(opt.widget); |
| 696 | const bool selected = (view->selectionModel()->currentIndex() == index); |
| 697 | QSize s; |
| 698 | s.setWidth(option.rect.width()); |
| 699 | |
| 700 | if (!selected && option.font == m_cachedFont && m_cachedHeight > 0) { |
| 701 | s.setHeight(m_cachedHeight); |
| 702 | return s; |
| 703 | } |
| 704 | |
| 705 | QFontMetrics fm(option.font); |
| 706 | int fontHeight = fm.height(); |
| 707 | int fontLeading = fm.leading(); |
| 708 | |
| 709 | TaskModel *model = static_cast<TaskFilterModel *>(view->model())->taskModel(); |
| 710 | Positions positions(option, model); |
| 711 | |
| 712 | if (selected) { |
| 713 | QString description = index.data(TaskModel::Description).toString(); |
| 714 | description += QLatin1Char('\n'); |
| 715 | description += index.data(TaskModel::ExtraInfo).toString(); |
| 716 | // Layout the description |
| 717 | int leading = fontLeading; |
| 718 | int height = 0; |
| 719 | description.replace(QLatin1Char('\n'), QChar::LineSeparator); |
| 720 | QTextLayout tl(description); |
| 721 | // TODO: tl.setAdditionalFormats(...); |
| 722 | tl.beginLayout(); |
| 723 | while (true) { |
| 724 | QTextLine line = tl.createLine(); |
| 725 | if (!line.isValid()) |
| 726 | break; |
| 727 | line.setLineWidth(positions.textAreaWidth()); |
| 728 | height += leading; |
| 729 | line.setPosition(QPoint(0, height)); |
| 730 | height += static_cast<int>(line.height()); |
| 731 | } |
| 732 | tl.endLayout(); |
| 733 | |
| 734 | s.setHeight(height + leading + fontHeight + 3); |
| 735 | } else { |
| 736 | s.setHeight(fontHeight + 3); |
| 737 | } |
| 738 | if (s.height() < positions.minimumHeight()) |
| 739 | s.setHeight(positions.minimumHeight()); |
| 740 | |
| 741 | if (!selected) { |
| 742 | m_cachedHeight = s.height(); |
| 743 | m_cachedFont = option.font; |
| 744 | } |
| 745 | |
| 746 | return s; |
| 747 | } |
nothing calls this directly
no test coverage detected