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", ""))
|
||||
|
||||
@@ -13,7 +13,6 @@ from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QCheckBox,
|
||||
QComboBox,
|
||||
QDialog,
|
||||
QFileDialog,
|
||||
QFrame,
|
||||
QGridLayout,
|
||||
@@ -43,6 +42,7 @@ from PySide6.QtWidgets import (
|
||||
|
||||
from ... import accounts, appconfig, diagnostics, image_studio, image_studio_images, product_suite
|
||||
from .. import file_manager
|
||||
from ..image_preview import ImagePreviewDialog
|
||||
from ..widgets import COLOR_DANGER, _emit_status, run_worker
|
||||
from ..workers import (
|
||||
ImageStudioDownloadOriginalWorker,
|
||||
@@ -109,42 +109,8 @@ def _user_error(error):
|
||||
return text if len(text) <= 90 else text[:87] + "..."
|
||||
|
||||
|
||||
class ProductSuitePreviewDialog(QDialog):
|
||||
"""Responsive preview for product originals and generated assets."""
|
||||
|
||||
def __init__(self, path, title="图片预览", parent=None):
|
||||
super().__init__(parent)
|
||||
self._source = QPixmap(str(path or ""))
|
||||
self.setWindowTitle(str(title or "图片预览"))
|
||||
layout = QVBoxLayout(self)
|
||||
self.image_label = QLabel()
|
||||
self.image_label.setAlignment(Qt.AlignCenter)
|
||||
self.image_label.setMinimumSize(320, 240)
|
||||
layout.addWidget(self.image_label, 1)
|
||||
close_button = QPushButton("关闭")
|
||||
close_button.clicked.connect(self.accept)
|
||||
button_row = QHBoxLayout()
|
||||
button_row.addStretch(1)
|
||||
button_row.addWidget(close_button)
|
||||
layout.addLayout(button_row)
|
||||
self.resize(820, 620)
|
||||
self._render()
|
||||
|
||||
def resizeEvent(self, event):
|
||||
super().resizeEvent(event)
|
||||
self._render()
|
||||
|
||||
def _render(self):
|
||||
if self._source.isNull():
|
||||
self.image_label.setText("图片文件不存在或无法读取")
|
||||
self.image_label.setPixmap(QPixmap())
|
||||
return
|
||||
target = self.image_label.size() - QSize(16, 16)
|
||||
if target.width() <= 0 or target.height() <= 0:
|
||||
return
|
||||
self.image_label.setPixmap(
|
||||
self._source.scaled(target, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
||||
)
|
||||
class ProductSuitePreviewDialog(ImagePreviewDialog):
|
||||
"""Current product-suite wrapper for the shared full-image preview."""
|
||||
|
||||
|
||||
class ProductOriginalDelegate(QStyledItemDelegate):
|
||||
|
||||
Reference in New Issue
Block a user