From f0d7cf7f36e6942c8aa795c180edae8a9112dd37 Mon Sep 17 00:00:00 2001 From: Ian Knight Date: Wed, 4 May 2016 21:40:42 +0930 Subject: [PATCH] Corrected aspect ratio on slide previews --- openlp/core/lib/__init__.py | 20 ++++++++++++++++++- openlp/core/lib/serviceitem.py | 1 + openlp/core/ui/listpreviewwidget.py | 13 ++++++------ openlp/core/ui/slidecontroller.py | 13 +++++++++--- .../lib/presentationcontroller.py | 4 ++-- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 6e62bbf9c..4e85fe7e4 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -55,9 +55,13 @@ class ImageSource(object): ``Theme`` This says, that the image is used by a theme. + + ``PresentationPlugin`` + This states that an image is being used by the presentation plugin. """ ImagePlugin = 1 Theme = 2 + PresentationPlugin = 3 class MediaType(object): @@ -174,10 +178,24 @@ def create_thumb(image_path, thumb_path, return_icon=True, size=None): ext = os.path.splitext(thumb_path)[1].lower() reader = QtGui.QImageReader(image_path) if size is None: + # No size given; use default height of 88 ratio = reader.size().width() / reader.size().height() reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) - else: + elif size.isValid(): + # Complete size given reader.setScaledSize(size) + else: + # Invalid size given + ratio = reader.size().width() / reader.size().height() + if size.width() >= 0: + # Valid width; scale height + reader.setScaledSize(QtCore.QSize(size.width(), int(size.width() / ratio))) + elif size.height() >= 0: + # Valid height; scale width + reader.setScaledSize(QtCore.QSize(int(ratio * size.height()), size.height())) + else: + # Invalid; use default height of 88 + reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) thumb = reader.read() thumb.save(thumb_path, ext[1:]) if not return_icon: diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index e45aa6e61..32afbfe4f 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -334,6 +334,7 @@ class ServiceItem(RegistryProperties): file_location_hash, ntpath.basename(image)) self._raw_frames.append({'title': file_name, 'image': image, 'path': path, 'display_title': display_title, 'notes': notes}) + self.image_manager.add_image(image, ImageSource.PresentationPlugin, '#000000') self._new_item() def get_service_repr(self, lite_save): diff --git a/openlp/core/ui/listpreviewwidget.py b/openlp/core/ui/listpreviewwidget.py index 88aef818a..4d62e3173 100644 --- a/openlp/core/ui/listpreviewwidget.py +++ b/openlp/core/ui/listpreviewwidget.py @@ -152,14 +152,15 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties): else: label.setScaledContents(True) if self.service_item.is_command(): - pixmap = QtGui.QPixmap(frame['image']) - pixmap.setDevicePixelRatio(label.devicePixelRatio()) - label.setPixmap(pixmap) + #pixmap = QtGui.QPixmap(frame['image']) + #pixmap.setDevicePixelRatio(label.devicePixelRatio()) + #label.setPixmap(pixmap) + image = self.image_manager.get_image(frame['image'], ImageSource.PresentationPlugin) else: image = self.image_manager.get_image(frame['path'], ImageSource.ImagePlugin) - pixmap = QtGui.QPixmap.fromImage(image) - pixmap.setDevicePixelRatio(label.devicePixelRatio()) - label.setPixmap(pixmap) + pixmap = QtGui.QPixmap.fromImage(image) + pixmap.setDevicePixelRatio(label.devicePixelRatio()) + label.setPixmap(pixmap) slide_height = width // self.screen_ratio # Setup and validate row height cap if in use. max_img_row_height = Settings().value('advanced/slide max height') diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 96ce82868..f04bff8fa 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -1132,9 +1132,16 @@ class SlideController(DisplayController, RegistryProperties): """ self.log_debug('update_preview %s ' % self.screens.current['primary']) if self.service_item and self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay): - # Grab now, but try again in a couple of seconds if slide change is slow - QtCore.QTimer.singleShot(500, self.grab_maindisplay) - QtCore.QTimer.singleShot(2500, self.grab_maindisplay) + if self.is_live: + # If live, grab screen-cap of main display now + QtCore.QTimer.singleShot(500, self.grab_maindisplay) + # but take another in a couple of seconds in case slide change is slow + QtCore.QTimer.singleShot(2500, self.grab_maindisplay) + else: + # If not live, use the slide's thumbnail instead + self.slide_image = QtGui.QPixmap.fromImage(self.image_manager.get_image(self.service_item.get_rendered_frame(self.selected_row), ImageSource.PresentationPlugin)) #QtGui.QPixmap(self.service_item.get_rendered_frame(self.selected_row)) + self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio()) + self.slide_preview.setPixmap(self.slide_image) else: self.slide_image = self.display.preview() self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio()) diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index abc71f867..fc90ddb0d 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -242,13 +242,13 @@ class PresentationDocument(object): def convert_thumbnail(self, file, idx): """ - Convert the slide image the application made to a standard 320x240 .png image. + Convert the slide image the application made to a scaled 360px height .png image. """ if self.check_thumbnails(): return if os.path.isfile(file): thumb_path = self.get_thumbnail_path(idx, False) - create_thumb(file, thumb_path, False, QtCore.QSize(320, 240)) + create_thumb(file, thumb_path, False, QtCore.QSize(-1, 360)) def get_thumbnail_path(self, slide_no, check_exists): """