18#include <KGlobalAccel>
19#include <KLocalizedString>
27static const qreal s_alpha = 0.2;
28static const QList<QColor> s_colors{
39 auto *toggleAction =
new QAction(
this);
40 toggleAction->setObjectName(QStringLiteral(
"Toggle"));
41 toggleAction->setText(i18n(
"Toggle Show Paint"));
42 KGlobalAccel::self()->setDefaultShortcut(toggleAction, {});
43 KGlobalAccel::self()->setShortcut(toggleAction, {});
45 connect(toggleAction, &QAction::triggered,
this, &ShowPaintEffect::toggle);
50 m_painted = QRegion();
57 if (++m_colorIndex == s_colors.count()) {
68void ShowPaintEffect::paintGL(
const QMatrix4x4 &projection, qreal scale)
75 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
76 QColor color = s_colors[m_colorIndex];
77 color.setAlphaF(s_alpha);
79 QList<QVector2D> verts;
80 verts.reserve(m_painted.rectCount() * 12);
81 for (
const QRect &r : m_painted) {
83 verts.push_back(QVector2D(deviceRect.x() + deviceRect.width(), deviceRect.y()));
84 verts.push_back(QVector2D(deviceRect.x(), deviceRect.y()));
85 verts.push_back(QVector2D(deviceRect.x(), deviceRect.y() + deviceRect.height()));
86 verts.push_back(QVector2D(deviceRect.x(), deviceRect.y() + deviceRect.height()));
87 verts.push_back(QVector2D(deviceRect.x() + deviceRect.width(), deviceRect.y() + deviceRect.height()));
88 verts.push_back(QVector2D(deviceRect.x() + deviceRect.width(), deviceRect.y()));
95void ShowPaintEffect::paintQPainter()
97 QColor color = s_colors[m_colorIndex];
98 color.setAlphaF(s_alpha);
99 for (
const QRect &r : m_painted) {
109void ShowPaintEffect::toggle()
111 m_active = !m_active;
117#include "moc_showpaint.cpp"
Representation of a window used by/for Effect classes.
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen)
CompositingType compositingType
void paintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, const QRegion ®ion, WindowPaintData &data)
bool isOpenGLCompositing() const
Whether the Compositor is OpenGL based (either GL 1 or 2).
Q_SCRIPTABLE void addRepaintFull()
QPainter * scenePainter()
Provides access to the QPainter which is rendering to the back buffer.
@ ModelViewProjectionMatrix
static GLVertexBuffer * streamingBuffer()
void render(GLenum primitiveMode)
void setVertices(const T &range)
QMatrix4x4 projectionMatrix() const
bool isActive() const override
void paintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen) override
KWIN_EXPORT QPointF snapToPixelGridF(const QPointF &point)
KWIN_EXPORT QRectF scaledRect(const QRectF &rect, qreal scale)