From e9eb8c4a421c2c406e1ada4c866b2ae9268d647d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 9 Oct 2015 17:10:30 +0200 Subject: [pwgui] Also use the grayed out fake background --- CMakeLists.txt | 13 ++++++----- src/backdrop.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++ src/backdrop.h | 26 +++++++++++++++++++++ src/maingui/backdrop.cpp | 56 ---------------------------------------------- src/maingui/backdrop.h | 26 --------------------- src/maingui/main.cpp | 2 +- src/maingui/printergui.cpp | 10 ++++++++- src/pwgui/main.cpp | 11 +++++++-- src/pwgui/pwgui.cpp | 5 +++-- 9 files changed, 112 insertions(+), 93 deletions(-) create mode 100644 src/backdrop.cpp create mode 100644 src/backdrop.h delete mode 100644 src/maingui/backdrop.cpp delete mode 100644 src/maingui/backdrop.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0745441..4d9b9cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,10 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0) IF (CMAKE_BUILD_TYPE STREQUAL "") SET(CMAKE_BUILD_TYPE Debug) ENDIF() -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -Wall -Wunused -Wunreachable-code -pedantic -fno-strict-aliasing") -SET(CMAKE_C_FLAGS_RELEASE "-O2 -fno-strict-aliasing") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wunused -Wunreachable-code -pedantic -fno-strict-aliasing") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -fno-strict-aliasing" ) +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -Wall -Wunused -Wunreachable-code -pedantic -fno-strict-aliasing -std=gnu99") +SET(CMAKE_C_FLAGS_RELEASE "-O2 -fno-strict-aliasing -std=gnu99") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall -Wunused -Wunreachable-code -pedantic -fno-strict-aliasing -std=gnu++0x") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -fno-strict-aliasing -std=gnu++0x" ) # local cmake modules SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) @@ -34,11 +34,13 @@ INCLUDE_DIRECTORIES( # printergui (maingui) FILE(GLOB MAINGUI_SRCS src/maingui/*.cpp + src/*.cpp ) # password gui (printpwgui FILE(GLOB PWGUI_SRCS src/pwgui/*.cpp + src/*.cpp ) ################################################################################ @@ -61,11 +63,12 @@ FILE(GLOB PWGUI_UIS # includes all header files that should be treated with moc SET(MAINGUI_MOC_HDRS src/maingui/printergui.h - src/maingui/backdrop.h + src/backdrop.h ) SET(PWGUI_MOC_HDRS src/pwgui/pwgui.h + src/backdrop.h ) # i18n diff --git a/src/backdrop.cpp b/src/backdrop.cpp new file mode 100644 index 0000000..4a907e8 --- /dev/null +++ b/src/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(); + } +} diff --git a/src/backdrop.h b/src/backdrop.h new file mode 100644 index 0000000..b798a89 --- /dev/null +++ b/src/backdrop.h @@ -0,0 +1,26 @@ +#ifndef BACKDROP_H_ +#define BACKDROP_H_ + +#include + +class QPixmap; + +class Backdrop : public QWidget +{ + Q_OBJECT + +private: + const QPixmap * screenshot; + QWidget * mainWindow; + +protected: + virtual void paintEvent(QPaintEvent * event); + virtual void mouseReleaseEvent(QMouseEvent * event); + +public: + explicit Backdrop(); + virtual ~Backdrop(); + void setMainWindow(QWidget *win) { mainWindow = win; } +}; + +#endif /* BACKDROP_H_ */ diff --git a/src/maingui/backdrop.cpp b/src/maingui/backdrop.cpp deleted file mode 100644 index 4a907e8..0000000 --- a/src/maingui/backdrop.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#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(); - } -} diff --git a/src/maingui/backdrop.h b/src/maingui/backdrop.h deleted file mode 100644 index b798a89..0000000 --- a/src/maingui/backdrop.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef BACKDROP_H_ -#define BACKDROP_H_ - -#include - -class QPixmap; - -class Backdrop : public QWidget -{ - Q_OBJECT - -private: - const QPixmap * screenshot; - QWidget * mainWindow; - -protected: - virtual void paintEvent(QPaintEvent * event); - virtual void mouseReleaseEvent(QMouseEvent * event); - -public: - explicit Backdrop(); - virtual ~Backdrop(); - void setMainWindow(QWidget *win) { mainWindow = win; } -}; - -#endif /* BACKDROP_H_ */ diff --git a/src/maingui/main.cpp b/src/maingui/main.cpp index 25f81a0..58ace07 100644 --- a/src/maingui/main.cpp +++ b/src/maingui/main.cpp @@ -2,7 +2,7 @@ #include #include #include "printergui.h" -#include "backdrop.h" +#include "../backdrop.h" #include #include diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp index 21e03f4..0dd9e13 100644 --- a/src/maingui/printergui.cpp +++ b/src/maingui/printergui.cpp @@ -112,7 +112,15 @@ void PrinterGui::initializeUI() QRect desktopRect = QApplication::desktop()->screenGeometry(this); this->move( desktopRect.width()/2-this->width()/2, desktopRect.height()/2-this->height()/2); - this->setWindowTitle(QString::fromUtf8("Drucken - %1").arg(this->user)); + const char *docName; + docName = getenv("J"); + if (docName == NULL) { + docName = getenv("N"); + } + if (docName == NULL) { + docName = "Untitled"; + } + this->setWindowTitle(QString::fromUtf8("Drucken - %1 [%2]").arg(this->user, QString::fromUtf8(docName))); this->show(); this->showNormal(); diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp index b916259..65fd469 100644 --- a/src/pwgui/main.cpp +++ b/src/pwgui/main.cpp @@ -1,4 +1,5 @@ #include "pwgui.h" +#include "../backdrop.h" #include "config.h" #include #include @@ -183,8 +184,14 @@ int main(int argc, char *argv[]) helper_dropprivs(); helper_copyenv(); QApplication a(argc, argv); - PwGui w(pfd[1], creds); - w.show(); + Backdrop *bg = new Backdrop; + bg->show(); + bg->raise(); + bg->activateWindow(); + bg->move(0, 0); + PwGui *w = new PwGui(pfd[1], creds); + bg->setMainWindow(w); + w->show(); exit(a.exec()); return CUPS_BACKEND_FAILED; } diff --git a/src/pwgui/pwgui.cpp b/src/pwgui/pwgui.cpp index 193341b..b6130f0 100644 --- a/src/pwgui/pwgui.cpp +++ b/src/pwgui/pwgui.cpp @@ -29,6 +29,9 @@ PwGui::~PwGui() void PwGui::initializeUI(char *user) { ui->setupUi(this); + this->setWindowModality(Qt::ApplicationModal); + // Put always on top + this->setWindowFlags(Qt::Dialog | Qt::WindowStaysOnTopHint); // Prefill username if (user != NULL) { @@ -41,8 +44,6 @@ void PwGui::initializeUI(char *user) /* Main Window properties */ - // Disable close button - this->setWindowFlags((this->windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::WindowStaysOnTopHint); // center dialog on screen center QRect desktopRect = QApplication::desktop()->screenGeometry(this); this->move( desktopRect.width()/2-this->width()/2, -- cgit v1.2.3-55-g7522