本文整理汇总了C++中QWebHitTestResult类的典型用法代码示例。如果您正苦于以下问题:C++ QWebHitTestResult类的具体用法?C++ QWebHitTestResult怎么用?C++ QWebHitTestResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QWebHitTestResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: page
void WebView::contextMenuEvent ( QContextMenuEvent * event )
{
QMenu menu;
QPoint pos = event->pos();
QWebHitTestResult hitTest = page()->mainFrame()->hitTestContent( pos );
if (!hitTest.linkElement().isNull()) {
menu.addAction( pageAction(QWebPage::CopyLinkToClipboard) );
menu.addSeparator();
}
if (hitTest.isContentEditable() || hitTest.isContentSelected()) {
menu.addAction( pageAction(QWebPage::Copy) );
if (hitTest.isContentEditable())
menu.addAction( pageAction(QWebPage::Paste) );
menu.addSeparator();
}
menu.addAction( pageAction(QWebPage::Back) );
menu.addAction( pageAction(QWebPage::Forward) );
menu.addAction( pageAction(QWebPage::Reload) );
menu.exec( event->globalPos() );
}
示例2: page
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
if (!r.linkUrl().isEmpty()) {
QMenu menu(this);
menu.addAction(pageAction(QWebPage::OpenLink));
// building a custom signal for external browser action
QSignalMapper* signalMapper = new QSignalMapper (this);
signalMapper->setProperty("url", QVariant(r.linkUrl()));
connect(signalMapper, SIGNAL(mapped(int)),
this, SLOT(triggerContextMenuAction(int)));
QAction* extAction = menu.addAction(tr("Open in External Browser"));
connect (extAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(extAction, QWebPage::OpenLink);
QAction* newAction = menu.addAction(tr("Open in new window"));
connect (newAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
signalMapper->setMapping(newAction, QWebPage::OpenLinkInNewWindow);
menu.addAction(pageAction(QWebPage::DownloadLinkToDisk));
menu.addAction(pageAction(QWebPage::CopyLinkToClipboard));
menu.exec(mapToGlobal(event->pos()));
return;
}
示例3: page
void WebView::contextMenuEvent(QContextMenuEvent* event)
{
if (isLoading_) return;
QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
QMenu *menu;
if (!r.linkUrl().isEmpty()) {
if (r.linkUrl().scheme() == "addnick") {
event->ignore();
return;
}
menu = URLObject::getInstance()->createPopupMenu(r.linkUrl().toEncoded());
//menu->addAction(pageAction(QWebPage::CopyLinkToClipboard));
} else {
menu = new QMenu(this);
if (!page()->selectedText().isEmpty()) {
menu->addAction(pageAction(QWebPage::Copy));
} else {
if (!menu->isEmpty()) {
menu->addSeparator();
}
menu->addAction(pageAction(QWebPage::SelectAll));
}
if (settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) {
menu->addAction(pageAction(QWebPage::InspectElement));
}
}
menu->addAction(pageAction(QWebPage::Reload));
menu->exec(mapToGlobal(event->pos()));
event->accept();
delete menu;
}
示例4: contextMenuRequest
void tab::contextMenuRequest(QPoint pos)
{
clickPos = pos;
QMenu menu;
QWebHitTestResult r = webView->page()->mainFrame()->hitTestContent(pos);
if(!r.linkUrl().isEmpty())
{
menu.addAction(tr("Open in New Tab"), this, SLOT(openLinkInNewTab()));
menu.addAction(webView->pageAction(QWebPage::DownloadLinkToDisk));
menu.addAction(webView->pageAction(QWebPage::CopyLinkToClipboard));
}
if(!r.imageUrl().isEmpty())
{
menu.addSeparator();
menu.addAction(webView->pageAction(QWebPage::DownloadImageToDisk));
menu.addAction(webView->pageAction(QWebPage::CopyImageToClipboard));
menu.addAction(webView->pageAction(QWebPage::CopyImageUrlToClipboard));
}
menu.addSeparator();
menu.addAction(webView->pageAction(QWebPage::InspectElement));
menu.exec(webView->mapToGlobal(pos));
}
示例5: while
QWebFrame *QtScrollerFilter::scrollingFrameAt_QWebView(QWebView *view, const QPoint &pos) const
{
if (!view->page())
return 0;
QWebFrame *mainFrame = view->page()->mainFrame();
QWebHitTestResult hitTest = mainFrame->hitTestContent(pos);
QWebFrame *hitFrame = hitTest.frame();
if (!hitFrame)
return 0;
QRect vsbrect = hitFrame->scrollBarGeometry(Qt::Vertical);
QRect hsbrect = hitFrame->scrollBarGeometry(Qt::Horizontal);
if (!vsbrect.isEmpty() && vsbrect.contains(hitTest.pos() - hitFrame->scrollPosition()))
return 0;
if (!hsbrect.isEmpty() && hsbrect.contains(hitTest.pos() - hitFrame->scrollPosition()))
return 0;
QSize range = hitFrame->contentsSize() - hitFrame->geometry().size();
while (hitFrame && range.width() <= 1 && range.height() <= 1)
hitFrame = hitFrame->parentFrame();
return hitFrame;
}
示例6: showBrowserContextMenu
void SearchPage::showBrowserContextMenu(const QPoint &pos) {
const QWebHitTestResult result = m_browser->page()->mainFrame()->hitTestContent(pos);
const QString url = result.linkUrl().toString();
if (url.isEmpty()) {
return;
}
QMenu menu(this);
QAction *copyAction = menu.addAction(QIcon::fromTheme("edit-copy"), tr("&Copy URL"));
QAction *addAction = menu.addAction(QIcon::fromTheme("list-add"), tr("&Add URL"));
QAction *retrieveAction = menu.addAction(QIcon::fromTheme("folder-remote"), tr("&Retrieve URLs"));
QAction *downloadAction = menu.addAction(QIcon::fromTheme("download"), tr("Retrieve &download requests"));
QAction *action = menu.exec(m_browser->mapToGlobal(pos));
if (!action) {
return;
}
if (action == copyAction) {
copyUrl(url);
}
else if (action == addAction) {
addUrl(url);
}
else if (action == retrieveAction) {
retrieveUrls(url);
}
else if (action == downloadAction) {
fetchDownloadRequests(url);
}
}
示例7: populateWebViewMenu
void CopyTitle::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)
{
m_view = view;
if (!r.linkUrl().isEmpty() || r.isContentEditable()) {
return;
}
QString title;
if (!r.imageUrl().isEmpty()) {
QString m_userFileName = r.imageUrl().toString().trimmed();
int pos = m_userFileName.lastIndexOf(QLatin1Char('/'));
if (pos != -1) {
int size = m_userFileName.size();
title = m_userFileName.right(size - pos - 1);
}
else {
title += "image";
}
}
else {
title = view->title();
}
menu->addAction(QIcon::fromTheme("edit-copy"), !r.imageUrl().isEmpty() ? tr("Copy Image Name") : tr("Copy Page Title"), this, SLOT(copyPageTitle()))->setData(title);
}
示例8: page
QString ViewWindow::anchorAt(const QPoint & pos)
{
QWebHitTestResult res = page()->currentFrame()->hitTestContent( pos );
if ( !res.linkUrl().isValid() )
return QString::null;
return res.linkUrl().path();
}
示例9: page
void WBWebTrapWebView::trapElementAtPos(const QPoint& pos)
{
QWebHitTestResult htr = page()->currentFrame()->hitTestContent(pos);
if (!htr.pixmap().isNull())
{
emit pixmapCaptured(htr.pixmap(), false);
}
else if (mCurrentContentType == ObjectOrEmbed)
{
QString embedSelector = QString("document.elementFromPoint(%1, %2)").arg(pos.x()).arg(pos.y());
QVariant tagName = page()->currentFrame()->evaluateJavaScript(embedSelector + ".tagName");
QVariant innerHTML = page()->currentFrame()->evaluateJavaScript(embedSelector + ".innerHTML");
qDebug() << "innerHTML" << innerHTML;
if (tagName.toString().toLower() == "object")
{
embedSelector = QString("document.elementFromPoint(%1, %2).getElementsByTagName('object')[0]")
.arg(pos.x()).arg(pos.y());
}
QString querySource = embedSelector + ".src";
QVariant resSource = page()->currentFrame()->evaluateJavaScript(querySource);
qDebug() << "resSource" << resSource;
QString source = resSource.toString();
QString queryType = embedSelector + ".type";
QVariant resType = page()->currentFrame()->evaluateJavaScript(queryType);
QString type = resType.toString();
qDebug() << "resType" << resType;
if (source.trimmed().length() > 0)
{
emit objectCaptured(QUrl(page()->currentFrame()->url().toString() + "/" + source), type,
htr.boundingRect().width(), htr.boundingRect().height());
UBApplication::boardController->downloadURL(QUrl(source), QPointF(0.0, 0.0));
UBApplication::applicationController->showBoard();
}
}
else if (mCurrentContentType == Input)
{
QString embedCode = potentialEmbedCodeAtPos(pos);
if (embedCode.length() > 0)
{
emit embedCodeCaptured(embedCode);
}
}
else if (mCurrentContentType == ElementByQuery)
{
webElementCaptured(page()->currentFrame()->url(), mElementQuery);
}
}
示例10: findElement
void ClickToFlash::findElement()
{
if (!loadButton_)
return;
QPoint objectPos = page_->view()->mapFromGlobal(loadButton_->mapToGlobal(loadButton_->pos()));
QWebFrame* objectFrame = page_->frameAt(objectPos);
QWebHitTestResult hitResult;
QWebElement hitElement;
if (objectFrame) {
hitResult = objectFrame->hitTestContent(objectPos);
hitElement = hitResult.element();
}
if (!hitElement.isNull() && (hitElement.tagName().compare("embed", Qt::CaseInsensitive) == 0 ||
hitElement.tagName().compare("object", Qt::CaseInsensitive) == 0)) {
element_ = hitElement;
return;
}
// HitTestResult failed, trying to find element by src
// attribute in elements at all frames on page (less accurate)
QList<QWebFrame*> frames;
frames.append(objectFrame);
frames.append(page_->mainFrame());
while (!frames.isEmpty()) {
QWebFrame* frame = frames.takeFirst();
if (!frame) {
continue;
}
QWebElement docElement = frame->documentElement();
QWebElementCollection elements;
elements.append(docElement.findAll(QLatin1String("embed")));
elements.append(docElement.findAll(QLatin1String("object")));
foreach (const QWebElement &element, elements) {
if (!checkElement(element) && !checkUrlOnElement(element)) {
continue;
}
element_ = element;
return;
}
frames += frame->childFrames();
}
}
示例11: contextMenu
void ChannelsView::contextMenu(QMenu *menu, const QWebHitTestResult &result)
{
menu->addSeparator();
const QUrl url = result.linkUrl();
if (url.scheme() == LS("chat") && url.host() == LS("channel"))
ChannelMenu::bind(menu, ChatUrls::channel(url), IChannelMenu::ChatViewScope);
menu->addSeparator();
if (!result.isContentEditable()) {
menu->removeAction(pageAction(QWebPage::SelectAll));
menu->addAction(pageAction(QWebPage::SelectAll));
}
}
示例12: SendToCGLX
void csWebView::SendToCGLX()
{
//printf("Hello at x: %d y: %d\n", hit_pos.x(), hit_pos.y());
QWebFrame *tframe=page()->currentFrame ();
QWebHitTestResult hitresult = tframe->hitTestContent ( hit_pos );
if(!hitresult.isNull())
{
QPixmap img = hitresult.pixmap();
if(!img.isNull())
{
//printf("Width: %d Height: %d Link: %s\n",img.width(), img.height(),hitresult.imageUrl().toString().toStdString().c_str());
emit send_image(img.width(), img.height() , hitresult.imageUrl());
}
}
}
示例13: contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent* event)
{
QMenu* menu = page()->createStandardContextMenu();
QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
if (!r.linkUrl().isEmpty()) {
QAction* newTabAction = menu->addAction(tr("Open in Default &Browser"), this, SLOT(openUrlInDefaultBrowser()));
newTabAction->setData(r.linkUrl());
menu->insertAction(menu->actions().at(2), newTabAction);
}
menu->exec(mapToGlobal(event->pos()));
delete menu;
}
示例14: position
/*!
Returns the area of the largest element at position (\a x,\a y) that is no larger
than \a maxWidth by \a maxHeight pixels.
May return an area larger in the case when no smaller element is at the position.
*/
QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxWidth, int maxHeight) const
{
QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x, y));
QRect hitRect = hit.boundingRect();
QWebElement element = hit.enclosingBlockElement();
if (maxWidth <= 0)
maxWidth = INT_MAX;
if (maxHeight <= 0)
maxHeight = INT_MAX;
while (!element.parent().isNull() && element.geometry().width() <= maxWidth && element.geometry().height() <= maxHeight) {
hitRect = element.geometry();
element = element.parent();
}
return hitRect;
}
示例15: QMenu
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = new QMenu(this);
QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
if (!r.linkUrl().isEmpty()) {
menu->addAction(tr("Open in New &Window"), this, SLOT(openLinkInNewWindow()));
menu->addAction(tr("Open in New &Tab"), this, SLOT(openLinkInNewTab()));
menu->addSeparator();
menu->addAction(tr("Save Lin&k"), this, SLOT(downloadLinkToDisk()));
menu->addAction(tr("&Bookmark This Link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl().toString());
menu->addSeparator();
menu->addAction(tr("&Copy Link Location"), this, SLOT(copyLinkToClipboard()));
if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled))
menu->addAction(pageAction(QWebPage::InspectElement));
}
if (!r.imageUrl().isEmpty()) {
if (!menu->isEmpty())
menu->addSeparator();
menu->addAction(tr("Open Image in New &Window"), this, SLOT(openImageInNewWindow()));
menu->addAction(tr("Open Image in New &Tab"), this, SLOT(openImageInNewTab()));
menu->addSeparator();
menu->addAction(tr("&Save Image"), this, SLOT(downloadImageToDisk()));
menu->addAction(tr("&Copy Image"), this, SLOT(copyImageToClipboard()));
menu->addAction(tr("C&opy Image Location"), this, SLOT(copyImageLocationToClipboard()))->setData(r.imageUrl().toString());
}
#ifdef WEBKIT_TRUNK // i.e. Qt 4.5, but not in Qt 4.5 yet
if (menu->isEmpty())
menu = page()->createStandardContextMenu();
#endif
if (!menu->isEmpty()) {
if (m_page->mainWindow()->menuBar()->isHidden()) {
menu->addSeparator();
menu->addAction(m_page->mainWindow()->showMenuBarAction());
}
menu->exec(mapToGlobal(event->pos()));
delete menu;
return;
}
delete menu;
QWebView::contextMenuEvent(event);
}