mirror of
https://github.com/arsenetar/dupeguru.git
synced 2024-10-31 22:05:58 +00:00
Use native QPixmap swap() method instead of manual setPixmap()
When swapping images, use getters to hopefully get a reference to each pixmap and swap them within a single slot.
This commit is contained in:
parent
8103cb3664
commit
b7abcf2989
@ -176,7 +176,12 @@ class DetailsDialog(DetailsDialogBase):
|
|||||||
self.tableView.setShowGrid(False)
|
self.tableView.setShowGrid(False)
|
||||||
self.verticalLayout.addWidget(self.tableView)
|
self.verticalLayout.addWidget(self.tableView)
|
||||||
|
|
||||||
self.disable_buttons()
|
self.buttonImgSwap.setEnabled(False)
|
||||||
|
self.buttonZoomIn.setEnabled(False)
|
||||||
|
self.buttonZoomOut.setEnabled(False)
|
||||||
|
self.buttonNormalSize.setEnabled(False)
|
||||||
|
self.buttonBestFit.setEnabled(False)
|
||||||
|
|
||||||
# We use different types of controller depending on the
|
# We use different types of controller depending on the
|
||||||
# underlying widgets we use to display images
|
# underlying widgets we use to display images
|
||||||
# because their interface methods might differ
|
# because their interface methods might differ
|
||||||
@ -213,14 +218,6 @@ class DetailsDialog(DetailsDialogBase):
|
|||||||
"""No item from the model, disable and clear everything."""
|
"""No item from the model, disable and clear everything."""
|
||||||
self.vController.clear_all()
|
self.vController.clear_all()
|
||||||
|
|
||||||
def disable_buttons(self):
|
|
||||||
# FIXME Only called once at startup
|
|
||||||
self.buttonImgSwap.setEnabled(False)
|
|
||||||
self.buttonZoomIn.setEnabled(False)
|
|
||||||
self.buttonZoomOut.setEnabled(False)
|
|
||||||
self.buttonNormalSize.setEnabled(False)
|
|
||||||
self.buttonBestFit.setEnabled(False)
|
|
||||||
|
|
||||||
# --- Override
|
# --- Override
|
||||||
def resizeEvent(self, event):
|
def resizeEvent(self, event):
|
||||||
if self.vController is None:
|
if self.vController is None:
|
||||||
@ -244,17 +241,10 @@ class DetailsDialog(DetailsDialogBase):
|
|||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def swapImages(self):
|
def swapImages(self):
|
||||||
"""Swap pixmaps between ImageViewers."""
|
"""Swap pixmaps between ImageViewers."""
|
||||||
self.vController.swapImages()
|
self.vController.swapPixmaps()
|
||||||
# swap the columns in the details table as well
|
# swap the columns in the details table as well
|
||||||
self.tableView.horizontalHeader().swapSections(1, 2)
|
self.tableView.horizontalHeader().swapSections(1, 2)
|
||||||
|
|
||||||
@pyqtSlot()
|
|
||||||
def deswapImages(self):
|
|
||||||
"""Restore swapped pixmaps between ImageViewers."""
|
|
||||||
self.vController.deswapImages()
|
|
||||||
# deswap the columns in the details table as well
|
|
||||||
self.tableView.horizontalHeader().swapSections(1, 2)
|
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def zoomIn(self):
|
def zoomIn(self):
|
||||||
self.vController.scaleImages(1.25)
|
self.vController.scaleImages(1.25)
|
||||||
|
@ -19,10 +19,13 @@ class BaseController(QObject):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.selectedViewer = selectedViewer
|
self.selectedViewer = selectedViewer
|
||||||
self.referenceViewer = referenceViewer
|
self.referenceViewer = referenceViewer
|
||||||
|
|
||||||
|
# cached pixmaps
|
||||||
self.selectedPixmap = QPixmap()
|
self.selectedPixmap = QPixmap()
|
||||||
self.referencePixmap = QPixmap()
|
self.referencePixmap = QPixmap()
|
||||||
self.scaledSelectedPixmap = QPixmap()
|
self.scaledSelectedPixmap = QPixmap()
|
||||||
self.scaledReferencePixmap = QPixmap()
|
self.scaledReferencePixmap = QPixmap()
|
||||||
|
|
||||||
self.scaleFactor = 1.0
|
self.scaleFactor = 1.0
|
||||||
self.bestFit = True
|
self.bestFit = True
|
||||||
self.parent = parent #needed to change buttons' states
|
self.parent = parent #needed to change buttons' states
|
||||||
@ -121,22 +124,13 @@ class BaseController(QObject):
|
|||||||
self.parent.buttonImgSwap.setDisabled(True)
|
self.parent.buttonImgSwap.setDisabled(True)
|
||||||
self.parent.buttonNormalSize.setDisabled(True)
|
self.parent.buttonNormalSize.setDisabled(True)
|
||||||
|
|
||||||
def swapImages(self):
|
@pyqtSlot()
|
||||||
if self.bestFit:
|
def swapPixmaps(self):
|
||||||
self.selectedViewer.setPixmap(self.scaledReferencePixmap)
|
self.selectedViewer.getPixmap().swap(self.referenceViewer.getPixmap())
|
||||||
self.referenceViewer.setPixmap(self.scaledSelectedPixmap)
|
self.selectedViewer.center_and_update()
|
||||||
else:
|
self.referenceViewer.center_and_update()
|
||||||
self.selectedViewer.setPixmap(self.referencePixmap)
|
|
||||||
self.referenceViewer.setPixmap(self.selectedPixmap)
|
|
||||||
|
|
||||||
def deswapImages(self):
|
|
||||||
if self.bestFit:
|
|
||||||
self.selectedViewer.setPixmap(self.scaledSelectedPixmap)
|
|
||||||
self.referenceViewer.setPixmap(self.scaledReferencePixmap)
|
|
||||||
else:
|
|
||||||
self.selectedViewer.setPixmap(self.selectedPixmap)
|
|
||||||
self.referenceViewer.setPixmap(self.referencePixmap)
|
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def zoomBestFit(self):
|
def zoomBestFit(self):
|
||||||
self.setBestFit(True)
|
self.setBestFit(True)
|
||||||
self.scaleFactor = 1.0
|
self.scaleFactor = 1.0
|
||||||
@ -145,6 +139,7 @@ class BaseController(QObject):
|
|||||||
self.parent.buttonZoomIn.setEnabled(False)
|
self.parent.buttonZoomIn.setEnabled(False)
|
||||||
self.parent.buttonNormalSize.setEnabled(True)
|
self.parent.buttonNormalSize.setEnabled(True)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
def zoomNormalSize(self):
|
def zoomNormalSize(self):
|
||||||
self.setBestFit(False)
|
self.setBestFit(False)
|
||||||
self.scaleFactor = 1.0
|
self.scaleFactor = 1.0
|
||||||
@ -302,6 +297,9 @@ class QWidgetImageViewer(QWidget):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'{self._instance_name}'
|
return f'{self._instance_name}'
|
||||||
|
|
||||||
|
def getPixmap(self):
|
||||||
|
return self._pixmap
|
||||||
|
|
||||||
def paintEvent(self, event):
|
def paintEvent(self, event):
|
||||||
painter = QPainter(self)
|
painter = QPainter(self)
|
||||||
painter.translate(self.rect().center())
|
painter.translate(self.rect().center())
|
||||||
@ -378,6 +376,9 @@ class QWidgetImageViewer(QWidget):
|
|||||||
self.connect_signals()
|
self.connect_signals()
|
||||||
self.setEnabled(True)
|
self.setEnabled(True)
|
||||||
self._pixmap = pixmap
|
self._pixmap = pixmap
|
||||||
|
self.center_and_update()
|
||||||
|
|
||||||
|
def center_and_update(self):
|
||||||
self._rect = self._pixmap.rect()
|
self._rect = self._pixmap.rect()
|
||||||
self._rect.translate(-self._rect.center())
|
self._rect.translate(-self._rect.center())
|
||||||
self.update()
|
self.update()
|
||||||
@ -538,7 +539,7 @@ class ScrollAreaImageViewer(QScrollArea):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def scale(self, factor):
|
def scale(self, factor):
|
||||||
self._scaleFactor = factor
|
self._scaleFactor *= factor
|
||||||
self.label.resize(self._scaleFactor * self.label.pixmap().size())
|
self.label.resize(self._scaleFactor * self.label.pixmap().size())
|
||||||
self.adjustScrollBar(self.scrollarea.horizontalScrollBar(), factor)
|
self.adjustScrollBar(self.scrollarea.horizontalScrollBar(), factor)
|
||||||
self.adjustScrollBar(self.scrollarea.verticalScrollBar(), factor)
|
self.adjustScrollBar(self.scrollarea.verticalScrollBar(), factor)
|
||||||
|
Loading…
Reference in New Issue
Block a user