--- infoscreen/pictureview.cpp 2010/01/05 16:54:21 525 +++ infoscreen/pictureview.cpp 2010/05/05 08:38:49 707 @@ -1,21 +1,41 @@ #include "pictureview.h" -#include -#include +#include #include -#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); + + QSize s = this->size(); + + QBrush blackBrush(Qt::black); + QPainter painter(this); - painter.drawPixmap(0,0,image); + 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(); } @@ -26,32 +46,23 @@ image = it.value(); this->repaint(); } else { - requestedUrl = source; + qDebug() << "Loading file " << source; - QUrl imageUrl(requestedUrl); - http = new QHttp(imageUrl.host() ); - http->connect(http, SIGNAL(requestFinished(int,bool)),this, SLOT(onLoad(int,bool)) ); + QPixmap pixmap; + if (source.at(0) == '/') { //local file + pixmap = QPixmap(source); + } else { + QByteArray data = HttpWrapper::getSyncData(source); + pixmap.loadFromData( data ); + } - http->get(imageUrl.path(), 0); - } -} - -void PictureView::onLoad(int id, bool ok) -{ - Q_UNUSED(id); - Q_UNUSED(ok); - - QByteArray data = http->readAll(); + QPixmap scaledImage = pixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); - QPixmap pixmap; - pixmap.loadFromData( data ); - delete http; - - QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation ); - - image = scaledImage; - this->repaint(); + image = scaledImage; + this->repaint(); - map.insert(requestedUrl, scaledImage); + map.insert(source, scaledImage); + } } +