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
* @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) {
Display.clearSlides();
@ -345,7 +345,7 @@ var Display = {
section.setAttribute("id", index);
section.setAttribute("data-background", "#000");
var img = document.createElement('img');
img.src = slide["file"];
img.src = slide["filename"];
img.setAttribute("style", "height: 100%; width: 100%;");
section.appendChild(img);
slidesDiv.appendChild(section);
@ -355,14 +355,14 @@ var Display = {
},
/**
* 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) {
this.clearSlides();
var section = document.createElement("section");
section.setAttribute("data-background", "#000");
var videoElement = document.createElement("video");
videoElement.src = video["file"];
videoElement.src = video["filename"];
videoElement.preload = "auto";
videoElement.setAttribute("id", "video");
videoElement.setAttribute("style", "height: 100%; width: 100%;");

View File

@ -200,8 +200,8 @@ class DisplayWindow(QtWidgets.QWidget):
Set images in the display
"""
for image in images:
if not image['file'].startswith('file://'):
image['file'] = 'file://' + image['file']
if not image['filename'].startswith('file://'):
image['filename'] = 'file://' + image['filename']
json_images = json.dumps(images)
self.run_javascript('Display.setImageSlides({images});'.format(images=json_images))
@ -209,8 +209,8 @@ class DisplayWindow(QtWidgets.QWidget):
"""
Load video in the display
"""
if not video['file'].startswith('file://'):
video['file'] = 'file://' + video['file']
if not video['filename'].startswith('file://'):
video['filename'] = 'file://' + video['filename']
json_video = json.dumps(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
self.slide_list[str(row)] = row - 1
# If current slide set background to image
if not self.service_item.is_command() and slide_index == slide_no:
self.service_item.bg_image_bytes = \
self.image_manager.get_image_bytes(slide['filename'], ImageSource.ImagePlugin)
# if not self.service_item.is_command() and slide_index == slide_no:
# self.service_item.bg_image_bytes = \
# self.image_manager.get_image_bytes(slide['filename'], ImageSource.ImagePlugin)
self.preview_widget.replace_service_item(self.service_item, width, slide_no)
self.enable_tool_bar(self.service_item)
# 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.settings import Settings
from openlp.core.lib import ImageSource, ItemCapabilities, ServiceItem
from openlp.core.widgets.layouts import AspectRatioLayout
def handle_mime_data_urls(mime_data):
@ -197,34 +198,42 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
else:
pixmap = QtGui.QPixmap(slide['image'])
else:
image = self.image_manager.get_image(slide['filename'], ImageSource.ImagePlugin)
pixmap = QtGui.QPixmap.fromImage(image)
pixmap.setDevicePixelRatio(label.devicePixelRatio())
# image = self.image_manager.get_image(slide['filename'], ImageSource.ImagePlugin)
# pixmap = QtGui.QPixmap.fromImage(image)
pixmap = QtGui.QPixmap(slide['filename'].replace('file://', ''))
# pixmap.setDevicePixelRatio(label.devicePixelRatio())
label.setPixmap(pixmap)
slide_height = width // self.screen_ratio
label.setScaledContents(True)
label.setAlignment(QtCore.Qt.AlignCenter)
container = QtWidgets.QWidget()
layout = AspectRatioLayout(container, self.screen_ratio)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(label)
container.setLayout(layout)
# 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
self.setCellWidget(slide_index, 0, label)
# 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
self.setCellWidget(slide_index, 0, container)
row += 1
text.append(str(row))
self.setItem(slide_index, 0, item)