summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authordknn <yoann.blein@free.fr>2012-08-10 18:04:56 (GMT)
committerdknn <yoann.blein@free.fr>2012-09-22 09:32:38 (GMT)
commit955c4589ca254814ae7ec6ed911e0a62febc5da1 (patch)
tree1d3ba8ecc732f8239462f7428e758224f3d38b94 /Swift
parent577fffec4a1da6909740a392cf76617bdcbe5570 (diff)
downloadswift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.zip
swift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.tar.bz2
Capture and send user UI events
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp86
-rw-r--r--Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h8
2 files changed, 89 insertions, 5 deletions
diff --git a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp
index 899f335..91a515f 100644
--- a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp
+++ b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp
@@ -20,6 +20,8 @@ namespace Swift {
RemoteScreenViewerWidget::RemoteScreenViewerWidget(boost::shared_ptr<IncomingScreenSharing> incScreenSharing, QWidget *parent) :
QWidget(parent), iss(incScreenSharing)
{
+ setMouseTracking(true);
+ setFocusPolicy(Qt::StrongFocus);
iss->onNewImageReceived.connect(boost::bind(&RemoteScreenViewerWidget::handleNewImageReceived, this, _1));
}
@@ -28,7 +30,7 @@ RemoteScreenViewerWidget::~RemoteScreenViewerWidget()
iss->onNewImageReceived.disconnect(boost::bind(&RemoteScreenViewerWidget::handleNewImageReceived, this, _1));
}
-void RemoteScreenViewerWidget::paintEvent(QPaintEvent* event)
+void RemoteScreenViewerWidget::paintEvent(QPaintEvent*)
{
if (!pixmap.isNull()) {
QPainter painter(this);
@@ -37,18 +39,94 @@ void RemoteScreenViewerWidget::paintEvent(QPaintEvent* event)
}
}
-void RemoteScreenViewerWidget::resizeEvent(QResizeEvent *event)
+void RemoteScreenViewerWidget::resizeEvent(QResizeEvent* event)
{
if (!pixmap.isNull()) {
- pixmap = pixmap.scaled(event->size(), Qt::KeepAspectRatio);
+ pixmap = pixmap.scaled(event->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
QWidget::resizeEvent(event);
}
+void RemoteScreenViewerWidget::keyPressEvent(QKeyEvent* event)
+{
+ InputEventPayload::Event ev(InputEventPayload::Event::KeyPress, event->key());
+ iss->sendInputEvent(ev);
+ QWidget::keyPressEvent(event);
+}
+
+void RemoteScreenViewerWidget::keyReleaseEvent(QKeyEvent* event)
+{
+ InputEventPayload::Event ev(InputEventPayload::Event::KeyRelease, event->key());
+ iss->sendInputEvent(ev);
+ QWidget::keyReleaseEvent(event);
+}
+
+void RemoteScreenViewerWidget::mouseMoveEvent(QMouseEvent* event)
+{
+ float x = static_cast<float>(event->x()) / pixmap.width();
+ float y = static_cast<float>(event->y()) / pixmap.height();
+ InputEventPayload::Event ev(InputEventPayload::Event::MouseMove, x, y);
+ iss->sendInputEvent(ev);
+ QWidget::mouseMoveEvent(event);
+}
+
+void RemoteScreenViewerWidget::mousePressEvent(QMouseEvent* event)
+{
+ int btnId = 0;
+ switch (event->button()) {
+ case Qt::LeftButton:
+ btnId = 3;
+ break;
+ case Qt::MidButton:
+ btnId = 2;
+ break;
+ case Qt::RightButton:
+ btnId = 1;
+ break;
+ default:
+ break;
+ }
+ if (btnId) {
+ InputEventPayload::Event ev(InputEventPayload::Event::MousePress, btnId);
+ iss->sendInputEvent(ev);
+ }
+ QWidget::mousePressEvent(event);
+}
+
+void RemoteScreenViewerWidget::mouseReleaseEvent(QMouseEvent* event)
+{
+ int btnId = 0;
+ switch (event->button()) {
+ case Qt::LeftButton:
+ btnId = 3;
+ break;
+ case Qt::MidButton:
+ btnId = 2;
+ break;
+ case Qt::RightButton:
+ btnId = 1;
+ break;
+ default:
+ break;
+ }
+ if (btnId) {
+ InputEventPayload::Event ev(InputEventPayload::Event::MouseRelease, btnId);
+ iss->sendInputEvent(ev);
+ }
+ QWidget::mouseReleaseEvent(event);
+}
+
+void RemoteScreenViewerWidget::wheelEvent(QWheelEvent* event)
+{
+ InputEventPayload::Event ev(InputEventPayload::Event::MouseWheel, event->delta());
+ iss->sendInputEvent(ev);
+ QWidget::wheelEvent(event);
+}
+
void RemoteScreenViewerWidget::handleNewImageReceived(const Image& image)
{
QImage qImg(image.data.data(), image.width, image.height, QImage::Format_RGB888);
- pixmap = QPixmap::fromImage(qImg).scaled(size(), Qt::KeepAspectRatio);
+ pixmap = QPixmap::fromImage(qImg).scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
update();
}
diff --git a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h
index b0a377e..2738e98 100644
--- a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h
+++ b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.h
@@ -21,8 +21,14 @@ namespace Swift {
~RemoteScreenViewerWidget();
protected:
- void paintEvent(QPaintEvent* event);
+ void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent* event);
+ void keyPressEvent(QKeyEvent* event);
+ void keyReleaseEvent(QKeyEvent* event);
+ void mouseMoveEvent(QMouseEvent* event);
+ void mousePressEvent(QMouseEvent* event);
+ void mouseReleaseEvent(QMouseEvent* event);
+ void wheelEvent(QWheelEvent* event);
private:
void handleNewImageReceived(const Image& image);