| #pragma once |
| |
| #ifndef SCHEMATICNODE_H |
| #define SCHEMATICNODE_H |
| |
| #include <QGraphicsItem> |
| #include "schematicviewer.h" |
| |
| |
| class SchematicPort; |
| |
| |
| |
| |
| |
| |
| |
| class SchematicName final : public QGraphicsTextItem { |
| Q_OBJECT |
| double m_width; |
| double m_height; |
| bool m_refocus; |
| QString m_defName; |
| QString m_curName; |
| QMenu *popup; |
| QAction *actionCut; |
| QAction *actionCopy; |
| QAction *actionPaste; |
| QAction *actionDelete; |
| QAction *actionSelectAll; |
| |
| public: |
| SchematicName(QGraphicsItem *parent, double width, double height); |
| ~SchematicName(); |
| |
| bool eventFilter(QObject *object, QEvent *event) override; |
| |
| void setName(const QString &name); |
| void acceptName(const QString &name); |
| |
| protected: |
| void focusInEvent(QFocusEvent *fe) override; |
| void focusOutEvent(QFocusEvent *fe) override; |
| |
| void keyPressEvent(QKeyEvent *ke) override; |
| void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override; |
| |
| signals: |
| void focusOut(); |
| |
| protected slots: |
| void onContentsChanged(); |
| void onPopupHide(); |
| void onCut(); |
| void onCopy(); |
| void onPaste(); |
| void onDelete(); |
| void onSelectAll(); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class SchematicThumbnailToggle final : public QObject, public QGraphicsItem { |
| Q_OBJECT |
| #ifndef MACOSX |
| Q_INTERFACES(QGraphicsItem) |
| #endif |
| |
| bool m_isDown; |
| |
| public: |
| SchematicThumbnailToggle(SchematicNode *parent, bool isOpened); |
| ~SchematicThumbnailToggle(); |
| |
| QRectF boundingRect() const override; |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override; |
| void setIsDown(bool value); |
| |
| protected: |
| void mousePressEvent(QGraphicsSceneMouseEvent *me) override; |
| |
| signals: |
| void toggled(bool isOpened); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class SchematicToggle : public QObject, public QGraphicsItem { |
| Q_OBJECT |
| #ifndef MACOSX |
| Q_INTERFACES(QGraphicsItem) |
| #endif |
| protected: |
| QIcon m_imageOn, m_imageOn2, m_imageOff; |
| QColor m_colorOn, m_colorOff; |
| int m_state; |
| int m_flags; |
| int m_width, m_height; |
| |
| public: |
| enum { eIsParentColumn = 0x01, eEnableNullState = 0x02 }; |
| |
| SchematicToggle(SchematicNode *parent, const QIcon &imageOn, QColor colorOn, |
| int flags, bool isNormalIconView = true); |
| |
| SchematicToggle(SchematicNode *parent, const QIcon &imageOn, QColor colorOn, |
| const QIcon &imageOff, QColor colorOff, int flags, |
| bool isNormalIconView = true); |
| |
| |
| SchematicToggle(SchematicNode *parent, const QIcon &imageOn, |
| const QIcon &imageOn2, QColor colorOn, int flags, |
| bool isNormalIconView = true); |
| |
| SchematicToggle(SchematicNode *parent, const QIcon &imageOn, |
| const QIcon &imageOn2, QColor colorOn, const QIcon &imageOff, |
| QColor colorOff, int flags, bool isNormalIconView = true); |
| |
| ~SchematicToggle(); |
| |
| QRectF boundingRect() const override; |
| |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override; |
| |
| |
| void setIsActive(bool value) { m_state = value ? 1 : 0; } |
| |
| |
| void setState(int state) { m_state = state; } |
| |
| void setSize(int width, int height) { |
| m_width = width; |
| m_height = height; |
| update(); |
| } |
| |
| protected: |
| |
| void mousePressEvent(QGraphicsSceneMouseEvent *me) override; |
| void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override; |
| signals: |
| |
| void toggled(bool isChecked); |
| |
| |
| void stateChanged(int state); |
| }; |
| |
| |
| |
| class SchematicToggle_SplineOptions final : public SchematicToggle { |
| Q_OBJECT |
| public: |
| SchematicToggle_SplineOptions(SchematicNode *parent, const QIcon &imageIcon, |
| int flags) |
| : SchematicToggle(parent, imageIcon, QColor(0, 0, 0, 0), flags) {} |
| SchematicToggle_SplineOptions(SchematicNode *parent, const QIcon &imageIcon, |
| const QIcon &imageIcon2, int flags) |
| : SchematicToggle(parent, imageIcon, imageIcon2, QColor(0, 0, 0, 0), |
| flags) {} |
| |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override; |
| |
| protected: |
| void mousePressEvent(QGraphicsSceneMouseEvent *me) override; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class SchematicHandleSpinBox : public QObject, public QGraphicsItem { |
| Q_OBJECT |
| #ifndef MACOSX |
| Q_INTERFACES(QGraphicsItem) |
| #endif |
| |
| protected: |
| Qt::MouseButton m_buttonState; |
| int m_delta; |
| QPixmap m_pixmap; |
| |
| public: |
| SchematicHandleSpinBox(QGraphicsItem *parent); |
| ~SchematicHandleSpinBox(); |
| |
| QRectF boundingRect() const override; |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override; |
| |
| signals: |
| void modifyHandle(int); |
| void changeStatus(); |
| void sceneChanged(); |
| void handleReleased(); |
| |
| protected: |
| void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override; |
| void mousePressEvent(QGraphicsSceneMouseEvent *me) override; |
| void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class SchematicLink : public QObject, public QGraphicsItem { |
| Q_OBJECT |
| Q_INTERFACES(QGraphicsItem) |
| |
| SchematicPort *m_startPort, *m_endPort; |
| QPainterPath m_path, m_hitPath; |
| bool m_lineShaped; |
| bool m_highlighted; |
| |
| public: |
| SchematicLink(QGraphicsItem *parent, QGraphicsScene *scene); |
| ~SchematicLink(); |
| |
| |
| QRectF boundingRect() const override; |
| |
| QPainterPath shape() const override; |
| |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override; |
| |
| |
| |
| |
| |
| |
| void updatePath(const QPointF &startPos, const QPointF &endPos); |
| |
| |
| |
| |
| void updatePath(SchematicPort *startPort, SchematicPort *endPort); |
| void updatePath() { updatePath(m_startPort, m_endPort); } |
| |
| void updateEndPos(const QPointF &endPos); |
| |
| |
| void setStartPort(SchematicPort *startPort) { m_startPort = startPort; } |
| |
| void setEndPort(SchematicPort *endPort) { m_endPort = endPort; } |
| |
| SchematicPort *getStartPort() const { return m_startPort; } |
| |
| SchematicPort *getEndPort() const { return m_endPort; } |
| |
| |
| |
| |
| SchematicPort *getOtherPort(const SchematicPort *port) const; |
| |
| |
| |
| |
| SchematicNode *getOtherNode(const SchematicNode *node) const; |
| |
| |
| bool isLineShaped() { return m_lineShaped; } |
| void setLineShaped(bool value) { m_lineShaped = value; } |
| |
| bool isHighlighted() { return m_highlighted; } |
| void setHighlighted(bool value) { m_highlighted = value; } |
| |
| protected: |
| void mousePressEvent(QGraphicsSceneMouseEvent *me) override; |
| void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override; |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class SchematicPort : public QObject, public QGraphicsItem { |
| Q_OBJECT |
| #ifndef MACOSX |
| Q_INTERFACES(QGraphicsItem) |
| #endif |
| |
| protected: |
| Qt::MouseButton m_buttonState; |
| SchematicNode *m_node; |
| QPointF m_hook; |
| bool m_highlighted; |
| QList<SchematicLink *> m_ghostLinks; |
| SchematicPort *m_linkingTo; |
| QList<SchematicLink *> m_links; |
| int m_type; |
| |
| public: |
| SchematicPort(QGraphicsItem *parent, SchematicNode *node, int type); |
| ~SchematicPort(); |
| |
| SchematicNode *getNode() const { return m_node; } |
| |
| QRectF boundingRect() const override { return QRectF(0, 0, 1, 1); }; |
| |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override{}; |
| |
| |
| void addLink(SchematicLink *link) { m_links.push_back(link); } |
| |
| |
| |
| int getLinkCount() const { return m_links.size(); } |
| |
| |
| void removeLink(SchematicLink *link); |
| |
| |
| void eraseLink(SchematicLink *link); |
| |
| void eraseAllLinks(); |
| |
| |
| |
| |
| SchematicLink *getLink(int index) const { |
| return (index < m_links.size() && index >= 0) ? m_links[index] : 0; |
| } |
| |
| SchematicNode *getLinkedNode(int index) const { |
| return m_links[index] ? m_links[index]->getOtherNode(m_node) : 0; |
| } |
| |
| |
| virtual SchematicLink *makeLink(SchematicPort *port); |
| |
| |
| |
| |
| |
| |
| virtual bool linkTo(SchematicPort *port, bool checkOnly = false) = 0; |
| |
| |
| QPointF getHook() const { return m_hook; } |
| |
| |
| |
| bool isLinkedTo(SchematicPort *port) const; |
| |
| void highLight(bool value) { m_highlighted = value; } |
| bool isHighlighted() const { return m_highlighted; } |
| |
| |
| void updateLinksGeometry(); |
| |
| |
| QPointF getLinkEndPoint() const; |
| |
| |
| |
| int getType() const { return m_type; } |
| |
| void setType(int type) { m_type = type; } |
| |
| protected: |
| void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override; |
| void mousePressEvent(QGraphicsSceneMouseEvent *me) override; |
| void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override; |
| |
| private: |
| virtual SchematicPort *searchPort(const QPointF &scenePos) = 0; |
| |
| |
| |
| virtual void hideSnappedLinks(SchematicPort *linkingPort) = 0; |
| virtual void showSnappedLinks(SchematicPort *linkingPort) = 0; |
| |
| signals: |
| void isClicked(); |
| void isReleased(const QPointF &); |
| void sceneChanged(); |
| void xsheetChanged(); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class SchematicNode : public QObject, public QGraphicsItem { |
| Q_OBJECT |
| #ifndef MACOSX |
| Q_INTERFACES(QGraphicsItem) |
| #endif |
| |
| protected: |
| SchematicScene *m_scene; |
| qreal m_width, m_height; |
| Qt::MouseButton m_buttonState; |
| QMap<int, SchematicPort *> m_ports; |
| |
| public: |
| SchematicNode(SchematicScene *scene); |
| ~SchematicNode(); |
| |
| QRectF boundingRect() const override; |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override; |
| |
| SchematicPort *addPort(int portId, SchematicPort *port); |
| void erasePort(int portId); |
| |
| SchematicPort *getPort(int portId) const; |
| QList<SchematicNode *> getLinkedNodes(int portId) const; |
| |
| virtual void setSchematicNodePos(const QPointF &pos) const = 0; |
| virtual void setPosition(const QPointF &newPos) = 0; |
| |
| void updateLinksGeometry(); |
| virtual void onClicked(){}; |
| |
| protected: |
| void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override; |
| void mousePressEvent(QGraphicsSceneMouseEvent *me) override; |
| void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override; |
| |
| signals: |
| void sceneChanged(); |
| void xsheetChanged(); |
| void nodeChangedSize(); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class SnapTargetItem : public QGraphicsItem { |
| QRectF m_rect; |
| QPointF m_theOtherEndPos, m_portEndOffset; |
| |
| public: |
| SnapTargetItem(const QPointF &pos, const QRectF &rect, |
| const QPointF &theOtherEndPos, const QPointF &portEndOffset); |
| |
| QRectF boundingRect() const override; |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| QWidget *widget = 0) override; |
| }; |
| |
| #endif // SCHEMATICNODE_H |