mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-06-09 03:33:14 +02:00
cd76b6a1d6
directly to the related component on its folio, framing the target element.
When a project is exported to PDF, every cross-reference becomes an internal
link. Four kinds are covered:
- **Master → contact**: the contact list on a coil/relay (`CrossRefItem`)
- **Folio report → report**: report element labels (`DynamicElementTextItem`)
- **Slave → master**: the `(folio-position)` reference shown on a slave
(both standalone `DynamicElementTextItem` and grouped `ElementTextItemGroup`)
Clicking a link navigates **inside** the open document (no new viewer
instance) and zooms to frame the target element.
1. **Injection** (`printDiagram`, only when the paint engine is a `QPdfEngine`):
link rectangles are added with `QPdfEngine::drawHyperlink()`. The scene→page
mapping is rebuilt to match exactly what `QGraphicsScene::render()` does
(top-left anchored, `KeepAspectRatio`, **no centering**), and rectangles are
passed in device pixels — `pageMatrix()` already applies the 72/resolution
scale and Y-flip internally.
2. Each link URL encodes the target page and the target element's rectangle, in
PDF points on its own page: `#page=N&fitr=L_B_R_T`.
3. **Post-processing** (`pdfConvertUriToGoTo`, run after the painter is closed):
the `/S /URI` annotations are rewritten to native `/S /GoTo` actions with a
`/D [pageObj 0 R /FitR L B R T]` destination, and the xref table is rebuilt.
Pages are enumerated from the `/Pages /Kids` tree (reliable), not by scanning
for `/Type /Page` in raw bytes.
- `sources/print/projectprintwindow.{cpp,h}` — injection + post-processing
- `sources/qetgraphicsitem/crossrefitem.{cpp,h}` — `hoveredContactsMap()` accessor; store text rect for hit area
- `sources/qetgraphicsitem/dynamicelementtextitem.h` — `slaveXrefItem()` / `masterElement()` accessors
- `sources/qetgraphicsitem/elementtextitemgroup.h` — `slaveXrefItem()` accessor
- `qelectrotech.pro`, `cmake/qet_compilation_vars.cmake` — enable Qt gui-private headers (`<private/qpdf_p.h>`)
- **Fit-to-page mode only.** Links are not injected in tiled mode (multiple
pages per folio), which would require a per-tile transform.
- Uses Qt private API (`QPdfEngine::drawHyperlink`), stable since Qt 4 but not
part of the public API; the build links against `gui-private`.
- Page-tree enumeration assumes the flat `/Kids` array Qt produces (no nested
page trees).
- The frame zoom is controlled by two constants in `destRectPdf` (`pad`,
`minSide`) and can be tuned.
- Tested on Qt5; the `/Kids` parsing and `pageMatrix` behaviour are identical on
Qt6.
107 lines
3.6 KiB
C++
107 lines
3.6 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef PROJECTPRINTWINDOW_H
|
|
#define PROJECTPRINTWINDOW_H
|
|
|
|
#include "../exportproperties.h"
|
|
|
|
#include <QMainWindow>
|
|
#include <QMap>
|
|
#include <QPrinter>
|
|
|
|
namespace Ui {
|
|
class ProjectPrintWindow;
|
|
}
|
|
|
|
class QETProject;
|
|
class QPrintPreviewWidget;
|
|
class QPrinter;
|
|
class ExportProperties;
|
|
class Diagram;
|
|
class QCheckBox;
|
|
|
|
/**
|
|
* @brief The ProjectPrintWindow class
|
|
* Windows used to configure and view diagram before print
|
|
*/
|
|
class ProjectPrintWindow : public QMainWindow
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
static void launchDialog(QETProject *project, QPrinter::OutputFormat format = QPrinter::NativeFormat, QWidget *parent = nullptr);
|
|
static QString docName(QETProject *project);
|
|
|
|
explicit ProjectPrintWindow(QETProject *project, QPrinter *printer, QWidget *parent = nullptr);
|
|
~ProjectPrintWindow();
|
|
|
|
private slots:
|
|
void on_m_draw_border_cb_clicked();
|
|
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_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();
|
|
void on_m_adjust_width_action_triggered();
|
|
void on_m_adjust_page_action_triggered();
|
|
void on_m_landscape_action_triggered();
|
|
void on_m_portrait_action_triggered();
|
|
void on_m_first_page_action_triggered();
|
|
void on_m_previous_page_action_triggered();
|
|
void on_m_next_page_action_triggered();
|
|
void on_m_last_page_action_triggered();
|
|
void on_m_display_single_page_action_triggered();
|
|
void on_m_display_two_page_action_triggered();
|
|
void on_m_display_all_page_action_triggered();
|
|
void on_m_page_setup_triggered();
|
|
void on_m_check_all_pb_clicked();
|
|
void on_m_uncheck_all_clicked();
|
|
void print();
|
|
void on_m_date_cb_userDateChanged(const QDate &date);
|
|
void on_m_date_from_cb_currentIndexChanged(int index);
|
|
void on_m_apply_date_pb_clicked();
|
|
|
|
private:
|
|
void requestPaint();
|
|
void printDiagram(Diagram *diagram, bool fit_page, QPainter *painter, QPrinter *printer, const QMap<Diagram*, int> &diagramPageMap = {});
|
|
QRect diagramRect(Diagram *diagram, const ExportProperties &option) const;
|
|
int horizontalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
|
|
int verticalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
|
|
ExportProperties exportProperties() const;
|
|
void setUpDiagramList();
|
|
QString settingsSectionName(const QPrinter *printer);
|
|
void loadPageSetupForCurrentPrinter();
|
|
void savePageSetupForCurrentPrinter();
|
|
void saveReloadDiagramParameters(Diagram *diagram, const ExportProperties &options, bool save);
|
|
QList<Diagram *> selectedDiagram() const;
|
|
void exportToPDF();
|
|
|
|
|
|
private:
|
|
Ui::ProjectPrintWindow *ui;
|
|
QETProject *m_project = nullptr;
|
|
QPrinter *m_printer = nullptr;
|
|
QPrintPreviewWidget *m_preview=nullptr;
|
|
QColor m_backup_diagram_background_color;
|
|
QHash<Diagram *, QCheckBox *> m_diagram_list_hash;
|
|
};
|
|
|
|
#endif // PROJECTPRINTWINDOW_H
|