| 173 | } |
| 174 | |
| 175 | void TaskDelegate::paintItemColumn(QPainter *painter, const QStyleOptionViewItem &option, |
| 176 | const QModelIndex &index, const QRect &iconRect) const |
| 177 | { |
| 178 | auto btnRect = paintFixButton(painter, option, index); |
| 179 | bool isSelected = (option.state & QStyle::State_Selected) && option.showDecorationSelected; |
| 180 | |
| 181 | painter->save(); |
| 182 | if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::ColorType::DarkType) { |
| 183 | painter->setPen(QColor(255, 255, 255, 180)); |
| 184 | } else { |
| 185 | painter->setPen(QColor(0, 0, 0, 180)); |
| 186 | } |
| 187 | |
| 188 | QRect textRect = option.rect; |
| 189 | textRect.setLeft(iconRect.right() + kItemMargin); |
| 190 | textRect.setRight(btnRect.left() - kItemMargin); |
| 191 | |
| 192 | QString description = index.data(TaskModel::Description).toString(); |
| 193 | if (!isSelected) { |
| 194 | description = option.fontMetrics.elidedText(description, Qt::ElideRight, textRect.width()); |
| 195 | painter->drawText(textRect, Qt::AlignLeft, description); |
| 196 | } else { |
| 197 | QFontMetrics fm(option.font); |
| 198 | description.replace(QLatin1Char('\n'), QChar::LineSeparator); |
| 199 | painter->setPen(QColor(Qt::white)); |
| 200 | int height = 0; |
| 201 | int leading = fm.leading(); |
| 202 | QTextLayout tl(description); |
| 203 | tl.beginLayout(); |
| 204 | while (true) { |
| 205 | QTextLine line = tl.createLine(); |
| 206 | if (!line.isValid()) |
| 207 | break; |
| 208 | line.setLineWidth(textRect.width()); |
| 209 | height += leading; |
| 210 | line.setPosition(QPoint(0, height)); |
| 211 | height += static_cast<int>(line.height()); |
| 212 | } |
| 213 | tl.endLayout(); |
| 214 | |
| 215 | tl.draw(painter, textRect.topLeft()); |
| 216 | } |
| 217 | |
| 218 | QString directory = QDir::toNativeSeparators(index.data(TaskModel::File).toString()); |
| 219 | if (isSelected) { |
| 220 | painter->setPen(QColor(Qt::white)); |
| 221 | if (index.data(TaskModel::FileNotFound).toBool() && !directory.isEmpty()) { |
| 222 | QString fileNotFound = tr("File not found: %1").arg(directory); |
| 223 | fileNotFound = option.fontMetrics.elidedText(fileNotFound, Qt::ElideRight, textRect.width()); |
| 224 | painter->setPen(Qt::red); |
| 225 | painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, fileNotFound); |
| 226 | } else { |
| 227 | directory = option.fontMetrics.elidedText(directory, Qt::ElideRight, textRect.width()); |
| 228 | painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, directory); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | painter->restore(); |
nothing calls this directly
no test coverage detected