all repos — mgba @ 73d28a1ae423017e3f16266dce1d019b8da292b4

mGBA Game Boy Advance Emulator

src/platform/qt/SavestateButton.cpp (view raw)

 1#include "SavestateButton.h"
 2
 3#include <QApplication>
 4#include <QPainter>
 5
 6using namespace QGBA;
 7
 8SavestateButton::SavestateButton(QWidget* parent)
 9	: QAbstractButton(parent)
10{
11	// Nothing to do
12}
13
14void SavestateButton::paintEvent(QPaintEvent*) {
15	QPainter painter(this);
16	QRect frame(0, 0, width(), height());
17	QRect full(1, 1, width() - 2, height() - 2);
18	QPalette palette = QApplication::palette(this);
19	painter.setPen(Qt::black);
20	QLinearGradient grad(0, 0, 0, 1);
21	grad.setCoordinateMode(QGradient::ObjectBoundingMode);
22	grad.setColorAt(0, palette.color(QPalette::Shadow));
23	grad.setColorAt(1, palette.color(QPalette::Dark));
24	painter.setBrush(grad);
25	painter.drawRect(frame);
26	painter.setPen(Qt::NoPen);
27	if (!icon().isNull()) {
28		painter.drawPixmap(full, icon().pixmap(full.size()));
29	}
30	if (hasFocus()) {
31		QColor highlight = palette.color(QPalette::Highlight);
32		highlight.setAlpha(128);
33		painter.fillRect(full, highlight);
34	}
35	painter.setPen(QPen(palette.text(), 0));
36	painter.drawText(full, Qt::AlignCenter, text());
37}