-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
53 lines (43 loc) · 1.56 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include <QtWidgets>
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
screenshotLabel = new QLabel;
screenshotLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
screenshotLabel->setAlignment(Qt::AlignCenter);
screenshotLabel->setMinimumSize(240, 160);
mainLayout = new QVBoxLayout;
mainLayout->addWidget(screenshotLabel);
setLayout(mainLayout);
frameCapture = new QTimer(this);
connect(frameCapture, SIGNAL(timeout()), this, SLOT(shootScreen()));
frameCapture->setInterval(5);
frameCapture->start();
effect = new QGraphicsOpacityEffect(this->screenshotLabel);
}
MainWindow::~MainWindow()
{
}
void MainWindow::resizeEvent(QResizeEvent * /* event */)
{
QSize scaledSize = originalPixmap.size();
scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio);
if (!screenshotLabel->pixmap() || scaledSize != screenshotLabel->pixmap()->size())
updateScreenshotLabel();
}
void MainWindow::shootScreen()
{
originalPixmap = QPixmap(); // clear image for low memory situations
// on embedded devices.
QScreen *screen = QGuiApplication::primaryScreen();
if (screen)
originalPixmap = screen->grabWindow(0);
updateScreenshotLabel();
}
void MainWindow::updateScreenshotLabel()
{
screenshotLabel->setPixmap(originalPixmap.scaled(screenshotLabel->size(),
Qt::KeepAspectRatio,
Qt::SmoothTransformation));
}