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
55
56
57
58
59
60
|
/*
* 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) :
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();
}
}
|