Add an option to use two lines for the text under the toolbar button in Preferences->Look & feel

This commit is contained in:
Kovid Goyal 2018-05-23 19:09:59 +05:30
parent 7fb27f7fa3
commit b8b6e85abe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 90 additions and 23 deletions

View File

@ -167,6 +167,7 @@ def create_defs():
defs['qv_follows_column'] = False defs['qv_follows_column'] = False
defs['book_details_narrow_comments_layout'] = 'float' defs['book_details_narrow_comments_layout'] = 'float'
defs['book_list_split'] = False defs['book_list_split'] = False
defs['wrap_toolbar_text'] = False
create_defs() create_defs()
@ -348,9 +349,9 @@ def extension(path):
def warning_dialog(parent, title, msg, det_msg='', show=False, def warning_dialog(parent, title, msg, det_msg='', show=False,
show_copy_button=True): show_copy_button=True):
from calibre.gui2.dialogs.message_box import MessageBox from calibre.gui2.dialogs.message_box import MessageBox
d = MessageBox(MessageBox.WARNING, _('WARNING:')+ ' ' + d = MessageBox(MessageBox.WARNING, _('WARNING:'
title, msg, det_msg, parent=parent, )+ ' ' + title, msg, det_msg, parent=parent,
show_copy_button=show_copy_button) show_copy_button=show_copy_button)
if show: if show:
return d.exec_() return d.exec_()
return d return d
@ -359,9 +360,9 @@ def warning_dialog(parent, title, msg, det_msg='', show=False,
def error_dialog(parent, title, msg, det_msg='', show=False, def error_dialog(parent, title, msg, det_msg='', show=False,
show_copy_button=True): show_copy_button=True):
from calibre.gui2.dialogs.message_box import MessageBox from calibre.gui2.dialogs.message_box import MessageBox
d = MessageBox(MessageBox.ERROR, _('ERROR:')+ ' ' + d = MessageBox(MessageBox.ERROR, _('ERROR:'
title, msg, det_msg, parent=parent, ) + ' ' + title, msg, det_msg, parent=parent,
show_copy_button=show_copy_button) show_copy_button=show_copy_button)
if show: if show:
return d.exec_() return d.exec_()
return d return d

View File

@ -7,6 +7,7 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from functools import partial
import sip import sip
from PyQt5.Qt import ( from PyQt5.Qt import (
Qt, QAction, QMenu, QObject, QToolBar, QToolButton, QSize, pyqtSignal, Qt, QAction, QMenu, QObject, QToolBar, QToolButton, QSize, pyqtSignal,
@ -61,6 +62,60 @@ class RevealBar(QWidget): # {{{
# }}} # }}}
MAX_TEXT_LENGTH = 10
connected_pairs = set()
def wrap_button_text(text, max_len=MAX_TEXT_LENGTH):
parts = text.split()
ans = ''
broken = False
for word in parts:
if broken:
ans += ' ' + word
else:
if len(ans) + len(word) < max_len:
if ans:
ans += ' ' + word
else:
ans = word
else:
if ans:
ans += '\n' + word
broken = True
else:
ans = word
if not broken:
if ' ' in ans:
ans = '\n'.join(ans.split(' ', 1))
elif '/' in ans:
ans = '/\n'.join(ans.split('/', 1))
else:
ans += '\n\xa0'
return ans
def rewrap_button(w):
if not sip.isdeleted(w):
w.setText(wrap_button_text(w.defaultAction().text()))
def wrap_all_button_texts(all_buttons):
if not all_buttons:
return
for w in all_buttons:
if hasattr(w, 'defaultAction'):
ac = w.defaultAction()
text = ac.text()
key = id(w), id(ac)
if key not in connected_pairs:
ac.changed.connect(partial(rewrap_button, w))
connected_pairs.add(key)
else:
text = w.text()
w.setText(wrap_button_text(text))
def create_donate_button(action): def create_donate_button(action):
ans = ThrobbingButton() ans = ThrobbingButton()
ans.setAutoRaise(True) ans.setAutoRaise(True)
@ -134,30 +189,32 @@ class ToolBar(QToolBar): # {{{
self.clear() self.clear()
self.added_actions = [] self.added_actions = []
self.donate_button = None self.donate_button = None
self.all_widgets = []
bar = self
for what in actions: for what in actions:
if what is None: if what is None:
bar.addSeparator() self.addSeparator()
elif what == 'Location Manager': elif what == 'Location Manager':
for ac in self.location_manager.all_actions: for ac in self.location_manager.all_actions:
bar.addAction(ac) self.addAction(ac)
bar.added_actions.append(ac) self.added_actions.append(ac)
bar.setup_tool_button(bar, ac, QToolButton.MenuButtonPopup) self.setup_tool_button(self, ac, QToolButton.MenuButtonPopup)
ac.setVisible(False) ac.setVisible(False)
elif what == 'Donate': elif what == 'Donate':
self.donate_button = create_donate_button(self.donate_action) self.donate_button = create_donate_button(self.donate_action)
bar.addWidget(self.donate_button) self.addWidget(self.donate_button)
self.donate_button.setIconSize(bar.iconSize()) self.donate_button.setIconSize(self.iconSize())
self.donate_button.setToolButtonStyle(self.toolButtonStyle()) self.donate_button.setToolButtonStyle(self.toolButtonStyle())
self.showing_donate = True self.showing_donate = True
elif what in self.gui.iactions: elif what in self.gui.iactions:
action = self.gui.iactions[what] action = self.gui.iactions[what]
bar.addAction(action.qaction) self.addAction(action.qaction)
self.added_actions.append(action.qaction) self.added_actions.append(action.qaction)
self.setup_tool_button(bar, action.qaction, action.popup_type) self.setup_tool_button(self, action.qaction, action.popup_type)
self.preferred_width = self.sizeHint().width() self.preferred_width = self.sizeHint().width()
if gprefs['wrap_toolbar_text']:
wrap_all_button_texts(self.all_widgets)
self.all_widgets = []
def setup_tool_button(self, bar, ac, menu_mode=None): def setup_tool_button(self, bar, ac, menu_mode=None):
ch = bar.widgetForAction(ac) ch = bar.widgetForAction(ac)
@ -165,6 +222,8 @@ class ToolBar(QToolBar): # {{{
ch = self.child_bar.widgetForAction(ac) ch = self.child_bar.widgetForAction(ac)
ch.setCursor(Qt.PointingHandCursor) ch.setCursor(Qt.PointingHandCursor)
ch.setAutoRaise(True) ch.setAutoRaise(True)
if hasattr(ch, 'setText') and hasattr(ch, 'text'):
self.all_widgets.append(ch)
m = ac.menu() m = ac.menu()
if m is not None: if m is not None:
if menu_mode is not None: if menu_mode is not None:

View File

@ -394,6 +394,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.opt_hidpi.setVisible(False), self.label_hidpi.setVisible(False) self.opt_hidpi.setVisible(False), self.label_hidpi.setVisible(False)
r('ui_style', gprefs, restart_required=True, choices=[(_('System default'), 'system'), (_('calibre style'), 'calibre')]) r('ui_style', gprefs, restart_required=True, choices=[(_('System default'), 'system'), (_('calibre style'), 'calibre')])
r('book_list_tooltips', gprefs) r('book_list_tooltips', gprefs)
r('wrap_toolbar_text', gprefs, restart_required=True)
r('show_layout_buttons', gprefs, restart_required=True) r('show_layout_buttons', gprefs, restart_required=True)
r('row_numbers_in_book_list', gprefs) r('row_numbers_in_book_list', gprefs)
r('tag_browser_old_look', gprefs) r('tag_browser_old_look', gprefs)
@ -478,11 +479,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('tag_browser_dont_collapse', gprefs, setting=CommaSeparatedList) r('tag_browser_dont_collapse', gprefs, setting=CommaSeparatedList)
choices = set([k for k in db.field_metadata.all_field_keys() choices = set([k for k in db.field_metadata.all_field_keys()
if (db.field_metadata[k]['is_category'] and if (db.field_metadata[k]['is_category'] and (
(db.field_metadata[k]['datatype'] in ['text', 'series', 'enumeration']) and db.field_metadata[k]['datatype'] in ['text', 'series', 'enumeration'
not db.field_metadata[k]['display'].get('is_names', False)) or ]) and not db.field_metadata[k]['display'].get('is_names', False)) or (
(db.field_metadata[k]['datatype'] in ['composite'] and db.field_metadata[k]['datatype'] in ['composite'
db.field_metadata[k]['display'].get('make_category', False))]) ] and db.field_metadata[k]['display'].get('make_category', False))])
choices -= set(['authors', 'publisher', 'formats', 'news', 'identifiers']) choices -= set(['authors', 'publisher', 'formats', 'news', 'identifiers'])
choices |= set(['search']) choices |= set(['search'])
self.opt_categories_using_hierarchy.update_items_cache(choices) self.opt_categories_using_hierarchy.update_items_cache(choices)
@ -722,8 +723,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
name = unicode(fi.family()) name = unicode(fi.family())
self.font_display.setFont(font) self.font_display.setFont(font)
self.font_display.setText(name + self.font_display.setText(name + ' [%dpt]'%fi.pointSize())
' [%dpt]'%fi.pointSize())
def change_font(self, *args): def change_font(self, *args):
fd = QFontDialog(self.build_font_obj(), self) fd = QFontDialog(self.build_font_obj(), self)

View File

@ -90,6 +90,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="opt_wrap_toolbar_text">
<property name="text">
<string>Use t&amp;wo lines for the text under the icons (needs restart)</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>