--- infoscreen/pictureview.cpp 2010/04/08 05:50:48 641 +++ infoscreen/pictureview.cpp 2010/05/05 09:37:08 709 @@ -11,13 +11,29 @@ } -// 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(); } @@ -38,7 +54,7 @@ pixmap.loadFromData( data ); } - QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation ); + QPixmap scaledImage = pixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); image = scaledImage; this->repaint();