From 530f11993871f7c1ca81140bd43da796fab32802 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Thu, 21 Jul 2016 22:37:25 +0200 Subject: [PATCH] Various improvements for chords on the mainview. --- openlp/core/lib/__init__.py | 19 +++++-- openlp/core/lib/htmlbuilder.py | 64 +++++++++++++--------- openlp/core/lib/renderer.py | 6 +- openlp/core/lib/serviceitem.py | 2 +- openlp/plugins/remotes/html/css/chords.css | 10 +++- openlp/plugins/remotes/html/js/chords.js | 6 +- 6 files changed, 65 insertions(+), 42 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 7d4bcb762..90d139673 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -282,12 +282,12 @@ def check_item_selected(list_widget, message): return True -def clean_tags(text, chords=False): +def clean_tags(text, remove_chords=False): """ Remove Tags from text for display :param text: Text to be cleaned - :param chords: Clean ChordPro tags + :param remove_chords: Clean ChordPro tags """ text = text.replace('
', '\n') text = text.replace('{br}', '\n') @@ -296,7 +296,7 @@ def clean_tags(text, chords=False): text = text.replace(tag['start tag'], '') text = text.replace(tag['end tag'], '') # Remove ChordPro tags - if chords: + if remove_chords: text = re.sub(r'\[.+?\]', r'', text) return text @@ -322,14 +322,21 @@ def expand_chords(text): """ text_lines = text.split('{br}') expanded_text_lines = [] + chords_on_last_line = False for line in text_lines: # If a ChordPro is detected in the line, replace it with a html-span tag and wrap the line in a span tag. if '[' in line and ']' in line: - new_line = '' - new_line += re.sub(r'(.*?)\[(.+?)\](.*?)', r'\1\2\3', line) + if chords_on_last_line: + new_line = '' + else: + new_line = '' + chords_on_last_line = True + new_line += re.sub(r'(.*?)\[(.+?)\](.*?)', + r'\1\2\3', line) new_line += '' expanded_text_lines.append(new_line) else: + chords_on_last_line = False expanded_text_lines.append(line) return '{br}'.join(expanded_text_lines) @@ -371,7 +378,7 @@ from .plugin import PluginStatus, StringContent, Plugin from .pluginmanager import PluginManager from .settingstab import SettingsTab from .serviceitem import ServiceItem, ServiceItemType, ItemCapabilities -from .htmlbuilder import build_html, build_lyrics_format_css, build_lyrics_outline_css +from .htmlbuilder import build_html, build_lyrics_format_css, build_lyrics_outline_css, build_chords_css from .imagemanager import ImageManager from .renderer import Renderer from .mediamanageritem import MediaManagerItem diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index bdcc0ed32..dd5f6c3f0 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -444,32 +444,8 @@ HTML_SRC = Template(""" position: relative; top: -0.3em; } - #chords { - /*font-size: 20pt; - color: gray; - background-color: gray; - color: white; - cursor: pointer;*/ - } - .chordline { - line-height: 2.0; - } - .chordline1 { - line-height: 1.0 - } - .chordline span.chord span { - position: relative; - } - .chordline span.chord span strong { - position: absolute; - top: -1em; - left: 0; - font-size: 75%; - font-weight: normal; - line-height: normal; - /*font: 30pt sans-serif; - color: yellow;*/ - } + /* Chords css */${chords_css} + + #main {position: absolute; top: 0px; %s %s} %s
""" % \ (build_lyrics_format_css(theme_data, self.page_width, self.page_height), - build_lyrics_outline_css(theme_data)) + build_lyrics_outline_css(theme_data), build_chords_css()) self.web.setHtml(html) self.empty_height = self.web_frame.contentsSize().height() diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 4248f2494..c272fcf62 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -263,7 +263,7 @@ class ServiceItem(RegistryProperties): new_frame = { 'title': clean_tags(page), 'text': clean_tags(page.rstrip(), True), - 'chords_text': expand_chords(clean_tags(page.rstrip(), False)), + 'chords_text': clean_tags(expand_chords(page.rstrip()), False), 'html': html_data.replace('&nbsp;', ' '), 'verseTag': verse_tag, } diff --git a/openlp/plugins/remotes/html/css/chords.css b/openlp/plugins/remotes/html/css/chords.css index 3f20649a7..8c15b4637 100644 --- a/openlp/plugins/remotes/html/css/chords.css +++ b/openlp/plugins/remotes/html/css/chords.css @@ -68,15 +68,21 @@ line-height: 1.0 } +.firstchordline { + line-height: 2.1em; +} + .chordline span.chord span { position: relative; } .chordline span.chord span strong { position: absolute; - top: -1em; + top: -0.8em; left: 0; - font: 30pt sans-serif; + font-size: 30pt; + font-weight: normal; + line-height: normal; color: yellow; } diff --git a/openlp/plugins/remotes/html/js/chords.js b/openlp/plugins/remotes/html/js/chords.js index fc786d78d..ac62fe253 100644 --- a/openlp/plugins/remotes/html/js/chords.js +++ b/openlp/plugins/remotes/html/js/chords.js @@ -177,8 +177,8 @@ window.OpenLP = { // Then leave a blank line between following verses var transposeValue = getTransposeValue(OpenLP.currentSlides[0].text.split("\n")[0]); var chordclass=/class="[a-z\s]*chord[a-z\s]*"\s*style="display:\s?none"/g; - var chordclassshow='class="chord" style="display:inline"'; - var regchord=/([\(\w#b♭\+\*\d/\)-]+)<\/strong><\/span><\/span>([\u0080-\uFFFF,\w]*)([\u0080-\uFFFF,\w,\s,\.,\,,\!,\?,\;,\:,\|,\",\',\-,\_]*)(
)?/g; + var chordclassshow='class="chord"'; + var regchord=/([\(\w#b♭\+\*\d/\)-]+)<\/strong><\/span><\/span>([\u0080-\uFFFF,\w]*)([\u0080-\uFFFF,\w,\s,\.,\,,\!,\?,\;,\:,\|,\",\',\-,\_]*)(
)?/g; var replaceChords=function(mstr,$1,$2,$3,$4) { var v='', w=''; var $1len = 0, $2len = 0, slimchars='fiíIÍjlĺľrtť.,;/ ()|"\'!:\\'; @@ -203,7 +203,7 @@ window.OpenLP = { } else { if (!$2 && $3.charAt(0) == ' ') {for (c = 0; c < $1len; c++) {w += ' ';}} } - return $.grep(['', $1, '', $2, w, $3, '', $4], Boolean).join(''); + return $.grep(['', $1, '', $2, w, $3, '', $4], Boolean).join(''); }; $("#verseorder span").removeClass("currenttag"); $("#tag" + OpenLP.currentTags[OpenLP.currentSlide]).addClass("currenttag");