| 345 | } |
| 346 | |
| 347 | void MarkdownEditor::paintEvent(QPaintEvent *event) |
| 348 | { |
| 349 | Q_D(MarkdownEditor); |
| 350 | |
| 351 | QPainter painter(viewport()); |
| 352 | QRect viewportRect = viewport()->rect(); |
| 353 | painter.fillRect(viewportRect, Qt::transparent); |
| 354 | |
| 355 | QPointF offset(contentOffset()); |
| 356 | QTextBlock block = firstVisibleBlock(); |
| 357 | |
| 358 | bool firstVisible = true; |
| 359 | |
| 360 | QRectF blockAreaRect; // Code or block quote rect. |
| 361 | bool inBlockArea = false; |
| 362 | MarkdownEditorPrivate::BlockType blockType = MarkdownEditorPrivate::BlockTypeNone; |
| 363 | bool clipTop = false; |
| 364 | bool drawBlock = false; |
| 365 | int dy = 0; |
| 366 | bool done = false; |
| 367 | |
| 368 | int cornerRadius = 5; |
| 369 | |
| 370 | if (InterfaceStyleSquare == d->editorCorners) { |
| 371 | cornerRadius = 0; |
| 372 | } |
| 373 | |
| 374 | // Draw text block area backgrounds for code blocks and block quotes. |
| 375 | // The backgrounds are drawn per each block area (consisting of multiple |
| 376 | // text blocks or lines), rather than one rectangle area per text block/ |
| 377 | // line in case there are margins between each text block. This way, |
| 378 | // the background will extend to cover the margins between text blocks |
| 379 | // as well. |
| 380 | // |
| 381 | // NOTE: Algorithm for looping through text blocks is a partial lift from |
| 382 | // Qt's QPlainTextEdit paintEvent() code. Please refer to the |
| 383 | // LGPL v. 3 license for the original Qt code. |
| 384 | // |
| 385 | while (block.isValid() && !done) { |
| 386 | MarkdownEditorPrivate::BlockType prevType; |
| 387 | |
| 388 | QRectF r = this->blockBoundingRect(block).translated(offset); |
| 389 | |
| 390 | // If the first visible block is in the middle of a text block area... |
| 391 | if (firstVisible |
| 392 | && d->insideBlockArea(block, blockType) |
| 393 | && d->insideBlockArea(block.previous(), prevType) |
| 394 | && (blockType == prevType)) { |
| 395 | clipTop = true; |
| 396 | inBlockArea = true; |
| 397 | blockAreaRect = r; |
| 398 | dy = 0; |
| 399 | } |
| 400 | // If the block begins a new text block area... |
| 401 | else if (!inBlockArea && d->atBlockAreaStart(block, blockType)) { |
| 402 | blockAreaRect = r; |
| 403 | dy = 0; |
| 404 | inBlockArea = true; |
nothing calls this directly
no test coverage detected