| 1ff0643 by Enrico Ros at 2009-02-20 |
1 |
/*************************************************************************** |
| 0e5745d by Enrico Ros at 2009-05-31 |
2 |
* Copyright (c) 2009 Enrico Ros * |
|
3 |
* 2009 Enrico Ros <enrico.ros@email.it> * |
|
4 |
* 2009 Alberto Scarpa <skaal.sl@gmail.com> * |
| 1ff0643 by Enrico Ros at 2009-02-20 |
5 |
* * |
|
6 |
* Permission is hereby granted, free of charge, to any person * |
|
7 |
* obtaining a copy of this software and associated documentation * |
|
8 |
* files (the "Software"), to deal in the Software without * |
|
9 |
* restriction, including without limitation the rights to use, * |
|
10 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell * |
|
11 |
* copies of the Software, and to permit persons to whom the * |
|
12 |
* Software is furnished to do so, subject to the following * |
|
13 |
* conditions: * |
|
14 |
* * |
|
15 |
* The above copyright notice and this permission notice shall be * |
|
16 |
* included in all copies or substantial portions of the Software. * |
|
17 |
* * |
|
18 |
***************************************************************************/ |
|
19 |
|
| e45848b by Enrico Ros at 2009-05-31 |
20 |
#include "ScreenCapture.h" |
| 1ff0643 by Enrico Ros at 2009-02-20 |
21 |
#include <QCoreApplication> |
|
22 |
#include <QDirIterator> |
|
23 |
#include <QImage> |
|
24 |
#include <QTimerEvent> |
|
25 |
#ifdef Q_WS_X11 |
|
26 |
#include <QX11Info> |
|
27 |
#else |
|
28 |
#include <QApplication> |
|
29 |
#endif |
|
30 |
#include <QDesktopWidget> |
|
31 |
#include <QPixmap> |
|
32 |
|
| e45848b by Enrico Ros at 2009-05-31 |
33 |
ScreenCapture::ScreenCapture( QObject * parent ) |
| 1ff0643 by Enrico Ros at 2009-02-20 |
34 |
: QObject( parent ) |
|
35 |
, m_enabled( false ) |
|
36 |
, m_fps( 0 ) |
|
37 |
{ |
|
38 |
} |
|
39 |
|
| e45848b by Enrico Ros at 2009-05-31 |
40 |
void ScreenCapture::setEnabled( bool enabled ) |
| 1ff0643 by Enrico Ros at 2009-02-20 |
41 |
{ |
|
42 |
m_enabled = enabled; |
|
43 |
} |
|
44 |
|
| e45848b by Enrico Ros at 2009-05-31 |
45 |
bool ScreenCapture::enabled() const |
| 1ff0643 by Enrico Ros at 2009-02-20 |
46 |
{ |
|
47 |
return m_enabled; |
|
48 |
} |
|
49 |
|
| e45848b by Enrico Ros at 2009-05-31 |
50 |
void ScreenCapture::setGeometry( const QRect & geometry ) |
| 1ff0643 by Enrico Ros at 2009-02-20 |
51 |
{ |
|
52 |
m_geometry = geometry; |
|
53 |
} |
|
54 |
|
| e45848b by Enrico Ros at 2009-05-31 |
55 |
QRect ScreenCapture::geometry() const |
| 1ff0643 by Enrico Ros at 2009-02-20 |
56 |
{ |
|
57 |
return m_geometry; |
|
58 |
} |
|
59 |
|
| e45848b by Enrico Ros at 2009-05-31 |
60 |
void ScreenCapture::setFrequency( int fps ) |
| 1ff0643 by Enrico Ros at 2009-02-20 |
61 |
{ |
|
62 |
m_fps = fps; |
| c03b1c8 by Enrico Ros on Win32 at 2009-06-03 |
63 |
m_timer.start( 100 * 1000 / m_fps, this ); |
| 1ff0643 by Enrico Ros at 2009-02-20 |
64 |
} |
|
65 |
|
| e45848b by Enrico Ros at 2009-05-31 |
66 |
int ScreenCapture::frequency() const |
| 1ff0643 by Enrico Ros at 2009-02-20 |
67 |
{ |
|
68 |
return m_fps; |
|
69 |
} |
|
70 |
|
| e45848b by Enrico Ros at 2009-05-31 |
71 |
QPixmap ScreenCapture::lastPixmap() const |
| 9d1b99e by Enrico Ros at 2009-02-25 |
72 |
{ |
|
73 |
return m_pixmap; |
|
74 |
} |
|
75 |
|
| e45848b by Enrico Ros at 2009-05-31 |
76 |
void ScreenCapture::timerEvent( QTimerEvent * event ) |
| 1ff0643 by Enrico Ros at 2009-02-20 |
77 |
{ |
|
78 |
if ( event->timerId() != m_timer.timerId() || m_geometry.isNull() ) |
|
79 |
return QObject::timerEvent( event ); |
|
80 |
|
|
81 |
if ( !m_enabled ) |
|
82 |
return; |
|
83 |
|
| 9d1b99e by Enrico Ros at 2009-02-25 |
84 |
m_pixmap = QPixmap::grabWindow( |
| 1ff0643 by Enrico Ros at 2009-02-20 |
85 |
#if defined(Q_WS_X11) |
|
86 |
QX11Info::appRootWindow(), |
|
87 |
#else |
|
88 |
QApplication::desktop()->winId(), |
|
89 |
#endif |
|
90 |
m_geometry.left(), m_geometry.top(), m_geometry.width(), m_geometry.height() ); |
|
91 |
|
| 9d1b99e by Enrico Ros at 2009-02-25 |
92 |
emit gotPixmap( m_pixmap, QCursor::pos() - QPoint( m_geometry.topLeft() ) ); |
| 1ff0643 by Enrico Ros at 2009-02-20 |
93 |
} |