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
1=== modified file 'openlp/core/lib/htmlbuilder.py'
2--- openlp/core/lib/htmlbuilder.py 2015-01-18 13:39:21 +0000
3+++ openlp/core/lib/htmlbuilder.py 2015-02-22 20:49:19 +0000
4@@ -585,7 +585,7 @@
5 build_background_css(item, width),
6 css_additions,
7 build_footer_css(item, height),
8- build_lyrics_css(item),
9+ build_lyrics_css(item, width),
10 'true' if theme_data and theme_data.display_slide_transition and is_live else 'false',
11 js_additions,
12 bgimage_src,
13@@ -641,7 +641,7 @@
14 return background
15
16
17-def build_lyrics_css(item):
18+def build_lyrics_css(item, display_width):
19 """
20 Build the lyrics display css
21
22@@ -669,8 +669,16 @@
23 lyrics = ''
24 lyricsmain = ''
25 if theme_data and item.main:
26- lyricstable = 'left: %spx; top: %spx;' % (item.main.x(), item.main.y())
27- lyrics = build_lyrics_format_css(theme_data, item.main.width(), item.main.height())
28+ lyricstable = 'left: 0px; padding-left: %spx; top: %spx; width: 100%%; ' % (item.main.x(), item.main.y())
29+ transparency = 1 - (float(theme_data.display_background_transparency) / 100)
30+ if theme_data.display_smooth_transparency:
31+ 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%%);'\
32+ % (transparency, transparency)
33+ else:
34+ lyricstable += 'background: rgba(0,0,0,%s);' % (transparency)
35+
36+
37+ lyrics = build_lyrics_format_css(theme_data, item.main.width(), item.main.height(), display_width)
38 lyricsmain += build_lyrics_outline_css(theme_data)
39 if theme_data.font_main_shadow:
40 lyricsmain += ' text-shadow: %s %spx %spx;' % \
41@@ -693,7 +701,7 @@
42 return ''
43
44
45-def build_lyrics_format_css(theme_data, width, height):
46+def build_lyrics_format_css(theme_data, width, height, display_width):
47 """
48 Build the css which controls the theme format. Also used by renderer for splitting verses
49
50@@ -715,13 +723,16 @@
51 padding_bottom = '0.5em'
52 else:
53 padding_bottom = '0'
54+
55+ padding_right = display_width - width;
56+
57 lyrics = '%s word-wrap: break-word; ' \
58 'text-align: %s; vertical-align: %s; font-family: %s; ' \
59 'font-size: %spt; color: %s; line-height: %d%%; margin: 0;' \
60- 'padding: 0; padding-bottom: %s; padding-left: %spx; width: %spx; height: %spx; ' % \
61+ 'padding: 0; padding-bottom: %s; padding-left: %spx; padding-right: %spx; width: %spx; height: %spx; ' % \
62 (justify, align, valign, theme_data.font_main_name, theme_data.font_main_size,
63 theme_data.font_main_color, 100 + int(theme_data.font_main_line_adjustment), padding_bottom,
64- left_margin, width, height)
65+ left_margin, padding_right, width, height)
66 if theme_data.font_main_italics:
67 lyrics += 'font-style:italic; '
68 if theme_data.font_main_bold:
69
70=== modified file 'openlp/core/lib/json/theme.json'
71--- openlp/core/lib/json/theme.json 2013-10-18 18:10:47 +0000
72+++ openlp/core/lib/json/theme.json 2015-02-22 20:49:19 +0000
73@@ -11,7 +11,9 @@
74 "display" :{
75 "horizontal_align": 0,
76 "slide_transition": false,
77- "vertical_align": 0
78+ "vertical_align": 0,
79+ "background_transparency": 100,
80+ "smooth_transparency": 0
81 },
82 "font": {
83 "footer": {
84
85=== modified file 'openlp/core/lib/renderer.py'
86--- openlp/core/lib/renderer.py 2015-01-18 13:39:21 +0000
87+++ openlp/core/lib/renderer.py 2015-02-22 20:49:19 +0000
88@@ -381,7 +381,7 @@
89 </script><style>*{margin: 0; padding: 0; border: 0;}
90 #main {position: absolute; top: 0px; %s %s}</style></head><body>
91 <div id="main"></div></body></html>""" % \
92- (build_lyrics_format_css(theme_data, self.page_width, self.page_height),
93+ (build_lyrics_format_css(theme_data, self.page_width, self.page_height, self.display.width()),
94 build_lyrics_outline_css(theme_data))
95 self.web.setHtml(html)
96 self.empty_height = self.web_frame.contentsSize().height()
97
98=== modified file 'openlp/core/lib/theme.py'
99--- openlp/core/lib/theme.py 2015-01-18 13:39:21 +0000
100+++ openlp/core/lib/theme.py 2015-02-22 20:49:19 +0000
101@@ -318,7 +318,7 @@
102 element.appendChild(value)
103 background.appendChild(element)
104
105- def add_display(self, horizontal, vertical, transition):
106+ def add_display(self, horizontal, vertical, transition, background_transparency, smooth_transparency):
107 """
108 Add a Display options.
109
110@@ -343,6 +343,16 @@
111 value = self.theme_xml.createTextNode(str(transition))
112 element.appendChild(value)
113 background.appendChild(element)
114+ # Background Transparency
115+ element = self.theme_xml.createElement('backgroundTransparency')
116+ value = self.theme_xml.createTextNode(str(background_transparency))
117+ element.appendChild(value)
118+ background.appendChild(element)
119+ # Smooth Transparency
120+ element = self.theme_xml.createElement('smoothTransparency')
121+ value = self.theme_xml.createTextNode(str(smooth_transparency))
122+ element.appendChild(value)
123+ background.appendChild(element)
124
125 def child_element(self, element, tag, value):
126 """
127@@ -555,5 +565,7 @@
128 self.add_display(
129 self.display_horizontal_align,
130 self.display_vertical_align,
131- self.display_slide_transition
132+ self.display_slide_transition,
133+ self.display_background_transparency,
134+ self.display_smooth_transparency
135 )
136
137=== modified file 'openlp/core/ui/themeform.py'
138--- openlp/core/ui/themeform.py 2015-01-18 13:39:21 +0000
139+++ openlp/core/ui/themeform.py 2015-02-22 20:49:19 +0000
140@@ -134,6 +134,8 @@
141 self.background_page.registerField('horizontal', self.horizontal_combo_box)
142 self.background_page.registerField('vertical', self.vertical_combo_box)
143 self.background_page.registerField('slide_transition', self.transitions_check_box)
144+ self.background_page.registerField('background_transparency', self.background_transparency_spin_box)
145+ self.background_page.registerField('smooth_transparency', self.smooth_transparency_check_box)
146 self.background_page.registerField('name', self.theme_name_edit)
147
148 def calculate_lines(self):
149@@ -366,6 +368,8 @@
150 self.setField('horizontal', self.theme.display_horizontal_align)
151 self.setField('vertical', self.theme.display_vertical_align)
152 self.setField('slide_transition', self.theme.display_slide_transition)
153+ self.setField('background_transparency', self.theme.display_background_transparency)
154+ self.setField('smooth_transparency', self.theme.display_smooth_transparency)
155
156 def set_preview_page_values(self):
157 """
158@@ -496,6 +500,8 @@
159 self.theme.display_horizontal_align = self.horizontal_combo_box.currentIndex()
160 self.theme.display_vertical_align = self.vertical_combo_box.currentIndex()
161 self.theme.display_slide_transition = self.field('slide_transition')
162+ self.theme.display_background_transparency = self.field('background_transparency')
163+ self.theme.display_smooth_transparency = self.field('smooth_transparency')
164
165 def accept(self):
166 """
167
168=== modified file 'openlp/core/ui/themewizard.py'
169--- openlp/core/ui/themewizard.py 2015-01-18 13:39:21 +0000
170+++ openlp/core/ui/themewizard.py 2015-02-22 20:49:19 +0000
171@@ -261,6 +261,23 @@
172 self.transitions_check_box.setObjectName('transitions_check_box')
173 self.alignment_layout.addRow(self.transitions_label, self.transitions_check_box)
174 self.alignment_layout.setItem(3, QtGui.QFormLayout.LabelRole, self.spacer)
175+ self.transparency_layout = QtGui.QHBoxLayout()
176+ self.transparency_layout.setObjectName('transparency_layout')
177+ self.background_transparency_label = QtGui.QLabel(self.alignment_page)
178+ self.background_transparency_label.setObjectName('background_transparency_label')
179+ self.background_transparency_spin_box = QtGui.QSpinBox(self.alignment_page)
180+ self.background_transparency_spin_box.setMaximum(100)
181+ self.background_transparency_spin_box.setObjectName('background_transparency_spin_box')
182+ self.transparency_layout.addWidget(self.background_transparency_spin_box)
183+ self.transparency_layout.addSpacing(20)
184+ self.smooth_transparency_label = QtGui.QLabel(self.alignment_page)
185+ self.smooth_transparency_label.setObjectName('smooth_transparency_label')
186+ self.transparency_layout.addWidget(self.smooth_transparency_label)
187+ self.transparency_layout.addSpacing(20)
188+ self.smooth_transparency_check_box = QtGui.QCheckBox(self.alignment_page)
189+ self.smooth_transparency_check_box.setObjectName('smooth_transparency_check_box')
190+ self.transparency_layout.addWidget(self.smooth_transparency_check_box)
191+ self.alignment_layout.addRow(self.smooth_transparency_label, self.transparency_layout)
192 theme_wizard.addPage(self.alignment_page)
193 # Area Position Page
194 self.area_position_page = QtGui.QWizardPage()
195@@ -458,6 +475,9 @@
196 self.horizontal_combo_box.setItemText(HorizontalType.Center, translate('OpenLP.ThemeWizard', 'Center'))
197 self.horizontal_combo_box.setItemText(HorizontalType.Justify, translate('OpenLP.ThemeWizard', 'Justify'))
198 self.transitions_label.setText(translate('OpenLP.ThemeWizard', 'Transitions:'))
199+ self.background_transparency_label.setText(translate('OpenLP.ThemeWizard', 'Transparency:'))
200+ self.background_transparency_spin_box.setSuffix(translate('OpenLP.ThemeWizard', '%'))
201+ self.smooth_transparency_label.setText(translate('OpenLP.ThemeWizard', 'Smooth Transition:'))
202 self.area_position_page.setTitle(translate('OpenLP.ThemeWizard', 'Output Area Locations'))
203 self.area_position_page.setSubTitle(translate('OpenLP.ThemeWizard', 'Allows you to change and move the'
204 ' Main and Footer areas.'))
205
206=== modified file 'tests/functional/openlp_core_lib/test_htmlbuilder.py'
207--- tests/functional/openlp_core_lib/test_htmlbuilder.py 2014-07-24 21:57:16 +0000
208+++ tests/functional/openlp_core_lib/test_htmlbuilder.py 2015-02-22 20:49:19 +0000
209@@ -169,7 +169,24 @@
210 z-index: 5;
211 position: absolute;
212 display: table;
213- left: 10px; top: 20px;
214+ left: 0px; padding-left: 10px; top: 20px; width: 100%; background: rgba(0,0,0,0.5);
215+}
216+.lyricscell {
217+ display: table-cell;
218+ word-wrap: break-word;
219+ -webkit-transition: opacity 0.4s ease;
220+ lyrics_format_css
221+}
222+.lyricsmain {
223+ text-shadow: #000000 5px 5px;
224+}
225+"""
226+LYRICS_CSS_SMOOTH = """
227+.lyricstable {
228+ z-index: 5;
229+ position: absolute;
230+ display: table;
231+ 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%);
232 }
233 .lyricscell {
234 display: table-cell;
235@@ -184,7 +201,7 @@
236 LYRICS_OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; '
237 LYRICS_FORMAT_CSS = ' word-wrap: break-word; text-align: justify; vertical-align: bottom; ' + \
238 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 108%; margin: 0;padding: 0; ' + \
239- 'padding-bottom: 0.5em; padding-left: 2px; width: 1580px; height: 810px; font-style:italic; font-weight:bold; '
240+ 'padding-bottom: 0.5em; padding-left: 2px; padding-right: 340px; width: 1580px; height: 810px; font-style:italic; font-weight:bold; '
241 FOOTER_CSS_BASE = """
242 left: 10px;
243 bottom: 0px;
244@@ -275,13 +292,40 @@
245 item.theme_data.font_main_shadow = True
246 item.theme_data.font_main_shadow_color = '#000000'
247 item.theme_data.font_main_shadow_size = 5
248-
249+ item.theme_data.display_background_transparency = 50
250+ item.theme_data.display_smooth_transparency = 0
251+ display_width = 1024
252+
253 # WHEN: Create the css.
254- css = build_lyrics_css(item)
255+ css = build_lyrics_css(item, display_width)
256
257 # THEN: The css should be equal.
258 self.assertEqual(LYRICS_CSS, css, 'The lyrics css should be equal.')
259
260+ def build_lyrics_css_smooth_transparency_test(self):
261+ """
262+ Test the build_lyrics_css() function with smooth transparency enabled
263+ """
264+ # GIVEN: Mocked method and arguments.
265+ with patch('openlp.core.lib.htmlbuilder.build_lyrics_format_css') as mocked_build_lyrics_format_css, \
266+ patch('openlp.core.lib.htmlbuilder.build_lyrics_outline_css') as mocked_build_lyrics_outline_css:
267+ mocked_build_lyrics_format_css.return_value = 'lyrics_format_css'
268+ mocked_build_lyrics_outline_css.return_value = ''
269+ item = MagicMock()
270+ item.main = QtCore.QRect(10, 20, 10, 20)
271+ item.theme_data.font_main_shadow = True
272+ item.theme_data.font_main_shadow_color = '#000000'
273+ item.theme_data.font_main_shadow_size = 5
274+ item.theme_data.display_background_transparency = 50
275+ item.theme_data.display_smooth_transparency = 1
276+ display_width = 1024
277+
278+ # WHEN: Create the css.
279+ css = build_lyrics_css(item, display_width)
280+
281+ # THEN: The css should be equal.
282+ self.assertEqual(LYRICS_CSS_SMOOTH, css, 'The lyrics css should be equal.')
283+
284 def build_lyrics_outline_css_test(self):
285 """
286 Test the build_lyrics_outline_css() function
287@@ -315,9 +359,11 @@
288 theme_data.font_main_line_adjustment = 8
289 width = 1580
290 height = 810
291+ display_width = 1920
292+
293
294 # WHEN: Get the css.
295- css = build_lyrics_format_css(theme_data, width, height)
296+ css = build_lyrics_format_css(theme_data, width, height, display_width)
297
298 # THEN: They should be equal.
299 self.assertEqual(LYRICS_FORMAT_CSS, css, 'The lyrics format css should be equal.')
300
301=== modified file 'tests/functional/openlp_core_lib/test_theme.py'
302--- tests/functional/openlp_core_lib/test_theme.py 2015-01-18 13:39:21 +0000
303+++ tests/functional/openlp_core_lib/test_theme.py 2015-02-22 20:49:19 +0000
304@@ -61,4 +61,4 @@
305 self.assertTrue(default_theme.font_footer_name == "Arial",
306 'The theme should have a font_footer_name of Arial')
307 self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false')
308- self.assertTrue(len(default_theme.__dict__) == 47, 'The theme should have 47 variables')
309+ self.assertTrue(len(default_theme.__dict__) == 49, 'The theme should have 49 variables')