mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Make font settings configurable
This commit is contained in:
parent
db4ff1e605
commit
92b2cc2d5f
200
src/calibre/gui2/viewer/config.ui
Normal file
200
src/calibre/gui2/viewer/config.ui
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
<ui version="4.0" >
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog" >
|
||||||
|
<property name="geometry" >
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>479</width>
|
||||||
|
<height>436</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle" >
|
||||||
|
<string>Configure Ebook viewer</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon" >
|
||||||
|
<iconset resource="../images.qrc" >
|
||||||
|
<normaloff>:/images/config.svg</normaloff>:/images/config.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_4" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<widget class="QGroupBox" name="groupBox" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>&Font options</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<layout class="QGridLayout" name="gridLayout" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<widget class="QLabel" name="label" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Se&rif family:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>serif_family</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" >
|
||||||
|
<widget class="QFontComboBox" name="serif_family" />
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<widget class="QLabel" name="label_2" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Sans family:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>sans_family</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" >
|
||||||
|
<widget class="QFontComboBox" name="sans_family" />
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" >
|
||||||
|
<widget class="QLabel" name="label_3" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Monospace family:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>mono_family</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" >
|
||||||
|
<widget class="QFontComboBox" name="mono_family" />
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2" >
|
||||||
|
<item row="0" column="0" >
|
||||||
|
<widget class="QLabel" name="label_4" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Default font size:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>default_font_size</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" >
|
||||||
|
<widget class="QSpinBox" name="default_font_size" >
|
||||||
|
<property name="suffix" >
|
||||||
|
<string> px</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum" >
|
||||||
|
<number>8</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum" >
|
||||||
|
<number>40</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<widget class="QLabel" name="label_5" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Monospace &font size:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>mono_font_size</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" >
|
||||||
|
<widget class="QSpinBox" name="mono_font_size" >
|
||||||
|
<property name="suffix" >
|
||||||
|
<string> px</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum" >
|
||||||
|
<number>8</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum" >
|
||||||
|
<number>50</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" >
|
||||||
|
<widget class="QLabel" name="label_6" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>S&tandard font:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>standard_font</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" >
|
||||||
|
<widget class="QComboBox" name="standard_font" >
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Serif</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Sans-serif</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Monospace</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||||
|
<property name="orientation" >
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons" >
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../images.qrc" />
|
||||||
|
</resources>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>Dialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
@ -7,10 +7,13 @@ __docformat__ = 'restructuredtext en'
|
|||||||
'''
|
'''
|
||||||
import os, math
|
import os, math
|
||||||
from PyQt4.Qt import QWidget, QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
from PyQt4.Qt import QWidget, QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \
|
||||||
QPainter, QPalette, QBrush, QFontDatabase, \
|
QPainter, QPalette, QBrush, QFontDatabase, QDialog, \
|
||||||
QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion
|
QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion, QFont
|
||||||
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings
|
||||||
|
|
||||||
|
from calibre.utils.config import Config, StringConfig
|
||||||
|
from calibre.gui2.viewer.config_ui import Ui_Dialog
|
||||||
|
|
||||||
def load_builtin_fonts():
|
def load_builtin_fonts():
|
||||||
from calibre.ebooks.lrf.fonts.liberation import LiberationMono_BoldItalic
|
from calibre.ebooks.lrf.fonts.liberation import LiberationMono_BoldItalic
|
||||||
QFontDatabase.addApplicationFontFromData(QByteArray(LiberationMono_BoldItalic.font_data))
|
QFontDatabase.addApplicationFontFromData(QByteArray(LiberationMono_BoldItalic.font_data))
|
||||||
@ -40,8 +43,68 @@ def load_builtin_fonts():
|
|||||||
# print f
|
# print f
|
||||||
return 'Liberation Serif', 'Liberation Sans', 'Liberation Mono'
|
return 'Liberation Serif', 'Liberation Sans', 'Liberation Mono'
|
||||||
|
|
||||||
|
def config(defaults=None):
|
||||||
|
desc = _('Options to customize the ebook viewer')
|
||||||
|
if defaults is None:
|
||||||
|
c = Config('viewer', desc)
|
||||||
|
else:
|
||||||
|
c = StringConfig(defaults, desc)
|
||||||
|
|
||||||
|
fonts = c.add_group('FONTS', _('Font options'))
|
||||||
|
fonts('serif_family', default='Liberation Serif', help=_('The serif font family'))
|
||||||
|
fonts('sans_family', default='Liberation Sans', help=_('The sans-serif font family'))
|
||||||
|
fonts('mono_family', default='Liberation Mono', help=_('The monospaced font family'))
|
||||||
|
fonts('default_font_size', default=20, help=_('The standard font size in px'))
|
||||||
|
fonts('mono_font_size', default=16, help=_('The monospaced font size in px'))
|
||||||
|
fonts('standard_font', default='serif', help=_('The standard font type'))
|
||||||
|
|
||||||
|
return c
|
||||||
|
|
||||||
|
class ConfigDialog(QDialog, Ui_Dialog):
|
||||||
|
|
||||||
|
def __init__(self, *args):
|
||||||
|
QDialog.__init__(self, *args)
|
||||||
|
self.setupUi(self)
|
||||||
|
|
||||||
|
opts = config().parse()
|
||||||
|
self.serif_family.setCurrentFont(QFont(opts.serif_family))
|
||||||
|
self.sans_family.setCurrentFont(QFont(opts.sans_family))
|
||||||
|
self.mono_family.setCurrentFont(QFont(opts.mono_family))
|
||||||
|
self.default_font_size.setValue(opts.default_font_size)
|
||||||
|
self.mono_font_size.setValue(opts.mono_font_size)
|
||||||
|
self.standard_font.setCurrentIndex({'serif':0, 'sans':1, 'mono':2}[opts.standard_font])
|
||||||
|
|
||||||
|
def accept(self, *args):
|
||||||
|
c = config()
|
||||||
|
c.set('serif_family', unicode(self.serif_family.currentFont().family()))
|
||||||
|
c.set('sans_family', unicode(self.sans_family.currentFont().family()))
|
||||||
|
c.set('mono_family', unicode(self.mono_family.currentFont().family()))
|
||||||
|
c.set('default_font_size', self.default_font_size.value())
|
||||||
|
c.set('mono_font_size', self.mono_font_size.value())
|
||||||
|
c.set('standard_font', {0:'serif', 1:'sans', 2:'mono'}[self.standard_font.currentIndex()])
|
||||||
|
return QDialog.accept(self, *args)
|
||||||
|
|
||||||
|
|
||||||
class Document(QWebPage):
|
class Document(QWebPage):
|
||||||
|
|
||||||
|
def set_font_settings(self):
|
||||||
|
opts = config().parse()
|
||||||
|
settings = self.settings()
|
||||||
|
settings.setFontSize(QWebSettings.DefaultFontSize, opts.default_font_size)
|
||||||
|
settings.setFontSize(QWebSettings.DefaultFixedFontSize, opts.mono_font_size)
|
||||||
|
settings.setFontSize(QWebSettings.MinimumLogicalFontSize, 8)
|
||||||
|
settings.setFontSize(QWebSettings.MinimumFontSize, 8)
|
||||||
|
settings.setFontFamily(QWebSettings.StandardFont, {'serif':opts.serif_family, 'sans':opts.sans_family, 'mono':opts.mono_family}[opts.standard_font])
|
||||||
|
settings.setFontFamily(QWebSettings.SerifFont, opts.serif_family)
|
||||||
|
settings.setFontFamily(QWebSettings.SansSerifFont, opts.sans_family)
|
||||||
|
settings.setFontFamily(QWebSettings.FixedFont, opts.mono_family)
|
||||||
|
|
||||||
|
def do_config(self, parent=None):
|
||||||
|
d = ConfigDialog(parent)
|
||||||
|
if d.exec_() == QDialog.Accepted:
|
||||||
|
self.set_font_settings()
|
||||||
|
self.triggerAction(QWebPage.Reload)
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QWebPage.__init__(self, *args)
|
QWebPage.__init__(self, *args)
|
||||||
self.setLinkDelegationPolicy(self.DelegateAllLinks)
|
self.setLinkDelegationPolicy(self.DelegateAllLinks)
|
||||||
@ -53,15 +116,8 @@ class Document(QWebPage):
|
|||||||
settings = self.settings()
|
settings = self.settings()
|
||||||
|
|
||||||
# Fonts
|
# Fonts
|
||||||
serif, sans, mono = load_builtin_fonts()
|
load_builtin_fonts()
|
||||||
settings.setFontSize(QWebSettings.DefaultFontSize, 20)
|
self.set_font_settings()
|
||||||
settings.setFontSize(QWebSettings.DefaultFixedFontSize, 16)
|
|
||||||
settings.setFontSize(QWebSettings.MinimumLogicalFontSize, 8)
|
|
||||||
settings.setFontSize(QWebSettings.MinimumFontSize, 8)
|
|
||||||
settings.setFontFamily(QWebSettings.StandardFont, serif)
|
|
||||||
settings.setFontFamily(QWebSettings.SerifFont, serif)
|
|
||||||
settings.setFontFamily(QWebSettings.SansSerifFont, sans)
|
|
||||||
settings.setFontFamily(QWebSettings.FixedFont, mono)
|
|
||||||
|
|
||||||
# Security
|
# Security
|
||||||
settings.setAttribute(QWebSettings.JavaEnabled, False)
|
settings.setAttribute(QWebSettings.JavaEnabled, False)
|
||||||
@ -178,6 +234,9 @@ class DocumentView(QWebView):
|
|||||||
self.connect(self.document, SIGNAL('linkHovered(QString,QString,QString)'), self.link_hovered)
|
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('selectionChanged()'), self.selection_changed)
|
||||||
|
|
||||||
|
def config(self, parent=None):
|
||||||
|
self.document.do_config(parent)
|
||||||
|
|
||||||
def selection_changed(self):
|
def selection_changed(self):
|
||||||
if self.manager is not None:
|
if self.manager is not None:
|
||||||
self.manager.selection_changed(unicode(self.document.selectedText()))
|
self.manager.selection_changed(unicode(self.document.selectedText()))
|
||||||
|
@ -210,6 +210,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
lambda x:self.find(unicode(self.search.text()), True, repeat=True))
|
lambda x:self.find(unicode(self.search.text()), True, repeat=True))
|
||||||
self.connect(self.action_back, SIGNAL('triggered(bool)'), self.back)
|
self.connect(self.action_back, SIGNAL('triggered(bool)'), self.back)
|
||||||
self.connect(self.action_forward, SIGNAL('triggered(bool)'), self.forward)
|
self.connect(self.action_forward, SIGNAL('triggered(bool)'), self.forward)
|
||||||
|
self.connect(self.action_preferences, SIGNAL('triggered(bool)'), lambda x: self.view.config(self))
|
||||||
self.connect(self.pos, SIGNAL('valueChanged(double)'), self.goto_page)
|
self.connect(self.pos, SIGNAL('valueChanged(double)'), self.goto_page)
|
||||||
self.connect(self.vertical_scrollbar, SIGNAL('valueChanged(int)'),
|
self.connect(self.vertical_scrollbar, SIGNAL('valueChanged(int)'),
|
||||||
lambda x: self.goto_page(x/100.))
|
lambda x: self.goto_page(x/100.))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user