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 --- CMakeLists.txt | 9 +- src/maingui/backdrop.cpp | 56 +++++++ src/maingui/backdrop.h | 26 +++ src/maingui/main.cpp | 18 +- src/maingui/printergui.cpp | 68 ++++++-- src/maingui/printergui.h | 15 +- src/maingui/printergui.ui | 404 +++++++++++++++++++++++---------------------- src/pwgui/main.cpp | 14 +- 8 files changed, 392 insertions(+), 218 deletions(-) create mode 100644 src/maingui/backdrop.cpp create mode 100644 src/maingui/backdrop.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7530b78..0745441 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") -SET(CMAKE_C_FLAGS_RELEASE "-O2") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wall") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2" ) +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" ) # local cmake modules SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) @@ -61,6 +61,7 @@ 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 ) SET(PWGUI_MOC_HDRS 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(); + } +} diff --git a/src/maingui/backdrop.h b/src/maingui/backdrop.h new file mode 100644 index 0000000..b798a89 --- /dev/null +++ b/src/maingui/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/main.cpp b/src/maingui/main.cpp index c22ad7b..25f81a0 100644 --- a/src/maingui/main.cpp +++ b/src/maingui/main.cpp @@ -2,9 +2,12 @@ #include #include #include "printergui.h" +#include "backdrop.h" #include #include +static Backdrop* showGrayBackground(); + int main(int argc, char *argv[]) { // First check parameter count @@ -26,9 +29,22 @@ int main(int argc, char *argv[]) } close(fh); - PrinterGui *w = new PrinterGui(argv); + Backdrop* bgWin = showGrayBackground(); + + PrinterGui *w = new PrinterGui(argv, bgWin); + bgWin->setMainWindow(w); w->show(); } return a.exec(); } + +static Backdrop* showGrayBackground() +{ + Backdrop *bg = new Backdrop; + bg->show(); + bg->raise(); + bg->activateWindow(); + bg->move(0, 0); + return bg; +} diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp index 8d2e81e..21e03f4 100644 --- a/src/maingui/printergui.cpp +++ b/src/maingui/printergui.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -13,9 +14,11 @@ static QStringList knownPageSizeOptions = QStringList() << "PageSize"; // ____________________________________________________________________________ PrinterGui::PrinterGui(char *argv[], QWidget *parent) : - QMainWindow(parent), + QDialog(parent), ui(new Ui::PrinterGui), - bgTimeout(-1) + statusBar(NULL), + bgTimeout(-1), + jobId(0) { // When called it is guaranteed that argv has (at least) 3 elements @@ -59,12 +62,19 @@ PrinterGui::~PrinterGui() void PrinterGui::initializeUI() { ui->setupUi(this); + this->setWindowModality(Qt::ApplicationModal); + // Put always on top + this->setWindowFlags(Qt::Dialog | Qt::WindowStaysOnTopHint); ui->horizontalLayoutButtons->setAlignment(Qt::AlignRight); ui->comboBoxColor->setEnabled(false); ui->comboBoxSides->setEnabled(false); ui->label_color->setEnabled(false); ui->label_duplex->setEnabled(false); + // Create a status bar (qt designer doesn't support this for dialogs) + statusBar = new QStatusBar(this); + ui->statusBarLayout->addWidget(statusBar); + /* Initialize Treeview */ ui->printerList->setColumnCount(3); @@ -98,8 +108,6 @@ void PrinterGui::initializeUI() /* 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, @@ -190,17 +198,43 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr // Check availability if (res & CUPS_PRINTER_REJECTING) { ui->buttonPrint->setEnabled(false); - statusBar()->showMessage("Dieser Drucker nimmt zur Zeit keine Aufträge an"); + statusBar->showMessage("Dieser Drucker nimmt zur Zeit keine Aufträge an"); } else { ui->buttonPrint->setEnabled(true); - statusBar()->clearMessage(); + statusBar->clearMessage(); } } +void PrinterGui::closeEvent(QCloseEvent * e) +{ + if (e->isAccepted()) { + if (jobId != 0) { + cupsCancelJob(ui->printerList->currentItem()->text(0).toUtf8().constData(), jobId); + jobId = 0; + } + QCoreApplication::instance()->exit(0); + } + QDialog::closeEvent(e); +} + +void PrinterGui::keyPressEvent(QKeyEvent * e) +{ + if(e->key() != Qt::Key_Escape) { + QDialog::keyPressEvent(e); + return; + } + this->close(); +} + +void PrinterGui::hideEvent(QHideEvent * e) +{ + this->close(); +} + // ____________________________________________________________________________ void PrinterGui::on_buttonCancel_clicked() { - QCoreApplication::instance()->exit(0); + this->close(); } // ____________________________________________________________________________ @@ -250,20 +284,28 @@ void PrinterGui::on_buttonPrint_clicked() } cupsSetUser(this->user); - char jobtitle[100]; - snprintf(jobtitle, 100, "gui-%d-%s", (int)getpid(), this->user); + char jobtitle[200]; + const char *docName; + docName = getenv("J"); + if (docName == NULL) { + docName = getenv("N"); + } + if (docName == NULL) { + docName = "Untitled"; + } + snprintf(jobtitle, sizeof(jobtitle), "gui-%d-%s (%s)", (int)getpid(), this->user, docName); // Drucken - if( 0 == cupsPrintFile(dest->name, + jobId = cupsPrintFile(dest->name, file, jobtitle, dest->num_options, - dest->options)) { + dest->options); + if (jobId == 0) { QMessageBox::critical(this, "CUPS Fehler", cupsLastErrorString()); } else { this->bgTimeout = 0; - statusBar()->showMessage("Druckauftrag wird verarbeitet..."); - ui->buttonCancel->setEnabled(false); + statusBar->showMessage("Druckauftrag wird verarbeitet..."); ui->buttonPrint->setEnabled(false); ui->cboPaperSize->setEnabled(false); ui->comboBoxColor->setEnabled(false); diff --git a/src/maingui/printergui.h b/src/maingui/printergui.h index cd71740..88ec685 100644 --- a/src/maingui/printergui.h +++ b/src/maingui/printergui.h @@ -1,7 +1,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include #include #include #include @@ -13,8 +13,12 @@ class PrinterGui; } class QTimer; +class QStatusBar; +class QCloseEvent; +class QHideEvent; +class QKeyEvent; -class PrinterGui : public QMainWindow +class PrinterGui : public QDialog { Q_OBJECT @@ -22,6 +26,11 @@ public: explicit PrinterGui(char *argv[], QWidget *parent = 0); ~PrinterGui(); +protected: + void closeEvent(QCloseEvent * e); + void hideEvent(QHideEvent * e); + void keyPressEvent(QKeyEvent * e); + private slots: void on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); void on_buttonCancel_clicked(); @@ -36,7 +45,9 @@ private: char * user; char * file; QTimer * bgTimer; + QStatusBar *statusBar; int bgTimeout; + int jobId; }; #endif // MAINWINDOW_H diff --git a/src/maingui/printergui.ui b/src/maingui/printergui.ui index 0b4849f..4666390 100644 --- a/src/maingui/printergui.ui +++ b/src/maingui/printergui.ui @@ -1,13 +1,13 @@ PrinterGui - + 0 0 - 590 - 286 + 629 + 330 @@ -19,201 +19,215 @@ Druckauftrag - - - - - - - - false + + + 0 + + + 5 + + + + + 5 + + + + + false + + + true + + + + 1 - - true - - + + + + + + + + + + + + + + + + + false + + + Anzahl Kopien: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + false + + + + 0 + 0 + + + + + 0 + 26 + + + + + 40 + 16777215 + + + + 00; + + + 1 + + + 2 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Farbe + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Duplex + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + - 1 + Papierformat + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + - - - - - - - - - - - - - - - - - false - - - Anzahl Kopien: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - false - - - - 0 - 0 - - - - - 0 - 26 - - - - - 40 - 16777215 - - - - 00; - - - 1 - - - 2 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Farbe - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Duplex - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Papierformat - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - - - - false - - - Abbrechen - - - - - - - false - - - - 0 - 0 - - - - Drucken - - - - - - - - - - - + + + + + + + + + 0 + 0 + + + + false + + + Abbrechen + + + + + + + false + + + + 0 + 0 + + + + Drucken + + + + + + + + + + + + + 0 + + + + diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp index edd594c..5dd5a07 100644 --- a/src/pwgui/main.cpp +++ b/src/pwgui/main.cpp @@ -282,13 +282,21 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * } } setenv("DEVICE_URI", uri, 1); - ERROR("DEVICE_URI: '%s'", uri); + char *args[8]; args[0] = uri; args[1] = jobid; args[2] = user; - args[3] = title; + // Fix job title if possible + if (strncmp(title, "gui-", 4) == 0) { + args[3] = strchr(title, ' '); + if (args[3] == NULL) { + args[3] = title; + } + } else { + args[3] = title; + } args[4] = copies; args[5] = options; args[6] = file; @@ -316,7 +324,7 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * if (strstr(buffer, "Unable to get printer status (Unauthorized)") != NULL) { needAuth = true; if (kill(pid, SIGTERM) < 0) { - ERROR("Sending SIGTERM to backend %d failed: %d\n", (int)pid, errno); + ERROR("Sending SIGTERM to backend %d failed: %d\n", (int)pid, (int)errno); } break; } else if (strstr(buffer, "Destination printer does not exist") != NULL) { -- cgit v1.2.3-55-g7522