本文整理汇总了C++中QWebElement::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ QWebElement::parent方法的具体用法?C++ QWebElement::parent怎么用?C++ QWebElement::parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWebElement
的用法示例。
在下文中一共展示了QWebElement::parent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onContextMenu
bool HistoryChatView::onContextMenu(ChatView *view, QMenu *menu, const QWebHitTestResult &result)
{
ChatId id(view->id());
if (id.type() != ChatId::ChannelId && id.type() != ChatId::UserId)
return false;
const QWebElement block = result.enclosingBlockElement();
if (!block.hasClass("blocks") || block.hasClass("removed"))
return false;
const QWebElement container = block.parent();
const qint64 mdate = container.attribute(LS("data-mdate")).toLongLong();
if (!mdate)
return false;
id.init(container.attribute(LS("id")).toLatin1());
id.setDate(mdate);
if (id.type() != ChatId::MessageId)
return false;
const int permissions = this->permissions(HistoryDB::get(id));
if (permissions == NoPermissions)
return false;
if (permissions & Remove) {
QVariantList data;
data << view->id() << (id.hasOid() ? ChatId::toBase32(id.oid().byteArray()) : id.toString());
menu->insertAction(menu->actions().first(), removeAction(data));
}
return true;
}
示例3: findChromeParent
QWebElement ChromeDOM::findChromeParent(QWebElement element)
{
while(!(element = element.parent()).isNull()){
if (element.attribute("class") == "GinebraSnippet"){
return element;
}
}
return element;
}
示例4: FindCloserContainer
QWebElement MyWebView::FindCloserContainer(QWebElement &elem)
{
// find by elem id
bool bIsContainer = false;
QString strTemp = elem.attribute("id");
WDomElem * welem = m_pMainWindow->m_treemodel.getElemByName (strTemp);
// check if valid parent
if (welem)
{
QDomElement delem = welem->getElem();
if (delem.attribute(g_strClassAttr).compare("WContainerWidget") == 0 ||
delem.attribute(g_strClassAttr).compare("WAnchor" ) == 0 ||
delem.attribute(g_strClassAttr).compare("WGroupBox" ) == 0 ||
delem.attribute(g_strClassAttr).compare("WPanel" ) == 0 ||
delem.attribute(g_strClassAttr).compare("WMenuItem" ) == 0 ||
delem.attribute(g_strClassAttr).compare("WStackedWidget" ) == 0 ||
delem.attribute(g_strClassAttr).compare("WTabItem" ) == 0)
{
bIsContainer = true;
}
}
// if container return, else keep looking
if (bIsContainer)
{
return elem;
}
else
{
if (!elem.parent().isNull())
{
QWebElement welemTemp = elem.parent();
return FindCloserContainer(welemTemp);
}
else
{
return QWebElement();
}
}
}
示例5: addSearchEngine
void WebView::addSearchEngine()
{
QAction *action = qobject_cast<QAction*>(sender());
if (!action)
return;
QVariant variant = action->data();
if (!variant.canConvert<QWebElement>())
return;
QWebElement element = qvariant_cast<QWebElement>(variant);
QString elementName = element.attribute(QLatin1String("name"));
QWebElement formElement = element;
while (formElement.tagName().toLower() != QLatin1String("form"))
formElement = formElement.parent();
if (formElement.isNull() || formElement.attribute(QLatin1String("action")).isEmpty())
return;
QString method = formElement.attribute(QLatin1String("method"), QLatin1String("get")).toLower();
if (method != QLatin1String("get")) {
QMessageBox::warning(this, tr("Method not supported"),
tr("%1 method is not supported.").arg(method.toUpper()));
return;
}
QUrl searchUrl(page()->mainFrame()->baseUrl().resolved(QUrl(formElement.attribute(QLatin1String("action")))));
QMap<QString, QString> searchEngines;
QWebElementCollection inputFields = formElement.findAll(QLatin1String("input"));
foreach (QWebElement inputField, inputFields) {
QString type = inputField.attribute(QLatin1String("type"), QLatin1String("text"));
QString name = inputField.attribute(QLatin1String("name"));
QString value = inputField.evaluateJavaScript(QLatin1String("this.value")).toString();
if (type == QLatin1String("submit")) {
searchEngines.insert(value, name);
} else if (type == QLatin1String("text")) {
if (inputField == element)
value = QLatin1String("{searchTerms}");
searchUrl.addQueryItem(name, value);
} else if (type == QLatin1String("checkbox") || type == QLatin1String("radio")) {
if (inputField.evaluateJavaScript(QLatin1String("this.checked")).toBool()) {
searchUrl.addQueryItem(name, value);
}
} else if (type == QLatin1String("hidden")) {
searchUrl.addQueryItem(name, value);
}
}
示例6: FindCloserWidget
QWebElement MyWebView::FindCloserWidget(QWebElement &elem)
{
QString strTemp = elem.attribute("id");
WDomElem * welem = m_pMainWindow->m_treemodel.getElemByName(strTemp);
// check if valid parent
if (welem)
{
return elem;
}
else
{
QWebElement welemTemp = elem.parent();
return FindCloserWidget(welemTemp);
}
}
示例7: createWebElementStruct
WebElementStruct PhpWebView::createWebElementStruct(QWebElement elem, int i)
{
WebElementStruct we;
we.el = elem;
we.position = elem.styleProperty("position", QWebElement::ComputedStyle);
we.z_index = 0;
we.i = i;
QWebElement cur = elem;
while (!cur.isNull())
{
QString z = cur.styleProperty("z-index", QWebElement::ComputedStyle);
bool res;
int zi = z.toInt(&res);
if (res)
{
we.z_index = zi;
break;
}
cur = cur.parent();
}
cur = elem;
while (!cur.isNull())
{
QString pos = cur.styleProperty("position", QWebElement::ComputedStyle);
if (pos != "inherit")
{
we.position = pos;
break;
}
cur = cur.parent();
}
return we;
}
示例8: render
void tdRenderer::render(QByteArray ba)
{
bufreset(m_buffer);
QWebElement element = m_body.findFirst(".__tmp__");
const char *data = ba.data();
uint beg = 0;
size_t e = ba.size();
int prevsize = 0;
int pos = m_fframe;
while (beg < e) {
const char *offs = data + beg;
int n = td_markdown_render(m_buffer, (const uint8_t *) offs,
e - beg, m_markdown);
QByteArray bytes((const char *) m_buffer->data + prevsize, m_buffer->size - prevsize);
m_sizes.insert(pos, n);
m_indices.insert(pos++, m_index);
if (m_pants) {
bufreset(m_tmpbuffer);
sdhtml_smartypants(m_tmpbuffer, (const uint8_t *) bytes.constData(), bytes.size());
QByteArray pants((const char *) m_tmpbuffer->data, m_tmpbuffer->size);
element.appendInside(pants);
} else {
element.appendInside(bytes);
}
QWebElementCollection children = element.findAll("*");
QString klassName = "__" % QString::number(m_index++) % "__";
QWebElementCollection::const_iterator i = children.constBegin();
for (; i != children.constEnd(); ++i) {
QWebElement e = *i;
e.addClass(klassName);
if (!e.parent().hasClass(klassName))
element.prependOutside(e.takeFromDocument());
}
if (m_body.findFirst("." % klassName).isNull())
element.prependOutside("<span class=\"" % klassName % "\"></span>");
beg += n;
prevsize = m_buffer->size;
}
element.takeFromDocument();
}
示例9: findTreeItemAndSelect
QTreeWidgetItem* XPathInspector::findTreeItemAndSelect(const QWebElement & elem)
{
QList<QWebElement> patharr;
QWebElement current = elem;
while (!current.isNull())
{
patharr.prepend(current);
current = current.parent();
}
QTreeWidgetItem *topitem = NULL;
for (int i=0; i<tree->topLevelItemCount(); i++)
{
QTreeWidgetItem *item = tree->topLevelItem(i);
QWebElement node = item->data(0, Qt::UserRole).value<QWebElement>();
if (node == patharr.at(0))
{
tree->expandItem(item);
topitem = item;
break;
}
}
for (int i=1; i<patharr.count(); i++)
{
if (topitem != NULL)
{
for (int j=0; j<topitem->childCount(); j++)
{
QWebElement node = topitem->child(j)->data(0, Qt::UserRole).value<QWebElement>();
if (patharr.at(i) == node)
{
topitem = topitem->child(j);
tree->expandItem(topitem);
break;
}
}
}
}
topitem->setSelected(true);
return topitem;
}
示例10: 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();
}
示例11: addEngineFromForm
void SearchEnginesManager::addEngineFromForm(const QWebElement &element, WebView* view)
{
QWebElement formElement = element.parent();
while (!formElement.isNull()) {
if (formElement.tagName().toLower() == QLatin1String("form")) {
break;
}
formElement = formElement.parent();
}
if (formElement.isNull()) {
return;
}
const QString method = formElement.hasAttribute("method") ? formElement.attribute("method").toUpper() : "GET";
bool isPost = method == QLatin1String("POST");
QUrl actionUrl = QUrl::fromEncoded(formElement.attribute("action").toUtf8());
if (actionUrl.isRelative()) {
actionUrl = view->url().resolved(actionUrl);
}
QUrl parameterUrl = actionUrl;
if (isPost) {
parameterUrl = QUrl("http://foo.bar");
}
#if QT_VERSION >= 0x050000
QUrlQuery query(parameterUrl);
query.addQueryItem(element.attribute("name"), "%s");
QWebElementCollection allInputs = formElement.findAll("input");
foreach (QWebElement e, allInputs) {
if (element == e || !e.hasAttribute("name")) {
continue;
}
query.addQueryItem(e.attribute("name"), e.evaluateJavaScript("this.value").toString());
}
parameterUrl.setQuery(query);
#else
QList<QPair<QByteArray, QByteArray> > queryItems;
QPair<QByteArray, QByteArray> item;
item.first = element.attribute("name").toUtf8();
item.second = "%s";
queryItems.append(item);
QWebElementCollection allInputs = formElement.findAll("input");
foreach (QWebElement e, allInputs) {
if (element == e || !e.hasAttribute("name")) {
continue;
}
QPair<QByteArray, QByteArray> item;
item.first = QUrl::toPercentEncoding(e.attribute("name").toUtf8());
item.second = QUrl::toPercentEncoding(e.evaluateJavaScript("this.value").toByteArray());
queryItems.append(item);
}
parameterUrl.setEncodedQueryItems(parameterUrl.encodedQueryItems() + queryItems);
#endif
if (!isPost) {
actionUrl = parameterUrl;
}
SearchEngine engine;
engine.name = view->title();
engine.icon = view->icon();
engine.url = actionUrl.toEncoded();
if (isPost) {
QByteArray data = parameterUrl.toEncoded(QUrl::RemoveScheme);
engine.postData = data.contains('?') ? data.mid(data.lastIndexOf('?') + 1) : QByteArray();
}
EditSearchEngine dialog(SearchEnginesDialog::tr("Add Search Engine"), view);
dialog.setName(engine.name);
dialog.setIcon(engine.icon);
dialog.setUrl(engine.url);
dialog.setPostData(engine.postData);
if (dialog.exec() != QDialog::Accepted) {
return;
}
engine.name = dialog.name();
engine.icon = dialog.icon();
engine.url = dialog.url();
engine.shortcut = dialog.shortcut();
engine.postData = dialog.postData().toUtf8();
if (engine.name.isEmpty() || engine.url.isEmpty()) {
return;
//.........这里部分代码省略.........
示例12: highliteElementAtPos
void WBWebTrapWebView::highliteElementAtPos ( const QPoint& pos)
{
mCurrentContentType = Unknown;
if(page() && page()->currentFrame())
{
QWebHitTestResult htr = page()->currentFrame()->hitTestContent (pos);
QRect pageHtr = htr.boundingRect().translated(htr.frame()->pos());
QRect updateRect = mWebViewElementRect.united(pageHtr);
updateRect = updateRect.adjusted(-8, -8, 8, 8);
mDomElementRect = htr.boundingRect();
if (!htr.pixmap().isNull())
{
mCurrentContentType = Image;
qDebug() << "found pixmap at " << htr.boundingRect();
}
else
{
QWebElement element = htr.element();
QString tagName = element.tagName().toLower();
if (tagName == "object"
|| tagName == "embed")
{
mCurrentContentType = ObjectOrEmbed;
}
else if ((tagName == "input") || (tagName == "textarea"))
{
QString ec = potentialEmbedCodeAtPos(pos);
if (ec.length() > 0)
{
qDebug() << "found input data \n\n" << ec;
mCurrentContentType = Input;
}
}
else
{
QString tagName = htr.element().tagName();
QString id = htr.element().attribute("id", "");
QWebElement el = htr.element();
QString idSelector = tagName + "#" + id;
bool idSuccess = (el == el.document().findFirst(idSelector));
if (idSuccess)
{
mElementQuery = idSelector;
mCurrentContentType = ElementByQuery;
}
else
{
//bool isValid = true;
QWebElement elParent = el.parent();
QWebElement currentEl = el;
QString path = tagName;
QStringList pathElements;
do
{
QWebElement someSibling = elParent.firstChild();
int index = 0;
bool foundIndex = false;
do
{
if (someSibling.tagName() == currentEl.tagName())
{
if (someSibling == currentEl)
{
foundIndex = true;
}
else
index++;
}
someSibling = someSibling.nextSibling();
}
while(!someSibling.isNull() && !foundIndex);
QString part;
if (index > 0)
part = QString("%1:nth-child(%2)").arg(currentEl.tagName()).arg(index);
else
part = currentEl.tagName();
pathElements.insert(0, part);
currentEl = elParent;
elParent = elParent.parent();
} while(!elParent.isNull());
//QString idSelector = tagName + "#" + id;
//.........这里部分代码省略.........
示例13: parseMarkdown
void tdRenderer::parseMarkdown(int at, int removed, int added)
{
QTextCursor cursor = m_editor->textCursor();
cursor.beginEditBlock();
int steps = m_editor->document()->availableUndoSteps();
bool undoStepsChanged = (steps != m_undoSteps);
m_undoSteps = steps;
if (undoStepsChanged && !m_isUndoRedo)
m_undoStack->push(new tdRendererCursorCommand(this, at, removed, added));
m_isUndoRedo = false;
int start;
int end;
if (m_sizes.isEmpty()) {
start = end = 0;
} else {
int i = 0, n = 0;
while (i < m_fframe)
n += m_sizes.at(i++);
start = n;
while (i <= m_lframe)
n += m_sizes.at(i++);
end = n;
}
int diff = added - removed;
m_count += diff;
if (m_sizes.isEmpty()) end = m_count;
else end += diff;
cursor.setPosition(start);
cursor.setPosition(qMin(end, m_count), QTextCursor::KeepAnchor);
int c = m_fframe;
int klass = 0;
QWebElementCollection collection;
while (c++ <= m_lframe && !m_sizes.isEmpty()) {
m_sizes.takeAt(m_fframe);
klass = m_indices.takeAt(m_fframe);
collection.append(m_body.findAll(".__" % QString::number(klass) % "__"));
}
QList<QWebElement> list = collection.toList();
QWebElement element;
if (klass) {
QString k = "__" % QString::number(klass) % "__";
element = list.last();
while (element.parent().hasClass(k))
element = element.parent();
list.removeAll(element);
element.setOuterXml("<div class=\"__tmp__\"></div>");
QList<QWebElement>::iterator i = list.begin();
for (; i != list.end(); ++i)
i->takeFromDocument();
} else {
m_body.prependInside("<div class=\"__tmp__\"></div>");
}
render(cursor.selection().toPlainText().toAscii());
cursor.endEditBlock();
updateFrameInterval();
emit parsingDone();
}
示例14: showContextMenu
void QtWebKitWebWidget::showContextMenu(const QPoint &position)
{
if (position.isNull() && m_webView->selectedText().isEmpty())
{
return;
}
const QPoint hitPosition = (position.isNull() ? m_webView->mapFromGlobal(QCursor::pos()) : position);
MenuFlags flags = NoMenu;
m_hitResult = m_webView->page()->frameAt(hitPosition)->hitTestContent(hitPosition);
if (m_hitResult.element().tagName().toLower() == QLatin1String("textarea") || m_hitResult.element().tagName().toLower() == QLatin1String("select") || (m_hitResult.element().tagName().toLower() == QLatin1String("input") && (m_hitResult.element().attribute(QLatin1String("type")).isEmpty() || m_hitResult.element().attribute(QLatin1String("type")).toLower() == QLatin1String("text"))))
{
QWebElement parentElement = m_hitResult.element().parent();
while (!parentElement.isNull() && parentElement.tagName().toLower() != QLatin1String("form"))
{
parentElement = parentElement.parent();
}
if (!parentElement.isNull() && parentElement.hasAttribute(QLatin1String("action")) && !parentElement.findFirst(QLatin1String("input[name], select[name], textarea[name]")).isNull())
{
flags |= FormMenu;
}
}
if (m_hitResult.pixmap().isNull() && m_hitResult.isContentSelected() && !m_webView->selectedText().isEmpty())
{
updateSearchActions(m_searchEngine);
flags |= SelectionMenu;
}
if (m_hitResult.linkUrl().isValid())
{
flags |= LinkMenu;
}
if (!m_hitResult.pixmap().isNull())
{
flags |= ImageMenu;
const bool isImageOpened = getUrl().matches(m_hitResult.imageUrl(), (QUrl::NormalizePathSegments | QUrl::RemoveFragment | QUrl::StripTrailingSlash));
getAction(OpenImageInNewTabAction)->setEnabled(!isImageOpened);
getAction(InspectElementAction)->setEnabled(!isImageOpened);
}
if (m_hitResult.mediaUrl().isValid())
{
flags |= MediaMenu;
const bool isVideo = (m_hitResult.element().tagName().toLower() == QLatin1String("video"));
const bool isPaused = m_hitResult.element().evaluateJavaScript(QLatin1String("this.paused")).toBool();
const bool isMuted = m_hitResult.element().evaluateJavaScript(QLatin1String("this.muted")).toBool();
getAction(SaveMediaToDiskAction)->setText(isVideo ? tr("Save Video...") : tr("Save Audio..."));
getAction(CopyMediaUrlToClipboardAction)->setText(isVideo ? tr("Copy Video Link to Clipboard") : tr("Copy Audio Link to Clipboard"));
getAction(ToggleMediaControlsAction)->setText(tr("Show Controls"));
getAction(ToggleMediaLoopAction)->setText(tr("Looping"));
getAction(ToggleMediaPlayPauseAction)->setIcon(Utils::getIcon(isPaused ? QLatin1String("media-playback-start") : QLatin1String("media-playback-pause")));
getAction(ToggleMediaPlayPauseAction)->setText(isPaused ? tr("Play") : tr("Pause"));
getAction(ToggleMediaMuteAction)->setIcon(Utils::getIcon(isMuted ? QLatin1String("audio-volume-medium") : QLatin1String("audio-volume-muted")));
getAction(ToggleMediaMuteAction)->setText(isMuted ? tr("Unmute") : tr("Mute"));
}
if (m_hitResult.isContentEditable())
{
flags |= EditMenu;
getAction(ClearAllAction)->setEnabled(getAction(SelectAllAction)->isEnabled());
}
if (flags == NoMenu || flags == FormMenu)
{
flags |= StandardMenu;
if (m_hitResult.frame() != m_webView->page()->mainFrame())
{
flags |= FrameMenu;
}
}
WebWidget::showContextMenu(hitPosition, flags);
}
示例15: triggerAction
void QtWebKitWebWidget::triggerAction(WindowAction action, bool checked)
{
const QWebPage::WebAction webAction = mapAction(action);
if (webAction != QWebPage::NoWebAction)
{
m_webView->triggerPageAction(webAction, checked);
return;
}
switch (action)
{
case RewindBackAction:
m_webView->page()->history()->goToItem(m_webView->page()->history()->itemAt(0));
break;
case RewindForwardAction:
m_webView->page()->history()->goToItem(m_webView->page()->history()->itemAt(m_webView->page()->history()->count() - 1));
break;
case CopyAddressAction:
QApplication::clipboard()->setText(getUrl().toString());
break;
case ZoomInAction:
setZoom(qMin((getZoom() + 10), 10000));
break;
case ZoomOutAction:
setZoom(qMax((getZoom() - 10), 10));
break;
case ZoomOriginalAction:
setZoom(100);
break;
case ReloadOrStopAction:
if (isLoading())
{
triggerAction(StopAction);
}
else
{
triggerAction(ReloadAction);
}
break;
case OpenLinkInNewTabAction:
if (m_hitResult.linkUrl().isValid())
{
emit requestedOpenUrl(m_hitResult.linkUrl(), false, false);
}
break;
case OpenLinkInNewTabBackgroundAction:
if (m_hitResult.linkUrl().isValid())
{
emit requestedOpenUrl(m_hitResult.linkUrl(), true, false);
}
break;
case OpenLinkInNewWindowAction:
if (m_hitResult.linkUrl().isValid())
{
emit requestedOpenUrl(m_hitResult.linkUrl(), false, true);
}
break;
case OpenLinkInNewWindowBackgroundAction:
if (m_hitResult.linkUrl().isValid())
{
emit requestedOpenUrl(m_hitResult.linkUrl(), true, true);
}
break;
case BookmarkLinkAction:
if (m_hitResult.linkUrl().isValid())
{
emit requestedAddBookmark(m_hitResult.linkUrl(), m_hitResult.element().attribute(QLatin1String("title")));
}
break;
case OpenSelectionAsLinkAction:
emit requestedOpenUrl(m_webView->selectedText(), false, false);
break;
case ImagePropertiesAction:
{
ImagePropertiesDialog dialog(m_hitResult.imageUrl(), m_hitResult.element().attribute(QLatin1String("alt")), m_hitResult.element().attribute(QLatin1String("longdesc")), m_hitResult.pixmap(), (m_networkAccessManager->cache() ? m_networkAccessManager->cache()->data(m_hitResult.imageUrl()) : NULL), this);
QEventLoop eventLoop;
m_parent->showDialog(&dialog);
connect(&dialog, SIGNAL(finished(int)), &eventLoop, SLOT(quit()));
connect(this, SIGNAL(destroyed()), &eventLoop, SLOT(quit()));
eventLoop.exec();
m_parent->hideDialog(&dialog);
//.........这里部分代码省略.........