#include "pictureview.h" #include #include #include "httpwrapper.h" PictureView::PictureView(QWidget* parent) : QWidget(parent) { } void PictureView::paintEvent ( QPaintEvent* event) { Q_UNUSED(event); QSize s = this->size(); QBrush blackBrush(Qt::black); QPainter painter(this); painter.fillRect( QRect(0,0,s.width(), s.height()), blackBrush); int x = 0; int y = 0; if (image.width() < s.width() ) { x = (s.width() - image.width()) / 2; } if (image.height() < s.height() ) { y = (s.height() - image.height()) / 2; } painter.drawPixmap(x,y,image); painter.end(); } void PictureView::loadFromUrl(QString source) { QMap::iterator it = map.find(source); if (it != map.end() ) { image = it.value(); this->repaint(); } else { qDebug() << "Loading file " << source; QPixmap pixmap; if (source.at(0) == '/') { //local file pixmap = QPixmap(source); } else { QByteArray data = HttpWrapper::getSyncData(source); pixmap.loadFromData( data ); } QPixmap scaledImage = pixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); image = scaledImage; this->repaint(); map.insert(source, scaledImage); } }