mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 08:10:52 +01:00
Add new QAction : export to pdf
This commit is contained in:
@@ -39,17 +39,11 @@
|
|||||||
* @brief ProjectPrintWindow::ProjectPrintWindow
|
* @brief ProjectPrintWindow::ProjectPrintWindow
|
||||||
* Use this static function to properly lauch the print dialog.
|
* Use this static function to properly lauch the print dialog.
|
||||||
* @param project : project to print
|
* @param project : project to print
|
||||||
|
* @param format : native format to print in physical printer, or pdf format to export in pdf
|
||||||
* @param parent : parent widget
|
* @param parent : parent widget
|
||||||
*/
|
*/
|
||||||
void ProjectPrintWindow::launchDialog(QETProject *project, QWidget *parent)
|
void ProjectPrintWindow::launchDialog(QETProject *project, QPrinter::OutputFormat format, 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();
|
auto printer_ = new QPrinter();
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||||
printer_->setOrientation(QPrinter::Landscape);
|
printer_->setOrientation(QPrinter::Landscape);
|
||||||
@@ -59,19 +53,16 @@ void ProjectPrintWindow::launchDialog(QETProject *project, QWidget *parent)
|
|||||||
#endif
|
#endif
|
||||||
qDebug()<<"Help code for QT 6 or later";
|
qDebug()<<"Help code for QT 6 or later";
|
||||||
#endif
|
#endif
|
||||||
printer_->setDocName(doc_name);
|
|
||||||
printer_->setCreator(QString("QElectroTech %1").arg(QET::displayedVersion));
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
printer_->setOutputFileName(file_name);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
if (format == QPrinter::NativeFormat) //To physical printer
|
||||||
|
{
|
||||||
QPrintDialog print_dialog(printer_, parent);
|
QPrintDialog print_dialog(printer_, parent);
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
print_dialog.setWindowFlags(Qt::Sheet);
|
print_dialog.setWindowFlags(Qt::Sheet);
|
||||||
#endif
|
#endif
|
||||||
print_dialog.setWindowTitle(tr("Options d'impression", "window title"));
|
print_dialog.setWindowTitle(tr("Options d'impression", "window title"));
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||||
print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintToFile | QAbstractPrintDialog::PrintShowPageSize);
|
print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintShowPageSize);
|
||||||
#else
|
#else
|
||||||
#if TODO_LIST
|
#if TODO_LIST
|
||||||
#pragma message("@TODO remove code for QT 6 or later")
|
#pragma message("@TODO remove code for QT 6 or later")
|
||||||
@@ -82,16 +73,25 @@ print_dialog.setWindowFlags(Qt::Sheet);
|
|||||||
delete printer_;
|
delete printer_;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else //To pdf file
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
printer_->setDocName(doc_name);
|
||||||
|
printer_->setCreator(QString("QElectroTech %1").arg(QET::displayedVersion));
|
||||||
|
printer_->setOutputFileName(file_name);
|
||||||
|
printer_->setOutputFormat(QPrinter::PdfFormat);
|
||||||
|
}
|
||||||
|
|
||||||
auto w = new ProjectPrintWindow(project, printer_, parent);
|
auto w = new ProjectPrintWindow(project, printer_, parent);
|
||||||
w->showMaximized();
|
w->showMaximized();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ProjectPrintWindow::docName
|
|
||||||
* @param project
|
|
||||||
* @return the doc name to use for project
|
|
||||||
*/
|
|
||||||
QString ProjectPrintWindow::docName(QETProject *project)
|
QString ProjectPrintWindow::docName(QETProject *project)
|
||||||
{
|
{
|
||||||
QString doc_name;
|
QString doc_name;
|
||||||
@@ -132,9 +132,18 @@ ProjectPrintWindow::ProjectPrintWindow(QETProject *project, QPrinter *printer, Q
|
|||||||
|
|
||||||
setUpDiagramList();
|
setUpDiagramList();
|
||||||
|
|
||||||
|
if (m_printer->outputFormat() == QPrinter::NativeFormat) //Print to physical printer
|
||||||
|
{
|
||||||
auto print_button = new QPushButton(QET::Icons::DocumentPrint, tr("Imprimer"));
|
auto print_button = new QPushButton(QET::Icons::DocumentPrint, tr("Imprimer"));
|
||||||
ui->m_button_box->addButton(print_button, QDialogButtonBox::ActionRole);
|
ui->m_button_box->addButton(print_button, QDialogButtonBox::ActionRole);
|
||||||
connect(print_button, &QPushButton::clicked, this, &ProjectPrintWindow::print);
|
connect(print_button, &QPushButton::clicked, this, &ProjectPrintWindow::print);
|
||||||
|
}
|
||||||
|
else //export to pdf
|
||||||
|
{
|
||||||
|
auto pdf_button = new QPushButton(QET::Icons::PDF, tr("Exporter en pdf"));
|
||||||
|
ui->m_button_box->addButton(pdf_button, QDialogButtonBox::ActionRole);
|
||||||
|
connect(pdf_button, &QPushButton::clicked, this, &ProjectPrintWindow::exportToPDF);
|
||||||
|
}
|
||||||
|
|
||||||
auto exp = ExportProperties::defaultPrintProperties();
|
auto exp = ExportProperties::defaultPrintProperties();
|
||||||
ui->m_draw_border_cb->setChecked(exp.draw_border);
|
ui->m_draw_border_cb->setChecked(exp.draw_border);
|
||||||
@@ -548,10 +557,13 @@ QList<Diagram *> ProjectPrintWindow::selectedDiagram() const
|
|||||||
|
|
||||||
void ProjectPrintWindow::exportToPDF()
|
void ProjectPrintWindow::exportToPDF()
|
||||||
{
|
{
|
||||||
auto file_name = QFileDialog::getSaveFileName(this);
|
auto file_name = QFileDialog::getSaveFileName(this, tr("Exporter sous : "), m_printer->outputFileName(), tr("Fichier (*.pdf"));
|
||||||
|
if (file_name.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_printer->setOutputFileName(file_name);
|
m_printer->setOutputFileName(file_name);
|
||||||
m_printer->setOutputFormat(QPrinter::PdfFormat);
|
m_printer->setOutputFormat(QPrinter::PdfFormat);
|
||||||
m_preview->print();
|
print();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectPrintWindow::on_m_draw_border_cb_clicked() { m_preview->updatePreview(); }
|
void ProjectPrintWindow::on_m_draw_border_cb_clicked() { m_preview->updatePreview(); }
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
#include "exportproperties.h"
|
#include "exportproperties.h"
|
||||||
|
#include <QPrinter>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ProjectPrintWindow;
|
class ProjectPrintWindow;
|
||||||
@@ -42,7 +43,7 @@ class ProjectPrintWindow : public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void launchDialog(QETProject *project, QWidget *parent = nullptr);
|
static void launchDialog(QETProject *project, QPrinter::OutputFormat format = QPrinter::NativeFormat, QWidget *parent = nullptr);
|
||||||
static QString docName(QETProject *project);
|
static QString docName(QETProject *project);
|
||||||
|
|
||||||
explicit ProjectPrintWindow(QETProject *project, QPrinter *printer, QWidget *parent = nullptr);
|
explicit ProjectPrintWindow(QETProject *project, QPrinter *printer, QWidget *parent = nullptr);
|
||||||
|
|||||||
@@ -253,10 +253,10 @@ void QETDiagramEditor::setUpAutonumberingWidget()
|
|||||||
void QETDiagramEditor::setUpActions()
|
void QETDiagramEditor::setUpActions()
|
||||||
{
|
{
|
||||||
//Export to another file type (jpeg, dxf etc...)
|
//Export to another file type (jpeg, dxf etc...)
|
||||||
m_export_diagram = new QAction(QET::Icons::DocumentExport, tr("E&xporter"), this);
|
m_export_to_images = new QAction(QET::Icons::DocumentExport, tr("E&xporter"), this);
|
||||||
m_export_diagram->setShortcut(QKeySequence(tr("Ctrl+Shift+X")));
|
m_export_to_images->setShortcut(QKeySequence(tr("Ctrl+Shift+X")));
|
||||||
m_export_diagram->setStatusTip(tr("Exporte le folio courant dans un autre format", "status bar tip"));
|
m_export_to_images->setStatusTip(tr("Exporte le folio courant dans un autre format", "status bar tip"));
|
||||||
connect(m_export_diagram, &QAction::triggered, [this]() {
|
connect(m_export_to_images, &QAction::triggered, [this]() {
|
||||||
ProjectView *current_project = currentProjectView();
|
ProjectView *current_project = currentProjectView();
|
||||||
if (current_project) {
|
if (current_project) {
|
||||||
current_project -> exportProject();
|
current_project -> exportProject();
|
||||||
@@ -270,7 +270,17 @@ void QETDiagramEditor::setUpActions()
|
|||||||
connect(m_print, &QAction::triggered, [this]() {
|
connect(m_print, &QAction::triggered, [this]() {
|
||||||
auto project = currentProject();
|
auto project = currentProject();
|
||||||
if (project) {
|
if (project) {
|
||||||
ProjectPrintWindow::launchDialog(project, this);
|
ProjectPrintWindow::launchDialog(project, QPrinter::NativeFormat ,this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//export to pdf
|
||||||
|
m_export_to_pdf = new QAction(QET::Icons::PDF, tr("Exporter en pdf"), this);
|
||||||
|
m_export_to_pdf->setStatusTip(tr("Exporte un ou plusieurs folios du projet courant", "status bar tip"));
|
||||||
|
connect(m_export_to_pdf, &QAction::triggered, [this] () {
|
||||||
|
auto project = currentProject();
|
||||||
|
if (project) {
|
||||||
|
ProjectPrintWindow::launchDialog(project, QPrinter::PdfFormat, this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -691,6 +701,7 @@ void QETDiagramEditor::setUpToolBar()
|
|||||||
|
|
||||||
main_tool_bar -> addActions(m_file_actions_group.actions());
|
main_tool_bar -> addActions(m_file_actions_group.actions());
|
||||||
main_tool_bar -> addAction(m_print);
|
main_tool_bar -> addAction(m_print);
|
||||||
|
main_tool_bar -> addAction(m_export_to_pdf);
|
||||||
main_tool_bar -> addSeparator();
|
main_tool_bar -> addSeparator();
|
||||||
main_tool_bar -> addAction(undo);
|
main_tool_bar -> addAction(undo);
|
||||||
main_tool_bar -> addAction(redo);
|
main_tool_bar -> addAction(redo);
|
||||||
@@ -757,8 +768,8 @@ void QETDiagramEditor::setUpMenu()
|
|||||||
menu_fichier -> addActions(m_file_actions_group.actions());
|
menu_fichier -> addActions(m_file_actions_group.actions());
|
||||||
menu_fichier -> addSeparator();
|
menu_fichier -> addSeparator();
|
||||||
//menu_fichier -> addAction(import_diagram);
|
//menu_fichier -> addAction(import_diagram);
|
||||||
menu_fichier -> addAction(m_export_diagram);
|
menu_fichier -> addAction(m_export_to_images);
|
||||||
//menu_fichier -> addSeparator();
|
menu_fichier -> addAction(m_export_to_pdf);
|
||||||
menu_fichier -> addAction(m_print);
|
menu_fichier -> addAction(m_print);
|
||||||
menu_fichier -> addSeparator();
|
menu_fichier -> addSeparator();
|
||||||
menu_fichier -> addAction(m_quit_editor);
|
menu_fichier -> addAction(m_quit_editor);
|
||||||
@@ -1484,27 +1495,28 @@ void QETDiagramEditor::slot_updateActions()
|
|||||||
bool opened_diagram = dv;
|
bool opened_diagram = dv;
|
||||||
bool editable_project = (pv && !pv -> project() -> isReadOnly());
|
bool editable_project = (pv && !pv -> project() -> isReadOnly());
|
||||||
|
|
||||||
m_close_file -> setEnabled(opened_project);
|
m_close_file-> setEnabled(opened_project);
|
||||||
m_save_file -> setEnabled(opened_project);
|
m_save_file-> setEnabled(opened_project);
|
||||||
m_save_file_as -> setEnabled(opened_project);
|
m_save_file_as-> setEnabled(opened_project);
|
||||||
m_project_edit_properties->setEnabled(opened_project);
|
m_project_edit_properties-> setEnabled(opened_project);
|
||||||
m_project_export_conductor_num->setEnabled(opened_project);
|
m_project_export_conductor_num->setEnabled(opened_project);
|
||||||
//prj_terminalBloc -> setEnabled(opened_project);
|
//prj_terminalBloc -> setEnabled(opened_project);
|
||||||
m_rotate_texts -> setEnabled(editable_project);
|
m_rotate_texts-> setEnabled(editable_project);
|
||||||
m_project_add_diagram -> setEnabled(editable_project);
|
m_project_add_diagram-> setEnabled(editable_project);
|
||||||
m_remove_diagram_from_project -> setEnabled(editable_project);
|
m_remove_diagram_from_project-> setEnabled(editable_project);
|
||||||
m_clean_project -> setEnabled(editable_project);
|
m_clean_project-> setEnabled(editable_project);
|
||||||
m_add_nomenclature->setEnabled(editable_project);
|
m_add_nomenclature-> setEnabled(editable_project);
|
||||||
m_add_summary->setEnabled(editable_project);
|
m_add_summary-> setEnabled(editable_project);
|
||||||
m_csv_export -> setEnabled(editable_project);
|
m_csv_export-> setEnabled(editable_project);
|
||||||
m_export_diagram -> setEnabled(opened_diagram);
|
m_export_to_images-> setEnabled(opened_diagram);
|
||||||
m_print -> setEnabled(opened_diagram);
|
m_print-> setEnabled(opened_diagram);
|
||||||
m_edit_diagram_properties -> setEnabled(opened_diagram);
|
m_export_to_pdf-> setEnabled(opened_diagram);
|
||||||
|
m_edit_diagram_properties-> setEnabled(opened_diagram);
|
||||||
m_zoom_actions_group. setEnabled(opened_diagram);
|
m_zoom_actions_group. setEnabled(opened_diagram);
|
||||||
m_select_actions_group. setEnabled(opened_diagram);
|
m_select_actions_group. setEnabled(opened_diagram);
|
||||||
m_add_item_actions_group. setEnabled(editable_project);
|
m_add_item_actions_group. setEnabled(editable_project);
|
||||||
m_row_column_actions_group.setEnabled(editable_project);
|
m_row_column_actions_group. setEnabled(editable_project);
|
||||||
m_grey_background->setEnabled(opened_diagram);
|
m_grey_background-> setEnabled(opened_diagram);
|
||||||
|
|
||||||
|
|
||||||
slot_updateUndoStack();
|
slot_updateUndoStack();
|
||||||
|
|||||||
@@ -166,7 +166,8 @@ class QETDiagramEditor : public QETMainWindow
|
|||||||
*m_windowed_view_mode, ///< Display projects as windows
|
*m_windowed_view_mode, ///< Display projects as windows
|
||||||
*m_mode_selection, ///< Set edition mode
|
*m_mode_selection, ///< Set edition mode
|
||||||
*m_mode_visualise, ///< Set visualisation mode
|
*m_mode_visualise, ///< Set visualisation mode
|
||||||
*m_export_diagram, ///< Export diagrams of the current project as imagess
|
*m_export_to_images, ///< Export diagrams of the current project as imagess
|
||||||
|
*m_export_to_pdf = nullptr, ///< Export project to pdf.
|
||||||
*m_print, ///< Print diagrams of the current project
|
*m_print, ///< Print diagrams of the current project
|
||||||
*m_quit_editor, ///< Quit the diagram editor
|
*m_quit_editor, ///< Quit the diagram editor
|
||||||
*undo, ///< Cancel the latest action
|
*undo, ///< Cancel the latest action
|
||||||
|
|||||||
Reference in New Issue
Block a user