thumbnailimageprovider.cpp 989 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "thumbnailimageprovider.h"
  2. #include "FilePathConst.h"
  3. #include <QApplication>
  4. #include <QDebug>
  5. #include <QUrl>
  6. ThumbnailImageProvider::ThumbnailImageProvider()
  7. : QDeclarativeImageProvider(QDeclarativeImageProvider::Image)
  8. {
  9. }
  10. QImage ThumbnailImageProvider::requestImage(const QString & id, QSize * size, const QSize & requestedSize)
  11. {
  12. QString path(QUrl(getThumbnailDataRoot()).toLocalFile());
  13. if (id.startsWith("resourceid"))
  14. {
  15. path += "drm/data/";
  16. }
  17. path += id;
  18. qDebug() << "requestImage " << path;
  19. int width = 100;
  20. int height = 50;
  21. if (size)
  22. *size = QSize(width, height);
  23. QImage image(requestedSize.width() > 0 ? requestedSize.width() : width,
  24. requestedSize.height() > 0 ? requestedSize.height() : height,
  25. QImage::Format_ARGB32_Premultiplied);
  26. if (!image.load(path))
  27. {
  28. qDebug() << "load failed";
  29. }
  30. return image;
  31. }