feat(gui): add shared zoomable image preview
This commit is contained in:
@@ -9,6 +9,7 @@ from PySide6.QtWidgets import QListView, QListWidget, QListWidgetItem, QSizePoli
|
||||
|
||||
from ... import accounts, appconfig, cmhub_models, db, diagnostics, image_studio, image_studio_export, image_studio_images, prompts
|
||||
from .. import file_manager
|
||||
from ..image_preview import ImagePreviewDialog
|
||||
from ..widgets import *
|
||||
from ..workers import (
|
||||
ImageStudioDownloadOriginalWorker as _RealImageStudioDownloadOriginalWorker,
|
||||
@@ -222,38 +223,13 @@ class ImageStudioSelectionList(QListWidget):
|
||||
return None
|
||||
|
||||
|
||||
class ImageStudioPreviewDialog(QDialog):
|
||||
"""Simple large image preview used by original and pool tables."""
|
||||
class ImageStudioPreviewDialog(ImagePreviewDialog):
|
||||
"""Compatibility wrapper for the shared full-image preview."""
|
||||
|
||||
def __init__(self, asset, parent=None):
|
||||
super().__init__(parent)
|
||||
self.asset = asset
|
||||
self.setWindowTitle(self._title_for_asset(asset))
|
||||
layout = QVBoxLayout(self)
|
||||
scroll = QScrollArea()
|
||||
scroll.setWidgetResizable(False)
|
||||
image_label = QLabel()
|
||||
image_label.setAlignment(Qt.AlignCenter)
|
||||
path = str(getattr(asset, "local_path", "") or "")
|
||||
image = QImage(path) if path and os.path.isfile(path) else QImage()
|
||||
if image.isNull():
|
||||
image_label.setText("图片尚未下载或读取失败")
|
||||
image_label.setMinimumSize(420, 260)
|
||||
else:
|
||||
image_label.setPixmap(QPixmap.fromImage(image))
|
||||
image_label.resize(image.size())
|
||||
self.setWindowTitle(
|
||||
f"{self._title_for_asset(asset)} · {image.width()}x{image.height()}"
|
||||
)
|
||||
scroll.setWidget(image_label)
|
||||
layout.addWidget(scroll, 1)
|
||||
buttons = QHBoxLayout()
|
||||
buttons.addStretch(1)
|
||||
close_button = QPushButton("关闭")
|
||||
close_button.clicked.connect(self.reject)
|
||||
buttons.addWidget(close_button)
|
||||
layout.addLayout(buttons)
|
||||
self.resize(720, 520)
|
||||
super().__init__(path, self._title_for_asset(asset), parent)
|
||||
|
||||
def _title_for_asset(self, asset):
|
||||
badge = _asset_badge(getattr(asset, "kind", ""))
|
||||
|
||||
Reference in New Issue
Block a user