This repository was archived by the owner on May 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenArea.cpp
More file actions
50 lines (40 loc) · 1.51 KB
/
ScreenArea.cpp
File metadata and controls
50 lines (40 loc) · 1.51 KB
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
#include "ScreenArea.h"
#include <QtGui>
ScreenArea::ScreenArea()
{
move(0,0); // Placement coin en haut à gauche
setAttribute(Qt::WA_TranslucentBackground, true);
setWindowFlags(Qt::FramelessWindowHint); // On enlève les bords
showMaximized(); // On prend tout l'écran
screenView = new ScreenView;
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
leaveAreaAction = new QAction("Annuler (Ctrl + F)",this);
leaveAreaAction->setShortcut(QKeySequence("Ctrl+F"));
// Menu contextuel
addAction(leaveAreaAction);
setContextMenuPolicy(Qt::ActionsContextMenu);
QObject::connect(leaveAreaAction,SIGNAL(triggered()),this,SIGNAL(leaveArea()));
QObject::connect(screenView,SIGNAL(screenSaved(QString)),this,SIGNAL(screenSaved(QString)));
}
void ScreenArea::mousePressEvent(QMouseEvent *event)
{
origin = event->pos();
rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
}
void ScreenArea::mouseMoveEvent(QMouseEvent *event)
{
rubberBand->setGeometry(QRect(origin, event->pos()).normalized());
}
void ScreenArea::mouseReleaseEvent(QMouseEvent *event)
{
if(screenView->isVisible())
return;
QRect area = rubberBand->geometry();
QPixmap screen = QPixmap::grabWindow(QApplication::desktop()->winId(),
area.x() + x() + 1,
area.y() + y() + 1,
area.width() - 2,
area.height() - 2);
screenView->setScreenPixmap(screen);
}