First go at making images work

This commit is contained in:
Raoul Snyman 2018-04-12 23:28:13 -07:00
parent 3ff3f501fa
commit af446d31b9
4 changed files with 46 additions and 37 deletions

View File

@ -335,7 +335,7 @@ var Display = {
}, },
/** /**
* Set image slides * Set image slides
* @param {Object[]} slides - A list of images to add as JS objects [{"file": "url/to/file"}] * @param {Object[]} slides - A list of images to add as JS objects [{"filename": "url/to/file"}]
*/ */
setImageSlides: function (slides) { setImageSlides: function (slides) {
Display.clearSlides(); Display.clearSlides();
@ -345,7 +345,7 @@ var Display = {
section.setAttribute("id", index); section.setAttribute("id", index);
section.setAttribute("data-background", "#000"); section.setAttribute("data-background", "#000");
var img = document.createElement('img'); var img = document.createElement('img');
img.src = slide["file"]; img.src = slide["filename"];
img.setAttribute("style", "height: 100%; width: 100%;"); img.setAttribute("style", "height: 100%; width: 100%;");
section.appendChild(img); section.appendChild(img);
slidesDiv.appendChild(section); slidesDiv.appendChild(section);
@ -355,14 +355,14 @@ var Display = {
}, },
/** /**
* Set a video * Set a video
* @param {Object} video - The video to show as a JS object: {"file": "url/to/file"} * @param {Object} video - The video to show as a JS object: {"filename": "url/to/file"}
*/ */
setVideo: function (video) { setVideo: function (video) {
this.clearSlides(); this.clearSlides();
var section = document.createElement("section"); var section = document.createElement("section");
section.setAttribute("data-background", "#000"); section.setAttribute("data-background", "#000");
var videoElement = document.createElement("video"); var videoElement = document.createElement("video");
videoElement.src = video["file"]; videoElement.src = video["filename"];
videoElement.preload = "auto"; videoElement.preload = "auto";
videoElement.setAttribute("id", "video"); videoElement.setAttribute("id", "video");
videoElement.setAttribute("style", "height: 100%; width: 100%;"); videoElement.setAttribute("style", "height: 100%; width: 100%;");

View File

@ -200,8 +200,8 @@ class DisplayWindow(QtWidgets.QWidget):
Set images in the display Set images in the display
""" """
for image in images: for image in images:
if not image['file'].startswith('file://'): if not image['filename'].startswith('file://'):
image['file'] = 'file://' + image['file'] image['filename'] = 'file://' + image['filename']
json_images = json.dumps(images) json_images = json.dumps(images)
self.run_javascript('Display.setImageSlides({images});'.format(images=json_images)) self.run_javascript('Display.setImageSlides({images});'.format(images=json_images))
@ -209,8 +209,8 @@ class DisplayWindow(QtWidgets.QWidget):
""" """
Load video in the display Load video in the display
""" """
if not video['file'].startswith('file://'): if not video['filename'].startswith('file://'):
video['file'] = 'file://' + video['file'] video['filename'] = 'file://' + video['filename']
json_video = json.dumps(video) json_video = json.dumps(video)
self.run_javascript('Display.setVideo({video});'.format(video=json_video)) self.run_javascript('Display.setVideo({video});'.format(video=json_video))

View File

@ -863,9 +863,9 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
row += 1 row += 1
self.slide_list[str(row)] = row - 1 self.slide_list[str(row)] = row - 1
# If current slide set background to image # If current slide set background to image
if not self.service_item.is_command() and slide_index == slide_no: # if not self.service_item.is_command() and slide_index == slide_no:
self.service_item.bg_image_bytes = \ # self.service_item.bg_image_bytes = \
self.image_manager.get_image_bytes(slide['filename'], ImageSource.ImagePlugin) # self.image_manager.get_image_bytes(slide['filename'], ImageSource.ImagePlugin)
self.preview_widget.replace_service_item(self.service_item, width, slide_no) self.preview_widget.replace_service_item(self.service_item, width, slide_no)
self.enable_tool_bar(self.service_item) self.enable_tool_bar(self.service_item)
# Pass to display for viewing. # Pass to display for viewing.

View File

@ -32,6 +32,7 @@ from openlp.core.common.path import Path
from openlp.core.common.registry import Registry from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings from openlp.core.common.settings import Settings
from openlp.core.lib import ImageSource, ItemCapabilities, ServiceItem from openlp.core.lib import ImageSource, ItemCapabilities, ServiceItem
from openlp.core.widgets.layouts import AspectRatioLayout
def handle_mime_data_urls(mime_data): def handle_mime_data_urls(mime_data):
@ -197,34 +198,42 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
else: else:
pixmap = QtGui.QPixmap(slide['image']) pixmap = QtGui.QPixmap(slide['image'])
else: else:
image = self.image_manager.get_image(slide['filename'], ImageSource.ImagePlugin) # image = self.image_manager.get_image(slide['filename'], ImageSource.ImagePlugin)
pixmap = QtGui.QPixmap.fromImage(image) # pixmap = QtGui.QPixmap.fromImage(image)
pixmap.setDevicePixelRatio(label.devicePixelRatio()) pixmap = QtGui.QPixmap(slide['filename'].replace('file://', ''))
# pixmap.setDevicePixelRatio(label.devicePixelRatio())
label.setPixmap(pixmap) label.setPixmap(pixmap)
slide_height = width // self.screen_ratio label.setScaledContents(True)
# Setup and validate row height cap if in use. label.setAlignment(QtCore.Qt.AlignCenter)
max_img_row_height = Settings().value('advanced/slide max height')
if isinstance(max_img_row_height, int) and max_img_row_height != 0:
if max_img_row_height > 0 and slide_height > max_img_row_height:
# Manual Setting
slide_height = max_img_row_height
elif max_img_row_height < 0 and slide_height > self.auto_row_height:
# Auto Setting
slide_height = self.auto_row_height
label.setMaximumWidth(slide_height * self.screen_ratio)
label.resize(slide_height * self.screen_ratio, slide_height)
# Build widget with stretch padding
container = QtWidgets.QWidget() container = QtWidgets.QWidget()
hbox = QtWidgets.QHBoxLayout() layout = AspectRatioLayout(container, self.screen_ratio)
hbox.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
hbox.addWidget(label, stretch=1) layout.addWidget(label)
hbox.addStretch(0) container.setLayout(layout)
container.setLayout(hbox) # 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')
# if isinstance(max_img_row_height, int) and max_img_row_height != 0:
# if max_img_row_height > 0 and slide_height > max_img_row_height:
# # Manual Setting
# slide_height = max_img_row_height
# elif max_img_row_height < 0 and slide_height > self.auto_row_height:
# # Auto Setting
# slide_height = self.auto_row_height
# label.setMaximumWidth(slide_height * self.screen_ratio)
# label.resize(slide_height * self.screen_ratio, slide_height)
# # Build widget with stretch padding
# container = QtWidgets.QWidget()
# hbox = QtWidgets.QHBoxLayout()
# hbox.setContentsMargins(0, 0, 0, 0)
# hbox.addWidget(label, stretch=1)
# hbox.addStretch(0)
# container.setLayout(hbox)
# # Add to table
# self.setCellWidget(slide_index, 0, container)
# else:
# Add to table # Add to table
self.setCellWidget(slide_index, 0, container) self.setCellWidget(slide_index, 0, container)
else:
# Add to table
self.setCellWidget(slide_index, 0, label)
row += 1 row += 1
text.append(str(row)) text.append(str(row))
self.setItem(slide_index, 0, item) self.setItem(slide_index, 0, item)