diff --git a/diagramprintdialog.cpp b/diagramprintdialog.cpp
new file mode 100644
index 000000000..a7b0737d4
--- /dev/null
+++ b/diagramprintdialog.cpp
@@ -0,0 +1,300 @@
+/*
+ Copyright 2006-2007 Xavier Guerrin
+ 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
+
+/**
+ Constructeur
+ @param dia Schema a imprimer
+ @param printer Imprimante a utiliser
+ @param parent Widget parent du dialogue
+*/
+DiagramPrintDialog::DiagramPrintDialog(Diagram *dia, QWidget *parent) :
+ QWidget(parent),
+ diagram(dia),
+ dialog(0)
+{
+ // initialise l'imprimante
+ printer = new QPrinter();
+}
+
+/**
+ Destructeur
+*/
+DiagramPrintDialog::~DiagramPrintDialog() {
+ delete dialog;
+ delete printer;
+}
+
+/**
+ Definit le nom du PDF si l'utilisateur choisit une sortie vers un PDF
+*/
+void DiagramPrintDialog::setPDFName(const QString &name) {
+ pdf_name = name;
+}
+
+/**
+ @return le nom du PDF
+*/
+QString DiagramPrintDialog::PDFName() const {
+ return(pdf_name);
+}
+
+/**
+ Execute le dialogue d'impression
+*/
+void DiagramPrintDialog::exec() {
+
+ // affichage du dialogue d'impression standard
+ QPrintDialog print_dialog(printer);
+ print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintToFile);
+ if (!pdf_name.isEmpty()) printer -> setOutputFileName(pdf_name);
+ if (print_dialog.exec() == QDialog::Rejected) return;
+
+ /*
+ Apres l'execution de ce premier dialogue, on connait le format papier a
+ utiliser, son orientation et on est sur que tout cela est supporte par
+ l'imprimante.
+ On peut donc en deduire le nombre de pages a imprimer
+ */
+
+ // affichage d'un second dialogue, non standard, pour connaitre les pages a imprimer
+ buildDialog();
+ if (dialog -> exec() == QDialog::Rejected) return;
+
+ // effectue l'impression en elle-meme
+ print();
+}
+
+/**
+ @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(bool fullpage) const {
+ return(horizontalPagesCount(fullpage) * verticalPagesCount(fullpage));
+}
+
+/**
+ @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(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 = diagram -> border().toRect();
+
+ int h_pages_count = ceil(qreal(diagram_rect.width()) / qreal(printable_area.width()));
+ return(h_pages_count);
+}
+
+/**
+ @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(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 = diagram -> border().toRect();
+
+ int v_pages_count = ceil(qreal(diagram_rect.height()) / qreal(printable_area.height()));
+ return(v_pages_count);
+}
+
+/**
+ Construit un dialogue non standard pour demander les pages a imprimer a l'utilisateur
+*/
+void DiagramPrintDialog::buildDialog() {
+ dialog = new QDialog();
+ dialog -> setWindowTitle(tr("Options d'impression"));
+ options_label = new QLabel();
+ use_full_page = new QCheckBox(tr("Utiliser toute la feuille"));
+ fit_diagram_to_page = new QCheckBox(tr("Adapter le sch\351ma \340 la page"));
+ range_from_label = new QLabel(tr("Plage de "));
+ start_page = new QSpinBox();
+ to_label = new QLabel(tr(" \340 "));
+ end_page = new QSpinBox();
+ buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+
+ QHBoxLayout *pages_layout = new QHBoxLayout();
+ pages_layout -> addWidget(range_from_label);
+ pages_layout -> addWidget(start_page);
+ pages_layout -> addWidget(to_label);
+ pages_layout -> addWidget(end_page);
+
+ QVBoxLayout *dialog_layout = new QVBoxLayout(dialog);
+ dialog_layout -> addWidget(options_label);
+ dialog_layout -> addWidget(use_full_page);
+ dialog_layout -> addWidget(fit_diagram_to_page);
+ dialog_layout -> addLayout(pages_layout);
+ dialog_layout -> addStretch();
+ dialog_layout -> addWidget(buttons);
+
+ connect(use_full_page, SIGNAL(stateChanged(int)), this, SLOT(updateDialog()));
+ connect(fit_diagram_to_page, SIGNAL(stateChanged(int)), this, SLOT(updateDialog()));
+ connect(start_page, SIGNAL(valueChanged(int)), this, SLOT(checkStartPage()));
+ connect(end_page, SIGNAL(valueChanged(int)), this, SLOT(checkEndPage()));
+ connect(buttons, SIGNAL(accepted()), dialog, SLOT(accept()));
+ connect(buttons, SIGNAL(rejected()), dialog, SLOT(reject()));
+
+ updateDialog();
+}
+
+/**
+ Assure la coherence du dialogue
+*/
+void DiagramPrintDialog::updateDialog() {
+ int pages_count;
+ // si on adapte le schema a la page, alors il n'y a qu'une page a imprimer
+ if (fit_diagram_to_page -> isChecked()) {
+ pages_count = 1;
+ } else {
+ pages_count = pagesCount(use_full_page -> isChecked());
+ }
+ options_label -> setText(tr("Nombre total de pages : ") + QString("%1").arg(pages_count));
+ setPagesRangeVisible(pages_count > 1);
+ start_page -> setRange(1, pages_count);
+ end_page -> setRange(1, pages_count);
+ end_page -> setValue(pages_count);
+}
+
+/**
+ S'assure que la premiere page ne soit pas superieure a la derniere page
+*/
+void DiagramPrintDialog::checkStartPage() {
+ if (start_page -> value() > end_page -> value()) {
+ start_page -> blockSignals(true);
+ start_page -> setValue(end_page -> value());
+ start_page -> blockSignals(false);
+ }
+}
+
+/**
+ S'assure que la derniere page ne soit pas inferieure a la premiere page
+*/
+void DiagramPrintDialog::checkEndPage() {
+ if (end_page -> value() < start_page -> value()) {
+ end_page -> blockSignals(true);
+ end_page -> setValue(start_page -> value());
+ end_page -> blockSignals(false);
+ }
+}
+
+/**
+ @param visible true pour afficher les pages, false sinon
+*/
+void DiagramPrintDialog::setPagesRangeVisible(bool visible) {
+ range_from_label -> setVisible(visible);
+ start_page -> setVisible(visible);
+ to_label -> setVisible(visible);
+ end_page -> setVisible(visible);
+}
+
+/**
+ Effectue l'impression elle-meme
+*/
+void DiagramPrintDialog::print() {
+ // recupere les informations collectees dans le second dialogue
+ bool full_page = use_full_page -> isChecked();
+ bool fit_page = fit_diagram_to_page -> isChecked();
+ int first_page = start_page -> value();
+ int last_page = end_page -> value();
+
+ // parametre l'imprimante
+ printer -> setFullPage(full_page);
+
+ // QPainter utiliser pour effectuer le rendu
+ QPainter qp(printer);
+
+ // impression physique (!= fichier PDF)
+ if (printer -> outputFileName().isEmpty()) {
+ // lorsqu'on imprime en paysage sur imprimante reelle, il faut pivoter soi-meme le rendu
+ if (printer -> orientation() == QPrinter::Landscape) {
+ qp.rotate(90.0);
+ qp.translate(0.0, -printer -> pageRect().height());
+ }
+ }
+
+ diagram -> setDisplayGrid(false);
+ diagram -> setDrawTerminals(false);
+
+ if (fit_page) {
+ // impression adaptee sur une seule page
+ diagram -> render(&qp, QRectF(), diagram -> border(), Qt::KeepAspectRatio);
+ } else {
+ // impression sur une ou plusieurs pages
+ QRect diagram_rect = diagram -> border().toRect();
+ QRect printed_area = full_page ? printer -> paperRect() : printer -> pageRect();
+ int used_width = printed_area.width();
+ int used_height = printed_area.height();
+ int h_pages_count = horizontalPagesCount(full_page);
+ int v_pages_count = verticalPagesCount(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) {
+ int page_number = (i * h_pages_count) + j + 1;
+ if (page_number >= first_page && page_number <= last_page) {
+ pages_to_print << pages_grid.at(i).at(j);
+ }
+ }
+ }
+
+ // parcourt les pages pour impression
+ for (int i = 0 ; i < pages_to_print.count() ; ++ i) {
+ QRect current_rect(pages_to_print.at(i));
+ 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();
+ }
+ }
+ }
+ diagram -> setDrawTerminals(true);
+ diagram -> setDisplayGrid(true);
+}
diff --git a/diagramprintdialog.h b/diagramprintdialog.h
new file mode 100644
index 000000000..bbc7bb127
--- /dev/null
+++ b/diagramprintdialog.h
@@ -0,0 +1,71 @@
+/*
+ Copyright 2006-2007 Xavier Guerrin
+ 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 "diagram.h"
+/**
+ Cette classe represente le dialogue de configuration de l'impression d'un
+ schema electrique.
+ Elle se charge egalement de l'impression elle-meme
+*/
+class DiagramPrintDialog : public QWidget {
+ Q_OBJECT
+ // Constructeurs, destructeur
+ public:
+ DiagramPrintDialog(Diagram *, QWidget * = 0);
+ virtual ~DiagramPrintDialog();
+ private:
+ DiagramPrintDialog(const DiagramPrintDialog &);
+
+ // methodes
+ public:
+ void setPDFName(const QString &);
+ QString PDFName() const;
+ int pagesCount(bool = false) const;
+ int horizontalPagesCount(bool = false) const;
+ int verticalPagesCount(bool = false) const;
+ void exec();
+
+ private:
+ void buildDialog();
+ void print();
+
+ private slots:
+ void updateDialog();
+ void checkStartPage();
+ void checkEndPage();
+ void setPagesRangeVisible(bool);
+
+ // attributs
+ private:
+ Diagram *diagram;
+ QPrinter *printer;
+ QString pdf_name;
+ QDialog *dialog;
+ QLabel *options_label;
+ QLabel *range_from_label;
+ QLabel *to_label;
+ QCheckBox *use_full_page;
+ QCheckBox *fit_diagram_to_page;
+ QSpinBox *start_page;
+ QSpinBox *end_page;
+ QDialogButtonBox *buttons;
+};
+#endif
diff --git a/diagramview.cpp b/diagramview.cpp
index 0c6479f0d..2fd71a8b6 100644
--- a/diagramview.cpp
+++ b/diagramview.cpp
@@ -19,6 +19,7 @@
#include "diagram.h"
#include "customelement.h"
#include "exportdialog.h"
+#include "diagramprintdialog.h"
#include "conductor.h"
#include "diagramcommands.h"
#include "conductorpropertieswidget.h"
@@ -530,31 +531,20 @@ void DiagramView::dialogExport() {
Imprime le schema.
*/
void DiagramView::dialogPrint() {
- // initialise l'acces a l'imprimante
- QPrinter qprin;
-#ifndef Q_OS_WIN32
- qprin.setOutputFormat(QPrinter::PdfFormat);
-#endif
- qprin.setOrientation(QPrinter::Landscape);
- qprin.setPageSize(QPrinter::A4);
- QPrintDialog qpd(&qprin, this);
- if (qpd.exec() == QDialog::Accepted) {
- QPainter qp(&qprin);
- // impression physique (!= fichier PDF)
- if (qprin.outputFileName().isEmpty()) {
- // lorsqu'on imprime en paysage sur imprimante reelle, il faut pivoter soi-meme le rendu
- if (qprin.orientation() == QPrinter::Landscape) {
- qp.rotate(90.0);
- qp.translate(0.0, -qprin.pageRect().height());
- }
- }
- scene -> setDisplayGrid(false);
- scene -> setDrawTerminals(false);
- scene -> render(&qp, QRectF(), scene -> border(), Qt::KeepAspectRatio);
- scene -> setDrawTerminals(true);
- scene -> setDisplayGrid(true);
+ // determine un nom possible pour le pdf
+ QString pdf_file_name;
+ if (!file_name.isEmpty()) {
+ pdf_file_name = file_name;
+ pdf_file_name.replace(QRegExp("\\.qet$", Qt::CaseInsensitive), "");
+ } else {
+ pdf_file_name = QDir::homePath() + tr("schema");
}
+ pdf_file_name += ".pdf";
+
+ DiagramPrintDialog print_dialog(scene, this);
+ print_dialog.setPDFName(pdf_file_name);
+ print_dialog.exec();
}
/**
diff --git a/lang/qet_en.qm b/lang/qet_en.qm
index 8f757a4b5..36242c39f 100644
Binary files a/lang/qet_en.qm and b/lang/qet_en.qm differ
diff --git a/lang/qet_en.ts b/lang/qet_en.ts
index bd71c6624..abf8c5900 100644
--- a/lang/qet_en.ts
+++ b/lang/qet_en.ts
@@ -1,5 +1,6 @@
+
AboutQET
@@ -45,7 +46,7 @@
© 2006-2008 Les développeurs de QElectroTech
- © 2006-2008 QElectroTech developers
+ © 2006-2008 QElectroTech developers
@@ -218,103 +219,141 @@
Configure QElectroTech
+
+ DiagramPrintDialog
+
+
+ Options d'impression
+ Print options
+
+
+
+ Utiliser toute la feuille
+ Use full page
+
+
+
+ Adapter le schéma à la page
+ Fit diagram to page
+
+
+
+ Plage de
+ Range from
+
+
+
+ à
+ to
+
+
+
+ Nombre total de pages :
+ Total pages count:
+
+
DiagramView
-
+
?
?
-
+
Enregistrer le schéma en cours ?
Save the current diagram ?
-
+
Enregistrer sous
Save as
-
+
Erreur
Error
-
+
Impossible d'ecrire dans ce fichier
Can't write to the file
-
+
Schéma QElectroTech (*.qet)
QElectroTech Diagram (*.qet)
-
+
Voulez-vous enregistrer le schéma
Do you wish to save the diagram
-
+
nouveau schéma
new diagram
-
+
Éditer les propriétés d'un conducteur
Edit conductor properties
-
+
Propriétés du schéma
Diagram properties
-
+
Dimensions du schéma
Diagram size
-
+
Colonnes :
Columns:
-
+
×
×
-
+
px
px
-
+
Hauteur :
Height:
-
+
Éditer les propriétés par défaut des conducteurs
Edit conductors default properties
-
+
Coller ici
Paste Here
-
+
Avertissement
Warning
-
+
Ce document semble avoir été enregistré avec une version ultérieure de QElectroTech. Il est possible que l'ouverture de tout ou partie de ce document échoue.
This document seems to have been saved by a more recent version of QElectroTech. The opening of the document may fail totally or partially.
+
+
+ schema
+ diagram
+
ElementDeleter
diff --git a/qelectrotech.pro b/qelectrotech.pro
index 09a5a7e0b..fc9a3bf08 100644
--- a/qelectrotech.pro
+++ b/qelectrotech.pro
@@ -50,6 +50,7 @@ HEADERS += aboutqet.h \
diagram.h \
diagramcommands.h \
diagramcontent.h \
+ diagramprintdialog.h \
diagramview.h \
diagramtextitem.h \
element.h \
@@ -114,6 +115,7 @@ SOURCES += aboutqet.cpp \
diagram.cpp \
diagramcommands.cpp \
diagramcontent.cpp \
+ diagramprintdialog.cpp \
diagramtextitem.cpp \
diagramview.cpp \
element.cpp \