mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: If there are entries in the Table of Contents that are long enough to be truncated, display the full text in a popup menu when the mouse hovers over the item. Fixes #1460093 [Request: Hover over TOC item to display full line if cut off](https://bugs.launchpad.net/calibre/+bug/1460093)
This commit is contained in:
parent
fb815c0bdb
commit
a0d06b48e9
@ -12,19 +12,37 @@ from functools import partial
|
|||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QStandardItem, QStandardItemModel, Qt, QFont, QTreeView, QWidget,
|
QStandardItem, QStandardItemModel, Qt, QFont, QTreeView, QWidget,
|
||||||
QHBoxLayout, QToolButton, QIcon, QModelIndex, pyqtSignal, QMenu)
|
QHBoxLayout, QToolButton, QIcon, QModelIndex, pyqtSignal, QMenu,
|
||||||
|
QStyledItemDelegate, QToolTip)
|
||||||
|
|
||||||
from calibre.ebooks.metadata.toc import TOC as MTOC
|
from calibre.ebooks.metadata.toc import TOC as MTOC
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
from calibre.gui2.search_box import SearchBox2
|
from calibre.gui2.search_box import SearchBox2
|
||||||
from calibre.utils.icu import primary_contains
|
from calibre.utils.icu import primary_contains
|
||||||
|
|
||||||
|
class Delegate(QStyledItemDelegate):
|
||||||
|
|
||||||
|
def helpEvent(self, ev, view, option, index):
|
||||||
|
# Show a tooltip only if the item is truncated
|
||||||
|
if not ev or not view:
|
||||||
|
return False
|
||||||
|
if ev.type() == ev.ToolTip:
|
||||||
|
rect = view.visualRect(index)
|
||||||
|
size = self.sizeHint(option, index)
|
||||||
|
if rect.width() < size.width():
|
||||||
|
tooltip = index.data(Qt.DisplayRole)
|
||||||
|
QToolTip.showText(ev.globalPos(), tooltip, view)
|
||||||
|
return True
|
||||||
|
return QStyledItemDelegate.helpEvent(self, ev, view, option, index)
|
||||||
|
|
||||||
class TOCView(QTreeView):
|
class TOCView(QTreeView):
|
||||||
|
|
||||||
searched = pyqtSignal(object)
|
searched = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QTreeView.__init__(self, *args)
|
QTreeView.__init__(self, *args)
|
||||||
|
self.delegate = Delegate(self)
|
||||||
|
self.setItemDelegate(self.delegate)
|
||||||
self.setMinimumWidth(80)
|
self.setMinimumWidth(80)
|
||||||
self.header().close()
|
self.header().close()
|
||||||
self.setMouseTracking(True)
|
self.setMouseTracking(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user