From ff25a7715989c28f7ccade2bf97f42b290e37959 Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Sat, 22 Aug 2026 18:53:36 +0200 Subject: [PATCH] Improve PDF import: DPI selection, page preview, Qt5 compat, custom icon - Add DPI selection (150/300/600) to the page selection dialog - Add live page preview in the selection dialog - Conditionally compile PDF import only for Qt6 (#if QT_VERSION) - Add custom pdf-import icon (PDF document with + symbol) - Register new icon in qelectrotech.qrc - Qt5 builds: PDF import action is hidden, everything else works as before --- cmake/qet_compilation_vars.cmake | 26 ++++++++--- ico/22x22/pdf-import.png | Bin 0 -> 1539 bytes qelectrotech.qrc | 1 + sources/diagramevent/diagrameventaddpdf.cpp | 30 +++++-------- sources/qetdiagrameditor.cpp | 10 +++++ sources/qeticons.cpp | 2 +- sources/ui/pdfpagesdialog.cpp | 46 +++++++++++++++----- sources/ui/pdfpagesdialog.h | 5 ++- 8 files changed, 83 insertions(+), 37 deletions(-) create mode 100644 ico/22x22/pdf-import.png diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake index 469405abd..36e4bb9b7 100644 --- a/cmake/qet_compilation_vars.cmake +++ b/cmake/qet_compilation_vars.cmake @@ -26,7 +26,6 @@ message(" - qet_compilation_vars") set(QET_COMPONENTS LinguistTools PrintSupport - Pdf Xml Svg Sql @@ -34,9 +33,13 @@ set(QET_COMPONENTS Widgets Concurrent) +# Qt6-only: QPdfDocument for PDF page import +if(QT_VERSION_MAJOR GREATER_EQUAL 6) + list(APPEND QET_COMPONENTS Pdf) +endif() + set(QET_PRIVATE_LIBRARIES Qt::PrintSupport - Qt::Pdf Qt::Gui Qt::GuiPrivate # Required for QPdfEngine::drawHyperlink (PDF internal links) Qt::Xml @@ -47,6 +50,11 @@ set(QET_PRIVATE_LIBRARIES Qt::Concurrent ) +# Qt6-only: QPdfDocument for PDF page import +if(QT_VERSION_MAJOR GREATER_EQUAL 6) + list(APPEND QET_PRIVATE_LIBRARIES Qt::Pdf) +endif() + set(QET_RES_FILES ${QET_DIR}/sources/autoNum/ui/autonumberingdockwidget.ui ${QET_DIR}/sources/autoNum/ui/autonumberingmanagementw.ui @@ -309,8 +317,6 @@ set(QET_SRC_FILES ${QET_DIR}/sources/diagramevent/diagrameventaddelement.h ${QET_DIR}/sources/diagramevent/diagrameventaddimage.cpp ${QET_DIR}/sources/diagramevent/diagrameventaddimage.h - ${QET_DIR}/sources/diagramevent/diagrameventaddpdf.cpp - ${QET_DIR}/sources/diagramevent/diagrameventaddpdf.h ${QET_DIR}/sources/diagramevent/diagrameventaddshape.cpp ${QET_DIR}/sources/diagramevent/diagrameventaddshape.h ${QET_DIR}/sources/diagramevent/diagrameventaddtext.cpp @@ -717,8 +723,6 @@ set(QET_SRC_FILES ${QET_DIR}/sources/ui/formulaassistantdialog.h ${QET_DIR}/sources/ui/imagepropertieswidget.cpp ${QET_DIR}/sources/ui/imagepropertieswidget.h - ${QET_DIR}/sources/ui/pdfpagesdialog.cpp - ${QET_DIR}/sources/ui/pdfpagesdialog.h ${QET_DIR}/sources/ui/importelementdialog.cpp ${QET_DIR}/sources/ui/importelementdialog.h ${QET_DIR}/sources/ui/importelementtextpatterndialog.cpp @@ -820,6 +824,16 @@ if(NOT BUILD_WITH_KF) ) endif() +# Qt6-only: PDF page import files +if(QT_VERSION_MAJOR GREATER_EQUAL 6) + list(APPEND QET_SRC_FILES + ${QET_DIR}/sources/diagramevent/diagrameventaddpdf.cpp + ${QET_DIR}/sources/diagramevent/diagrameventaddpdf.h + ${QET_DIR}/sources/ui/pdfpagesdialog.cpp + ${QET_DIR}/sources/ui/pdfpagesdialog.h + ) +endif() + set(TS_FILES ${QET_DIR}/lang/qet_ar.ts ${QET_DIR}/lang/qet_ca.ts diff --git a/ico/22x22/pdf-import.png b/ico/22x22/pdf-import.png new file mode 100644 index 0000000000000000000000000000000000000000..f84ef79ab79f98d8cd46f12d3cfa48a5ed336ad4 GIT binary patch literal 1539 zcmZ{kdoKq46SzB9Ysj)GE^?P zM9L*f3=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&Q_BgkX;tM-M|DdNuY{E4p%BUH$pZ(e`5fU-7g;VlfZ(-QEl6-u{1QP@33Yy%zkNdvs(^bRT|JQThrB6S;D zcIpgUFGgShgKA8Pq(T7*cmh!eZ>U2cxa$#(cdy}LJl+_O$Avpy{+~b#4-5&4{klLV ltQtdt)_)TiAv9_fBY+n1bw^zDico/22x22/go-up.png ico/22x22/hotspot.png ico/22x22/insert-image.png + ico/22x22/pdf-import.png ico/22x22/label.png ico/22x22/landscape.png ico/22x22/line.png diff --git a/sources/diagramevent/diagrameventaddpdf.cpp b/sources/diagramevent/diagrameventaddpdf.cpp index 602e48be2..21931c404 100644 --- a/sources/diagramevent/diagrameventaddpdf.cpp +++ b/sources/diagramevent/diagrameventaddpdf.cpp @@ -28,11 +28,6 @@ #include #include -// Target rendering DPI for PDF pages. -// 150 DPI provides good quality for screen display and printing -// while keeping file size reasonable. -static const int PDF_RENDER_DPI = 150; - /** @brief DiagramEventAddPdf::DiagramEventAddPdf Constructor @@ -160,8 +155,8 @@ bool DiagramEventAddPdf::isNull() const /** @brief DiagramEventAddPdf::openDialog Opens a file dialog to select a PDF file, then opens a page selection - dialog. The selected page is rendered to a QImage at 150 DPI and - converted to a DiagramImageItem. + dialog with DPI options. The selected page is rendered to a QImage at + the chosen DPI and converted to a DiagramImageItem. */ void DiagramEventAddPdf::openDialog() { @@ -203,21 +198,18 @@ void DiagramEventAddPdf::openDialog() return; } - // If only one page, import directly without showing dialog - int pageIndex = 0; - if (pageCount > 1) - { - PdfPagesDialog dialog(document, - m_diagram->views().isEmpty() ? nullptr : m_diagram->views().first()); - if (dialog.exec() != QDialog::Accepted) return; - pageIndex = dialog.selectedPage() - 1; // Convert to 0-based index - } + // Always show the dialog so the user can choose page and DPI + PdfPagesDialog dialog(document, + m_diagram->views().isEmpty() ? nullptr : m_diagram->views().first()); + if (dialog.exec() != QDialog::Accepted) return; + int pageIndex = dialog.selectedPage() - 1; // Convert to 0-based index + int dpi = dialog.selectedDpi(); - // Calculate pixel size from PDF points at target DPI + // Calculate pixel size from PDF points at the user-selected DPI // PDF point = 1/72 inch QSizeF pageSize = document.pagePointSize(pageIndex); - int pixelWidth = qRound((pageSize.width() / 72.0) * PDF_RENDER_DPI); - int pixelHeight = qRound((pageSize.height() / 72.0) * PDF_RENDER_DPI); + int pixelWidth = qRound((pageSize.width() / 72.0) * dpi); + int pixelHeight = qRound((pageSize.height() / 72.0) * dpi); if (pixelWidth <= 0 || pixelHeight <= 0) { diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 8505e6fbc..e9e0838ee 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -23,7 +23,9 @@ #include "conductornumexport.h" #include "diagramcommands.h" #include "diagramevent/diagrameventaddimage.h" +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include "diagramevent/diagrameventaddpdf.h" +#endif #include "diagramevent/diagrameventaddshape.h" #include "diagramevent/diagrameventaddtext.h" #include "diagramview.h" @@ -717,7 +719,9 @@ void QETDiagramEditor::setUpActions() //Adding action (add text, image, shape...) QAction *add_text = m_add_item_actions_group.addAction(QET::Icons::PartTextField, tr("Ajouter un champ de texte")); QAction *add_image = m_add_item_actions_group.addAction(QET::Icons::adding_image, tr("Ajouter une image")); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QAction *add_pdf = m_add_item_actions_group.addAction(QET::Icons::adding_pdf, tr("Ajouter un PDF")); +#endif QAction *add_line = m_add_item_actions_group.addAction(QET::Icons::PartLine, tr("Ajouter une ligne", "Draw line")); QAction *add_rectangle = m_add_item_actions_group.addAction(QET::Icons::PartRectangle, tr("Ajouter un rectangle")); QAction *add_ellipse = m_add_item_actions_group.addAction(QET::Icons::PartEllipse, tr("Ajouter une ellipse")); @@ -726,7 +730,9 @@ void QETDiagramEditor::setUpActions() add_text ->setStatusTip(tr("Ajoute un champ de texte sur le folio actuel")); add_image ->setStatusTip(tr("Ajoute une image sur le folio actuel")); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) add_pdf ->setStatusTip(tr("Ajoute une page PDF sur le folio actuel")); +#endif add_line ->setStatusTip(tr("Ajoute une ligne sur le folio actuel")); add_rectangle->setStatusTip(tr("Ajoute un rectangle sur le folio actuel")); add_ellipse ->setStatusTip(tr("Ajoute une ellipse sur le folio actuel")); @@ -735,7 +741,9 @@ void QETDiagramEditor::setUpActions() add_text ->setData(QStringLiteral("text")); add_image ->setData(QStringLiteral("image")); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) add_pdf ->setData(QStringLiteral("pdf")); +#endif add_line ->setData(QStringLiteral("line")); add_rectangle->setData(QStringLiteral("rectangle")); add_ellipse ->setData(QStringLiteral("ellipse")); @@ -1573,6 +1581,7 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) else diagram_event = deai; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) else if (value == "pdf") { DiagramEventAddPdf *deap = new DiagramEventAddPdf(d); @@ -1584,6 +1593,7 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) else diagram_event = deap; } +#endif else if (value == "text") { diagram_event = new DiagramEventAddText(d); diff --git a/sources/qeticons.cpp b/sources/qeticons.cpp index d1dca1af7..6d53c46c6 100644 --- a/sources/qeticons.cpp +++ b/sources/qeticons.cpp @@ -454,7 +454,7 @@ void QET::Icons::initIcons() EditClear .addFile(":/ico/22x22/edit-clear.png"); EditText .addFile(":/ico/22x22/names.png"); adding_image .addFile(":/ico/22x22/insert-image.png"); - adding_pdf .addFile(":/ico/22x22/document-import.png"); + adding_pdf .addFile(":/ico/22x22/pdf-import.png"); if (rtl) { EditClearLocationBar.addPixmap(QPixmap(":/ico/16x16/edit-clear-locationbar-ltr.png").transformed(reverse)); diff --git a/sources/ui/pdfpagesdialog.cpp b/sources/ui/pdfpagesdialog.cpp index a4553abb6..7f6069248 100644 --- a/sources/ui/pdfpagesdialog.cpp +++ b/sources/ui/pdfpagesdialog.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -28,8 +29,10 @@ #include // Preview rendering DPI for the thumbnail in the dialog. -// Lower than the final render DPI to keep the dialog fast and compact. +// Fixed at 96 DPI to keep the preview fast and compact regardless +// of the final render DPI selected by the user. static const int PREVIEW_DPI = 96; +static const int PREVIEW_WIDTH = 400; /** @brief PdfPagesDialog::PdfPagesDialog @@ -43,7 +46,7 @@ PdfPagesDialog::PdfPagesDialog(QPdfDocument &document, QWidget *parent) { setWindowTitle(tr("Sélectionner une page")); setMinimumWidth(500); - setMinimumHeight(400); + setMinimumHeight(500); int pageCount = document.pageCount(); @@ -71,6 +74,19 @@ PdfPagesDialog::PdfPagesDialog(QPdfDocument &document, QWidget *parent) m_page_spinbox->setValue(1); page_layout->addWidget(m_page_spinbox); + page_layout->addStretch(); + + // DPI selection + QLabel *dpi_label = new QLabel(tr("Résolution :"), this); + page_layout->addWidget(dpi_label); + + m_dpi_combo = new QComboBox(this); + m_dpi_combo->addItem(tr("150 DPI (écran)"), 150); + m_dpi_combo->addItem(tr("300 DPI (impression)"), 300); + m_dpi_combo->addItem(tr("600 DPI (haute qualité)"), 600); + m_dpi_combo->setCurrentIndex(0); + page_layout->addWidget(m_dpi_combo); + main_layout->addLayout(page_layout); // Preview area @@ -98,9 +114,11 @@ PdfPagesDialog::PdfPagesDialog(QPdfDocument &document, QWidget *parent) connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); main_layout->addWidget(button_box); - // Update preview when spinbox value changes + // Update preview when spinbox or DPI changes connect(m_page_spinbox, QOverload::of(&QSpinBox::valueChanged), this, &PdfPagesDialog::updatePreview); + connect(m_dpi_combo, QOverload::of(&QComboBox::currentIndexChanged), + this, &PdfPagesDialog::updatePreview); // Render initial preview updatePreview(); @@ -115,11 +133,20 @@ int PdfPagesDialog::selectedPage() const return m_page_spinbox->value(); } +/** + @brief PdfPagesDialog::selectedDpi + @return the selected DPI value (150, 300, or 600) +*/ +int PdfPagesDialog::selectedDpi() const +{ + return m_dpi_combo->currentData().toInt(); +} + /** @brief PdfPagesDialog::updatePreview Renders the currently selected page as a thumbnail and displays it - in the preview label. Uses a fixed preview width of 400 pixels - while preserving the page aspect ratio. + in the preview label. The preview size scales with the selected DPI + to give a visual hint of the output quality. */ void PdfPagesDialog::updatePreview() { @@ -129,12 +156,11 @@ void PdfPagesDialog::updatePreview() QSizeF pageSize = m_document.pagePointSize(pageIndex); if (pageSize.isEmpty()) return; - const int previewWidth = 400; qreal ratio = pageSize.height() / pageSize.width(); - int previewHeight = qRound(previewWidth * ratio); + int previewHeight = qRound(PREVIEW_WIDTH * ratio); - // Render the page to QImage - QImage preview = m_document.render(pageIndex, QSize(previewWidth, previewHeight)); + // Render the page to QImage at preview DPI + QImage preview = m_document.render(pageIndex, QSize(PREVIEW_WIDTH, previewHeight)); if (preview.isNull()) return; // Fill white background to handle transparent PDFs @@ -145,6 +171,6 @@ void PdfPagesDialog::updatePreview() painter.end(); m_preview_label->setPixmap(QPixmap::fromImage(background).scaled( - previewWidth, previewHeight, + PREVIEW_WIDTH, previewHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } diff --git a/sources/ui/pdfpagesdialog.h b/sources/ui/pdfpagesdialog.h index 64b1fb676..f2eb2d82d 100644 --- a/sources/ui/pdfpagesdialog.h +++ b/sources/ui/pdfpagesdialog.h @@ -21,6 +21,7 @@ #include class QSpinBox; +class QComboBox; class QLabel; class QPdfDocument; @@ -28,7 +29,7 @@ class QPdfDocument; @brief The PdfPagesDialog class Dialog for selecting a page from a PDF document. Displays the total page count, a live preview of the selected page, - and allows the user to choose which page to import. + DPI options (150/300/600), and allows the user to choose which page to import. */ class PdfPagesDialog : public QDialog { @@ -37,6 +38,7 @@ class PdfPagesDialog : public QDialog public: explicit PdfPagesDialog(QPdfDocument &document, QWidget *parent = nullptr); int selectedPage() const; + int selectedDpi() const; private slots: void updatePreview(); @@ -46,6 +48,7 @@ class PdfPagesDialog : public QDialog QLabel *m_info_label; QLabel *m_preview_label; QSpinBox *m_page_spinbox; + QComboBox *m_dpi_combo; }; #endif // PDFPAGESDIALOG_H