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-20 23:49:17 +00:00
|
|
|
from PyQt5.QtWidgets import (QLayout, QVBoxLayout, QAbstractItemView, QHBoxLayout,
|
2020-06-09 23:24:51 +00:00
|
|
|
QLabel, QSizePolicy, QToolBar, QToolButton, QGridLayout, QStyle, QAction,
|
2020-06-20 23:49:17 +00:00
|
|
|
QWidget, QApplication, QSpacerItem )
|
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-16 19:14:28 +00:00
|
|
|
from qt.pe.image_viewer import (
|
|
|
|
QWidgetImageViewer, ScrollAreaImageViewer, GraphicsViewViewer,
|
|
|
|
QWidgetController, ScrollAreaController, GraphicsViewController)
|
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 = [
|
|
|
|
(
|
|
|
|
"actionZoomIn",
|
|
|
|
QKeySequence.ZoomIn,
|
|
|
|
"zoom-in",
|
2020-06-20 23:49:17 +00:00
|
|
|
tr("Increase zoom"),
|
2020-05-01 16:22:25 +00:00
|
|
|
self.zoomIn,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"actionZoomOut",
|
|
|
|
QKeySequence.ZoomOut,
|
|
|
|
"zoom-out",
|
2020-06-20 23:49:17 +00:00
|
|
|
tr("Decrease zoom"),
|
2020-05-01 16:22:25 +00:00
|
|
|
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()
|
2020-06-20 23:49:17 +00:00
|
|
|
# Minimum width for the toolbar in the middle:
|
2020-05-01 16:22:25 +00:00
|
|
|
self.horizontalLayout.setColumnMinimumWidth(1, 30)
|
|
|
|
self.horizontalLayout.setColumnStretch(0,1)
|
|
|
|
self.horizontalLayout.setColumnStretch(1,0)
|
|
|
|
self.horizontalLayout.setColumnStretch(2,1)
|
2020-06-20 23:49:17 +00:00
|
|
|
# self.horizontalLayout.setColumnStretch(3,0)
|
|
|
|
self.horizontalLayout.setSpacing(2)
|
2020-06-04 00:33:54 +00:00
|
|
|
|
2020-06-20 23:49:17 +00:00
|
|
|
self.selectedImageViewer = ScrollAreaImageViewer(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
|
|
|
|
2020-06-20 23:49:17 +00:00
|
|
|
# self.horizontalLayout.addItem(QSpacerItem(5,0, QSizePolicy.Minimum),
|
|
|
|
# 1, 3, 1, 1, Qt.Alignment(Qt.AlignRight))
|
|
|
|
|
2020-05-01 16:22:25 +00:00
|
|
|
self.verticalToolBar = QToolBar(self)
|
2020-06-20 23:49:17 +00:00
|
|
|
self.verticalToolBar.setOrientation(Qt.Orientation(Qt.Vertical))
|
2020-05-01 16:22:25 +00:00
|
|
|
# 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-16 19:14:28 +00:00
|
|
|
self.buttonImgSwap.released.connect(self.swapImages)
|
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-20 23:49:17 +00:00
|
|
|
self.referenceImageViewer = ScrollAreaImageViewer(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()
|
|
|
|
# )
|
2020-06-20 23:49:17 +00:00
|
|
|
# self.referenceImageViewer.setSizePolicy(sizePolicy)
|
|
|
|
# self.referenceImageViewer.setAlignment(Qt.AlignCenter)
|
2020-06-09 23:24:51 +00:00
|
|
|
self.horizontalLayout.addWidget(self.referenceImageViewer, 0, 2, 3, 1)
|
2020-06-20 23:49:17 +00:00
|
|
|
# self.horizontalLayout.addWidget(self.referenceImageViewer)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.verticalLayout.addLayout(self.horizontalLayout)
|
2020-06-20 23:49:17 +00:00
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
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)
|
2020-06-20 23:49:17 +00:00
|
|
|
self.tableView.hide()
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2020-06-10 20:02:08 +00:00
|
|
|
self.buttonImgSwap.setEnabled(False)
|
|
|
|
self.buttonZoomIn.setEnabled(False)
|
|
|
|
self.buttonZoomOut.setEnabled(False)
|
|
|
|
self.buttonNormalSize.setEnabled(False)
|
|
|
|
self.buttonBestFit.setEnabled(False)
|
|
|
|
|
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):
|
2020-06-16 19:14:28 +00:00
|
|
|
self.vController = QWidgetController(
|
2020-06-09 23:24:51 +00:00
|
|
|
self.selectedImageViewer,
|
|
|
|
self.referenceImageViewer,
|
|
|
|
self)
|
|
|
|
elif isinstance(self.selectedImageViewer, ScrollAreaImageViewer):
|
2020-06-16 19:14:28 +00:00
|
|
|
self.vController = ScrollAreaController(
|
|
|
|
self.selectedImageViewer,
|
|
|
|
self.referenceImageViewer,
|
|
|
|
self)
|
|
|
|
elif isinstance(self.selectedImageViewer, GraphicsViewViewer):
|
|
|
|
self.vController = GraphicsViewController(
|
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-16 19:14:28 +00:00
|
|
|
# No item from the model, disable and clear everything.
|
|
|
|
self.vController.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
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Override
|
2009-06-01 09:55:11 +00:00
|
|
|
def resizeEvent(self, event):
|
2020-06-20 23:49:17 +00:00
|
|
|
# HACK referenceViewer might be 1 pixel shorter in width
|
|
|
|
# due to dynamic resizing in the GridLayout's engine
|
|
|
|
# Couldn't find a way to ensure both viewers have the exact same size
|
|
|
|
# at all time without using resize().
|
|
|
|
self.horizontalLayout.setColumnMinimumWidth(
|
|
|
|
0, self.selectedImageViewer.size().width())
|
|
|
|
self.horizontalLayout.setColumnMinimumWidth(
|
|
|
|
2, self.selectedImageViewer.size().width())
|
|
|
|
|
|
|
|
if self.vController is None or not self.vController.bestFit:
|
2020-06-04 00:33:54 +00:00
|
|
|
return
|
2020-06-20 23:49:17 +00:00
|
|
|
# Only update the scaled down pixmaps
|
|
|
|
self.vController._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-06-04 00:33:54 +00:00
|
|
|
@pyqtSlot()
|
2020-05-01 16:22:25 +00:00
|
|
|
def swapImages(self):
|
2020-06-10 20:02:08 +00:00
|
|
|
self.vController.swapPixmaps()
|
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()
|
2020-05-01 16:22:25 +00:00
|
|
|
def zoomIn(self):
|
2020-06-20 23:49:17 +00:00
|
|
|
self.vController.scaleImagesBy(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-20 23:49:17 +00:00
|
|
|
self.vController.scaleImagesBy(0.8)
|
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-20 23:49:17 +00:00
|
|
|
self.vController.ScaleToBestFit()
|
2020-06-04 00:33:54 +00:00
|
|
|
|
|
|
|
@pyqtSlot()
|
|
|
|
def zoomNormalSize(self):
|
2020-06-09 23:24:51 +00:00
|
|
|
self.vController.zoomNormalSize()
|