""" Thermal Analysis Panel Panel for displaying thermal camera data and temperature analysis. Currently shows offline status with thermal gradient mockup. """ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QSizePolicy from PyQt5.QtCore import Qt, QTimer from PyQt5.QtGui import QFont, QPixmap, QImage, QPainter, QColor, QPen, QBrush, QLinearGradient, QRadialGradient from ui.widgets.panel_header import PanelHeader from ui.widgets.coming_soon_overlay import ComingSoonOverlay class QualityThermalPanel(QWidget): """ Panel for thermal analysis display. Shows thermal gradient visualization with offline status. """ def __init__(self, parent=None): super().__init__(parent) self.current_temperature = 28.5 self.temperature_range = (22.0, 32.0) self.init_ui() def init_ui(self): """Initialize the panel UI.""" # Set size policy to expand equally self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) # Main panel container with card styling self.setStyleSheet(""" QWidget { background-color: white; border: 1px solid #ddd; } """) # Header using the PanelHeader widget header = PanelHeader( title="Thermal Analysis", color="#e67e22" # Orange for thermal ) layout.addWidget(header) # Content area content = QWidget() content.setStyleSheet(""" background-color: #2c3e50; border: 1px solid #34495e; border-top: none; """) content_layout = QVBoxLayout(content) content_layout.setContentsMargins(10, 10, 10, 10) content_layout.setAlignment(Qt.AlignCenter) content_layout.setSpacing(5) # Thermal visualization area self.thermal_display = ThermalVisualizationWidget() self.thermal_display.setMinimumSize(200, 150) content_layout.addWidget(self.thermal_display) # Temperature info temp_widget = QWidget() temp_layout = QVBoxLayout(temp_widget) temp_layout.setContentsMargins(0, 5, 0, 0) temp_layout.setSpacing(2) # Current temperature reading self.temp_label = QLabel(f"{self.current_temperature}°C") self.temp_label.setFont(QFont("Arial", 16, QFont.Bold)) self.temp_label.setStyleSheet("color: #f39c12;") self.temp_label.setAlignment(Qt.AlignCenter) temp_layout.addWidget(self.temp_label) # Temperature scale label scale_label = QLabel("Temperature Range:") scale_label.setFont(QFont("Arial", 10)) scale_label.setStyleSheet("color: #bdc3c7;") scale_label.setAlignment(Qt.AlignCenter) temp_layout.addWidget(scale_label) # Temperature scale widget self.scale_widget = TemperatureScaleWidget(self.temperature_range) self.scale_widget.setFixedHeight(20) temp_layout.addWidget(self.scale_widget) # Min/Max labels minmax_widget = QWidget() minmax_layout = QHBoxLayout(minmax_widget) minmax_layout.setContentsMargins(0, 0, 0, 0) min_label = QLabel(f"{self.temperature_range[0]}°C") min_label.setFont(QFont("Arial", 9)) min_label.setStyleSheet("color: #7f8c8d;") max_label = QLabel(f"{self.temperature_range[1]}°C") max_label.setFont(QFont("Arial", 9)) max_label.setStyleSheet("color: #7f8c8d;") minmax_layout.addWidget(min_label) minmax_layout.addStretch() minmax_layout.addWidget(max_label) temp_layout.addWidget(minmax_widget) # Offline status offline_label = QLabel("🔴 OFFLINE") offline_label.setFont(QFont("Arial", 9)) offline_label.setStyleSheet("color: #e74c3c; font-weight: bold;") offline_label.setAlignment(Qt.AlignCenter) temp_layout.addWidget(offline_label) content_layout.addWidget(temp_widget) layout.addWidget(content, 1) def update_temperature(self, temperature): """Update current temperature reading.""" self.current_temperature = temperature self.temp_label.setText(f"{temperature}°C") self.thermal_display.update_temperature(temperature) self.update() def set_temperature_range(self, min_temp, max_temp): """Set temperature range for the scale.""" self.temperature_range = (min_temp, max_temp) self.scale_widget.update_range(min_temp, max_temp) class ThermalVisualizationWidget(QWidget): """Widget showing thermal gradient visualization.""" def __init__(self, parent=None): super().__init__(parent) self.temperature = 28.5 self.setAttribute(Qt.WA_StyledBackground, True) def update_temperature(self, temperature): """Update temperature for visualization.""" self.temperature = temperature self.update() def paintEvent(self, event): """Custom paint event to draw thermal gradient.""" painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # Get widget dimensions width = self.width() height = self.height() # Draw background painter.fillRect(0, 0, width, height, QColor("#000000")) # Create thermal gradient (blue to red through yellow) gradient = QLinearGradient(0, 0, width, height) # Define color stops for thermal gradient gradient.setColorAt(0.0, QColor("#3498db")) # Blue (cool) gradient.setColorAt(0.25, QColor("#27ae60")) # Green gradient.setColorAt(0.5, QColor("#f1c40f")) # Yellow gradient.setColorAt(0.75, QColor("#e67e22")) # Orange gradient.setColorAt(1.0, QColor("#e74c3c")) # Red (hot) # Draw gradient background painter.fillRect(0, 0, width, height, gradient) # Draw thermal "hot spots" or patterns self._draw_thermal_patterns(painter, width, height) # Draw temperature overlay self._draw_temperature_overlay(painter, width, height) def _draw_thermal_patterns(self, painter, width, height): """Draw thermal pattern visualization.""" # Draw some elliptical "hot spots" center_x = width // 2 center_y = height // 2 # Main thermal area (elliptical) thermal_width = width * 3 // 4 thermal_height = height * 2 // 3 # Create radial gradient for thermal effect radial_gradient = QRadialGradient(center_x, center_y, max(thermal_width, thermal_height) // 2) # Center is hottest (red), edges cooler (yellow) radial_gradient.setColorAt(0.0, QColor("#e74c3c")) radial_gradient.setColorAt(0.7, QColor("#f39c12")) radial_gradient.setColorAt(1.0, QColor("#f1c40f")) painter.setBrush(radial_gradient) painter.setPen(Qt.NoPen) painter.drawEllipse(center_x - thermal_width // 2, center_y - thermal_height // 2, thermal_width, thermal_height) def _draw_temperature_overlay(self, painter, width, height): """Draw temperature overlay information.""" # Draw current temperature in center painter.setPen(QPen(QColor("white"), 2)) temp_text = f"{self.temperature}°C" painter.drawText(width // 2 - 30, height // 2 - 10, temp_text) def update(self): """Override update to ensure repaint.""" super().update() self.repaint() class TemperatureScaleWidget(QWidget): """Widget showing temperature scale with color gradient.""" def __init__(self, temp_range, parent=None): super().__init__(parent) self.temp_range = temp_range def update_range(self, min_temp, max_temp): """Update temperature range.""" self.temp_range = (min_temp, max_temp) self.update() def paintEvent(self, event): """Custom paint event to draw temperature scale.""" painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) width = self.width() height = self.height() # Draw temperature scale gradient gradient = QLinearGradient(0, 0, width, 0) # Blue to red gradient for temperature scale gradient.setColorAt(0.0, QColor("#3498db")) # Cool gradient.setColorAt(0.25, QColor("#27ae60")) gradient.setColorAt(0.5, QColor("#f1c40f")) gradient.setColorAt(0.75, QColor("#e67e22")) gradient.setColorAt(1.0, QColor("#e74c3c")) # Hot painter.fillRect(0, 0, width, height, gradient) # Draw scale border painter.setPen(QPen(QColor("#34495e"), 1)) painter.drawRect(0, 0, width - 1, height - 1) def update(self): """Override update to ensure repaint.""" super().update() self.repaint()