#include "pictureview.h" #include #include #include "httpwrapper.h" PictureView::PictureView(QWidget* parent) : QWidget(parent) { } // TODO: if the picture doesn't fill the screen, fill the canvas with black before drawing the picture and // place the image mid-screen void PictureView::paintEvent ( QPaintEvent* event) { Q_UNUSED(event); QPainter painter(this); painter.drawPixmap(0,0,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.scaledToHeight(size().height(), Qt::SmoothTransformation ); image = scaledImage; this->repaint(); map.insert(source, scaledImage); } }