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 000000000..f84ef79ab
Binary files /dev/null and b/ico/22x22/pdf-import.png differ
diff --git a/qelectrotech.qrc b/qelectrotech.qrc
index 7b506d46c..531dde1f4 100644
--- a/qelectrotech.qrc
+++ b/qelectrotech.qrc
@@ -140,6 +140,7 @@
ico/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