MCPcopy Create free account
hub / github.com/KDE/ghostwriter / paintEvent

Method paintEvent

src/editor/markdowneditor.cpp:347–610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347void 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;

Callers

nothing calls this directly

Calls 15

cursorRectMethod · 0.95
isValidMethod · 0.80
insideBlockAreaMethod · 0.80
atBlockAreaStartMethod · 0.80
atBlockAreaEndMethod · 0.80
isCodeBlockMethod · 0.80
lengthMethod · 0.80
fontMethod · 0.80
previousMethod · 0.65
textMethod · 0.65
nextMethod · 0.65
endMethod · 0.65

Tested by

no test coverage detected