本文整理汇总了C++中QWebFrame::renderTreeDump方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebFrame::renderTreeDump方法的具体用法?C++ QWebFrame::renderTreeDump怎么用?C++ QWebFrame::renderTreeDump使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebFrame
的用法示例。
在下文中一共展示了QWebFrame::renderTreeDump方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dump
void DumpRenderTree::dump()
{
// Prevent any further frame load or resource load callbacks from appearing after we dump the result.
DumpRenderTreeSupportQt::dumpFrameLoader(false);
DumpRenderTreeSupportQt::dumpResourceLoadCallbacks(false);
QWebFrame *mainFrame = m_page->mainFrame();
if (isStandAloneMode()) {
QString markup = mainFrame->toHtml();
fprintf(stdout, "Source:\n\n%s\n", markup.toUtf8().constData());
}
QString mimeType = DumpRenderTreeSupportQt::responseMimeType(mainFrame);
if (mimeType == "text/plain")
m_controller->dumpAsText();
// Dump render text...
QString resultString;
if (m_controller->shouldDumpAsText())
resultString = dumpFramesAsText(mainFrame);
else {
resultString = mainFrame->renderTreeDump();
resultString += dumpFrameScrollPosition(mainFrame);
}
if (!resultString.isEmpty()) {
fprintf(stdout, "Content-Type: text/plain\n");
fprintf(stdout, "%s", resultString.toUtf8().constData());
if (m_controller->shouldDumpBackForwardList()) {
fprintf(stdout, "%s", dumpBackForwardList(webPage()).toUtf8().constData());
foreach (QObject* widget, windows) {
QWebPage* page = qobject_cast<QWebPage*>(widget->findChild<QWebPage*>());
fprintf(stdout, "%s", dumpBackForwardList(page).toUtf8().constData());
}
示例2: saveSnapshot
void CutyCapt::saveSnapshot() {
QWebFrame *mainFrame = mPage->mainFrame();
QPainter painter;
const char* format = NULL;
for (int ix = 0; CutyExtMap[ix].id != OtherFormat; ++ix) {
if (CutyExtMap[ix].id == mFormat) {
format = CutyExtMap[ix].identifier;
}
}
// TODO: sometimes contents/viewport can have size 0x0 in which case saving
// them will fail. This is likely the result of the method being called too
// early. So far I've been unable to find a workaround, except using --delay
// with some substantial wait time. I've tried to resize multiple time, make
// a fake render, check for other events... This is primarily a problem under
// my Ubuntu virtual machine.
mPage->setViewportSize( mainFrame->contentsSize() );
switch (mFormat) {
case SvgFormat: {
QSvgGenerator svg;
svg.setFileName(mOutput);
svg.setSize(mPage->viewportSize());
painter.begin(&svg);
mainFrame->render(&painter);
painter.end();
break;
}
case PdfFormat:
case PsFormat: {
QPrinter printer;
printer.setPageSize(QPrinter::A4);
printer.setOutputFileName(mOutput);
// TODO: change quality here?
mainFrame->print(&printer);
break;
}
#if QT_VERSION < 0x050000
case RenderTreeFormat:
QFile file(mOutput);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream s(&file);
s.setCodec("utf-8");
s << mainFrame->renderTreeDump();
break;
}
#endif
case InnerTextFormat:
case HtmlFormat: {
QFile file(mOutput);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream s(&file);
s.setCodec("utf-8");
s << (mFormat == InnerTextFormat ? mainFrame->toPlainText() : (mFormat == HtmlFormat ? mainFrame->toHtml() : "bug"));
break;
}
default: {
QImage image(mPage->viewportSize(), QImage::Format_ARGB32);
painter.begin(&image);
mainFrame->render(&painter);
painter.end();
// TODO: add quality
image.save(mOutput, format);
}
};