2025-09-26 19:27:29 +02:00

66 lines
2.2 KiB
Python

from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtWidgets import QLabel
from PyQt6.QtGui import QPainter, QPen, QColor
from app.core.main_manager import MainManager
import math
class LoadingSpinner(QLabel):
def __init__(self, size=40, parent=None):
super().__init__(parent)
self.size = size
self.angle = 0
self.setFixedSize(size, size)
# Timer pour l'animation
self.timer = QTimer()
self.timer.timeout.connect(self.rotate)
self.timer.start(50) # 50ms = rotation fluide
def rotate(self):
self.angle = (self.angle + 10) % 360
self.update()
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
# Obtenir la couleur du thème
main_manager = MainManager.get_instance()
theme = main_manager.get_theme_manager().get_theme()
color = theme.get_color("background_secondary_color")
# Dessiner le cercle de chargement
rect = self.rect()
center_x, center_y = rect.width() // 2, rect.height() // 2
radius = min(center_x, center_y) - 5
painter.translate(center_x, center_y)
painter.rotate(self.angle)
# Dessiner les segments du spinner
pen = QPen()
pen.setWidth(3)
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
for i in range(8):
alpha = 255 - (i * 25) # Dégradé d'opacité
pen.setColor(self.hex_to_qcolor(color, alpha))
painter.setPen(pen)
angle = i * 45
start_x = radius * 0.7 * math.cos(math.radians(angle))
start_y = radius * 0.7 * math.sin(math.radians(angle))
end_x = radius * math.cos(math.radians(angle))
end_y = radius * math.sin(math.radians(angle))
painter.drawLine(int(start_x), int(start_y), int(end_x), int(end_y))
def hex_to_qcolor(self, hex_color, alpha=255):
hex_color = hex_color.lstrip('#')
r = int(hex_color[0:2], 16)
g = int(hex_color[2:4], 16)
b = int(hex_color[4:6], 16)
return QColor(r, g, b, alpha)
def stop(self):
self.timer.stop()