| #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; |
| |
| public: |
| SchematicName(QGraphicsItem *parent, double width, double height); |
| ~SchematicName(); |
| |
| bool eventFilter(QObject *object, QEvent *event) override; |
| |
| void setName(const QString &name); |
| |
| protected: |
| void focusInEvent(QFocusEvent *fe) override; |
| void focusOutEvent(QFocusEvent *fe) override; |
| |
| void keyPressEvent(QKeyEvent *ke) override; |
| |
| signals: |
| void focusOut(); |
| |
| protected slots: |
| void onContentsChanged(); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| 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: |
| QPixmap m_pixmap1, m_pixmap2; |
| int m_state; |
| int m_flags; |
| int m_width, m_height; |
| |
| public: |
| enum { eIsParentColumn = 0x01, eEnableNullState = 0x02 }; |
| |
| SchematicToggle(SchematicNode *parent, const QPixmap &pixmap, int flags, |
| bool isLargeScaled = true); |
| |
| |
| SchematicToggle(SchematicNode *parent, const QPixmap &pixmap1, |
| const QPixmap &pixmap2, int flags, bool isLargeScaled = 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 QPixmap &pixmap, |
| int flags) |
| : SchematicToggle(parent, pixmap, flags) {} |
| SchematicToggle_SplineOptions(SchematicNode *parent, const QPixmap &pixmap1, |
| const QPixmap &pixmap2, int flags) |
| : SchematicToggle(parent, pixmap1, pixmap2, 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 |
| 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 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; |
| SchematicLink *m_ghostLink; |
| 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() = 0; |
| virtual void showSnappedLinks() = 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(); |
| }; |
| |
| #endif |