diff --git a/qelectrotech.pro b/qelectrotech.pro
index 2901a30d5..eb5f7d921 100644
--- a/qelectrotech.pro
+++ b/qelectrotech.pro
@@ -117,7 +117,8 @@ INCLUDEPATH += sources \
sources/pugixml \
sources/dataBase \
sources/dataBase/ui \
- sources/factory/ui
+ sources/factory/ui \
+ sources/print
# Fichiers sources
@@ -150,7 +151,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
$$files(sources/pugixml/*.hpp) \
$$files(sources/dataBase/*.h) \
$$files(sources/dataBase/ui/*.h) \
- $$files(sources/factory/ui/*.h)
+ $$files(sources/factory/ui/*.h) \
+ $$files(sources/print/*.h)
SOURCES += $$files(sources/*.cpp) \
$$files(sources/editor/*.cpp) \
@@ -182,7 +184,8 @@ SOURCES += $$files(sources/*.cpp) \
$$files(sources/pugixml/*.cpp) \
$$files(sources/dataBase/*.cpp) \
$$files(sources/dataBase/ui/*.cpp) \
- $$files(sources/factory/ui/*.cpp)
+ $$files(sources/factory/ui/*.cpp) \
+ $$files(sources/print/*.cpp)
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
RESOURCES += qelectrotech.qrc
@@ -207,7 +210,8 @@ FORMS += $$files(sources/richtext/*.ui) \
$$files(sources/NameList/ui/*.ui) \
$$files(sources/qetgraphicsitem/ViewItem/ui/*.ui) \
$$files(sources/dataBase/ui/*.ui) \
- $$files(sources/factory/ui/*.ui)
+ $$files(sources/factory/ui/*.ui) \
+ $$files(sources/print/*.ui)
UI_SOURCES_DIR = sources/ui/
UI_HEADERS_DIR = sources/ui/
diff --git a/sources/diagramprintdialog.cpp b/sources/diagramprintdialog.cpp
deleted file mode 100644
index 38860967e..000000000
--- a/sources/diagramprintdialog.cpp
+++ /dev/null
@@ -1,657 +0,0 @@
-/*
- Copyright 2006-2020 The QElectroTech Team
- This file is part of QElectroTech.
-
- QElectroTech is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- QElectroTech is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with QElectroTech. If not, see .
-*/
-#include "diagramprintdialog.h"
-#include "qetprintpreviewdialog.h"
-#include
-#include "diagramschooser.h"
-#include "exportproperties.h"
-#include "qeticons.h"
-#include "qetmessagebox.h"
-
-#include
-#include
-
-/**
- Constructeur
- @param project Schema a imprimer
- @param parent Widget parent du dialogue
-*/
-DiagramPrintDialog::DiagramPrintDialog(QETProject *project, QWidget *parent) :
- QWidget(parent),
- project_(project),
- dialog_(nullptr)
-{
- // initialise l'imprimante
- printer_ = new QPrinter();
-
- // orientation paysage par defaut
- printer_ -> setOrientation(QPrinter::Landscape);
- backup_diagram_background_color = Diagram::background_color;
- Diagram::background_color = Qt::white;
-}
-
-/**
- Destructeur
-*/
-DiagramPrintDialog::~DiagramPrintDialog()
-{
- delete dialog_;
- delete printer_;
- Diagram::background_color = backup_diagram_background_color;
-}
-
-/**
- Definit le nom du PDF si l'utilisateur choisit une sortie vers un PDF
-*/
-void DiagramPrintDialog::setFileName(const QString &name) {
- file_name_ = name;
-}
-
-/**
- @return le nom du PDF
-*/
-QString DiagramPrintDialog::fileName() const
-{
- return(file_name_);
-}
-
-/**
- Definit le nom du document
-*/
-void DiagramPrintDialog::setDocName(const QString &name) {
- doc_name_ = name;
-}
-
-/**
- @return le nom du document
-*/
-QString DiagramPrintDialog::docName() const
-{
- return(doc_name_);
-}
-
-/**
- @brief DiagramPrintDialog::diagramRect
- @param diagram : Diagram to be printed
- @param options :
- @return the rectangle to be printed
-*/
-QRect DiagramPrintDialog::diagramRect(Diagram *diagram,
- const ExportProperties &options) const
-{
- if (!diagram) return(QRect());
-
- QRectF diagram_rect = diagram -> border_and_titleblock.borderAndTitleBlockRect();
- if (!options.draw_titleblock) {
- qreal titleblock_height = diagram -> border_and_titleblock.titleBlockRect().height();
- diagram_rect.setHeight(diagram_rect.height() - titleblock_height);
- }
-
- // ajuste la bordure du schema d'un pixel (epaisseur du trait)
- diagram_rect = diagram_rect.adjusted(0.0, 0.0, 1.0, 1.0);
-
- return(diagram_rect.toAlignedRect());
-}
-
-/**
- Execute le dialogue d'impression
-*/
-void DiagramPrintDialog::exec()
-{
-
- // prise en compte du nom du document
- if (!doc_name_.isEmpty()) printer_ -> setDocName(doc_name_);
- printer_ -> setCreator(QString("QElectroTech %1").arg(QET::displayedVersion));
-
- // affichage d'un premier dialogue demandant a l'utilisateur le type
- // d'impression qu'il souhaite effectuer
- buildPrintTypeDialog();
- if (dialog_ -> exec() == QDialog::Rejected) return;
-
- // parametrage de l'imprimante en fonction du type d'impression choisi
- if (printer_choice_ -> isChecked()) {
- // affichage du dialogue d'impression standard pour parametrer l'imprimante
- QPrintDialog print_dialog(printer_, parentWidget());
-#ifdef Q_OS_MACOS
- print_dialog.setWindowFlags(Qt::Sheet);
-#endif
- print_dialog.setWindowTitle(tr("Options d'impression", "window title"));
- print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintShowPageSize);
- if (print_dialog.exec() == QDialog::Rejected) return;
- }
- else
- {
- printer_ -> setOutputFormat(QPrinter::PdfFormat);
- printer_ -> setOutputFileName(filepath_field_ -> text());
- }
-
- loadPageSetupForCurrentPrinter();
-
- //Preview before print
-#if defined Q_OS_LINUX
- //Due to some bug with xfwm, we display this dialog has a windows on linux os (X11)
- //@TODO see if we must this line with graphic server wayland
-#if TODO_LIST
-#pragma message("@TODO see if we must this line with graphic server wayland")
-#endif
- QETPrintPreviewDialog preview_dialog(project_, printer_, parentWidget(), Qt::Window);
-#else
- QETPrintPreviewDialog preview_dialog(project_, printer_, parentWidget());
-#endif
- connect(
- &preview_dialog,
- SIGNAL(paintRequested(const QList &, bool, const ExportProperties, QPrinter *)),
- this,
- SLOT(print(const QList &, bool, const ExportProperties))
- );
- DiagramsChooser *dc = preview_dialog.diagramsChooser();
- dc -> setSelectedAllDiagrams();
- if (preview_dialog.exec() == QDialog::Rejected) return;
-
- savePageSetupForCurrentPrinter();
-
- // effectue l'impression en elle-meme
- print(
- dc -> selectedDiagrams(),
- preview_dialog.fitDiagramsToPages(),
- preview_dialog.exportProperties()
- );
-}
-
-/**
- @param diagram Schema a imprimer
- @param options Rendering options
- @param fullpage true pour utiliser toute la feuille dans le calcul
- @return Le nombre de pages necessaires pour imprimer le schema
- avec l'orientation et le format papier utilise dans l'imprimante en cours.
-*/
-int DiagramPrintDialog::pagesCount(Diagram *diagram, const ExportProperties &options, bool fullpage) const
-{
- return(horizontalPagesCount(diagram, options, fullpage) * verticalPagesCount(diagram, options, fullpage));
-}
-
-/**
- @param diagram Schema a imprimer
- @param options Rendering options
- @param fullpage true pour utiliser toute la feuille dans le calcul
- @return La largeur du "poster" en nombre de pages pour imprimer le schema
- avec l'orientation et le format papier utilise dans l'imprimante en cours.
-*/
-int DiagramPrintDialog::horizontalPagesCount(Diagram *diagram, const ExportProperties &options, bool fullpage) const
-{
- // note : pageRect et Paper Rect tiennent compte de l'orientation du papier
- QRect printable_area = fullpage ? printer_ -> paperRect() : printer_ -> pageRect();
- QRect diagram_rect = diagramRect(diagram, options);
-
- int h_pages_count = int(ceil(qreal(diagram_rect.width()) / qreal(printable_area.width())));
- return(h_pages_count);
-}
-
-/**
- @param diagram Schema a imprimer
- @param options Rendering options
- @param fullpage true pour utiliser toute la feuille dans le calcul
- @return La largeur du "poster" en nombre de pages pour imprimer le schema
- avec l'orientation et le format papier utilise dans l'imprimante en cours.
-*/
-int DiagramPrintDialog::verticalPagesCount(Diagram *diagram, const ExportProperties &options, bool fullpage) const
-{
- // note : pageRect et Paper Rect tiennent compte de l'orientation du papier
- QRect printable_area = fullpage ? printer_ -> paperRect() : printer_ -> pageRect();
- QRect diagram_rect = diagramRect(diagram, options);
-
- int v_pages_count = int(ceil(qreal(diagram_rect.height()) / qreal(printable_area.height())));
- return(v_pages_count);
-}
-
-/**
- Construit un dialogue non standard pour demander a l'utilisateur quelle type
- d'impression il souhaite effectuer : PDF, PS ou imprimante physique
-*/
-void DiagramPrintDialog::buildPrintTypeDialog()
-{
- // initialisation des widgets
- dialog_ = new QDialog(parentWidget());
-#ifdef Q_OS_MACOS
- dialog_ -> setWindowFlags(Qt::Sheet);
-#endif
-
- printtype_label_ = new QLabel(tr("Quel type d'impression désirez-vous effectuer ?"));
- printer_icon_ = new QLabel();
- pdf_icon_ = new QLabel();
-
- printtype_choice_ = new QButtonGroup();
- printer_choice_ = new QRadioButton(tr("Impression sur une imprimante physique", "Print type choice"));
- pdf_choice_ = new QRadioButton(tr("Impression vers un fichier au format PDF", "Print type choice"));
-
- filepath_field_ = new QLineEdit();
- browse_button_ = new QPushButton("...");
- buttons_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
-
- dialog_ -> setWindowTitle(tr("Choix du type d'impression"));
- printer_icon_ -> setPixmap(QET::Icons::Printer.pixmap(32, 32));
- pdf_icon_ -> setPixmap(QET::Icons::PDF.pixmap(32, 32));
-
- printtype_choice_ -> addButton(printer_choice_);
- printtype_choice_ -> addButton(pdf_choice_);
-
- printer_choice_ -> setChecked(true);
- if (!file_name_.isEmpty()) filepath_field_ -> setText(file_name_ + ".pdf");
-
- // connexions signaux / slots
- connect(printer_choice_, SIGNAL(toggled(bool)), this, SLOT(updatePrintTypeDialog()));
- connect(pdf_choice_, SIGNAL(toggled(bool)), this, SLOT(updatePrintTypeDialog()));
- connect(browse_button_, SIGNAL(clicked(bool)), this, SLOT(browseFilePrintTypeDialog()));
- connect(buttons_, SIGNAL(accepted()), this, SLOT(acceptPrintTypeDialog()));
- connect(buttons_, SIGNAL(rejected()), dialog_, SLOT(reject()));
-
- // organisation graphique
- glayout0_ = new QGridLayout();
- hlayout0_ = new QHBoxLayout();
- vlayout0_ = new QVBoxLayout();
-
- hlayout0_ -> addWidget(filepath_field_);
- hlayout0_ -> addWidget(browse_button_);
- glayout0_ -> addWidget(printer_icon_, 0, 0);
- glayout0_ -> addWidget(printer_choice_, 0, 1);
- glayout0_ -> addWidget(pdf_icon_, 1, 0);
- glayout0_ -> addWidget(pdf_choice_, 1, 1);
- glayout0_ -> addLayout(hlayout0_, 3, 1);
-
- vlayout0_ -> addWidget(printtype_label_);
- vlayout0_ -> addLayout(glayout0_);
- vlayout0_ -> addWidget(buttons_);
-
- dialog_ -> setLayout(vlayout0_);
-
- updatePrintTypeDialog();
-}
-
-/**
- Assure la coherence du dialogue permettant le choix du type d'impression
-*/
-void DiagramPrintDialog::updatePrintTypeDialog()
-{
- // imprime-t-on vers un fichier ?
- bool file_print = !(printer_choice_ -> isChecked());
-
- // on n'active le champ fichier que pour les impressions vers un fichier
- filepath_field_ -> setEnabled(file_print);
- browse_button_ -> setEnabled(file_print);
-
- // on corrige eventuellement l'extension du fichier deja selectionne
- if (file_print)
- {
- QString filepath = filepath_field_ -> text();
- if (!filepath.isEmpty())
- {
- if (pdf_choice_ -> isChecked() && filepath.endsWith(".ps"))
- {
- QRegularExpression re
- ("\\.ps$",
- QRegularExpression::CaseInsensitiveOption);
- filepath.replace(re, ".pdf");
- filepath_field_ -> setText(filepath);
- }
- }
- }
-}
-
-/**
- Verifie l'etat du dialogue permettant le choix du type d'impression lorsque
- l'utilisateur le valide.
-*/
-void DiagramPrintDialog::acceptPrintTypeDialog()
-{
- bool file_print = !(printer_choice_ -> isChecked());
- if (file_print) {
- // un fichier doit avoir ete entre
- if (filepath_field_ -> text().isEmpty()) {
- QET::QetMessageBox::information(
- parentWidget(),
- tr("Fichier manquant", "message box title"),
- tr("Vous devez indiquer le chemin du fichier PDF/PS à créer.", "message box content")
- );
- } else dialog_ -> accept();
- } else {
-#if TODO_LIST
-#pragma message("@TODO une imprimante doit avoir ete selectionnee")
-#endif
- // une imprimante doit avoir ete selectionnee
- /// @todo
- dialog_ -> accept();
- }
-}
-
-/**
- Permet a l'utilisateur de choisir un fichier
-*/
-void DiagramPrintDialog::browseFilePrintTypeDialog()
-{
- QString extension;
- QString filter;
- if (printer_choice_ -> isChecked()) return;
- else if (pdf_choice_ -> isChecked())
- {
- extension = ".pdf";
- filter = tr("Fichiers PDF (*.pdf)", "file filter");
- }
-
- QString filepath = QFileDialog::getSaveFileName(
- parentWidget(),
- QString(),
- filepath_field_ -> text(),
- filter
- );
-
- if (!filepath.isEmpty()) {
- if (!filepath.endsWith(extension)) filepath += extension;
- filepath = QDir::toNativeSeparators(QDir::cleanPath(filepath));
- filepath_field_ -> setText(filepath);
- }
-}
-
-/**
- Effectue l'impression elle-meme
- @param diagrams Schemas a imprimer
- @param fit_page Booleen indiquant s'il faut adapter les schemas aux pages
- ou non
- @param options Options de rendu
-*/
-void DiagramPrintDialog::print(const QList &diagrams,
- bool fit_page,
- const ExportProperties& options) {
- //qDebug() << "Demande d'impression de " << diagrams.count() << "schemas.";
-#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
- #ifdef Q_OS_WIN
- #ifdef QT_DEBUG
- qDebug() << "--";
- qDebug() << "DiagramPrintDialog::print printer_->resolution() before " << printer_->resolution();
- qDebug() << "DiagramPrintDialog::print screennumber " << QApplication::desktop()->screenNumber();
- #endif
-
- QScreen *srn = QApplication::screens().at(QApplication::desktop()->screenNumber());
- qreal dotsPerInch = (qreal)srn->logicalDotsPerInch();
- printer_->setResolution(dotsPerInch);
-
- #ifdef QT_DEBUG
- qDebug() << "DiagramPrintDialog::print dotsPerInch " << dotsPerInch;
- qDebug() << "DiagramPrintDialog::print printer_->resolution() after" << printer_->resolution();
- qDebug() << "--";
- #endif
- #endif
-#endif
- // QPainter utiliser pour effectuer le rendu
- QPainter qp(printer_);
-
- // cas special : il n'y a aucun schema a imprimer
- if (!diagrams.count()) {
- qp.end();
- return;
- }
-
- // imprime les schemas
- for (int i = 0 ; i < diagrams.count() ; ++ i) {
- printDiagram(diagrams[i], fit_page, options, &qp, printer_);
- if (i != diagrams.count() - 1) {
- printer_ -> newPage();
- }
- }
-}
-
-/**
- Imprime un schema
- @param diagram Schema a imprimer
- @param fit_page True pour adapter les schemas aux pages, false sinon
- @param options Options de rendu a appliquer pour l'impression
- @param qp QPainter a utiliser (deja initialise sur printer)
- @param printer Imprimante a utiliser
-*/
-void DiagramPrintDialog::printDiagram(Diagram *diagram,
- bool fit_page,
- const ExportProperties &options,
- QPainter *qp,
- QPrinter *printer) {
- //qDebug() << printer -> paperSize() << printer -> paperRect() << diagram -> title();
- // l'imprimante utilise-t-elle toute la feuille ?
- bool full_page = printer -> fullPage();
-
- // impression physique (!= fichier PDF)
- if (printer -> outputFileName().isEmpty()) {
- // utiliser cette condition pour agir differemment en cas d'impression physique
- }
-
- saveReloadDiagramParameters(diagram, options, true);
-
- // deselectionne tous les elements
- QList selected_elmts = diagram -> selectedItems();
- foreach (QGraphicsItem *qgi, selected_elmts) qgi -> setSelected(false);
-
- // enleve le flag focusable de tous les elements concernes pour eviter toute reprise de focus par un champ de texte editable
- QList focusable_items;
- foreach (QGraphicsItem *qgi, diagram -> items()) {
- if (qgi -> flags() & QGraphicsItem::ItemIsFocusable) {
- focusable_items << qgi;
- qgi -> setFlag(QGraphicsItem::ItemIsFocusable, false);
- }
- }
-
- // evite toute autre forme d'interaction
- foreach (QGraphicsView *view, diagram -> views()) {
- view -> setInteractive(false);
- }
-
- QRect diagram_rect = diagramRect(diagram, options);
- if (fit_page) {
- // impression adaptee sur une seule page
- diagram -> render(qp, QRectF(), diagram_rect, Qt::KeepAspectRatio);
- } else {
- // impression sur une ou plusieurs pages
- QRect printed_area = full_page ? printer -> paperRect() : printer -> pageRect();
- //qDebug() << "impression sur une ou plusieurs pages";
- //qDebug() << " schema :" << diagram_rect;
- //qDebug() << " page :" << printed_area;
-
- int used_width = printed_area.width();
- int used_height = printed_area.height();
- int h_pages_count = horizontalPagesCount(diagram, options, full_page);
- int v_pages_count = verticalPagesCount(diagram, options, full_page);
-
- QVector< QVector< QRect > > pages_grid;
- // le schema est imprime sur une matrice de feuilles
- // parcourt les lignes de la matrice
- int y_offset = 0;
- for (int i = 0 ; i < v_pages_count ; ++ i) {
- pages_grid << QVector< QRect >();
-
- // parcourt les feuilles de la ligne
- int x_offset = 0;
- for (int j = 0 ; j < h_pages_count ; ++ j) {
- pages_grid.last() << QRect(
- QPoint(x_offset, y_offset),
- QSize(
- qMin(used_width, diagram_rect.width() - x_offset),
- qMin(used_height, diagram_rect.height() - y_offset)
- )
- );
- x_offset += used_width;
- }
-
- y_offset += used_height;
- }
-
- // ne retient que les pages a imprimer
- QVector pages_to_print;
- for (int i = 0 ; i < v_pages_count ; ++ i) {
- for (int j = 0 ; j < h_pages_count ; ++ j) {
- pages_to_print << pages_grid.at(i).at(j);
- }
- }
- //qDebug() << " " << pages_to_print.count() << " pages a imprimer :";
-
- // parcourt les pages pour impression
- for (int i = 0 ; i < pages_to_print.count() ; ++ i) {
- QRect current_rect(pages_to_print.at(i));
- //qDebug() << " " << current_rect;
- diagram -> render(
- qp,
- QRect(QPoint(0,0), current_rect.size()),
- current_rect.translated(diagram_rect.topLeft()),
- Qt::KeepAspectRatio
- );
- if (i != pages_to_print.count() - 1) {
- printer -> newPage();
- }
- }
- }
-
- // remet en place les interactions
- foreach (QGraphicsView *view, diagram -> views()) {
- view -> setInteractive(true);
- }
-
- // restaure les flags focusable
- foreach (QGraphicsItem *qgi, focusable_items) {
- qgi -> setFlag(QGraphicsItem::ItemIsFocusable, true);
- }
-
- // restaure les elements selectionnes
- foreach (QGraphicsItem *qgi, selected_elmts) qgi -> setSelected(true);
-
- saveReloadDiagramParameters(diagram, options, false);
-}
-
-/**
- Sauve ou restaure les parametres du schema
- @param diagram Schema dont on sauve ou restaure les parametres
- @param options Parametres a appliquer
- @param save true pour memoriser les parametres du schema et appliquer ceux
- definis dans options, false pour restaurer les parametres
-*/
-void DiagramPrintDialog::saveReloadDiagramParameters(Diagram *diagram, const ExportProperties& options, bool save) {
- static ExportProperties state_exportProperties;
-
- if (save) {
- // memorise les parametres relatifs au schema tout en appliquant les nouveaux
- state_exportProperties = diagram -> applyProperties(options);
- } else {
- // restaure les parametres relatifs au schema
- diagram -> applyProperties(state_exportProperties);
- }
-}
-
-/**
- Save parameters set in the "page setup" dialog into the QElectroTech
- configuration. Key/values pairs are associated to the printer for which
- they have been set.
-*/
-void DiagramPrintDialog::savePageSetupForCurrentPrinter()
-{
- QSettings settings;
- QString printer_section = settingsSectionName(printer_);
-
- while (!settings.group().isEmpty()) settings.endGroup();
- settings.beginGroup("printers");
- settings.beginGroup(printer_section);
-
- settings.setValue("orientation", printer_ -> orientation() == QPrinter::Portrait ? "portrait" : "landscape");
- settings.setValue("papersize", int(printer_ -> paperSize()));
- if (printer_ -> paperSize() == QPrinter::Custom) {
- QSizeF size = printer_ -> paperSize(QPrinter::Millimeter);
- settings.setValue("customwidthmm", size.width());
- settings.setValue("customheightmm", size.height());
- } else {
- settings.remove("customwidthmm");
- settings.remove("customheightmm");
- }
- qreal left, top, right, bottom;
- printer_ -> getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
- settings.setValue("marginleft", left);
- settings.setValue("margintop", top);
- settings.setValue("marginright", right);
- settings.setValue("marginbottom", bottom);
- settings.setValue("fullpage", printer_ -> fullPage() ? "true" : "false");
- settings.endGroup();
- settings.endGroup();
- settings.sync();
-}
-
-
-/**
- Load parameters previously set in the "page setup" dialog for the current
- printer, if any.
-*/
-void DiagramPrintDialog::loadPageSetupForCurrentPrinter()
-{
- QSettings settings;
- QString printer_section = settingsSectionName(printer_);
-
- while (!settings.group().isEmpty()) settings.endGroup();
- settings.beginGroup("printers");
- if (!settings.childGroups().contains(printer_section)) {
- settings.endGroup();
- return;
- }
-
- settings.beginGroup(printer_section);
- if (settings.contains("orientation")) {
- QString value = settings.value("orientation", "landscape").toString();
- printer_ -> setOrientation(value == "landscape" ? QPrinter::Landscape : QPrinter::Portrait);
- }
- if (settings.contains("papersize")) {
- int value = settings.value("papersize", QPrinter::A4).toInt();
- if (value == QPrinter::Custom) {
- bool w_ok, h_ok;
- int w = settings.value("customwidthmm", -1).toInt(&w_ok);
- int h = settings.value("customheightmm", -1).toInt(&h_ok);
- if (w_ok && h_ok && w != -1 && h != -1) {
- printer_ -> setPaperSize(QSizeF(w, h), QPrinter::Millimeter);
- }
- } else if (value < QPrinter::Custom) {
- printer_ -> setPaperSize(static_cast(value));
- }
- }
-
- qreal margins[4];
- printer_ -> getPageMargins(&margins[0], &margins[1], &margins[2], &margins[3], QPrinter::Millimeter);
- QStringList margins_names(QStringList() << "left" << "top" << "right" << "bottom");
- for (int i = 0 ; i < 4 ; ++ i) {
- bool conv_ok;
- qreal value = settings.value("margin" + margins_names.at(i), -1.0).toReal(&conv_ok);
- if (conv_ok && value != -1.0) margins[i] = value;
- }
- printer_ -> setPageMargins(margins[0], margins[1], margins[2], margins[3], QPrinter::Millimeter);
- printer_ -> setFullPage(settings.value("fullpage", "false").toString() == "true");
-
- settings.endGroup();
- settings.endGroup();
-}
-
-/**
- @return a section name for use with QSettings in order to store parameters
- related to \a printer.
-*/
-QString DiagramPrintDialog::settingsSectionName(const QPrinter *printer) {
- QPrinter::OutputFormat printer_format = printer -> outputFormat();
- if (printer_format == QPrinter::NativeFormat) {
- return(printer -> printerName().replace(" ", "_"));
- } else if (printer_format == QPrinter::PdfFormat) {
- return("QET_PDF_Printing");
- }
- return(QString());
-}
diff --git a/sources/diagramprintdialog.h b/sources/diagramprintdialog.h
deleted file mode 100644
index a996eca97..000000000
--- a/sources/diagramprintdialog.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- Copyright 2006-2020 The QElectroTech Team
- This file is part of QElectroTech.
-
- QElectroTech is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- QElectroTech is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with QElectroTech. If not, see .
-*/
-#ifndef DIAGRAM_PRINT_DIALOG_H
-#define DIAGRAM_PRINT_DIALOG_H
-#include
-
-#include "qetproject.h"
-#include "diagram.h"
-#include "exportproperties.h"
-
-class QPrinter;
-
-/**
- @brief The DiagramPrintDialog class
- This class implements both the dialog allowing users to configure
- the printing of a project file and the printing itself.
-*/
-class DiagramPrintDialog : public QWidget
-{
-
-
- Q_OBJECT
- // Constructors, destructor
- public:
- DiagramPrintDialog(QETProject *, QWidget * = nullptr);
- ~DiagramPrintDialog() override;
- private:
- DiagramPrintDialog(const DiagramPrintDialog &);
-
- // methods
- public:
- void setFileName(const QString &);
- QString fileName() const;
- void setDocName(const QString &);
- QString docName() const;
- QRect diagramRect(Diagram *, const ExportProperties &) const;
- int pagesCount(Diagram *,
- const ExportProperties &,
- bool = false) const;
- int horizontalPagesCount(Diagram *,
- const ExportProperties &,
- bool = false) const;
- int verticalPagesCount(Diagram *,
- const ExportProperties &,
- bool = false) const;
- void exec();
-
- private:
- void buildPrintTypeDialog();
- void buildDialog();
- void saveReloadDiagramParameters(Diagram *,
- const ExportProperties&,
- bool);
- void savePageSetupForCurrentPrinter();
- void loadPageSetupForCurrentPrinter();
- QString settingsSectionName(const QPrinter *);
-
- private slots:
- void print(const QList &, bool, const ExportProperties&);
- void printDiagram(Diagram *,
- bool,
- const ExportProperties &,
- QPainter *,
- QPrinter * = nullptr);
- void updatePrintTypeDialog();
- void acceptPrintTypeDialog();
- void browseFilePrintTypeDialog();
-
- // attributes
- private:
- QETProject *project_;
- QPrinter *printer_;
- QString doc_name_;
- QString file_name_;
-
- QDialog *dialog_;
- QLabel *printtype_label_;
- QGridLayout *glayout0_;
- QVBoxLayout *vlayout0_;
- QHBoxLayout *hlayout0_;
- QLabel *printer_icon_;
- QLabel *pdf_icon_;
- QButtonGroup *printtype_choice_;
- QRadioButton *printer_choice_;
- QRadioButton *pdf_choice_;
- QLineEdit *filepath_field_;
- QPushButton *browse_button_;
- QDialogButtonBox *buttons_;
- QColor backup_diagram_background_color;
-};
-#endif
diff --git a/sources/print/projectprintwindow.cpp b/sources/print/projectprintwindow.cpp
new file mode 100644
index 000000000..5527df4c4
--- /dev/null
+++ b/sources/print/projectprintwindow.cpp
@@ -0,0 +1,580 @@
+/*
+ Copyright 2006-2020 The QElectroTech Team
+ This file is part of QElectroTech.
+
+ QElectroTech is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ QElectroTech is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with QElectroTech. If not, see .
+*/
+#include "projectprintwindow.h"
+#include "ui_projectprintwindow.h"
+
+#include "qetproject.h"
+#include "diagram.h"
+#include "qeticons.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+/**
+ * @brief ProjectPrintWindow::ProjectPrintWindow
+ * Use this static function to properly lauch the print dialog.
+ * @param project : project to print
+ * @param parent : parent widget
+ */
+void ProjectPrintWindow::launchDialog(QETProject *project, QWidget *parent)
+{
+ auto dir_path = project->currentDir();
+ auto doc_name = ProjectPrintWindow::docName(project);
+ QString file_name = QDir::toNativeSeparators(QDir::cleanPath(dir_path + "/" + doc_name));
+ if (!file_name.endsWith(".pdf")) {
+ file_name.append(".pdf");
+ }
+
+ auto printer_ = new QPrinter();
+ printer_->setOrientation(QPrinter::Landscape);
+ printer_->setDocName(doc_name);
+ printer_->setOutputFileName(file_name);
+ printer_->setCreator(QString("QElectroTech %1").arg(QET::displayedVersion));
+
+ QPrintDialog print_dialog(printer_, parent);
+#ifdef Q_OS_MACOS
+print_dialog.setWindowFlags(Qt::Sheet);
+#endif
+ print_dialog.setWindowTitle(tr("Options d'impression", "window title"));
+ print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintToFile | QAbstractPrintDialog::PrintShowPageSize);
+ if (print_dialog.exec() == QDialog::Rejected) {
+ delete printer_;
+ return;
+ }
+
+ auto w = new ProjectPrintWindow(project, printer_, parent);
+ w->showMaximized();
+}
+
+/**
+ * @brief ProjectPrintWindow::docName
+ * @param project
+ * @return the doc name to use for project
+ */
+QString ProjectPrintWindow::docName(QETProject *project)
+{
+ QString doc_name;
+ if (!project->title().isEmpty()) {
+ doc_name = project->title();
+ } else if (!project->filePath().isEmpty()) {
+ doc_name = QFileInfo(project->filePath()).baseName();
+ }
+
+ doc_name = QET::stringToFileName(doc_name);
+ if (doc_name.isEmpty()) {
+ doc_name = tr("projet", "string used to generate a filename");
+ }
+
+ return doc_name;
+}
+
+/**
+ * @brief ProjectPrintWindow::ProjectPrintWindow
+ * Constructor, don't use this class directly, instead use ProjectPrintWindow::launchDialog static function.
+ * @param project
+ * @param printer : QPrinter to use. Note that ProjectPrintWindow take ownerchip of @printer
+ * @param parent
+ */
+ProjectPrintWindow::ProjectPrintWindow(QETProject *project, QPrinter *printer, QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::ProjectPrintWindow),
+ m_project(project),
+ m_printer(printer)
+{
+ ui->setupUi(this);
+
+ loadPageSetupForCurrentPrinter();
+
+ m_preview = new QPrintPreviewWidget(m_printer);
+ connect(m_preview, &QPrintPreviewWidget::paintRequested, this, &ProjectPrintWindow::requestPaint);
+ ui->m_vertical_layout->addWidget(m_preview);
+
+ setUpDiagramList();
+
+ auto print_button = new QPushButton(QET::Icons::DocumentPrint, tr("Imprimer"));
+ ui->m_button_box->addButton(print_button, QDialogButtonBox::ActionRole);
+ connect(print_button, &QPushButton::clicked, this, &ProjectPrintWindow::print);
+
+ auto exp = ExportProperties::defaultPrintProperties();
+ ui->m_draw_border_cb->setChecked(exp.draw_border);
+ ui->m_draw_titleblock_cb->setChecked(exp.draw_titleblock);
+ ui->m_draw_terminal_cb->setChecked(exp.draw_terminals);
+ ui->m_keep_conductor_color_cb->setChecked(exp.draw_colored_conductors);
+
+ m_backup_diagram_background_color = Diagram::background_color;
+ Diagram::background_color = Qt::white;
+}
+
+/**
+ * @brief ProjectPrintWindow::~ProjectPrintWindow
+ */
+ProjectPrintWindow::~ProjectPrintWindow()
+{
+ delete ui;
+ delete m_printer;
+ Diagram::background_color = m_backup_diagram_background_color;
+}
+
+/**
+ * @brief ProjectPrintWindow::requestPaint
+ * @param slot called when m_preview emit paintRequested
+ */
+void ProjectPrintWindow::requestPaint()
+{
+ #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
+ #ifdef Q_OS_WIN
+ #ifdef QT_DEBUG
+ qDebug() << "--";
+ qDebug() << "DiagramPrintDialog::print printer_->resolution() before " << printer->resolution();
+ qDebug() << "DiagramPrintDialog::print screennumber " << QApplication::desktop()->screenNumber();
+ #endif
+
+ QScreen *srn = QApplication::screens().at(QApplication::desktop()->screenNumber());
+ qreal dotsPerInch = (qreal)srn->logicalDotsPerInch();
+ printer->setResolution(dotsPerInch);
+
+ #ifdef QT_DEBUG
+ qDebug() << "DiagramPrintDialog::print dotsPerInch " << dotsPerInch;
+ qDebug() << "DiagramPrintDialog::print printer_->resolution() after" << printer->resolution();
+ qDebug() << "--";
+ #endif
+ #endif
+ #endif
+
+ if (!m_project->diagrams().count()) {
+ return;
+ }
+
+ bool first = true;
+ QPainter painter(m_printer);
+ for (auto diagram : selectedDiagram())
+ {
+ first ? first = false : m_printer->newPage();
+ printDiagram(diagram, ui->m_fit_in_page_cb->isChecked(), &painter, m_printer);
+ }
+}
+
+/**
+ * @brief ProjectPrintWindow::printDiagram
+ * Print @diagram on the @printer
+ * @param diagram
+ * @param fit_page
+ * @param printer
+ */
+void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter *painter, QPrinter *printer)
+{
+
+ ////Prepare the print////
+ //Deselect all
+ diagram->deselectAll();
+ //Disable focus flags
+ QList focusable_items;
+ for (auto qgi : diagram->items()) {
+ if (qgi->flags() & QGraphicsItem::ItemIsFocusable) {
+ focusable_items << qgi;
+ qgi->setFlag(QGraphicsItem::ItemIsFocusable, false);
+ }
+ }
+ //Disable intercation
+ for (auto view : diagram->views()) {
+ view->setInteractive(false);
+ }
+ auto option = exportProperties();
+ saveReloadDiagramParameters(diagram, option, true);
+ ////Prepare end////
+
+
+ auto full_page = printer->fullPage();
+ auto diagram_rect = diagramRect(diagram, option);
+ if (fit_page) {
+ diagram->render(painter, QRectF(), diagram_rect, Qt::KeepAspectRatio);
+ } else {
+ //Print on one or several pages
+ auto printed_rect = full_page ? printer->paperRect() : printer->pageRect();
+
+ auto used_width = printed_rect.width();
+ auto used_height = printed_rect.height();
+ auto h_pages_count = horizontalPagesCount(diagram, option, full_page);
+ auto v_pages_count = verticalPagesCount(diagram, option, full_page);
+
+ QVector> page_grid;
+ //The diagram is printed on a matrix of sheet
+ //scrolls through the rows of the matrix
+ auto y_offset = 0;
+ for (auto i=0 ; i();
+ //scrolls through the lines of sheet
+ auto x_offset = 0;
+ for (auto j=0 ; j page_to_print;
+ for (auto i=0 ; i < v_pages_count ; ++i) {
+ for (int j=0 ; j < h_pages_count ; ++j) {
+ page_to_print << page_grid.at(i).at(j);
+ }
+ }
+
+ //Scrolls through the page for print
+ bool first_ = true;
+ for (auto page : page_to_print)
+ {
+ first_ ? first_ = false : m_printer->newPage();
+ diagram->render(painter, QRect(QPoint(0,0), page.size()), page.translated(diagram_rect.topLeft()), Qt::KeepAspectRatio);
+ }
+ }
+
+ ////Print is finished, restore diagram and graphics item properties
+ for (auto view : diagram->views()) {
+ view->setInteractive(true);
+ }
+ for (auto qgi : focusable_items) {
+ qgi->setFlag(QGraphicsItem::ItemIsFocusable, true);
+ }
+ saveReloadDiagramParameters(diagram, option, false);
+}
+
+/**
+ * @brief ProjectPrintWindow::diagramRect
+ * @param diagram
+ * @param option
+ * @return The rectangle of diagram to be printed
+ */
+QRect ProjectPrintWindow::diagramRect(Diagram *diagram, const ExportProperties &option) const
+{
+ auto diagram_rect = diagram->border_and_titleblock.borderAndTitleBlockRect();
+ if (!option.draw_titleblock) {
+ auto titleblock_height = diagram->border_and_titleblock.titleBlockRect().height();
+ diagram_rect.setHeight(diagram_rect.height() - titleblock_height);
+ }
+
+ //Adjust the border of diagram to 1px (width of the line)
+ diagram_rect.adjust(0,0,1,1);
+
+ return (diagram_rect.toAlignedRect());
+}
+
+/**
+ * @brief ProjectPrintWindow::horizontalPagesCount
+ * @param diagram : diagram to print
+ * @param option : option used to render
+ * @param full_page : full page or not
+ * @return The width of the "poster" in number of page for print the diagram
+ * with the orientation and the paper format used by the actual printer
+ */
+int ProjectPrintWindow::horizontalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const
+{
+ QRect printable_area = full_page ? m_printer-> paperRect() : m_printer-> pageRect();
+ QRect diagram_rect = diagramRect(diagram, option);
+
+ int h_pages_count = int(ceil(qreal(diagram_rect.width()) / qreal(printable_area.width())));
+ return(h_pages_count);
+}
+
+/**
+ * @brief ProjectPrintWindow::verticalPagesCount
+ * @param diagram : diagram to print
+ * @param option : option used to render
+ * @param full_page : full page or not
+ * @return The height of the "poster" in number of pages for print the diagram
+ * with the orientation and paper format used by the actual printer
+ */
+int ProjectPrintWindow::verticalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const
+{
+ QRect printable_area = full_page ? m_printer->paperRect() : m_printer->pageRect();
+ QRect diagram_rect = diagramRect(diagram, option);
+
+ int v_pages_count = int(ceil(qreal(diagram_rect.height()) / qreal(printable_area.height())));
+ return(v_pages_count);
+}
+
+ExportProperties ProjectPrintWindow::exportProperties() const
+{
+ ExportProperties exp;
+ exp.draw_border = ui->m_draw_border_cb->isChecked();
+ exp.draw_titleblock = ui->m_draw_titleblock_cb->isChecked();
+ exp.draw_terminals = ui->m_draw_terminal_cb->isChecked();
+ exp.draw_colored_conductors = ui->m_keep_conductor_color_cb->isChecked();
+ exp.draw_grid = false;
+
+ return exp;
+}
+
+void ProjectPrintWindow::setUpDiagramList()
+{
+ auto layout = new QVBoxLayout();
+ auto widget = new QWidget();
+ widget->setLayout(layout);
+ widget->setMinimumSize(170, 0);
+ widget->setMaximumSize(470, 10000);
+ widget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
+ ui->m_diagram_list->setWidget(widget);
+
+ for (auto diagram : m_project->diagrams())
+ {
+ auto title = diagram->title();
+ if (title.isEmpty()) {
+ title = tr("Folio sans titre");
+ }
+
+ auto checkbox = new QCheckBox(title);
+ checkbox->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum));
+ checkbox->setChecked(true);
+ layout->addWidget(checkbox, 0, Qt::AlignLeft | Qt::AlignTop);
+ connect(checkbox, &QCheckBox::clicked, m_preview, &QPrintPreviewWidget::updatePreview);
+ m_diagram_list_hash.insert(diagram, checkbox);
+ }
+}
+
+QString ProjectPrintWindow::settingsSectionName(const QPrinter *printer)
+{
+ QPrinter::OutputFormat printer_format = printer -> outputFormat();
+ if (printer_format == QPrinter::NativeFormat) {
+ return(printer -> printerName().replace(" ", "_"));
+ } else if (printer_format == QPrinter::PdfFormat) {
+ return("QET_PDF_Printing");
+ }
+ return(QString());
+}
+
+void ProjectPrintWindow::loadPageSetupForCurrentPrinter()
+{
+ QSettings settings;
+ QString printer_section = settingsSectionName(m_printer);
+
+ while (!settings.group().isEmpty()) settings.endGroup();
+ settings.beginGroup("printers");
+ if (!settings.childGroups().contains(printer_section)) {
+ settings.endGroup();
+ return;
+ }
+
+ settings.beginGroup(printer_section);
+ if (settings.contains("orientation")) {
+ QString value = settings.value("orientation", "landscape").toString();
+ m_printer -> setOrientation(value == "landscape" ? QPrinter::Landscape : QPrinter::Portrait);
+ }
+ if (settings.contains("papersize")) {
+ int value = settings.value("papersize", QPrinter::A4).toInt();
+ if (value == QPrinter::Custom) {
+ bool w_ok, h_ok;
+ int w = settings.value("customwidthmm", -1).toInt(&w_ok);
+ int h = settings.value("customheightmm", -1).toInt(&h_ok);
+ if (w_ok && h_ok && w != -1 && h != -1) {
+ m_printer -> setPaperSize(QSizeF(w, h), QPrinter::Millimeter);
+ }
+ } else if (value < QPrinter::Custom) {
+ m_printer -> setPaperSize(static_cast(value));
+ }
+ }
+
+ qreal margins[4];
+ m_printer -> getPageMargins(&margins[0], &margins[1], &margins[2], &margins[3], QPrinter::Millimeter);
+ QStringList margins_names(QStringList() << "left" << "top" << "right" << "bottom");
+ for (int i = 0 ; i < 4 ; ++ i) {
+ bool conv_ok;
+ qreal value = settings.value("margin" + margins_names.at(i), -1.0).toReal(&conv_ok);
+ if (conv_ok && value != -1.0) margins[i] = value;
+ }
+ m_printer -> setPageMargins(margins[0], margins[1], margins[2], margins[3], QPrinter::Millimeter);
+ m_printer -> setFullPage(settings.value("fullpage", "false").toString() == "true");
+
+ settings.endGroup();
+ settings.endGroup();
+}
+
+void ProjectPrintWindow::savePageSetupForCurrentPrinter()
+{
+ QSettings settings;
+ QString printer_section = settingsSectionName(m_printer);
+
+ while (!settings.group().isEmpty()) settings.endGroup();
+ settings.beginGroup("printers");
+ settings.beginGroup(printer_section);
+
+ settings.setValue("orientation", m_printer -> orientation() == QPrinter::Portrait ? "portrait" : "landscape");
+ settings.setValue("papersize", int(m_printer -> paperSize()));
+ if (m_printer -> paperSize() == QPrinter::Custom) {
+ QSizeF size = m_printer -> paperSize(QPrinter::Millimeter);
+ settings.setValue("customwidthmm", size.width());
+ settings.setValue("customheightmm", size.height());
+ } else {
+ settings.remove("customwidthmm");
+ settings.remove("customheightmm");
+ }
+ qreal left, top, right, bottom;
+ m_printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
+ settings.setValue("marginleft", left);
+ settings.setValue("margintop", top);
+ settings.setValue("marginright", right);
+ settings.setValue("marginbottom", bottom);
+ settings.setValue("fullpage", m_printer->fullPage() ? "true" : "false");
+ settings.endGroup();
+ settings.endGroup();
+ settings.sync();
+}
+
+/**
+ * @brief ProjectPrintWindow::saveReloadDiagramParameters
+ * Save or restor the parameter of @diagram
+ * @param diagram
+ * @param options
+ * @param save
+ */
+void ProjectPrintWindow::saveReloadDiagramParameters(Diagram *diagram, const ExportProperties &options, bool save)
+{
+ static ExportProperties state_exportProperties;
+
+ if (save) {
+ state_exportProperties = diagram -> applyProperties(options);
+ } else {
+ diagram -> applyProperties(state_exportProperties);
+ }
+}
+
+QList ProjectPrintWindow::selectedDiagram() const
+{
+ QList selected_diagram;
+ for (auto diagram : m_project->diagrams()) {
+ auto cb = m_diagram_list_hash[diagram];
+ if (cb && cb->isChecked()) {
+ selected_diagram << diagram;
+ }
+ }
+
+ return selected_diagram;
+}
+
+void ProjectPrintWindow::exportToPDF()
+{
+ auto file_name = QFileDialog::getSaveFileName(this);
+ m_printer->setOutputFileName(file_name);
+ m_printer->setOutputFormat(QPrinter::PdfFormat);
+ m_preview->print();
+}
+
+void ProjectPrintWindow::on_m_draw_border_cb_clicked() { m_preview->updatePreview(); }
+void ProjectPrintWindow::on_m_draw_titleblock_cb_clicked() { m_preview->updatePreview(); }
+void ProjectPrintWindow::on_m_keep_conductor_color_cb_clicked() { m_preview->updatePreview(); }
+void ProjectPrintWindow::on_m_draw_terminal_cb_clicked() { m_preview->updatePreview(); }
+void ProjectPrintWindow::on_m_fit_in_page_cb_clicked() { m_preview->updatePreview(); }
+void ProjectPrintWindow::on_m_use_full_page_cb_clicked()
+{
+ m_printer->setFullPage(ui->m_use_full_page_cb->isChecked());
+ m_preview->updatePreview();
+}
+
+void ProjectPrintWindow::on_m_zoom_out_action_triggered() {
+ m_preview->zoomOut(4.0/3.0);
+}
+
+void ProjectPrintWindow::on_m_zoom_in_action_triggered() {
+ m_preview->zoomIn(4.0/3.0);
+}
+
+void ProjectPrintWindow::on_m_adjust_width_action_triggered() {
+ m_preview->fitToWidth();
+}
+
+void ProjectPrintWindow::on_m_adjust_page_action_triggered() {
+ m_preview->fitInView();
+}
+
+void ProjectPrintWindow::on_m_landscape_action_triggered() {
+ m_preview->setLandscapeOrientation();
+}
+
+void ProjectPrintWindow::on_m_portrait_action_triggered() {
+ m_preview->setPortraitOrientation();
+}
+
+void ProjectPrintWindow::on_m_first_page_action_triggered() {
+ m_preview->setCurrentPage(1);
+}
+
+void ProjectPrintWindow::on_m_previous_page_action_triggered()
+{
+ auto previous_page = m_preview->currentPage() - 1;
+ m_preview->setCurrentPage(std::max(previous_page, 0));
+}
+
+void ProjectPrintWindow::on_m_next_page_action_triggered()
+{
+ auto next_page = m_preview->currentPage() + 1;
+ m_preview->setCurrentPage(std::min(next_page, m_preview->pageCount()));
+}
+
+void ProjectPrintWindow::on_m_last_page_action_triggered() {
+ m_preview->setCurrentPage(m_preview->pageCount());
+}
+
+void ProjectPrintWindow::on_m_display_single_page_action_triggered() {
+ m_preview->setSinglePageViewMode();
+}
+
+void ProjectPrintWindow::on_m_display_two_page_action_triggered() {
+ m_preview->setFacingPagesViewMode();
+}
+
+void ProjectPrintWindow::on_m_display_all_page_action_triggered() {
+ m_preview->setAllPagesViewMode();
+}
+
+void ProjectPrintWindow::on_m_page_setup_triggered()
+{
+ QPageSetupDialog d(m_printer, this);
+ if (d.exec() == QDialog::Accepted) {
+ m_preview->updatePreview();
+ }
+}
+
+void ProjectPrintWindow::on_m_check_all_pb_clicked()
+{
+ for (auto cb : m_diagram_list_hash.values()) {
+ cb->setChecked(true);
+ }
+ m_preview->updatePreview();
+}
+
+void ProjectPrintWindow::on_m_uncheck_all_clicked()
+{
+ for (auto cb : m_diagram_list_hash.values()) {
+ cb->setChecked(false);
+ }
+ m_preview->updatePreview();
+}
+
+void ProjectPrintWindow::print()
+{
+ m_preview->print();
+ savePageSetupForCurrentPrinter();
+ this->close();
+}
diff --git a/sources/print/projectprintwindow.h b/sources/print/projectprintwindow.h
new file mode 100644
index 000000000..321b84437
--- /dev/null
+++ b/sources/print/projectprintwindow.h
@@ -0,0 +1,101 @@
+/*
+ Copyright 2006-2020 The QElectroTech Team
+ This file is part of QElectroTech.
+
+ QElectroTech is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ QElectroTech is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with QElectroTech. If not, see .
+*/
+#ifndef PROJECTPRINTWINDOW_H
+#define PROJECTPRINTWINDOW_H
+
+#include
+
+#include "exportproperties.h"
+
+namespace Ui {
+class ProjectPrintWindow;
+}
+
+class QETProject;
+class QPrintPreviewWidget;
+class QPrinter;
+class ExportProperties;
+class Diagram;
+class QCheckBox;
+
+/**
+ * @brief The ProjectPrintWindow class
+ * Windows used to configur and view diagram befor print
+ */
+class ProjectPrintWindow : public QMainWindow
+{
+ Q_OBJECT
+
+ public:
+ static void launchDialog(QETProject *project, QWidget *parent = nullptr);
+ static QString docName(QETProject *project);
+
+ explicit ProjectPrintWindow(QETProject *project, QPrinter *printer, QWidget *parent = nullptr);
+ ~ProjectPrintWindow();
+
+ private slots:
+ void on_m_draw_border_cb_clicked();
+ void on_m_draw_titleblock_cb_clicked();
+ void on_m_keep_conductor_color_cb_clicked();
+ void on_m_draw_terminal_cb_clicked();
+ void on_m_fit_in_page_cb_clicked();
+ void on_m_use_full_page_cb_clicked();
+ void on_m_zoom_out_action_triggered();
+ void on_m_zoom_in_action_triggered();
+ void on_m_adjust_width_action_triggered();
+ void on_m_adjust_page_action_triggered();
+ void on_m_landscape_action_triggered();
+ void on_m_portrait_action_triggered();
+ void on_m_first_page_action_triggered();
+ void on_m_previous_page_action_triggered();
+ void on_m_next_page_action_triggered();
+ void on_m_last_page_action_triggered();
+ void on_m_display_single_page_action_triggered();
+ void on_m_display_two_page_action_triggered();
+ void on_m_display_all_page_action_triggered();
+ void on_m_page_setup_triggered();
+ void on_m_check_all_pb_clicked();
+ void on_m_uncheck_all_clicked();
+ void print();
+
+ private:
+ void requestPaint();
+ void printDiagram(Diagram *diagram, bool fit_page, QPainter *painter, QPrinter *printer);
+ QRect diagramRect(Diagram *diagram, const ExportProperties &option) const;
+ int horizontalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
+ int verticalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
+ ExportProperties exportProperties() const;
+ void setUpDiagramList();
+ QString settingsSectionName(const QPrinter *printer);
+ void loadPageSetupForCurrentPrinter();
+ void savePageSetupForCurrentPrinter();
+ void saveReloadDiagramParameters(Diagram *diagram, const ExportProperties &options, bool save);
+ QList selectedDiagram() const;
+ void exportToPDF();
+
+
+ private:
+ Ui::ProjectPrintWindow *ui;
+ QETProject *m_project = nullptr;
+ QPrinter *m_printer = nullptr;
+ QPrintPreviewWidget *m_preview=nullptr;
+ QColor m_backup_diagram_background_color;
+ QHash m_diagram_list_hash;
+};
+
+#endif // PROJECTPRINTWINDOW_H
diff --git a/sources/print/projectprintwindow.ui b/sources/print/projectprintwindow.ui
new file mode 100644
index 000000000..210a9463c
--- /dev/null
+++ b/sources/print/projectprintwindow.ui
@@ -0,0 +1,367 @@
+
+
+ ProjectPrintWindow
+
+
+
+ 0
+ 0
+ 956
+ 506
+
+
+
+
+ 0
+ 0
+
+
+
+ MainWindow
+
+
+
+ -
+
+
-
+
+
-
+
+
+ Folios à imprimer :
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ 3
+
+
+ 3
+
+
+ Qt::ScrollBarAlwaysOff
+
+
+ true
+
+
+
+
+ 0
+ 0
+ 932
+ 60
+
+
+
+
+
+ -
+
+
+ Tout cocher
+
+
+
+ -
+
+
+ Tout décoher
+
+
+
+
+
+
+
+ -
+
+
+ Option de rendu
+
+
+
-
+
+
+ Dessiner le cadre
+
+
+
+ -
+
+
+ Dessiner le cartouche
+
+
+
+ -
+
+
+ Conserver les couleurs des conducteurs
+
+
+
+ -
+
+
+ Dessiner les bornes
+
+
+
+
+
+
+ -
+
+
+ Option d'impression
+
+
+
-
+
+
+ Adapter le folio à la page
+
+
+ true
+
+
+
+ -
+
+
+ Utiliser toute la feuille
+
+
+
+ -
+
+
+ Si cette option est cochée, le folio sera agrandi ou rétréci de façon à remplir toute la surface imprimable d'une et une seule page."
+
+
+ 0
+
+
+
+ -
+
+
+ Si cette option est cochée, les marges de la feuille seront ignorées et toute sa surface sera utilisée pour l'impression. Cela peut ne pas être supporté par votre imprimante.
+
+
+ true
+
+
+ 0
+
+
+ false
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+
+
+
+ -
+
+
+ QDialogButtonBox::Cancel
+
+
+
+
+
+
+
+ toolBar
+
+
+ TopToolBarArea
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ :/ico/22x22/view_fit_width.png:/ico/22x22/view_fit_width.png
+
+
+ Ajuster la largeur
+
+
+
+
+
+ :/ico/22x22/view-fit-window.png:/ico/22x22/view-fit-window.png
+
+
+ Ajuster la page
+
+
+
+
+
+ :/ico/16x16/zoom-out.png:/ico/16x16/zoom-out.png
+
+
+ Zoom arrière
+
+
+
+
+
+ :/ico/16x16/zoom-in.png:/ico/16x16/zoom-in.png
+
+
+ Zoom avant
+
+
+
+
+
+ :/ico/22x22/landscape.png:/ico/22x22/landscape.png
+
+
+ Paysage
+
+
+
+
+
+ :/ico/22x22/portrait.png:/ico/22x22/portrait.png
+
+
+ Portrait
+
+
+
+
+
+ :/ico/16x16/arrow-left-double.png:/ico/16x16/arrow-left-double.png
+
+
+ Première page
+
+
+
+
+
+ :/ico/16x16/arrow-left.png:/ico/16x16/arrow-left.png
+
+
+ Page précédente
+
+
+
+
+
+ :/ico/16x16/arrow-right.png:/ico/16x16/arrow-right.png
+
+
+ Page suivante
+
+
+
+
+
+ :/ico/22x22/arrow-right-double.png:/ico/22x22/arrow-right-double.png
+
+
+ Dernière page
+
+
+
+
+
+ :/ico/22x22/single_page.png:/ico/22x22/single_page.png
+
+
+ Affichier une seul page
+
+
+
+
+
+ :/ico/22x22/two_pages.png:/ico/22x22/two_pages.png
+
+
+ Afficher deux pages
+
+
+
+
+
+ :/ico/22x22/all_pages.png:/ico/22x22/all_pages.png
+
+
+ Afficher un aperçu de toutes les pages
+
+
+
+
+
+ :/ico/48x48/document-print-frame.png:/ico/48x48/document-print-frame.png
+
+
+ mise en page
+
+
+
+
+
+
+
+
+ m_button_box
+ rejected()
+ ProjectPrintWindow
+ close()
+
+
+ 477
+ 484
+
+
+ 477
+ 252
+
+
+
+
+
diff --git a/sources/projectview.cpp b/sources/projectview.cpp
index 95b99b4ee..be83c21c1 100644
--- a/sources/projectview.cpp
+++ b/sources/projectview.cpp
@@ -19,7 +19,6 @@
#include "qetproject.h"
#include "diagramview.h"
#include "diagram.h"
-#include "diagramprintdialog.h"
#include "exportdialog.h"
#include "qetapp.h"
#include "qetelementeditor.h"
@@ -522,7 +521,7 @@ void ProjectView::moveDiagramUpTop(DiagramView *diagram_view)
// le schema est le premier du projet
return;
}
- m_tab -> tabBar() -> moveTab(diagram_view_position, (diagram_views().size(), 0));
+ m_tab->tabBar()->moveTab(diagram_view_position, diagram_views().size());
}
/*
@@ -575,38 +574,6 @@ void ProjectView::moveDiagramDownx10(Diagram *diagram) {
moveDiagramDownx10(findDiagram(diagram));
}
-/**
- Ce slot demarre un dialogue permettant a l'utilisateur de parametrer et de
- lancer l'impression de toute ou partie du projet.
-*/
-void ProjectView::printProject()
-{
- if (!m_project) return;
-
- // transforme le titre du projet en nom utilisable pour le document
- QString doc_name;
- if (!(m_project -> title().isEmpty())) {
- doc_name = m_project -> title();
- } else if (!m_project -> filePath().isEmpty()) {
- doc_name = QFileInfo(m_project -> filePath()).baseName();
- }
- doc_name = QET::stringToFileName(doc_name);
- if (doc_name.isEmpty()) {
- doc_name = tr("projet", "string used to generate a filename");
- }
-
- // recupere le dossier contenant le fichier courant
- QString dir_path = m_project -> currentDir();
-
- // determine un chemin pour le pdf / ps
- QString file_name = QDir::toNativeSeparators(QDir::cleanPath(dir_path + "/" + doc_name));
-
- DiagramPrintDialog print_dialog(m_project, this);
- print_dialog.setDocName(doc_name);
- print_dialog.setFileName(file_name);
- print_dialog.exec();
-}
-
/**
Exporte le schema.
*/
diff --git a/sources/projectview.h b/sources/projectview.h
index 7fb7014a0..574b0ccba 100644
--- a/sources/projectview.h
+++ b/sources/projectview.h
@@ -117,7 +117,6 @@ class ProjectView : public QWidget
void moveDiagramUpx10(Diagram *);
void moveDiagramDownx10(DiagramView *);
void moveDiagramDownx10(Diagram *);
- void printProject();
void exportProject();
QETResult save();
QETResult saveAs();
diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp
index 0f8a1efdf..a9f62c989 100644
--- a/sources/qetdiagrameditor.cpp
+++ b/sources/qetdiagrameditor.cpp
@@ -39,6 +39,7 @@
#include "bomexportdialog.h"
#include "QWidgetAnimation/qwidgetanimation.h"
#include "qetgraphicstablefactory.h"
+#include "projectprintwindow.h"
#include
@@ -269,9 +270,9 @@ void QETDiagramEditor::setUpActions()
m_print->setShortcut(QKeySequence(QKeySequence::Print));
m_print->setStatusTip(tr("Imprime un ou plusieurs folios du projet courant", "status bar tip"));
connect(m_print, &QAction::triggered, [this]() {
- ProjectView *current_project = currentProjectView();
- if (current_project) {
- current_project -> printProject();
+ auto project = currentProject();
+ if (project) {
+ ProjectPrintWindow::launchDialog(project, this);
}
});
diff --git a/sources/qetprintpreviewdialog.cpp b/sources/qetprintpreviewdialog.cpp
deleted file mode 100644
index e70c8e26a..000000000
--- a/sources/qetprintpreviewdialog.cpp
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- Copyright 2006-2020 The QElectroTech Team
- This file is part of QElectroTech.
-
- QElectroTech is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- QElectroTech is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with QElectroTech. If not, see .
-*/
-#include "qetprintpreviewdialog.h"
-#include "diagramschooser.h"
-#include "exportproperties.h"
-#include "exportpropertieswidget.h"
-#include "qeticons.h"
-
-#include
-#include
-#include
-
-/**
- Constructeur
- @param project Projet a imprimer
- @param printer Imprimante a utiliser pour
- @param widget Widget parent
- @param f Flags passes au constructeur de QDialog puis QWidget
-*/
-QETPrintPreviewDialog::QETPrintPreviewDialog(
- QETProject *project,
- QPrinter *printer,
- QWidget *widget,
- Qt::WindowFlags f) :
- QDialog(widget, f),
- project_(project),
- printer_(printer)
-{
- setWindowTitle(tr("QElectroTech : Aperçu avant impression"));
- build();
-
- connect(preview_, SIGNAL(paintRequested(QPrinter *)),
- this, SLOT(requestPaint(QPrinter *)));
- connect(diagrams_list_, SIGNAL(selectionChanged()),
- preview_, SLOT(updatePreview()));
- connect(diagrams_list_, SIGNAL(selectionChanged()),
- this, SLOT(checkDiagramsCount()));
-
- setWindowState(windowState() | Qt::WindowMaximized);
-}
-
-/**
- Destructeur
-*/
-QETPrintPreviewDialog::~QETPrintPreviewDialog()
-{
-}
-
-/**
- @return le widget permettant de choisir les schemas a imprimer.
-*/
-DiagramsChooser *QETPrintPreviewDialog::diagramsChooser()
-{
- return(diagrams_list_);
-}
-
-/**
- @return true si l'option "Adapter le schema a la page" est activee
-*/
-bool QETPrintPreviewDialog::fitDiagramsToPages() const
-{
- return(fit_diagram_to_page_ -> isChecked());
-}
-
-/**
- @return les options de rendu definies par l'utilisateur
-*/
-ExportProperties QETPrintPreviewDialog::exportProperties() const
-{
- return(render_properties_ -> exportProperties());
-}
-
-/**
- Passe a la premiere page
-*/
-void QETPrintPreviewDialog::firstPage()
-{
- preview_ -> setCurrentPage(1);
-}
-
-/**
- Passe a la page precedente
-*/
-void QETPrintPreviewDialog::previousPage()
-{
- int preview_previous_page = preview_ -> currentPage() - 1;
- preview_ -> setCurrentPage(qMax(preview_previous_page, 0));
-}
-
-/**
- Passe a la page suivante
-*/
-void QETPrintPreviewDialog::nextPage()
-{
- int preview_next_page = preview_ -> currentPage() + 1;
- preview_ -> setCurrentPage(qMin(preview_next_page,
- preview_ -> pageCount()));
-}
-
-/**
- Passe a la derniere page
-*/
-void QETPrintPreviewDialog::lastPage()
-{
- preview_ -> setCurrentPage(preview_ -> pageCount());
-}
-
-/**
- Copnfigure la mise en page
-*/
-void QETPrintPreviewDialog::pageSetup()
-{
- QPageSetupDialog page_setup_dialog(printer_, this);
- if (page_setup_dialog.exec() == QDialog::Accepted) {
- preview_ -> updatePreview();
- updateZoomList();
- }
-}
-
-/**
- Utilise ou non toute la page sans teni compte des marges
- @param full_page true pour utiliser toute la page, false sinon
-*/
-void QETPrintPreviewDialog::useFullPage(bool full_page) {
- printer_ -> setFullPage(full_page);
- preview_ -> updatePreview();
- updateZoomList();
-}
-
-/**
- Fait tenir ou non chaque schema sur une page
- @param fit_diagram true pour adapter chaque schema sur une page,
- false sinon
-*/
-void QETPrintPreviewDialog::fitDiagramToPage(bool fit_diagram) {
- Q_UNUSED(fit_diagram);
- preview_ -> updatePreview();
- updateZoomList();
-}
-
-/**
- Effectue l'action "zoom avant" sur l'apercu avant impression
-*/
-void QETPrintPreviewDialog::zoomIn()
-{
- preview_ -> zoomIn(4.0/3.0);
- updateZoomList();
-}
-
-/**
- Effectue l'action "zoom arriere" sur l'apercu avant impression
-*/
-void QETPrintPreviewDialog::zoomOut()
-{
- preview_ -> zoomOut(4.0/3.0);
- updateZoomList();
-}
-
-/**
- Selectionne tous les schemas
-*/
-void QETPrintPreviewDialog::selectAllDiagrams()
-{
- diagrams_list_ -> setSelectedAllDiagrams(true);
-}
-
-/**
- Deselectionne tous les schemas
-*/
-void QETPrintPreviewDialog::selectNoDiagram()
-{
- diagrams_list_ -> setSelectedAllDiagrams(false);
-}
-
-/**
- Met en place le dialogue
-*/
-void QETPrintPreviewDialog::build()
-{
- preview_ = new QPrintPreviewWidget(printer_);
- diagrams_label_ = new QLabel(tr("Folios à imprimer :"));
- diagrams_list_ = new DiagramsChooser(project_);
- diagrams_select_all_ = new QPushButton(tr("Tout cocher"));
- diagrams_select_none_ = new QPushButton(tr("Tout décocher"));
- toggle_diagrams_list_ = new QAction(QET::Icons::Diagram, tr("Cacher la liste des folios"), this);
- toggle_print_options_ = new QAction(QET::Icons::Configure, tr("Cacher les options d'impression"), this);
- adjust_width_ = new QAction(QET::Icons::ViewFitWidth, tr("Ajuster la largeur"), this);
- adjust_page_ = new QAction(QET::Icons::ViewFitWindow, tr("Ajuster la page"), this);
- zoom_out_ = new QAction(QET::Icons::ZoomOut, tr("Zoom arrière"), this);
- zoom_box_ = new QComboBox(this);
- zoom_in_ = new QAction(QET::Icons::ZoomIn, tr("Zoom avant"), this);
- landscape_ = new QAction(QET::Icons::PrintLandscape, tr("Paysage"), this);
- portrait_ = new QAction(QET::Icons::PrintPortrait, tr("Portrait"), this);
- first_page_ = new QAction(QET::Icons::ArrowLeftDouble, tr("Première page"), this);
- previous_page_ = new QAction(QET::Icons::ArrowLeft, tr("Page précédente"), this);
- next_page_ = new QAction(QET::Icons::ArrowRight, tr("Page suivante"), this);
- last_page_ = new QAction(QET::Icons::ArrowRightDouble, tr("Dernière page"), this);
- single_page_view_ = new QAction(QET::Icons::SinglePage, tr("Afficher une seule page"), this);
- facing_pages_view_ = new QAction(QET::Icons::PrintTwoPages, tr("Afficher deux pages"), this);
- all_pages_view_ = new QAction(QET::Icons::PrintAllPages, tr("Afficher un aperçu de toutes les pages"), this);
- page_setup_ = new QAction(QET::Icons::DocumentPrintFrame, tr("Mise en page"), this);
-
- toggle_diagrams_list_ -> setCheckable(true);
- toggle_diagrams_list_ -> setChecked(true);
- toggle_print_options_ -> setCheckable(true);
- toggle_print_options_ -> setChecked(true);
-
-#ifdef Q_OS_WIN32
- /*
- Sous Windows, le QPageSetupDialog utilise le dialogue natif ; ce
- dernier ne peut gerer que les imprimantes physiques ("native
- printers" ).
- cf avertissement : QAbstractPageSetupDialog::QAbstractPageSetupDialog:
- Page setup dialog cannot be used on non-native printers
- */
- if (!(printer_ -> outputFileName().isEmpty())) {
- page_setup_ -> setEnabled(false);
- page_setup_ -> setText(tr("Mise en page (non disponible sous Windows pour l'impression PDF/PS)"));
- }
-#endif
-
- toolbar_ = new QToolBar();
- toolbar_ -> addAction(toggle_diagrams_list_);
- toolbar_ -> addAction(toggle_print_options_);
- toolbar_ -> addSeparator();
- toolbar_ -> addAction(adjust_width_);
- toolbar_ -> addAction(adjust_page_);
- toolbar_ -> addAction(zoom_out_);
- toolbar_ -> addWidget(zoom_box_);
- toolbar_ -> addAction(zoom_in_);
- toolbar_ -> addSeparator();
- toolbar_ -> addAction(landscape_);
- toolbar_ -> addAction(portrait_);
- toolbar_ -> addSeparator();
- toolbar_ -> addAction(first_page_);
- toolbar_ -> addAction(previous_page_);
- toolbar_ -> addAction(next_page_);
- toolbar_ -> addAction(last_page_);
- toolbar_ -> addSeparator();
- toolbar_ -> addAction(single_page_view_);
- toolbar_ -> addAction(facing_pages_view_);
- toolbar_ -> addAction(all_pages_view_);
- toolbar_ -> addSeparator();
- toolbar_ -> addAction(page_setup_);
-
- print_options_box_= new QGroupBox(tr("Options d'impression"));
- use_full_page_ = new QCheckBox(tr("Utiliser toute la feuille"));
- use_full_page_ -> setChecked(printer_ -> fullPage());
- use_full_page_label_ = new QLabel(tr(
- "Si cette option est cochée, les marges de la feuille seront "
- "ignorées et toute sa surface sera utilisée pour l'impression. "
- "Cela peut ne pas être supporté par votre imprimante."
- ));
- use_full_page_label_ -> setWordWrap(true);
- use_full_page_label_ -> setContentsMargins(20, 0, 0, 0);
- fit_diagram_to_page_ = new QCheckBox(tr("Adapter le folio à la page"));
- fit_diagram_to_page_label_ = new QLabel(tr(
- "Si cette option est cochée, le folio sera agrandi ou "
- "rétréci de façon à remplir toute la surface imprimable "
- "d'une et une seule page."
- ));
- fit_diagram_to_page_label_ -> setWordWrap(true);
- fit_diagram_to_page_label_ -> setContentsMargins(20, 0, 0, 0);
- fit_diagram_to_page_ -> setChecked(true);
-
- // recupere les parametres d'export definis dans la configuration de l'application
- ExportProperties default_print_properties = ExportProperties::defaultPrintProperties();
-
- render_properties_ = new ExportPropertiesWidget(default_print_properties);
- render_properties_ -> setPrintingMode(true);
-
- buttons_ = new QDialogButtonBox();
- buttons_ -> addButton(new QPushButton(QET::Icons::DocumentPrint, tr("Imprimer")), QDialogButtonBox::AcceptRole);
- buttons_ -> addButton(QDialogButtonBox::Cancel);
-
- connect(diagrams_select_all_, SIGNAL(released()), this, SLOT(selectAllDiagrams()));
- connect(diagrams_select_none_, SIGNAL(released()), this, SLOT(selectNoDiagram()));
- connect(toggle_diagrams_list_, SIGNAL(toggled(bool)), this, SLOT(setDiagramsListVisible(bool)));
- connect(toggle_print_options_, SIGNAL(toggled(bool)), this, SLOT(setPrintOptionsVisible(bool)));
- connect(adjust_width_, SIGNAL(triggered()), preview_, SLOT(fitToWidth()));
- connect(adjust_page_, SIGNAL(triggered()), preview_, SLOT(fitInView()));
- connect(zoom_out_, SIGNAL(triggered()), this, SLOT(zoomOut()));
- connect(zoom_in_, SIGNAL(triggered()), this, SLOT(zoomIn()));
- connect(landscape_, SIGNAL(triggered()), preview_, SLOT(setLandscapeOrientation()));
- connect(portrait_, SIGNAL(triggered()), preview_, SLOT(setPortraitOrientation()));
- connect(first_page_, SIGNAL(triggered()), this, SLOT(firstPage()));
- connect(previous_page_, SIGNAL(triggered()), this, SLOT(previousPage()));
- connect(next_page_, SIGNAL(triggered()), this, SLOT(nextPage()));
- connect(last_page_, SIGNAL(triggered()), this, SLOT(lastPage()));
- connect(single_page_view_, SIGNAL(triggered()), preview_, SLOT(setSinglePageViewMode()));
- connect(facing_pages_view_, SIGNAL(triggered()), preview_, SLOT(setFacingPagesViewMode()));
- connect(all_pages_view_, SIGNAL(triggered()), preview_, SLOT(setAllPagesViewMode()));
- connect(page_setup_, SIGNAL(triggered()), this, SLOT(pageSetup()));
-
- connect(use_full_page_, SIGNAL(toggled(bool)), this, SLOT(useFullPage(bool)));
- connect(fit_diagram_to_page_, SIGNAL(toggled(bool)), this, SLOT(fitDiagramToPage(bool)));
-
- connect(render_properties_, SIGNAL(optionChanged()), preview_, SLOT(updatePreview()));
-
- connect(preview_, SIGNAL(previewChanged()), this, SLOT(updateZoomList()));
- connect(zoom_box_, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreviewZoom()));
-
- connect(buttons_, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttons_, SIGNAL(rejected()), this, SLOT(reject()));
-
- hlayout0_ = new QHBoxLayout();
- vlayout0_ = new QVBoxLayout();
- vlayout1_ = new QVBoxLayout();
- vlayout2_ = new QVBoxLayout();
-
- vlayout1_ -> addWidget(use_full_page_);
- vlayout1_ -> addWidget(use_full_page_label_);
- vlayout1_ -> addWidget(fit_diagram_to_page_);
- vlayout1_ -> addWidget(fit_diagram_to_page_label_);
- print_options_box_ -> setLayout(vlayout1_);
-
- vlayout2_ -> addWidget(diagrams_label_);
- vlayout2_ -> addWidget(diagrams_list_);
- vlayout2_ -> addWidget(diagrams_select_all_);
- vlayout2_ -> addWidget(diagrams_select_none_);
-
- hlayout0_ -> addLayout(vlayout2_);
- hlayout0_ -> addWidget(preview_);
-
- vlayout0_ -> addWidget(toolbar_);
- vlayout0_ -> addLayout(hlayout0_);
- vlayout0_ -> addWidget(render_properties_);
- vlayout0_ -> addWidget(print_options_box_);
- vlayout0_ -> addWidget(buttons_);
-
- setLayout(vlayout0_);
- updateZoomList();
-}
-
-/**
- Ce slot prive emet le signal paintRequested avec :
- * la liste des schemas a imprimer / selectionnes
- * un booleen indiquant s'il faut adapter les schemas aux pages ou non
- * l'imprimante a utiliser
-*/
-void QETPrintPreviewDialog::requestPaint(QPrinter *printer) {
- emit(
- paintRequested(
- diagrams_list_ -> selectedDiagrams(),
- fit_diagram_to_page_ -> isChecked(),
- render_properties_ -> exportProperties(),
- printer
- )
- );
-}
-
-/**
- Ce slot prive verifie que le nombre de schemas a imprimer est bien superieur
- a 0 et active ou desactive le bouton "Imprimer" en consequence.
-*/
-void QETPrintPreviewDialog::checkDiagramsCount()
-{
- int diagrams_count = diagrams_list_ -> selectedDiagrams().count();
-
- // desactive le premier bouton de la liste (= le bouton "Imprimer")
- QList buttons = buttons_ -> buttons();
- if (buttons.count()) buttons[0] -> setEnabled(diagrams_count);
-}
-
-/**
- Ce slot prive affiche ou cache la liste des schemas
- @param display true pour affiche la liste des schemas, false pour la cacher
-*/
-void QETPrintPreviewDialog::setDiagramsListVisible(bool display) {
- diagrams_label_ -> setVisible(display);
- diagrams_list_ -> setVisible(display);
- diagrams_select_all_ -> setVisible(display);
- diagrams_select_none_ -> setVisible(display);
-
- if (display) {
- toggle_diagrams_list_ -> setText(tr("Cacher la liste des folios"));
- } else {
- toggle_diagrams_list_ -> setText(tr("Afficher la liste des folios"));
- }
-}
-
-/**
- Ce slot prive affiche ou cache les options d'impression
- @param display true pour affiche les options d'impression, false pour les
- cacher
-*/
-void QETPrintPreviewDialog::setPrintOptionsVisible(bool display) {
- print_options_box_ -> setVisible(display);
- render_properties_ -> setVisible(display);
-
- if (display) {
- toggle_print_options_ -> setText(tr("Cacher les options d'impression"));
- } else {
- toggle_print_options_ -> setText(tr("Afficher les options d'impression"));
- }
-}
-
-/**
- Met a jour la liste des zooms disponibles
-*/
-void QETPrintPreviewDialog::updateZoomList()
-{
- // recupere le zooom courant
- qreal current_zoom = preview_ -> zoomFactor();
- bool current_zoom_is_not_null = bool(int(current_zoom * 100.0));
-
- // liste des zooms par defaut
- QList zooms_real;
- zooms_real << 0.25 << 0.5 << 0.75 << 1.0 << 1.5 << 2.0 << 4.0 << 8.0;
-
- // ajout du zoom en cours
- if (current_zoom_is_not_null && (!zooms_real.contains(current_zoom))) {
- zooms_real << current_zoom;
- std::sort(zooms_real.begin(), zooms_real.end());
- }
-
- // remplissage de la liste deroulante
- int current_zoom_index = -1;
- zoom_box_ -> blockSignals(true);
- zoom_box_ -> clear();
- foreach (qreal z, zooms_real) {
- zoom_box_ -> addItem(QString(tr("%1 %")).arg(z * 100.0, 0, 'f', 2), z);
- if (z == current_zoom) current_zoom_index = zoom_box_ -> count() - 1;
- }
- zoom_box_ -> setCurrentIndex(current_zoom_index);
- zoom_box_ -> blockSignals(false);
-}
-
-/**
- Change le zoom de l'apercu en fonctiopn du contenu du zoom selectionne
-*/
-void QETPrintPreviewDialog::updatePreviewZoom()
-{
- preview_ -> setZoomFactor(
- zoom_box_ -> itemData(zoom_box_ -> currentIndex()).toDouble()
- );
- updateZoomList();
-}
diff --git a/sources/qetprintpreviewdialog.h b/sources/qetprintpreviewdialog.h
deleted file mode 100644
index 506dc08b0..000000000
--- a/sources/qetprintpreviewdialog.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- Copyright 2006-2020 The QElectroTech Team
- This file is part of QElectroTech.
-
- QElectroTech is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- QElectroTech is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with QElectroTech. If not, see .
-*/
-#ifndef QET_PRINT_PREVIEW_DIALOG
-#define QET_PRINT_PREVIEW_DIALOG
-#include
-#include "exportproperties.h"
-
-class Diagram;
-class DiagramsChooser;
-class ExportPropertiesWidget;
-class QETProject;
-class QPrintPreviewWidget;
-class QPrinter;
-
-/**
- This class provides a dialog for users to refine printing options for a
- particular project by relying on a visual print preview.
-*/
-class QETPrintPreviewDialog : public QDialog {
- Q_OBJECT
-
- // constructors, destructor
- public:
- QETPrintPreviewDialog(QETProject *, QPrinter *, QWidget * = nullptr, Qt::WindowFlags = Qt::Widget);
- ~QETPrintPreviewDialog() override;
- private:
- QETPrintPreviewDialog(const QETPrintPreviewDialog &);
-
- // methods
- public:
- DiagramsChooser *diagramsChooser();
- bool fitDiagramsToPages() const;
- ExportProperties exportProperties() const;
-
- // signaux
- signals:
- void paintRequested(const QList &, bool, const ExportProperties, QPrinter *);
-
- public slots:
- void firstPage();
- void previousPage();
- void nextPage();
- void lastPage();
- void pageSetup();
- void useFullPage(bool);
- void fitDiagramToPage(bool);
- void zoomIn();
- void zoomOut();
- void selectAllDiagrams();
- void selectNoDiagram();
-
- // attributes
- private:
- QETProject *project_;
- QPrinter *printer_;
- QHBoxLayout *hlayout0_;
- QVBoxLayout *vlayout0_;
- QVBoxLayout *vlayout1_;
- QVBoxLayout *vlayout2_;
- QToolBar *toolbar_;
- QPrintPreviewWidget *preview_;
- QLabel *diagrams_label_;
- DiagramsChooser *diagrams_list_;
- QPushButton *diagrams_select_all_;
- QPushButton *diagrams_select_none_;
- QAction *toggle_diagrams_list_;
- QAction *toggle_print_options_;
- QAction *adjust_width_;
- QAction *adjust_page_;
- QAction *zoom_in_;
- QComboBox *zoom_box_;
- QAction *zoom_out_;
- QAction *landscape_;
- QAction *portrait_;
- QAction *first_page_;
- QAction *previous_page_;
- QAction *next_page_;
- QAction *last_page_;
- QAction *all_pages_view_;
- QAction *facing_pages_view_;
- QAction *single_page_view_;
- QAction *page_setup_;
- QDialogButtonBox *buttons_;
- QGroupBox *print_options_box_;
- QCheckBox *use_full_page_;
- QLabel *use_full_page_label_;
- QCheckBox *fit_diagram_to_page_;
- QLabel *fit_diagram_to_page_label_;
- ExportPropertiesWidget *render_properties_;
-
- // methods
- private:
- void build();
-
- private slots:
- void requestPaint(QPrinter *);
- void checkDiagramsCount();
- void setDiagramsListVisible(bool);
- void setPrintOptionsVisible(bool);
- void updateZoomList();
- void updatePreviewZoom();
-};
-#endif