19 #include <QSvgGenerator> 39 #include <QGraphicsSimpleTextItem> 56 if (!
project_ -> filePath().isEmpty()) {
61 setMinimumSize(800, 590);
62 resize(minimumSize());
63 setWindowTitle(
tr(
"Exporter les folios du projet",
"window title"));
69 buttons =
new QDialogButtonBox(
this);
72 QPushButton *export_button =
buttons -> button(QDialogButtonBox::Save);
73 export_button -> setText(
tr(
"Exporter"));
77 QHBoxLayout *hLayout =
new QHBoxLayout();
78 hLayout -> addWidget(
new QLabel(
tr(
"Choisissez les folios que vous désirez exporter ainsi que leurs dimensions :")));
89 QVBoxLayout *layout =
new QVBoxLayout(
this);
90 layout -> addLayout(hLayout);
92 layout -> addWidget(
epw);
99 connect(
buttons, SIGNAL(rejected()),
this, SLOT(reject()));
115 int checked_diagrams_count = 0;
117 if (diagram_line -> must_export -> isChecked()) ++ checked_diagrams_count;
119 return(checked_diagrams_count);
144 diagrams_list_layout_ -> addWidget(
new QLabel(
tr(
"Titre du folio")), line_count, 1, Qt::AlignHCenter | Qt::AlignVCenter);
145 diagrams_list_layout_ -> addWidget(
new QLabel(
tr(
"Nom de fichier")), line_count, 2, Qt::AlignHCenter | Qt::AlignVCenter);
146 diagrams_list_layout_ -> addWidget(
new QLabel(
tr(
"Dimensions")), line_count, 3, Qt::AlignHCenter | Qt::AlignVCenter);
162 width_mapper_ -> setMapping(diagram_line -> width, line_count);
164 ratio_mapper_ -> setMapping(diagram_line -> keep_ratio, line_count);
165 reset_mapper_ -> setMapping(diagram_line -> reset_size, line_count);
166 connect(diagram_line -> width, SIGNAL(valueChanged(
int)),
width_mapper_, SLOT(map()));
167 connect(diagram_line -> height, SIGNAL(valueChanged(
int)),
height_mapper_, SLOT(map()));
168 connect(diagram_line -> keep_ratio, SIGNAL(toggled(
bool)),
ratio_mapper_, SLOT(map()));
169 connect(diagram_line -> reset_size, SIGNAL(clicked(
bool)),
reset_mapper_, SLOT(map()));
173 connect(diagram_line -> preview, SIGNAL(clicked(
bool)),
preview_mapper_, SLOT(map()));
177 connect(diagram_line -> clipboard, SIGNAL(clicked(
bool)),
clipboard_mapper_, SLOT(map()));
180 QWidget *widget_diagrams_list =
new QWidget();
183 QScrollArea *scroll_diagrams_list =
new QScrollArea();
184 scroll_diagrams_list -> setWidget(widget_diagrams_list);
186 return(scroll_diagrams_list);
191 diagramLine -> must_export -> setChecked(
true);
197 diagramLine -> must_export -> setChecked(
false);
209 qreal diagram_ratio = (qreal)diagram_size.width() / (qreal)diagram_size.height();
210 return(diagram_ratio);
220 bool state_useBorder = diagram -> useBorder();
224 QSize diagram_size = diagram -> imageSize();
227 diagram -> setUseBorder(state_useBorder);
229 return(diagram_size);
241 if (!current_diagram)
return;
244 if (!(current_diagram -> keep_ratio -> isChecked()))
return;
247 qreal diagram_ratio =
diagramRatio(current_diagram -> diagram);
250 current_diagram -> width -> blockSignals(
true);
251 current_diagram -> width -> setValue(qRound(current_diagram -> height -> value() * diagram_ratio));
252 current_diagram -> width -> blockSignals(
false);
264 if (!current_diagram)
return;
267 if (!(current_diagram -> keep_ratio -> isChecked()))
return;
270 qreal diagram_ratio =
diagramRatio(current_diagram -> diagram);
273 current_diagram -> height -> blockSignals(
true);
274 current_diagram -> height -> setValue(qRound(current_diagram -> width -> value() / diagram_ratio));
275 current_diagram -> height -> blockSignals(
false);
286 if (!current_diagram)
return;
289 if (current_diagram -> keep_ratio -> isChecked()) {
296 if (!(current_diagram -> keep_ratio -> isChecked()))
return;
309 if (!current_diagram)
return;
312 QSize diagram_size =
diagramSize(current_diagram -> diagram);
315 current_diagram -> width -> blockSignals(
true);
316 current_diagram -> height -> blockSignals(
true);
317 current_diagram -> width -> setValue(diagram_size.width());
318 current_diagram -> height -> setValue(diagram_size.height());
319 current_diagram -> width -> blockSignals(
false);
320 current_diagram -> height -> blockSignals(
false);
334 QImage image(width, height, QImage::Format_RGB32);
335 diagram -> toPaintDevice(
339 keep_aspect_ratio ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio
358 state_exportProperties = diagram -> applyProperties(
epw -> exportProperties());
361 diagram -> applyProperties(state_exportProperties);
378 diagram -> toPaintDevice(
382 keep_aspect_ratio ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio
386 QSvgGenerator svg_engine;
387 svg_engine.setSize(QSize(width, height));
388 svg_engine.setOutputDevice(&io_device);
389 QPainter svg_painter(&svg_engine);
390 picture.play(&svg_painter);
415 if (
epw -> exportProperties().draw_border) {
418 diagram -> border_and_titleblock.drawDxf(width, height, keep_aspect_ratio, file_path, 0);
421 QList<Element *> list_elements;
422 QList<Conductor *> list_conductors;
423 QList<DiagramTextItem *> list_texts;
424 QList<DiagramImageItem *> list_images;
425 QList<QLineF *> list_lines;
426 QList<QRectF *> list_rectangles;
428 QList <QetShapeItem *> list_shapes;
432 list_lines = ptr -> lines();
433 list_rectangles = ptr -> rectangles();
437 QString authorTranslatable =
tr(
"Auteur");
438 QString titleTranslatable =
tr(
"Titre");
439 QString folioTranslatable =
tr(
"Folio");
440 QString dateTranslatable =
tr(
"Date");
442 qreal x0 = list_rectangles[0] -> topLeft().x();
443 qreal y0 = list_rectangles[0] -> topLeft().y();
444 qreal rowHeight = (list_rectangles[0] -> height())/30;
445 QRectF row_RectF(x0, y0, list_rectangles[0] -> width(), rowHeight);
447 fillRow(file_path, row_RectF, authorTranslatable, titleTranslatable, folioTranslatable, dateTranslatable);
448 QList<Diagram *> diagram_list = ptr -> project() -> diagrams();
450 int startDiagram = (ptr -> getId()) *29;
452 for (
int i = startDiagram; i < startDiagram+29 && i < diagram_list.size(); ++i) {
454 QRectF row_rect(x0, y0, list_rectangles[0] -> width(), rowHeight);
455 if (settings.value(
"genericpanel/folio",
true).toBool()){
456 fillRow(file_path, row_rect, diagram_list[i] -> border_and_titleblock.author(),
457 diagram_list[i] -> title(),
458 diagram_list[i] -> border_and_titleblock.finalfolio(),
459 diagram_list[i] -> border_and_titleblock.date().toString(
"dd/MM/yy"));
462 fillRow(file_path, row_rect, diagram_list[i] -> border_and_titleblock.author(),
463 diagram_list[i] -> title(),
464 QString::number(diagram_list[i] ->folioIndex()+1),
465 diagram_list[i] -> border_and_titleblock.date().toString(
"dd/MM/yy"));
472 foreach(QGraphicsItem *qgi, diagram -> items()) {
473 if (
Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
474 list_elements << elmt;
475 }
else if (
Conductor *f = qgraphicsitem_cast<Conductor *>(qgi)) {
476 list_conductors << f;
479 }
else if (
DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
481 }
else if (
QetShapeItem *dii = qgraphicsitem_cast<QetShapeItem *>(qgi)) {
492 foreach(
Element *elmt, list_elements)
494 double rotation_angle = elmt -> orientation() * 90;
496 qreal elem_pos_x = elmt -> pos().x();
497 qreal elem_pos_y = elmt -> pos().y();
504 for(QGraphicsSimpleTextItem *text : primitives.m_texts)
506 qreal fontSize = text->font().pointSizeF();
508 fontSize = text->font().pixelSize();
511 qreal x = elem_pos_x + text->pos().x();
512 qreal y = elem_pos_y + text->pos().y();
516 x = transformed_point.x();
517 y = transformed_point.y();
518 QStringList lines = text->text().split(
'\n');
519 y += (fontSize/2) * (lines.count()-1);
520 for (QString line : lines)
522 qreal angle = 360 - (text->rotation() + rotation_angle);
523 if (line.size() > 0 && line !=
"_" ) {
528 if (
int(angle) % 360 == 0)
530 else if (
int(angle - 180) % 360 == 0)
532 else if (
int(angle - 270) % 360 == 0)
539 for (QLineF line : primitives.m_lines)
544 x1 = transformed_point.x();
545 y1 = transformed_point.y();
549 x2 = transformed_point.x();
550 y2 = transformed_point.y();
554 for (QRectF rect : primitives.m_rectangles)
564 x1 = transformed_point.x();
565 y1 = transformed_point.y();
567 x2 = transformed_point.x();
568 y2 = transformed_point.y();
569 qreal bottom_left_x = (x1 < x2) ? x1 : x2;
570 qreal bottom_left_y = (y1 < y2) ? y1 : y2;
571 w = (x1 < x2) ? x2-x1 : x1-x2;
572 h = (y1 < y2) ? y2-y1 : y1-y2;
576 for (QRectF circle_rect : primitives.m_circles)
582 x1 = transformed_point.x();
583 y1 = transformed_point.y();
587 for (QVector<QPointF> polygon : primitives.m_polygons)
589 if (polygon.size() == 0)
594 x1 = transformed_point.x();
595 y1 = transformed_point.y();
596 for (
int i = 1; i < polygon.size(); ++i ) {
600 x2 = transformed_point.x();
601 y2 = transformed_point.y();
609 for (QVector<qreal> arc : primitives.m_arcs)
617 qreal startAngle = arc.at(4);
618 qreal spanAngle = arc .at(5);
619 Createdxf::drawArcEllipse(file_path, x, y, w, h, startAngle, spanAngle, hotspot_x, hotspot_y, rotation_angle, 0);
624 foreach(
Conductor *cond, list_conductors) {
635 qreal fontSize = textItem -> font().pointSizeF();
637 fontSize = textItem -> font().pixelSize();
641 QStringList lines = textItem->toPlainText().split(
'\n');
642 foreach (QString line, lines) {
643 qreal angle = 360 - (textItem -> rotation());
644 if (line.size() > 0 && line !=
"_" )
649 if (
int(angle) % 360 == 0)
651 else if (
int(angle - 180) % 360 == 0)
653 else if (
int(angle - 270) % 360 == 0)
664 qreal fontSize = dti -> font().pointSizeF();
666 fontSize = dti -> font().pixelSize();
670 QStringList lines = dti -> toPlainText().split(
'\n');
671 foreach (QString line, lines) {
672 qreal angle = 360 - (dti -> rotation());
673 if (line.size() > 0 && line !=
"_" )
678 if (
int(angle) % 360 == 0)
680 else if (
int(angle - 180) % 360 == 0)
682 else if (
int(angle - 270) % 360 == 0)
694 QString folio, QString date)
696 qreal x = row_rect.bottomLeft().x();
697 qreal y = row_rect.bottomLeft().y();
709 QString heading =
tr(
"Titre");
710 if (title == heading)
732 angle *= -3.14159265 / 180;
734 float s = sin(angle);
735 float c = cos(angle);
738 qreal Vx = px - origin_x;
739 qreal Vy = py - origin_y;
742 float xnew = Vx * c - Vy * s;
743 float ynew = Vx * s + Vy * c;
745 return QPointF(xnew + origin_x, ynew + origin_y);
755 QList<ExportDiagramLine *> diagrams_to_export;
757 if (diagram_line -> must_export -> isChecked()) {
758 diagrams_to_export << diagram_line;
763 QSet<QString> filenames;
765 QString diagram_file = diagram_line -> file_name -> text();
766 if (!diagram_file.isEmpty()) {
767 filenames << diagram_file;
770 if (filenames.count() != diagrams_to_export.count()) {
773 tr(
"Noms des fichiers cibles",
"message box title"),
775 "Vous devez entrer un nom de fichier non vide et unique pour chaque " 777 "message box content" 785 QDir target_dir_path(
epw -> exportProperties().destination_directory);
786 if (!target_dir_path.exists()) {
789 tr(
"Dossier non spécifié",
"message box title"),
790 tr(
"Vous devez spécifier le chemin du dossier dans lequel seront enregistrés les fichiers images.",
"message box content"),
814 QString format_acronym = export_properties.
format;
815 QString format_extension =
"." + format_acronym.toLower();
818 QString diagram_path = diagram_line -> file_name -> text();
822 diagram_path = target_dir_path.absoluteFilePath(diagram_path);
825 QFileInfo file_infos(diagram_path);
828 if (file_infos.exists() && !file_infos.isWritable()) {
831 tr(
"Impossible d'écrire dans ce fichier",
"message box title"),
834 "Il semblerait que vous n'ayez pas les permissions " 835 "nécessaires pour écrire dans le fichier %1.",
836 "message box content" 845 QFile target_file(diagram_path);
848 if (format_acronym ==
"SVG") {
850 diagram_line -> diagram,
851 diagram_line -> width -> value(),
852 diagram_line -> height -> value(),
853 diagram_line -> keep_ratio -> isChecked(),
856 }
else if (format_acronym ==
"DXF") {
858 diagram_line -> diagram,
859 diagram_line -> width -> value(),
860 diagram_line -> height -> value(),
861 diagram_line -> keep_ratio -> isChecked(),
866 diagram_line -> diagram,
867 diagram_line -> width -> value(),
868 diagram_line -> height -> value(),
869 diagram_line -> keep_ratio -> isChecked()
871 image.save(&target_file, format_acronym.toUtf8().data());
886 if (diagram_line -> keep_ratio -> isChecked()) {
899 QPushButton *export_button =
buttons -> button(QDialogButtonBox::Save);
910 QString format_acronym =
epw -> exportProperties().
format;
911 QString format_extension =
"." + format_acronym.toLower();
915 QString diagram_filename = diagram_line -> file_name -> text();
918 if (diagram_filename.endsWith(format_extension, Qt::CaseInsensitive)) {
922 QFileInfo diagram_filename_info(diagram_filename);
924 if (diagram_filename_info.suffix().isEmpty()) {
925 if (force_extension) {
926 diagram_filename = diagram_filename_info.completeBaseName() + format_extension;
930 diagram_filename = diagram_filename_info.completeBaseName() + format_extension;
933 diagram_line -> file_name -> setText(diagram_filename);
945 if (!current_diagram)
return;
948 QDialog preview_dialog;
949 preview_dialog.setWindowTitle(
tr(
"Aperçu"));
950 preview_dialog.setWindowState(preview_dialog.windowState() | Qt::WindowMaximized);
952 QGraphicsScene *preview_scene =
new QGraphicsScene();
953 preview_scene -> setBackgroundBrush(Qt::lightGray);
954 QGraphicsView *preview_view =
new QGraphicsView(preview_scene);
955 preview_view -> setDragMode(QGraphicsView::ScrollHandDrag);
956 QDialogButtonBox *
buttons =
new QDialogButtonBox(QDialogButtonBox::Ok);
957 connect(
buttons, SIGNAL(accepted()), &preview_dialog, SLOT(accept()));
959 QVBoxLayout *vboxlayout1 =
new QVBoxLayout();
960 vboxlayout1 -> addWidget(preview_view);
961 vboxlayout1 -> addWidget(
buttons);
962 preview_dialog.setLayout(vboxlayout1);
966 current_diagram -> diagram,
967 current_diagram -> width -> value(),
968 current_diagram -> height -> value(),
969 current_diagram -> keep_ratio -> isChecked()
973 foreach (QGraphicsItem *qgi, preview_scene -> items()) {
974 preview_scene -> removeItem(qgi);
979 QGraphicsPixmapItem *qgpi =
new QGraphicsPixmapItem(QPixmap::fromImage(preview_image));
980 preview_scene -> addItem(qgpi);
981 preview_scene -> setSceneRect(QRectF(0.0, 0.0, preview_image.width(), preview_image.height()));
984 preview_dialog.exec();
994 if (!diagram_line)
return;
997 QString format_acronym =
epw -> exportProperties().
format;
999 QClipboard *clipboard = QApplication::clipboard();
1002 if (format_acronym ==
"SVG") {
1004 QBuffer buffer(&ba);
1005 buffer.open(QIODevice::WriteOnly);
1007 diagram_line -> diagram,
1008 diagram_line -> width -> value(),
1009 diagram_line -> height -> value(),
1010 diagram_line -> keep_ratio -> isChecked(),
1014 clipboard -> setText(ba);
1017 diagram_line -> diagram,
1018 diagram_line -> width -> value(),
1019 diagram_line -> height -> value(),
1020 diagram_line -> keep_ratio -> isChecked()
1022 clipboard -> setImage(image);
1037 QString diagram_title =
diagram -> title();
1038 QString diagram_index = QString::number(
diagram -> folioIndex()+1);
1040 if (diagram_title.isEmpty()) diagram_title =
QObject::tr(
"Folio sans titre");
1041 QString diagram_filename =
diagram -> title();
1042 if (diagram_filename.isEmpty()) diagram_filename =
QObject::tr(
"schema");
1051 width =
new QSpinBox();
1052 width -> setRange(1, 10000);
1054 width -> setValue(diagram_size.width());
1057 height -> setRange(1, 10000);
1059 height -> setValue(diagram_size.height());
1093 QHBoxLayout *layout =
new QHBoxLayout();
1094 layout -> addWidget(width);
1095 layout -> addWidget(x_label);
1096 layout -> addWidget(height);
1097 layout -> addWidget(keep_ratio);
1098 layout -> addWidget(reset_size);
1099 layout -> addWidget(preview);
1100 layout -> addWidget(clipboard);
ExportDiagramLine(Diagram *, QSize)
void slot_keepRatioChanged(int)
QString format
Image format of generated files.
QPushButton * deSelectAll
ElementsLocation location() const
QHash< int, ExportDialog::ExportDiagramLine * > diagram_lines_
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
void saveReloadDiagramParameters(Diagram *, bool=true)
static void dxfEnd(const QString &)
void generateDxf(Diagram *, int, int, bool, QString &)
static const qreal margin
margin around the diagram
static ElementPictureFactory * instance()
instance
static void drawRectangle(const QString &filepath, double, double, double, double, const int &colorcode)
QSignalMapper * preview_mapper_
void slot_deSelectAllClicked()
static void drawText(const QString &, const QString &, double, double, double, double, int)
static const double sheetHeight
QWidget * initDiagramsListPart()
QSignalMapper * reset_mapper_
static void drawArcEllipse(const QString &file_path, qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal spanAngle, qreal hotspot_x, qreal hotspot_y, qreal rotation_angle, const int &colorcode)
void fillRow(const QString &, const QRectF &, QString, const QString &, QString, QString)
void slot_exportToClipBoard(int)
void generateSvg(Diagram *, int, int, bool, QIODevice &)
void slot_checkDiagramsCount()
void slot_changeUseBorder()
virtual ~ExportDiagramLine()
void slot_selectAllClicked()
QDir destination_directory
Target directory for generated files.
static ExportProperties defaultExportProperties()
ExportProperties::defaultProperties.
ElementPictureFactory::primitives getPrimitives(const ElementsLocation &location)
ElementPictureFactory::getPrimitives.
QBoxLayout * sizeLayout()
void exportDiagram(ExportDiagramLine *)
QSize diagramSize(Diagram *)
QString stringToFileName(const QString &)
static const double sheetWidth
void slot_correctWidth(int)
ExportPropertiesWidget * epw
The QetShapeItem class this class is used to draw a basic shape (line, rectangle, ellipse) into a dia...
static QPointF rotation_transformed(qreal, qreal, qreal, qreal, qreal)
QDialogButtonBox * buttons
QSignalMapper * height_mapper_
static void drawCircle(const QString &, double, double, double, int)
ExportDialog(QETProject *, QWidget *=nullptr)
void slot_correctHeight(int)
void slot_changeFilesExtension(bool=false)
qreal diagramRatio(Diagram *)
int diagramsToExportCount() const
static void drawTextAligned(const QString &fileName, const QString &text, double x, double y, double height, double rotation, double oblique, int hAlign, int vAlign, double xAlign, int colour, bool leftAlign=false, float scale=0)
QImage generateImage(Diagram *, int, int, bool)
QGridLayout * diagrams_list_layout_
QSignalMapper * clipboard_mapper_
QMessageBox::StandardButton critical(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
Export the diagram along with its border and title block.
static void drawLine(const QString &filapath, double, double, double, double, const int &clorcode)
QSignalMapper * ratio_mapper_
void slot_previewDiagram(int)
virtual bool toDXF(const QString &filepath, const QPen &pen)
QetShapeItem::toDXF Draw this element to the dxf document.
QSignalMapper * width_mapper_
QMessageBox::StandardButton warning(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)
static void dxfBegin(const QString &)
static qreal colWidths[7]