1 |
#include "pictureview.h" |
#include "pictureview.h" |
2 |
|
|
3 |
#include <QGraphicsView> |
#include <QPainter> |
|
#include <QGraphicsScene> |
|
4 |
#include <QDebug> |
#include <QDebug> |
5 |
#include <QUrl> |
|
6 |
#include <QHttp> |
#include "httpwrapper.h" |
7 |
|
|
8 |
PictureView::PictureView(QWidget* parent) |
PictureView::PictureView(QWidget* parent) |
9 |
: QWidget(parent) |
: 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); |
28 |
image = it.value(); |
image = it.value(); |
29 |
this->repaint(); |
this->repaint(); |
30 |
} else { |
} else { |
31 |
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)) ); |
|
|
|
|
|
http->get(imageUrl.path(), 0); |
|
|
} |
|
|
} |
|
32 |
|
|
33 |
void PictureView::onLoad(int id, bool ok) |
QPixmap pixmap; |
34 |
{ |
if (source.at(0) == '/') { //local file |
35 |
Q_UNUSED(id); |
pixmap = QPixmap(source); |
36 |
Q_UNUSED(ok); |
} else { |
37 |
|
QByteArray data = HttpWrapper::getSyncData(source); |
38 |
QByteArray data = http->readAll(); |
pixmap.loadFromData( data ); |
39 |
|
} |
|
QPixmap pixmap; |
|
|
pixmap.loadFromData( data ); |
|
|
delete http; |
|
40 |
|
|
41 |
QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation ); |
QPixmap scaledImage = pixmap.scaledToHeight(size().height(), Qt::SmoothTransformation ); |
42 |
|
|
43 |
image = scaledImage; |
image = scaledImage; |
44 |
this->repaint(); |
this->repaint(); |
45 |
|
|
46 |
map.insert(requestedUrl, scaledImage); |
map.insert(source, scaledImage); |
47 |
|
|
48 |
|
} |
49 |
} |
} |
50 |
|
|