Skip to content

Commit 2581749

Browse files
fix: bug when panning with adaptive background
1 parent d48ad74 commit 2581749

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/ui/main_window.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
QMenu, QInputDialog, QDialog, QApplication, QTableWidget,
1111
QTableWidgetItem, QHeaderView, QDialogButtonBox, QLabel as QDialogLabel
1212
)
13-
from PySide6.QtGui import QPixmap, QImage, QTransform, QAction, QPainter
13+
from PySide6.QtGui import QPixmap, QImage, QTransform, QAction, QPainter, QColor
1414
from PySide6.QtCore import Qt, QTimer, QSize, QSettings, QThread, Signal
1515

1616
from .widgets import ClickableLabel, MinimalProgressBar, ButtonOverlay
@@ -649,7 +649,10 @@ def _update_zoom_display(self):
649649
if self.pan_offset_x != 0 or self.pan_offset_y != 0:
650650
# Create a canvas the size of the label
651651
canvas = QPixmap(self.image_label.size())
652-
canvas.fill(Qt.black) # Use black background instead of transparent
652+
653+
# Get the appropriate background color based on current mode
654+
bg_color = self._get_current_background_color()
655+
canvas.fill(bg_color)
653656

654657
# Paint the scaled image with offset
655658
painter = QPainter(canvas)
@@ -754,6 +757,30 @@ def cycle_background_mode(self):
754757

755758
self.change_bg_mode(next_mode)
756759

760+
def _get_current_background_color(self):
761+
"""Get the current background color as QColor based on the active mode."""
762+
mode = self.settings.value("bg_mode", "Black")
763+
764+
if mode == "Gray":
765+
return QColor(0x44, 0x44, 0x44) # #444444
766+
elif mode == "Adaptive Color":
767+
# Try to extract the current background color from the parent widget
768+
parent = self.image_label.parentWidget()
769+
if parent:
770+
style = parent.styleSheet()
771+
# Look for rgb() or background-color in the stylesheet
772+
import re
773+
rgb_match = re.search(r'rgb\((\d+),\s*(\d+),\s*(\d+)\)', style)
774+
if rgb_match:
775+
r, g, b = map(int, rgb_match.groups())
776+
return QColor(r, g, b)
777+
778+
# Fallback to dark gray if we can't extract the adaptive color
779+
return QColor(40, 40, 40)
780+
else:
781+
# Default to black
782+
return QColor(0, 0, 0)
783+
757784
def show_keyboard_shortcuts(self):
758785
"""Show the keyboard shortcuts help dialog."""
759786
dialog = KeyboardShortcutsDialog(self)

0 commit comments

Comments
 (0)