Merge lp:~tcf38012/openlp/stretchimage into lp:openlp

Proposed by Theodore Frederick
Status: Merged
Approved by: Tim Bentley
Approved revision: 2735
Merged at revision: 2761
Proposed branch: lp:~tcf38012/openlp/stretchimage
Merge into: lp:openlp
Diff against target: 126 lines (+33/-4)
5 files modified
openlp/core/common/settings.py (+1/-0)
openlp/core/lib/__init__.py (+2/-2)
openlp/core/lib/imagemanager.py (+3/-2)
openlp/core/ui/advancedtab.py (+6/-0)
tests/functional/openlp_core_lib/test_lib.py (+21/-0)
To merge this branch: bzr merge lp:~tcf38012/openlp/stretchimage
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Review via email: mp+323440@code.launchpad.net

Commit message

Add option to ignore aspect ratio and stretch image.

Description of the change

Adds option to ignore aspect ratio and stretch image.

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) wrote :

Looks good but all commits need tests to help build up our bank of tests,
These tests ideally should cover the area changed.
If you need help with the tests ask on our IRC channel.

I am wondering if we need a hover text as well as you change will impact Theme backgrounds and Images.

review: Needs Fixing
lp:~tcf38012/openlp/stretchimage updated
2735. By Theodore Frederick

Add Tests for Ignoring Aspect Ratio

Revision history for this message
Theodore Frederick (tcf38012) wrote :

Everything else seems to be covered by previous tests.

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Sorry for not coming back to this, but this looks good now.

review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/common/settings.py'
--- openlp/core/common/settings.py 2017-02-18 07:23:15 +0000
+++ openlp/core/common/settings.py 2017-04-30 17:33:52 +0000
@@ -121,6 +121,7 @@
121 'advanced/enable exit confirmation': True,121 'advanced/enable exit confirmation': True,
122 'advanced/expand service item': False,122 'advanced/expand service item': False,
123 'advanced/hide mouse': True,123 'advanced/hide mouse': True,
124 'advanced/ignore aspect ratio': False,
124 'advanced/is portable': False,125 'advanced/is portable': False,
125 'advanced/max recent files': 20,126 'advanced/max recent files': 20,
126 'advanced/print file meta data': False,127 'advanced/print file meta data': False,
127128
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py 2016-12-31 11:01:36 +0000
+++ openlp/core/lib/__init__.py 2017-04-30 17:33:52 +0000
@@ -227,7 +227,7 @@
227 return image_date <= thumb_date227 return image_date <= thumb_date
228228
229229
230def resize_image(image_path, width, height, background='#000000'):230def resize_image(image_path, width, height, background='#000000', ignore_aspect_ratio=False):
231 """231 """
232 Resize an image to fit on the current screen.232 Resize an image to fit on the current screen.
233233
@@ -244,7 +244,7 @@
244 image_ratio = reader.size().width() / reader.size().height()244 image_ratio = reader.size().width() / reader.size().height()
245 resize_ratio = width / height245 resize_ratio = width / height
246 # Figure out the size we want to resize the image to (keep aspect ratio).246 # Figure out the size we want to resize the image to (keep aspect ratio).
247 if image_ratio == resize_ratio:247 if image_ratio == resize_ratio or ignore_aspect_ratio:
248 size = QtCore.QSize(width, height)248 size = QtCore.QSize(width, height)
249 elif image_ratio < resize_ratio:249 elif image_ratio < resize_ratio:
250 # Use the image's height as reference for the new size.250 # Use the image's height as reference for the new size.
251251
=== modified file 'openlp/core/lib/imagemanager.py'
--- openlp/core/lib/imagemanager.py 2016-12-31 11:01:36 +0000
+++ openlp/core/lib/imagemanager.py 2017-04-30 17:33:52 +0000
@@ -31,7 +31,7 @@
3131
32from PyQt5 import QtCore32from PyQt5 import QtCore
3333
34from openlp.core.common import Registry34from openlp.core.common import Registry, Settings
35from openlp.core.lib import ScreenList, resize_image, image_to_byte35from openlp.core.lib import ScreenList, resize_image, image_to_byte
3636
37log = logging.getLogger(__name__)37log = logging.getLogger(__name__)
@@ -306,7 +306,8 @@
306 # Let's see if the image was requested with specific dimensions306 # Let's see if the image was requested with specific dimensions
307 width = self.width if image.width == -1 else image.width307 width = self.width if image.width == -1 else image.width
308 height = self.height if image.height == -1 else image.height308 height = self.height if image.height == -1 else image.height
309 image.image = resize_image(image.path, width, height, image.background)309 image.image = resize_image(image.path, width, height, image.background,
310 Settings().value('advanced/ignore aspect ratio'))
310 # Set the priority to Lowest and stop here as we need to process more important images first.311 # Set the priority to Lowest and stop here as we need to process more important images first.
311 if image.priority == Priority.Normal:312 if image.priority == Priority.Normal:
312 self._conversion_queue.modify_priority(image, Priority.Lowest)313 self._conversion_queue.modify_priority(image, Priority.Lowest)
313314
=== modified file 'openlp/core/ui/advancedtab.py'
--- openlp/core/ui/advancedtab.py 2016-12-31 11:01:36 +0000
+++ openlp/core/ui/advancedtab.py 2017-04-30 17:33:52 +0000
@@ -224,6 +224,9 @@
224 self.display_workaround_group_box.setObjectName('display_workaround_group_box')224 self.display_workaround_group_box.setObjectName('display_workaround_group_box')
225 self.display_workaround_layout = QtWidgets.QVBoxLayout(self.display_workaround_group_box)225 self.display_workaround_layout = QtWidgets.QVBoxLayout(self.display_workaround_group_box)
226 self.display_workaround_layout.setObjectName('display_workaround_layout')226 self.display_workaround_layout.setObjectName('display_workaround_layout')
227 self.ignore_aspect_ratio_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
228 self.ignore_aspect_ratio_check_box.setObjectName('ignore_aspect_ratio_check_box')
229 self.display_workaround_layout.addWidget(self.ignore_aspect_ratio_check_box)
227 self.x11_bypass_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)230 self.x11_bypass_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
228 self.x11_bypass_check_box.setObjectName('x11_bypass_check_box')231 self.x11_bypass_check_box.setObjectName('x11_bypass_check_box')
229 self.display_workaround_layout.addWidget(self.x11_bypass_check_box)232 self.display_workaround_layout.addWidget(self.x11_bypass_check_box)
@@ -333,6 +336,7 @@
333 translate('OpenLP.AdvancedTab', '<strong>WARNING:</strong> New data directory location contains '336 translate('OpenLP.AdvancedTab', '<strong>WARNING:</strong> New data directory location contains '
334 'OpenLP data files. These files WILL be replaced during a copy.'))337 'OpenLP data files. These files WILL be replaced during a copy.'))
335 self.display_workaround_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Display Workarounds'))338 self.display_workaround_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Display Workarounds'))
339 self.ignore_aspect_ratio_check_box.setText(translate('OpenLP.AdvancedTab', 'Ignore Aspect Ratio'))
336 self.x11_bypass_check_box.setText(translate('OpenLP.AdvancedTab', 'Bypass X11 Window Manager'))340 self.x11_bypass_check_box.setText(translate('OpenLP.AdvancedTab', 'Bypass X11 Window Manager'))
337 self.alternate_rows_check_box.setText(translate('OpenLP.AdvancedTab', 'Use alternating row colours in lists'))341 self.alternate_rows_check_box.setText(translate('OpenLP.AdvancedTab', 'Use alternating row colours in lists'))
338 # Slide Limits342 # Slide Limits
@@ -377,6 +381,7 @@
377 default_service_enabled = settings.value('default service enabled')381 default_service_enabled = settings.value('default service enabled')
378 self.service_name_check_box.setChecked(default_service_enabled)382 self.service_name_check_box.setChecked(default_service_enabled)
379 self.service_name_check_box_toggled(default_service_enabled)383 self.service_name_check_box_toggled(default_service_enabled)
384 self.ignore_aspect_ratio_check_box.setChecked(settings.value('ignore aspect ratio'))
380 self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))385 self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))
381 self.slide_limits = settings.value('slide limits')386 self.slide_limits = settings.value('slide limits')
382 self.is_search_as_you_type_enabled = settings.value('search as type')387 self.is_search_as_you_type_enabled = settings.value('search as type')
@@ -433,6 +438,7 @@
433 settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())438 settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())
434 settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())439 settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())
435 settings.setValue('slide limits', self.slide_limits)440 settings.setValue('slide limits', self.slide_limits)
441 settings.setValue('ignore aspect ratio', self.ignore_aspect_ratio_check_box.isChecked())
436 if self.x11_bypass_check_box.isChecked() != settings.value('x11 bypass wm'):442 if self.x11_bypass_check_box.isChecked() != settings.value('x11 bypass wm'):
437 settings.setValue('x11 bypass wm', self.x11_bypass_check_box.isChecked())443 settings.setValue('x11 bypass wm', self.x11_bypass_check_box.isChecked())
438 self.settings_form.register_post_process('config_screen_changed')444 self.settings_form.register_post_process('config_screen_changed')
439445
=== modified file 'tests/functional/openlp_core_lib/test_lib.py'
--- tests/functional/openlp_core_lib/test_lib.py 2016-12-31 11:01:36 +0000
+++ tests/functional/openlp_core_lib/test_lib.py 2017-04-30 17:33:52 +0000
@@ -672,6 +672,27 @@
672 self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')672 self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
673 self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')673 self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
674674
675 def test_resize_thumb_ignoring_aspect_ratio(self):
676 """
677 Test the resize_thumb() function ignoring aspect ratio
678 """
679 # GIVEN: A path to an image.
680 image_path = os.path.join(TEST_PATH, 'church.jpg')
681 wanted_width = 1000
682 wanted_height = 1000
683 # We want the background to be white.
684 wanted_background_hex = '#FFFFFF'
685 wanted_background_rgb = QtGui.QColor(wanted_background_hex).rgb()
686
687 # WHEN: Resize the image and add a background.
688 image = resize_image(image_path, wanted_width, wanted_height, wanted_background_hex, True)
689
690 # THEN: Check if the size is correct and the background was set.
691 result_size = image.size()
692 self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.')
693 self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
694 self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
695
675 def test_create_separated_list_qlocate(self):696 def test_create_separated_list_qlocate(self):
676 """697 """
677 Test the create_separated_list function using the Qt provided method698 Test the create_separated_list function using the Qt provided method