Commit 6bacb01a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add code to scroll webengine page

parent e9a8b35d
......@@ -62,6 +62,13 @@ TestWebEngineScrollAddAttachment::TestWebEngineScrollAddAttachment(QWidget *pare
void TestWebEngineScrollAddAttachment::handleScrollToAnchor(const QVariant &result)
{
qDebug() << " result "<<result;
if (result.isValid()) {
const QList<QVariant> lst = result.toList();
if (lst.count() == 2) {
const QPoint pos(lst.at(0).toInt(), lst.at(1).toInt());
mTestWebEngine->page()->runJavaScript(MessageViewer::WebEngineScript::scrollToPosition(pos));
}
}
}
void TestWebEngineScrollAddAttachment::slotScrollToAttachment()
......
......@@ -106,3 +106,10 @@ QString WebEngineScript::searchElementPosition(const QString &elementStr)
qDebug()<<" source "<<source;
return source;
}
QString WebEngineScript::scrollToPosition(const QPoint &pos)
{
const QString source = QString::fromLatin1("window.scrollTo(%1, %2); [window.scrollX, window.scrollY];").arg(pos.x()).arg(pos.y());
qDebug()<<" source "<<source;
return source;
}
......@@ -18,6 +18,7 @@
#define WEBENGINESCRIPT_H
#include <QString>
#include <QPoint>
#include "messageviewer_export.h"
namespace MessageViewer
......@@ -29,6 +30,7 @@ MESSAGEVIEWER_EXPORT QString findAllScripts();
MESSAGEVIEWER_EXPORT QString findAllAnchors();
MESSAGEVIEWER_EXPORT QString findAllAnchorsAndForms();
MESSAGEVIEWER_EXPORT QString searchElementPosition(const QString &elementStr);
MESSAGEVIEWER_EXPORT QString scrollToPosition(const QPoint &pos);
}
}
#endif // WEBENGINESCRIPT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment