| 758 | } |
| 759 | |
| 760 | void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 761 | { |
| 762 | QStyleOptionViewItem opt = option; |
| 763 | initStyleOption(&opt, index); |
| 764 | painter->save(); |
| 765 | |
| 766 | QFontMetrics fm(opt.font); |
| 767 | QColor backgroundColor; |
| 768 | QColor textColor; |
| 769 | |
| 770 | const QAbstractItemView * view = qobject_cast<const QAbstractItemView *>(opt.widget); |
| 771 | bool selected = view->selectionModel()->currentIndex() == index; |
| 772 | |
| 773 | if (selected) { |
| 774 | painter->setBrush(opt.palette.highlight().color()); |
| 775 | backgroundColor = opt.palette.highlight().color(); |
| 776 | } else { |
| 777 | painter->setBrush(opt.palette.window().color()); |
| 778 | backgroundColor = opt.palette.window().color(); |
| 779 | } |
| 780 | painter->setPen(Qt::NoPen); |
| 781 | painter->drawRect(opt.rect); |
| 782 | |
| 783 | // Set Text Color |
| 784 | if (selected) |
| 785 | textColor = opt.palette.highlightedText().color(); |
| 786 | else |
| 787 | textColor = opt.palette.text().color(); |
| 788 | |
| 789 | painter->setPen(textColor); |
| 790 | |
| 791 | TaskModel *model = static_cast<TaskFilterModel *>(view->model())->taskModel(); |
| 792 | Positions positions(opt, model); |
| 793 | |
| 794 | // Paint TaskIconArea: |
| 795 | QIcon icon = index.data(TaskModel::Icon).value<QIcon>(); |
| 796 | painter->drawPixmap(positions.left(), positions.top(), |
| 797 | icon.pixmap(positions.taskIconWidth(), positions.taskIconHeight())); |
| 798 | |
| 799 | // Paint TextArea: |
| 800 | if (!selected) { |
| 801 | // in small mode we lay out differently |
| 802 | QString bottom = index.data(TaskModel::Description).toString(); |
| 803 | painter->setClipRect(positions.textArea()); |
| 804 | painter->drawText(positions.textAreaLeft(), positions.top() + fm.ascent(), bottom); |
| 805 | if (fm.horizontalAdvance(bottom) > positions.textAreaWidth()) { |
| 806 | // draw a gradient to mask the text |
| 807 | int gradientStart = positions.textAreaRight() - ELLIPSIS_GRADIENT_WIDTH + 1; |
| 808 | QLinearGradient lg(gradientStart, 0, gradientStart + ELLIPSIS_GRADIENT_WIDTH, 0); |
| 809 | lg.setColorAt(0, Qt::transparent); |
| 810 | lg.setColorAt(1, backgroundColor); |
| 811 | painter->fillRect(gradientStart, positions.top(), ELLIPSIS_GRADIENT_WIDTH, positions.firstLineHeight(), lg); |
| 812 | } |
| 813 | } else { |
| 814 | // Description |
| 815 | QString description = index.data(TaskModel::Description).toString(); |
| 816 | description += QLatin1Char('\n'); |
| 817 | description += index.data(TaskModel::ExtraInfo).toString(); |
nothing calls this directly
no test coverage detected