mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ebook viewer: Fix scroll bar not updating after animated scrolling to bookmark or reference
This commit is contained in:
parent
e757bedb50
commit
d1dadc3402
@ -8,7 +8,8 @@ __docformat__ = 'restructuredtext en'
|
||||
import os, math, re
|
||||
from PyQt4.Qt import QWidget, QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
||||
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
||||
QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion, QFont
|
||||
QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion, \
|
||||
QFont, QObject, QApplication, pyqtSignature
|
||||
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
||||
|
||||
from calibre.utils.config import Config, StringConfig
|
||||
@ -72,6 +73,20 @@ def config(defaults=None):
|
||||
|
||||
return c
|
||||
|
||||
class PythonJS(QObject):
|
||||
|
||||
def __init__(self, callback):
|
||||
QObject.__init__(self, QApplication.instance())
|
||||
self.setObjectName("py_bridge")
|
||||
self._callback = callback
|
||||
|
||||
@pyqtSignature("QString")
|
||||
def callback(self, msg):
|
||||
print "callback called"
|
||||
self._callback(msg)
|
||||
|
||||
|
||||
|
||||
class ConfigDialog(QDialog, Ui_Dialog):
|
||||
|
||||
def __init__(self, *args):
|
||||
@ -89,6 +104,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
self.css.setPlainText(opts.user_css)
|
||||
self.css.setToolTip(_('Set the user CSS stylesheet. This can be used to customize the look of all books.'))
|
||||
|
||||
|
||||
def accept(self, *args):
|
||||
c = config()
|
||||
c.set('serif_family', unicode(self.serif_family.currentFont().family()))
|
||||
@ -125,7 +141,10 @@ class Document(QWebPage):
|
||||
|
||||
def __init__(self, *args):
|
||||
QWebPage.__init__(self, *args)
|
||||
self.setObjectName("py_bridge")
|
||||
self.debug_javascript = False
|
||||
#self.js_bridge = PythonJS(self.js_callback)
|
||||
|
||||
self.setLinkDelegationPolicy(self.DelegateAllLinks)
|
||||
self.scroll_marks = []
|
||||
pal = self.palette()
|
||||
@ -160,12 +179,17 @@ class Document(QWebPage):
|
||||
self.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(pt.name))
|
||||
|
||||
def load_javascript_libraries(self):
|
||||
self.mainFrame().addToJavaScriptWindowObject("py_bridge", self)
|
||||
from calibre.resources import jquery, jquery_scrollTo
|
||||
self.javascript(jquery)
|
||||
self.javascript(jquery_scrollTo)
|
||||
self.javascript(bookmarks)
|
||||
self.javascript(referencing)
|
||||
|
||||
@pyqtSignature("")
|
||||
def animated_scroll_done(self):
|
||||
self.emit(SIGNAL('animated_scroll_done()'))
|
||||
|
||||
def reference_mode(self, enable):
|
||||
self.javascript(('enter' if enable else 'leave')+'_reference_mode()')
|
||||
|
||||
@ -302,6 +326,12 @@ class DocumentView(QWebView):
|
||||
self.connect(self.document, SIGNAL('linkClicked(QUrl)'), self.link_clicked)
|
||||
self.connect(self.document, SIGNAL('linkHovered(QString,QString,QString)'), self.link_hovered)
|
||||
self.connect(self.document, SIGNAL('selectionChanged()'), self.selection_changed)
|
||||
self.connect(self.document, SIGNAL('animated_scroll_done()'),
|
||||
self.animated_scroll_done, Qt.QueuedConnection)
|
||||
|
||||
def animated_scroll_done(self):
|
||||
if self.manager is not None:
|
||||
self.manager.scrolled(self.document.scroll_fraction)
|
||||
|
||||
def reference_mode(self, enable):
|
||||
self._reference_mode = enable
|
||||
|
@ -54,10 +54,15 @@ function calculate_bookmark(y) {
|
||||
return sel + "|" + ratio;
|
||||
}
|
||||
|
||||
function animated_scrolling_done() {
|
||||
window.py_bridge.animated_scroll_done();
|
||||
}
|
||||
|
||||
function scroll_to_bookmark(bookmark) {
|
||||
bm = bookmark.split("|");
|
||||
var ratio = 0.7 * parseFloat(bm[1]);
|
||||
$.scrollTo($(bm[0]), 1000, {over:ratio});
|
||||
$.scrollTo($(bm[0]), 1000,
|
||||
{over:ratio, onAfter:function(){window.py_bridge.animated_scroll_done()}});
|
||||
}
|
||||
|
||||
'''
|
||||
@ -112,7 +117,8 @@ function goto_reference(ref) {
|
||||
if (num < 0) {alert("Invalid reference: "+ref); return;}
|
||||
var p = $("p");
|
||||
if (num >= p.length) {alert("Reference not found: "+ref); return;}
|
||||
$.scrollTo($(p[num]), 1000);
|
||||
$.scrollTo($(p[num]), 1000,
|
||||
{onAfter:function(){window.py_bridge.animated_scroll_done()}});
|
||||
}
|
||||
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user