Implement switching of layout without restart

This commit is contained in:
Kovid Goyal 2023-12-22 15:38:49 +05:30
parent 051a3f6c34
commit bb1784e716
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 24 additions and 6 deletions

View File

@ -309,6 +309,17 @@ class CentralContainer(QWidget):
def is_wide(self):
return self.layout is Layout.wide
def change_layout(self, gui, is_wide):
layout = Layout.wide if is_wide else Layout.narrow
if layout is self.layout:
return False
gui.book_details.vertical = is_wide
self.layout = layout
self.write_settings()
# TODO: Also change the button order
self.relayout()
return True
def serialized_settings(self):
return {
'layout': self.layout.name,
@ -344,6 +355,8 @@ class CentralContainer(QWidget):
if self.serialized_settings() != before:
self.update_button_states_from_visibility()
self.relayout()
return True
return False
def reset_to_defaults(self):
before = self.serialized_settings()
@ -650,12 +663,12 @@ class CentralContainer(QWidget):
tb = max(0, width_to_share - cb)
central_width = available_width - (tb + cb)
if self.is_visible.tag_browser:
self.tag_browser.setGeometry(0, 0, int(tb), int(self.height()))
self.tag_browser.setGeometry(0, 0, int(tb), int(central_height))
self.left_handle.move(tb, 0)
central_x = self.left_handle.x() + self.left_handle.width()
self.right_handle.move(tb + central_width + self.left_handle.width(), 0)
if self.is_visible.cover_browser and not self.separate_cover_browser:
self.cover_browser.setGeometry(int(self.right_handle.x() + self.right_handle.width()), 0, int(cb), int(self.height()))
self.cover_browser.setGeometry(int(self.right_handle.x() + self.right_handle.width()), 0, int(cb), int(central_height))
self.top_handle.resize(int(central_width), int(normal_handle_width if self.is_visible.quick_view else 0))
central_height -= self.top_handle.height()
qv = 0

View File

@ -721,7 +721,6 @@ class LayoutMixin: # {{{
def save_layout_state(self):
for x in ('library', 'memory', 'card_a', 'card_b'):
getattr(self, x+'_view').save_state()
self.layout_container.write_settings()
self.grid_view_button.save_state()
self.search_bar_button.save_state()
@ -729,6 +728,7 @@ class LayoutMixin: # {{{
def read_layout_settings(self):
# View states are restored automatically when set_database is called
self.layout_container.read_settings()
self.book_details.vertical = self.layout_container.is_wide
self.grid_view_button.restore_state()
self.search_bar_button.restore_state()

View File

@ -273,7 +273,7 @@ class ConfigWidgetBase(QWidget, ConfigWidgetInterface):
Register a setting.
:param name: The setting name
:param config: The config object that reads/writes the setting
:param config_obj: The config object that reads/writes the setting
:param gui_name: The name of the GUI object that presents an interface
to change the setting. By default it is assumed to be
``'opt_' + name``.

View File

@ -577,7 +577,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.icon_theme_button.clicked.connect(self.choose_icon_theme)
self.default_author_link = DefaultAuthorLink(self.default_author_link_container)
self.default_author_link.changed_signal.connect(self.changed_signal)
r('gui_layout', config, restart_required=True, choices=[(_('Wide'), 'wide'), (_('Narrow'), 'narrow')])
r('ui_style', gprefs, restart_required=True, choices=[(_('System default'), 'system'), (_('calibre style'), 'calibre')])
r('color_palette', gprefs, restart_required=True, choices=[(_('System default'), 'system'), (_('Light'), 'light'), (_('Dark'), 'dark')])
r('book_list_tooltips', gprefs)
@ -831,6 +830,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.sections_view.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
self.tabWidget.currentWidget().setFocus(Qt.FocusReason.OtherFocusReason)
self.opt_ui_style.currentIndexChanged.connect(self.update_color_palette_state)
self.opt_gui_layout.addItem(_('Wide'), 'wide')
self.opt_gui_layout.addItem(_('Narrow'), 'narrow')
self.opt_gui_layout.currentIndexChanged.connect(self.changed_signal)
def initial_tab_changed(self):
self.sections_view.setCurrentRow(self.tabWidget.currentIndex())
@ -1038,6 +1040,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.opt_book_details_css.blockSignals(False)
self.tb_focus_label.setVisible(self.opt_tag_browser_allow_keyboard_focus.isChecked())
self.update_color_palette_state()
self.opt_gui_layout.setCurrentIndex(0 if self.gui.layout_container.is_wide else 1)
def open_cg_cache(self):
open_local_file(self.gui.grid_view.thumbnail_cache.location)
@ -1090,6 +1093,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.set_cg_color(gprefs.defaults['cover_grid_color'])
self.set_cg_texture(gprefs.defaults['cover_grid_texture'])
self.opt_book_details_css.setPlainText(P('templates/book_details.css', allow_user_override=False, data=True).decode('utf-8'))
self.opt_gui_layout.setCurrentIndex(0)
def change_cover_grid_color(self):
col = QColorDialog.getColor(self.cg_bg_widget.bcol,
@ -1172,6 +1176,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
if defcss == bcss:
bcss = None
set_data('templates/book_details.css', bcss)
self.gui.layout_container.change_layout(self.gui, self.opt_gui_layout.currentIndex() == 0)
return rr

View File

@ -143,7 +143,7 @@
<item row="3" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>&amp;User interface layout (needs restart):</string>
<string>&amp;User interface layout:</string>
</property>
<property name="buddy">
<cstring>opt_gui_layout</cstring>