fix(gui): keep cover candidate controls below images
This commit is contained in:
@@ -181,6 +181,38 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertTrue(image.save(path))
|
||||
return path
|
||||
|
||||
def assert_cover_candidate_cards_do_not_overlap(self, dialog, check_horizontal=True):
|
||||
previous_right = None
|
||||
maximum_card_height = 0
|
||||
for candidate_path in dialog.candidates:
|
||||
card = dialog.candidate_items[candidate_path]
|
||||
layout = card.layout()
|
||||
thumbnail = layout.itemAt(0).widget()
|
||||
radio = layout.itemAt(1).widget()
|
||||
meta = layout.itemAt(2).widget()
|
||||
spacing = max(0, layout.spacing())
|
||||
|
||||
self.assertGreaterEqual(
|
||||
radio.geometry().top(),
|
||||
thumbnail.geometry().bottom() + 1 + spacing,
|
||||
)
|
||||
self.assertGreaterEqual(
|
||||
meta.geometry().top(),
|
||||
radio.geometry().bottom() + 1 + spacing,
|
||||
)
|
||||
self.assertGreaterEqual(card.minimumHeight(), layout.sizeHint().height())
|
||||
self.assertGreaterEqual(card.height(), meta.geometry().bottom() + 1)
|
||||
if check_horizontal and previous_right is not None:
|
||||
self.assertGreaterEqual(
|
||||
card.geometry().left(),
|
||||
previous_right + 1 + dialog.candidate_layout.spacing(),
|
||||
)
|
||||
previous_right = card.geometry().right()
|
||||
maximum_card_height = max(maximum_card_height, card.height())
|
||||
|
||||
self.assertGreaterEqual(dialog.candidate_content.minimumHeight(), maximum_card_height)
|
||||
self.assertGreaterEqual(dialog.candidate_content.height(), maximum_card_height)
|
||||
|
||||
def _cover_gallery_task(self, temp_dir, generate_cover=True):
|
||||
cfg = self.make_config(temp_dir)
|
||||
cfg.setdefault("ai", {})["generate_cover"] = bool(generate_cover)
|
||||
@@ -4205,6 +4237,77 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_cover_gallery_arrow_switch_syncs_full_candidate_card_geometry(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg, account, tasks, canonicals, archives = self._cover_gallery_task_set(
|
||||
temp_dir,
|
||||
count=2,
|
||||
)
|
||||
os.remove(archives[0])
|
||||
second_prefix = os.path.splitext(canonicals[1])[0]
|
||||
long_candidate = self.write_test_image(
|
||||
f"{second_prefix}_20260709101100_候选图片文件名很长用于验证自适应布局.jpg"
|
||||
)
|
||||
self.write_test_image(f"{second_prefix}_20260709101200.jpg")
|
||||
broken_candidate = f"{second_prefix}_20260709101300.jpg"
|
||||
with open(broken_candidate, "wb") as file_handle:
|
||||
file_handle.write(b"not-an-image")
|
||||
|
||||
dialog = CoverGalleryDialog(
|
||||
tasks[0],
|
||||
cfg["image_dir"],
|
||||
cfg["db_path"],
|
||||
account=account,
|
||||
visible_tasks=tasks,
|
||||
task_index=0,
|
||||
account_by_alias={"alias-a": account},
|
||||
)
|
||||
self.addCleanup(dialog.close)
|
||||
dialog.resize(1100, 700)
|
||||
dialog.show()
|
||||
QApplication.processEvents()
|
||||
dialog._candidate_resize_timer.stop()
|
||||
dialog._update_candidate_thumbnail_layout()
|
||||
initial_thumbnail_size = dialog.candidate_thumbnail_size
|
||||
dialog.next_button.setFocus()
|
||||
down_event = QKeyEvent(QKeyEvent.KeyPress, gui.Qt.Key_Down, gui.Qt.NoModifier)
|
||||
|
||||
QApplication.sendEvent(dialog.next_button, down_event)
|
||||
|
||||
self.assertTrue(down_event.isAccepted())
|
||||
self.assertEqual(tasks[1].id, dialog.task.id)
|
||||
self.assertGreaterEqual(len(dialog.candidates), 5)
|
||||
self.assertLess(dialog.candidate_thumbnail_size, initial_thumbnail_size)
|
||||
self.assertEqual(0, dialog.candidate_scroll.horizontalScrollBar().value())
|
||||
self.assert_cover_candidate_cards_do_not_overlap(dialog, check_horizontal=False)
|
||||
self.assertEqual("图片读取失败", dialog.candidate_thumbnails[broken_candidate].text())
|
||||
self.assertNotEqual(
|
||||
os.path.basename(long_candidate),
|
||||
dialog.candidate_buttons[long_candidate].text(),
|
||||
)
|
||||
self.assertIn(
|
||||
os.path.basename(long_candidate),
|
||||
dialog.candidate_buttons[long_candidate].toolTip(),
|
||||
)
|
||||
|
||||
QApplication.processEvents()
|
||||
dialog._candidate_resize_timer.stop()
|
||||
dialog._update_candidate_thumbnail_layout()
|
||||
QApplication.processEvents()
|
||||
self.assert_cover_candidate_cards_do_not_overlap(dialog)
|
||||
|
||||
horizontal_bar = dialog.candidate_scroll.horizontalScrollBar()
|
||||
self.assertGreater(horizontal_bar.maximum(), 0)
|
||||
horizontal_bar.setValue(horizontal_bar.maximum())
|
||||
self.assertGreater(horizontal_bar.value(), 0)
|
||||
self.assertTrue(dialog.switch_task(-1))
|
||||
self.assertEqual(0, horizontal_bar.value())
|
||||
self.assert_cover_candidate_cards_do_not_overlap(dialog, check_horizontal=False)
|
||||
QApplication.processEvents()
|
||||
self.assert_cover_candidate_cards_do_not_overlap(dialog)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_cover_gallery_save_switches_current_cover(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user