2016-06-01 01:59:31 +00:00
|
|
|
# Copyright 2016 Hardcoded Software (http://www.hardcoded.net)
|
|
|
|
#
|
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2020-06-05 20:39:16 +00:00
|
|
|
from PyQt5.QtCore import Qt, QSize, pyqtSlot, pyqtSignal
|
|
|
|
from PyQt5.QtGui import QPixmap, QIcon, QKeySequence
|
2020-06-09 23:24:51 +00:00
|
|
|
from PyQt5.QtWidgets import (QVBoxLayout, QAbstractItemView, QHBoxLayout,
|
|
|
|
QLabel, QSizePolicy, QToolBar, QToolButton, QGridLayout, QStyle, QAction,
|
|
|
|
QWidget, QApplication )
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
2020-05-02 00:29:23 +00:00
|
|
|
from hscommon import desktop
|
2016-06-01 01:59:31 +00:00
|
|
|
from ..details_dialog import DetailsDialog as DetailsDialogBase
|
|
|
|
from ..details_table import DetailsTable
|
2020-05-01 16:22:25 +00:00
|
|
|
from qtlib.util import createActions
|
2020-06-10 16:23:48 +00:00
|
|
|
from qt.pe.image_viewer import (QWidgetImageViewer, ScrollAreaImageViewer,
|
2020-06-09 23:24:51 +00:00
|
|
|
QWidgetImageViewerController, QLabelImageViewerController)
|
2020-01-01 02:16:27 +00:00
|
|
|
tr = trget("ui")
|
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
class DetailsDialog(DetailsDialogBase):
|
2009-06-01 09:55:11 +00:00
|
|
|
def __init__(self, parent, app):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController = None
|
2020-06-04 00:33:54 +00:00
|
|
|
super().__init__(parent, app)
|
2020-06-09 23:24:51 +00:00
|
|
|
|
2020-05-01 16:22:25 +00:00
|
|
|
|
2020-06-04 00:33:54 +00:00
|
|
|
def setupActions(self):
|
2020-05-01 16:22:25 +00:00
|
|
|
# (name, shortcut, icon, desc, func)
|
|
|
|
ACTIONS = [
|
|
|
|
(
|
2020-06-04 00:33:54 +00:00
|
|
|
# FIXME probably not used right now
|
2020-05-01 16:22:25 +00:00
|
|
|
"actionSwap",
|
|
|
|
QKeySequence.Backspace,
|
2020-06-09 23:24:51 +00:00
|
|
|
"view-refresh",
|
2020-05-01 16:22:25 +00:00
|
|
|
tr("Swap images"),
|
|
|
|
self.swapImages,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"actionZoomIn",
|
|
|
|
QKeySequence.ZoomIn,
|
|
|
|
"zoom-in",
|
|
|
|
tr("Increase zoom factor"),
|
|
|
|
self.zoomIn,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"actionZoomOut",
|
|
|
|
QKeySequence.ZoomOut,
|
|
|
|
"zoom-out",
|
|
|
|
tr("Decrease zoom factor"),
|
|
|
|
self.zoomOut,
|
|
|
|
),
|
|
|
|
(
|
2020-05-02 13:09:01 +00:00
|
|
|
"actionNormalSize",
|
|
|
|
QKeySequence.Refresh,
|
2020-06-09 23:24:51 +00:00
|
|
|
"zoom-original",
|
2020-05-02 13:09:01 +00:00
|
|
|
tr("Normal size"),
|
|
|
|
self.zoomNormalSize,
|
2020-05-02 16:05:19 +00:00
|
|
|
),
|
2020-05-02 13:09:01 +00:00
|
|
|
(
|
|
|
|
"actionBestFit",
|
2020-06-04 00:33:54 +00:00
|
|
|
tr("Ctrl+p"),
|
2020-06-09 23:24:51 +00:00
|
|
|
"zoom-best-fit",
|
2020-05-02 13:09:01 +00:00
|
|
|
tr("Best fit"),
|
|
|
|
self.zoomBestFit,
|
2020-05-01 16:22:25 +00:00
|
|
|
)
|
|
|
|
]
|
|
|
|
createActions(ACTIONS, self)
|
|
|
|
|
2010-02-05 20:09:04 +00:00
|
|
|
def _setupUi(self):
|
2020-06-04 00:33:54 +00:00
|
|
|
self.setupActions()
|
2011-01-21 12:57:54 +00:00
|
|
|
self.setWindowTitle(tr("Details"))
|
2010-10-04 13:29:00 +00:00
|
|
|
self.resize(502, 295)
|
|
|
|
self.setMinimumSize(QSize(250, 250))
|
|
|
|
self.verticalLayout = QVBoxLayout(self)
|
|
|
|
self.verticalLayout.setSpacing(0)
|
2013-11-16 18:38:07 +00:00
|
|
|
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
2020-05-01 16:22:25 +00:00
|
|
|
# self.horizontalLayout = QHBoxLayout()
|
|
|
|
self.horizontalLayout = QGridLayout()
|
|
|
|
self.horizontalLayout.setColumnMinimumWidth(1, 30)
|
|
|
|
self.horizontalLayout.setColumnStretch(0,1)
|
|
|
|
self.horizontalLayout.setColumnStretch(1,0)
|
|
|
|
self.horizontalLayout.setColumnStretch(2,1)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.horizontalLayout.setSpacing(4)
|
2020-06-04 00:33:54 +00:00
|
|
|
|
2020-06-09 23:24:51 +00:00
|
|
|
self.selectedImageViewer = QWidgetImageViewer(
|
|
|
|
self, "selectedImage")
|
2020-05-02 16:05:19 +00:00
|
|
|
# self.selectedImage = QLabel(self)
|
|
|
|
# sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
|
|
|
|
# sizePolicy.setHorizontalStretch(0)
|
|
|
|
# sizePolicy.setVerticalStretch(0)
|
|
|
|
# sizePolicy.setHeightForWidth(
|
|
|
|
# self.selectedImage.sizePolicy().hasHeightForWidth()
|
|
|
|
# )
|
|
|
|
# self.selectedImage.setSizePolicy(sizePolicy)
|
|
|
|
# self.selectedImage.setScaledContents(False)
|
|
|
|
# self.selectedImage.setAlignment(Qt.AlignCenter)
|
|
|
|
# # self.horizontalLayout.addWidget(self.selectedImage)
|
2020-06-09 23:24:51 +00:00
|
|
|
self.horizontalLayout.addWidget(self.selectedImageViewer, 0, 0, 3, 1)
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
self.verticalToolBar = QToolBar(self)
|
|
|
|
self.verticalToolBar.setOrientation(Qt.Orientation(2))
|
|
|
|
# self.subVLayout = QVBoxLayout(self)
|
|
|
|
# self.subVLayout.addWidget(self.verticalToolBar)
|
|
|
|
# self.horizontalLayout.addLayout(self.subVLayout)
|
|
|
|
|
|
|
|
self.buttonImgSwap = QToolButton(self.verticalToolBar)
|
|
|
|
self.buttonImgSwap.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
2020-06-09 23:24:51 +00:00
|
|
|
self.buttonImgSwap.setIcon(QIcon.fromTheme('view-refresh', \
|
2020-05-01 16:22:25 +00:00
|
|
|
self.style().standardIcon(QStyle.SP_BrowserReload)))
|
|
|
|
self.buttonImgSwap.setText('Swap images')
|
2020-06-04 00:33:54 +00:00
|
|
|
self.buttonImgSwap.setToolTip('Swap images')
|
2020-05-01 16:22:25 +00:00
|
|
|
self.buttonImgSwap.pressed.connect(self.swapImages)
|
2020-06-04 00:33:54 +00:00
|
|
|
self.buttonImgSwap.released.connect(self.deswapImages)
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
self.buttonZoomIn = QToolButton(self.verticalToolBar)
|
|
|
|
self.buttonZoomIn.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
|
|
|
self.buttonZoomIn.setDefaultAction(self.actionZoomIn)
|
|
|
|
self.buttonZoomIn.setText('ZoomIn')
|
2020-06-09 23:24:51 +00:00
|
|
|
self.buttonZoomIn.setIcon(QIcon.fromTheme('zoom-in'))
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
self.buttonZoomOut = QToolButton(self.verticalToolBar)
|
|
|
|
self.buttonZoomOut.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
|
|
|
self.buttonZoomOut.setDefaultAction(self.actionZoomOut)
|
|
|
|
self.buttonZoomOut.setText('ZoomOut')
|
|
|
|
self.buttonZoomOut.setIcon(QIcon.fromTheme('zoom-out'))
|
|
|
|
self.buttonZoomOut.setEnabled(False)
|
|
|
|
|
2020-05-02 13:09:01 +00:00
|
|
|
self.buttonNormalSize = QToolButton(self.verticalToolBar)
|
|
|
|
self.buttonNormalSize.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
|
|
|
self.buttonNormalSize.setDefaultAction(self.actionNormalSize)
|
|
|
|
self.buttonNormalSize.setText('Normal Size')
|
|
|
|
self.buttonNormalSize.setIcon(QIcon.fromTheme('zoom-original'))
|
|
|
|
self.buttonNormalSize.setEnabled(True)
|
|
|
|
|
|
|
|
self.buttonBestFit = QToolButton(self.verticalToolBar)
|
|
|
|
self.buttonBestFit.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
2020-05-02 16:05:19 +00:00
|
|
|
self.buttonBestFit.setDefaultAction(self.actionBestFit)
|
2020-05-02 13:09:01 +00:00
|
|
|
self.buttonBestFit.setText('BestFit')
|
|
|
|
self.buttonBestFit.setIcon(QIcon.fromTheme('zoom-best-fit'))
|
|
|
|
self.buttonBestFit.setEnabled(False)
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
self.verticalToolBar.addWidget(self.buttonImgSwap)
|
|
|
|
self.verticalToolBar.addWidget(self.buttonZoomIn)
|
|
|
|
self.verticalToolBar.addWidget(self.buttonZoomOut)
|
2020-05-02 13:09:01 +00:00
|
|
|
self.verticalToolBar.addWidget(self.buttonNormalSize)
|
|
|
|
self.verticalToolBar.addWidget(self.buttonBestFit)
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
self.horizontalLayout.addWidget(self.verticalToolBar, 1, 1, 1, 1, Qt.AlignCenter)
|
|
|
|
# self.horizontalLayout.addWidget(self.verticalToolBar, Qt.AlignVCenter)
|
|
|
|
|
2020-06-09 23:24:51 +00:00
|
|
|
self.referenceImageViewer = QWidgetImageViewer(
|
|
|
|
self, "referenceImage")
|
2020-06-04 00:33:54 +00:00
|
|
|
# self.referenceImage = QLabel(self)
|
|
|
|
# sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
|
|
|
|
# sizePolicy.setHorizontalStretch(0)
|
|
|
|
# sizePolicy.setVerticalStretch(0)
|
|
|
|
# sizePolicy.setHeightForWidth(
|
|
|
|
# self.referenceImage.sizePolicy().hasHeightForWidth()
|
|
|
|
# )
|
|
|
|
# self.referenceImage.setSizePolicy(sizePolicy)
|
|
|
|
# self.referenceImage.setAlignment(Qt.AlignCenter)
|
2020-06-09 23:24:51 +00:00
|
|
|
self.horizontalLayout.addWidget(self.referenceImageViewer, 0, 2, 3, 1)
|
2020-05-01 16:22:25 +00:00
|
|
|
# self.horizontalLayout.addWidget(self.referenceImage)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout.addLayout(self.horizontalLayout)
|
|
|
|
self.tableView = DetailsTable(self)
|
|
|
|
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
|
|
|
sizePolicy.setHeightForWidth(self.tableView.sizePolicy().hasHeightForWidth())
|
|
|
|
self.tableView.setSizePolicy(sizePolicy)
|
|
|
|
self.tableView.setMinimumSize(QSize(0, 188))
|
|
|
|
self.tableView.setMaximumSize(QSize(16777215, 190))
|
|
|
|
self.tableView.setAlternatingRowColors(True)
|
|
|
|
self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
|
|
|
|
self.tableView.setShowGrid(False)
|
|
|
|
self.verticalLayout.addWidget(self.tableView)
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2020-06-05 20:39:16 +00:00
|
|
|
self.disable_buttons()
|
2020-06-09 23:24:51 +00:00
|
|
|
# We use different types of controller depending on the
|
|
|
|
# underlying widgets we use to display images
|
|
|
|
# because their interface methods might differ
|
|
|
|
if isinstance(self.selectedImageViewer, QWidgetImageViewer):
|
|
|
|
self.vController = QWidgetImageViewerController(
|
|
|
|
self.selectedImageViewer,
|
|
|
|
self.referenceImageViewer,
|
|
|
|
self)
|
|
|
|
elif isinstance(self.selectedImageViewer, ScrollAreaImageViewer):
|
2020-06-10 16:23:48 +00:00
|
|
|
self.vController = QLabelImageViewerController(
|
2020-06-09 23:24:51 +00:00
|
|
|
self.selectedImageViewer,
|
|
|
|
self.referenceImageViewer,
|
|
|
|
self)
|
|
|
|
|
2020-06-04 15:38:28 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _update(self):
|
2011-09-20 19:06:29 +00:00
|
|
|
if not self.app.model.selected_dupes:
|
2020-06-05 20:39:16 +00:00
|
|
|
self.clear_all()
|
2009-06-01 09:55:11 +00:00
|
|
|
return
|
2011-09-20 19:06:29 +00:00
|
|
|
dupe = self.app.model.selected_dupes[0]
|
|
|
|
group = self.app.model.results.get_group_of_duplicate(dupe)
|
2009-06-01 09:55:11 +00:00
|
|
|
ref = group.ref
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2020-06-09 23:24:51 +00:00
|
|
|
if self.vController is None:
|
|
|
|
return
|
|
|
|
self.vController.update(ref, dupe)
|
2020-05-02 00:29:23 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _updateImages(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
if not self.vController.bestFit:
|
|
|
|
return
|
|
|
|
self.vController._updateImages()
|
2020-06-05 20:39:16 +00:00
|
|
|
|
|
|
|
def clear_all(self):
|
|
|
|
"""No item from the model, disable and clear everything."""
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.clear_all()
|
2020-06-05 20:39:16 +00:00
|
|
|
|
|
|
|
def disable_buttons(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
# FIXME Only called once at startup
|
2020-06-05 20:39:16 +00:00
|
|
|
self.buttonImgSwap.setEnabled(False)
|
|
|
|
self.buttonZoomIn.setEnabled(False)
|
|
|
|
self.buttonZoomOut.setEnabled(False)
|
|
|
|
self.buttonNormalSize.setEnabled(False)
|
|
|
|
self.buttonBestFit.setEnabled(False)
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Override
|
2009-06-01 09:55:11 +00:00
|
|
|
def resizeEvent(self, event):
|
2020-06-09 23:24:51 +00:00
|
|
|
if self.vController is None:
|
2020-06-04 00:33:54 +00:00
|
|
|
return
|
2009-06-01 09:55:11 +00:00
|
|
|
self._updateImages()
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def show(self):
|
2010-02-05 20:09:04 +00:00
|
|
|
DetailsDialogBase.show(self)
|
2009-06-01 09:55:11 +00:00
|
|
|
self._update()
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2010-02-05 20:09:04 +00:00
|
|
|
# model --> view
|
|
|
|
def refresh(self):
|
|
|
|
DetailsDialogBase.refresh(self)
|
2009-06-01 09:55:11 +00:00
|
|
|
if self.isVisible():
|
|
|
|
self._update()
|
2020-05-01 16:22:25 +00:00
|
|
|
|
2020-06-05 20:39:16 +00:00
|
|
|
# ImageViewers
|
2020-05-01 16:22:25 +00:00
|
|
|
def scaleImages(self, factor):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.scaleImages(factor)
|
2020-05-01 16:22:25 +00:00
|
|
|
|
2020-06-04 00:33:54 +00:00
|
|
|
@pyqtSlot()
|
2020-05-01 16:22:25 +00:00
|
|
|
def swapImages(self):
|
2020-06-05 20:39:16 +00:00
|
|
|
"""Swap pixmaps between ImageViewers."""
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.swapImages()
|
2020-05-01 16:22:25 +00:00
|
|
|
# swap the columns in the details table as well
|
|
|
|
self.tableView.horizontalHeader().swapSections(1, 2)
|
|
|
|
|
2020-06-04 00:33:54 +00:00
|
|
|
@pyqtSlot()
|
|
|
|
def deswapImages(self):
|
2020-06-05 20:39:16 +00:00
|
|
|
"""Restore swapped pixmaps between ImageViewers."""
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.deswapImages()
|
|
|
|
# deswap the columns in the details table as well
|
2020-06-04 00:33:54 +00:00
|
|
|
self.tableView.horizontalHeader().swapSections(1, 2)
|
|
|
|
|
|
|
|
@pyqtSlot()
|
2020-05-01 16:22:25 +00:00
|
|
|
def zoomIn(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.scaleImages(1.25)
|
2020-05-01 16:22:25 +00:00
|
|
|
|
2020-06-04 00:33:54 +00:00
|
|
|
@pyqtSlot()
|
2020-05-01 16:22:25 +00:00
|
|
|
def zoomOut(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.scaleImages(0.8)
|
2020-05-02 13:09:01 +00:00
|
|
|
|
2020-06-04 00:33:54 +00:00
|
|
|
@pyqtSlot()
|
|
|
|
def scale_to_bestfit(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.scale_to_bestfit()
|
2020-05-01 16:22:25 +00:00
|
|
|
|
2020-06-04 00:33:54 +00:00
|
|
|
@pyqtSlot()
|
2020-05-02 13:09:01 +00:00
|
|
|
def zoomBestFit(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.zoomBestFit()
|
2020-06-04 00:33:54 +00:00
|
|
|
self.scale_to_bestfit()
|
|
|
|
|
|
|
|
@pyqtSlot()
|
|
|
|
def zoomNormalSize(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.zoomNormalSize()
|