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
1=== modified file 'openlp/core/common/settings.py'
2--- openlp/core/common/settings.py 2017-02-18 07:23:15 +0000
3+++ openlp/core/common/settings.py 2017-04-30 17:33:52 +0000
4@@ -121,6 +121,7 @@
5 'advanced/enable exit confirmation': True,
6 'advanced/expand service item': False,
7 'advanced/hide mouse': True,
8+ 'advanced/ignore aspect ratio': False,
9 'advanced/is portable': False,
10 'advanced/max recent files': 20,
11 'advanced/print file meta data': False,
12
13=== modified file 'openlp/core/lib/__init__.py'
14--- openlp/core/lib/__init__.py 2016-12-31 11:01:36 +0000
15+++ openlp/core/lib/__init__.py 2017-04-30 17:33:52 +0000
16@@ -227,7 +227,7 @@
17 return image_date <= thumb_date
18
19
20-def resize_image(image_path, width, height, background='#000000'):
21+def resize_image(image_path, width, height, background='#000000', ignore_aspect_ratio=False):
22 """
23 Resize an image to fit on the current screen.
24
25@@ -244,7 +244,7 @@
26 image_ratio = reader.size().width() / reader.size().height()
27 resize_ratio = width / height
28 # Figure out the size we want to resize the image to (keep aspect ratio).
29- if image_ratio == resize_ratio:
30+ if image_ratio == resize_ratio or ignore_aspect_ratio:
31 size = QtCore.QSize(width, height)
32 elif image_ratio < resize_ratio:
33 # Use the image's height as reference for the new size.
34
35=== modified file 'openlp/core/lib/imagemanager.py'
36--- openlp/core/lib/imagemanager.py 2016-12-31 11:01:36 +0000
37+++ openlp/core/lib/imagemanager.py 2017-04-30 17:33:52 +0000
38@@ -31,7 +31,7 @@
39
40 from PyQt5 import QtCore
41
42-from openlp.core.common import Registry
43+from openlp.core.common import Registry, Settings
44 from openlp.core.lib import ScreenList, resize_image, image_to_byte
45
46 log = logging.getLogger(__name__)
47@@ -306,7 +306,8 @@
48 # Let's see if the image was requested with specific dimensions
49 width = self.width if image.width == -1 else image.width
50 height = self.height if image.height == -1 else image.height
51- image.image = resize_image(image.path, width, height, image.background)
52+ image.image = resize_image(image.path, width, height, image.background,
53+ Settings().value('advanced/ignore aspect ratio'))
54 # Set the priority to Lowest and stop here as we need to process more important images first.
55 if image.priority == Priority.Normal:
56 self._conversion_queue.modify_priority(image, Priority.Lowest)
57
58=== modified file 'openlp/core/ui/advancedtab.py'
59--- openlp/core/ui/advancedtab.py 2016-12-31 11:01:36 +0000
60+++ openlp/core/ui/advancedtab.py 2017-04-30 17:33:52 +0000
61@@ -224,6 +224,9 @@
62 self.display_workaround_group_box.setObjectName('display_workaround_group_box')
63 self.display_workaround_layout = QtWidgets.QVBoxLayout(self.display_workaround_group_box)
64 self.display_workaround_layout.setObjectName('display_workaround_layout')
65+ self.ignore_aspect_ratio_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
66+ self.ignore_aspect_ratio_check_box.setObjectName('ignore_aspect_ratio_check_box')
67+ self.display_workaround_layout.addWidget(self.ignore_aspect_ratio_check_box)
68 self.x11_bypass_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
69 self.x11_bypass_check_box.setObjectName('x11_bypass_check_box')
70 self.display_workaround_layout.addWidget(self.x11_bypass_check_box)
71@@ -333,6 +336,7 @@
72 translate('OpenLP.AdvancedTab', '<strong>WARNING:</strong> New data directory location contains '
73 'OpenLP data files. These files WILL be replaced during a copy.'))
74 self.display_workaround_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Display Workarounds'))
75+ self.ignore_aspect_ratio_check_box.setText(translate('OpenLP.AdvancedTab', 'Ignore Aspect Ratio'))
76 self.x11_bypass_check_box.setText(translate('OpenLP.AdvancedTab', 'Bypass X11 Window Manager'))
77 self.alternate_rows_check_box.setText(translate('OpenLP.AdvancedTab', 'Use alternating row colours in lists'))
78 # Slide Limits
79@@ -377,6 +381,7 @@
80 default_service_enabled = settings.value('default service enabled')
81 self.service_name_check_box.setChecked(default_service_enabled)
82 self.service_name_check_box_toggled(default_service_enabled)
83+ self.ignore_aspect_ratio_check_box.setChecked(settings.value('ignore aspect ratio'))
84 self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))
85 self.slide_limits = settings.value('slide limits')
86 self.is_search_as_you_type_enabled = settings.value('search as type')
87@@ -433,6 +438,7 @@
88 settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())
89 settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())
90 settings.setValue('slide limits', self.slide_limits)
91+ settings.setValue('ignore aspect ratio', self.ignore_aspect_ratio_check_box.isChecked())
92 if self.x11_bypass_check_box.isChecked() != settings.value('x11 bypass wm'):
93 settings.setValue('x11 bypass wm', self.x11_bypass_check_box.isChecked())
94 self.settings_form.register_post_process('config_screen_changed')
95
96=== modified file 'tests/functional/openlp_core_lib/test_lib.py'
97--- tests/functional/openlp_core_lib/test_lib.py 2016-12-31 11:01:36 +0000
98+++ tests/functional/openlp_core_lib/test_lib.py 2017-04-30 17:33:52 +0000
99@@ -672,6 +672,27 @@
100 self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
101 self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
102
103+ def test_resize_thumb_ignoring_aspect_ratio(self):
104+ """
105+ Test the resize_thumb() function ignoring aspect ratio
106+ """
107+ # GIVEN: A path to an image.
108+ image_path = os.path.join(TEST_PATH, 'church.jpg')
109+ wanted_width = 1000
110+ wanted_height = 1000
111+ # We want the background to be white.
112+ wanted_background_hex = '#FFFFFF'
113+ wanted_background_rgb = QtGui.QColor(wanted_background_hex).rgb()
114+
115+ # WHEN: Resize the image and add a background.
116+ image = resize_image(image_path, wanted_width, wanted_height, wanted_background_hex, True)
117+
118+ # THEN: Check if the size is correct and the background was set.
119+ result_size = image.size()
120+ self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.')
121+ self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
122+ self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
123+
124 def test_create_separated_list_qlocate(self):
125 """
126 Test the create_separated_list function using the Qt provided method