Corrected aspect ratio on slide previews

This commit is contained in:
Ian Knight 2016-05-04 21:40:42 +09:30
parent f6cb085b0d
commit f0d7cf7f36
5 changed files with 39 additions and 12 deletions

View File

@ -55,9 +55,13 @@ class ImageSource(object):
``Theme`` ``Theme``
This says, that the image is used by a 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 ImagePlugin = 1
Theme = 2 Theme = 2
PresentationPlugin = 3
class MediaType(object): 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() ext = os.path.splitext(thumb_path)[1].lower()
reader = QtGui.QImageReader(image_path) reader = QtGui.QImageReader(image_path)
if size is None: if size is None:
# No size given; use default height of 88
ratio = reader.size().width() / reader.size().height() ratio = reader.size().width() / reader.size().height()
reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88))
else: elif size.isValid():
# Complete size given
reader.setScaledSize(size) 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 = reader.read()
thumb.save(thumb_path, ext[1:]) thumb.save(thumb_path, ext[1:])
if not return_icon: if not return_icon:

View File

@ -334,6 +334,7 @@ class ServiceItem(RegistryProperties):
file_location_hash, ntpath.basename(image)) file_location_hash, ntpath.basename(image))
self._raw_frames.append({'title': file_name, 'image': image, 'path': path, self._raw_frames.append({'title': file_name, 'image': image, 'path': path,
'display_title': display_title, 'notes': notes}) 'display_title': display_title, 'notes': notes})
self.image_manager.add_image(image, ImageSource.PresentationPlugin, '#000000')
self._new_item() self._new_item()
def get_service_repr(self, lite_save): def get_service_repr(self, lite_save):

View File

@ -152,14 +152,15 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
else: else:
label.setScaledContents(True) label.setScaledContents(True)
if self.service_item.is_command(): if self.service_item.is_command():
pixmap = QtGui.QPixmap(frame['image']) #pixmap = QtGui.QPixmap(frame['image'])
pixmap.setDevicePixelRatio(label.devicePixelRatio()) #pixmap.setDevicePixelRatio(label.devicePixelRatio())
label.setPixmap(pixmap) #label.setPixmap(pixmap)
image = self.image_manager.get_image(frame['image'], ImageSource.PresentationPlugin)
else: else:
image = self.image_manager.get_image(frame['path'], ImageSource.ImagePlugin) image = self.image_manager.get_image(frame['path'], ImageSource.ImagePlugin)
pixmap = QtGui.QPixmap.fromImage(image) pixmap = QtGui.QPixmap.fromImage(image)
pixmap.setDevicePixelRatio(label.devicePixelRatio()) pixmap.setDevicePixelRatio(label.devicePixelRatio())
label.setPixmap(pixmap) label.setPixmap(pixmap)
slide_height = width // self.screen_ratio slide_height = width // self.screen_ratio
# Setup and validate row height cap if in use. # Setup and validate row height cap if in use.
max_img_row_height = Settings().value('advanced/slide max height') max_img_row_height = Settings().value('advanced/slide max height')

View File

@ -1132,9 +1132,16 @@ class SlideController(DisplayController, RegistryProperties):
""" """
self.log_debug('update_preview %s ' % self.screens.current['primary']) self.log_debug('update_preview %s ' % self.screens.current['primary'])
if self.service_item and self.service_item.is_capable(ItemCapabilities.ProvidesOwnDisplay): 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 if self.is_live:
QtCore.QTimer.singleShot(500, self.grab_maindisplay) # If live, grab screen-cap of main display now
QtCore.QTimer.singleShot(2500, self.grab_maindisplay) 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: else:
self.slide_image = self.display.preview() self.slide_image = self.display.preview()
self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio()) self.slide_image.setDevicePixelRatio(self.main_window.devicePixelRatio())

View File

@ -242,13 +242,13 @@ class PresentationDocument(object):
def convert_thumbnail(self, file, idx): 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(): if self.check_thumbnails():
return return
if os.path.isfile(file): if os.path.isfile(file):
thumb_path = self.get_thumbnail_path(idx, False) 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): def get_thumbnail_path(self, slide_no, check_exists):
""" """