From 4e95237574cfabb2091ef36fbb95192f7e221bc1 Mon Sep 17 00:00:00 2001 From: Ronit Jadhav Date: Thu, 27 Jul 2023 10:20:04 +0200 Subject: [PATCH 1/3] loading the thumbnail_full in preview --- qgis_hub_plugin/gui/resource_browser.py | 4 +++- qgis_hub_plugin/gui/resource_item.py | 5 ++++- qgis_hub_plugin/utilities/common.py | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/qgis_hub_plugin/gui/resource_browser.py b/qgis_hub_plugin/gui/resource_browser.py index c585909..d544a95 100644 --- a/qgis_hub_plugin/gui/resource_browser.py +++ b/qgis_hub_plugin/gui/resource_browser.py @@ -318,7 +318,9 @@ def update_preview(self): self.show_preview() # Thumbnail - thumbnail_path = download_resource_thumbnail(resource.thumbnail, resource.uuid) + thumbnail_path = download_resource_thumbnail( + resource.thumbnail_full, resource.uuid, "thumbnails_full" + ) pixmap = QPixmap(str(thumbnail_path.absolute())) if not pixmap.isNull(): item = QGraphicsPixmapItem(pixmap) diff --git a/qgis_hub_plugin/gui/resource_item.py b/qgis_hub_plugin/gui/resource_item.py index 6fa132c..f6d0a41 100644 --- a/qgis_hub_plugin/gui/resource_item.py +++ b/qgis_hub_plugin/gui/resource_item.py @@ -27,11 +27,14 @@ def __init__(self, params: dict): self.description = params.get("description") self.file = params.get("file") self.thumbnail = params.get("thumbnail") + self.thumbnail_full = params.get("thumbnail_full") # Custom attribute self.setText(self.name) self.setToolTip(f"{self.name} by {self.creator}") - thumbnail_path = download_resource_thumbnail(self.thumbnail, self.uuid) + thumbnail_path = download_resource_thumbnail( + self.thumbnail, self.uuid, "thumbnails" + ) if thumbnail_path: self.setIcon(QIcon(str(thumbnail_path))) else: diff --git a/qgis_hub_plugin/utilities/common.py b/qgis_hub_plugin/utilities/common.py index 13fd174..73825bb 100644 --- a/qgis_hub_plugin/utilities/common.py +++ b/qgis_hub_plugin/utilities/common.py @@ -25,7 +25,7 @@ def download_file(url: str, file_path: Path, force: bool = False): return file_path.exists() -def download_resource_thumbnail(url: str, uuid: str): +def download_resource_thumbnail(url: str, uuid: str, folder: str): qgis_user_dir = QgsApplication.qgisSettingsDirPath() # Assume it as jpg extension = ".jpg" @@ -34,7 +34,7 @@ def download_resource_thumbnail(url: str, uuid: str): except IndexError(): pass - thumbnail_dir = Path(qgis_user_dir, "qgis_hub", "thumbnails") + thumbnail_dir = Path(qgis_user_dir, "qgis_hub", folder) thumbnail_path = Path(thumbnail_dir, f"{uuid}.{extension}") if not thumbnail_dir.exists(): thumbnail_dir.mkdir(parents=True, exist_ok=True) From f5947baca8a10a1fe31a06e0303ee6eab889f059 Mon Sep 17 00:00:00 2001 From: Ronit Jadhav Date: Thu, 27 Jul 2023 10:49:43 +0200 Subject: [PATCH 2/3] load from thumbnail if thumbnail_full does not work --- qgis_hub_plugin/gui/resource_browser.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qgis_hub_plugin/gui/resource_browser.py b/qgis_hub_plugin/gui/resource_browser.py index d544a95..745e0c8 100644 --- a/qgis_hub_plugin/gui/resource_browser.py +++ b/qgis_hub_plugin/gui/resource_browser.py @@ -328,6 +328,17 @@ def update_preview(self): self.graphicsViewPreview.scene().clear() self.graphicsViewPreview.scene().addItem(item) self.graphicsViewPreview.fitInView(item, Qt.KeepAspectRatio) + else: + thumbnail_path = download_resource_thumbnail( + resource.thumbnail, resource.uuid, "thumbnails" + ) + pixmap = QPixmap(str(thumbnail_path.absolute())) + if not pixmap.isNull(): + item = QGraphicsPixmapItem(pixmap) + + self.graphicsViewPreview.scene().clear() + self.graphicsViewPreview.scene().addItem(item) + self.graphicsViewPreview.fitInView(item, Qt.KeepAspectRatio) # Description self.labelName.setText(resource.name) From ea3032a2177e2884b67d82e286678cbcf86e7e1d Mon Sep 17 00:00:00 2001 From: Ronit Jadhav Date: Thu, 27 Jul 2023 11:36:10 +0200 Subject: [PATCH 3/3] center align thumbnail_full in preview --- qgis_hub_plugin/gui/resource_browser.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qgis_hub_plugin/gui/resource_browser.py b/qgis_hub_plugin/gui/resource_browser.py index 745e0c8..97139be 100644 --- a/qgis_hub_plugin/gui/resource_browser.py +++ b/qgis_hub_plugin/gui/resource_browser.py @@ -327,6 +327,10 @@ def update_preview(self): self.graphicsViewPreview.scene().clear() self.graphicsViewPreview.scene().addItem(item) + # Center-align the image + center = self.graphicsViewPreview.rect().center() + item.setPos(center - item.boundingRect().center()) + self.graphicsViewPreview.fitInView(item, Qt.KeepAspectRatio) else: thumbnail_path = download_resource_thumbnail(