Adds option to ignore aspect ratio and stretch image.

bzr-revno: 2761
This commit is contained in:
Theodore Frederick 2017-08-23 21:21:11 +01:00 committed by Tim Bentley
commit ae62538a02
5 changed files with 33 additions and 4 deletions

View File

@ -121,6 +121,7 @@ class Settings(QtCore.QSettings):
'advanced/enable exit confirmation': True,
'advanced/expand service item': False,
'advanced/hide mouse': True,
'advanced/ignore aspect ratio': False,
'advanced/is portable': False,
'advanced/max recent files': 20,
'advanced/print file meta data': False,

View File

@ -230,7 +230,7 @@ def validate_thumb(file_path, thumb_path):
return image_date <= thumb_date
def resize_image(image_path, width, height, background='#000000'):
def resize_image(image_path, width, height, background='#000000', ignore_aspect_ratio=False):
"""
Resize an image to fit on the current screen.
@ -247,7 +247,7 @@ def resize_image(image_path, width, height, background='#000000'):
image_ratio = reader.size().width() / reader.size().height()
resize_ratio = width / height
# Figure out the size we want to resize the image to (keep aspect ratio).
if image_ratio == resize_ratio:
if image_ratio == resize_ratio or ignore_aspect_ratio:
size = QtCore.QSize(width, height)
elif image_ratio < resize_ratio:
# Use the image's height as reference for the new size.

View File

@ -31,7 +31,7 @@ import queue
from PyQt5 import QtCore
from openlp.core.common import Registry
from openlp.core.common import Registry, Settings
from openlp.core.lib import ScreenList, resize_image, image_to_byte
log = logging.getLogger(__name__)
@ -327,7 +327,8 @@ class ImageManager(QtCore.QObject):
# Let's see if the image was requested with specific dimensions
width = self.width if image.width == -1 else image.width
height = self.height if image.height == -1 else image.height
image.image = resize_image(image.path, width, height, image.background)
image.image = resize_image(image.path, width, height, image.background,
Settings().value('advanced/ignore aspect ratio'))
# Set the priority to Lowest and stop here as we need to process more important images first.
if image.priority == Priority.Normal:
self._conversion_queue.modify_priority(image, Priority.Lowest)

View File

@ -208,6 +208,9 @@ class AdvancedTab(SettingsTab):
self.display_workaround_group_box.setObjectName('display_workaround_group_box')
self.display_workaround_layout = QtWidgets.QVBoxLayout(self.display_workaround_group_box)
self.display_workaround_layout.setObjectName('display_workaround_layout')
self.ignore_aspect_ratio_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
self.ignore_aspect_ratio_check_box.setObjectName('ignore_aspect_ratio_check_box')
self.display_workaround_layout.addWidget(self.ignore_aspect_ratio_check_box)
self.x11_bypass_check_box = QtWidgets.QCheckBox(self.display_workaround_group_box)
self.x11_bypass_check_box.setObjectName('x11_bypass_check_box')
self.display_workaround_layout.addWidget(self.x11_bypass_check_box)
@ -311,6 +314,7 @@ class AdvancedTab(SettingsTab):
translate('OpenLP.AdvancedTab', '<strong>WARNING:</strong> New data directory location contains '
'OpenLP data files. These files WILL be replaced during a copy.'))
self.display_workaround_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Display Workarounds'))
self.ignore_aspect_ratio_check_box.setText(translate('OpenLP.AdvancedTab', 'Ignore Aspect Ratio'))
self.x11_bypass_check_box.setText(translate('OpenLP.AdvancedTab', 'Bypass X11 Window Manager'))
self.alternate_rows_check_box.setText(translate('OpenLP.AdvancedTab', 'Use alternating row colours in lists'))
# Slide Limits
@ -355,6 +359,7 @@ class AdvancedTab(SettingsTab):
default_service_enabled = settings.value('default service enabled')
self.service_name_check_box.setChecked(default_service_enabled)
self.service_name_check_box_toggled(default_service_enabled)
self.ignore_aspect_ratio_check_box.setChecked(settings.value('ignore aspect ratio'))
self.x11_bypass_check_box.setChecked(settings.value('x11 bypass wm'))
self.slide_limits = settings.value('slide limits')
self.is_search_as_you_type_enabled = settings.value('search as type')
@ -410,6 +415,7 @@ class AdvancedTab(SettingsTab):
settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked())
settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked())
settings.setValue('slide limits', self.slide_limits)
settings.setValue('ignore aspect ratio', self.ignore_aspect_ratio_check_box.isChecked())
if self.x11_bypass_check_box.isChecked() != settings.value('x11 bypass wm'):
settings.setValue('x11 bypass wm', self.x11_bypass_check_box.isChecked())
self.settings_form.register_post_process('config_screen_changed')

View File

@ -704,6 +704,27 @@ class TestLib(TestCase):
self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
def test_resize_thumb_ignoring_aspect_ratio(self):
"""
Test the resize_thumb() function ignoring aspect ratio
"""
# GIVEN: A path to an image.
image_path = os.path.join(TEST_PATH, 'church.jpg')
wanted_width = 1000
wanted_height = 1000
# We want the background to be white.
wanted_background_hex = '#FFFFFF'
wanted_background_rgb = QtGui.QColor(wanted_background_hex).rgb()
# WHEN: Resize the image and add a background.
image = resize_image(image_path, wanted_width, wanted_height, wanted_background_hex, True)
# THEN: Check if the size is correct and the background was set.
result_size = image.size()
self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.')
self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
def test_create_separated_list_qlocate(self):
"""
Test the create_separated_list function using the Qt provided method