-
Notifications
You must be signed in to change notification settings - Fork 1
/
windowcontentcopy.cpp
69 lines (62 loc) · 1.66 KB
/
windowcontentcopy.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "windowcontentcopy.h"
#include <QPaintEvent>
#include <QPainter>
#include <QTimer>
#include <QPixmap>
#include <QDebug>
#include <QApplication>
#include <QDesktopWidget>
#include "windowutils.h"
WindowContentCopy::WindowContentCopy(QWidget *parent) :
QWidget(parent), m_hasWindow(false)
{
QTimer* timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(20);
}
void WindowContentCopy::paintEvent(QPaintEvent *event)
{
checkTargetWindow();
if (!m_hasWindow) {
event->accept();
return;
}
QPainter painter(this);
QPixmap windowPixmap = WindowUtils::grabWindow(targetWindow());
//qDebug() << windowPixmap.size() << "for target window" << targetWindow();
painter.drawPixmap(QPoint(), windowPixmap);
event->accept();
}
void WindowContentCopy::checkTargetWindow()
{
if (!m_hasWindow) return;
if (!WindowUtils::isValid(targetWindow())) {
m_hasWindow = false;
window()->setWindowTitle("window-copy");
}
}
void WindowContentCopy::copyTitle()
{
window()->setWindowTitle(
WindowUtils::windowTitle(targetWindow()) + "#");
}
// todo add signal to be sent when target window closes
void WindowContentCopy::update()
{
checkTargetWindow();
if (!m_hasWindow) return;
QWidget::update();
//qDebug() << WindowUtils::windowGeometry(targetWindow()).size();
window()->resize(WindowUtils::windowGeometry(targetWindow()).size());
copyTitle();
}
void WindowContentCopy::setTargetWindow(WId arg)
{
m_window = arg;
m_hasWindow = true;
// copyTitle();
}
WId WindowContentCopy::targetWindow() const
{
return m_window;
}