本文整理汇总了C++中QWebElement::geometry方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebElement::geometry方法的具体用法?C++ QWebElement::geometry怎么用?C++ QWebElement::geometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebElement
的用法示例。
在下文中一共展示了QWebElement::geometry方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: elementAreaAt
/*!
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;
}
示例2: elemRect
QList<CachedHandler> ChromeDOM::getCachedHandlers(const QString &elementId, const QRectF & ownerArea)
{
QWebElement snippet = getElementById(elementId);
QList <QWebElement> controls = snippet.findAll(".GinebraCached").toList();
QList <CachedHandler> handlers;
for (int i = 0; i < controls.size(); i++){
QWebElement elem = controls.at(i);
//Element rectangle relative to snippet, so we can handle mouse events relative to snippet
//qDebug() << "====> Owner X: " << ownerArea.x() << " Owner Width: " << ownerArea.width() << " Elem X: " << elem.geometry().x() << " Elem Width: " << elem.geometry().width();
QRectF elemRect(elem.geometry().x() - ownerArea.x(), elem.geometry().y() - ownerArea.y(), elem.geometry().width(), elem.geometry().height());
//NB: For now we handle only onclick from cache. Should add at least long-press too.
CachedHandler handler(elem.attribute("id"), elem.attribute("data-GinebraOnClick"), elemRect, m_chrome, elem.attribute("data-GinebraTargetView"));
//qDebug() << "Cached handler" << handler.elementId() << ": " << handler.script() << ": " << handler.rect();
handlers.append(handler);
}
return handlers;
}
示例3: findZoomableRectForPoint
QRectF WebContentAnimationItem::findZoomableRectForPoint(const QPointF& point)
{
QPointF zoomPoint = m_webView->mapFromParent(point);
QWebHitTestResult hitResult = m_webView->page()->mainFrame()->hitTestContent(zoomPoint.toPoint());
QWebElement targetElement = hitResult.enclosingBlockElement();
while (!targetElement.isNull() && targetElement.geometry().width() < MinDoubleClickZoomTargetWidth)
targetElement = targetElement.parent();
if (!targetElement.isNull()) {
QRectF elementRect = targetElement.geometry();
qreal overMinWidth = elementRect.width() - ZoomableContentMinWidth;
if (overMinWidth < 0)
elementRect.adjust(overMinWidth / 2, 0, -overMinWidth / 2, 0);
zoomPoint.setX(elementRect.x());
QRectF resultRect(zoomPoint, elementRect.size());
return QRectF(m_webView->mapToParent(resultRect.topLeft()),
m_webView->mapToParent(resultRect.bottomRight()));
}
return QRectF();
}
示例4: WebChromeContainerSnippet
ChromeSnippet *ChromeDOM::getSnippet(const QString &docElementId, QGraphicsItem* parent) {
Q_UNUSED(parent)
ChromeSnippet * snippet = 0;
QWebElement doc = m_page->mainFrame()->documentElement();
QWebElement element = doc.findFirst("#" + docElementId);
QRect rect = element.geometry();
//TODO: This may not be accurate since final heights may not have been computed at this point!!
m_height += rect.height();
// qDebug() << "Snippet: ID: " << docElementId << " Owner Area: " << rect << " Element Rect: " << element.geometry();
if (!rect.isNull()) {
QString className = element.attribute("data-GinebraNativeClass", "__NO_CLASS__");
if (className == "__NO_CLASS__") {
if (element.attribute("data-GinebraContainer", "false") == "true") {
snippet = new WebChromeContainerSnippet(docElementId, m_chrome, element);
snippet->setChromeWidget(new ChromeItem(snippet));
}
else {
snippet = new WebChromeSnippet(docElementId, m_chrome, element);
m_renderer->addRenderItem((static_cast<WebChromeSnippet*> (snippet))->item());
}
}
else {
snippet = nativeSnippetForClassName(className, docElementId, element);
//TODO: Is the following still needed?
QGraphicsWidget * widget = snippet->widget();
//Have snippet determine its own size when in anchor layout. Again, these will not
//necessarily be accurate at this point.
widget->resize(rect.width(), rect.height());
widget->setPreferredSize(rect.width(), rect.height());
widget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
//Have snippet determine its own location when NOT in anchor layout
widget->setPos(rect.x(), rect.y());
}
QWebElement parentElem;
if (!(parentElem = findChromeParent(element)).isNull()) {
snippet->setParentId(parentElem.attribute("id"));
}
//Set auto-layout attributes
snippet->setAnchor(element.attribute("data-GinebraAnchor", "AnchorNone"), false);
snippet->setAnchorOffset(element.attribute("data-GinebraAnchorOffset", "0").toInt());
snippet->setInitiallyVisible(element.attribute("data-GinebraVisible", "false") == "true");
snippet->setHidesContent(element.attribute("data-GinebraHidesContent", "false") == "true");
}
return snippet;
}
示例5: setActiveElement
void XPathInspector::setActiveElement(const QWebElement & elem, bool select)
{
if (elem.isNull()) return;
selectElements(false);
//if (!activeElement.isNull())
// activeElement.setStyleProperty("border", activeOldStyle);
selectedElements.clear();
selectedElements.append(elem);
activeElement = elem;
QString path = PhpBrowser::getxpath(elem);
//activeOldStyle = activeElement.styleProperty("border", QWebElement::ComputedStyle);
//activeElement.setStyleProperty("border", "2px dashed red");
selectElements(true);
QString attrsStr = "";
QStringList attrs = activeElement.attributeNames();
for (int i=0; i<attrs.size(); i++)
{
attrsStr += attrs.at(i) + " = \"" + elem.attribute(attrs.at(i)) +"\"\n";
}
attrsStr += "rect: x:"+QString::number(elem.geometry().topLeft().x())+", y:"+QString::number(elem.geometry().topLeft().y())+
", w:"+QString::number(elem.geometry().width())+", h:"+QString::number(elem.geometry().height())+"\n";
edit->setText(path);
edit2->setPlainText(attrsStr);
if (select)
{
deselectTreeItems();
findTreeItemAndSelect(elem);
}
}
示例6: updateContentRect
void AlertWebApp::updateContentRect()
{
QWebFrame* frame = page()->page()->mainFrame();
QWebElement el = frame->findFirstElement("[x-palm-popup-content]");
QRect r;
if (!el.isNull()) {
r = el.geometry();
r.setLeft(MAX(0, r.left()));
r.setRight(MIN(r.right(), (int) m_windowWidth));
r.setTop(MAX(0, r.top()));
r.setBottom(MIN(r.bottom(), (int) m_windowHeight));
}
m_channel->sendAsyncMessage(new ViewHost_Alert_SetContentRect(routingId(),
r.left(), r.right(),
r.top(), r.bottom()));
}
示例7: findElementByCoord
bool PhpWebView::findElementByCoord(QWebElement & root, QPoint & point, QList<WebElementStruct> & list)
{
QWebElement child = root.lastChild();
bool isfind = false;
while (!child.isNull())
{
if (findElementByCoord(child, point, list))
isfind = true;
child = child.previousSibling();
}
QString display = root.styleProperty("display", QWebElement::ComputedStyle);
if (display != "none" && root.geometry().contains(point) && !isfind)
{
list.append(createWebElementStruct(root, list.count()));
return true;
}
else
return false;
}
示例8: toMap
extern QVariantMap toMap(QWebElement el, QStringList css_attrs) {
QVariantMap map;
map["isNull"] = false;
map["classes"] = QVariant(el.classes());
map["tagName"] = QVariant(el.tagName());
QRect rect = el.geometry();
QVariantMap geo;
geo["width"] = rect.width();
geo["height"] = rect.height();
geo["x"] = rect.x();
geo["y"] = rect.y();
map["geometry"] = QVariant(geo);
QVariantMap attrs;
QStringList attributes = el.attributeNames();
foreach(QString name,attributes) {
attrs[name] = el.attribute(name);
}
示例9: showMapTip
void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
QgsPoint & mapPosition,
QPoint & thePixelPosition,
QgsMapCanvas *pMapCanvas )
{
// Do the search using the active layer and the preferred label field for the
// layer. The label field must be defined in the layer configuration
// file/database. The code required to do this is similar to identify, except
// we only want the first qualifying feature and we will only display the
// field defined as the label field in the layer configuration file/database
// Show the maptip on the canvas
QString tipText, lastTipText, tipHtml, bodyStyle, containerStyle,
backgroundColor, borderColor;
delete mWidget;
mWidget = new QWidget( pMapCanvas );
mWebView = new QgsWebView( mWidget );
#if WITH_QTWEBKIT
mWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );//Handle link clicks by yourself
mWebView->setContextMenuPolicy( Qt::NoContextMenu ); //No context menu is allowed if you don't need it
connect( mWebView, SIGNAL( linkClicked( QUrl ) ), this, SLOT( onLinkClicked( QUrl ) ) );
#endif
mWebView->page()->settings()->setAttribute(
QWebSettings::DeveloperExtrasEnabled, true );
mWebView->page()->settings()->setAttribute(
QWebSettings::JavascriptEnabled, true );
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget( mWebView );
mWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
mWidget->setLayout( layout );
//assure the map tip is never larger than half the map canvas
const int MAX_WIDTH = pMapCanvas->geometry().width() / 2;
const int MAX_HEIGHT = pMapCanvas->geometry().height() / 2;
mWidget->setMaximumSize( MAX_WIDTH, MAX_HEIGHT );
// start with 0 size,
// the content will automatically make it grow up to MaximumSize
mWidget->resize( 0, 0 );
backgroundColor = mWidget->palette().base().color().name();
borderColor = mWidget->palette().shadow().color().name();
mWidget->setStyleSheet( QString(
".QWidget{"
"border: 1px solid %1;"
"background-color: %2;}" ).arg(
borderColor, backgroundColor ) );
tipText = fetchFeature( pLayer, mapPosition, pMapCanvas );
mMapTipVisible = !tipText.isEmpty();
if ( !mMapTipVisible )
{
clear();
return;
}
if ( tipText == lastTipText )
{
return;
}
bodyStyle = QString(
"background-color: %1;"
"margin: 0;" ).arg( backgroundColor );
containerStyle = QString(
"display: inline-block;"
"margin: 0px" );
tipHtml = QString(
"<html>"
"<body style='%1'>"
"<div id='QgsWebViewContainer' style='%2'>%3</div>"
"</body>"
"</html>" ).arg( bodyStyle, containerStyle, tipText );
mWidget->move( thePixelPosition.x(),
thePixelPosition.y() );
mWebView->setHtml( tipHtml );
lastTipText = tipText;
mWidget->show();
#if WITH_QTWEBKIT
int scrollbarWidth = mWebView->page()->mainFrame()->scrollBarGeometry(
Qt::Vertical ).width();
int scrollbarHeight = mWebView->page()->mainFrame()->scrollBarGeometry(
Qt::Horizontal ).height();
if ( scrollbarWidth > 0 || scrollbarHeight > 0 )
{
// Get the content size
//.........这里部分代码省略.........
示例10: click
int PhpWebView::click(const QString & xpath, bool samewnd)
{
QWebElement elem = getElementByXPath(QString(xpath));
if (elem.isNull())
return 0;
elem.setFocus();
if (samewnd)
elem.removeAttribute("target");
QString js = "var node = this; var x = node.offsetLeft; var y = node.offsetTop; ";
js += "var w = node.offsetWidth/2; ";
js += "var h = node.offsetHeight/2; ";
js += "while (node.offsetParent != null) { ";
js += " node = node.offsetParent; ";
js += " x += node.offsetLeft; ";
js += " y += node.offsetTop; ";
js += "} ";
js += "[x+w, y+h]; ";
QList<QVariant> vlist = elem.evaluateJavaScript(js).toList();
QPoint point;
point.setX(vlist.at(0).toInt());
point.setY(vlist.at(1).toInt());
QRect elGeom = elem.geometry();
QPoint elPoint = elGeom.center();
int elX = point.x(); //elPoint.x();
int elY = point.y(); //elPoint.y();
int webWidth = width();
int webHeight = height();
int pixelsToScrollRight=0;
int pixelsToScrollDown=0;
if (elX > webWidth)
pixelsToScrollRight = elX-webWidth+elGeom.width()/2+50; //the +10 part if for the page to scroll a bit further
if (elY > webHeight)
pixelsToScrollDown = elY-webHeight+elGeom.height()/2+50; //the +10 part if for the page to scroll a bit further
/*pixelsToScrollRight = elX-elGeom.width()/2-50;
pixelsToScrollDown = elY-elGeom.height()/2-50;
if (pixelsToScrollRight < 0)
pixelsToScrollRight = 0;
if (pixelsToScrollRight > page()->mainFrame()->scrollBarMaximum(Qt::Horizontal))
pixelsToScrollRight = page()->mainFrame()->scrollBarMaximum(Qt::Horizontal);
if (pixelsToScrollDown < 0)
pixelsToScrollDown = 0;
if (pixelsToScrollDown > page()->mainFrame()->scrollBarMaximum(Qt::Vertical))
pixelsToScrollDown = page()->mainFrame()->scrollBarMaximum(Qt::Vertical);*/
int oldHoriz = page()->mainFrame()->scrollBarValue(Qt::Horizontal);
int oldVert = page()->mainFrame()->scrollBarValue(Qt::Vertical);
page()->mainFrame()->setScrollBarValue(Qt::Horizontal, pixelsToScrollRight);
page()->mainFrame()->setScrollBarValue(Qt::Vertical, pixelsToScrollDown);
QPoint pointToClick(elX-pixelsToScrollRight, elY-pixelsToScrollDown);
QEventLoop loop;
isNewViewCreated = false;
isNewViewBegin = false;
//QMouseEvent *pressEvent = new QMouseEvent(QMouseEvent::MouseButtonPress, pointToClick, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
//QApplication::postEvent(browser, pressEvent);
//QApplication::processEvents();
//QMouseEvent releaseEvent(QMouseEvent::MouseButtonRelease,pointToClick,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
//QApplication::sendEvent(browser, &releaseEvent);
QString js2 = "var e = document.createEvent('MouseEvents');";
//js2 += "e.initEvent( 'click', true, true );";
//js2 += "e.initMouseEvent('click', true, true, window, 0, 0, 0, "+QString::number(elX)+", "+QString::number(elY)+", false, false, false, false, 0, null);";
js2 += "e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);";
js2 += "this.dispatchEvent(e);";
elem.evaluateJavaScript(js2);
QTimer::singleShot(1000, &loop, SLOT(quit()));
loop.exec();
while (browser && isNewViewBegin && !isNewViewCreated)
loop.processEvents();
//page()->mainFrame()->setScrollBarValue(Qt::Horizontal, oldHoriz);
//page()->mainFrame()->setScrollBarValue(Qt::Vertical, oldVert);
return 1;
}