mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
E-book viewer: Allow setting the number of pages per screen separately for portrait and landscape modes. Fixes #1483313 [[Enhancement] Viewer: auto adjust number of columns when display orientation changes](https://bugs.launchpad.net/calibre/+bug/1483313)
This commit is contained in:
parent
0a11860fd6
commit
3f11fae224
@ -78,6 +78,9 @@ def config(defaults=None):
|
|||||||
c.add_opt('show_fullscreen_help', default=True, action='store_false',
|
c.add_opt('show_fullscreen_help', default=True, action='store_false',
|
||||||
help=_('Show full screen usage help'))
|
help=_('Show full screen usage help'))
|
||||||
c.add_opt('cols_per_screen', default=1)
|
c.add_opt('cols_per_screen', default=1)
|
||||||
|
c.add_opt('cols_per_screen_portrait', default=1)
|
||||||
|
c.add_opt('cols_per_screen_landscape', default=1)
|
||||||
|
c.add_opt('cols_per_screen_migrated', default=False, action='store_true')
|
||||||
c.add_opt('use_book_margins', default=False, action='store_true')
|
c.add_opt('use_book_margins', default=False, action='store_true')
|
||||||
c.add_opt('top_margin', default=20)
|
c.add_opt('top_margin', default=20)
|
||||||
c.add_opt('side_margin', default=40)
|
c.add_opt('side_margin', default=40)
|
||||||
@ -98,6 +101,15 @@ def config(defaults=None):
|
|||||||
fonts('standard_font', default='serif', help=_('The standard font type'))
|
fonts('standard_font', default='serif', help=_('The standard font type'))
|
||||||
fonts('minimum_font_size', default=8, help=_('The minimum font size in px'))
|
fonts('minimum_font_size', default=8, help=_('The minimum font size in px'))
|
||||||
|
|
||||||
|
oparse = c.parse
|
||||||
|
|
||||||
|
def parse():
|
||||||
|
ans = oparse()
|
||||||
|
if not ans.cols_per_screen_migrated:
|
||||||
|
ans.cols_per_screen_portrait = ans.cols_per_screen_landscape = ans.cols_per_screen
|
||||||
|
return ans
|
||||||
|
c.parse = parse
|
||||||
|
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def load_themes():
|
def load_themes():
|
||||||
@ -322,7 +334,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.opt_start_in_fullscreen.setChecked(opts.start_in_fullscreen)
|
self.opt_start_in_fullscreen.setChecked(opts.start_in_fullscreen)
|
||||||
self.opt_show_fullscreen_help.setChecked(opts.show_fullscreen_help)
|
self.opt_show_fullscreen_help.setChecked(opts.show_fullscreen_help)
|
||||||
self.opt_fullscreen_pos.setChecked(opts.fullscreen_pos)
|
self.opt_fullscreen_pos.setChecked(opts.fullscreen_pos)
|
||||||
self.opt_cols_per_screen.setValue(opts.cols_per_screen)
|
self.opt_cols_per_screen_portrait.setValue(opts.cols_per_screen_portrait)
|
||||||
|
self.opt_cols_per_screen_landscape.setValue(opts.cols_per_screen_landscape)
|
||||||
self.opt_override_book_margins.setChecked(not opts.use_book_margins)
|
self.opt_override_book_margins.setChecked(not opts.use_book_margins)
|
||||||
for x in ('top', 'bottom', 'side'):
|
for x in ('top', 'bottom', 'side'):
|
||||||
getattr(self, 'opt_%s_margin'%x).setValue(getattr(opts,
|
getattr(self, 'opt_%s_margin'%x).setValue(getattr(opts,
|
||||||
@ -405,7 +418,9 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
c.set('fullscreen_pos', self.opt_fullscreen_pos.isChecked())
|
c.set('fullscreen_pos', self.opt_fullscreen_pos.isChecked())
|
||||||
c.set('fullscreen_scrollbar', self.opt_fullscreen_scrollbar.isChecked())
|
c.set('fullscreen_scrollbar', self.opt_fullscreen_scrollbar.isChecked())
|
||||||
c.set('show_fullscreen_help', self.opt_show_fullscreen_help.isChecked())
|
c.set('show_fullscreen_help', self.opt_show_fullscreen_help.isChecked())
|
||||||
c.set('cols_per_screen', int(self.opt_cols_per_screen.value()))
|
c.set('cols_per_screen_migrated', True)
|
||||||
|
c.set('cols_per_screen_portrait', int(self.opt_cols_per_screen_portrait.value()))
|
||||||
|
c.set('cols_per_screen_landscape', int(self.opt_cols_per_screen_landscape.value()))
|
||||||
c.set('start_in_fullscreen', self.opt_start_in_fullscreen.isChecked())
|
c.set('start_in_fullscreen', self.opt_start_in_fullscreen.isChecked())
|
||||||
c.set('use_book_margins', not
|
c.set('use_book_margins', not
|
||||||
self.opt_override_book_margins.isChecked())
|
self.opt_override_book_margins.isChecked())
|
||||||
|
@ -261,20 +261,27 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="3" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="label_13">
|
<widget class="Line" name="line">
|
||||||
<property name="text">
|
<property name="orientation">
|
||||||
<string>The number of &pages of text to show on screen </string>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>opt_cols_per_screen</cstring>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="5" column="0">
|
||||||
<widget class="QSpinBox" name="opt_cols_per_screen">
|
<widget class="QLabel" name="label_27">
|
||||||
<property name="suffix">
|
<property name="text">
|
||||||
<string> page(s)</string>
|
<string>In &Portrait orientation:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_cols_per_screen_portrait</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QSpinBox" name="opt_cols_per_screen_portrait">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Controls the number of pages on the screen when the viewer window's width is less than its height</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
@ -284,7 +291,7 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="8" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_override_book_margins">
|
<widget class="QCheckBox" name="opt_override_book_margins">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Override the page margin settings specified in the book</string>
|
<string>&Override the page margin settings specified in the book</string>
|
||||||
@ -294,7 +301,7 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="9" column="0">
|
||||||
<widget class="QLabel" name="label_18">
|
<widget class="QLabel" name="label_18">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Top margin</string>
|
<string>&Top margin</string>
|
||||||
@ -304,7 +311,7 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="9" column="1">
|
||||||
<widget class="QSpinBox" name="opt_top_margin">
|
<widget class="QSpinBox" name="opt_top_margin">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> px</string>
|
<string> px</string>
|
||||||
@ -317,7 +324,7 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="10" column="0">
|
||||||
<widget class="QLabel" name="label_19">
|
<widget class="QLabel" name="label_19">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Side margin</string>
|
<string>&Side margin</string>
|
||||||
@ -327,7 +334,7 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="10" column="1">
|
||||||
<widget class="QSpinBox" name="opt_side_margin">
|
<widget class="QSpinBox" name="opt_side_margin">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> px</string>
|
<string> px</string>
|
||||||
@ -340,7 +347,7 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0">
|
<item row="11" column="0">
|
||||||
<widget class="QLabel" name="label_17">
|
<widget class="QLabel" name="label_17">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Bottom margin</string>
|
<string>&Bottom margin</string>
|
||||||
@ -350,7 +357,7 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="11" column="1">
|
||||||
<widget class="QSpinBox" name="opt_bottom_margin">
|
<widget class="QSpinBox" name="opt_bottom_margin">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string> px</string>
|
<string> px</string>
|
||||||
@ -363,6 +370,43 @@ QToolBox::tab:hover {
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="7" column="0" colspan="2">
|
||||||
|
<widget class="Line" name="line_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="label_13">
|
||||||
|
<property name="text">
|
||||||
|
<string>The number of pages of text to show on screen </string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<widget class="QLabel" name="label_28">
|
||||||
|
<property name="text">
|
||||||
|
<string>In &Landscape orientation: </string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_cols_per_screen_landscape</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1">
|
||||||
|
<widget class="QSpinBox" name="opt_cols_per_screen_landscape">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Controls the number of pages on the screen when the viewer window's height is less than its width</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_2">
|
<widget class="QWidget" name="page_2">
|
||||||
@ -370,8 +414,8 @@ QToolBox::tab:hover {
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>799</width>
|
<width>381</width>
|
||||||
<height>378</height>
|
<height>193</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="label">
|
<attribute name="label">
|
||||||
@ -472,8 +516,8 @@ QToolBox::tab:hover {
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>799</width>
|
<width>340</width>
|
||||||
<height>378</height>
|
<height>70</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="label">
|
<attribute name="label">
|
||||||
@ -551,8 +595,8 @@ QToolBox::tab:hover {
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>799</width>
|
<width>384</width>
|
||||||
<height>378</height>
|
<height>140</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="label">
|
<attribute name="label">
|
||||||
@ -629,8 +673,8 @@ QToolBox::tab:hover {
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>799</width>
|
<width>479</width>
|
||||||
<height>378</height>
|
<height>226</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<attribute name="label">
|
<attribute name="label">
|
||||||
|
@ -183,7 +183,8 @@ class Document(QWebPage): # {{{
|
|||||||
self.start_in_fullscreen = opts.start_in_fullscreen
|
self.start_in_fullscreen = opts.start_in_fullscreen
|
||||||
self.show_fullscreen_help = opts.show_fullscreen_help
|
self.show_fullscreen_help = opts.show_fullscreen_help
|
||||||
self.use_book_margins = opts.use_book_margins
|
self.use_book_margins = opts.use_book_margins
|
||||||
self.cols_per_screen = opts.cols_per_screen
|
self.cols_per_screen_portrait = opts.cols_per_screen_portrait
|
||||||
|
self.cols_per_screen_landscape = opts.cols_per_screen_landscape
|
||||||
self.side_margin = opts.side_margin
|
self.side_margin = opts.side_margin
|
||||||
self.top_margin, self.bottom_margin = opts.top_margin, opts.bottom_margin
|
self.top_margin, self.bottom_margin = opts.top_margin, opts.bottom_margin
|
||||||
self.show_controls = opts.show_controls
|
self.show_controls = opts.show_controls
|
||||||
@ -291,12 +292,14 @@ class Document(QWebPage): # {{{
|
|||||||
def switch_to_paged_mode(self, onresize=False, last_loaded_path=None):
|
def switch_to_paged_mode(self, onresize=False, last_loaded_path=None):
|
||||||
if onresize and not self.loaded_javascript:
|
if onresize and not self.loaded_javascript:
|
||||||
return
|
return
|
||||||
|
cols_per_screen = self.cols_per_screen_portrait if self.is_portrait else self.cols_per_screen_landscape
|
||||||
|
cols_per_screen = max(1, min(5, cols_per_screen))
|
||||||
self.javascript('''
|
self.javascript('''
|
||||||
window.paged_display.use_document_margins = %s;
|
window.paged_display.use_document_margins = %s;
|
||||||
window.paged_display.set_geometry(%d, %d, %d, %d);
|
window.paged_display.set_geometry(%d, %d, %d, %d);
|
||||||
'''%(
|
'''%(
|
||||||
('true' if self.use_book_margins else 'false'),
|
('true' if self.use_book_margins else 'false'),
|
||||||
self.cols_per_screen, self.top_margin, self.side_margin,
|
cols_per_screen, self.top_margin, self.side_margin,
|
||||||
self.bottom_margin
|
self.bottom_margin
|
||||||
))
|
))
|
||||||
force_fullscreen_layout = bool(getattr(last_loaded_path,
|
force_fullscreen_layout = bool(getattr(last_loaded_path,
|
||||||
@ -448,6 +451,10 @@ class Document(QWebPage): # {{{
|
|||||||
def window_width(self):
|
def window_width(self):
|
||||||
return self.javascript('window.innerWidth', 'int')
|
return self.javascript('window.innerWidth', 'int')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_portrait(self):
|
||||||
|
return self.window_width < self.window_height
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def xpos(self):
|
def xpos(self):
|
||||||
return self.mainFrame().scrollPosition().x()
|
return self.mainFrame().scrollPosition().x()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user