File indexing completed on 2024-05-12 16:02:29

0001 /*
0002  * SPDX-FileCopyrightText: 2022 Alvin Wong <alvin@alvinhc.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #ifndef KIS_REPAINT_DEBUGGER_H
0008 #define KIS_REPAINT_DEBUGGER_H
0009 
0010 #include <QtGlobal>
0011 
0012 #include <kritawidgetutils_export.h>
0013 
0014 class QPaintDevice;
0015 class QPaintEvent;
0016 class QRect;
0017 
0018 /**
0019  * A utility class to aid debugging widget or surface redraws. It lets you
0020  * paint out the update rects and makes it obvious by cycling between colors
0021  * with sharp contrast for each paint. This class is controlled globally by
0022  * the environment variable KRITA_DEBUG_REPAINT. KisRepaintDebugger will only
0023  * work when this environment variable is set to `1`.
0024  *
0025  * For optimal effect, one of the `paint` methods shall be called at the end
0026  * of the `paintEvent`, after all the custom painting. If a QPainter has been
0027  * instantiated at the topmost function scope, you must explicitly call `end()`
0028  * on it to release the paint device so that KisRepaintDebugger can use it.
0029  *
0030  * This class is stateful, so it shall be kept as a class member object and
0031  * reused.
0032  *
0033  * Seizure Warning: Enabling repaint debug will produce heavy flashing visuals.
0034  * This may potentially trigger seizures for people with photosensitive epilepsy.
0035  */
0036 class KRITAWIDGETUTILS_EXPORT KisRepaintDebugger
0037 {
0038 public:
0039     /**
0040      * Whether KisRepaintDebugger is enabled globally. This is controlled
0041      * by the environment variable KRITA_DEBUG_REPAINT.
0042      */
0043     static bool enabled();
0044 
0045     KisRepaintDebugger() = default;
0046     ~KisRepaintDebugger() = default;
0047 
0048     void paint(QPaintDevice *paintDevice, const QRect &widgetRect);
0049     void paint(QPaintDevice *paintDevice, const QVector<QRect> &widgetRects);
0050     void paint(QPaintDevice *paintDevice, const QPaintEvent *event);
0051     void paintFull(QPaintDevice *paintDevice);
0052 
0053 private:
0054     void paint(QPaintDevice *paintDevice, const QRect *widgetRects, size_t count);
0055 
0056 private:
0057     unsigned int m_colorIndex {0};
0058 };
0059 
0060 #endif // KIS_REPAINT_DEBUGGER_H