diff --git a/resources/sankore.qrc b/resources/sankore.qrc
index f6f69124..d07c048f 100644
--- a/resources/sankore.qrc
+++ b/resources/sankore.qrc
@@ -265,6 +265,7 @@
images/libpalette/notFound.png
images/libpalette/trash_favorite.svg
images/libpalette/back.png
+ images/libpalette/loading.png
images/stylusPalette/eraserArrow.png
images/stylusPalette/eraserOnArrow.png
images/stylusPalette/markerArrow.png
diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp
index 889bc654..cad07bbb 100644
--- a/src/gui/UBFeaturesWidget.cpp
+++ b/src/gui/UBFeaturesWidget.cpp
@@ -10,7 +10,9 @@
#include "globals/UBGlobals.h"
#include "board/UBBoardController.h"
-UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent)
+UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name)
+ : UBDockPaletteWidget(parent)
+ , imageGatherer(NULL)
{
setObjectName(name);
mName = "FeaturesWidget";
@@ -139,6 +141,8 @@ UBFeaturesWidget::~UBFeaturesWidget()
delete thumbSlider;
thumbSlider = NULL;
}
+ if (NULL != imageGatherer)
+ delete imageGatherer;
}
bool UBFeaturesWidget::eventFilter( QObject *target, QEvent *event )
@@ -353,7 +357,19 @@ void UBFeaturesWidget::thumbnailSizeChanged( int value )
void UBFeaturesWidget::onDisplayMetadata( QMap metadata )
{
- UBFeature feature( QString(), QPixmap(":images/libpalette/notFound.png"), QString(), metadata["Url"], FEATURE_ITEM );
+ QString previewImageUrl;
+
+ previewImageUrl = ":images/libpalette/loading.png";
+
+ if (!imageGatherer)
+ imageGatherer = new UBDownloadHttpFile(0, this);
+
+ connect(imageGatherer, SIGNAL(downloadFinished(int, bool, QUrl, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onPreviewLoaded(int, bool, QUrl, QString, QByteArray, QPointF, QSize, bool)));
+
+ // We send here the request and store its reply in order to be able to cancel it if needed
+ imageGatherer->get(QUrl(metadata["Url"]), QPoint(0,0), QSize(), false);
+
+ UBFeature feature( QString(), QPixmap(previewImageUrl), QString(), metadata["Url"], FEATURE_ITEM );
feature.setMetadata( metadata );
featureProperties->showElement( feature );
@@ -361,6 +377,16 @@ void UBFeaturesWidget::onDisplayMetadata( QMap metadata )
mActionBar->setCurrentState( IN_PROPERTIES );
}
+
+void UBFeaturesWidget::onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground)
+{
+ QImage img;
+ img.loadFromData(pData);
+ QPixmap pix = QPixmap::fromImage(img);
+ featureProperties->setOrigPixmap(pix);
+ featureProperties->setThumbnail(pix);
+}
+
void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData)
{
if ( pSuccess )
@@ -738,6 +764,20 @@ UBFeature UBFeatureProperties::getCurrentElement() const
return UBFeature();
}
+void UBFeatureProperties::setOrigPixmap(QPixmap &pix)
+{
+
+ if (mpOrigPixmap)
+ delete mpOrigPixmap;
+
+ mpOrigPixmap = new QPixmap(pix);
+}
+
+void UBFeatureProperties::setThumbnail(QPixmap &pix)
+{
+ mpThumbnail->setPixmap(pix.scaledToWidth(THUMBNAIL_WIDTH));
+}
+
void UBFeatureProperties::adaptSize()
{
if( NULL != mpOrigPixmap )
@@ -819,7 +859,8 @@ void UBFeatureProperties::onAddToPage()
{
QWidget *w = parentWidget()->parentWidget();
UBFeaturesWidget* featuresWidget = dynamic_cast( w );
- featuresWidget->getFeaturesController()->addItemToPage( *mpElement );
+ if (featuresWidget)
+ featuresWidget->getFeaturesController()->addItemToPage( *mpElement );
}
void UBFeatureProperties::onAddToLib()
diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h
index afd29c97..94222f62 100644
--- a/src/gui/UBFeaturesWidget.h
+++ b/src/gui/UBFeaturesWidget.h
@@ -88,7 +88,11 @@ private:
int currentStackedWidget;
+
+ UBDownloadHttpFile* imageGatherer;
+
private slots:
+ void onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void currentSelected( const QModelIndex & );
//void currentPathChanged(const QString &);
void currentPathChanged( const QModelIndex & );
@@ -153,6 +157,9 @@ public:
void showElement(const UBFeature &elem);
UBFeature getCurrentElement() const;
+ void setOrigPixmap(QPixmap &pix);
+ void setThumbnail(QPixmap &pix);
+
protected:
void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event);