Cleanup previous PR

Fixes #2107685 [Menu ≡ key in detached Book details gives erratic results](https://bugs.launchpad.net/calibre/+bug/2107685)
This commit is contained in:
Kovid Goyal 2025-04-20 21:09:42 +05:30
parent cec69d1287
commit 804ec31459
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,6 +7,7 @@ import re
from collections import namedtuple from collections import namedtuple
from contextlib import suppress from contextlib import suppress
from functools import lru_cache, partial from functools import lru_cache, partial
from math import ceil
from qt.core import ( from qt.core import (
QAction, QAction,
@ -39,7 +40,7 @@ from qt.core import (
) )
from calibre import fit_image, sanitize_file_name from calibre import fit_image, sanitize_file_name
from calibre.constants import config_dir, iswindows from calibre.constants import DEBUG, config_dir, iswindows
from calibre.db.constants import DATA_DIR_NAME, DATA_FILE_PATTERN, NO_SEARCH_LINK, RESOURCE_URL_SCHEME from calibre.db.constants import DATA_DIR_NAME, DATA_FILE_PATTERN, NO_SEARCH_LINK, RESOURCE_URL_SCHEME
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS
from calibre.ebooks.metadata.book.base import Metadata, field_metadata from calibre.ebooks.metadata.book.base import Metadata, field_metadata
@ -675,7 +676,7 @@ def create_copy_links(menu, data=None):
def details_context_menu_event(view, ev, book_info, add_popup_action=False, edit_metadata=None): def details_context_menu_event(view, ev, book_info, add_popup_action=False, edit_metadata=None):
if not (url := view.anchorAt(ev.pos())): if not (url := view.anchorAt(ev.pos())) and (dpr := ceil(view.devicePixelRatio())) > 1:
# Attempt to compensate for high density displays. When tabbing into an # Attempt to compensate for high density displays. When tabbing into an
# anchor (URL) Qt picks a point on the outer right edge for the # anchor (URL) Qt picks a point on the outer right edge for the
# position. Theory: on high-resolution displays, the outer right edge # position. Theory: on high-resolution displays, the outer right edge
@ -688,19 +689,16 @@ def details_context_menu_event(view, ev, book_info, add_popup_action=False, edit
# an anchor when the user clicks in narrow empty space between anchors. # an anchor when the user clicks in narrow empty space between anchors.
# I think this is ok because exact pixel mouse clicking is extremely # I think this is ok because exact pixel mouse clicking is extremely
# difficult. # difficult.
# It could be that instead of using 3 pixels we should use one of the
# constants such as devicePixelRatio. I don't have a suitable screen so
# I can't test that.
p = ev.pos() p = ev.pos()
p += QPoint(-3, 0) p += QPoint(-dpr, 0)
url = view.anchorAt(p) url = view.anchorAt(p)
def pnt_to_str(p): def pnt_to_str(p):
return f'{p.x()}, {p.y()}' return f'{p.x()}, {p.y()}'
def rect_to_str(p): def rect_to_str(p):
return f'{p.x()}, {p.y()}, {p.width()}, {p.height()}' return f'{p.x()}, {p.y()}, {p.width()}, {p.height()}'
print(f'BD context menu pos. ev.pos: ({pnt_to_str(ev.pos())}), ' if DEBUG:
f'new pos: ({pnt_to_str(p)}), cursor rect: ({rect_to_str(view.cursorRect())})') print(f'BD context menu pos. ev.pos: ({pnt_to_str(ev.pos())}), '
f'new pos: ({pnt_to_str(p)}), cursor rect: ({rect_to_str(view.cursorRect())})')
menu = QMenu(view) menu = QMenu(view)
copy_menu = menu.addMenu(QIcon.ic('edit-copy.png'), _('Copy')) copy_menu = menu.addMenu(QIcon.ic('edit-copy.png'), _('Copy'))
copy_menu.addAction(QIcon.ic('edit-copy.png'), _('All book details'), partial(copy_all, view)) copy_menu.addAction(QIcon.ic('edit-copy.png'), _('All book details'), partial(copy_all, view))