diff options
author | Morten Sorvig <msorvig@trolltech.com> | 2009-08-25 07:08:18 +0200 |
---|---|---|
committer | Morten Sorvig <msorvig@trolltech.com> | 2009-08-25 07:08:18 +0200 |
commit | be92e5b92322e4cbc8386b3a098689c718e4a9af (patch) | |
tree | 10c68b62f337a3f305f4472b0e6bb9e4575772be | |
parent | 4c25d9ed3135a36780cbf517761670c0c0d87902 (diff) |
attempt sending input events to all webviews
-rw-r--r-- | loadtester/mainwindow.cpp | 22 | ||||
-rw-r--r-- | loadtester/mainwindow.h | 3 | ||||
-rw-r--r-- | loadtester/mainwindow.ui | 10 | ||||
-rw-r--r-- | src/eventqueue.cpp | 10 | ||||
-rw-r--r-- | src/eventqueue.h | 12 | ||||
-rw-r--r-- | src/webclientserver.cpp | 9 |
6 files changed, 51 insertions, 15 deletions
diff --git a/loadtester/mainwindow.cpp b/loadtester/mainwindow.cpp index 383996f..5d5df39 100644 --- a/loadtester/mainwindow.cpp +++ b/loadtester/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include <QWebView> +#include <QtCore> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -17,10 +18,31 @@ MainWindow::~MainWindow() delete ui; } +bool MainWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (ui->checkBox_clickThrough->isChecked() == false) + return true; + + if (event->type() == QEvent::MouseButtonPress + || event->type() == QEvent::MouseButtonRelease + || event->type() == QEvent::KeyPress + || event->type() == QEvent::KeyRelease) { + qDebug() << "got event"; + foreach (QWebView *webView, webViews) { + QApplication::sendEvent(obj, event); + } + return false; + } + + return true; +} + void MainWindow::loadPages() { for (int i = 0; i < ui->spinBox_connectCount->value(); ++i) { QWebView *webView = new QWebView(this); + installEventFilter(webView); + webViews.append(webView); webView->load(QUrl(ui->lineEdit_url->text())); ui->stackedWidget_pages->addWidget(webView); } diff --git a/loadtester/mainwindow.h b/loadtester/mainwindow.h index 563da1f..af73606 100644 --- a/loadtester/mainwindow.h +++ b/loadtester/mainwindow.h @@ -8,6 +8,7 @@ namespace Ui class MainWindow; } +class QWebView; class MainWindow : public QMainWindow { Q_OBJECT @@ -15,6 +16,7 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = 0); ~MainWindow(); + bool eventFilter(QObject *obj, QEvent *event); private slots: void loadPages(); @@ -23,6 +25,7 @@ private slots: private: Ui::MainWindow *ui; int pageCount; + QList<QWebView *> webViews; }; #endif // MAINWINDOW_H diff --git a/loadtester/mainwindow.ui b/loadtester/mainwindow.ui index 3076b93..a312ae9 100644 --- a/loadtester/mainwindow.ui +++ b/loadtester/mainwindow.ui @@ -58,8 +58,7 @@ </layout> </item> <item> - <widget class="QStackedWidget" name="stackedWidget_pages"> - </widget> + <widget class="QStackedWidget" name="stackedWidget_pages"/> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout"> @@ -103,6 +102,13 @@ </property> </spacer> </item> + <item> + <widget class="QCheckBox" name="checkBox_clickThrough"> + <property name="text"> + <string>ClickThrough Events</string> + </property> + </widget> + </item> </layout> </item> </layout> diff --git a/src/eventqueue.cpp b/src/eventqueue.cpp index 16b8663..76c68f7 100644 --- a/src/eventqueue.cpp +++ b/src/eventqueue.cpp @@ -118,7 +118,7 @@ void EventQueue::handleImageRequest(json_object* jsonRequest, HttpResponse *resp if (!idObject) return; - const int id = json_object_get_int(idObject); + const quintptr id = json_object_get_int(idObject); DEBUG << "id" << this << id << images.value(id).size(); QByteArray block; @@ -131,7 +131,7 @@ void EventQueue::handleImageRequest(json_object* jsonRequest, HttpResponse *resp response->setContentType("image/png"); } -void EventQueue::addUpdateEvent(int id, const QImage &image, QRect updateRect) +void EventQueue::addUpdateEvent(quintptr id, const QImage &image, QRect updateRect) { DEBUG << "addUpdateEvent" << this << id << image.size(); @@ -152,7 +152,7 @@ void EventQueue::addUpdateEvent(int id, const QImage &image, QRect updateRect) addEvent(id, EventEntry::Update); } -void EventQueue::addGeometryEvent(int id, QRect globalGeometry) +void EventQueue::addGeometryEvent(quintptr id, QRect globalGeometry) { if (geometries[id] == globalGeometry) { return; @@ -161,13 +161,13 @@ void EventQueue::addGeometryEvent(int id, QRect globalGeometry) addEvent(id, EventEntry::Geometry); } -void EventQueue::addParentChangeEvent(int id) +void EventQueue::addParentChangeEvent(quintptr id) { // DEBUG << "parentchanged"; addEvent(id, EventEntry::ParentChange); } -void EventQueue::addEvent(int id, EventEntry::Type type) +void EventQueue::addEvent(quintptr id, EventEntry::Type type) { EventEntry entry(id, type); diff --git a/src/eventqueue.h b/src/eventqueue.h index 6cc1caf..3f418b8 100644 --- a/src/eventqueue.h +++ b/src/eventqueue.h @@ -33,10 +33,10 @@ public: void handleRequest(HttpRequest *request, HttpResponse *response); void handleJsonRequest(QByteArray jsonText, HttpResponse *response); void handleImageRequest(json_object* jsonRequest, HttpResponse *response); - void addUpdateEvent(int id, const QImage &image, QRect updateRect); - void addGeometryEvent(int id, QRect globalGeometry); - void addParentChangeEvent(int id); - void addEvent(int id, EventEntry::Type type); + void addUpdateEvent(quintptr id, const QImage &image, QRect updateRect); + void addGeometryEvent(quintptr id, QRect globalGeometry); + void addParentChangeEvent(quintptr id); + void addEvent(quintptr id, EventEntry::Type type); QByteArray queueToByteArray(); json_object *toJson(const EventEntry &event) const; json_object *jsonShowEvent(const EventEntry &event) const; @@ -52,8 +52,8 @@ public: //private: Session *m_session; QQueue<EventEntry> events; - QHash<int, QImage> images; - QHash<int, QRect> geometries; + QHash<quintptr, QImage> images; + QHash<quintptr, QRect> geometries; }; #endif diff --git a/src/webclientserver.cpp b/src/webclientserver.cpp index abf55f2..d85b548 100644 --- a/src/webclientserver.cpp +++ b/src/webclientserver.cpp @@ -209,12 +209,17 @@ void Server::printRequest(const QList<QByteArray> &request) void Server::contentAvailable(Session *session) { // DEBUG << "content available!"; - QTcpSocket *socket = session->m_idleSocket; - if (socket == 0) + // Check if there is a long-polling socket available. + // If not, then no content can be sent at this point. + if (session->m_idleSocket == 0) return; + // The socket is no longer the idle socket. + QTcpSocket *socket = session->m_idleSocket; disconnect(socket, SIGNAL(disconnected()), session, SLOT(idleSocketDisconnect())); session->m_idleSocket = 0; + + // Get content from the session and write it to the socket. session->emitRequestContent(&session->m_idleRequest, &session->m_idleResponse); socket->write(session->m_idleResponse.toText()); } |