| 342 | } |
| 343 | |
| 344 | void RefactorWidget::dimContextLines(const QString &contextBefore, const QString &contextAfter) |
| 345 | { |
| 346 | QTextCharFormat dimFormat; |
| 347 | dimFormat.setForeground(Utils::creatorColor(Utils::Theme::TextColorDisabled)); |
| 348 | |
| 349 | auto dimLines = [&](QTextDocument *doc, int lineCount, bool fromStart) { |
| 350 | QTextCursor cursor(doc); |
| 351 | if (!fromStart) { |
| 352 | cursor.movePosition(QTextCursor::End); |
| 353 | } |
| 354 | |
| 355 | for (int i = 0; i < lineCount; ++i) { |
| 356 | cursor.movePosition(QTextCursor::StartOfBlock); |
| 357 | cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); |
| 358 | cursor.setCharFormat(dimFormat); |
| 359 | |
| 360 | if (fromStart) { |
| 361 | if (!cursor.block().isValid() || !cursor.movePosition(QTextCursor::NextBlock)) { |
| 362 | break; |
| 363 | } |
| 364 | } else { |
| 365 | if (!cursor.movePosition(QTextCursor::PreviousBlock)) { |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | }; |
| 371 | |
| 372 | if (!contextBefore.isEmpty()) { |
| 373 | int lines = contextBefore.count('\n') + (contextBefore.endsWith('\n') ? 0 : 1); |
| 374 | dimLines(m_leftDocument->document(), lines, true); |
| 375 | dimLines(m_rightDocument->document(), lines, true); |
| 376 | } |
| 377 | |
| 378 | if (!contextAfter.isEmpty()) { |
| 379 | int lines = contextAfter.count('\n') + (contextAfter.endsWith('\n') ? 0 : 1); |
| 380 | dimLines(m_leftDocument->document(), lines, false); |
| 381 | dimLines(m_rightDocument->document(), lines, false); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | QString RefactorWidget::getRefactoredText() const |
| 386 | { |