Merge lp:~oliwee/openlp/transparentBackground into lp:openlp

Proposed by Oliver Wieland
Status: Needs review
Proposed branch: lp:~oliwee/openlp/transparentBackground
Merge into: lp:openlp
Diff against target: 309 lines (+114/-17)
8 files modified
openlp/core/lib/htmlbuilder.py (+18/-7)
openlp/core/lib/json/theme.json (+3/-1)
openlp/core/lib/renderer.py (+1/-1)
openlp/core/lib/theme.py (+14/-2)
openlp/core/ui/themeform.py (+6/-0)
openlp/core/ui/themewizard.py (+20/-0)
tests/functional/openlp_core_lib/test_htmlbuilder.py (+51/-5)
tests/functional/openlp_core_lib/test_theme.py (+1/-1)
To merge this branch: bzr merge lp:~oliwee/openlp/transparentBackground
Reviewer Review Type Date Requested Status
OpenLP Core Pending
Review via email: mp+250562@code.launchpad.net

Description of the change

Added transparency behind main text to theme

new theme option 'Transparency' for setting the transparency of the background of the main text

new theme option 'Smooth transition' to choose if there should be a smoother transition to the transparent area

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

New features are only for 2.4. Let's park this until 2.2 is out the door.

Unmerged revisions

2514. By Oliver Wieland

Added transparency behind main text to theme
  new theme option 'Transparency' for setting the transparency of the background of the main text
  new theme option 'Smooth transition' to choose if there should be a smoother transition to the transparent area

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/lib/htmlbuilder.py'
--- openlp/core/lib/htmlbuilder.py 2015-01-18 13:39:21 +0000
+++ openlp/core/lib/htmlbuilder.py 2015-02-22 20:49:19 +0000
@@ -585,7 +585,7 @@
585 build_background_css(item, width),585 build_background_css(item, width),
586 css_additions,586 css_additions,
587 build_footer_css(item, height),587 build_footer_css(item, height),
588 build_lyrics_css(item),588 build_lyrics_css(item, width),
589 'true' if theme_data and theme_data.display_slide_transition and is_live else 'false',589 'true' if theme_data and theme_data.display_slide_transition and is_live else 'false',
590 js_additions,590 js_additions,
591 bgimage_src,591 bgimage_src,
@@ -641,7 +641,7 @@
641 return background641 return background
642642
643643
644def build_lyrics_css(item):644def build_lyrics_css(item, display_width):
645 """645 """
646 Build the lyrics display css646 Build the lyrics display css
647647
@@ -669,8 +669,16 @@
669 lyrics = ''669 lyrics = ''
670 lyricsmain = ''670 lyricsmain = ''
671 if theme_data and item.main:671 if theme_data and item.main:
672 lyricstable = 'left: %spx; top: %spx;' % (item.main.x(), item.main.y())672 lyricstable = 'left: 0px; padding-left: %spx; top: %spx; width: 100%%; ' % (item.main.x(), item.main.y())
673 lyrics = build_lyrics_format_css(theme_data, item.main.width(), item.main.height())673 transparency = 1 - (float(theme_data.display_background_transparency) / 100)
674 if theme_data.display_smooth_transparency:
675 lyricstable += 'background: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%%, rgba(0,0,0,%s) 2%%, rgba(0,0,0,%s) 98%%,rgba(0,0,0,0) 100%%);'\
676 % (transparency, transparency)
677 else:
678 lyricstable += 'background: rgba(0,0,0,%s);' % (transparency)
679
680
681 lyrics = build_lyrics_format_css(theme_data, item.main.width(), item.main.height(), display_width)
674 lyricsmain += build_lyrics_outline_css(theme_data)682 lyricsmain += build_lyrics_outline_css(theme_data)
675 if theme_data.font_main_shadow:683 if theme_data.font_main_shadow:
676 lyricsmain += ' text-shadow: %s %spx %spx;' % \684 lyricsmain += ' text-shadow: %s %spx %spx;' % \
@@ -693,7 +701,7 @@
693 return ''701 return ''
694702
695703
696def build_lyrics_format_css(theme_data, width, height):704def build_lyrics_format_css(theme_data, width, height, display_width):
697 """705 """
698 Build the css which controls the theme format. Also used by renderer for splitting verses706 Build the css which controls the theme format. Also used by renderer for splitting verses
699707
@@ -715,13 +723,16 @@
715 padding_bottom = '0.5em'723 padding_bottom = '0.5em'
716 else:724 else:
717 padding_bottom = '0'725 padding_bottom = '0'
726
727 padding_right = display_width - width;
728
718 lyrics = '%s word-wrap: break-word; ' \729 lyrics = '%s word-wrap: break-word; ' \
719 'text-align: %s; vertical-align: %s; font-family: %s; ' \730 'text-align: %s; vertical-align: %s; font-family: %s; ' \
720 'font-size: %spt; color: %s; line-height: %d%%; margin: 0;' \731 'font-size: %spt; color: %s; line-height: %d%%; margin: 0;' \
721 'padding: 0; padding-bottom: %s; padding-left: %spx; width: %spx; height: %spx; ' % \732 'padding: 0; padding-bottom: %s; padding-left: %spx; padding-right: %spx; width: %spx; height: %spx; ' % \
722 (justify, align, valign, theme_data.font_main_name, theme_data.font_main_size,733 (justify, align, valign, theme_data.font_main_name, theme_data.font_main_size,
723 theme_data.font_main_color, 100 + int(theme_data.font_main_line_adjustment), padding_bottom,734 theme_data.font_main_color, 100 + int(theme_data.font_main_line_adjustment), padding_bottom,
724 left_margin, width, height)735 left_margin, padding_right, width, height)
725 if theme_data.font_main_italics:736 if theme_data.font_main_italics:
726 lyrics += 'font-style:italic; '737 lyrics += 'font-style:italic; '
727 if theme_data.font_main_bold:738 if theme_data.font_main_bold:
728739
=== modified file 'openlp/core/lib/json/theme.json'
--- openlp/core/lib/json/theme.json 2013-10-18 18:10:47 +0000
+++ openlp/core/lib/json/theme.json 2015-02-22 20:49:19 +0000
@@ -11,7 +11,9 @@
11 "display" :{11 "display" :{
12 "horizontal_align": 0,12 "horizontal_align": 0,
13 "slide_transition": false,13 "slide_transition": false,
14 "vertical_align": 014 "vertical_align": 0,
15 "background_transparency": 100,
16 "smooth_transparency": 0
15 },17 },
16 "font": {18 "font": {
17 "footer": {19 "footer": {
1820
=== modified file 'openlp/core/lib/renderer.py'
--- openlp/core/lib/renderer.py 2015-01-18 13:39:21 +0000
+++ openlp/core/lib/renderer.py 2015-02-22 20:49:19 +0000
@@ -381,7 +381,7 @@
381 </script><style>*{margin: 0; padding: 0; border: 0;}381 </script><style>*{margin: 0; padding: 0; border: 0;}
382 #main {position: absolute; top: 0px; %s %s}</style></head><body>382 #main {position: absolute; top: 0px; %s %s}</style></head><body>
383 <div id="main"></div></body></html>""" % \383 <div id="main"></div></body></html>""" % \
384 (build_lyrics_format_css(theme_data, self.page_width, self.page_height),384 (build_lyrics_format_css(theme_data, self.page_width, self.page_height, self.display.width()),
385 build_lyrics_outline_css(theme_data))385 build_lyrics_outline_css(theme_data))
386 self.web.setHtml(html)386 self.web.setHtml(html)
387 self.empty_height = self.web_frame.contentsSize().height()387 self.empty_height = self.web_frame.contentsSize().height()
388388
=== modified file 'openlp/core/lib/theme.py'
--- openlp/core/lib/theme.py 2015-01-18 13:39:21 +0000
+++ openlp/core/lib/theme.py 2015-02-22 20:49:19 +0000
@@ -318,7 +318,7 @@
318 element.appendChild(value)318 element.appendChild(value)
319 background.appendChild(element)319 background.appendChild(element)
320320
321 def add_display(self, horizontal, vertical, transition):321 def add_display(self, horizontal, vertical, transition, background_transparency, smooth_transparency):
322 """322 """
323 Add a Display options.323 Add a Display options.
324324
@@ -343,6 +343,16 @@
343 value = self.theme_xml.createTextNode(str(transition))343 value = self.theme_xml.createTextNode(str(transition))
344 element.appendChild(value)344 element.appendChild(value)
345 background.appendChild(element)345 background.appendChild(element)
346 # Background Transparency
347 element = self.theme_xml.createElement('backgroundTransparency')
348 value = self.theme_xml.createTextNode(str(background_transparency))
349 element.appendChild(value)
350 background.appendChild(element)
351 # Smooth Transparency
352 element = self.theme_xml.createElement('smoothTransparency')
353 value = self.theme_xml.createTextNode(str(smooth_transparency))
354 element.appendChild(value)
355 background.appendChild(element)
346356
347 def child_element(self, element, tag, value):357 def child_element(self, element, tag, value):
348 """358 """
@@ -555,5 +565,7 @@
555 self.add_display(565 self.add_display(
556 self.display_horizontal_align,566 self.display_horizontal_align,
557 self.display_vertical_align,567 self.display_vertical_align,
558 self.display_slide_transition568 self.display_slide_transition,
569 self.display_background_transparency,
570 self.display_smooth_transparency
559 )571 )
560572
=== modified file 'openlp/core/ui/themeform.py'
--- openlp/core/ui/themeform.py 2015-01-18 13:39:21 +0000
+++ openlp/core/ui/themeform.py 2015-02-22 20:49:19 +0000
@@ -134,6 +134,8 @@
134 self.background_page.registerField('horizontal', self.horizontal_combo_box)134 self.background_page.registerField('horizontal', self.horizontal_combo_box)
135 self.background_page.registerField('vertical', self.vertical_combo_box)135 self.background_page.registerField('vertical', self.vertical_combo_box)
136 self.background_page.registerField('slide_transition', self.transitions_check_box)136 self.background_page.registerField('slide_transition', self.transitions_check_box)
137 self.background_page.registerField('background_transparency', self.background_transparency_spin_box)
138 self.background_page.registerField('smooth_transparency', self.smooth_transparency_check_box)
137 self.background_page.registerField('name', self.theme_name_edit)139 self.background_page.registerField('name', self.theme_name_edit)
138140
139 def calculate_lines(self):141 def calculate_lines(self):
@@ -366,6 +368,8 @@
366 self.setField('horizontal', self.theme.display_horizontal_align)368 self.setField('horizontal', self.theme.display_horizontal_align)
367 self.setField('vertical', self.theme.display_vertical_align)369 self.setField('vertical', self.theme.display_vertical_align)
368 self.setField('slide_transition', self.theme.display_slide_transition)370 self.setField('slide_transition', self.theme.display_slide_transition)
371 self.setField('background_transparency', self.theme.display_background_transparency)
372 self.setField('smooth_transparency', self.theme.display_smooth_transparency)
369373
370 def set_preview_page_values(self):374 def set_preview_page_values(self):
371 """375 """
@@ -496,6 +500,8 @@
496 self.theme.display_horizontal_align = self.horizontal_combo_box.currentIndex()500 self.theme.display_horizontal_align = self.horizontal_combo_box.currentIndex()
497 self.theme.display_vertical_align = self.vertical_combo_box.currentIndex()501 self.theme.display_vertical_align = self.vertical_combo_box.currentIndex()
498 self.theme.display_slide_transition = self.field('slide_transition')502 self.theme.display_slide_transition = self.field('slide_transition')
503 self.theme.display_background_transparency = self.field('background_transparency')
504 self.theme.display_smooth_transparency = self.field('smooth_transparency')
499505
500 def accept(self):506 def accept(self):
501 """507 """
502508
=== modified file 'openlp/core/ui/themewizard.py'
--- openlp/core/ui/themewizard.py 2015-01-18 13:39:21 +0000
+++ openlp/core/ui/themewizard.py 2015-02-22 20:49:19 +0000
@@ -261,6 +261,23 @@
261 self.transitions_check_box.setObjectName('transitions_check_box')261 self.transitions_check_box.setObjectName('transitions_check_box')
262 self.alignment_layout.addRow(self.transitions_label, self.transitions_check_box)262 self.alignment_layout.addRow(self.transitions_label, self.transitions_check_box)
263 self.alignment_layout.setItem(3, QtGui.QFormLayout.LabelRole, self.spacer)263 self.alignment_layout.setItem(3, QtGui.QFormLayout.LabelRole, self.spacer)
264 self.transparency_layout = QtGui.QHBoxLayout()
265 self.transparency_layout.setObjectName('transparency_layout')
266 self.background_transparency_label = QtGui.QLabel(self.alignment_page)
267 self.background_transparency_label.setObjectName('background_transparency_label')
268 self.background_transparency_spin_box = QtGui.QSpinBox(self.alignment_page)
269 self.background_transparency_spin_box.setMaximum(100)
270 self.background_transparency_spin_box.setObjectName('background_transparency_spin_box')
271 self.transparency_layout.addWidget(self.background_transparency_spin_box)
272 self.transparency_layout.addSpacing(20)
273 self.smooth_transparency_label = QtGui.QLabel(self.alignment_page)
274 self.smooth_transparency_label.setObjectName('smooth_transparency_label')
275 self.transparency_layout.addWidget(self.smooth_transparency_label)
276 self.transparency_layout.addSpacing(20)
277 self.smooth_transparency_check_box = QtGui.QCheckBox(self.alignment_page)
278 self.smooth_transparency_check_box.setObjectName('smooth_transparency_check_box')
279 self.transparency_layout.addWidget(self.smooth_transparency_check_box)
280 self.alignment_layout.addRow(self.smooth_transparency_label, self.transparency_layout)
264 theme_wizard.addPage(self.alignment_page)281 theme_wizard.addPage(self.alignment_page)
265 # Area Position Page282 # Area Position Page
266 self.area_position_page = QtGui.QWizardPage()283 self.area_position_page = QtGui.QWizardPage()
@@ -458,6 +475,9 @@
458 self.horizontal_combo_box.setItemText(HorizontalType.Center, translate('OpenLP.ThemeWizard', 'Center'))475 self.horizontal_combo_box.setItemText(HorizontalType.Center, translate('OpenLP.ThemeWizard', 'Center'))
459 self.horizontal_combo_box.setItemText(HorizontalType.Justify, translate('OpenLP.ThemeWizard', 'Justify'))476 self.horizontal_combo_box.setItemText(HorizontalType.Justify, translate('OpenLP.ThemeWizard', 'Justify'))
460 self.transitions_label.setText(translate('OpenLP.ThemeWizard', 'Transitions:'))477 self.transitions_label.setText(translate('OpenLP.ThemeWizard', 'Transitions:'))
478 self.background_transparency_label.setText(translate('OpenLP.ThemeWizard', 'Transparency:'))
479 self.background_transparency_spin_box.setSuffix(translate('OpenLP.ThemeWizard', '%'))
480 self.smooth_transparency_label.setText(translate('OpenLP.ThemeWizard', 'Smooth Transition:'))
461 self.area_position_page.setTitle(translate('OpenLP.ThemeWizard', 'Output Area Locations'))481 self.area_position_page.setTitle(translate('OpenLP.ThemeWizard', 'Output Area Locations'))
462 self.area_position_page.setSubTitle(translate('OpenLP.ThemeWizard', 'Allows you to change and move the'482 self.area_position_page.setSubTitle(translate('OpenLP.ThemeWizard', 'Allows you to change and move the'
463 ' Main and Footer areas.'))483 ' Main and Footer areas.'))
464484
=== modified file 'tests/functional/openlp_core_lib/test_htmlbuilder.py'
--- tests/functional/openlp_core_lib/test_htmlbuilder.py 2014-07-24 21:57:16 +0000
+++ tests/functional/openlp_core_lib/test_htmlbuilder.py 2015-02-22 20:49:19 +0000
@@ -169,7 +169,24 @@
169 z-index: 5;169 z-index: 5;
170 position: absolute;170 position: absolute;
171 display: table;171 display: table;
172 left: 10px; top: 20px;172 left: 0px; padding-left: 10px; top: 20px; width: 100%; background: rgba(0,0,0,0.5);
173}
174.lyricscell {
175 display: table-cell;
176 word-wrap: break-word;
177 -webkit-transition: opacity 0.4s ease;
178 lyrics_format_css
179}
180.lyricsmain {
181 text-shadow: #000000 5px 5px;
182}
183"""
184LYRICS_CSS_SMOOTH = """
185.lyricstable {
186 z-index: 5;
187 position: absolute;
188 display: table;
189 left: 0px; padding-left: 10px; top: 20px; width: 100%; background: -webkit-linear-gradient(top, rgba(0,0,0,0) 0%, rgba(0,0,0,0.5) 2%, rgba(0,0,0,0.5) 98%,rgba(0,0,0,0) 100%);
173}190}
174.lyricscell {191.lyricscell {
175 display: table-cell;192 display: table-cell;
@@ -184,7 +201,7 @@
184LYRICS_OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; '201LYRICS_OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; '
185LYRICS_FORMAT_CSS = ' word-wrap: break-word; text-align: justify; vertical-align: bottom; ' + \202LYRICS_FORMAT_CSS = ' word-wrap: break-word; text-align: justify; vertical-align: bottom; ' + \
186 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 108%; margin: 0;padding: 0; ' + \203 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 108%; margin: 0;padding: 0; ' + \
187 'padding-bottom: 0.5em; padding-left: 2px; width: 1580px; height: 810px; font-style:italic; font-weight:bold; '204 'padding-bottom: 0.5em; padding-left: 2px; padding-right: 340px; width: 1580px; height: 810px; font-style:italic; font-weight:bold; '
188FOOTER_CSS_BASE = """205FOOTER_CSS_BASE = """
189 left: 10px;206 left: 10px;
190 bottom: 0px;207 bottom: 0px;
@@ -275,13 +292,40 @@
275 item.theme_data.font_main_shadow = True292 item.theme_data.font_main_shadow = True
276 item.theme_data.font_main_shadow_color = '#000000'293 item.theme_data.font_main_shadow_color = '#000000'
277 item.theme_data.font_main_shadow_size = 5294 item.theme_data.font_main_shadow_size = 5
278295 item.theme_data.display_background_transparency = 50
296 item.theme_data.display_smooth_transparency = 0
297 display_width = 1024
298
279 # WHEN: Create the css.299 # WHEN: Create the css.
280 css = build_lyrics_css(item)300 css = build_lyrics_css(item, display_width)
281301
282 # THEN: The css should be equal.302 # THEN: The css should be equal.
283 self.assertEqual(LYRICS_CSS, css, 'The lyrics css should be equal.')303 self.assertEqual(LYRICS_CSS, css, 'The lyrics css should be equal.')
284304
305 def build_lyrics_css_smooth_transparency_test(self):
306 """
307 Test the build_lyrics_css() function with smooth transparency enabled
308 """
309 # GIVEN: Mocked method and arguments.
310 with patch('openlp.core.lib.htmlbuilder.build_lyrics_format_css') as mocked_build_lyrics_format_css, \
311 patch('openlp.core.lib.htmlbuilder.build_lyrics_outline_css') as mocked_build_lyrics_outline_css:
312 mocked_build_lyrics_format_css.return_value = 'lyrics_format_css'
313 mocked_build_lyrics_outline_css.return_value = ''
314 item = MagicMock()
315 item.main = QtCore.QRect(10, 20, 10, 20)
316 item.theme_data.font_main_shadow = True
317 item.theme_data.font_main_shadow_color = '#000000'
318 item.theme_data.font_main_shadow_size = 5
319 item.theme_data.display_background_transparency = 50
320 item.theme_data.display_smooth_transparency = 1
321 display_width = 1024
322
323 # WHEN: Create the css.
324 css = build_lyrics_css(item, display_width)
325
326 # THEN: The css should be equal.
327 self.assertEqual(LYRICS_CSS_SMOOTH, css, 'The lyrics css should be equal.')
328
285 def build_lyrics_outline_css_test(self):329 def build_lyrics_outline_css_test(self):
286 """330 """
287 Test the build_lyrics_outline_css() function331 Test the build_lyrics_outline_css() function
@@ -315,9 +359,11 @@
315 theme_data.font_main_line_adjustment = 8359 theme_data.font_main_line_adjustment = 8
316 width = 1580360 width = 1580
317 height = 810361 height = 810
362 display_width = 1920
363
318364
319 # WHEN: Get the css.365 # WHEN: Get the css.
320 css = build_lyrics_format_css(theme_data, width, height)366 css = build_lyrics_format_css(theme_data, width, height, display_width)
321367
322 # THEN: They should be equal.368 # THEN: They should be equal.
323 self.assertEqual(LYRICS_FORMAT_CSS, css, 'The lyrics format css should be equal.')369 self.assertEqual(LYRICS_FORMAT_CSS, css, 'The lyrics format css should be equal.')
324370
=== modified file 'tests/functional/openlp_core_lib/test_theme.py'
--- tests/functional/openlp_core_lib/test_theme.py 2015-01-18 13:39:21 +0000
+++ tests/functional/openlp_core_lib/test_theme.py 2015-02-22 20:49:19 +0000
@@ -61,4 +61,4 @@
61 self.assertTrue(default_theme.font_footer_name == "Arial",61 self.assertTrue(default_theme.font_footer_name == "Arial",
62 'The theme should have a font_footer_name of Arial')62 'The theme should have a font_footer_name of Arial')
63 self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false')63 self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false')
64 self.assertTrue(len(default_theme.__dict__) == 47, 'The theme should have 47 variables')64 self.assertTrue(len(default_theme.__dict__) == 49, 'The theme should have 49 variables')