27 #include <QPrintDialog> 43 printer_ -> setOrientation(QPrinter::Landscape);
92 if (!diagram)
return(QRect());
94 QRectF diagram_rect = diagram -> border_and_titleblock.borderAndTitleBlockRect();
96 qreal titleblock_height = diagram -> border_and_titleblock.titleBlockRect().height();
97 diagram_rect.setHeight(diagram_rect.height() - titleblock_height);
101 diagram_rect = diagram_rect.adjusted(0.0, 0.0, 1.0, 1.0);
103 return(diagram_rect.toAlignedRect());
118 if (
dialog_ ->
exec() == QDialog::Rejected)
return;
123 QPrintDialog print_dialog(
printer_, parentWidget());
125 print_dialog.setWindowFlags(Qt::Sheet);
127 print_dialog.setWindowTitle(
tr(
"Options d'impression",
"window title"));
128 print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintShowPageSize);
129 if (print_dialog.exec() == QDialog::Rejected)
return;
133 printer_ -> setOutputFormat(QPrinter::PdfFormat);
140 #if defined Q_OS_LINUX 149 SIGNAL(paintRequested(
const QList<Diagram *> &,
bool,
const ExportProperties, QPrinter *)),
154 dc -> setSelectedAllDiagrams();
155 if (preview_dialog.exec() == QDialog::Rejected)
return;
161 dc -> selectedDiagrams(),
187 QRect printable_area = fullpage ?
printer_ -> paperRect() :
printer_ -> pageRect();
188 QRect diagram_rect =
diagramRect(diagram, options);
190 int h_pages_count = int(ceil(qreal(diagram_rect.width()) / qreal(printable_area.width())));
191 return(h_pages_count);
203 QRect printable_area = fullpage ?
printer_ -> paperRect() :
printer_ -> pageRect();
204 QRect diagram_rect =
diagramRect(diagram, options);
206 int v_pages_count = int(ceil(qreal(diagram_rect.height()) / qreal(printable_area.height())));
207 return(v_pages_count);
216 dialog_ =
new QDialog(parentWidget());
218 dialog_ -> setWindowFlags(Qt::Sheet);
226 printer_choice_ =
new QRadioButton(
tr(
"Impression sur une imprimante physique",
"Print type choice"));
227 pdf_choice_ =
new QRadioButton(
tr(
"Impression vers un fichier au format PDF",
"Print type choice"));
233 dialog_ -> setWindowTitle(
tr(
"Choix du type d'impression"));
287 if (!filepath.isEmpty())
289 if (
pdf_choice_ -> isChecked() && filepath.endsWith(
".ps"))
291 QRegExp re(
"\\.ps$", Qt::CaseInsensitive);
292 filepath.replace(re,
".pdf");
310 tr(
"Fichier manquant",
"message box title"),
311 tr(
"Vous devez indiquer le chemin du fichier PDF/PS à créer.",
"message box content")
331 filter =
tr(
"Fichiers PDF (*.pdf)",
"file filter");
334 QString filepath = QFileDialog::getSaveFileName(
341 if (!filepath.isEmpty()) {
342 if (!filepath.endsWith(extension)) filepath += extension;
343 filepath = QDir::toNativeSeparators(QDir::cleanPath(filepath));
357 #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) 361 qDebug() <<
"DiagramPrintDialog::print printer_->resolution() before " <<
printer_->resolution();
362 qDebug() <<
"DiagramPrintDialog::print screennumber " << QApplication::desktop()->screenNumber();
365 QScreen *srn = QApplication::screens().at(QApplication::desktop()->screenNumber());
366 qreal dotsPerInch = (qreal)srn->logicalDotsPerInch();
367 printer_->setResolution(dotsPerInch);
370 qDebug() <<
"DiagramPrintDialog::print dotsPerInch " << dotsPerInch;
371 qDebug() <<
"DiagramPrintDialog::print printer_->resolution() after" <<
printer_->resolution();
380 if (!diagrams.count()) {
386 for (
int i = 0 ; i < diagrams.count() ; ++ i) {
388 if (i != diagrams.count() - 1) {
405 bool full_page = printer -> fullPage();
408 if (printer -> outputFileName().isEmpty()) {
415 QList<QGraphicsItem *> selected_elmts = diagram -> selectedItems();
416 foreach (QGraphicsItem *qgi, selected_elmts) qgi -> setSelected(
false);
419 QList<QGraphicsItem *> focusable_items;
420 foreach (QGraphicsItem *qgi, diagram -> items()) {
421 if (qgi -> flags() & QGraphicsItem::ItemIsFocusable) {
422 focusable_items << qgi;
423 qgi -> setFlag(QGraphicsItem::ItemIsFocusable,
false);
428 foreach (QGraphicsView *view, diagram -> views()) {
429 view -> setInteractive(
false);
432 QRect diagram_rect =
diagramRect(diagram, options);
435 diagram -> render(qp, QRectF(), diagram_rect, Qt::KeepAspectRatio);
438 QRect printed_area = full_page ? printer -> paperRect() : printer -> pageRect();
443 int used_width = printed_area.width();
444 int used_height = printed_area.height();
448 QVector< QVector< QRect > > pages_grid;
452 for (
int i = 0 ; i < v_pages_count ; ++ i) {
453 pages_grid << QVector< QRect >();
457 for (
int j = 0 ; j < h_pages_count ; ++ j) {
458 pages_grid.last() << QRect(
459 QPoint(x_offset, y_offset),
461 qMin(used_width, diagram_rect.width() - x_offset),
462 qMin(used_height, diagram_rect.height() - y_offset)
465 x_offset += used_width;
468 y_offset += used_height;
472 QVector<QRect> pages_to_print;
473 for (
int i = 0 ; i < v_pages_count ; ++ i) {
474 for (
int j = 0 ; j < h_pages_count ; ++ j) {
475 pages_to_print << pages_grid.at(i).at(j);
481 for (
int i = 0 ; i < pages_to_print.count() ; ++ i) {
482 QRect current_rect(pages_to_print.at(i));
486 QRect(QPoint(0,0), current_rect.size()),
487 current_rect.translated(diagram_rect.topLeft()),
490 if (i != pages_to_print.count() - 1) {
491 printer -> newPage();
497 foreach (QGraphicsView *view, diagram -> views()) {
498 view -> setInteractive(
true);
502 foreach (QGraphicsItem *qgi, focusable_items) {
503 qgi -> setFlag(QGraphicsItem::ItemIsFocusable,
true);
507 foreach (QGraphicsItem *qgi, selected_elmts) qgi -> setSelected(
true);
524 state_exportProperties = diagram -> applyProperties(options);
527 diagram -> applyProperties(state_exportProperties);
541 while (!settings.group().isEmpty()) settings.endGroup();
542 settings.beginGroup(
"printers");
543 settings.beginGroup(printer_section);
545 settings.setValue(
"orientation",
printer_ -> orientation() == QPrinter::Portrait ?
"portrait" :
"landscape");
546 settings.setValue(
"papersize",
int(
printer_ -> paperSize()));
548 QSizeF size =
printer_ -> paperSize(QPrinter::Millimeter);
549 settings.setValue(
"customwidthmm", size.width());
550 settings.setValue(
"customheightmm", size.height());
552 settings.remove(
"customwidthmm");
553 settings.remove(
"customheightmm");
555 qreal left, top, right, bottom;
556 printer_ -> getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
557 settings.setValue(
"marginleft", left);
558 settings.setValue(
"margintop", top);
559 settings.setValue(
"marginright", right);
560 settings.setValue(
"marginbottom", bottom);
561 settings.setValue(
"fullpage",
printer_ -> fullPage() ?
"true" :
"false");
577 while (!settings.group().isEmpty()) settings.endGroup();
578 settings.beginGroup(
"printers");
579 if (!settings.childGroups().contains(printer_section)) {
584 settings.beginGroup(printer_section);
585 if (settings.contains(
"orientation")) {
586 QString value = settings.value(
"orientation",
"landscape").toString();
587 printer_ -> setOrientation(value ==
"landscape" ? QPrinter::Landscape : QPrinter::Portrait);
589 if (settings.contains(
"papersize")) {
590 int value = settings.value(
"papersize", QPrinter::A4).toInt();
593 int w = settings.value(
"customwidthmm", -1).toInt(&w_ok);
594 int h = settings.value(
"customheightmm", -1).toInt(&h_ok);
595 if (w_ok && h_ok && w != -1 && h != -1) {
596 printer_ -> setPaperSize(QSizeF(w, h), QPrinter::Millimeter);
599 printer_ -> setPaperSize(static_cast<QPrinter::PaperSize>(value));
604 printer_ -> getPageMargins(&margins[0], &margins[1], &margins[2], &margins[3], QPrinter::Millimeter);
605 QStringList margins_names(QStringList() <<
"left" <<
"top" <<
"right" <<
"bottom");
606 for (
int i = 0 ; i < 4 ; ++ i) {
608 qreal value = settings.value(
"margin" + margins_names.at(i), -1.0).toReal(&conv_ok);
609 if (conv_ok && value != -1.0) margins[i] = value;
611 printer_ -> setPageMargins(margins[0], margins[1], margins[2], margins[3], QPrinter::Millimeter);
612 printer_ -> setFullPage(settings.value(
"fullpage",
"false").toString() ==
"true");
623 QPrinter::OutputFormat printer_format = printer -> outputFormat();
624 if (printer_format == QPrinter::NativeFormat) {
625 return(printer -> printerName().replace(
" ",
"_"));
626 }
else if (printer_format == QPrinter::PdfFormat) {
627 return(
"QET_PDF_Printing");
ExportProperties exportProperties() const
DiagramPrintDialog(QETProject *, QWidget *=nullptr)
QColor backup_diagram_background_color
DiagramsChooser * diagramsChooser()
void printDiagram(Diagram *, bool, const ExportProperties &, QPainter *, QPrinter *=nullptr)
void browseFilePrintTypeDialog()
QString settingsSectionName(const QPrinter *)
void updatePrintTypeDialog()
QDialogButtonBox * buttons_
const QString displayedVersion
QElectroTech displayed version.
void saveReloadDiagramParameters(Diagram *, const ExportProperties &, bool)
QRadioButton * pdf_choice_
void print(const QList< Diagram *> &, bool, const ExportProperties &)
int horizontalPagesCount(Diagram *, const ExportProperties &, bool=false) const
~DiagramPrintDialog() override
QLabel * printtype_label_
QRect diagramRect(Diagram *, const ExportProperties &) const
QPushButton * browse_button_
bool fitDiagramsToPages() const
int pagesCount(Diagram *, const ExportProperties &, bool=false) const
QRadioButton * printer_choice_
void acceptPrintTypeDialog()
bool draw_titleblock
Whether to render the title block.
void loadPageSetupForCurrentPrinter()
static QColor background_color
background color of diagram
void buildPrintTypeDialog()
QButtonGroup * printtype_choice_
int verticalPagesCount(Diagram *, const ExportProperties &, bool=false) const
QMessageBox::StandardButton information(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
void savePageSetupForCurrentPrinter()
QLineEdit * filepath_field_
void setFileName(const QString &)
void setDocName(const QString &)