本文整理汇总了C++中QWebPage::mainFrame方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebPage::mainFrame方法的具体用法?C++ QWebPage::mainFrame怎么用?C++ QWebPage::mainFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebPage
的用法示例。
在下文中一共展示了QWebPage::mainFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateResizesToContentsForPage
void QGraphicsWebViewPrivate::updateResizesToContentsForPage()
{
ASSERT(page);
if (resizesToContents) {
// resizes to contents mode requires preferred contents size to be set
if (!page->preferredContentsSize().isValid())
page->setPreferredContentsSize(QSize(960, 800));
#if QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)
QObject::connect(page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)),
q, SLOT(_q_contentsSizeChanged(const QSize&)), Qt::UniqueConnection);
#else
QObject::connect(page->mainFrame(), SIGNAL(contentsSizeChanged(QSize)),
q, SLOT(_q_contentsSizeChanged(const QSize&)));
#endif
} else {
示例2: setWebView
void BrowserApi::setWebView(QWebView *view)
{
QWebPage *page = view->page();
m_frame = page->mainFrame();
attachObject();
connect(m_frame, SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(attachObject()));
}
示例3: loadingFinished
void SourceViewer::loadingFinished()
{
QWebPage page;
QByteArray response = m_reply->readAll();
page.mainFrame()->setContent(response, QString(), m_request->url());
/* If original request was POST or a different problem is there, fall
back to modified version of QWebFrame.toHtml() */
if (page.mainFrame()->toHtml() != *m_source)
m_edit->setPlainText(*m_source);
else
m_edit->setPlainText(QLatin1String(response));
m_reply->close();
delete m_request;
delete m_source;
}
示例4: createWindow
Page* ChromeClientQt::createWindow(Frame*, const FrameLoadRequest& request, const WindowFeatures& features)
{
QWebPage *newPage = m_webPage->createWindow(features.dialog ? QWebPage::WebModalDialog : QWebPage::WebBrowserWindow);
if (!newPage)
return 0;
newPage->mainFrame()->load(request.resourceRequest().url());
return newPage->d->page;
}
示例5: createModalDialog
Page* ChromeClientQt::createModalDialog(Frame*, const FrameLoadRequest& request)
{
QWebPage *newPage = m_webPage->createWindow(QWebPage::WebModalDialog);
if (!newPage)
return 0;
newPage->mainFrame()->load(request.resourceRequest().url());
return newPage->d->page;
}
示例6: viewModeChanged
void HTMLDocument::viewModeChanged(int tabNumber)
{
switch (tabNumber)
{
case 0:
if (this->currentMode == Code)
{
this->code = this->editor->toPlainText();
this->designArea->page()->mainFrame()->setHtml(this->editor->toPlainText());
}
else if (this->currentMode == Preview)
{
this->designArea->setHtml(this->code);
}
this->currentMode = Design;
break;
case 1: //going to code mode
if (this->currentMode == Design)
{
QWebPage *page = this->designArea->page();
this->code = page->mainFrame()->toHtml();
this->editor->setPlainText(this->code);
this->editor->setFocus();
}
else if (this->currentMode == Preview)
{
this->editor->setPlainText(this->code);
}
this->currentMode = Code;
break;
case 2:
if (this->currentMode == Design)
{
QWebPage *page = this->designArea->page();
this->code = page->mainFrame()->toHtml();
}
else if (this->currentMode == Code)
{
this->code = this->editor->toPlainText();
}
this->currentMode = Preview;
this->previewArea->setHtml(this->code);
break;
}
}
示例7: openActionUrlInNewWindow
void WebView::openActionUrlInNewWindow()
{
if (QAction *action = qobject_cast<QAction*>(sender())) {
QWebPage *page = tabWidget()->getView(TabWidget::NewWindow, this)->page();
QNetworkRequest request(action->data().toUrl());
request.setRawHeader("Referer", url().toEncoded());
page->mainFrame()->load(request);
}
}
示例8: QString
void
message_view::prepend_body_fragment(const QString& fragment)
{
QWebPage* page = m_bodyv->page();
page->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
QString js = QString("try {var b=document.getElementsByTagName('body')[0]; var p=document.createElement('div'); p.innerHTML=\"%1\"; b.insertBefore(p, b.firstChild); 1;} catch(e) { e; }").arg(escape_js_string(fragment));
QVariant v = page->mainFrame()->evaluateJavaScript(js);
page->settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
}
示例9: diagnoseLoad
// --- DIAGNOSE LOAD ---
// Verify that the page loaded successfully, else present error message.
// If successful, set other data parts and handle filters.
void MainWindow::diagnoseLoad(bool ok) {
setReloadButton();
if (!ok) {
//QMessageBox::critical(this, tr("Error"), tr("Failed to load the URL")); // FIXME: triggers crash with favicon path customized due to QtWebkit bug!
// Don't return to the event loop.
}
else {
//QWidget* tab = tabWidget->currentWidget
tabWidget->setTabText(tabWidget->currentIndex(), wv->title());
tabWidget->setTabIcon(tabWidget->currentIndex(), wv->icon());
addressBar->setText(wv->url().toString());
QString title = wv->title();
if (title.size() > 200) {
title.resize(200);
}
setWindowTitle(title + " - WildFox");
// check the page URL against the filters
if (extFilters.size() < 1) {
return;
}
QWebPage* page = (QWebPage*) sender();
if (page == 0) {
return;
}
QWebFrame* frame = page->mainFrame();
if (frame == 0) {
return;
}
QString url = frame->url().path();
QStringList urlbit = url.split("://");
QDir extension;
extension.setPath(manifest.fileName());
if (urlbit.size() > 1) {
QString scheme = urlbit[0];
QStringList bits = urlbit[1].split(".");
for (int i = 0; i < extFilters.size(); ++i) {
if (extFilters[i].scheme != scheme) {
continue;
}
for (int j = 0; extFilters[i].segments.size(); ++j) {
if (extFilters[i].segments[j] != bits[j] && extFilters[i].segments[j] != "*") {
continue;
}
}
// matched filter, inject associated scripts into the content.
QWebElement root = frame->documentElement();
QWebElement head = root.findFirst("head");
head.appendOutside("<script type=\"text/javascript\" src=\"" +
extension.absolutePath() + "\" />");
}
}
}
}
示例10: dispatchCreatePage
WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage()
{
if (!m_webFrame)
return 0;
QWebPage *newPage = m_webFrame->page()->createWindow(QWebPage::WebBrowserWindow);
if (!newPage)
return 0;
return newPage->mainFrame()->d->frame;
}
示例11: onLoad
void Widget::onLoad()
{
QWebPage *page = qobject_cast<QWebPage*>(sender());
QElapsedTimer timer;
timer.start();
QStringList scripts = contentScripts();
qDebug() << timer.elapsed(); timer.start();
foreach (const QString &script, scripts) {
page->mainFrame()->evaluateJavaScript(script);
};
示例12: main
int main(int argc, char *argv[])
{
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = term;
sigaction(SIGTERM, &action, NULL);
int fps = atoi(argv[4]);
int width = atoi(argv[2]);
int height = atoi(argv[3]);
init_shared_data(atoi(argv[2]), atoi(argv[3]));
QApplication app(argc, argv);
QWebPage page;
QPalette palette = page.palette();
palette.setBrush(QPalette::Base, Qt::transparent);
page.setPalette(palette);
page.mainFrame()->setUrl(QUrl::fromUserInput(argv[1]));
page.setViewportSize(QSize(width, height));
page.mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
page.mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
pthread_mutex_lock(&data->mutex);
QImage image(&data->data, width, height, QImage::Format_RGBA8888);
QPainter painter(&image);
pthread_mutex_unlock(&data->mutex);
while (!done) {
app.processEvents();
pthread_mutex_lock(&data->mutex);
image.fill(0);
page.mainFrame()->render(&painter, QWebFrame::ContentsLayer);
pthread_mutex_unlock(&data->mutex);
usleep(1000000 / fps);
}
return 0;
}
示例13: onGetLyricPageResult
void LyricsManiaAPI::onGetLyricPageResult()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>(QObject::sender());
bool found = false;
Lyric* lyric = 0;
if (reply->error() != QNetworkReply::NoError) {
qCritical() << "Cannot fetch lyric";
} else {
QWebPage page;
page.settings()->setAttribute(QWebSettings::AutoLoadImages, false);
page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
page.mainFrame()->setHtml(reply->readAll());
QWebElement lyricbox = page.mainFrame()->findFirstElement("div[class=lyrics-body]");
if (lyricbox.isNull()) {
qCritical() << "Cannot find lyric text in HTML page";
} else {
// Remove the video div
lyricbox.findFirst(QStringLiteral("div")).removeFromDocument();
// Remove the song title
lyricbox.findFirst(QStringLiteral("strong")).removeFromDocument();
lyric = lyrics.take(reply);
if (!lyric) {
qCritical() << "Got an invalid lyric object!";
} else {
lyric->setText(lyricbox.toPlainText());
found = true;
}
}
}
qDebug() << "Lyric found:" << found;
Q_EMIT lyricFetched(lyric, found);
reply->deleteLater();
}
示例14: forceRender
void Editor::forceRender(QSize size)
{
QWebPage *page = m_webView->page();
page->setViewportSize(size);
QImage image(size.width(), size.height(), QImage::Format_Mono);
QPainter painter(&image);
page->mainFrame()->render(&painter);
}
示例15: onPageLoaded
void WebViewLoaderLoop::onPageLoaded()
{
disconnect(m_pages.first().data(), 0, this, 0);
m_pages.removeFirst();
m_htmls.removeFirst();
if (!m_pages.isEmpty()) {
QWebPage *page = m_pages.first().data();
QString html = m_htmls.first();
page->mainFrame()->setHtml(html);
}
}