1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-10-31 22:05:58 +00:00

add zoom and swap buttons to details dialog

This commit is contained in:
glubsy 2020-05-01 18:22:25 +02:00
parent 092cf1471b
commit 9b48e1851d
4 changed files with 158 additions and 6 deletions

2
.gitignore vendored
View File

@ -23,3 +23,5 @@ cocoa/autogen
*.pyd
*.exe
*.spec
.vscode

View File

@ -61,7 +61,7 @@ class DetailsTable(QTableView):
hheader.setHighlightSections(False)
hheader.setStretchLastSection(False)
hheader.resizeSection(0, 100)
hheader.setSectionResizeMode(0, QHeaderView.Fixed)
hheader.setSectionResizeMode(0, QHeaderView.Interactive)
hheader.setSectionResizeMode(1, QHeaderView.Stretch)
hheader.setSectionResizeMode(2, QHeaderView.Stretch)
vheader = self.verticalHeader()

View File

@ -5,5 +5,6 @@
<file alias="plus">../images/plus_8.png</file>
<file alias="minus">../images/minus_8.png</file>
<file alias="search_clear_13">../qtlib/images/search_clear_13.png</file>
<file alias="zoom-in">../images/zoom-in.png</file>
</qresource>
</RCC>

View File

@ -5,18 +5,24 @@
# http://www.gnu.org/licenses/gpl-3.0.html
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QPixmap
from PyQt5.QtGui import QPixmap, QIcon, QKeySequence
from PyQt5.QtWidgets import (
QVBoxLayout,
QAbstractItemView,
QHBoxLayout,
QLabel,
QSizePolicy,
QToolBar,
QToolButton,
QGridLayout,
QStyle,
QAction
)
from hscommon.trans import trget
from ..details_dialog import DetailsDialog as DetailsDialogBase
from ..details_table import DetailsTable
from qtlib.util import createActions
tr = trget("ui")
@ -26,15 +32,63 @@ class DetailsDialog(DetailsDialogBase):
DetailsDialogBase.__init__(self, parent, app)
self.selectedPixmap = None
self.referencePixmap = None
self.ZoomFactor = 0
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)
def _setupUi(self):
self._setupActions()
self.setWindowTitle(tr("Details"))
self.resize(502, 295)
self.setMinimumSize(QSize(250, 250))
self.verticalLayout = QVBoxLayout(self)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout = QHBoxLayout()
# 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)
self.horizontalLayout.setSpacing(4)
self.selectedImage = QLabel(self)
sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
@ -46,7 +100,51 @@ class DetailsDialog(DetailsDialogBase):
self.selectedImage.setSizePolicy(sizePolicy)
self.selectedImage.setScaledContents(False)
self.selectedImage.setAlignment(Qt.AlignCenter)
self.horizontalLayout.addWidget(self.selectedImage)
# self.horizontalLayout.addWidget(self.selectedImage)
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)
self.referenceImage = QLabel(self)
sizePolicy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
@ -56,7 +154,8 @@ class DetailsDialog(DetailsDialogBase):
)
self.referenceImage.setSizePolicy(sizePolicy)
self.referenceImage.setAlignment(Qt.AlignCenter)
self.horizontalLayout.addWidget(self.referenceImage)
self.horizontalLayout.addWidget(self.referenceImage, 0, 2, 3, 1)
# self.horizontalLayout.addWidget(self.referenceImage)
self.verticalLayout.addLayout(self.horizontalLayout)
self.tableView = DetailsTable(self)
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
@ -81,8 +180,10 @@ class DetailsDialog(DetailsDialogBase):
self.selectedPixmap = QPixmap(str(dupe.path))
if ref is dupe:
self.referencePixmap = None
self.buttonImgSwap.setEnabled(False)
else:
self.referencePixmap = QPixmap(str(ref.path))
self.buttonImgSwap.setEnabled(True)
self._updateImages()
def _updateImages(self):
@ -116,3 +217,51 @@ class DetailsDialog(DetailsDialogBase):
DetailsDialogBase.refresh(self)
if self.isVisible():
self._update()
def scaleImages(self, factor):
self.ZoomFactor = self.ZoomFactor + factor
print(f'Factor is now = {self.ZoomFactor}.')
if 0 < self.ZoomFactor < 10:
self.buttonZoomIn.setEnabled(True)
self.buttonZoomOut.setEnabled(True)
self.buttonResetZoom.setEnabled(True)
elif self.ZoomFactor >= 10:
self.buttonZoomIn.setEnabled(False)
else:
self.buttonZoomIn.setEnabled(True)
self.buttonZoomOut.setEnabled(False)
self.buttonResetZoom.setEnabled(False)
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):
if self.ZoomFactor >= 10: # clamping to x10
return
print("ZoomIN")
self.scaleImages(1)
def zoomOut(self):
if self.ZoomFactor == 0:
return
print("ZoomOut")
self.scaleImages(-1)
def zoomReset(self):
print("ZoomReset")
self.ZoomFactor = 0
self.buttonResetZoom.setEnabled(False)
self.buttonZoomOut.setEnabled(False)
self.buttonZoomIn.setEnabled(True)
def imagePan(self):
pass