diff --git a/qgis_hub_plugin/gui/resource_browser.py b/qgis_hub_plugin/gui/resource_browser.py index c585909..97139be 100644 --- a/qgis_hub_plugin/gui/resource_browser.py +++ b/qgis_hub_plugin/gui/resource_browser.py @@ -318,14 +318,31 @@ 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) 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( + 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) 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)