Move backgrounds to css from images

This commit is contained in:
Tim Bentley 2010-09-04 08:48:58 +01:00
parent 6deac45c2c
commit e5b2ff9e06
3 changed files with 108 additions and 68 deletions

View File

@ -24,10 +24,13 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import logging
from PyQt4 import QtWebKit
from openlp.core.lib import image_to_byte
log = logging.getLogger(__name__)
HTMLSRC = u"""
<html>
<head>
@ -39,7 +42,7 @@ HTMLSRC = u"""
border: 0;
}
body {
background-color: black;
%s;
}
.size {
position: absolute;
@ -265,6 +268,7 @@ def build_html(item, screen, alert, islive):
"""
try:
webkitvers = float(QtWebKit.qWebKitVersion())
log.debug(u'Webkit version = %s' % webkitvers)
except AttributeError:
webkitvers = 0
width = screen[u'size'].width()
@ -274,7 +278,8 @@ def build_html(item, screen, alert, islive):
image = u'data:image/png;base64,%s' % image_to_byte(item.bg_frame)
else:
image = u''
html = HTMLSRC % (width, height,
html = HTMLSRC % (build_background_css(item, width, height),
width, height,
build_alert_css(alert, width),
build_footer_css(item),
build_lyrics_css(item, webkitvers),
@ -284,6 +289,38 @@ def build_html(item, screen, alert, islive):
build_lyrics_html(item, webkitvers))
return html
def build_background_css(item, width, height):
"""
Build the background css
`item`
Service Item containing theme and location information
"""
width = int(width) / 2
theme = item.themedata
background = u'background-color: black'
if theme:
if theme.background_type == u'solid':
background = u'background-color: %s' % theme.background_color
else:
if theme.background_direction == u'horizontal':
background = \
u'background: -webkit-gradient(linear, left top, left bottom, ' \
'from(%s), to(%s))' % (theme.background_startColor,
theme.background_endColor)
elif theme.background_direction == u'vertical':
background = \
u'background: -webkit-gradient(linear, left top, right top,' \
'from(%s), to(%s))' % (theme.background_startColor,
theme.background_endColor)
else:
background = \
u'background: -webkit-gradient(radial, %s 50%%, 100, %s 50%%, %s,' \
'from(%s), to(%s))' % (width, width, width, theme.background_startColor,
theme.background_endColor)
return background
def build_lyrics_css(item, webkitvers):
"""
Build the video display css

View File

@ -190,43 +190,46 @@ class Renderer(object):
self.bg_frame = QtGui.QImage(self.frame.width(),
self.frame.height(), QtGui.QImage.Format_ARGB32_Premultiplied)
log.debug(u'render background %s start', self._theme.background_type)
painter = QtGui.QPainter()
painter.begin(self.bg_frame)
if self._theme.background_type == u'solid':
painter.fillRect(self.frame.rect(),
QtGui.QColor(self._theme.background_color))
self.bg_frame = None
# painter.fillRect(self.frame.rect(),
# QtGui.QColor(self._theme.background_color))
elif self._theme.background_type == u'gradient':
self.bg_frame = None
# gradient
gradient = None
if self._theme.background_direction == u'horizontal':
w = int(self.frame.width()) / 2
# vertical
gradient = QtGui.QLinearGradient(w, 0, w, self.frame.height())
elif self._theme.background_direction == u'vertical':
h = int(self.frame.height()) / 2
# Horizontal
gradient = QtGui.QLinearGradient(0, h, self.frame.width(), h)
else:
w = int(self.frame.width()) / 2
h = int(self.frame.height()) / 2
# Circular
gradient = QtGui.QRadialGradient(w, h, w)
gradient.setColorAt(0,
QtGui.QColor(self._theme.background_startColor))
gradient.setColorAt(1,
QtGui.QColor(self._theme.background_endColor))
painter.setBrush(QtGui.QBrush(gradient))
rect_path = QtGui.QPainterPath()
max_x = self.frame.width()
max_y = self.frame.height()
rect_path.moveTo(0, 0)
rect_path.lineTo(0, max_y)
rect_path.lineTo(max_x, max_y)
rect_path.lineTo(max_x, 0)
rect_path.closeSubpath()
painter.drawPath(rect_path)
# gradient = None
# if self._theme.background_direction == u'horizontal':
# w = int(self.frame.width()) / 2
# # vertical
# gradient = QtGui.QLinearGradient(w, 0, w, self.frame.height())
# elif self._theme.background_direction == u'vertical':
# h = int(self.frame.height()) / 2
# # Horizontal
# gradient = QtGui.QLinearGradient(0, h, self.frame.width(), h)
# else:
# w = int(self.frame.width()) / 2
# h = int(self.frame.height()) / 2
# # Circular
# gradient = QtGui.QRadialGradient(w, h, w)
# gradient.setColorAt(0,
# QtGui.QColor(self._theme.background_startColor))
# gradient.setColorAt(1,
# QtGui.QColor(self._theme.background_endColor))
# painter.setBrush(QtGui.QBrush(gradient))
# rect_path = QtGui.QPainterPath()
# max_x = self.frame.width()
# max_y = self.frame.height()
# rect_path.moveTo(0, 0)
# rect_path.lineTo(0, max_y)
# rect_path.lineTo(max_x, max_y)
# rect_path.lineTo(max_x, 0)
# rect_path.closeSubpath()
# painter.drawPath(rect_path)
# painter.end()
elif self._theme.background_type == u'image':
# image
painter = QtGui.QPainter()
painter.begin(self.bg_frame)
painter.fillRect(self.frame.rect(), QtCore.Qt.black)
if self.bg_image:
painter.drawImage(0, 0, self.bg_image)

View File

@ -138,7 +138,7 @@ class MainDisplay(DisplayWidget):
painter_image = QtGui.QPainter()
painter_image.begin(self.black)
painter_image.fillRect(self.black.rect(), QtCore.Qt.black)
#Build the initial frame.
# Build the initial frame.
initialFrame = QtGui.QImage(
self.screens.current[u'size'].width(),
self.screens.current[u'size'].height(),