CmvrControlStation/src/snapshotimageview.h

28 lines
885 B
C++

#pragma once
#include <QImage>
#include <QPainter>
#include <QWidget>
// Still images use the raster painter, independently of the video GL context.
class SnapshotImageView : public QWidget
{
public:
explicit SnapshotImageView(QWidget *parent = nullptr) : QWidget(parent) {}
void setImage(const QImage &image) { m_image = image; update(); }
protected:
void paintEvent(QPaintEvent *) override
{
QPainter painter(this);
painter.fillRect(rect(), QColor(QStringLiteral("#0e1115")));
if (m_image.isNull()) return;
QSize target = m_image.size();
target.scale(size(), Qt::KeepAspectRatio);
painter.drawImage(QRect((width() - target.width()) / 2,
(height() - target.height()) / 2,
target.width(), target.height()), m_image);
}
private:
QImage m_image;
};