mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Remember the last used font size multiplier. Fixes #774343 (Private bug)
This commit is contained in:
parent
9dfc49aeb5
commit
d3545e9c0a
@ -8,10 +8,11 @@ import os, math, re, glob, sys
|
|||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
from PyQt4.Qt import (QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer,
|
||||||
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
QPainter, QPalette, QBrush, QFontDatabase, QDialog,
|
||||||
QColor, QPoint, QImage, QRegion, QVariant, QIcon, \
|
QColor, QPoint, QImage, QRegion, QVariant, QIcon,
|
||||||
QFont, pyqtSignature, QAction, QByteArray, QMenu
|
QFont, pyqtSignature, QAction, QByteArray, QMenu,
|
||||||
|
pyqtSignal)
|
||||||
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
||||||
|
|
||||||
from calibre.utils.config import Config, StringConfig
|
from calibre.utils.config import Config, StringConfig
|
||||||
@ -496,6 +497,7 @@ class EntityDeclarationProcessor(object): # {{{
|
|||||||
|
|
||||||
class DocumentView(QWebView): # {{{
|
class DocumentView(QWebView): # {{{
|
||||||
|
|
||||||
|
magnification_changed = pyqtSignal(object)
|
||||||
DISABLED_BRUSH = QBrush(Qt.lightGray, Qt.Dense5Pattern)
|
DISABLED_BRUSH = QBrush(Qt.lightGray, Qt.Dense5Pattern)
|
||||||
|
|
||||||
def __init__(self, *args):
|
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:
|
if notify and self.manager is not None and self.document.ypos != old_pos:
|
||||||
self.manager.scrolled(self.scroll_fraction)
|
self.manager.scrolled(self.scroll_fraction)
|
||||||
|
|
||||||
|
@dynamic_property
|
||||||
def multiplier(self):
|
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):
|
def magnify_fonts(self):
|
||||||
self.document.mainFrame().setTextSizeMultiplier(self.multiplier()+0.2)
|
self.multiplier += 0.2
|
||||||
return self.document.scroll_fraction
|
return self.document.scroll_fraction
|
||||||
|
|
||||||
def shrink_fonts(self):
|
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
|
return self.document.scroll_fraction
|
||||||
|
|
||||||
def changeEvent(self, event):
|
def changeEvent(self, event):
|
||||||
|
@ -175,6 +175,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
def __init__(self, pathtoebook=None, debug_javascript=False):
|
def __init__(self, pathtoebook=None, debug_javascript=False):
|
||||||
MainWindow.__init__(self, None)
|
MainWindow.__init__(self, None)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.view.magnification_changed.connect(self.magnification_changed)
|
||||||
self.show_toc_on_open = False
|
self.show_toc_on_open = False
|
||||||
self.current_book_has_toc = False
|
self.current_book_has_toc = False
|
||||||
self.base_window_title = unicode(self.windowTitle())
|
self.base_window_title = unicode(self.windowTitle())
|
||||||
@ -345,6 +346,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
if self.toc.isVisible():
|
if self.toc.isVisible():
|
||||||
vprefs.set('viewer_splitter_state',
|
vprefs.set('viewer_splitter_state',
|
||||||
bytearray(self.splitter.saveState()))
|
bytearray(self.splitter.saveState()))
|
||||||
|
vprefs['multiplier'] = self.view.multiplier
|
||||||
|
|
||||||
def restore_state(self):
|
def restore_state(self):
|
||||||
state = vprefs.get('viewer_toolbar_state', None)
|
state = vprefs.get('viewer_toolbar_state', None)
|
||||||
@ -354,6 +356,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.restoreState(state, self.STATE_VERSION)
|
self.restoreState(state, self.STATE_VERSION)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
mult = vprefs.get('multiplier', None)
|
||||||
|
if mult:
|
||||||
|
self.view.multiplier = mult
|
||||||
|
|
||||||
|
|
||||||
def lookup(self, word):
|
def lookup(self, word):
|
||||||
@ -476,16 +481,22 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
|
|
||||||
def font_size_larger(self, checked):
|
def font_size_larger(self, checked):
|
||||||
frac = self.view.magnify_fonts()
|
frac = self.view.magnify_fonts()
|
||||||
self.action_font_size_larger.setEnabled(self.view.multiplier() < 3)
|
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_smaller.setEnabled(self.view.multiplier > 0.2)
|
||||||
self.set_page_number(frac)
|
self.set_page_number(frac)
|
||||||
|
|
||||||
def font_size_smaller(self, checked):
|
def font_size_smaller(self, checked):
|
||||||
frac = self.view.shrink_fonts()
|
frac = self.view.shrink_fonts()
|
||||||
self.action_font_size_larger.setEnabled(self.view.multiplier() < 3)
|
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_smaller.setEnabled(self.view.multiplier > 0.2)
|
||||||
self.set_page_number(frac)
|
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):
|
def find(self, text, repeat=False, backwards=False):
|
||||||
if not text:
|
if not text:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user