forked from openlp/openlp
Merge branch 'fix-default-location-buttons' into 'master'
Fix "Use default location" buttons Closes #306 See merge request openlp/openlp!53
This commit is contained in:
commit
4408797e52
@ -280,12 +280,21 @@ class Theme(object):
|
||||
Set the header and footer size into the current primary screen.
|
||||
10 px on each side is removed to allow for a border.
|
||||
"""
|
||||
self.set_default_header()
|
||||
self.set_default_footer()
|
||||
|
||||
def set_default_header(self):
|
||||
current_screen_geometry = ScreenList().current.display_geometry
|
||||
self.font_main_x = 10
|
||||
self.font_main_y = 0
|
||||
self.font_main_width = current_screen_geometry.width() - 20
|
||||
self.font_main_height = current_screen_geometry.height() * 9 / 10
|
||||
self.font_footer_width = current_screen_geometry.width() - 20
|
||||
|
||||
def set_default_footer(self):
|
||||
current_screen_geometry = ScreenList().current.display_geometry
|
||||
self.font_footer_x = 10
|
||||
self.font_footer_y = current_screen_geometry.height() * 9 / 10
|
||||
self.font_footer_width = current_screen_geometry.width() - 20
|
||||
self.font_footer_height = current_screen_geometry.height() / 10
|
||||
|
||||
def load_theme(self, theme, theme_path=None):
|
||||
|
@ -537,15 +537,22 @@ class ThemeForm(QtWidgets.QWizard, Ui_ThemeWizard, RegistryProperties):
|
||||
# footer page
|
||||
self.theme.font_footer_name = self.footer_font_combo_box.currentFont().family()
|
||||
self.theme.font_footer_size = self.field('footer_size_spin_box')
|
||||
# position page
|
||||
# position page (main)
|
||||
if self.theme.font_main_override:
|
||||
self.theme.font_main_x = self.field('main_position_x')
|
||||
self.theme.font_main_y = self.field('main_position_y')
|
||||
self.theme.font_main_height = self.field('main_position_height')
|
||||
self.theme.font_main_width = self.field('main_position_width')
|
||||
else:
|
||||
self.theme.set_default_header()
|
||||
# position page (footer)
|
||||
if self.theme.font_footer_override:
|
||||
self.theme.font_footer_x = self.field('footer_position_x')
|
||||
self.theme.font_footer_y = self.field('footer_position_y')
|
||||
self.theme.font_footer_height = self.field('footer_position_height')
|
||||
self.theme.font_footer_width = self.field('footer_position_width')
|
||||
else:
|
||||
self.theme.set_default_footer()
|
||||
# position page
|
||||
self.theme.display_horizontal_align = self.horizontal_combo_box.currentIndex()
|
||||
self.theme.display_vertical_align = self.vertical_combo_box.currentIndex()
|
||||
|
@ -23,6 +23,7 @@ Package to test the openlp.core.lib.theme package.
|
||||
"""
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from openlp.core.lib.theme import BackgroundType, Theme
|
||||
|
||||
@ -175,6 +176,79 @@ class TestTheme(TestCase):
|
||||
lt.load_theme(save_theme_json)
|
||||
self.check_theme(lt)
|
||||
|
||||
@patch('openlp.core.display.screens.ScreenList.current')
|
||||
def test_set_default_footer(self, mock_geometry):
|
||||
"""
|
||||
Test the set_default_footer function sets the footer back to default
|
||||
(reletive to the screen)
|
||||
"""
|
||||
# GIVEN: A screen geometry object and a Theme footer with a strange area
|
||||
mock_geometry.display_geometry = MagicMock()
|
||||
mock_geometry.display_geometry.height.return_value = 600
|
||||
mock_geometry.display_geometry.width.return_value = 400
|
||||
theme = Theme()
|
||||
theme.font_main_x = 20
|
||||
theme.font_footer_x = 207
|
||||
theme.font_footer_y = 25
|
||||
theme.font_footer_width = 4253
|
||||
theme.font_footer_height = 5423
|
||||
|
||||
# WHEN: set_default_footer is called
|
||||
theme.set_default_footer()
|
||||
|
||||
# THEN: footer should be set, header should not have changed
|
||||
assert theme.font_main_x == 20, 'header should not have been changed'
|
||||
assert theme.font_footer_x == 10, 'x pos should be reset to default of 10'
|
||||
assert theme.font_footer_y == 540, 'y pos should be reset to (screen_size_height * 9 / 10)'
|
||||
assert theme.font_footer_width == 380, 'width should have been reset to (screen_size_width - 20)'
|
||||
assert theme.font_footer_height == 60, 'height should have been reset to (screen_size_height / 10)'
|
||||
|
||||
@patch('openlp.core.display.screens.ScreenList.current')
|
||||
def test_set_default_header(self, mock_geometry):
|
||||
"""
|
||||
Test the set_default_header function sets the header back to default
|
||||
(reletive to the screen)
|
||||
"""
|
||||
# GIVEN: A screen geometry object and a Theme header with a strange area
|
||||
mock_geometry.display_geometry = MagicMock()
|
||||
mock_geometry.display_geometry.height.return_value = 600
|
||||
mock_geometry.display_geometry.width.return_value = 400
|
||||
theme = Theme()
|
||||
theme.font_footer_x = 200
|
||||
theme.font_main_x = 687
|
||||
theme.font_main_y = 546
|
||||
theme.font_main_width = 345
|
||||
theme.font_main_height = 653
|
||||
|
||||
# WHEN: set_default_header is called
|
||||
theme.set_default_header()
|
||||
|
||||
# THEN: footer should be set, header should not have changed
|
||||
assert theme.font_footer_x == 200, 'footer should not have been changed'
|
||||
assert theme.font_main_x == 10, 'x pos should be reset to default of 10'
|
||||
assert theme.font_main_y == 0, 'y pos should be reset to 0'
|
||||
assert theme.font_main_width == 380, 'width should have been reset to (screen_size_width - 20)'
|
||||
assert theme.font_main_height == 540, 'height should have been reset to (screen_size_height * 9 / 10)'
|
||||
|
||||
@patch('openlp.core.display.screens.ScreenList.current')
|
||||
def test_set_default_header_footer(self, mock_geometry):
|
||||
"""
|
||||
Test the set_default_header_footer function sets the header and footer back to default
|
||||
(reletive to the screen)
|
||||
"""
|
||||
# GIVEN: A screen geometry object and a Theme header with a strange area
|
||||
mock_geometry.display_geometry = MagicMock()
|
||||
theme = Theme()
|
||||
theme.font_footer_x = 200
|
||||
theme.font_main_x = 687
|
||||
|
||||
# WHEN: set_default_header is called
|
||||
theme.set_default_header_footer()
|
||||
|
||||
# THEN: footer should be set, header should not have changed
|
||||
assert theme.font_footer_x == 10, 'footer x pos should be reset to default of 10'
|
||||
assert theme.font_main_x == 10, 'header x pos should be reset to default of 10'
|
||||
|
||||
def check_theme(self, theme):
|
||||
assert '#000000' == theme.background_border_color, 'background_border_color should be "#000000"'
|
||||
assert 'solid' == theme.background_type, 'background_type should be "solid"'
|
||||
|
Loading…
Reference in New Issue
Block a user