void AbstractNavigationContext::addHtml(QString html) { QRegExp newLineRegExp("<br>|<br */>"); foreach(const QString& line, splitAndKeep(html, newLineRegExp)) { m_currentText += line; if(line.indexOf(newLineRegExp) != -1) { ++m_currentLine; if(m_currentLine == m_currentPositionLine) { m_currentText += "<font color=\"#880088\"> <a name = \"currentPosition\" >" + Qt::escape("<->") + "</a> </font>"; } } }
TikzCommandList TikzCommandInserter::getChildCommands() { TikzCommandList commandList; QList<TikzCommand> commands; commandList.title = tr(xml.attributes().value("title").toString().toLatin1().data()); QString name; QString description; QString insertion; QString highlightString; QString type; QRegExp newLineRegExp("([^\\\\])\\\\n"); // newlines are the "\n" not preceded by a backslash as in "\\node" QRegExp descriptionRegExp("<([^<>]*)>"); // descriptions are between < and > while (xml.readNextStartElement()) { if (xml.name() == "item") { name = tr(xml.attributes().value("name").toString().toLatin1().data()); description = xml.attributes().value("description").toString(); insertion = xml.attributes().value("insert").toString(); highlightString = xml.attributes().value("highlight").toString(); type = xml.attributes().value("type").toString(); if (description.contains(QLatin1String("\\n"))) // minimize the number of uses of QRegExp { description.replace(newLineRegExp, QLatin1String("\\1\n")); // replace newlines, these are the "\n" not preceded by a backslash as in "\\node" description.replace(newLineRegExp, QLatin1String("\\1\n")); // do this twice to replace all newlines } description.replace(QLatin1String("\\\\"), QLatin1String("\\")); // translate options in the description: QString tempDescription; for (int pos = 0, oldPos = 0; pos >= 0;) { oldPos = pos; pos = descriptionRegExp.indexIn(description, pos); tempDescription += description.midRef(oldPos, pos - oldPos + 1); if (pos >= 0) { tempDescription += tr(descriptionRegExp.cap(1).toLatin1().data()); pos += descriptionRegExp.matchedLength() - 1; } } if (!tempDescription.isEmpty()) description = tempDescription; if (insertion.contains(QLatin1String("\\n"))) // minimize the number of uses of QRegExp { insertion.replace(newLineRegExp, QLatin1String("\\1\n")); // replace newlines, these are the "\n" not preceded by a backslash as in "\\node" insertion.replace(newLineRegExp, QLatin1String("\\1\n")); // do this twice to replace all newlines } insertion.replace(QLatin1String("\\\\"), QLatin1String("\\")); if (name.isEmpty()) { name = description; description.remove('&'); // we assume that if name.isEmpty() then an accelerator is defined in description if (name.isEmpty()) name = insertion; } if (description.isEmpty()) description = insertion; if (type.isEmpty()) type = '0'; commands << newCommand(name, description, insertion, highlightString, xml.attributes().value("dx").toString().toInt(), xml.attributes().value("dy").toString().toInt(), type.toInt()); xml.skipCurrentElement(); // allow to read the next start element on the same level: this skips reading the current end element which would cause xml.readNextStartElement() to evaluate to false } else if (xml.name() == "separator") { commands << newCommand("", "", "", "", 0, 0, 0); xml.skipCurrentElement(); // same as above } else if (xml.name() == "section") { commands << newCommand("", "", "", "", 0, 0, -1); // the i-th command with type == -1 corresponds to the i-th submenu (assumed in getMenu()) commandList.children << getChildCommands(); } else xml.skipCurrentElement(); } commandList.commands = commands; return commandList; }