summaryrefslogtreecommitdiffstats
path: root/src/maingui/backdrop.cpp
blob: 4a907e83b3cdd1bba30186465c403375819d64ee (plain) (blame)
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
#include "backdrop.h"

#include <QApplication>
#include <QDesktopWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QPixmap>
#include <QRgb>

Backdrop::Backdrop() :
			QWidget(NULL),
			screenshot(NULL),
			mainWindow(NULL)
{
	QPixmap shot = QPixmap::grabWindow(QApplication::desktop()->winId());
	if (!shot.isNull() && shot.height() > 0) {
		QImage img = shot.toImage();
		if (img.format() != QImage::Format_RGB32) {
			img = img.convertToFormat(QImage::Format_RGB32);
		}
		for (int i = 0; i < img.height(); ++i) {
			uchar *line = img.scanLine(i);
			if (line == NULL)
				continue;
			QRgb *rgb = (QRgb*)line;
			for (int x = 0; x < img.width(); ++x) {
				const int val = (qRed(*rgb)*11 + qGreen(*rgb)*16 + qBlue(*rgb)*5) / 32;
				*rgb = qRgb(val, val, val);
				rgb++;
			}
		}
		shot = QPixmap::fromImage(img);
	}
	screenshot = new QPixmap(shot);
	this->resize(screenshot->width(), screenshot->height());
	this->setWindowFlags(Qt::Tool | Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
}

Backdrop::~Backdrop()
{
	delete screenshot;
}

void Backdrop::paintEvent(QPaintEvent * event)
{
	QPainter p(this);
	p.drawPixmap(event->rect(), *screenshot, event->rect());
}

void Backdrop::mouseReleaseEvent(QMouseEvent * event)
{
	if (mainWindow != NULL) {
		mainWindow->raise();
		mainWindow->activateWindow();
	}
}