From a163f2b5431ab8b274e7ac2e4b7dbf2299675905 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Oct 2015 19:33:33 +0200 Subject: Add fullscreen bg to printergui; preserve job name --- src/maingui/backdrop.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/maingui/backdrop.cpp (limited to 'src/maingui/backdrop.cpp') diff --git a/src/maingui/backdrop.cpp b/src/maingui/backdrop.cpp new file mode 100644 index 0000000..4a907e8 --- /dev/null +++ b/src/maingui/backdrop.cpp @@ -0,0 +1,56 @@ +#include "backdrop.h" + +#include +#include +#include +#include +#include +#include + +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(); + } +} -- cgit v1.2.3-55-g7522