Commit b51a413f authored by Laurent Montel's avatar Laurent Montel 😁

Add test application for scroll up/scroll down

parent f6f4bc1e
......@@ -15,10 +15,13 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "testmailwebengine.h"
#include "webengine/webenginescript.h"
#include <KActionCollection>
#include <QApplication>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWebEngineSettings>
#include <viewer/webengine/mailwebengineview.h>
......@@ -28,7 +31,19 @@ TestMailWebEngine::TestMailWebEngine(QWidget *parent)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
mTestWebEngine = new MessageViewer::MailWebEngineView(new KActionCollection(this), this);
mTestWebEngine->load(QUrl(QStringLiteral("http://www.kde.org")));
mTestWebEngine->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
vbox->addWidget(mTestWebEngine);
QHBoxLayout *hButtonBox = new QHBoxLayout;
vbox->addLayout(hButtonBox);
QPushButton *scrollUp = new QPushButton(QStringLiteral("scrollUp 10px"), this);
connect(scrollUp, &QPushButton::clicked, this, &TestMailWebEngine::slotScrollUp);
hButtonBox->addWidget(scrollUp);
QPushButton *scrollDown = new QPushButton(QStringLiteral("scrollDown 10px"), this);
connect(scrollDown, &QPushButton::clicked, this, &TestMailWebEngine::slotScrollDown);
hButtonBox->addWidget(scrollDown);
}
TestMailWebEngine::~TestMailWebEngine()
......@@ -36,6 +51,16 @@ TestMailWebEngine::~TestMailWebEngine()
}
void TestMailWebEngine::slotScrollDown()
{
mTestWebEngine->page()->runJavaScript(MessageViewer::WebEngineScript::scrollDown(10));
}
void TestMailWebEngine::slotScrollUp()
{
mTestWebEngine->page()->runJavaScript(MessageViewer::WebEngineScript::scrollUp(10));
}
int main(int argc, char *argv[])
{
......
......@@ -31,6 +31,10 @@ class TestMailWebEngine : public QWidget
public:
explicit TestMailWebEngine(QWidget *parent = Q_NULLPTR);
~TestMailWebEngine();
private Q_SLOTS:
void slotScrollUp();
void slotScrollDown();
private:
MessageViewer::MailWebEngineView *mTestWebEngine;
};
......
......@@ -126,13 +126,13 @@ QString WebEngineScript::searchElementPosition(const QString &elementStr)
QString WebEngineScript::scrollUp(int pixel)
{
const QString source = QString::fromLatin1("window.scrollBy(0, %1").arg(pixel);
const QString source = QString::fromLatin1("window.scrollBy(0, %1);").arg(-pixel);
return source;
}
QString WebEngineScript::scrollDown(int pixel)
{
const QString source = QString::fromLatin1("window.scrollBy(0, %1").arg(-pixel);
const QString source = QString::fromLatin1("window.scrollBy(0, %1);").arg(pixel);
return source;
}
......
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