diff options
author | Simon Rettberg | 2015-10-08 19:33:33 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-10-08 19:33:33 +0200 |
commit | a163f2b5431ab8b274e7ac2e4b7dbf2299675905 (patch) | |
tree | 1a9e935ddf5c201cc268a89b647821b6c2c2d50d | |
parent | move msgBox closer to center :) TOFIX (diff) | |
download | printergui-a163f2b5431ab8b274e7ac2e4b7dbf2299675905.tar.gz printergui-a163f2b5431ab8b274e7ac2e4b7dbf2299675905.tar.xz printergui-a163f2b5431ab8b274e7ac2e4b7dbf2299675905.zip |
Add fullscreen bg to printergui; preserve job name
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/maingui/backdrop.cpp | 56 | ||||
-rw-r--r-- | src/maingui/backdrop.h | 26 | ||||
-rw-r--r-- | src/maingui/main.cpp | 18 | ||||
-rw-r--r-- | src/maingui/printergui.cpp | 68 | ||||
-rw-r--r-- | src/maingui/printergui.h | 15 | ||||
-rw-r--r-- | src/maingui/printergui.ui | 404 | ||||
-rw-r--r-- | src/pwgui/main.cpp | 14 |
8 files changed, 392 insertions, 218 deletions
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 <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(); + } +} 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 <QWidget> + +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 <QMessageBox> #include <fstream> #include "printergui.h" +#include "backdrop.h" #include <fcntl.h> #include <sys/stat.h> +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 <unistd.h> #include <QTimer> #include <QStatusBar> +#include <QCloseEvent> #include <pwd.h> #include <cups/ppd.h> @@ -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 <QMainWindow> +#include <QDialog> #include <QDebug> #include <QDesktopWidget> #include <QTreeWidget> @@ -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 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>PrinterGui</class> - <widget class="QMainWindow" name="PrinterGui"> + <widget class="QDialog" name="PrinterGui"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>590</width> - <height>286</height> + <width>629</width> + <height>330</height> </rect> </property> <property name="minimumSize"> @@ -19,201 +19,215 @@ <property name="windowTitle"> <string>Druckauftrag</string> </property> - <widget class="QWidget" name="centralWidget"> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QTreeWidget" name="printerList"> - <property name="showDropIndicator" stdset="0"> - <bool>false</bool> + <layout class="QGridLayout" name="gridLayout_3"> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>5</number> + </property> + <item row="0" column="0"> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="margin"> + <number>5</number> + </property> + <item> + <widget class="QTreeWidget" name="printerList"> + <property name="showDropIndicator" stdset="0"> + <bool>false</bool> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <column> + <property name="text"> + <string notr="true">1</string> </property> - <property name="alternatingRowColors"> - <bool>true</bool> - </property> - <column> + </column> + </widget> + </item> + <item> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="2" column="1"> + <widget class="QComboBox" name="comboBoxColor"/> + </item> + <item row="3" column="1"> + <widget class="QComboBox" name="comboBoxSides"/> + </item> + <item row="2" column="3"> + <layout class="QHBoxLayout" name="horizontalLayoutCopies"> + <item> + <widget class="QLabel" name="labelCopies"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Anzahl Kopien:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditCopies"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>26</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>40</width> + <height>16777215</height> + </size> + </property> + <property name="inputMask"> + <string>00; </string> + </property> + <property name="text"> + <string>1</string> + </property> + <property name="maxLength"> + <number>2</number> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="2"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="3" column="2"> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_color"> + <property name="text"> + <string>Farbe</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_duplex"> + <property name="text"> + <string>Duplex</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="lblPaperSize"> <property name="text"> - <string notr="true">1</string> + <string>Papierformat</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QComboBox" name="cboPaperSize"/> + </item> + <item row="4" column="2"> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> </property> - </column> - </widget> - </item> - <item> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="2" column="1"> - <widget class="QComboBox" name="comboBoxColor"/> - </item> - <item row="3" column="1"> - <widget class="QComboBox" name="comboBoxSides"/> - </item> - <item row="2" column="3"> - <layout class="QHBoxLayout" name="horizontalLayoutCopies"> - <item> - <widget class="QLabel" name="labelCopies"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Anzahl Kopien:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="lineEditCopies"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>26</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>40</width> - <height>16777215</height> - </size> - </property> - <property name="inputMask"> - <string>00; </string> - </property> - <property name="text"> - <string>1</string> - </property> - <property name="maxLength"> - <number>2</number> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - </layout> - </item> - <item row="2" column="2"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="3" column="2"> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_color"> - <property name="text"> - <string>Farbe</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_duplex"> - <property name="text"> - <string>Duplex</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="lblPaperSize"> - <property name="text"> - <string>Papierformat</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QComboBox" name="cboPaperSize"/> - </item> - <item row="4" column="2"> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="4" column="3"> - <layout class="QHBoxLayout" name="horizontalLayoutButtons"> - <item> - <widget class="QPushButton" name="buttonCancel"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="autoFillBackground"> - <bool>false</bool> - </property> - <property name="text"> - <string>Abbrechen</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="buttonPrint"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Drucken</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </widget> + </spacer> + </item> + <item row="4" column="3"> + <layout class="QHBoxLayout" name="horizontalLayoutButtons"> + <item> + <widget class="QPushButton" name="buttonCancel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Abbrechen</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="buttonPrint"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Drucken</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </item> + <item row="1" column="0"> + <layout class="QVBoxLayout" name="statusBarLayout"> + <property name="spacing"> + <number>0</number> + </property> + </layout> + </item> + </layout> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> 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) { |