mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Try to preserve the current position when toggling fullscreen mode in the ebook viewer
This commit is contained in:
parent
99eb7bf591
commit
91fb0462b1
@ -301,6 +301,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
_('Press Esc to quit')),
|
_('Press Esc to quit')),
|
||||||
self)
|
self)
|
||||||
self.full_screen_label.setVisible(False)
|
self.full_screen_label.setVisible(False)
|
||||||
|
self.window_mode_toggle_timer = QTimer(self)
|
||||||
|
self.window_mode_toggle_timer.timeout.connect(self.handle_window_mode_toggle)
|
||||||
self.full_screen_label.setStyleSheet('''
|
self.full_screen_label.setStyleSheet('''
|
||||||
QLabel {
|
QLabel {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@ -311,6 +313,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
}
|
}
|
||||||
''')
|
''')
|
||||||
|
self.window_mode_changed = None
|
||||||
self.toggle_toolbar_action = QAction(_('Show/hide controls'), self)
|
self.toggle_toolbar_action = QAction(_('Show/hide controls'), self)
|
||||||
self.toggle_toolbar_action.triggered.connect(self.toggle_toolbars)
|
self.toggle_toolbar_action.triggered.connect(self.toggle_toolbars)
|
||||||
self.addAction(self.toggle_toolbar_action)
|
self.addAction(self.toggle_toolbar_action)
|
||||||
@ -441,6 +444,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.showFullScreen()
|
self.showFullScreen()
|
||||||
|
|
||||||
def showFullScreen(self):
|
def showFullScreen(self):
|
||||||
|
self.view.document.page_position.save()
|
||||||
|
self.window_mode_changed = 'fullscreen'
|
||||||
self.tool_bar.setVisible(False)
|
self.tool_bar.setVisible(False)
|
||||||
self.tool_bar2.setVisible(False)
|
self.tool_bar2.setVisible(False)
|
||||||
self._original_frame_margins = (
|
self._original_frame_margins = (
|
||||||
@ -450,7 +455,6 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.centralwidget.layout().setContentsMargins(0, 0, 0, 0)
|
self.centralwidget.layout().setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
super(EbookViewer, self).showFullScreen()
|
super(EbookViewer, self).showFullScreen()
|
||||||
QTimer.singleShot(10, self.show_full_screen_label)
|
|
||||||
|
|
||||||
def show_full_screen_label(self):
|
def show_full_screen_label(self):
|
||||||
f = self.full_screen_label
|
f = self.full_screen_label
|
||||||
@ -469,6 +473,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.view.document.switch_to_fullscreen_mode()
|
self.view.document.switch_to_fullscreen_mode()
|
||||||
|
|
||||||
def showNormal(self):
|
def showNormal(self):
|
||||||
|
self.view.document.page_position.save()
|
||||||
|
self.window_mode_changed = 'normal'
|
||||||
self.esc_full_screen_action.setEnabled(False)
|
self.esc_full_screen_action.setEnabled(False)
|
||||||
self.tool_bar.setVisible(True)
|
self.tool_bar.setVisible(True)
|
||||||
self.tool_bar2.setVisible(True)
|
self.tool_bar2.setVisible(True)
|
||||||
@ -478,7 +484,16 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.centralwidget.layout().setContentsMargins(om[0])
|
self.centralwidget.layout().setContentsMargins(om[0])
|
||||||
self.frame.layout().setContentsMargins(om[1])
|
self.frame.layout().setContentsMargins(om[1])
|
||||||
super(EbookViewer, self).showNormal()
|
super(EbookViewer, self).showNormal()
|
||||||
self.view.document.switch_to_window_mode()
|
|
||||||
|
def handle_window_mode_toggle(self):
|
||||||
|
if self.window_mode_changed:
|
||||||
|
fs = self.window_mode_changed == 'fullscreen'
|
||||||
|
self.window_mode_changed = None
|
||||||
|
if fs:
|
||||||
|
self.show_full_screen_label()
|
||||||
|
else:
|
||||||
|
self.view.document.switch_to_window_mode()
|
||||||
|
self.view.document.page_position.restore()
|
||||||
|
|
||||||
def goto(self, ref):
|
def goto(self, ref):
|
||||||
if ref:
|
if ref:
|
||||||
@ -679,6 +694,10 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
self.view.load_path(path, pos=pos)
|
self.view.load_path(path, pos=pos)
|
||||||
|
|
||||||
def viewport_resized(self, frac):
|
def viewport_resized(self, frac):
|
||||||
|
if self.window_mode_changed:
|
||||||
|
# Soak up extra window resize events
|
||||||
|
self.window_mode_toggle_timer.start(15)
|
||||||
|
return
|
||||||
new_page = self.pos.value()
|
new_page = self.pos.value()
|
||||||
if self.current_page is not None:
|
if self.current_page is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -57,12 +57,20 @@ class PagePosition(object):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self._cpos = self.current_pos
|
self.save()
|
||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
|
self.restore()
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
self._cpos = self.current_pos
|
||||||
|
|
||||||
|
def restore(self):
|
||||||
|
if self._cpos is None: return
|
||||||
if isinstance(self._cpos, (int, float)):
|
if isinstance(self._cpos, (int, float)):
|
||||||
self.document.scroll_fraction = self._cpos
|
self.document.scroll_fraction = self._cpos
|
||||||
else:
|
else:
|
||||||
self.scroll_to_cfi(self._cpos)
|
self.scroll_to_cfi(self._cpos)
|
||||||
self._cpos = None
|
self._cpos = None
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user