| 388 | } |
| 389 | |
| 390 | void PatchHighlighter::documentReloaded(KTextEditor::Document* doc) |
| 391 | { |
| 392 | qCDebug(PLUGIN_PATCHREVIEW) << "re-doing"; |
| 393 | //The document was loaded / reloaded |
| 394 | if ( !m_model->differences() ) |
| 395 | return; |
| 396 | |
| 397 | clear(); |
| 398 | |
| 399 | constexpr int markPixmapSize = 32; |
| 400 | KColorScheme scheme( QPalette::Active ); |
| 401 | |
| 402 | QImage tintedInsertion = QIcon::fromTheme(QStringLiteral("insert-text")).pixmap(markPixmapSize, markPixmapSize).toImage(); |
| 403 | KIconEffect::colorize( tintedInsertion, scheme.foreground( KColorScheme::NegativeText ).color(), 1.0 ); |
| 404 | QImage tintedRemoval = QIcon::fromTheme(QStringLiteral("edit-delete")).pixmap(markPixmapSize, markPixmapSize).toImage(); |
| 405 | KIconEffect::colorize( tintedRemoval, scheme.foreground( KColorScheme::NegativeText ).color(), 1.0 ); |
| 406 | QImage tintedChange = QIcon::fromTheme(QStringLiteral("text-field")).pixmap(markPixmapSize, markPixmapSize).toImage(); |
| 407 | KIconEffect::colorize( tintedChange, scheme.foreground( KColorScheme::NegativeText ).color(), 1.0 ); |
| 408 | |
| 409 | doc->setMarkDescription(MarkType::markType22, i18nc("@item", "Insertion")); |
| 410 | doc->setMarkIcon(MarkType::markType22, QPixmap::fromImage(tintedInsertion)); |
| 411 | doc->setMarkDescription(MarkType::markType23, i18nc("@item", "Removal")); |
| 412 | doc->setMarkIcon(MarkType::markType23, QPixmap::fromImage(tintedRemoval)); |
| 413 | doc->setMarkDescription(MarkType::markType24, i18nc("@item", "Change")); |
| 414 | doc->setMarkIcon(MarkType::markType24, QPixmap::fromImage(tintedChange)); |
| 415 | |
| 416 | doc->setMarkDescription(MarkType::markType25, i18nc("@item", "Insertion")); |
| 417 | doc->setMarkIcon(MarkType::markType25, QIcon::fromTheme(QStringLiteral("insert-text"))); |
| 418 | doc->setMarkDescription(MarkType::markType26, i18nc("@item", "Removal")); |
| 419 | doc->setMarkIcon(MarkType::markType26, QIcon::fromTheme(QStringLiteral("edit-delete"))); |
| 420 | doc->setMarkDescription(MarkType::markType27, i18nc("@item", "Change")); |
| 421 | doc->setMarkIcon(MarkType::markType27, QIcon::fromTheme(QStringLiteral("text-field"))); |
| 422 | |
| 423 | for (auto* const diff : std::as_const(*m_model->differences())) { |
| 424 | int line, lineCount; |
| 425 | KompareDiff2::DifferenceStringList lines; |
| 426 | |
| 427 | if( diff->applied() ) { |
| 428 | line = diff->destinationLineNumber(); |
| 429 | lineCount = diff->destinationLineCount(); |
| 430 | lines = diff->destinationLines(); |
| 431 | } else { |
| 432 | line = diff->sourceLineNumber(); |
| 433 | lineCount = diff->sourceLineCount(); |
| 434 | lines = diff->sourceLines(); |
| 435 | } |
| 436 | |
| 437 | if ( line > 0 ) |
| 438 | line -= 1; |
| 439 | |
| 440 | KTextEditor::Cursor c( line, 0 ); |
| 441 | KTextEditor::Cursor endC( line + lineCount, 0 ); |
| 442 | if ( doc->lines() <= c.line() ) |
| 443 | c.setLine( doc->lines() - 1 ); |
| 444 | if ( doc->lines() <= endC.line() ) |
| 445 | endC.setLine( doc->lines() ); |
| 446 | |
| 447 | if ( endC.isValid() && c.isValid() ) { |