本文整理汇总了C++中QWebElement::toInnerXml方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebElement::toInnerXml方法的具体用法?C++ QWebElement::toInnerXml怎么用?C++ QWebElement::toInnerXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebElement
的用法示例。
在下文中一共展示了QWebElement::toInnerXml方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attachStyles
void MainWindow::attachStyles()
{
if (!mainSettings->contains("attach/styles")) {
return;
}
QStringList styles = mainSettings->value("attach/styles").toStringList();
if (!styles.length()) {
return;
}
QWebElement headElem = view->page()->mainFrame()->findFirstElement("head");
QString content = "";
if (headElem.isNull() || headElem.toInnerXml().trimmed().isEmpty()) {
// Page without head... We need something in <head> to interact with?
return;
}
QStringListIterator stylesIterator(styles);
QString file_name;
QFileInfo finfo = QFileInfo();
quint32 countStyles = 0;
while (stylesIterator.hasNext()) {
file_name = stylesIterator.next();
if (!file_name.trimmed().length()) continue;
qDebug() << "-- attach " << file_name;
countStyles++;
finfo.setFile(file_name);
if (finfo.isFile()) {
qDebug("-- it's local file");
QFile f(file_name);
content += "\n<style type=\"text/css\">\n";
content += QString(f.readAll());
content += "</style>\n";
f.close();
} else {
qDebug("-- it's remote file");
content += "\n<link type=\"text/css\" rel=\"stylesheet\" href=\"";
content += file_name;
content += "\"/>\n";
}
}
if (countStyles > 0 && content.trimmed().length() > 0) {
headElem.setInnerXml(headElem.toInnerXml() + content);
qDebug() << "Page loaded, found " << countStyles << " user style files...";
}
}
示例2: attachJavascripts
void MainWindow::attachJavascripts()
{
if (!mainSettings->contains("attach/javascripts")) {
return;
}
QStringList scripts = mainSettings->value("attach/javascripts").toStringList();
if (!scripts.length()) {
return;
}
QWebElement bodyElem = view->page()->mainFrame()->findFirstElement("body");
QString content = "";
if (bodyElem.isNull() || bodyElem.toInnerXml().trimmed().isEmpty()) {
// No body here... We need something in <body> to interact with?
return;
}
QStringListIterator scriptsIterator(scripts);
QFileInfo finfo = QFileInfo();
QString file_name;
quint32 countScripts = 0;
while (scriptsIterator.hasNext()) {
file_name = scriptsIterator.next();
if (!file_name.trimmed().length()) continue;
qDebug() << "-- attach " << file_name;
countScripts++;
finfo.setFile(file_name);
if (finfo.isFile()) {
qDebug("-- it's local file");
QFile f(file_name);
content += "\n<script type=\"text/javascript\">";
content += QString(f.readAll());
content += "</script>\n";
f.close();
} else {
qDebug("-- it's remote file");
content += "\n<script type=\"text/javascript\" src=\"";
content += file_name;
content += "\"></script>\n";
}
}
if (countScripts > 0 && content.trimmed().length() > 0) {
bodyElem.setInnerXml(bodyElem.toInnerXml() + content);
qDebug() << "Page loaded, found " << countScripts << " user javascript files...";
}
}
示例3: finished_loading
void MainWindow::finished_loading(bool ok)
{
if(!ok)
std::cout << "LOAD FINISH NOT OK!\n\n";
QString output;
QWebElement body;
progress = 100;
adjust_title();
QWebFrame *frame = uimw->webView->page()->mainFrame();
QWebElement document = frame->documentElement();
QWebElement element = document.firstChild();
while(!element.isNull())
{
if(element.tagName() == "BODY")
{
output = element.toInnerXml();
if(output == "ok\n")
{
QNetworkCookieJar *cj = uimw->webView->page()->networkAccessManager()->cookieJar();
QList<QNetworkCookie> cookies = cj->cookiesForUrl(testauth);
for(QList<QNetworkCookie>::const_iterator i = cookies.begin() ; i != cookies.end() ; i++ )
{
std::cout << "Set-Cookie: ";
QByteArray ba = i->toRawForm();
std::cout.write(ba.data(), ba.count());
std::cout << "\r\n";
}
exit(0);
}
}
element = element.nextSibling();
}
this->show();
}
示例4: disableSelection
bool MainWindow::disableSelection()
{
if (mainSettings->value("view/disable_selection").toBool()) {
qDebug("Try to disable text selection...");
// Then webkit loads page and it's "empty" - empty html DOM loaded...
// So we wait before real page DOM loaded...
QWebElement bodyElem = view->page()->mainFrame()->findFirstElement("body");
if (!bodyElem.isNull() && !bodyElem.toInnerXml().trimmed().isEmpty()) {
QWebElement headElem = view->page()->mainFrame()->findFirstElement("head");
if (headElem.isNull() || headElem.toInnerXml().trimmed().isEmpty()) {
qDebug("... html head not loaded ... wait...");
return false;
}
//qDebug() << "... head element content:\n" << headElem.toInnerXml();
// http://stackoverflow.com/a/5313735
QString content;
content = "<style type=\"text/css\">\n";
content += "body, div, p, span, h1, h2, h3, h4, h5, h6, caption, td, li, dt, dd {\n";
content += " -moz-user-select: none;\n";
content += " -khtml-user-select: none;\n";
content += " -webkit-user-select: none;\n";
content += " user-select: none;\n";
content += " }\n";
content += "</style>\n";
// Ugly hack, but it's works...
if (!headElem.toInnerXml().contains(content)) {
headElem.setInnerXml(headElem.toInnerXml() + content);
qDebug("... html head loaded ... hack inserted...");
} else {
qDebug("... html head loaded ... hack already inserted...");
}
//headElem = view->page()->mainFrame()->findFirstElement("head");
//qDebug() << "... head element content after:\n" << headElem.toInnerXml() ;
} else {
qDebug("... html body not loaded ... wait...");
return false;
}
}
return true;
}
示例5: move
void HtmlExtractor::move(QWebElement &element, const QString &file, bool outer)
{
if(!element.isNull())
{
WriteFile(file, outer?element.toOuterXml():element.toInnerXml());
element.removeFromDocument();
}
}
示例6: fixLinkNode
void EnmlFormatter::fixLinkNode(QWebElement e) {
QString enTag = e.attribute("en-tag", "");
if (enTag.toLower() == "en-media") {
resources.append(e.attribute("lid").toInt());
e.removeAttribute("style");
e.removeAttribute("href");
e.removeAttribute("title");
removeInvalidAttributes(e);
e.removeAllChildren();
QString newXml = e.toOuterXml();
newXml.replace("<a", "<en-media");
newXml.replace("</a>", "</en-media>");
e.setOuterXml(newXml);
}
QString latex = e.attribute("href", "");
if (latex.toLower().startsWith("latex://")) {
removeInvalidAttributes(e);
e.removeAttribute("title");
e.removeAttribute("href");
e.setOuterXml(e.toInnerXml());
}
removeInvalidAttributes(e);
}
示例7: modifyTags
/*
This will go through and modify some of the ENML tags and turn
them into HTML tags. Things like en-media & en-crypt have no
HTML values, so we turn them into HTML.
*/
void NoteFormatter::modifyTags(QWebPage &doc) {
tempFiles.clear();
// Modify en-media tags
QLOG_TRACE() << "Searching for all en-media tags;";
QWebElementCollection anchors = doc.mainFrame()->findAllElements("en-media");
QLOG_TRACE() << "Search complete: " << anchors.toList().size();
foreach (QWebElement enmedia, anchors) {
if (enmedia.hasAttribute("type")) {
QString attr = enmedia.attribute("type");
QString hash = enmedia.attribute("hash");
QStringList type = attr.split("/");
if (type.size() >= 2) {
QString appl = type[1];
QLOG_TRACE() << "En-Media tag type: " << type[0];
if (type[0] == "image")
modifyImageTags(enmedia, hash);
else
modifyApplicationTags(enmedia, hash, appl);
QLOG_TRACE() << "Type modified";
}
}
}
// Modify todo tags
anchors = doc.mainFrame()->findAllElements("en-todo");
qint32 enTodoCount = anchors.count();
for (qint32 i=enTodoCount-1; i>=0; i--) {
QWebElement enmedia = anchors.at(i);
modifyTodoTags(enmedia);
}
anchors = doc.mainFrame()->findAllElements("en-crypt");
qint32 enCryptLen = anchors.count();
for (qint32 i=enCryptLen-1; i>=0; i--) {
QWebElement enmedia = anchors.at(i);
QString hint = enmedia.attribute("hint");
QString cipher = enmedia.attribute("cipher", "RC2");
QString length = enmedia.attribute("length","64");
enmedia.setAttribute("contentEditable","false");
enmedia.setAttribute("src", QString("file://")+global.fileManager.getImageDirPath("encrypt.png"));
enmedia.setAttribute("en-tag","en-crypt");
enmedia.setAttribute("cipher", cipher);
enmedia.setAttribute("length", length);
enmedia.setAttribute("hint", hint);
enmedia.setAttribute("alt", enmedia.toInnerXml());
global.cryptCounter++;
enmedia.setAttribute("id", "crypt"+QString().number(global.cryptCounter));
QString encryptedText = enmedia.toInnerXml();
// If the encryption string contains crlf at the end, remove them because they mess up the javascript.
if (encryptedText.endsWith("\n"))
encryptedText.truncate(encryptedText.length()-1);
if (encryptedText.endsWith("\r"))
encryptedText.truncate(encryptedText.length()-1);
// Add the commands
hint = hint.replace("'","'");
enmedia.setAttribute("onClick", "window.browserWindow.decryptText('crypt"+
QString().number(global.cryptCounter)+
"', '"+encryptedText+"', '"+
hint +"', '" +
cipher+ "', " +
length +
");");
enmedia.setAttribute("onMouseOver", "style.cursor='hand'");
enmedia.setInnerXml("");
QString k = enmedia.toOuterXml();
k.replace("<en-crypt", "<img");
k.replace("img>", "<en-crypt");
enmedia.setOuterXml(k);
}
// Modify link tags
anchors = doc.mainFrame()->findAllElements("a");
enCryptLen = anchors.count();
for (qint32 i=0; i<anchors.count(); i++) {
QWebElement element = anchors.at(i);
if (!element.attribute("href").toLower().startsWith("latex://"))
element.setAttribute("title", element.attribute("href"));
else {
element.setAttribute("title", element.attribute("title").toLower().replace("http://latex.codecogs.com/gif.latex?",""));
}
}
}