From 30595b6bf0309907ed0b7cccd5e60578b6a27a69 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Jan 2013 16:25:47 +0530 Subject: [PATCH] E-book viewer: Add an option to hide the toolbars in the viewer window (Preferences->Miscellaneous->Show controls in the viewr preferences). You can unhide them by right clicking in the viewer window. --- src/calibre/gui2/viewer/config.py | 3 +++ src/calibre/gui2/viewer/config.ui | 19 +++++++++++++------ src/calibre/gui2/viewer/documentview.py | 5 ++++- src/calibre/gui2/viewer/main.py | 12 ++++++++++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/viewer/config.py b/src/calibre/gui2/viewer/config.py index 2b36164798..f4d23602ce 100644 --- a/src/calibre/gui2/viewer/config.py +++ b/src/calibre/gui2/viewer/config.py @@ -70,6 +70,7 @@ def config(defaults=None): c.add_opt('bottom_margin', default=20) c.add_opt('text_color', default=None) c.add_opt('background_color', default=None) + c.add_opt('show_controls', default=True) fonts = c.add_group('FONTS', _('Font options')) fonts('serif_family', default='Times New Roman' if iswindows else 'Liberation Serif', @@ -221,6 +222,7 @@ class ConfigDialog(QDialog, Ui_Dialog): for x in ('text', 'background'): setattr(self, 'current_%s_color'%x, getattr(opts, '%s_color'%x)) self.update_sample_colors() + self.opt_show_controls.setChecked(opts.show_controls) def change_color(self, which, reset=False): if reset: @@ -292,6 +294,7 @@ class ConfigDialog(QDialog, Ui_Dialog): self.opt_override_book_margins.isChecked()) c.set('text_color', self.current_text_color) c.set('background_color', self.current_background_color) + c.set('show_controls', self.opt_show_controls.isChecked()) for x in ('top', 'bottom', 'side'): c.set(x+'_margin', int(getattr(self, 'opt_%s_margin'%x).value())) diff --git a/src/calibre/gui2/viewer/config.ui b/src/calibre/gui2/viewer/config.ui index 3ae2efe597..b36a5caceb 100644 --- a/src/calibre/gui2/viewer/config.ui +++ b/src/calibre/gui2/viewer/config.ui @@ -347,8 +347,8 @@ QToolBox::tab:hover { 0 0 - 811 - 352 + 352 + 176 @@ -573,8 +573,8 @@ QToolBox::tab:hover { 0 0 - 352 - 123 + 811 + 352 @@ -605,20 +605,27 @@ QToolBox::tab:hover { - + Remember last used &window size and layout - + Remember the &current page when quitting + + + + Show &controls in the viewer window + + + diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 6f6f202619..2086ae9b8a 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -33,6 +33,7 @@ class Document(QWebPage): # {{{ page_turn = pyqtSignal(object) mark_element = pyqtSignal(QWebElement) + settings_changed = pyqtSignal() def set_font_settings(self, opts): settings = self.settings() @@ -57,6 +58,7 @@ class Document(QWebPage): # {{{ self.set_font_settings(opts) self.set_user_stylesheet(opts) self.misc_config(opts) + self.settings_changed.emit() self.after_load() def __init__(self, shortcuts, parent=None, debug_javascript=False): @@ -153,6 +155,7 @@ class Document(QWebPage): # {{{ self.cols_per_screen = opts.cols_per_screen self.side_margin = opts.side_margin self.top_margin, self.bottom_margin = opts.top_margin, opts.bottom_margin + self.show_controls = opts.show_controls def fit_images(self): if self.do_fit_images and not self.in_paged_mode: @@ -676,7 +679,7 @@ class DocumentView(QWebView): # {{{ if not text and img.isNull() and self.manager is not None: menu.addSeparator() - if self.document.in_fullscreen_mode and self.manager is not None: + if (not self.document.show_controls or self.document.in_fullscreen_mode) and self.manager is not None: menu.addAction(self.manager.toggle_toolbar_action) menu.addAction(self.manager.action_full_screen) diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 903f41eeb5..bcb10a2f5b 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -303,6 +303,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer): self.toggle_toolbar_action = QAction(_('Show/hide controls'), self) self.toggle_toolbar_action.setCheckable(True) self.toggle_toolbar_action.triggered.connect(self.toggle_toolbars) + self.toolbar_hidden = None self.addAction(self.toggle_toolbar_action) self.full_screen_label_anim = QPropertyAnimation( self.full_screen_label, 'size') @@ -359,7 +360,10 @@ class EbookViewer(MainWindow, Ui_EbookViewer): # continue to function even when the toolbars are hidden self.addAction(action) + self.view.document.settings_changed.connect(self.settings_changed) + self.restore_state() + self.settings_changed() self.action_toggle_paged_mode.toggled[bool].connect(self.toggle_paged_mode) if (start_in_fullscreen or self.view.document.start_in_fullscreen): self.action_full_screen.trigger() @@ -373,6 +377,11 @@ class EbookViewer(MainWindow, Ui_EbookViewer): if at_start: return self.reload() + def settings_changed(self): + for x in ('', '2'): + x = getattr(self, 'tool_bar'+x) + x.setVisible(self.view.document.show_controls) + def reload(self): if hasattr(self, 'current_index') and self.current_index > -1: self.view.document.page_position.save(overwrite=False) @@ -575,8 +584,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer): self.vertical_scrollbar.setVisible(True) self.window_mode_changed = 'normal' self.esc_full_screen_action.setEnabled(False) - self.tool_bar.setVisible(True) - self.tool_bar2.setVisible(True) + self.settings_changed() self.full_screen_label.setVisible(False) if hasattr(self, '_original_frame_margins'): om = self._original_frame_margins