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:
Kovid Goyal 2015-05-29 21:29:50 +05:30
parent fb815c0bdb
commit a0d06b48e9

View File

@ -12,19 +12,37 @@ from functools import partial
from PyQt5.Qt import (
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.gui2 import error_dialog
from calibre.gui2.search_box import SearchBox2
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):
searched = pyqtSignal(object)
def __init__(self, *args):
QTreeView.__init__(self, *args)
self.delegate = Delegate(self)
self.setItemDelegate(self.delegate)
self.setMinimumWidth(80)
self.header().close()
self.setMouseTracking(True)