Blame | Last modification | View Log | RSS feed
#include "ImageWidget.h"
ImageWidget::ImageWidget(QWidget *parent)
: QWidget(parent) {
pixmapOffset = QPoint();
setBackgroundRole(QPalette::Base);
setAutoFillBackground(true);
}
ImageWidget::~ImageWidget() {
}
void ImageWidget::setSize(int x, int y) {
widgetSize = QSize(x, y);
}
void ImageWidget::setText(QString str) {
initText = str;
}
QSize ImageWidget::minimumSizeHint() const {
return widgetSize;
}
QSize ImageWidget::sizeHint() const {
return widgetSize;
}
void ImageWidget::paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
// Draw a border around this widget
painter.save();
painter.setRenderHint(QPainter::Antialiasing, false);
painter.setPen(palette().dark().color());
painter.setBrush(Qt::NoBrush);
painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
painter.restore();
// Set default image
if (pixmap.isNull()) {
painter.setPen(Qt::black);
painter.drawText(rect(), Qt::AlignCenter, initText);
return;
}
// Display the saved image
painter.drawPixmap(pixmapOffset, pixmap);
}
void ImageWidget::updateImage(const QImage &image) {
if (&image == NULL)
pixmap = QPixmap(0, 0);
else {
// Save the received image as a QPixmap
pixmap = QPixmap::fromImage(image);
update();
}
}