mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-05 21:13:55 -07:00
Longer variable names.
Took 10 minutes Took 5 seconds
This commit is contained in:
parent
59dc3ca409
commit
042e879f43
1 changed files with 20 additions and 19 deletions
|
|
@ -31,41 +31,42 @@ void ColorButton::pickColor()
|
||||||
|
|
||||||
void ColorButton::updateSwatch()
|
void ColorButton::updateSwatch()
|
||||||
{
|
{
|
||||||
QPixmap pm(size() * devicePixelRatioF());
|
QPixmap pixmap(size() * devicePixelRatioF());
|
||||||
pm.setDevicePixelRatio(devicePixelRatioF());
|
pixmap.setDevicePixelRatio(devicePixelRatioF());
|
||||||
pm.fill(Qt::transparent);
|
pixmap.fill(Qt::transparent);
|
||||||
QPainter p(&pm);
|
QPainter painter(&pixmap);
|
||||||
p.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
// Checkerboard for alpha
|
// Checkerboard for alpha
|
||||||
const int cs = 4;
|
const int cellSize = 4;
|
||||||
for (int y = 0; y < height(); y += cs) {
|
for (int y = 0; y < height(); y += cellSize) {
|
||||||
for (int x = 0; x < width(); x += cs) {
|
for (int x = 0; x < width(); x += cellSize) {
|
||||||
p.fillRect(x, y, cs, cs, ((x / cs + y / cs) % 2) ? QColor(180, 180, 180) : Qt::white);
|
painter.fillRect(x, y, cellSize, cellSize,
|
||||||
|
((x / cellSize + y / cellSize) % 2) ? QColor(180, 180, 180) : Qt::white);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color fill
|
// Color fill
|
||||||
p.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
p.setBrush(color);
|
painter.setBrush(color);
|
||||||
p.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
|
painter.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
|
||||||
|
|
||||||
// Border
|
// Border
|
||||||
QColor border = palette().color(QPalette::Shadow);
|
QColor border = palette().color(QPalette::Shadow);
|
||||||
border.setAlpha(180);
|
border.setAlpha(180);
|
||||||
p.setPen(QPen(border, 1));
|
painter.setPen(QPen(border, 1));
|
||||||
p.setBrush(Qt::NoBrush);
|
painter.setBrush(Qt::NoBrush);
|
||||||
p.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
|
painter.drawRoundedRect(QRectF(0.5, 0.5, width() - 1, height() - 1), 3, 3);
|
||||||
|
|
||||||
// Hex label — black or white for contrast
|
// Hex label — black or white for contrast
|
||||||
int luma = 0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue();
|
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();
|
QFont f = font();
|
||||||
f.setPixelSize(8);
|
f.setPixelSize(8);
|
||||||
p.setFont(f);
|
painter.setFont(f);
|
||||||
p.drawText(rect(), Qt::AlignCenter, color.name().toUpper());
|
painter.drawText(rect(), Qt::AlignCenter, color.name().toUpper());
|
||||||
|
|
||||||
setIcon(QIcon(pm));
|
setIcon(QIcon(pixmap));
|
||||||
setIconSize(size());
|
setIconSize(size());
|
||||||
setText({});
|
setText({});
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue