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-05-02 00:29:23 +00:00
|
|
|
from PyQt5.QtCore import Qt, QSize, pyqtSignal, QModelIndex
|
2020-05-01 16:22:25 +00:00
|
|
|
from PyQt5.QtGui import QPixmap, QIcon, QKeySequence
|
2020-01-01 02:16:27 +00:00
|
|
|
from PyQt5.QtWidgets import (
|
|
|
|
QVBoxLayout,
|
|
|
|
QAbstractItemView,
|
|
|
|
QHBoxLayout,
|
|
|
|
QLabel,
|
|
|
|
QSizePolicy,
|
2020-05-01 16:22:25 +00:00
|
|
|
QToolBar,
|
|
|
|
QToolButton,
|
|
|
|
QGridLayout,
|
|
|
|
QStyle,
|
|
|
|
QAction
|
2020-01-01 02:16:27 +00:00
|
|
|
)
|
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
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
tr = trget("ui")
|
|
|
|
|
2020-05-02 00:29:23 +00:00
|
|
|
class ClickableLabel(QLabel):
|
|
|
|
def __init__(self, parent):
|
|
|
|
QLabel.__init__(self, parent)
|
|
|
|
self.path = ""
|
|
|
|
|
|
|
|
def mouseDoubleClickEvent(self, event):
|
|
|
|
self.doubleClicked.emit()
|
|
|
|
|
|
|
|
doubleClicked = pyqtSignal()
|
2011-11-01 19:44:18 +00:00
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
class DetailsDialog(DetailsDialogBase):
|
2009-06-01 09:55:11 +00:00
|
|
|
def __init__(self, parent, app):
|
2010-02-05 20:09:04 +00:00
|
|
|
DetailsDialogBase.__init__(self, parent, app)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.selectedPixmap = None
|
|
|
|
self.referencePixmap = None
|
2020-05-02 00:29:23 +00:00
|
|
|
self.scaleFactor = 0
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
def _setupActions(self):
|
|
|
|
# (name, shortcut, icon, desc, func)
|
|
|
|
ACTIONS = [
|
|
|
|
(
|
|
|
|
"actionSwap",
|
|
|
|
QKeySequence.Backspace,
|
|
|
|
"swap",
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"actionZoomReset",
|
|
|
|
QKeySequence.Refresh,
|
|
|
|
"zoom-reset",
|
|
|
|
tr("Reset zoom factor"),
|
|
|
|
self.zoomReset,
|
|
|
|
)
|
|
|
|
]
|
|
|
|
createActions(ACTIONS, self)
|
|
|
|
|
|
|
|
# special case as it resets when button is released
|
|
|
|
# self.actionSwap = QAction(self)
|
|
|
|
# # self.actionSwap.setIcon(QIcon(QPixmap()))
|
|
|
|
# self.actionSwap.setShortcut(QKeySequence.Backspace)
|
|
|
|
# self.actionSwap.setText(tr("Swap images"))
|
|
|
|
# self.actionSwap.pressed.connect(self.swapImages)
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2010-02-05 20:09:04 +00:00
|
|
|
def _setupUi(self):
|
2020-05-01 16:22:25 +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-05-02 00:29:23 +00:00
|
|
|
self.selectedImage = ClickableLabel(self)
|
2010-10-04 13:29:00 +00:00
|
|
|
sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
|
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
2020-01-01 02:16:27 +00:00
|
|
|
sizePolicy.setHeightForWidth(
|
|
|
|
self.selectedImage.sizePolicy().hasHeightForWidth()
|
|
|
|
)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.selectedImage.setSizePolicy(sizePolicy)
|
|
|
|
self.selectedImage.setScaledContents(False)
|
|
|
|
self.selectedImage.setAlignment(Qt.AlignCenter)
|
2020-05-01 16:22:25 +00:00
|
|
|
# self.horizontalLayout.addWidget(self.selectedImage)
|
2020-05-02 00:29:23 +00:00
|
|
|
self.selectedImage.doubleClicked.connect(self.mouseDoubleClickedEvent)
|
2020-05-01 16:22:25 +00:00
|
|
|
self.horizontalLayout.addWidget(self.selectedImage, 0, 0, 3, 1)
|
|
|
|
|
|
|
|
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)
|
|
|
|
self.buttonImgSwap.setIcon(QIcon.fromTheme('document-revert', \
|
|
|
|
self.style().standardIcon(QStyle.SP_BrowserReload)))
|
|
|
|
self.buttonImgSwap.setText('Swap images')
|
|
|
|
self.buttonImgSwap.pressed.connect(self.swapImages)
|
|
|
|
self.buttonImgSwap.released.connect(self.swapImages)
|
|
|
|
|
|
|
|
self.buttonZoomIn = QToolButton(self.verticalToolBar)
|
|
|
|
self.buttonZoomIn.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
|
|
|
self.buttonZoomIn.setDefaultAction(self.actionZoomIn)
|
|
|
|
self.buttonZoomIn.setText('ZoomIn')
|
|
|
|
self.buttonZoomIn.setIcon(QIcon.fromTheme(('zoom-in'), QIcon(":images/zoom-in.png")))
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
self.buttonResetZoom = QToolButton(self.verticalToolBar)
|
|
|
|
self.buttonResetZoom.setToolButtonStyle(Qt.ToolButtonIconOnly)
|
|
|
|
self.buttonResetZoom.setDefaultAction(self.actionZoomReset)
|
|
|
|
self.buttonResetZoom.setText('ResetZoom')
|
|
|
|
self.buttonResetZoom.setIcon(QIcon.fromTheme('zoom-original'))
|
|
|
|
self.buttonResetZoom.setEnabled(False)
|
|
|
|
|
|
|
|
self.verticalToolBar.addWidget(self.buttonImgSwap)
|
|
|
|
self.verticalToolBar.addWidget(self.buttonZoomIn)
|
|
|
|
self.verticalToolBar.addWidget(self.buttonZoomOut)
|
|
|
|
self.verticalToolBar.addWidget(self.buttonResetZoom)
|
|
|
|
|
|
|
|
self.horizontalLayout.addWidget(self.verticalToolBar, 1, 1, 1, 1, Qt.AlignCenter)
|
|
|
|
# self.horizontalLayout.addWidget(self.verticalToolBar, Qt.AlignVCenter)
|
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
self.referenceImage = QLabel(self)
|
|
|
|
sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
|
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
2020-01-01 02:16:27 +00:00
|
|
|
sizePolicy.setHeightForWidth(
|
|
|
|
self.referenceImage.sizePolicy().hasHeightForWidth()
|
|
|
|
)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.referenceImage.setSizePolicy(sizePolicy)
|
|
|
|
self.referenceImage.setAlignment(Qt.AlignCenter)
|
2020-05-01 16:22:25 +00:00
|
|
|
self.horizontalLayout.addWidget(self.referenceImage, 0, 2, 3, 1)
|
|
|
|
# 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
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _update(self):
|
2020-05-02 00:29:23 +00:00
|
|
|
self._updateButtons()
|
2011-09-20 19:06:29 +00:00
|
|
|
if not self.app.model.selected_dupes:
|
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
|
|
|
|
2010-08-11 14:39:06 +00:00
|
|
|
self.selectedPixmap = QPixmap(str(dupe.path))
|
2009-06-01 09:55:11 +00:00
|
|
|
if ref is dupe:
|
2009-10-03 12:29:16 +00:00
|
|
|
self.referencePixmap = None
|
2020-05-01 16:22:25 +00:00
|
|
|
self.buttonImgSwap.setEnabled(False)
|
2009-06-01 09:55:11 +00:00
|
|
|
else:
|
2010-08-11 14:39:06 +00:00
|
|
|
self.referencePixmap = QPixmap(str(ref.path))
|
2020-05-01 16:22:25 +00:00
|
|
|
self.buttonImgSwap.setEnabled(True)
|
2020-05-02 00:29:23 +00:00
|
|
|
self.scaleFactor = 0
|
|
|
|
|
|
|
|
self._updateButtons()
|
2009-06-01 09:55:11 +00:00
|
|
|
self._updateImages()
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2020-05-02 00:29:23 +00:00
|
|
|
def _updateButtons(self):
|
|
|
|
if 0 < self.scaleFactor < 10:
|
|
|
|
self.buttonZoomIn.setEnabled(True)
|
|
|
|
self.buttonZoomOut.setEnabled(True)
|
|
|
|
self.buttonResetZoom.setEnabled(True)
|
|
|
|
elif self.scaleFactor >= 10:
|
|
|
|
self.buttonZoomIn.setEnabled(False)
|
|
|
|
else: # scaleFactor == 0
|
|
|
|
self.buttonZoomIn.setEnabled(True)
|
|
|
|
self.buttonZoomOut.setEnabled(False)
|
|
|
|
self.buttonResetZoom.setEnabled(False)
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _updateImages(self):
|
|
|
|
if self.selectedPixmap is not None:
|
|
|
|
target_size = self.selectedImage.size()
|
2020-05-02 00:29:23 +00:00
|
|
|
if self.scaleFactor:
|
|
|
|
scaledPixmap = self.selectedPixmap.scaled(
|
|
|
|
target_size, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation) # widget expands here
|
|
|
|
else:
|
|
|
|
scaledPixmap = self.selectedPixmap.scaled(
|
|
|
|
target_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.selectedImage.setPixmap(scaledPixmap)
|
2009-10-03 12:29:16 +00:00
|
|
|
else:
|
|
|
|
self.selectedImage.setPixmap(QPixmap())
|
2020-05-02 00:29:23 +00:00
|
|
|
self.scaleFactor = 0
|
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
if self.referencePixmap is not None:
|
|
|
|
target_size = self.referenceImage.size()
|
2020-05-02 00:29:23 +00:00
|
|
|
if self.scaleFactor:
|
|
|
|
scaledPixmap = self.referencePixmap.scaled(
|
|
|
|
target_size, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation) # widget expands here
|
|
|
|
else:
|
|
|
|
scaledPixmap = self.referencePixmap.scaled(
|
|
|
|
target_size, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.referenceImage.setPixmap(scaledPixmap)
|
2009-10-03 12:29:16 +00:00
|
|
|
else:
|
|
|
|
self.referenceImage.setPixmap(QPixmap())
|
2020-05-02 00:29:23 +00:00
|
|
|
self.scaleFactor = 0
|
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):
|
|
|
|
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
|
|
|
|
|
|
|
def scaleImages(self, factor):
|
2020-05-02 00:29:23 +00:00
|
|
|
self.scaleFactor += factor
|
|
|
|
print(f'Factor is now = {self.scaleFactor}.')
|
|
|
|
self._updateButtons()
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
def swapImages(self):
|
|
|
|
# self.horizontalLayout.replaceWidget(self.selectedImage, self.referenceImage)
|
|
|
|
self._tempPixmap = self.referencePixmap
|
|
|
|
self.referencePixmap = self.selectedPixmap
|
|
|
|
self.selectedPixmap = self._tempPixmap
|
|
|
|
self._updateImages()
|
|
|
|
# swap the columns in the details table as well
|
|
|
|
self.tableView.horizontalHeader().swapSections(1, 2)
|
|
|
|
|
|
|
|
def zoomIn(self):
|
2020-05-02 00:29:23 +00:00
|
|
|
if self.scaleFactor >= 10: # clamping to x10
|
2020-05-01 16:22:25 +00:00
|
|
|
return
|
|
|
|
print("ZoomIN")
|
|
|
|
self.scaleImages(1)
|
|
|
|
|
|
|
|
def zoomOut(self):
|
2020-05-02 00:29:23 +00:00
|
|
|
if self.scaleFactor <= 0:
|
2020-05-01 16:22:25 +00:00
|
|
|
return
|
|
|
|
print("ZoomOut")
|
|
|
|
self.scaleImages(-1)
|
|
|
|
|
|
|
|
def zoomReset(self):
|
|
|
|
print("ZoomReset")
|
2020-05-02 00:29:23 +00:00
|
|
|
self.scaleFactor = 0
|
2020-05-01 16:22:25 +00:00
|
|
|
self.buttonResetZoom.setEnabled(False)
|
|
|
|
self.buttonZoomOut.setEnabled(False)
|
|
|
|
self.buttonZoomIn.setEnabled(True)
|
2020-05-02 00:29:23 +00:00
|
|
|
self._updateImages()
|
2020-05-01 16:22:25 +00:00
|
|
|
|
|
|
|
def imagePan(self):
|
|
|
|
pass
|
2020-05-02 00:29:23 +00:00
|
|
|
|
|
|
|
def mouseDoubleClickedEvent(self, path):
|
|
|
|
desktop.open_path(path)
|
|
|
|
|
|
|
|
# TODO: open default application when double click on label
|
|
|
|
# TODO: place handle above table view to drag and resize (splitter?)
|
|
|
|
# TODO: colorize or bolden values in table views when they differ?
|