-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverscreen.cpp
More file actions
executable file
·181 lines (153 loc) · 5.02 KB
/
Copy pathoverscreen.cpp
File metadata and controls
executable file
·181 lines (153 loc) · 5.02 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "overscreen.h"
#include <QMoveEvent>
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
#include <QThread>
#include <QApplication>
#include <QDesktopWidget>
#include <QTimer>
#include <QDir>
#include <QBitmap>
#include "worker.h"
int startX;
int startY;
int endX;
int endY;
int clickCounter;
bool takeScreenShot;
bool scrDone;
bool firstRelease;
overScreen::overScreen(QWidget *parent) : QWidget(parent){
this->setMouseTracking(true);
paint = false;
takeScreenShot = false;
scrDone = false;
firstRelease = true;
sizeDesktop = QApplication::desktop()->size();
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
setWindowState(Qt::WindowFullScreen);
//setAttribute( Qt::WA_TranslucentBackground,true );
#ifdef Q_WS_WIN
this->setWindowOpacity(0.1);
firstRelease = false;
#endif
setScreenFullWidhtHeight();
move( 0, 0 );
qDebug("Started QWidget");
resize(fullScrWidth, fullScrHeight);
setFocusPolicy( Qt::StrongFocus );
}
void overScreen::mousePressEvent(QMouseEvent * event ){
if ( takeScreenShot == false ){
this->paint = true;
startX = event->x();
startY = event->y();
}
}
void overScreen::mouseReleaseEvent(QMouseEvent * event ){
if(firstRelease){
firstRelease = false;
} else {
//if ( takeScreenShot == false ){
endX = event->x();
endY = event->y();
paint = false;
takeScreenShot = true;
this->repaint();
this->hide();
//}
}
}
void overScreen::mouseMoveEvent ( QMouseEvent * event ){
if(paint){
endX = event->x();
endY = event->y();
}
this->repaint();
}
void overScreen::paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.eraseRect( 0, 0, this->width(), this->height() );
painter.setPen(QColor("#000000"));
if(takeScreenShot){
paint = false;
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(getCoordonatesRegion()));
timer->setSingleShot(true);
timer->start(100);
takeScreenShot = false;
}
if( paint ) {
painter.setOpacity(1);
painter.setBrush(QColor("#860000"));
painter.drawRect( getMin(startX, endX ), getMin( startY, endY ), abs( startX - endX ), abs( startY - endY ) );
}
}
void overScreen::getCoordonates(){
//qDebug("received");
newScreenShot( );
}
void overScreen::getCoordonatesRegion(){
newScreenShot( getMin(startX, endX ), getMin( startY, endY ), abs( startX - endX ), abs( startY - endY ) );
}
void overScreen::getCoordonates(int x, int y, int wd, int hd){
newScreenShot( x, y, wd, hd );
}
int overScreen::getMin(int min1, int min2){
if( min1 > min2 ){
return min2;
} else {
return min1;
}
}
void overScreen::setScreenFullWidhtHeight(){
int scrNum = QApplication::desktop()->screenCount();
qDebug() << scrNum;
for (int i=0; i < scrNum; i++){
if( scrNum > 1 ){
qDebug() << QApplication::desktop()->screenGeometry(i);
if( QApplication::desktop()->screenGeometry(i).top() == 0 ) {
fullScrWidth += QApplication::desktop()->screenGeometry(i).width();
fullScrHeight = QApplication::desktop()->screenGeometry(i).height();
} else {
fullScrWidth = QApplication::desktop()->screenGeometry(i).width();
fullScrHeight += QApplication::desktop()->screenGeometry(i).height();
}
} else {
fullScrWidth += QApplication::desktop()->screenGeometry(0).width();
fullScrHeight += QApplication::desktop()->screenGeometry(0).height(); }
}
qDebug() << fullScrWidth << fullScrHeight;
}
void overScreen::newScreenShot(){
hide();
overScreen::shootScreen();
}
void overScreen::newScreenShot(int x, int y, int wd, int hd){
hide();
overScreen::shootScreen( x, y, wd, hd );
}
void overScreen::saveScreenshot(){
QString format = "png";
QString initialPath = QDir::currentPath() + "/";
QString fileName = initialPath + "newscreenshot" + "." + format;
originalPixmap.save( fileName, format.toAscii() );
qDebug() << "Should be finished";
emit finished();
close();
//delete this;
//this->destroy(true, true);
}
void overScreen::shootScreen(){
originalPixmap = QPixmap(); // clear image for low memory situations on embedded devices.
originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId() );
show();
overScreen::saveScreenshot();
}
void overScreen::shootScreen(int x, int y, int wd, int hd){
originalPixmap = QPixmap(); // clear image for low memory situations on embedded devices.
originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), x, y, wd, hd );
show();
overScreen::saveScreenshot();
}