Permalink
Browse files

All any text widgets to use templates, not just the one whose name ar…

…e defined in the map

This allows to use more creatively the widget dependencies, without being bound to specified object names
  • Loading branch information...
jyavenard committed Jul 9, 2013
1 parent 1745a01 commit 8e614f1c895f728e770b2b1a5875a8f5f0c6e9cf
Showing with 32 additions and 37 deletions.
  1. +1 −2 mythtv/libs/libmythui/mythscreentype.cpp
  2. +31 −35 mythtv/libs/libmythui/mythuitext.cpp
@@ -441,10 +441,9 @@ static void DoSetTextFromMap(MythUIType *UItype, QHash<QString, QString> &infoMa
MythUIType *type = i.next();
textType = dynamic_cast<MythUIText *> (type);
if (textType && infoMap.contains(textType->objectName()))
if (textType)
textType->SetTextFromMap(infoMap);
MythUIGroup *group = dynamic_cast<MythUIGroup *> (type);
if (group)
DoSetTextFromMap(type, infoMap);
@@ -151,51 +151,47 @@ void MythUIText::SetText(const QString &text)
void MythUIText::SetTextFromMap(QHash<QString, QString> &map)
{
if (map.contains(objectName()))
{
QString newText = GetTemplateText();
QString newText = GetTemplateText();
if (newText.isEmpty())
newText = GetDefaultText();
if (newText.isEmpty())
newText = GetDefaultText();
QRegExp regexp("%(([^\\|%]+)?\\||\\|(.))?(\\w+)(\\|(.+))?%");
regexp.setMinimal(true);
QRegExp regexp("%(([^\\|%]+)?\\||\\|(.))?(\\w+)(\\|(.+))?%");
regexp.setMinimal(true);
if (!newText.isEmpty() && newText.contains(regexp))
{
int pos = 0;
if (!newText.isEmpty() && newText.contains(regexp))
{
int pos = 0;
QString translatedTemplate = qApp->translate("ThemeUI",
newText.toUtf8(),
NULL,
QCoreApplication::UnicodeUTF8);
QString translatedTemplate = qApp->translate("ThemeUI",
newText.toUtf8(),
NULL,
QCoreApplication::UnicodeUTF8);
QString tempString = translatedTemplate;
QString tempString = translatedTemplate;
while ((pos = regexp.indexIn(translatedTemplate, pos)) != -1)
{
QString key = regexp.cap(4).toLower().trimmed();
QString replacement;
if (!map.value(key).isEmpty())
{
replacement = QString("%1%2%3%4")
.arg(regexp.cap(2))
.arg(regexp.cap(3))
.arg(map.value(key))
.arg(regexp.cap(6));
}
while ((pos = regexp.indexIn(translatedTemplate, pos)) != -1)
{
QString key = regexp.cap(4).toLower().trimmed();
QString replacement;
tempString.replace(regexp.cap(0), replacement);
pos += regexp.matchedLength();
if (!map.value(key).isEmpty())
{
replacement = QString("%1%2%3%4")
.arg(regexp.cap(2))
.arg(regexp.cap(3))
.arg(map.value(key))
.arg(regexp.cap(6));
}
newText = tempString;
tempString.replace(regexp.cap(0), replacement);
pos += regexp.matchedLength();
}
else
newText = map.value(objectName());
SetText(newText);
SetText(tempString);
}
else if (map.contains(objectName()))
{
SetText(map.value(objectName()));
}
}

0 comments on commit 8e614f1

Please sign in to comment.