mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
* Initial commit for new UI * Initial commit for new UI * WIP * Status bar updates and has an icon for online / offline * Add log_viewer.py * Use JSON for delete_engine_download API * Fix class issue with Downloaders * Move Config class to new ui * Add engine_browser.py * Add a close event handler to the main window * Fix issue with engine manager not deleting engines properly * Rearrange all the files * Add icons and resources * Cache system info in RenderServerProxy * Toolbar polish * Fix resource path in status bar * Add config_dir to misc_helper.py * Add try block to zeroconf setup * Add add_job.py * Add raw args to add_job.py
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from PyQt6.QtCore import QRectF
|
|
from PyQt6.QtGui import QPainter
|
|
from PyQt6.QtWidgets import QLabel
|
|
|
|
|
|
class ProportionalImageLabel(QLabel):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def setPixmap(self, pixmap):
|
|
self._pixmap = pixmap
|
|
super().setPixmap(self._pixmap)
|
|
|
|
def paintEvent(self, event):
|
|
if self._pixmap.isNull():
|
|
super().paintEvent(event)
|
|
return
|
|
|
|
painter = QPainter(self)
|
|
targetRect = event.rect()
|
|
|
|
# Calculate the aspect ratio of the pixmap
|
|
aspectRatio = self._pixmap.width() / self._pixmap.height()
|
|
|
|
# Calculate the size of the pixmap within the target rectangle while maintaining the aspect ratio
|
|
if aspectRatio > targetRect.width() / targetRect.height():
|
|
scaledWidth = targetRect.width()
|
|
scaledHeight = targetRect.width() / aspectRatio
|
|
else:
|
|
scaledHeight = targetRect.height()
|
|
scaledWidth = targetRect.height() * aspectRatio
|
|
|
|
# Calculate the position to center the pixmap within the target rectangle
|
|
x = targetRect.x() + (targetRect.width() - scaledWidth) / 2
|
|
y = targetRect.y() + (targetRect.height() - scaledHeight) / 2
|
|
|
|
sourceRect = QRectF(0.0, 0.0, self._pixmap.width(), self._pixmap.height())
|
|
targetRect = QRectF(x, y, scaledWidth, scaledHeight)
|
|
|
|
painter.drawPixmap(targetRect, self._pixmap, sourceRect) |