1 |
#include "pictureview.h" |
2 |
|
3 |
#include <QPainter> |
4 |
|
5 |
|
6 |
#include "httpwrapper.h" |
7 |
|
8 |
PictureView::PictureView(QWidget* parent) |
9 |
: QWidget(parent) |
10 |
{ |
11 |
} |
12 |
|
13 |
void PictureView::paintEvent ( QPaintEvent* event) |
14 |
{ |
15 |
Q_UNUSED(event); |
16 |
QPainter painter(this); |
17 |
painter.drawPixmap(0,0,image); |
18 |
painter.end(); |
19 |
} |
20 |
|
21 |
void PictureView::loadFromUrl(QString source) |
22 |
{ |
23 |
QMap<QString, QPixmap>::iterator it = map.find(source); |
24 |
if (it != map.end() ) { |
25 |
image = it.value(); |
26 |
this->repaint(); |
27 |
} else { |
28 |
QByteArray data = HttpWrapper::getSyncData(source); |
29 |
|
30 |
QPixmap pixmap; |
31 |
pixmap.loadFromData( data ); |
32 |
|
33 |
QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation ); |
34 |
|
35 |
image = scaledImage; |
36 |
this->repaint(); |
37 |
|
38 |
map.insert(source, scaledImage); |
39 |
|
40 |
} |
41 |
} |