Print: display an error message if no printers are found
When pressing Print or Preview from the PrintDialog, we need to first check if there are printers installed. If not we abort and show an error message. This is needed because if no printers are installed, things like the reported page height could be zero and the profile and table print code in PrintLayout will break. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
1a8dd659ca
commit
69676b08fb
@ -11,6 +11,8 @@
|
||||
#include <QPrintPreviewDialog>
|
||||
#include <QPrintDialog>
|
||||
#include <QShortcut>
|
||||
#include <QPrinterInfo>
|
||||
#include <QMessageBox>
|
||||
|
||||
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||
{
|
||||
@ -65,8 +67,24 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
|
||||
}
|
||||
|
||||
bool PrintDialog::checkForAvailablePrinters(void)
|
||||
{
|
||||
QList<QPrinterInfo> list = QPrinterInfo::availablePrinters();
|
||||
if (!list.length()) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(tr("Subsurface cannot find installed printers on this system!"));
|
||||
msgBox.setWindowIcon(QIcon(":subsurface-icon"));
|
||||
msgBox.exec();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PrintDialog::previewClicked(void)
|
||||
{
|
||||
if (!checkForAvailablePrinters())
|
||||
return;
|
||||
QPrintPreviewDialog previewDialog(&printer, this);
|
||||
connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
|
||||
previewDialog.exec();
|
||||
@ -74,6 +92,8 @@ void PrintDialog::previewClicked(void)
|
||||
|
||||
void PrintDialog::printClicked(void)
|
||||
{
|
||||
if (!checkForAvailablePrinters())
|
||||
return;
|
||||
QPrintDialog printDialog(&printer, this);
|
||||
if (printDialog.exec() == QDialog::Accepted){
|
||||
printLayout->print();
|
||||
|
||||
@ -18,6 +18,7 @@ public:
|
||||
explicit PrintDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||
|
||||
private:
|
||||
bool checkForAvailablePrinters(void);
|
||||
PrintOptions *optionsWidget;
|
||||
PrintLayout *printLayout;
|
||||
QProgressBar *progressBar;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user