Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRepaintDebugger.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Alvin Wong <alvin@alvinhc.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
8
9#include <KLocalizedString>
10
11#include <QPaintDevice>
12#include <QPainter>
13#include <QPaintEvent>
14#include <QThread>
15#include <QApplication>
16#include <QMessageBox>
17#include <QDebug>
18
20{
21 static bool enabled = qEnvironmentVariableIntValue("KRITA_DEBUG_REPAINT") == 1;
22 return enabled;
23}
24
25void KisRepaintDebugger::paint(QPaintDevice *paintDevice, const QRect &widgetRect)
26{
27 paint(paintDevice, &widgetRect, 1);
28}
29
30void KisRepaintDebugger::paint(QPaintDevice *paintDevice, const QVector<QRect> &widgetRects)
31{
32 paint(paintDevice, widgetRects.constData(), widgetRects.size());
33}
34
35void KisRepaintDebugger::paint(QPaintDevice *paintDevice, const QPaintEvent *event)
36{
37 paint(paintDevice, event->rect());
38}
39
40void KisRepaintDebugger::paintFull(QPaintDevice *pd)
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}
49
50void KisRepaintDebugger::paint(QPaintDevice *paintDevice, const QRect *widgetRects, size_t count)
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}
void paint(QPaintDevice *paintDevice, const QRect &widgetRect)
void paintFull(QPaintDevice *paintDevice)
#define ALPHA(rgba)
Definition pixels.h:51