E-book viewer: Remember the last used font size multiplier. Fixes #774343 (Private bug)

This commit is contained in:
Kovid Goyal 2011-06-09 14:21:32 -06:00
parent 9dfc49aeb5
commit d3545e9c0a
2 changed files with 31 additions and 11 deletions

View File

@ -8,10 +8,11 @@ import os, math, re, glob, sys
from base64 import b64encode
from functools import partial
from PyQt4.Qt import QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
QColor, QPoint, QImage, QRegion, QVariant, QIcon, \
QFont, pyqtSignature, QAction, QByteArray, QMenu
from PyQt4.Qt import (QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer,
QPainter, QPalette, QBrush, QFontDatabase, QDialog,
QColor, QPoint, QImage, QRegion, QVariant, QIcon,
QFont, pyqtSignature, QAction, QByteArray, QMenu,
pyqtSignal)
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
from calibre.utils.config import Config, StringConfig
@ -496,6 +497,7 @@ class EntityDeclarationProcessor(object): # {{{
class DocumentView(QWebView): # {{{
magnification_changed = pyqtSignal(object)
DISABLED_BRUSH = QBrush(Qt.lightGray, Qt.Dense5Pattern)
def __init__(self, *args):
@ -908,15 +910,22 @@ class DocumentView(QWebView): # {{{
if notify and self.manager is not None and self.document.ypos != old_pos:
self.manager.scrolled(self.scroll_fraction)
@dynamic_property
def multiplier(self):
return self.document.mainFrame().textSizeMultiplier()
def fget(self):
return self.document.mainFrame().textSizeMultiplier()
def fset(self, val):
self.document.mainFrame().setTextSizeMultiplier(val)
self.magnification_changed.emit(val)
return property(fget=fget, fset=fset)
def magnify_fonts(self):
self.document.mainFrame().setTextSizeMultiplier(self.multiplier()+0.2)
self.multiplier += 0.2
return self.document.scroll_fraction
def shrink_fonts(self):
self.document.mainFrame().setTextSizeMultiplier(max(self.multiplier()-0.2, 0))
if self.multiplier >= 0.2:
self.multiplier -= 0.2
return self.document.scroll_fraction
def changeEvent(self, event):

View File

@ -175,6 +175,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
def __init__(self, pathtoebook=None, debug_javascript=False):
MainWindow.__init__(self, None)
self.setupUi(self)
self.view.magnification_changed.connect(self.magnification_changed)
self.show_toc_on_open = False
self.current_book_has_toc = False
self.base_window_title = unicode(self.windowTitle())
@ -345,6 +346,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
if self.toc.isVisible():
vprefs.set('viewer_splitter_state',
bytearray(self.splitter.saveState()))
vprefs['multiplier'] = self.view.multiplier
def restore_state(self):
state = vprefs.get('viewer_toolbar_state', None)
@ -354,6 +356,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
self.restoreState(state, self.STATE_VERSION)
except:
pass
mult = vprefs.get('multiplier', None)
if mult:
self.view.multiplier = mult
def lookup(self, word):
@ -476,16 +481,22 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
def font_size_larger(self, checked):
frac = self.view.magnify_fonts()
self.action_font_size_larger.setEnabled(self.view.multiplier() < 3)
self.action_font_size_smaller.setEnabled(self.view.multiplier() > 0.2)
self.action_font_size_larger.setEnabled(self.view.multiplier < 3)
self.action_font_size_smaller.setEnabled(self.view.multiplier > 0.2)
self.set_page_number(frac)
def font_size_smaller(self, checked):
frac = self.view.shrink_fonts()
self.action_font_size_larger.setEnabled(self.view.multiplier() < 3)
self.action_font_size_smaller.setEnabled(self.view.multiplier() > 0.2)
self.action_font_size_larger.setEnabled(self.view.multiplier < 3)
self.action_font_size_smaller.setEnabled(self.view.multiplier > 0.2)
self.set_page_number(frac)
def magnification_changed(self, val):
tt = _('Make font size %s\nCurrent magnification: %.1f')
self.action_font_size_larger.setToolTip(
tt %(_('larger'), val))
self.action_font_size_smaller.setToolTip(
tt %(_('smaller'), val))
def find(self, text, repeat=False, backwards=False):
if not text: