mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-22 00:04:14 +02:00
Export component info as invisible PDF text annotations
This commit is contained in:
@@ -20,10 +20,12 @@
|
||||
#include "../diagram.h"
|
||||
#include "../pdf_links.h"
|
||||
#include "../qeticons.h"
|
||||
#include "../qetinformation.h"
|
||||
#include "../qetproject.h"
|
||||
#include "../qetversion.h"
|
||||
#include "../qetgraphicsitem/crossrefitem.h"
|
||||
#include "../qetgraphicsitem/dynamicelementtextitem.h"
|
||||
#include "../qetgraphicsitem/element.h"
|
||||
#include "../qetgraphicsitem/elementtextitemgroup.h"
|
||||
|
||||
#include "ui_projectprintwindow.h"
|
||||
@@ -156,6 +158,7 @@ ProjectPrintWindow::ProjectPrintWindow(QETProject *project, QPrinter *printer, Q
|
||||
ui->m_button_box->addButton(pdf_button, QDialogButtonBox::ActionRole);
|
||||
connect(pdf_button, &QPushButton::clicked, this, &ProjectPrintWindow::exportToPDF);
|
||||
}
|
||||
ui->m_component_info_cb->setVisible(m_printer->outputFormat() == QPrinter::PdfFormat);
|
||||
|
||||
auto exp = ExportProperties::defaultPrintProperties();
|
||||
ui->m_draw_border_cb->setChecked(exp.draw_border);
|
||||
@@ -426,6 +429,50 @@ void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter
|
||||
PdfLinks::injectCrossRefLinks(
|
||||
pdfEngine, diagram, geom, diagramPageMap,
|
||||
printer->outputFileName());
|
||||
|
||||
////Collect component info for popup annotations////
|
||||
if (ui->m_component_info_cb->isChecked()) {
|
||||
for (auto *item : diagram->items()) {
|
||||
auto *el = dynamic_cast<Element*>(item);
|
||||
if (!el) continue;
|
||||
|
||||
// Skip reports and slaves
|
||||
auto lt = el->linkType();
|
||||
if (lt & Element::AllReport) continue;
|
||||
if (lt == Element::Slave) continue;
|
||||
|
||||
auto info = el->elementInformations();
|
||||
if (info.count() == 0) continue;
|
||||
|
||||
// Build info text
|
||||
QStringList lines;
|
||||
for (const QString &key : {"label", "manufacturer", "designation", "description"}) {
|
||||
if (info.contains(key) && !info.value(key).toString().isEmpty())
|
||||
lines << QETInformation::translatedInfoKey(key) + ": " + info.value(key).toString();
|
||||
}
|
||||
for (const QString &key : info.keys()) {
|
||||
if (key == "formula") continue;
|
||||
QString translated = QETInformation::translatedInfoKey(key);
|
||||
if (lines.contains(translated + ": " + info.value(key).toString())) continue;
|
||||
if (info.value(key).toString().isEmpty()) continue;
|
||||
lines << translated + ": " + info.value(key).toString();
|
||||
}
|
||||
if (lines.isEmpty()) continue;
|
||||
|
||||
// Compute element rect in device pixels
|
||||
QRectF elemScene = el->mapRectToScene(el->boundingRect());
|
||||
QRectF devRect = fit.mapRect(elemScene);
|
||||
|
||||
PdfLinks::ComponentInfo ci;
|
||||
ci.contents = lines.join("\n");
|
||||
m_componentInfoList.append(ci);
|
||||
|
||||
// Create a link annotation as placeholder — post-processing
|
||||
// will convert it to an invisible text annotation with the actual content
|
||||
pdfEngine->drawHyperlink(devRect, QUrl("http://componentinfo.local/"));
|
||||
}
|
||||
}
|
||||
////Component info end////
|
||||
}
|
||||
}
|
||||
////PDF links end////
|
||||
@@ -799,6 +846,7 @@ void ProjectPrintWindow::on_m_draw_titleblock_cb_clicked() { m_preview->upd
|
||||
void ProjectPrintWindow::on_m_keep_conductor_color_cb_clicked() { m_preview->updatePreview(); }
|
||||
void ProjectPrintWindow::on_m_draw_terminal_cb_clicked() { m_preview->updatePreview(); }
|
||||
void ProjectPrintWindow::on_m_draw_terminal_names_cb_clicked() { m_preview->updatePreview(); }
|
||||
void ProjectPrintWindow::on_m_component_info_cb_clicked() { m_preview->updatePreview(); }
|
||||
void ProjectPrintWindow::on_m_fit_in_page_cb_clicked() { m_preview->updatePreview(); }
|
||||
void ProjectPrintWindow::on_m_use_full_page_cb_clicked()
|
||||
{
|
||||
@@ -903,9 +951,16 @@ void ProjectPrintWindow::print()
|
||||
// which prevents the black screen observed on Apple Silicon under
|
||||
// macOS Sequoia (QPrintPreviewWidget + CALayer timing issue).
|
||||
QTimer::singleShot(0, this, [this, pdfFile]() {
|
||||
// Convert component-info link annotations into invisible text annotations
|
||||
if (ui->m_component_info_cb->isChecked() && !m_componentInfoList.isEmpty()) {
|
||||
PdfLinks::convertComponentInfoAnnotations(pdfFile, m_componentInfoList);
|
||||
m_componentInfoList.clear();
|
||||
}
|
||||
|
||||
// Convert URI link annotations into native internal GoTo/FitR
|
||||
// actions so cross-references jump inside the document.
|
||||
PdfLinks::convertUriToGoTo(pdfFile);
|
||||
|
||||
this->close();
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define PROJECTPRINTWINDOW_H
|
||||
|
||||
#include "../exportproperties.h"
|
||||
#include "../pdf_links.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QMap>
|
||||
@@ -55,8 +56,9 @@ class ProjectPrintWindow : public QMainWindow
|
||||
void on_m_draw_titleblock_cb_clicked();
|
||||
void on_m_keep_conductor_color_cb_clicked();
|
||||
void on_m_draw_terminal_cb_clicked();
|
||||
void on_m_draw_terminal_names_cb_clicked();
|
||||
void on_m_fit_in_page_cb_clicked();
|
||||
void on_m_draw_terminal_names_cb_clicked();
|
||||
void on_m_component_info_cb_clicked();
|
||||
void on_m_fit_in_page_cb_clicked();
|
||||
void on_m_use_full_page_cb_clicked();
|
||||
void on_m_zoom_out_action_triggered();
|
||||
void on_m_zoom_in_action_triggered();
|
||||
@@ -102,6 +104,7 @@ class ProjectPrintWindow : public QMainWindow
|
||||
QPrintPreviewWidget *m_preview=nullptr;
|
||||
QColor m_backup_diagram_background_color;
|
||||
QHash<Diagram *, QCheckBox *> m_diagram_list_hash;
|
||||
QList<PdfLinks::ComponentInfo> m_componentInfoList;
|
||||
};
|
||||
|
||||
#endif // PROJECTPRINTWINDOW_H
|
||||
|
||||
@@ -183,17 +183,27 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="m_draw_terminal_names_cb">
|
||||
<property name="text">
|
||||
<string>Dessiner les noms des bornes</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="m_draw_terminal_names_cb">
|
||||
<property name="text">
|
||||
<string>Dessiner les noms des bornes</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="m_component_info_cb">
|
||||
<property name="text">
|
||||
<string>Inscrire les informations des composants</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
Reference in New Issue
Block a user