Qt: Draw with QPicture instead of a pixmap
Jeffrey Pfau jeffrey@endrift.com
Fri, 07 Nov 2014 22:46:41 -0800
5 files changed,
6 insertions(+),
10 deletions(-)
M
src/platform/qt/GBAKeyEditor.cpp
→
src/platform/qt/GBAKeyEditor.cpp
@@ -2,7 +2,6 @@ #include "GBAKeyEditor.h"
#include <QPaintEvent> #include <QPainter> -#include <QPicture> #include <QPushButton> #include "InputController.h"@@ -21,9 +20,7 @@ const qreal GBAKeyEditor::DPAD_HEIGHT = 0.1;
GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* parent) : QWidget(parent) - , m_background(QString(":/res/keymap.png")) { - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint); setMinimumSize(300, 300);@@ -118,9 +115,7 @@ };
m_currentKey = m_keyOrder.end(); - QPixmap background(":/res/keymap.png"); - m_background = background.scaled(QSize(300, 300) * devicePixelRatio(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - m_background.setDevicePixelRatio(devicePixelRatio()); + m_background.load(":/res/keymap.qpic"); } void GBAKeyEditor::setAll() {@@ -144,7 +139,8 @@ }
void GBAKeyEditor::paintEvent(QPaintEvent* event) { QPainter painter(this); - painter.drawPixmap(0, 0, m_background); + painter.scale(width() / 480.0, height() / 480.0); + painter.drawPicture(0, 0, m_background); } void GBAKeyEditor::setNext() {
M
src/platform/qt/GBAKeyEditor.h
→
src/platform/qt/GBAKeyEditor.h
@@ -2,7 +2,7 @@ #ifndef QGBA_GBA_KEY_EDITOR
#define QGBA_GBA_KEY_EDITOR #include <QList> -#include <QPixmap> +#include <QPicture> #include <QWidget> class QPushButton;@@ -51,7 +51,7 @@ QList<KeyEditor*>::iterator m_currentKey;
InputController* m_controller; - QPixmap m_background; + QPicture m_background; }; }
M
src/platform/qt/resources.qrc
→
src/platform/qt/resources.qrc
@@ -1,6 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0"> <qresource> <file>../../../res/mgba-1024.png</file> - <file>../../../res/keymap.png</file> + <file>../../../res/keymap.qpic</file> </qresource> </RCC>