← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~j-corwin/openlp/transparent into lp:openlp

 

Jonathan Corwin has proposed merging lp:~j-corwin/openlp/transparent into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~j-corwin/openlp/transparent/+merge/87530

This change allows a Theme to have a Transparent background (again) so that the desktop or any other applications can be viewed behind the lyrics.

Note it wouldn't work on non-composite Linux desktops so this would need to be documented.

I made a change to the routine that grabs the preview of the display for the slidecontrollers and theme wizard since the old way didn't work with transparency. I don't know if this has any side effects, I didn't spot any at my end but any testing would be appreciated.

-- 
https://code.launchpad.net/~j-corwin/openlp/transparent/+merge/87530
Your team OpenLP Core is requested to review the proposed merge of lp:~j-corwin/openlp/transparent into lp:openlp.
=== modified file 'openlp/core/lib/htmlbuilder.py'
--- openlp/core/lib/htmlbuilder.py	2011-12-27 10:33:55 +0000
+++ openlp/core/lib/htmlbuilder.py	2012-01-04 20:25:22 +0000
@@ -129,10 +129,10 @@
         var match = /-webkit-text-fill-color:[^;\"]+/gi;
         if(timer != null)
             clearTimeout(timer);
-        /* 
-        QtWebkit bug with outlines and justify causing outline alignment 
-        problems. (Bug 859950) Surround each word with a <span> to workaround, 
-        but only in this scenario. 
+        /*
+        QtWebkit bug with outlines and justify causing outline alignment
+        problems. (Bug 859950) Surround each word with a <span> to workaround,
+        but only in this scenario.
         */
         var txt = document.getElementById('lyricsmain');
         if(window.getComputedStyle(txt).textAlign == 'justify'){
@@ -141,7 +141,7 @@
                 txt = outline;
             if(window.getComputedStyle(txt).webkitTextStrokeWidth != '0px'){
                 newtext = newtext.replace(/(\s|&nbsp;)+(?![^<]*>)/g,
-                    function(match) { 
+                    function(match) {
                         return '</span>' + match + '<span>';
                     });
                 newtext = '<span>' + newtext + '</span>';
@@ -288,6 +288,9 @@
     background = u'background-color: black'
     if theme:
         if theme.background_type == \
+            BackgroundType.to_string(BackgroundType.Transparent):
+            background = u''
+        elif theme.background_type == \
             BackgroundType.to_string(BackgroundType.Solid):
             background = u'background-color: %s' % theme.background_color
         else:

=== modified file 'openlp/core/lib/theme.py'
--- openlp/core/lib/theme.py	2011-12-27 10:33:55 +0000
+++ openlp/core/lib/theme.py	2012-01-04 20:25:22 +0000
@@ -100,6 +100,7 @@
     Solid = 0
     Gradient = 1
     Image = 2
+    Transparent = 3
 
     @staticmethod
     def to_string(background_type):
@@ -112,6 +113,8 @@
             return u'gradient'
         elif background_type == BackgroundType.Image:
             return u'image'
+        elif background_type == BackgroundType.Transparent:
+            return u'transparent'
 
     @staticmethod
     def from_string(type_string):
@@ -124,6 +127,8 @@
             return BackgroundType.Gradient
         elif type_string == u'image':
             return BackgroundType.Image
+        elif type_string == u'transparent':
+            return BackgroundType.Transparent
 
 
 class BackgroundGradientType(object):
@@ -246,7 +251,7 @@
         Add a transparent background.
         """
         background = self.theme_xml.createElement(u'background')
-        background.setAttribute(u'mode', u'transparent')
+        background.setAttribute(u'type', u'transparent')
         self.theme.appendChild(background)
 
     def add_background_solid(self, bkcolor):
@@ -487,25 +492,25 @@
             return
         xml_iter = theme_xml.getiterator()
         for element in xml_iter:
+            master = u''
+            if element.tag == u'background':
+                if element.attrib:
+                    for attr in element.attrib:
+                        self._create_attr(element.tag, attr, \
+                        element.attrib[attr])
             parent = element.getparent()
-            master = u''
             if parent is not None:
-                if element.getparent().tag == u'font':
-                    master = element.getparent().tag + u'_' + \
-                    element.getparent().attrib[u'type']
+                if parent.tag == u'font':
+                    master = parent.tag + u'_' + parent.attrib[u'type']
                 # set up Outline and Shadow Tags and move to font_main
-                if element.getparent().tag == u'display':
+                if parent.tag == u'display':
                     if element.tag.startswith(u'shadow') or \
                         element.tag.startswith(u'outline'):
                         self._create_attr(u'font_main', element.tag,
                             element.text)
-                    master = element.getparent().tag
-                if element.getparent().tag == u'background':
-                    master = element.getparent().tag
-                    if element.getparent().attrib:
-                        for attr in element.getparent().attrib:
-                            self._create_attr(master, attr, \
-                            element.getparent().attrib[attr])
+                    master = parent.tag
+                if parent.tag == u'background':
+                    master = parent.tag
             if master:
                 self._create_attr(master, element.tag, element.text)
                 if element.attrib:
@@ -599,9 +604,13 @@
                 self.background_start_color,
                 self.background_end_color,
                 self.background_direction)
-        else:
+        elif self.background_type == \
+            BackgroundType.to_string(BackgroundType.Image):
             filename = os.path.split(self.background_filename)[1]
             self.add_background_image(filename, self.background_border_color)
+        elif self.background_type == \
+            BackgroundType.to_string(BackgroundType.Transparent):
+            self.add_background_transparent()
         self.add_font(self.font_main_name,
             self.font_main_color,
             self.font_main_size,

=== modified file 'openlp/core/ui/maindisplay.py'
--- openlp/core/ui/maindisplay.py	2011-12-29 17:50:42 +0000
+++ openlp/core/ui/maindisplay.py	2012-01-04 20:25:22 +0000
@@ -81,6 +81,10 @@
             self.screen[u'size'].width(), self.screen[u'size'].height())
         self.webView.settings().setAttribute(
             QtWebKit.QWebSettings.PluginsEnabled, True)
+        palette = self.webView.palette()
+        palette.setBrush(QtGui.QPalette.Base, QtCore.Qt.transparent)
+        self.webView.page().setPalette(palette)
+        self.webView.setAttribute(QtCore.Qt.WA_OpaquePaintEvent, False)
         self.page = self.webView.page()
         self.frame = self.page.mainFrame()
         if self.isLive and log.getEffectiveLevel() == logging.DEBUG:
@@ -138,6 +142,7 @@
             windowFlags = windowFlags | QtCore.Qt.SplashScreen
         self.setWindowFlags(windowFlags)
         self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
+        self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
         if self.isLive:
             QtCore.QObject.connect(Receiver.get_receiver(),
                 QtCore.SIGNAL(u'live_display_hide'), self.hideDisplay)
@@ -346,13 +351,7 @@
                         self.setVisible(True)
                 else:
                     self.setVisible(True)
-        preview = QtGui.QPixmap(self.screen[u'size'].width(),
-            self.screen[u'size'].height())
-        painter = QtGui.QPainter(preview)
-        painter.setRenderHint(QtGui.QPainter.Antialiasing)
-        self.frame.render(painter)
-        painter.end()
-        return preview
+        return QtGui.QPixmap.grabWidget(self)
 
     def buildHtml(self, serviceItem, image=None):
         """

=== modified file 'openlp/core/ui/themeform.py'
--- openlp/core/ui/themeform.py	2011-12-27 10:33:55 +0000
+++ openlp/core/ui/themeform.py	2012-01-04 20:25:22 +0000
@@ -359,11 +359,15 @@
             self.gradientEndButton.setStyleSheet(u'background-color: %s' %
                     self.theme.background_end_color)
             self.setField(u'background_type', QtCore.QVariant(1))
-        else:
+        elif self.theme.background_type == \
+            BackgroundType.to_string(BackgroundType.Image):
             self.imageColorButton.setStyleSheet(u'background-color: %s' %
                     self.theme.background_border_color)
             self.imageFileEdit.setText(self.theme.background_filename)
             self.setField(u'background_type', QtCore.QVariant(2))
+        elif self.theme.background_type == \
+            BackgroundType.to_string(BackgroundType.Transparent):
+            self.setField(u'background_type', QtCore.QVariant(3))
         if self.theme.background_direction == \
             BackgroundGradientType.to_string(BackgroundGradientType.Horizontal):
             self.setField(u'gradient', QtCore.QVariant(0))

=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py	2011-12-27 10:33:55 +0000
+++ openlp/core/ui/thememanager.py	2012-01-04 20:25:22 +0000
@@ -813,10 +813,13 @@
                 unicode(theme.BackgroundParameter1.name())
             newtheme.background_end_color = \
                 unicode(theme.BackgroundParameter2.name())
-        else:
+        elif theme.BackgroundType == 2:
             newtheme.background_type = \
                 BackgroundType.to_string(BackgroundType.Image)
             newtheme.background_filename = unicode(theme.BackgroundParameter1)
+        elif theme.BackgroundType == 3:
+            newtheme.background_type = \
+                BackgroundType.to_string(BackgroundType.Transparent)
         newtheme.font_main_name = theme.FontName
         newtheme.font_main_color = unicode(theme.FontColor.name())
         newtheme.font_main_size = theme.FontProportion * 3

=== modified file 'openlp/core/ui/themewizard.py'
--- openlp/core/ui/themewizard.py	2011-12-27 10:33:55 +0000
+++ openlp/core/ui/themewizard.py	2012-01-04 20:25:22 +0000
@@ -54,7 +54,7 @@
         self.backgroundLabel = QtGui.QLabel(self.backgroundPage)
         self.backgroundLabel.setObjectName(u'BackgroundLabel')
         self.backgroundComboBox = QtGui.QComboBox(self.backgroundPage)
-        self.backgroundComboBox.addItems([u'', u'', u''])
+        self.backgroundComboBox.addItems([u'', u'', u'', u''])
         self.backgroundComboBox.setObjectName(u'BackgroundComboBox')
         self.backgroundTypeLayout.addRow(self.backgroundLabel,
             self.backgroundComboBox)
@@ -126,6 +126,12 @@
         self.imageLayout.addRow(self.imageLabel, self.imageFileLayout)
         self.imageLayout.setItem(2, QtGui.QFormLayout.LabelRole, self.spacer)
         self.backgroundStack.addWidget(self.imageWidget)
+        self.transparentWidget = QtGui.QWidget(self.backgroundPage)
+        self.transparentWidget.setObjectName(u'TransparentWidget')
+        self.transparentLayout = QtGui.QFormLayout(self.transparentWidget)
+        self.transparentLayout.setMargin(0)
+        self.transparentLayout.setObjectName(u'TransparentLayout')
+        self.backgroundStack.addWidget(self.transparentWidget)
         self.backgroundLayout.addLayout(self.backgroundStack)
         themeWizard.addPage(self.backgroundPage)
         # Main Area Page
@@ -432,6 +438,8 @@
             translate('OpenLP.ThemeWizard', 'Gradient'))
         self.backgroundComboBox.setItemText(
             BackgroundType.Image, UiStrings().Image)
+        self.backgroundComboBox.setItemText(BackgroundType.Transparent,
+            translate('OpenLP.ThemeWizard', 'Transparent'))
         self.colorLabel.setText(translate('OpenLP.ThemeWizard', 'Color:'))
         self.gradientStartLabel.setText(
             translate(u'OpenLP.ThemeWizard', 'Starting color:'))


Follow ups