mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-10 22:24:13 +02:00
a3594c6633
Edit > Add > Generic device (also on the Add toolbar, and found by the
command search as diagrameditor.add_generic_device) opens a three-page
wizard for devices used too rarely to draw a symbol for, such as a VSD
or a power supply:
1. Layout: terminals per side (0 for none), a gap every N terminals,
divider marks on gaps, groups lined up across opposite sides, pitch
and extra size.
2. Terminals: a table per side and the same list as one line, where
In{4} is In1..In4, Q{z4} is Q0..Q3, X{3-6} is X3..X6 and an empty
entry is a gap; number pins 1..n counter-clockwise; paste rows of
side, name, function from a spreadsheet or a CSV file.
3. Information: name, label, manufacturer, reference, description.
A preview beside every page shows the box as it will be placed. Finish,
available from the first page, writes an ordinary symbol to the folder
"Generic devices" of the project's collection and puts it on the cursor.
The box sizes itself to its terminals and their names; every terminal
lands on the grid and gets a uuid. No new XML: any QElectroTech reads it.
The layout is pure (sources/genericdevice/genericdevice.cpp) and tested
by tst_genericdevice. ElementPictureFactory gains pictureFromDefinition()
to draw the preview with the same code as a placed element.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
208 lines
7.5 KiB
C++
208 lines
7.5 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 DIAGRAMVIEW_H
|
|
#define DIAGRAMVIEW_H
|
|
|
|
#include "../ElementsCollection/elementslocation.h"
|
|
#include "titleblock/templatelocation.h"
|
|
|
|
#include <QClipboard>
|
|
#include "palettegraphicsview.h"
|
|
|
|
class CellRuler;
|
|
class Conductor;
|
|
class Diagram;
|
|
class DiagramContextToolbar;
|
|
class DiagramGestureOverlay;
|
|
class QETDiagramEditor;
|
|
class DVEventInterface;
|
|
class QInputEvent;
|
|
class QGestureEvent;
|
|
class QMenu;
|
|
|
|
/**
|
|
This class provides a widget to render an electric diagram in an editable,
|
|
interactive way.
|
|
*/
|
|
class DiagramView : public PaletteGraphicsView
|
|
{
|
|
Q_OBJECT
|
|
|
|
// constructors, destructor
|
|
public:
|
|
DiagramView(Diagram *diagram, QWidget * = nullptr);
|
|
~DiagramView() override;
|
|
|
|
private:
|
|
DiagramView(const DiagramView &);
|
|
|
|
// attributes
|
|
|
|
Diagram *m_diagram = nullptr;
|
|
DVEventInterface *m_event_interface = nullptr;
|
|
QAction *m_paste_here = nullptr;
|
|
QAction *m_multi_paste = nullptr;
|
|
QAction *m_create_template = nullptr;
|
|
QAction *m_generate_cabinet_thumbnail = nullptr;
|
|
QMenu *m_folio_report_menu = nullptr;
|
|
QPoint m_paste_here_pos;
|
|
QPoint m_press_pos;
|
|
DiagramContextToolbar *m_context_toolbar = nullptr;
|
|
/// Right-drag gestures: tracking since the right button went down
|
|
bool m_gesture_tracking = false;
|
|
/// The platform's own right-click menu event is to be ignored:
|
|
/// the view opens the menu itself on release
|
|
bool m_swallow_native_menu = false;
|
|
bool m_menu_from_gesture = false;
|
|
/// The right press went to a running tool; a drag ends the tool
|
|
bool m_gesture_over_tool = false;
|
|
QPoint m_gesture_origin;
|
|
DiagramGestureOverlay *m_gesture_overlay = nullptr;
|
|
QPoint m_last_mouse_pos = QPoint(-1, -1);
|
|
QPointF m_drag_last_pos;
|
|
bool m_fresh_focus_in,
|
|
m_first_activation = true;
|
|
/// True while the view pans because Ctrl+Shift is held, as opposed
|
|
/// to the visualisation mode chosen from the toolbar.
|
|
bool m_ctrl_shift_panning = false;
|
|
QList<QAction *> m_separators;
|
|
QPolygonF m_free_rubberband;
|
|
bool m_free_rubberbanding = false;
|
|
CellRuler *m_top_ruler = nullptr;
|
|
CellRuler *m_side_ruler = nullptr;
|
|
bool m_cell_rulers_shown = false;
|
|
/// Last viewport transform the rulers were painted for
|
|
QTransform m_rulers_transform;
|
|
bool m_cell_lines_shown = false;
|
|
|
|
|
|
public:
|
|
QString title() const;
|
|
void editDiagramProperties();
|
|
Diagram *diagram() { return(m_diagram); }
|
|
QETDiagramEditor *diagramEditor() const;
|
|
void editSelection();
|
|
void setEventInterface (DVEventInterface *event_interface);
|
|
QList<QAction *> contextMenuActions() const;
|
|
/// Last mouse position seen by mouseMoveEvent(), in viewport
|
|
/// coordinates -- (-1, -1) if the mouse hasn't moved over this
|
|
/// view yet. Filled from ordinary Qt mouse events, not a global
|
|
/// cursor query (QCursor::pos()/setPos() are silently ignored by
|
|
/// several window managers and compositors, Wayland included).
|
|
QPoint lastMousePos() const { return m_last_mouse_pos; }
|
|
|
|
bool startElementPlacement(const ElementsLocation &location,
|
|
const QPointF &scene_pos);
|
|
QPointF defaultPlacementPos() const;
|
|
void setCellRulersShown(bool shown);
|
|
void setCellLinesShown(bool shown);
|
|
|
|
protected:
|
|
void mouseDoubleClickEvent(QMouseEvent *) override;
|
|
void contextMenuEvent(QContextMenuEvent *) override;
|
|
void wheelEvent(QWheelEvent *) override;
|
|
void focusInEvent(QFocusEvent *) override;
|
|
void focusOutEvent(QFocusEvent *) override;
|
|
void keyPressEvent(QKeyEvent *) override;
|
|
void keyReleaseEvent(QKeyEvent *) override;
|
|
bool event(QEvent *) override;
|
|
bool focusNextPrevChild(bool next) override;
|
|
///Set for one call only, by the Escape handler, to let focus leave the view.
|
|
bool m_releasing_focus = false;
|
|
void paintEvent(QPaintEvent *event) override;
|
|
bool viewportEvent(QEvent *event) override;
|
|
void drawBackground(QPainter *painter, const QRectF &rect) override;
|
|
void paintingInverted(bool inverted) override;
|
|
void mousePressEvent(QMouseEvent *) override;
|
|
void mouseMoveEvent(QMouseEvent *) override;
|
|
void mouseReleaseEvent(QMouseEvent *) override;
|
|
void dragEnterEvent(QDragEnterEvent *) override;
|
|
void dragMoveEvent(QDragMoveEvent *) override;
|
|
void dropEvent(QDropEvent *) override;
|
|
|
|
virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e);
|
|
virtual bool switchToSelectionModeIfNeeded(QInputEvent *e);
|
|
virtual bool isCtrlShifting(QInputEvent *);
|
|
virtual bool selectedItemHasFocus();
|
|
|
|
private:
|
|
void handleElementDrop(QDropEvent *);
|
|
void updateFolioReportMenu();
|
|
void handleTitleBlockDrop(QDropEvent *);
|
|
void handleTextDrop(QDropEvent *);
|
|
void handleImageFilesDrop(QDropEvent *);
|
|
void scrollOnMovement(QKeyEvent *);
|
|
bool gestureEvent(QGestureEvent *event);
|
|
QRectF viewedSceneRect() const;
|
|
bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const;
|
|
bool gestures() const;
|
|
void updateCellRulers();
|
|
void placeCellRulers();
|
|
void showContextToolbar(const QPoint &viewport_pos);
|
|
QList<QAction *> selectionCommands() const;
|
|
QList<QAction *> gestureCommands() const;
|
|
|
|
/// Lowest and highest allowed value of the view transform scale (m11).
|
|
/// Prevents wheel-zoom from driving the transform to overflow, which
|
|
/// crashes the editor (see GitHub issue #798, same class of bug).
|
|
static constexpr qreal m_min_zoom = 0.01;
|
|
static constexpr qreal m_max_zoom = 200.0;
|
|
|
|
signals:
|
|
/// Signal emitted after the selection mode changed
|
|
void modeChanged();
|
|
/// Signal emitted after the diagram title changed
|
|
void titleChanged(DiagramView *, const QString &);
|
|
/// Signal emitted when users wish to locate an element from the diagram within elements collection
|
|
void findElementRequired(const ElementsLocation &);
|
|
/// Signal emitted when diagram must be show
|
|
void showDiagram (Diagram *);
|
|
/// Signal emitted when free rubberband changed.
|
|
/// When free rubberband selection ends this signal will be emitted with null value.
|
|
void freeRubberBandChanged(QPolygonF polygon);
|
|
/// Signal emitted when the placement mode is entered for an
|
|
/// element (not a macro), whether from a drop or not.
|
|
void elementPlacementStarted(const ElementsLocation &);
|
|
|
|
public slots:
|
|
void setVisualisationMode();
|
|
void setSelectionMode();
|
|
void zoom(const qreal zoom_factor);
|
|
void zoomFit();
|
|
void zoomContent();
|
|
void zoomReset();
|
|
void zoomToRect(const QRectF &rect);
|
|
void centerOnCursor();
|
|
void cut();
|
|
void copy();
|
|
void paste(const QPointF & = QPointF(), QClipboard::Mode = QClipboard::Clipboard);
|
|
void pasteHere();
|
|
void duplicate(const QPoint &stepOffset);
|
|
void adjustSceneRect();
|
|
void updateWindowTitle();
|
|
void resetConductors();
|
|
void addGenericDevice();
|
|
|
|
private slots:
|
|
void adjustGridToZoom();
|
|
void applyReadOnly();
|
|
void createTemplateFromSelection();
|
|
void generateCabinetThumbnails();
|
|
};
|
|
#endif
|