/[projects]/infoscreen/pictureview.cpp
ViewVC logotype

Diff of /infoscreen/pictureview.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 528 by torben, Wed Jan 6 22:18:52 2010 UTC revision 707 by torben, Wed May 5 08:38:49 2010 UTC
# Line 1  Line 1 
1  #include "pictureview.h"  #include "pictureview.h"
2    
3  #include <QPainter>  #include <QPainter>
4    #include <QDebug>
5    
6  #include "httpwrapper.h"  #include "httpwrapper.h"
7    
# Line 10  PictureView::PictureView(QWidget* parent Line 10  PictureView::PictureView(QWidget* parent
10  {  {
11  }  }
12    
13    
14    // TODO: if the picture doesn't fill the screen, fill the canvas with black before drawing the picture and
15    // place the image mid-screen
16  void PictureView::paintEvent ( QPaintEvent* event)  void PictureView::paintEvent ( QPaintEvent* event)
17  {      {    
18      Q_UNUSED(event);      Q_UNUSED(event);
19    
20        QSize s = this->size();
21    
22        QBrush blackBrush(Qt::black);
23    
24      QPainter painter(this);      QPainter painter(this);
25      painter.drawPixmap(0,0,image);      painter.fillRect( QRect(0,0,s.width(), s.height()), blackBrush);
26    
27        int x = 0;
28        int y = 0;
29    
30        if (image.width() < s.width() )  {
31            x = (s.width() - image.width()) / 2;
32        }
33        if (image.height() < s.height() ) {
34            y = (s.height() - image.height()) / 2;
35        }
36    
37    
38        painter.drawPixmap(x,y,image);
39      painter.end();      painter.end();
40  }  }
41    
# Line 25  void PictureView::loadFromUrl(QString so Line 46  void PictureView::loadFromUrl(QString so
46          image = it.value();          image = it.value();
47          this->repaint();          this->repaint();
48      } else {      } else {
49          QByteArray data = HttpWrapper::getSyncData(source);          qDebug() << "Loading file " << source;
50    
51          QPixmap pixmap;          QPixmap pixmap;
52          pixmap.loadFromData( data );          if (source.at(0) == '/') { //local file
53                pixmap = QPixmap(source);
54            } else {
55                QByteArray data = HttpWrapper::getSyncData(source);
56                pixmap.loadFromData( data );
57            }
58    
59          QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation );          QPixmap scaledImage = pixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
60    
61          image = scaledImage;          image = scaledImage;
62          this->repaint();          this->repaint();

Legend:
Removed from v.528  
changed lines
  Added in v.707

  ViewVC Help
Powered by ViewVC 1.1.20