diff options
Diffstat (limited to 'Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp')
-rw-r--r-- | Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp new file mode 100644 index 0000000..f601f1b --- /dev/null +++ b/Swift/QtUI/ScreenSharing/RemoteScreenViewerWidget.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "RemoteScreenViewerWidget.h" + +#include <QResizeEvent> +#include <QPainter> + +#include <boost/bind.hpp> + +#include <Swiften/ScreenSharing/IncomingScreenSharing.h> +#include <Swiften/ScreenSharing/Image.h> + + +namespace Swift { + +RemoteScreenViewerWidget::RemoteScreenViewerWidget(boost::shared_ptr<IncomingScreenSharing> incScreenSharing, QWidget *parent) : + QWidget(parent), iss(incScreenSharing) +{ + iss->onNewImageReceived.connect(boost::bind(&RemoteScreenViewerWidget::handleNewImageReceived, this, _1)); +} + +RemoteScreenViewerWidget::~RemoteScreenViewerWidget() +{ + iss->onNewImageReceived.disconnect(boost::bind(&RemoteScreenViewerWidget::handleNewImageReceived, this, _1)); +} + +void RemoteScreenViewerWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + if (!pixmap.isNull()) { + painter.translate(geometry().center()); + painter.drawPixmap(-pixmap.rect().center(), pixmap); + } +} + +void RemoteScreenViewerWidget::resizeEvent(QResizeEvent *event) +{ + if (!pixmap.isNull()) + pixmap = pixmap.scaled(event->size(), Qt::KeepAspectRatio); + QWidget::resizeEvent(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); + update(); +} + +} |