From 76ff4be59851d8b9d67bb5d3d13e1d4805e33db5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 26 Oct 2019 10:00:07 +0000 Subject: [PATCH] Fix "Use default location" buttons --- openlp/core/lib/theme.py | 11 ++- openlp/core/ui/themeform.py | 25 ++++--- .../functional/openlp_core/lib/test_theme.py | 74 +++++++++++++++++++ 3 files changed, 100 insertions(+), 10 deletions(-) diff --git a/openlp/core/lib/theme.py b/openlp/core/lib/theme.py index 7dc2e7bd3..3c3ec1e24 100644 --- a/openlp/core/lib/theme.py +++ b/openlp/core/lib/theme.py @@ -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): diff --git a/openlp/core/ui/themeform.py b/openlp/core/ui/themeform.py index 6e57d80f0..c769c64d6 100644 --- a/openlp/core/ui/themeform.py +++ b/openlp/core/ui/themeform.py @@ -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 - 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') - 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') + # 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() diff --git a/tests/functional/openlp_core/lib/test_theme.py b/tests/functional/openlp_core/lib/test_theme.py index 2e0db972e..b738abaa0 100644 --- a/tests/functional/openlp_core/lib/test_theme.py +++ b/tests/functional/openlp_core/lib/test_theme.py @@ -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"'