Exemple #1
0
void ScreenshotWidget::pixmapCapturedSlot(QPixmap pixmap)
{
	hide();

	emit pixmapCaptured(pixmap);
	deleteLater();
}
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);
    }
}