mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:43:23 +00:00
Lazy Initialize QPrinter
it was taking 3 - 4 secs here to open the print dialog, first I tought it was a bug in our side, but it looks like it's a Qt bug, and by lazy initializing it we don't actually solve this, since it will still take 3 - 4 secs for the printer to start, but the dialog will appear much quicker. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
25aa80846b
commit
19dee335e4
2 changed files with 28 additions and 8 deletions
|
@ -14,7 +14,10 @@
|
||||||
|
|
||||||
template_options::color_palette_struct ssrf_colors, almond_colors, blueshades_colors, custom_colors;
|
template_options::color_palette_struct ssrf_colors, almond_colors, blueshades_colors, custom_colors;
|
||||||
|
|
||||||
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) :
|
||||||
|
QDialog(parent, f),
|
||||||
|
printer(NULL),
|
||||||
|
qprinter(NULL)
|
||||||
{
|
{
|
||||||
// initialize const colors
|
// initialize const colors
|
||||||
ssrf_colors.color1 = QColor::fromRgb(0xff, 0xff, 0xff);
|
ssrf_colors.color1 = QColor::fromRgb(0xff, 0xff, 0xff);
|
||||||
|
@ -57,7 +60,6 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
printOptions.color_selected = s.value("color_selected").toBool();
|
printOptions.color_selected = s.value("color_selected").toBool();
|
||||||
printOptions.landscape = s.value("landscape").toBool();
|
printOptions.landscape = s.value("landscape").toBool();
|
||||||
printOptions.p_template = s.value("template_selected").toString();
|
printOptions.p_template = s.value("template_selected").toString();
|
||||||
qprinter.setOrientation((QPrinter::Orientation)printOptions.landscape);
|
|
||||||
templateOptions.font_index = s.value("font").toInt();
|
templateOptions.font_index = s.value("font").toInt();
|
||||||
templateOptions.font_size = s.value("font_size").toDouble();
|
templateOptions.font_size = s.value("font_size").toDouble();
|
||||||
templateOptions.color_palette_index = s.value("color_palette").toInt();
|
templateOptions.color_palette_index = s.value("color_palette").toInt();
|
||||||
|
@ -95,9 +97,6 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
// create a print options object and pass our options struct
|
// create a print options object and pass our options struct
|
||||||
optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
|
optionsWidget = new PrintOptions(this, &printOptions, &templateOptions);
|
||||||
|
|
||||||
// create a new printer object
|
|
||||||
printer = new Printer(&qprinter, &printOptions, &templateOptions, Printer::PRINT);
|
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
@ -140,6 +139,12 @@ PrintDialog::PrintDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f
|
||||||
connect(this, SIGNAL(finished(int)), this, SLOT(onFinished()));
|
connect(this, SIGNAL(finished(int)), this, SLOT(onFinished()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrintDialog::~PrintDialog()
|
||||||
|
{
|
||||||
|
delete qprinter;
|
||||||
|
delete printer;
|
||||||
|
}
|
||||||
|
|
||||||
void PrintDialog::onFinished()
|
void PrintDialog::onFinished()
|
||||||
{
|
{
|
||||||
QSettings s;
|
QSettings s;
|
||||||
|
@ -165,9 +170,20 @@ void PrintDialog::onFinished()
|
||||||
s.setValue("custom_color_5", custom_colors.color5.name());
|
s.setValue("custom_color_5", custom_colors.color5.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintDialog::createPrinterObj()
|
||||||
|
{
|
||||||
|
// create a new printer object
|
||||||
|
if (!printer) {
|
||||||
|
qprinter = new QPrinter();
|
||||||
|
qprinter->setOrientation((QPrinter::Orientation)printOptions.landscape);
|
||||||
|
printer = new Printer(qprinter, &printOptions, &templateOptions, Printer::PRINT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PrintDialog::previewClicked(void)
|
void PrintDialog::previewClicked(void)
|
||||||
{
|
{
|
||||||
QPrintPreviewDialog previewDialog(&qprinter, this, Qt::Window
|
createPrinterObj();
|
||||||
|
QPrintPreviewDialog previewDialog(qprinter, this, Qt::Window
|
||||||
| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint
|
| Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint
|
||||||
| Qt::WindowTitleHint);
|
| Qt::WindowTitleHint);
|
||||||
connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
|
connect(&previewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(onPaintRequested(QPrinter *)));
|
||||||
|
@ -176,7 +192,8 @@ void PrintDialog::previewClicked(void)
|
||||||
|
|
||||||
void PrintDialog::printClicked(void)
|
void PrintDialog::printClicked(void)
|
||||||
{
|
{
|
||||||
QPrintDialog printDialog(&qprinter, this);
|
createPrinterObj();
|
||||||
|
QPrintDialog printDialog(qprinter, this);
|
||||||
if (printDialog.exec() == QDialog::Accepted) {
|
if (printDialog.exec() == QDialog::Accepted) {
|
||||||
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
||||||
printer->print();
|
printer->print();
|
||||||
|
@ -186,6 +203,7 @@ void PrintDialog::printClicked(void)
|
||||||
|
|
||||||
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
|
void PrintDialog::onPaintRequested(QPrinter *printerPtr)
|
||||||
{
|
{
|
||||||
|
createPrinterObj();
|
||||||
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
|
||||||
printer->print();
|
printer->print();
|
||||||
progressBar->setValue(0);
|
progressBar->setValue(0);
|
||||||
|
|
|
@ -18,12 +18,13 @@ class PrintDialog : public QDialog {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PrintDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
explicit PrintDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
|
virtual ~PrintDialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PrintOptions *optionsWidget;
|
PrintOptions *optionsWidget;
|
||||||
QProgressBar *progressBar;
|
QProgressBar *progressBar;
|
||||||
Printer *printer;
|
Printer *printer;
|
||||||
QPrinter qprinter;
|
QPrinter *qprinter;
|
||||||
struct print_options printOptions;
|
struct print_options printOptions;
|
||||||
struct template_options templateOptions;
|
struct template_options templateOptions;
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ slots:
|
||||||
void previewClicked();
|
void previewClicked();
|
||||||
void printClicked();
|
void printClicked();
|
||||||
void onPaintRequested(QPrinter *);
|
void onPaintRequested(QPrinter *);
|
||||||
|
void createPrinterObj();
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
#endif // PRINTDIALOG_H
|
#endif // PRINTDIALOG_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue