mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Edit Book: Add a setting to control icon size for the toolbars (Preferences->Toolbars)
This commit is contained in:
parent
c510fdc2c6
commit
ec2dfb5d74
@ -70,6 +70,7 @@ d['templates'] = {}
|
||||
d['auto_close_tags'] = True
|
||||
d['restore_book_state'] = True
|
||||
d['editor_accepts_drops'] = True
|
||||
d['toolbar_icon_size'] = 24
|
||||
del d
|
||||
|
||||
ucase_map = {l:string.ascii_uppercase[i] for i, l in enumerate(string.ascii_lowercase)}
|
||||
|
@ -148,6 +148,7 @@ class Boss(QObject):
|
||||
|
||||
def preferences(self):
|
||||
orig_spell = tprefs['inline_spell_check']
|
||||
orig_size = tprefs['toolbar_icon_size']
|
||||
p = Preferences(self.gui)
|
||||
ret = p.exec_()
|
||||
if p.dictionaries_changed:
|
||||
@ -158,6 +159,12 @@ class Boss(QObject):
|
||||
for ed in editors.itervalues():
|
||||
if hasattr(ed, 'populate_toolbars'):
|
||||
ed.populate_toolbars()
|
||||
if orig_size != tprefs['toolbar_icon_size']:
|
||||
for ed in editors.itervalues():
|
||||
if hasattr(ed, 'bars'):
|
||||
for bar in ed.bars:
|
||||
bar.setIconSize(QSize(tprefs['toolbar_icon_size'], tprefs['toolbar_icon_size']))
|
||||
|
||||
if ret == p.Accepted:
|
||||
setup_cssutils_serialization()
|
||||
self.gui.apply_settings()
|
||||
|
@ -10,7 +10,7 @@ import sys
|
||||
from functools import partial
|
||||
|
||||
from PyQt5.Qt import (
|
||||
QMainWindow, Qt, QApplication, pyqtSignal, QLabel, QIcon, QFormLayout,
|
||||
QMainWindow, Qt, QApplication, pyqtSignal, QLabel, QIcon, QFormLayout, QSize,
|
||||
QDialog, QSpinBox, QCheckBox, QDialogButtonBox, QToolButton, QMenu, QInputDialog)
|
||||
|
||||
from calibre.gui2 import error_dialog
|
||||
@ -284,6 +284,7 @@ class Editor(QMainWindow):
|
||||
for x in self.bars:
|
||||
x.setFloatable(False)
|
||||
x.topLevelChanged.connect(self.toolbar_floated)
|
||||
x.setIconSize(QSize(tprefs['toolbar_icon_size'], tprefs['toolbar_icon_size']))
|
||||
self.restore_state()
|
||||
|
||||
def toolbar_floated(self, floating):
|
||||
|
@ -11,7 +11,7 @@ from functools import partial
|
||||
|
||||
from PyQt5.Qt import (
|
||||
QMainWindow, Qt, QApplication, pyqtSignal, QMenu, qDrawShadeRect, QPainter,
|
||||
QImage, QColor, QIcon, QPixmap, QToolButton, QAction, QTextCursor)
|
||||
QImage, QColor, QIcon, QPixmap, QToolButton, QAction, QTextCursor, QSize)
|
||||
|
||||
from calibre import prints
|
||||
from calibre.constants import DEBUG
|
||||
@ -25,7 +25,8 @@ from calibre.gui2.tweak_book.editor.help import help_url
|
||||
from calibre.gui2.tweak_book.editor.text import TextEdit
|
||||
from calibre.utils.icu import utf16_length
|
||||
|
||||
def create_icon(text, palette=None, sz=32, divider=2):
|
||||
def create_icon(text, palette=None, sz=None, divider=2):
|
||||
sz = sz or tprefs['toolbar_icon_size']
|
||||
if palette is None:
|
||||
palette = QApplication.palette()
|
||||
img = QImage(sz, sz, QImage.Format_ARGB32)
|
||||
@ -34,7 +35,7 @@ def create_icon(text, palette=None, sz=32, divider=2):
|
||||
p.setRenderHints(p.TextAntialiasing | p.Antialiasing)
|
||||
qDrawShadeRect(p, img.rect(), palette, fill=QColor('#ffffff'), lineWidth=1, midLineWidth=1)
|
||||
f = p.font()
|
||||
f.setFamily('Liberation Sans'), f.setPixelSize(sz // divider), f.setBold(True)
|
||||
f.setFamily('Liberation Sans'), f.setPixelSize(int(sz // divider)), f.setBold(True)
|
||||
p.setFont(f), p.setPen(Qt.black)
|
||||
p.drawText(img.rect().adjusted(2, 2, -2, -2), Qt.AlignCenter, text)
|
||||
p.end()
|
||||
@ -301,6 +302,7 @@ class Editor(QMainWindow):
|
||||
for x in self.bars:
|
||||
x.setFloatable(False)
|
||||
x.topLevelChanged.connect(self.toolbar_floated)
|
||||
x.setIconSize(QSize(tprefs['toolbar_icon_size'], tprefs['toolbar_icon_size']))
|
||||
|
||||
def toolbar_floated(self, floating):
|
||||
if not floating:
|
||||
|
@ -425,6 +425,14 @@ class ToolbarSettings(QWidget):
|
||||
self.toggle_visibility(False)
|
||||
self.bars.currentIndexChanged.connect(self.bar_changed)
|
||||
|
||||
self.toolbar_icon_size = ics = QSpinBox(self)
|
||||
ics.setMinimum(16), ics.setMaximum(128), ics.setSuffix(' px'), ics.setValue(tprefs['toolbar_icon_size'])
|
||||
ics.setToolTip('<p>' + _('Adjust the size of icons on all toolbars'))
|
||||
r = l.rowCount()
|
||||
self.toolbar_icon_size_label = la = QLabel(_('Toolbar &icon size:'))
|
||||
la.setBuddy(ics)
|
||||
l.addWidget(la, r, 0), l.addWidget(ics, r, 1)
|
||||
|
||||
def read_settings(self, prefs=None):
|
||||
prefs = prefs or tprefs
|
||||
val = self.original_settings = {}
|
||||
@ -541,9 +549,12 @@ class ToolbarSettings(QWidget):
|
||||
self.read_settings(tprefs.defaults)
|
||||
self.original_settings = o
|
||||
self.build_lists()
|
||||
self.toolbar_icon_size.setValue(tprefs.defaults['toolbar_icon_size'])
|
||||
self.changed_signal.emit()
|
||||
|
||||
def commit(self):
|
||||
if self.toolbar_icon_size.value() != tprefs['toolbar_icon_size']:
|
||||
tprefs['toolbar_icon_size'] = self.toolbar_icon_size.value()
|
||||
if self.original_settings != self.current_settings:
|
||||
self.changed = True
|
||||
with tprefs:
|
||||
|
@ -14,7 +14,7 @@ from future_builtins import map
|
||||
from PyQt5.Qt import (
|
||||
QDockWidget, Qt, QLabel, QIcon, QAction, QApplication, QWidget, QEvent,
|
||||
QVBoxLayout, QStackedWidget, QTabWidget, QImage, QPixmap, pyqtSignal,
|
||||
QMenu, QHBoxLayout, QTimer, QUrl)
|
||||
QMenu, QHBoxLayout, QTimer, QUrl, QSize)
|
||||
|
||||
from calibre import prints
|
||||
from calibre.constants import __appname__, get_version, isosx, DEBUG
|
||||
@ -289,6 +289,8 @@ class Main(MainWindow):
|
||||
self.setCorner(getattr(Qt, '%s%sCorner' % tuple(map(capitalize, (v, h)))), area)
|
||||
self.preview.apply_settings()
|
||||
self.live_css.apply_theme()
|
||||
for bar in (self.global_bar, self.tools_bar, self.plugins_bar):
|
||||
bar.setIconSize(QSize(tprefs['toolbar_icon_size'], tprefs['toolbar_icon_size']))
|
||||
|
||||
def show_status_message(self, msg, timeout=5):
|
||||
self.status_bar.showMessage(msg, int(timeout*1000))
|
||||
@ -609,6 +611,7 @@ class Main(MainWindow):
|
||||
b = self.addToolBar(text)
|
||||
b.setObjectName(name) # Needed for saveState
|
||||
actions[name] = b.toggleViewAction()
|
||||
b.setIconSize(QSize(tprefs['toolbar_icon_size'], tprefs['toolbar_icon_size']))
|
||||
return b
|
||||
self.global_bar = create(_('Book tool bar'), 'global')
|
||||
self.tools_bar = create(_('Tools tool bar'), 'tools')
|
||||
|
Loading…
x
Reference in New Issue
Block a user