Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRepaintDebugger Class Reference

#include <KisRepaintDebugger.h>

Public Member Functions

 KisRepaintDebugger ()=default
 
void paint (QPaintDevice *paintDevice, const QPaintEvent *event)
 
void paint (QPaintDevice *paintDevice, const QRect &widgetRect)
 
void paint (QPaintDevice *paintDevice, const QVector< QRect > &widgetRects)
 
void paintFull (QPaintDevice *paintDevice)
 
 ~KisRepaintDebugger ()=default
 

Static Public Member Functions

static bool enabled ()
 

Private Member Functions

void paint (QPaintDevice *paintDevice, const QRect *widgetRects, size_t count)
 

Private Attributes

unsigned int m_colorIndex {0}
 

Detailed Description

A utility class to aid debugging widget or surface redraws. It lets you paint out the update rects and makes it obvious by cycling between colors with sharp contrast for each paint. This class is controlled globally by the environment variable KRITA_DEBUG_REPAINT. KisRepaintDebugger will only work when this environment variable is set to 1.

For optimal effect, one of the paint methods shall be called at the end of the paintEvent, after all the custom painting. If a QPainter has been instantiated at the topmost function scope, you must explicitly call end() on it to release the paint device so that KisRepaintDebugger can use it.

This class is stateful, so it shall be kept as a class member object and reused.

Seizure Warning: Enabling repaint debug will produce heavy flashing visuals. This may potentially trigger seizures for people with photosensitive epilepsy.

Definition at line 36 of file KisRepaintDebugger.h.

Constructor & Destructor Documentation

◆ KisRepaintDebugger()

KisRepaintDebugger::KisRepaintDebugger ( )
default

◆ ~KisRepaintDebugger()

KisRepaintDebugger::~KisRepaintDebugger ( )
default

Member Function Documentation

◆ enabled()

bool KisRepaintDebugger::enabled ( )
static

Whether KisRepaintDebugger is enabled globally. This is controlled by the environment variable KRITA_DEBUG_REPAINT.

Definition at line 19 of file KisRepaintDebugger.cpp.

20{
21 static bool enabled = qEnvironmentVariableIntValue("KRITA_DEBUG_REPAINT") == 1;
22 return enabled;
23}

References enabled().

◆ paint() [1/4]

void KisRepaintDebugger::paint ( QPaintDevice * paintDevice,
const QPaintEvent * event )

Definition at line 35 of file KisRepaintDebugger.cpp.

36{
37 paint(paintDevice, event->rect());
38}
void paint(QPaintDevice *paintDevice, const QRect &widgetRect)

References paint().

◆ paint() [2/4]

void KisRepaintDebugger::paint ( QPaintDevice * paintDevice,
const QRect & widgetRect )

Definition at line 25 of file KisRepaintDebugger.cpp.

26{
27 paint(paintDevice, &widgetRect, 1);
28}

References paint().

◆ paint() [3/4]

void KisRepaintDebugger::paint ( QPaintDevice * paintDevice,
const QRect * widgetRects,
size_t count )
private

Definition at line 50 of file KisRepaintDebugger.cpp.

51{
52 if (!enabled()) {
53 return;
54 }
55 constexpr int ALPHA = 63;
56 static QVector<QColor> colors {
57 QColor(255, 0, 0, ALPHA),
58 QColor(0, 255, 0, ALPHA),
59 QColor(0, 0, 255, ALPHA),
60 QColor(255, 255, 0, ALPHA),
61 QColor(255, 0, 255, ALPHA),
62 QColor(0, 255, 255, ALPHA),
63 };
64 m_colorIndex = (m_colorIndex + 1) % colors.size();
65 QPainter gc(paintDevice);
66 for (size_t i = 0; i < count; i++) {
67 gc.fillRect(widgetRects[i], colors[m_colorIndex]);
68 }
69}
#define ALPHA(rgba)
Definition pixels.h:51

References ALPHA, enabled(), and m_colorIndex.

◆ paint() [4/4]

void KisRepaintDebugger::paint ( QPaintDevice * paintDevice,
const QVector< QRect > & widgetRects )

Definition at line 30 of file KisRepaintDebugger.cpp.

31{
32 paint(paintDevice, widgetRects.constData(), widgetRects.size());
33}

References paint().

◆ paintFull()

void KisRepaintDebugger::paintFull ( QPaintDevice * paintDevice)

Definition at line 40 of file KisRepaintDebugger.cpp.

41{
42 if (!enabled()) {
43 return;
44 }
45 const QRect rect = QRectF(QPointF(), QSizeF(pd->width(), pd->height()) * pd->devicePixelRatioF())
46 .toAlignedRect();
47 paint(pd, &rect, 1);
48}

References enabled(), and paint().

Member Data Documentation

◆ m_colorIndex

unsigned int KisRepaintDebugger::m_colorIndex {0}
private

Definition at line 57 of file KisRepaintDebugger.h.

57{0};

The documentation for this class was generated from the following files: