Пример #1
0
void MythUIText::SetTextFromMap(QHash<QString, QString> &map)
{
    if (!IsVisible())
        return;

    if (map.contains(objectName()))
    {
        QString newText = GetTemplateText();

        if (newText.isEmpty())
            newText = GetDefaultText();

        QRegExp regexp("%(([^\\|%]+)?\\||\\|(.))?(\\w+)(\\|(.+))?%");
        regexp.setMinimal(true);

        if (!newText.isEmpty() && newText.contains(regexp))
        {
            int pos = 0;

            QString translatedTemplate = qApp->translate("ThemeUI",
                                         newText.toUtf8(),
                                         NULL,
                                         QCoreApplication::UnicodeUTF8);

            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));
                }

                tempString.replace(regexp.cap(0), replacement);
                pos += regexp.matchedLength();
            }

            newText = tempString;
        }
        else
            newText = map.value(objectName());

        SetText(newText);
    }
}
Пример #2
0
void MythUIText::SetTextFromMap(const InfoMap &map)
{
    QString newText = GetTemplateText();

    if (newText.isEmpty())
        newText = GetDefaultText();

    QRegExp regexp("%(([^\\|%]+)?\\||\\|(.))?([\\w#]+)(\\|(.+))?%");
    regexp.setMinimal(true);

    if (!newText.isEmpty() && newText.contains(regexp))
    {
        int pos = 0;

        QString translatedTemplate = qApp->translate("ThemeUI",
                                                     newText.toUtf8());

        QString tempString = translatedTemplate;
        bool replaced = map.contains(objectName());

        while ((pos = regexp.indexIn(translatedTemplate, pos)) != -1)
        {
            QString key = regexp.cap(4).toLower().trimmed();
            QString replacement;

            if (map.contains(key))
            {
                replaced = true;
            }
            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));
            }

            tempString.replace(regexp.cap(0), replacement);
            pos += regexp.matchedLength();
        }
        if (replaced)
        {
            SetText(tempString);
        }
    }
    else if (map.contains(objectName()))
    {
        SetText(map.value(objectName()));
    }
}
Пример #3
0
void MythUIText::ResetMap(const InfoMap &map)
{
    QString newText = GetTemplateText();

    if (newText.isEmpty())
        newText = GetDefaultText();

    QRegExp regexp("%(([^\\|%]+)?\\||\\|(.))?([\\w#]+)(\\|(.+))?%");
    regexp.setMinimal(true);

    bool replaced = map.contains(objectName());

    if (!replaced && !newText.isEmpty() && newText.contains(regexp))
    {
        int pos = 0;

        QString translatedTemplate = qApp->translate("ThemeUI",
                                                     newText.toUtf8());

        while ((pos = regexp.indexIn(translatedTemplate, pos)) != -1)
        {
            QString key = regexp.cap(4).toLower().trimmed();

            if (map.contains(key))
            {
                replaced = true;
                break;
            }
            pos += regexp.matchedLength();
        }
    }

    if (replaced)
    {
        Reset();
    }
}