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
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import Qt, QSize
|
2020-01-01 02:16:27 +00:00
|
|
|
from PyQt5.QtWidgets import (
|
2020-07-02 20:49:45 +00:00
|
|
|
QAbstractItemView, QSizePolicy, QGridLayout, QSplitter, QFrame)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
2016-06-01 01:59:31 +00:00
|
|
|
from ..details_dialog import DetailsDialog as DetailsDialogBase
|
|
|
|
from ..details_table import DetailsTable
|
2020-07-02 20:49:45 +00:00
|
|
|
from .image_viewer import (
|
|
|
|
ViewerToolBar, ScrollAreaImageViewer, ScrollAreaController)
|
2020-01-01 02:16:27 +00:00
|
|
|
tr = trget("ui")
|
|
|
|
|
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):
|
2020-07-02 20:49:45 +00:00
|
|
|
self.vController = None
|
|
|
|
super().__init__(parent, app)
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2010-02-05 20:09:04 +00:00
|
|
|
def _setupUi(self):
|
2011-01-21 12:57:54 +00:00
|
|
|
self.setWindowTitle(tr("Details"))
|
2020-07-02 20:49:45 +00:00
|
|
|
self.resize(502, 502)
|
2010-10-04 13:29:00 +00:00
|
|
|
self.setMinimumSize(QSize(250, 250))
|
2020-07-13 03:06:04 +00:00
|
|
|
self.setAllowedAreas(Qt.AllDockWidgetAreas)
|
2020-07-02 20:49:45 +00:00
|
|
|
self.splitter = QSplitter(Qt.Vertical, self)
|
|
|
|
self.topFrame = QFrame()
|
|
|
|
self.topFrame.setFrameShape(QFrame.StyledPanel)
|
|
|
|
self.horizontalLayout = QGridLayout()
|
|
|
|
# Minimum width for the toolbar in the middle:
|
|
|
|
self.horizontalLayout.setColumnMinimumWidth(1, 10)
|
|
|
|
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.horizontalLayout.setColumnStretch(0, 32)
|
|
|
|
# Smaller value for the toolbar in the middle to avoid excessive resize
|
|
|
|
self.horizontalLayout.setColumnStretch(1, 2)
|
|
|
|
self.horizontalLayout.setColumnStretch(2, 32)
|
|
|
|
# This avoids toolbar getting incorrectly partially hidden when window resizes
|
|
|
|
self.horizontalLayout.setRowStretch(0, 1)
|
|
|
|
self.horizontalLayout.setRowStretch(1, 24)
|
|
|
|
self.horizontalLayout.setRowStretch(2, 1)
|
|
|
|
self.horizontalLayout.setSpacing(1) # probably not important
|
|
|
|
|
|
|
|
self.selectedImageViewer = ScrollAreaImageViewer(self, "selectedImage")
|
|
|
|
self.horizontalLayout.addWidget(self.selectedImageViewer, 0, 0, 3, 1)
|
|
|
|
# Use a specific type of controller depending on the underlying viewer type
|
|
|
|
self.vController = ScrollAreaController(self)
|
|
|
|
|
|
|
|
self.verticalToolBar = ViewerToolBar(self, self.vController)
|
|
|
|
self.verticalToolBar.setOrientation(Qt.Orientation(Qt.Vertical))
|
|
|
|
self.horizontalLayout.addWidget(self.verticalToolBar, 1, 1, 1, 1, Qt.AlignCenter)
|
|
|
|
|
|
|
|
self.referenceImageViewer = ScrollAreaImageViewer(self, "referenceImage")
|
|
|
|
self.horizontalLayout.addWidget(self.referenceImageViewer, 0, 2, 3, 1)
|
|
|
|
self.topFrame.setLayout(self.horizontalLayout)
|
|
|
|
self.splitter.addWidget(self.topFrame)
|
|
|
|
self.splitter.setStretchFactor(0, 8)
|
|
|
|
|
2010-10-04 13:29:00 +00:00
|
|
|
self.tableView = DetailsTable(self)
|
2020-07-02 20:49:45 +00:00
|
|
|
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
|
2010-10-04 13:29:00 +00:00
|
|
|
sizePolicy.setHorizontalStretch(0)
|
|
|
|
sizePolicy.setVerticalStretch(0)
|
|
|
|
self.tableView.setSizePolicy(sizePolicy)
|
2020-07-02 20:49:45 +00:00
|
|
|
# self.tableView.setMinimumSize(QSize(0, 190))
|
|
|
|
# self.tableView.setMaximumSize(QSize(16777215, 190))
|
2010-10-04 13:29:00 +00:00
|
|
|
self.tableView.setAlternatingRowColors(True)
|
|
|
|
self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
|
|
|
|
self.tableView.setShowGrid(False)
|
2020-07-02 20:49:45 +00:00
|
|
|
self.splitter.addWidget(self.tableView)
|
|
|
|
self.splitter.setStretchFactor(1, 1)
|
|
|
|
# Late population needed here for connections to the toolbar
|
|
|
|
self.vController.setupViewers(
|
|
|
|
self.selectedImageViewer, self.referenceImageViewer)
|
2020-07-13 03:06:04 +00:00
|
|
|
# self.setCentralWidget(self.splitter) # only as QMainWindow
|
|
|
|
self.setWidget(self.splitter) # only as QDockWidget
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def _update(self):
|
2020-07-02 20:49:45 +00:00
|
|
|
if self.vController is None: # Not yet constructed!
|
|
|
|
return
|
2011-09-20 19:06:29 +00:00
|
|
|
if not self.app.model.selected_dupes:
|
2020-07-02 20:49:45 +00:00
|
|
|
# No item from the model, disable and clear everything.
|
|
|
|
self.vController.resetViewersState()
|
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-07-02 20:49:45 +00:00
|
|
|
self.vController.updateView(ref, dupe, group)
|
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-07-13 03:06:04 +00:00
|
|
|
# HACK This ensures same size while shrinking.
|
|
|
|
# ReferenceViewer might be 1 pixel shorter in width
|
2020-07-02 20:49:45 +00:00
|
|
|
# due to the toolbar in the middle keeping the same width,
|
|
|
|
# so resizing in the GridLayout's engine leads to not enough space
|
|
|
|
# left for the panel on the right.
|
2020-07-13 03:06:04 +00:00
|
|
|
# This doesn't work as a QDockWidget however!
|
|
|
|
# self.horizontalLayout.setColumnMinimumWidth(
|
|
|
|
# 0, self.selectedImageViewer.size().width())
|
|
|
|
# self.horizontalLayout.setColumnMinimumWidth(
|
|
|
|
# 2, self.selectedImageViewer.size().width())
|
|
|
|
|
2020-07-02 20:49:45 +00:00
|
|
|
# This works when expanding but it's ugly:
|
|
|
|
if self.selectedImageViewer.size().width() > self.referenceImageViewer.size().width():
|
|
|
|
# print(f"""Before selected size: {self.selectedImageViewer.size()}\n""",
|
|
|
|
# f"""Before reference size: {self.referenceImageViewer.size()}""")
|
|
|
|
self.selectedImageViewer.resize(self.referenceImageViewer.size())
|
|
|
|
# print(f"""After selected size: {self.selectedImageViewer.size()}\n""",
|
|
|
|
# f"""After reference size: {self.referenceImageViewer.size()}""")
|
|
|
|
|
|
|
|
if self.vController is None or not self.vController.bestFit:
|
|
|
|
return
|
|
|
|
# Only update the scaled down pixmaps
|
|
|
|
self.vController.updateBothImages()
|
2016-06-01 01:59:31 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def show(self):
|
2020-07-02 20:49:45 +00:00
|
|
|
# Compute the maximum size the table view can reach
|
|
|
|
# Assuming all rows below headers have the same height
|
|
|
|
self.tableView.setMaximumHeight(
|
|
|
|
self.tableView.rowHeight(1)
|
|
|
|
* self.tableModel.model.row_count()
|
|
|
|
+ self.tableView.verticalHeader().sectionSize(0))
|
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()
|