/* * Copyright (c) 2012 Yoann Blein * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include "RemoteScreenViewerWidget.h" #include #include #include #include #include namespace Swift { RemoteScreenViewerWidget::RemoteScreenViewerWidget(boost::shared_ptr incScreenSharing, QWidget *parent) : QFrame(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* event) { QFrame::paintEvent(event); if (!pixmap.isNull()) { QPainter painter(this); painter.translate(geometry().center()); painter.drawPixmap(-pixmap.rect().center(), pixmap); } } void RemoteScreenViewerWidget::resizeEvent(QResizeEvent *event) { if (!pixmap.isNull()) { int frameWidth2 = frameWidth() * 2; QSize borders(frameWidth2, frameWidth2); pixmap = pixmap.scaled(event->size() - borders, Qt::KeepAspectRatio); } QFrame::resizeEvent(event); } void RemoteScreenViewerWidget::handleNewImageReceived(const Image& image) { QImage qImg(image.data.data(), image.width, image.height, QImage::Format_RGB888); int frameWidth2 = frameWidth() * 2; QSize borders(frameWidth2, frameWidth2); pixmap = QPixmap::fromImage(qImg).scaled(size() - borders, Qt::KeepAspectRatio); update(); } }