d70352a6ce
OBS Studio currently does not support retina rendering for any of the images in the app. This adds support for retina pixmap rendering as well as adding higher resolution versions of each icon that was not a high enough resolution to support 2x. The icons work when switching themes and will only render the 2x versions when the device pixel ratio is greater than or equal to 2. I also added credits to the readme for images that were already being used that require credit to the author. If the OBS community has paid for these images already, I can remove the credits from the readme. The credit is for the invisible, visible, and gear icons.
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include <QPaintEvent>
|
|
#include <QPixmap>
|
|
#include <QPainter>
|
|
#include "locked-checkbox.hpp"
|
|
|
|
#include <util/c99defs.h>
|
|
|
|
LockedCheckBox::LockedCheckBox() : QCheckBox()
|
|
{
|
|
QString lockedFile;
|
|
QString unlockedFile;
|
|
if (devicePixelRatio() >= 2) {
|
|
lockedFile = ":/res/images/locked_mask@2x.png";
|
|
unlockedFile = ":/res/images/unlocked_mask@2x.png";
|
|
} else {
|
|
lockedFile = ":/res/images/locked_mask.png";
|
|
unlockedFile = ":/res/images/unlocked_mask.png";
|
|
}
|
|
lockedImage = QPixmap::fromImage(QImage(lockedFile));
|
|
unlockedImage = QPixmap::fromImage(QImage(unlockedFile));
|
|
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, 16, 16, QPixmap::fromImage(image));
|
|
}
|