Longer variable names.

Took 10 minutes

Took 5 seconds
This commit is contained in:
Lukas Brübach 2026-05-17 09:12:17 +02:00
parent 59dc3ca409
commit 042e879f43

View file

@ -31,41 +31,42 @@ void ColorButton::pickColor()
void ColorButton::updateSwatch()
{
QPixmap pm(size() * devicePixelRatioF());
pm.setDevicePixelRatio(devicePixelRatioF());
pm.fill(Qt::transparent);
QPainter p(&pm);
p.setRenderHint(QPainter::Antialiasing);
QPixmap pixmap(size() * devicePixelRatioF());
pixmap.setDevicePixelRatio(devicePixelRatioF());
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
// Checkerboard for alpha
const int cs = 4;
for (int y = 0; y < height(); y += cs) {
for (int x = 0; x < width(); x += cs) {
p.fillRect(x, y, cs, cs, ((x / cs + y / cs) % 2) ? QColor(180, 180, 180) : Qt::white);
const int cellSize = 4;
for (int y = 0; y < height(); y += cellSize) {
for (int x = 0; x < width(); x += cellSize) {
painter.fillRect(x, y, cellSize, cellSize,
((x / cellSize + y / cellSize) % 2) ? QColor(180, 180, 180) : Qt::white);
}
}
// Color fill
p.setPen(Qt::NoPen);
p.setBrush(color);
p.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
painter.setPen(Qt::NoPen);
painter.setBrush(color);
painter.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
// Border
QColor border = palette().color(QPalette::Shadow);
border.setAlpha(180);
p.setPen(QPen(border, 1));
p.setBrush(Qt::NoBrush);
p.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
painter.setPen(QPen(border, 1));
painter.setBrush(Qt::NoBrush);
painter.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
// Hex label — black or white for contrast
int luma = 0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue();
p.setPen((luma > 128 && color.alpha() > 80) ? QColor(0, 0, 0, 180) : QColor(255, 255, 255, 200));
painter.setPen((luma > 128 && color.alpha() > 80) ? QColor(0, 0, 0, 180) : QColor(255, 255, 255, 200));
QFont f = font();
f.setPixelSize(8);
p.setFont(f);
p.drawText(rect(), Qt::AlignCenter, color.name().toUpper());
painter.setFont(f);
painter.drawText(rect(), Qt::AlignCenter, color.name().toUpper());
setIcon(QIcon(pm));
setIcon(QIcon(pixmap));
setIconSize(size());
setText({});
}