mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
feat: add basic "wallpaper" functionality
This commit is contained in:
@@ -39,32 +39,49 @@ class Image(QObject):
|
|||||||
self.overlay_label.hide()
|
self.overlay_label.hide()
|
||||||
return
|
return
|
||||||
|
|
||||||
scaled_image = image.scaledToWidth(
|
if getattr(state, "image_as_wallpaper", False):
|
||||||
state.image_width, Qt.TransformationMode.SmoothTransformation
|
scaled_image = image.scaled(
|
||||||
)
|
parent.size(),
|
||||||
|
Qt.AspectRatioMode.KeepAspectRatioByExpanding,
|
||||||
max_width = parent.width()
|
Qt.TransformationMode.SmoothTransformation
|
||||||
max_height = parent.height()
|
|
||||||
if scaled_image.width() > max_width or scaled_image.height() > max_height:
|
|
||||||
scaled_image = scaled_image.scaled(
|
|
||||||
QSize(max_width, max_height),
|
|
||||||
Qt.AspectRatioMode.KeepAspectRatio,
|
|
||||||
Qt.TransformationMode.SmoothTransformation,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pixmap = QPixmap.fromImage(scaled_image)
|
crop_x = (scaled_image.width() - parent.width()) // 2
|
||||||
self.overlay_label.setPixmap(pixmap)
|
crop_y = (scaled_image.height() - parent.height()) // 2
|
||||||
self.overlay_label.adjustSize()
|
scaled_image = scaled_image.copy(crop_x, crop_y, parent.width(), parent.height())
|
||||||
self.overlay_label.raise_()
|
|
||||||
|
|
||||||
x = parent.width() - self.overlay_label.width() - int(state.image_offset)
|
pixmap = QPixmap.fromImage(scaled_image)
|
||||||
y = parent.height() - self.overlay_label.height() - int(state.image_offset)
|
self.overlay_label.setPixmap(pixmap)
|
||||||
|
|
||||||
self.opacity_effect.setOpacity(state.image_opacity / 100)
|
self.overlay_label.setGeometry(0, 0, parent.width(), parent.height())
|
||||||
|
self.overlay_label.lower()
|
||||||
|
|
||||||
self.overlay_label.move(x, y)
|
else:
|
||||||
|
scaled_image = image.scaledToWidth(
|
||||||
|
state.image_width, Qt.TransformationMode.SmoothTransformation
|
||||||
|
)
|
||||||
|
|
||||||
|
max_width = parent.width()
|
||||||
|
max_height = parent.height()
|
||||||
|
if scaled_image.width() > max_width or scaled_image.height() > max_height:
|
||||||
|
scaled_image = scaled_image.scaled(
|
||||||
|
QSize(max_width, max_height),
|
||||||
|
Qt.AspectRatioMode.KeepAspectRatio,
|
||||||
|
Qt.TransformationMode.SmoothTransformation,
|
||||||
|
)
|
||||||
|
|
||||||
|
pixmap = QPixmap.fromImage(scaled_image)
|
||||||
|
self.overlay_label.setPixmap(pixmap)
|
||||||
|
self.overlay_label.adjustSize()
|
||||||
|
self.overlay_label.raise_()
|
||||||
|
|
||||||
|
x = parent.width() - self.overlay_label.width() - int(state.image_offset)
|
||||||
|
y = parent.height() - self.overlay_label.height() - int(state.image_offset)
|
||||||
|
|
||||||
|
self.opacity_effect.setOpacity(state.image_opacity / 100)
|
||||||
|
|
||||||
|
self.overlay_label.move(x, y)
|
||||||
self.overlay_label.show()
|
self.overlay_label.show()
|
||||||
|
|
||||||
def update_image_overlay(self, new_image_path):
|
def update_image_overlay(self, new_image_path):
|
||||||
self._load_and_display(new_image_path)
|
self._load_and_display(new_image_path)
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class AppState(QObject):
|
|||||||
self._image_width: int = 300 # Default to 300px
|
self._image_width: int = 300 # Default to 300px
|
||||||
self._image_offset: int = 50
|
self._image_offset: int = 50
|
||||||
self._image_opacity: int = 100
|
self._image_opacity: int = 100
|
||||||
|
self._image_as_wallpaper: bool = True
|
||||||
|
|
||||||
# Trackers / Scraping
|
# Trackers / Scraping
|
||||||
self.posts: list[Dict[str,str]] | None = None # titles, urls, author, seeders, leechers
|
self.posts: list[Dict[str,str]] | None = None # titles, urls, author, seeders, leechers
|
||||||
@@ -104,4 +105,14 @@ class AppState(QObject):
|
|||||||
self._image_enabled = new_state
|
self._image_enabled = new_state
|
||||||
self.image_changed.emit(self._image_path)
|
self.image_changed.emit(self._image_path)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def image_as_wallpaper(self) -> bool:
|
||||||
|
return self._image_as_wallpaper
|
||||||
|
|
||||||
|
@image_as_wallpaper.setter
|
||||||
|
def image_as_wallpaper(self, new_state: bool):
|
||||||
|
if new_state != self._image_as_wallpaper:
|
||||||
|
self._image_as_wallpaper = new_state
|
||||||
|
self.image_changed.emit(self._image_path)
|
||||||
|
|
||||||
state = AppState()
|
state = AppState()
|
||||||
|
|||||||
Reference in New Issue
Block a user