QList <QWebElement> ChromeDOM::getInitialElements() { m_renderer->clearRenderList(); QWebElement test = getElementById("TestTableCell9"); //qDebug() << "TEST ELEMENT:" << test.toPlainText(); m_height = 0; QWebElement doc = m_page->mainFrame()->documentElement(); #if QT_VERSION < 0x040600 //TBD: Do we care, given that the dom api is not officially supported before 4.6? return doc.findAll(".GinebraSnippet"); #else return doc.findAll(".GinebraSnippet").toList(); #endif }
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(); } }
void FilmwebProvider::queryLoadFinished(bool ok) { timeout->stop(); if (ok) { QWebElement document = webPage->mainFrame()->documentElement(); QWebElementCollection links = document.findAll("li.searchResult"); foreach (QWebElement e, links) { if (e.findFirst("span.searchResultTypeAlias").toPlainText() == "film" || e.findFirst("span.searchResultTypeAlias").toPlainText() == "TV") { QString plainName = e.findFirst("a.searchResultTitle").toPlainText(); QStringList name = plainName.split(QRegExp(" / "), QString::SkipEmptyParts); QString plainDetails = e.findFirst("div.searchResultDetails").toPlainText(); QStringList details = plainDetails.split(QRegExp(" | "), QString::SkipEmptyParts); resultsModel->appendRow(new ResultsItem(name[0], (name.size() > 1) ? (name[1]) : (QString("")), details[0], "http://www.filmweb.pl" + e.findFirst("a.searchResultTitle").attribute("href"))); } } } else
void PIM_Handler::pageLoadFinished() { WebPage* page = qobject_cast<WebPage*>(sender()); if (!page) { return; } if (!m_loaded) { loadSettings(); } const QWebElement document = page->mainFrame()->documentElement(); const QWebElementCollection elements = document.findAll("input[type=\"text\"]"); foreach (QWebElement element, elements) { const QString name = element.attribute("name"); if (name.isEmpty()) { continue; } PI_Type match = nameMatch(name); if (match != PI_Invalid) { element.setStyleProperty("-webkit-appearance", "none"); element.setStyleProperty("-webkit-box-shadow", "inset 0 0 2px 1px #EEE000"); } } }
bool PIM_Handler::keyPress(WebView* view, QKeyEvent* event) { if (!view) { return false; } bool isEnter = event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter; bool isControlModifier = event->modifiers() & Qt::ControlModifier; if (!isEnter || !isControlModifier) { return false; } const QWebElement document = view->page()->mainFrame()->documentElement(); const QWebElementCollection elements = document.findAll("input[type=\"text\"]"); foreach (QWebElement element, elements) { const QString name = element.attribute("name"); if (name.isEmpty()) { continue; } PI_Type match = nameMatch(name); if (match != PI_Invalid) { element.evaluateJavaScript(QString("this.value = \"%1\"").arg(m_allInfo[match])); } } return true; }
void MangaherePlugin::downloadedMangaList(bool ok) { if(!ok) { qDebug() << tr("There was an error loading the manga list from host 'www.mangahere.co'."); return; } //MangaList successfully downloaded, processing the HTML... m_mangaListLoaded = true; m_mangaList.clear(); QWebElement element = m_pPageMangaList.mainFrame()->documentElement(); QWebElementCollection collAllMangas = element.findAll(".manga_info"); qDebug() << "Sample Manga:" << collAllMangas.at(0).toPlainText() << " url(" << collAllMangas.at(0).attribute("href", "ERROR") << ")"; int i = 0; foreach (QWebElement oneManga, collAllMangas) { qApp->processEvents(QEventLoop::ExcludeUserInputEvents); Manga::Simple manga; manga.title = oneManga.toPlainText(); manga.url = oneManga.attribute("href", "ERROR"); m_mangaList << manga; i++; }
void MainWindow::_loadFinished(bool ok) { if (ok) { QString indexUrl = _appSettings.host(); indexUrl += "index.php"; QString pageUrl = ui->webView->url().toString(); QWebPage* page = ui->webView->page(); QWebFrame* frame = page->currentFrame(); QWebElement root = frame->documentElement(); if (!root.findFirst("#loginForm").isNull()) { QWebElementCollection allInputs = root.findAll("input"); foreach (QWebElement inputElement, allInputs) { if (inputElement.hasAttribute("name")) { QString name = inputElement.attribute("name"); if (name == "username") { inputElement.setAttribute("value", _appSettings.user()); } else if (name == "password") { inputElement.setAttribute("value", _appSettings.password()); } } } root.findFirst("input[type=submit]").evaluateJavaScript("this.click()"); } else if (pageUrl == indexUrl)
void MainWindow::exportSelected(const QString &filename) { QWebElement element = ui->webViewResults->page()->mainFrame()->documentElement().clone(); QWebElementCollection nodes; nodes = element.findAll("html > head > script, html > head > link, #spacer, #intro, #templates"); foreach (QWebElement node, nodes) node.removeFromDocument(); nodes = element.findAll(".selected, .unselected"); foreach (QWebElement node, nodes) { node.removeClass("selected"); node.removeClass("unselected"); }
foreach (const QWebElement &selectField, selectFields) { QString name = selectField.attribute(QLatin1String("name")); int selectedIndex = selectField.scriptableProperty(QLatin1String("selectedIndex")).toInt(); if (selectedIndex == -1) continue; QList<QWebElement> options = selectField.findAll(QLatin1String("option")); QString value = options.at(selectedIndex).toPlainText(); searchUrl.addQueryItem(name, value); }
foreach (QWebElement selectField, selectFields) { QString name = selectField.attribute(QLatin1String("name")); int selectedIndex = selectField.evaluateJavaScript(QLatin1String("this.selectedIndex")).toInt(); if (selectedIndex == -1) continue; QWebElementCollection options = selectField.findAll(QLatin1String("option")); QString value = options.at(selectedIndex).toPlainText(); searchUrl.addQueryItem(name, value); }
void SexpRenderer::render() { QWebElement document = page.currentFrame()->documentElement(); QWebElementCollection allSpans = document.findAll("span"); for (auto span : allSpans) { std::cout << "found span!" << std::endl; } emit finished(); }
void HtmlThread::run() { Helper::Download(this->url); QWebElement root; QString flag("False"); emit this->ParseHtml(this->getUrl(),root,flag); while("True"==flag){break;} QWebElementCollection items; items = root.findAll("table"); qDebug()<<items.count(); }
void TranslationHandler::onMultipleGenerationFinished(bool ok) { Request *req = m_pendingRequests.take(sender()); if (ok && req) { QMultiMap<Type,QString> words; QWebElement table = req->webFrame()->findFirstElement("table"); QWebElementCollection items = table.findAll("li"); foreach (const QWebElement &item, items) words.insert(Any, item.toPlainText()); emit generated(words); } else {
void FakePluginWidget::load (bool loadAll) { QWebView *view = webViewFrom(parentWidget()); if (!view) return; // WORKAROUND: For some reason, when we load on demand plugins the scroll // position gets utterly screwed up and reset to the beginning of the // document. This is an effort to workaround that issue. connect(view->page(), SIGNAL(scrollRequested(int,int,QRect)), this, SLOT(updateScrollPoisition(int,int,QRect)), Qt::QueuedConnection); hide(); m_swapping = true; QList<QWebFrame*> frames; frames.append(view->page()->mainFrame()); QString selector (QLatin1String("applet:not([type]),embed:not([type]),object:not([type]),applet[type=\"")); selector += m_mimeType; selector += QLatin1String("\"],embed[type=\""); selector += m_mimeType; selector += QLatin1String("\"],object[type=\""); selector += m_mimeType; selector += QLatin1String("\"]"); while (!frames.isEmpty()) { bool loaded = false; QWebFrame *frame = frames.takeFirst(); QWebElement docElement = frame->documentElement(); QWebElementCollection elements = docElement.findAll(selector); Q_FOREACH (QWebElement element, elements) { if (loadAll || element.evaluateJavaScript(QLatin1String("this.swapping")).toBool()) { QWebElement substitute = element.clone(); emit pluginLoaded(m_id); m_updateScrollPosition = true; element.replace(substitute); deleteLater(); if (!loadAll) { loaded = true; break; // Found the one plugin we wanted to start so exit loop. } } } if (loaded && !loadAll) { break; // Loading only one item, exit the outer loop as well... } frames += frame->childFrames(); } m_swapping = false; }
//! [return pressed] void Window::on_elementLineEdit_returnPressed() { QWebFrame *frame = webView->page()->mainFrame(); //! [select elements] QWebElement document = frame->documentElement(); QWebElementCollection elements = document.findAll(elementLineEdit->text()); //! [select elements] foreach (QWebElement element, elements) element.setAttribute("style", "background-color: #f0f090"); }
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); } }
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(); }
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; }
void CWebNewsLoader::on_webPageLoadFinished(bool res) { if (res) { QWebFrame *frame = m_webView->page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElementCollection elements = document.findAll("li a"); QStringList newsList; foreach (QWebElement element, elements) newsList.append(element.toPlainText()); emit newsListLoadFinished(m_webView->url().toString(), newsList); } delete m_webView; }
void downloader::render(QString rawHtml) { currencyLoaded.clear(); rateLoaded.clear(); QWebFrame *mainFrame = webPage.mainFrame(); mainFrame->setHtml(rawHtml); QWebElement documentElement = mainFrame->documentElement(); QWebElementCollection elements = documentElement.findAll("#content > div:nth-child(1) > div > div.col2.pull-right.module.bottomMargin > div.moduleContent > table:nth-child(4) > tbody > tr"); int i = 0; foreach (QWebElement element, elements) { currency.push_back(element.findFirst("td:nth-child(1)").toInnerXml()); rate.push_back(element.findFirst("td:nth-child(3) > a").toInnerXml()); // qDebug()<< currency[i+(elements.count()*downloadCount)]+"\t\t"+rate[i+(elements.count()*downloadCount)]+"\n"; currencyLoaded.push_back(currency[i+(elements.count()*downloadCount)]); rateLoaded.push_back(rate[i+(elements.count()*downloadCount)]); i++; }
void CustomWebPage::handleLoadFinished (bool ok) { QWebElement body = mainFrame ()->findFirstElement ("body"); if (body.findAll ("*").count () == 1 && body.firstChild ().tagName () == "IMG") mainFrame ()->evaluateJavaScript ("function centerImg() {" "var img = document.querySelector('img');" "img.style.left = Math.floor((document.width - img.width) / 2) + 'px';" "img.style.top = Math.floor((document.height - img.height) / 2) + 'px';" "img.style.position = 'absolute';" "}" "window.addEventListener('resize', centerImg, false);" "centerImg();"); Util::DefaultHookProxy_ptr proxy (new Util::DefaultHookProxy ()); emit hookLoadFinished (proxy, this, ok); if (proxy->IsCancelled ()) return; emit delayedFillForms (mainFrame ()); }
void CadastreWrapper::networkFinished(QNetworkReply *reply) { if (m_pendingTiles.contains(reply)) { QFile target(m_pendingTiles[reply]); QByteArray ba = reply->readAll(); // white -> transparent QImage img; img.loadFromData(ba); QImage img2 = img.convertToFormat(QImage::Format_ARGB32); Q_ASSERT(img2.hasAlphaChannel()); int w=0; for (int y=0; y<img2.height(); ++y) { for (int x=0; x<img2.width(); ++x) { QColor col = QColor(img2.pixel(x, y)); if (col == QColor(255, 255, 255)) { col.setAlpha(0); img2.setPixel(x, y, col.rgba()); ++w; } } } //Full transparent if (w == img2.height()*img2.width()) { img2 = QImage(1, 1, QImage::Format_ARGB32); img2.setPixel(0, 0, QColor(0, 0, 0, 0).rgba()); } target.open(QIODevice::WriteOnly); // target.write(reply->readAll()); img2.save(&target, "PNG"); target.close(); m_pendingTiles.remove(reply); if (m_progress) { m_progress->setValue(m_progress->value()+1); if (m_progress->value() > 10) { double ms = m_startTime.secsTo(QDateTime::currentDateTime()); double us = ms/m_progress->value(); int tot = us*(m_progress->maximum() - m_progress->value()); if (tot<3600) m_progress->setLabelText(tr("Downloaded: %1/%2\nRemaining time: %3:%4").arg(m_progress->value()).arg(m_progress->maximum()).arg(int(tot/60)).arg(int(tot%60), 2, 10, QChar('0'))); else m_progress->setLabelText(tr("Downloaded: %1/%2\nRemaining time: %3:%4:%5").arg(m_progress->value()).arg(m_progress->maximum()).arg(int(tot/3600)).arg(int((tot%3600)/60), 2, 10, QChar('0')).arg(int(tot%60), 2, 10, QChar('0'))); } else m_progress->setLabelText(tr("Downloaded: %1/%2").arg(m_progress->value()).arg(m_progress->maximum())); } } else if (reply->url() == QUrl("http://www.cadastre.gouv.fr/scpc/accueil.do")) { qDebug() << "Ok, I've got a cookie... I LOVE COOKIES."; reply->readAll(); m_gotCookie = true; } else if (reply->url() == QUrl("http://www.cadastre.gouv.fr/scpc/rechercherPlan.do")) { QString pageData = reply->readAll(); qDebug() << pageData; QWebPage parsedPage(this); QWebFrame *frame = parsedPage.mainFrame(); frame->setHtml(pageData); QWebElement codeCommune = frame->findFirstElement("#codeCommune"); QMap<QString, QString> results; if (!codeCommune.isNull()) { // If there is a codeCommune object in the DOM, it means that the search was not successfull. if (codeCommune.tagName().toLower() != "select") { qDebug() << "Invalid page ???"; return; } QWebElementCollection options = codeCommune.findAll("option"); foreach (QWebElement option, options) { if (!option.attribute("value").isEmpty()) results[option.attribute("value")] = option.toPlainText(); } } else {
void DivBoxLevel::makeElementBoxes( const QWebElement &document, Ogre::Real scale, std::vector<QString> tags, Ogre::String meshName, Ogre::SceneManager * sceneManager) { DotSceneLoader* pDotSceneLoader = new DotSceneLoader(); pDotSceneLoader->parseDotScene("papercraft_man_line_running.scene", "General", sceneManager, sceneManager->getRootSceneNode()); delete pDotSceneLoader; Animation::Instance().animationStates.clear(); Animation::Instance().init(sceneManager, "arm_left"); Animation::Instance().init(sceneManager, "arm_right"); Animation::Instance().init(sceneManager, "chest"); Animation::Instance().init(sceneManager, "leg_left"); Animation::Instance().init(sceneManager, "leg_right"); Animation::Instance().init(sceneManager, "pants"); QWebElementCollection elements; foreach(QString tag, tags) elements.append(document.findAll(tag)); Ogre::Vector3 position = Ogre::Vector3(0.0, 1000.0, 0.0); int elementCount = 0; foreach(QWebElement element, elements) { if (fits(&element, 10, 4096)) { Ogre::String textureName = "PageTex" + element.tagName().toStdString() + Ogre::StringConverter::toString(elementCount); Box box; box.width = element.geometry().width()*scale; box.height = element.geometry().height()*scale; box.sceneNode = sceneManager->createSceneNode(textureName); element.setStyleProperty("background-color", "white"); Ogre::Entity* cube = sceneManager->createEntity(meshName); makeOgreImage(&element, textureName); Ogre::MaterialPtr material = makeMaterial("PageMat" + Ogre::StringConverter::toString(position), textureName, 1.3); cube->getSubEntity(1)->setMaterial(material); box.sceneNode->attachObject(cube); box.sceneNode->setScale(box.width, box.height, box.width); if (box.width > 50) bigBoxes.push_back(box); else if (box.width > 5) smallBoxes.push_back(box); elementCount++; } } int smallBoxIndex = 0; for (int i = 0; i < bigBoxes.size(); i++) { CollisionActor* actor = simulation->terrainFactory->createActor() ->addPoint(bigBoxes[i].width, bigBoxes[i].height) ->addPoint(-bigBoxes[i].width, -bigBoxes[i].height) ->createCollisionShape(CollisionShape2::DEF_AABB); if (i == 0) { // FIRST PLANE----------------------- actor->teleport(100.0, 100.0); characterSceneNode = simulation->characterFactory->createActor() ->addPoint(4.0, 30.0) ->addPoint(-4.0, -10.0) ->createCollisionShape(CollisionShape2::DEF_CONVEX) ->teleport(100.0, bigBoxes[i].height * 2 + 200.0) ->sceneNode; Ogre::SceneNode* sn = sceneManager->getSceneNode("Armature"); sceneManager->getRootSceneNode()->removeChild(sn); characterSceneNode->addChild(sn); sn->scale(0.4, 0.4, 0.4); sn->translate(0, 10, 0); sn->setOrientation( Ogre::Quaternion(Ogre::Degree(90.0), Ogre::Vector3::UNIT_Y)); } else { // FURTHER PLANES-------------------- float lX = bigBoxes[i - 1].sceneNode->_getDerivedPosition().x; float lY = bigBoxes[i - 1].sceneNode->_getDerivedPosition().y; float lW = bigBoxes[i - 1].width; float lH = bigBoxes[i - 1].height; float cX = bigBoxes[i].sceneNode->_getDerivedPosition().x; float cY = bigBoxes[i].sceneNode->_getDerivedPosition().y; float cW = bigBoxes[i].width; float cH = bigBoxes[i].height; if (cH - lH > 50.0 && smallBoxes.size() - 1 - smallBoxIndex > 1) { // current is mutch higher then last actor->teleport(lX + lW + cW, 100.0); float sX = smallBoxes[smallBoxIndex].sceneNode->_getDerivedPosition().x; float sY = smallBoxes[smallBoxIndex].sceneNode->_getDerivedPosition().y; float sW = smallBoxes[smallBoxIndex].width; float sH = smallBoxes[smallBoxIndex].height; CollisionActor* hoverplane = simulation->hoverplaneFactory ->createActor() ->addPoint(sW, sH) ->addPoint(-sW, -sH) ->createCollisionShape(CollisionShape2::DEF_AABB); static_cast<Hoverplane*>(hoverplane) ->setSpeed(0.2 + static_cast<float> (static_cast<int>(lX * cX * cW) % 5) * 0.1) ->setPath(lX + lW - sW - 100.0, lY + lH - sH + 10.0, lX + lW - sW - 100.0, lY + lH - sH + cH - lH); hoverplane->sceneNode->addChild(smallBoxes[smallBoxIndex].sceneNode); smallBoxIndex++; } else { if (lH - cH > 50.0 && smallBoxes.size() - 1 - smallBoxIndex > 1) { actor->teleport(lX + lW + cW, 100.0); float sX = smallBoxes[smallBoxIndex].sceneNode-> _getDerivedPosition().x; float sY = smallBoxes[smallBoxIndex].sceneNode-> _getDerivedPosition().y; float sW = smallBoxes[smallBoxIndex].width; float sH = smallBoxes[smallBoxIndex].height; CollisionActor* hoverplane = simulation->hoverplaneFactory ->createActor() ->addPoint(sW, sH) ->addPoint(-sW, -sH) ->createCollisionShape(CollisionShape2::DEF_AABB); static_cast<Hoverplane*>(hoverplane) ->setSpeed(0.2 + static_cast<float> (static_cast<int>(lX * cX * cW) % 5) * 0.1) ->setPath(cX, cY + cH + sH + 10.0, cX, cY + cH + sH + lH); hoverplane->sceneNode->addChild(smallBoxes[smallBoxIndex].sceneNode); smallBoxIndex++; } else { if (i%3 == 2 && smallBoxes.size() - 1 - smallBoxIndex > 3) { actor->teleport(lX + lW + cW + smallBoxes[smallBoxIndex].sceneNode ->_getDerivedPosition().x + smallBoxes[smallBoxIndex+1].sceneNode ->_getDerivedPosition().x + smallBoxes[smallBoxIndex+2].sceneNode ->_getDerivedPosition().x + 400.0, 100.0); { float sX = smallBoxes[smallBoxIndex].sceneNode-> _getDerivedPosition().x; float sY = smallBoxes[smallBoxIndex].sceneNode-> _getDerivedPosition().y; float sW = smallBoxes[smallBoxIndex].width; float sH = smallBoxes[smallBoxIndex].height; CollisionActor* hoverplane = simulation->hoverplaneFactory ->createActor() ->addPoint(sW, sH) ->addPoint(-sW, -sH) ->createCollisionShape(CollisionShape2::DEF_AABB); static_cast<Hoverplane*>(hoverplane) ->setSpeed(0.1 + static_cast<float> (static_cast<int>(lX * cX * sW) % 5) * 0.1) ->setPath(lX + lW + 100.0, lY + lH - sH, lX + lW + 100.0, lY + lH + cH + 200.0); hoverplane->sceneNode ->addChild(smallBoxes[smallBoxIndex].sceneNode); } { float sX = smallBoxes[smallBoxIndex+1].sceneNode-> _getDerivedPosition().x; float sY = smallBoxes[smallBoxIndex+1].sceneNode-> _getDerivedPosition().y; float sW = smallBoxes[smallBoxIndex+1].width; float sH = smallBoxes[smallBoxIndex+1].height; CollisionActor* hoverplane = simulation->hoverplaneFactory ->createActor() ->addPoint(sW, sH) ->addPoint(-sW, -sH) ->createCollisionShape(CollisionShape2::DEF_AABB); static_cast<Hoverplane*>(hoverplane) ->setSpeed(0.2 + static_cast<float> (static_cast<int>(lX * cX * sW) % 5) * 0.1) ->setPath(lX + lW + 200.0, lY + lH - sH, lX + lW + 200.0, lY + lH + cH + 200.0); hoverplane->sceneNode ->addChild(smallBoxes[smallBoxIndex+1].sceneNode); } { float sX = smallBoxes[smallBoxIndex+2].sceneNode-> _getDerivedPosition().x; float sY = smallBoxes[smallBoxIndex+2].sceneNode-> _getDerivedPosition().y; float sW = smallBoxes[smallBoxIndex+2].width; float sH = smallBoxes[smallBoxIndex+2].height; CollisionActor* hoverplane = simulation->hoverplaneFactory ->createActor() ->addPoint(sW, sH) ->addPoint(-sW, -sH) ->createCollisionShape(CollisionShape2::DEF_AABB); static_cast<Hoverplane*>(hoverplane) ->setSpeed(0.15 + static_cast<float> (static_cast<int>(lX * cX * sW) % 5) * 0.1) ->setPath(lX + lW + 300.0, lY + lH - sH, lX + lW + 300.0, lY + lH + cH + 200.0); hoverplane->sceneNode ->addChild(smallBoxes[smallBoxIndex+2].sceneNode); } smallBoxIndex += 3; } else { actor->teleport(lX + lW + cW + 100.0, 100.0); } } } } actor->sceneNode->addChild(bigBoxes[i].sceneNode); qDebug() << "dooors" << doors.size() << "\n\n"; if ((i == (bigBoxes.size()-1) / 2 || i == bigBoxes.size()-1) && this->doors.size() >= 1) { CollisionActor* door; if (i == (bigBoxes.size()-1) / 2) { door = this->doors[0]; qDebug() << "dooors0\n\n\n\n\n"; } else { door = this->doors[0]; qDebug() << "dooors1\n\n\n\n\n"; } door ->addPoint(0.0, 0.0) ->addPoint(40., 60.) ->createCollisionShape(CollisionShape2::DEF_AABB) ->teleport( bigBoxes[i].sceneNode->_getDerivedPosition().x, bigBoxes[i].sceneNode->_getDerivedPosition().y + bigBoxes[i].height); Ogre::Entity* doorEntity = sceneManager->createEntity("door.mesh"); door->sceneNode->attachObject(doorEntity); door->sceneNode->setScale(20, 30, 20); door->sceneNode->setOrientation( Ogre::Quaternion(Ogre::Degree(180.0), Ogre::Vector3::UNIT_Y)); } } }
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; } addEngine(engine); }
void ClickToFlash::findElement() { if (!m_toolButton) { return; } QWidget* parent = parentWidget(); QWebView* view = 0; while (parent) { if (QWebView* aView = qobject_cast<QWebView*>(parent)) { view = aView; break; } parent = parent->parentWidget(); } if (!view) { return; } QPoint objectPos = view->mapFromGlobal(m_toolButton->mapToGlobal(m_toolButton->pos())); QWebFrame* objectFrame = view->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)) { m_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); m_mainFrame = view->page()->mainFrame(); frames.append(m_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; } m_element = element; return; } frames += frame->childFrames(); } }
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); } break; case InspectPageAction: if (!m_inspector) { m_inspector = new QWebInspector(this); m_inspector->setPage(m_webView->page()); m_inspector->setContextMenuPolicy(Qt::NoContextMenu); m_inspector->setMinimumHeight(200); m_splitter->addWidget(m_inspector); } m_inspector->setVisible(checked); getAction(InspectPageAction)->setChecked(checked); emit actionsChanged(); emit progressBarGeometryChanged(); break; case SaveLinkToDownloadsAction: TransfersManager::startTransfer(m_hitResult.linkUrl().toString(), QString(), isPrivate(), true); break; case OpenFrameInThisTabAction: if (m_hitResult.frame()) { setUrl(m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()); } break; case OpenFrameInNewTabBackgroundAction: if (m_hitResult.frame()) { emit requestedOpenUrl((m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()), true, false); } break; case CopyFrameLinkToClipboardAction: if (m_hitResult.frame()) { QGuiApplication::clipboard()->setText((m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()).toString()); } break; case ReloadFrameAction: if (m_hitResult.frame()) { const QUrl url = (m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()); m_hitResult.frame()->setUrl(QUrl()); m_hitResult.frame()->setUrl(url); } break; case SearchAction: search(getAction(SearchAction)); break; case CreateSearchAction: { QWebElement parentElement = m_hitResult.element().parent(); while (!parentElement.isNull() && parentElement.tagName().toLower() != "form") { parentElement = parentElement.parent(); } const QWebElementCollection inputs = parentElement.findAll(QLatin1String("input:not([disabled])[name], select:not([disabled])[name], textarea:not([disabled])[name]")); if (!parentElement.isNull() && parentElement.hasAttribute(QLatin1String("action")) && inputs.count() > 0) { QUrlQuery parameters; for (int i = 0; i < inputs.count(); ++i) { QString value; if (inputs.at(i).tagName().toLower() == QLatin1String("textarea")) { value = inputs.at(i).toPlainText(); } else if (inputs.at(i).tagName().toLower() == QLatin1String("select")) { const QWebElementCollection options = inputs.at(i).findAll(QLatin1String("option")); for (int j = 0; j < options.count(); ++j) { if (options.at(j).hasAttribute(QLatin1String("selected"))) { value = options.at(j).attribute(QLatin1String("value"), options.at(j).toPlainText()); break; } } } else { if ((inputs.at(i).attribute(QLatin1String("type")) == QLatin1String("checkbox") || inputs.at(i).attribute(QLatin1String("type")) == QLatin1String("radio")) && !inputs.at(i).hasAttribute(QLatin1String("checked"))) { continue; } value = inputs.at(i).attribute(QLatin1String("value")); } parameters.addQueryItem(inputs.at(i).attribute(QLatin1String("name")), ((inputs.at(i) == m_hitResult.element()) ? QLatin1String("{searchTerms}") : value)); } const QStringList identifiers = SearchesManager::getSearchEngines(); QStringList shortcuts; QList<SearchInformation*> engines; for (int i = 0; i < identifiers.count(); ++i) { SearchInformation *engine = SearchesManager::getSearchEngine(identifiers.at(i)); if (!engine) { continue; } engines.append(engine); const QString shortcut = engine->shortcut; if (!shortcut.isEmpty()) { shortcuts.append(shortcut); } } QString identifier = getUrl().host().toLower().remove(QRegularExpression(QLatin1String("[^a-z0-9]"))); while (identifier.isEmpty() || identifiers.contains(identifier)) { identifier = QInputDialog::getText(this, tr("Select Identifier"), tr("Input Unique Search Engine Identifier:")); if (identifier.isEmpty()) { return; } } const QIcon icon = m_webView->icon(); const QUrl url(parentElement.attribute(QLatin1String("action"))); QVariantHash engineData; engineData[QLatin1String("identifier")] = identifier; engineData[QLatin1String("isDefault")] = false; engineData[QLatin1String("encoding")] = QLatin1String("UTF-8"); engineData[QLatin1String("selfUrl")] = QString(); engineData[QLatin1String("resultsUrl")] = (url.isEmpty() ? getUrl() : (url.isRelative() ? getUrl().resolved(url) : url)).toString(); engineData[QLatin1String("resultsEnctype")] = parentElement.attribute(QLatin1String("enctype")); engineData[QLatin1String("resultsMethod")] = ((parentElement.attribute(QLatin1String("method"), QLatin1String("get")).toLower() == QLatin1String("post")) ? QLatin1String("post") : QLatin1String("get")); engineData[QLatin1String("resultsParameters")] = parameters.toString(QUrl::FullyDecoded); engineData[QLatin1String("suggestionsUrl")] = QString(); engineData[QLatin1String("suggestionsEnctype")] = QString(); engineData[QLatin1String("suggestionsMethod")] = QLatin1String("get"); engineData[QLatin1String("suggestionsParameters")] = QString(); engineData[QLatin1String("shortcut")] = QString(); engineData[QLatin1String("title")] = getTitle(); engineData[QLatin1String("description")] = QString(); engineData[QLatin1String("icon")] = (icon.isNull() ? Utils::getIcon(QLatin1String("edit-find")) : icon); SearchPropertiesDialog dialog(engineData, shortcuts, this); if (dialog.exec() == QDialog::Rejected) { return; } engineData = dialog.getEngineData(); if (shortcuts.contains(engineData[QLatin1String("shortcut")].toString())) { engineData[QLatin1String("shortcut")] = QString(); } SearchInformation *engine = new SearchInformation(); engine->identifier = engineData[QLatin1String("identifier")].toString(); engine->title = engineData[QLatin1String("title")].toString(); engine->description = engineData[QLatin1String("description")].toString(); engine->shortcut = engineData[QLatin1String("shortcut")].toString(); engine->encoding = engineData[QLatin1String("encoding")].toString(); engine->selfUrl = engineData[QLatin1String("selfUrl")].toString(); engine->resultsUrl.url = engineData[QLatin1String("resultsUrl")].toString(); engine->resultsUrl.enctype = engineData[QLatin1String("resultsEnctype")].toString(); engine->resultsUrl.method = engineData[QLatin1String("resultsMethod")].toString(); engine->resultsUrl.parameters = QUrlQuery(engineData[QLatin1String("resultsParameters")].toString()); engine->icon = engineData[QLatin1String("icon")].value<QIcon>(); engines.append(engine); if (SearchesManager::setSearchEngines(engines) && engineData[QLatin1String("isDefault")].toBool()) { SettingsManager::setValue(QLatin1String("Browser/DefaultSearchEngine"), engineData[QLatin1String("identifier")].toString()); } } } break; case ClearAllAction: triggerAction(SelectAllAction); triggerAction(DeleteAction); break; default: break; } }
void HtmlBookmarksImporter::processElement(const QWebElement &element) { if (element.tagName().toLower() == QLatin1String("h3")) { BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), element.toPlainText(), getCurrentFolder()); const QString keyword = element.attribute(QLatin1String("SHORTCUTURL")); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty()) { const QDateTime time = QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()); bookmark->setData(time, BookmarksModel::TimeAddedRole); bookmark->setData(time, BookmarksModel::TimeModifiedRole); } setCurrentFolder(bookmark); } else if (element.tagName().toLower() == QLatin1String("a")) { const QUrl url(element.attribute(QLatin1String("href"))); if (!allowDuplicates() && BookmarksManager::hasBookmark(url)) { return; } BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, url, element.toPlainText(), getCurrentFolder()); const QString keyword = element.attribute(QLatin1String("SHORTCUTURL")); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } if (element.parent().nextSibling().tagName().toLower() == QLatin1String("dd")) { bookmark->setData(element.parent().nextSibling().toPlainText(), BookmarksModel::DescriptionRole); } if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()), BookmarksModel::TimeAddedRole); } if (!element.attribute(QLatin1String("LAST_MODIFIED")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_MODIFIED")).toUInt()), BookmarksModel::TimeModifiedRole); } if (!element.attribute(QLatin1String("LAST_VISITED")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_VISITED")).toUInt()), BookmarksModel::TimeVisitedRole); } } else if (element.tagName().toLower() == QLatin1String("hr")) { BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder()); } const QWebElementCollection descendants = element.findAll(QLatin1String("*")); for (int i = 0; i < descendants.count(); ++i) { if (descendants.at(i).parent() == element) { processElement(descendants.at(i)); } } if (element.tagName().toLower() == QLatin1String("dl")) { goToParent(); } }