forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocked-checkbox.cpp
36 lines (29 loc) · 1001 Bytes
/
locked-checkbox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <QPaintEvent>
#include <QPixmap>
#include <QPainter>
#include "locked-checkbox.hpp"
#include <util/c99defs.h>
LockedCheckBox::LockedCheckBox() : QCheckBox()
{
lockedImage =
QPixmap::fromImage(QImage(":/res/images/locked_mask.png"));
unlockedImage =
QPixmap::fromImage(QImage(":/res/images/unlocked_mask.png"));
setMinimumSize(16, 16);
setStyleSheet("outline: none;");
}
void LockedCheckBox::paintEvent(QPaintEvent *event)
{
UNUSED_PARAMETER(event);
QPixmap &pixmap = isChecked() ? lockedImage : unlockedImage;
QImage image(pixmap.size(), QImage::Format_ARGB32);
QPainter draw(&image);
draw.setCompositionMode(QPainter::CompositionMode_Source);
draw.drawPixmap(0, 0, pixmap.width(), pixmap.height(), pixmap);
draw.setCompositionMode(QPainter::CompositionMode_SourceIn);
draw.fillRect(QRectF(QPointF(0.0f, 0.0f), pixmap.size()),
palette().color(foregroundRole()));
QPainter p(this);
p.drawPixmap(0, 0, image.width(), image.height(),
QPixmap::fromImage(image));
}