Guest User

Untitled

a guest
Jul 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <QObject>
  2. #include <QImage>
  3. #include "ImageProvider.h"
  4.  
  5. class Item : public QObject
  6. {
  7. Q_OBJECT
  8. Q_PROPERTY(QImage getItemPhoto READ getItemPhoto WRITE setItemPhoto NOTIFY photoChanged)
  9.  
  10. public:
  11. // ---- PUBLIC METHODS ----
  12. //! Sets up unique ID for Item
  13. explicit Item();
  14.  
  15. //! Returns image source path
  16. QImage getItemPhoto() const { return photo_; }
  17.  
  18. //! Sets source path for the image of the Item
  19. void setItemPhoto(const QImage &imageSource);
  20.  
  21. signals:
  22. // ---- SIGNALS ----
  23.  
  24. photoChanged();
  25.  
  26. private:
  27. // ---- PRIVATE METHODS ----
  28. //! Set id of Item
  29. void setId(const int &ID);
  30.  
  31. private:
  32. // ---- PRIVATE ATTRIBUTES ---
  33.  
  34. QImage photo_;
  35.  
  36. QImage heatMap_;
  37. };
  38.  
  39. #include <QObject>
  40. #include <QImage>
  41. #include <QQuickImageProvider>
  42.  
  43. class ImageProvider : public QObject, QQuickImageProvider
  44. {
  45. Q_OBJECT
  46. public:
  47. ImageProvider();
  48.  
  49. QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
  50.  
  51. public slots:
  52. void setPhoto(const QImage &photo);
  53.  
  54. signals:
  55. void photoChanged();
  56.  
  57. private:
  58. QImage photo_;
  59. };
  60.  
  61. #include "ImageProvider.h"
  62.  
  63. ImageProvider::ImageProvider() : QQuickImageProvider(QQuickImageProvider::Image)
  64. {
  65. this->blockSignals(false);
  66. }
  67.  
  68. QImage ImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
  69. {
  70. Q_UNUSED(id)
  71. QImage res = this->photo_;
  72.  
  73. if(res.isNull())
  74. return QImage();
  75.  
  76. if(size)
  77. {
  78. *size = res.size();
  79. }
  80.  
  81. if(requestedSize.width() > 0 && requestedSize.height() > 0)
  82. res = res.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio); //TODO
  83.  
  84. return res;
  85. }
  86.  
  87. void ImageProvider::setPhoto(const QImage &photo)
  88. {
  89. if(photo_ != photo)
  90. {
  91. photo_ = photo;
  92. emit photoChanged();
  93. }
  94. }
  95.  
  96. GridView {
  97. //....
  98. model:filterModel
  99.  
  100. delegate: Image {
  101. id: item
  102. //....
  103. source: item.getItemPhoto //item is role name for Item
  104. }
  105. }
Add Comment
Please, Sign In to add comment