summaryrefslogtreecommitdiffstats
blob: f601f1b1497d01a0fbf97f077b59770276c049e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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();
}

}