Skip to content

Commit

Permalink
All any text widgets to use templates, not just the one whose name ar…
Browse files Browse the repository at this point in the history
…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 8e614f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 37 deletions.
3 changes: 1 addition & 2 deletions mythtv/libs/libmythui/mythscreentype.cpp
Expand Up @@ -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);
Expand Down
66 changes: 31 additions & 35 deletions mythtv/libs/libmythui/mythuitext.cpp
Expand Up @@ -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()));
}
}

Expand Down

0 comments on commit 8e614f1

Please sign in to comment.