1 |
#include "pictureview.h" |
2 |
|
3 |
#include <QPainter> |
4 |
#include <QDebug> |
5 |
|
6 |
#include "httpwrapper.h" |
7 |
|
8 |
PictureView::PictureView(QWidget* parent) |
9 |
: 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) |
17 |
{ |
18 |
Q_UNUSED(event); |
19 |
QPainter painter(this); |
20 |
painter.drawPixmap(0,0,image); |
21 |
painter.end(); |
22 |
} |
23 |
|
24 |
void PictureView::loadFromUrl(QString source) |
25 |
{ |
26 |
QMap<QString, QPixmap>::iterator it = map.find(source); |
27 |
if (it != map.end() ) { |
28 |
image = it.value(); |
29 |
this->repaint(); |
30 |
} else { |
31 |
qDebug() << "Loading file " << source; |
32 |
|
33 |
QPixmap pixmap; |
34 |
if (source.at(0) == '/') { //local file |
35 |
pixmap = QPixmap(source); |
36 |
} else { |
37 |
QByteArray data = HttpWrapper::getSyncData(source); |
38 |
pixmap.loadFromData( data ); |
39 |
} |
40 |
|
41 |
QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation ); |
42 |
|
43 |
image = scaledImage; |
44 |
this->repaint(); |
45 |
|
46 |
map.insert(source, scaledImage); |
47 |
|
48 |
} |
49 |
} |