all repos — mgba @ e17e4fd19003209ff9db1f0ac1394e463c7b4a47

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "SavestateButton.h"
 7
 8#include <QApplication>
 9#include <QPainter>
10
11using namespace QGBA;
12
13SavestateButton::SavestateButton(QWidget* parent)
14	: QAbstractButton(parent)
15{
16	setAttribute(Qt::WA_TranslucentBackground);
17}
18
19void SavestateButton::paintEvent(QPaintEvent*) {
20	QPainter painter(this);
21	QRect frame(0, 0, width(), height());
22	QRect full(1, 1, width() - 2, height() - 2);
23	QPalette palette = QApplication::palette(this);
24	painter.setPen(Qt::black);
25	QLinearGradient grad(0, 0, 0, 1);
26	grad.setCoordinateMode(QGradient::ObjectBoundingMode);
27	QColor shadow = palette.color(QPalette::Shadow);
28	QColor dark = palette.color(QPalette::Dark);
29	shadow.setAlpha(128);
30	dark.setAlpha(128);
31	grad.setColorAt(0, shadow);
32	grad.setColorAt(1, dark);
33	painter.setBrush(grad);
34	painter.drawRect(frame);
35	painter.setPen(Qt::NoPen);
36	if (!icon().isNull()) {
37		painter.drawPixmap(full, icon().pixmap(full.size()));
38	}
39	if (hasFocus()) {
40		QColor highlight = palette.color(QPalette::Highlight);
41		highlight.setAlpha(128);
42		painter.fillRect(full, highlight);
43	}
44	painter.setPen(QPen(palette.text(), 0));
45	painter.drawText(full, Qt::AlignCenter, text());
46}