|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef SCHEMATICNODE_H
|
|
Toshihiro Shimizu |
890ddd |
#define SCHEMATICNODE_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <qgraphicsitem></qgraphicsitem>
|
|
Toshihiro Shimizu |
890ddd |
#include "schematicviewer.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// forward declarations
|
|
Toshihiro Shimizu |
890ddd |
class SchematicPort;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// StageSchematicName.
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class SchematicName final : public QGraphicsTextItem {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Shinya Kitaoka |
120a6e |
double m_width;
|
|
Shinya Kitaoka |
120a6e |
double m_height;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SchematicName(QGraphicsItem *parent, double width, double height);
|
|
Shinya Kitaoka |
120a6e |
~SchematicName();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
bool eventFilter(QObject *object, QEvent *event) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setName(const QString &name);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void focusInEvent(QFocusEvent *fe) override;
|
|
Shinya Kitaoka |
473e70 |
void focusOutEvent(QFocusEvent *fe) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
void keyPressEvent(QKeyEvent *ke) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
signals:
|
|
Shinya Kitaoka |
120a6e |
void focusOut();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected slots:
|
|
Shinya Kitaoka |
120a6e |
void onContentsChanged();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// SchematicThumbnailToggle
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class SchematicThumbnailToggle final : public QObject, public QGraphicsItem {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Shinya Kitaoka |
120a6e |
Q_INTERFACES(QGraphicsItem)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool m_isDown;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SchematicThumbnailToggle(SchematicNode *parent, bool isOpened);
|
|
Shinya Kitaoka |
120a6e |
~SchematicThumbnailToggle();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
QRectF boundingRect() const override;
|
|
Shinya Kitaoka |
120a6e |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
473e70 |
QWidget *widget = 0) override;
|
|
Shinya Kitaoka |
120a6e |
void setIsDown(bool value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
signals:
|
|
Shinya Kitaoka |
120a6e |
void toggled(bool isOpened);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// SchematicToggle
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class SchematicToggle : public QObject, public QGraphicsItem {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Shinya Kitaoka |
120a6e |
Q_INTERFACES(QGraphicsItem)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
manongjohn |
d6e3cc |
QIcon m_imageOn, m_imageOn2, m_imageOff;
|
|
manongjohn |
d6e3cc |
QColor m_colorOn, m_colorOff;
|
|
Shinya Kitaoka |
120a6e |
int m_state;
|
|
Shinya Kitaoka |
120a6e |
int m_flags;
|
|
Shinya Kitaoka |
120a6e |
int m_width, m_height;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
enum { eIsParentColumn = 0x01, eEnableNullState = 0x02 };
|
|
Toshihiro Shimizu |
890ddd |
|
|
manongjohn |
d6e3cc |
SchematicToggle(SchematicNode *parent, const QIcon &imageOn, QColor colorOn,
|
|
manongjohn |
d6e3cc |
int flags, bool isNormalIconView = true);
|
|
manongjohn |
d6e3cc |
|
|
manongjohn |
d6e3cc |
SchematicToggle(SchematicNode *parent, const QIcon &imageOn, QColor colorOn,
|
|
manongjohn |
d6e3cc |
const QIcon &imageOff, QColor colorOff, int flags,
|
|
manongjohn |
d6e3cc |
bool isNormalIconView = true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! the schematic toggle can be a 3-state or a 2-state toggle!
|
|
manongjohn |
d6e3cc |
SchematicToggle(SchematicNode *parent, const QIcon &imageOn,
|
|
manongjohn |
d6e3cc |
const QIcon &imageOn2, QColor colorOn, int flags,
|
|
manongjohn |
d6e3cc |
bool isNormalIconView = true);
|
|
manongjohn |
d6e3cc |
|
|
manongjohn |
d6e3cc |
SchematicToggle(SchematicNode *parent, const QIcon &imageOn,
|
|
manongjohn |
d6e3cc |
const QIcon &imageOn2, QColor colorOn, const QIcon &imageOff,
|
|
manongjohn |
d6e3cc |
QColor colorOff, int flags, bool isNormalIconView = true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
~SchematicToggle();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
QRectF boundingRect() const override;
|
|
Shinya Kitaoka |
120a6e |
// reimplemeted in SchematicToggle_SplineOptions
|
|
Shinya Kitaoka |
473e70 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
38fd86 |
QWidget *widget = 0) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! this is used for a 2-state toggle;
|
|
Shinya Kitaoka |
120a6e |
void setIsActive(bool value) { m_state = value ? 1 : 0; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! this is used for a 3-state toggle;
|
|
Shinya Kitaoka |
120a6e |
void setState(int state) { m_state = state; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setSize(int width, int height) {
|
|
Shinya Kitaoka |
120a6e |
m_width = width;
|
|
Shinya Kitaoka |
120a6e |
m_height = height;
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
// reimplemeted in SchematicToggle_SplineOptions
|
|
Shinya Kitaoka |
473e70 |
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
|
|
Toshihiro Shimizu |
890ddd |
signals:
|
|
Shinya Kitaoka |
120a6e |
//! this is triggered for a 2-state toggle;
|
|
Shinya Kitaoka |
120a6e |
void toggled(bool isChecked);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! this is triggered for a 3-state toggle;
|
|
Shinya Kitaoka |
120a6e |
void stateChanged(int state);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class SchematicToggle_SplineOptions final : public SchematicToggle {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SchematicToggle_SplineOptions(SchematicNode *parent, const QPixmap &pixmap,
|
|
Shinya Kitaoka |
120a6e |
int flags)
|
|
manongjohn |
d6e3cc |
: SchematicToggle(parent, QIcon(pixmap), QColor(0, 0, 0, 0), flags) {}
|
|
Shinya Kitaoka |
120a6e |
SchematicToggle_SplineOptions(SchematicNode *parent, const QPixmap &pixmap1,
|
|
Shinya Kitaoka |
120a6e |
const QPixmap &pixmap2, int flags)
|
|
manongjohn |
d6e3cc |
: SchematicToggle(parent, QIcon(pixmap1), QIcon(pixmap2),
|
|
manongjohn |
d6e3cc |
QColor(0, 0, 0, 0), flags) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
473e70 |
QWidget *widget = 0) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// SchematicHandleSpinBox
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class SchematicHandleSpinBox : public QObject, public QGraphicsItem {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Shinya Kitaoka |
120a6e |
Q_INTERFACES(QGraphicsItem)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
Qt::MouseButton m_buttonState;
|
|
Shinya Kitaoka |
120a6e |
int m_delta;
|
|
Shinya Kitaoka |
120a6e |
QPixmap m_pixmap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SchematicHandleSpinBox(QGraphicsItem *parent);
|
|
Shinya Kitaoka |
120a6e |
~SchematicHandleSpinBox();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
QRectF boundingRect() const override;
|
|
Shinya Kitaoka |
120a6e |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
473e70 |
QWidget *widget = 0) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
signals:
|
|
Shinya Kitaoka |
120a6e |
void modifyHandle(int);
|
|
Shinya Kitaoka |
120a6e |
void changeStatus();
|
|
Shinya Kitaoka |
120a6e |
void sceneChanged();
|
|
Shinya Kitaoka |
120a6e |
void handleReleased();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// class SchematicLink
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
\brief The class provides method to draw links between two SchematicPort
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
A link can has a cubic shape or a line shape and is drawing calling the
|
|
Shinya Kitaoka |
120a6e |
updatePath() method. The class also provides
|
|
Shinya Kitaoka |
120a6e |
methods to retrieve the start SchematicPort and the end SchematicPort of
|
|
Shinya Kitaoka |
120a6e |
the link and a method to remove the
|
|
Shinya Kitaoka |
120a6e |
link from these two SchematicPort.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
\see SchematicPort, SchematicNode.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
class SchematicLink : public QObject, public QGraphicsItem {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *m_startPort, *m_endPort;
|
|
Shinya Kitaoka |
120a6e |
QPainterPath m_path, m_hitPath;
|
|
Shinya Kitaoka |
120a6e |
bool m_lineShaped;
|
|
Shinya Kitaoka |
120a6e |
bool m_highlighted;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SchematicLink(QGraphicsItem *parent, QGraphicsScene *scene);
|
|
Shinya Kitaoka |
120a6e |
~SchematicLink();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Reimplements the pure virtual QGraphicsItem::boundingRect() method.
|
|
Shinya Kitaoka |
473e70 |
QRectF boundingRect() const override;
|
|
Shinya Kitaoka |
120a6e |
//! Reimplements the virtual QGraphicsItem::shape() method.
|
|
Shinya Kitaoka |
473e70 |
QPainterPath shape() const override;
|
|
Shinya Kitaoka |
120a6e |
//! Reimplements the pure virtual QGraphicsItem::paint() method.
|
|
Shinya Kitaoka |
120a6e |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
473e70 |
QWidget *widget = 0) override;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*! Update the link path.\n
|
|
Shinya Kitaoka |
120a6e |
The link is has a cubic shape starting from \b startPos and ending to \b
|
|
Shinya Kitaoka |
120a6e |
endPos.
|
|
Shinya Kitaoka |
120a6e |
If a link path already exists, the path is updating otherwise a path is
|
|
Shinya Kitaoka |
120a6e |
created.*/
|
|
Shinya Kitaoka |
120a6e |
void updatePath(const QPointF &startPos, const QPointF &endPos);
|
|
Shinya Kitaoka |
120a6e |
//! Update the link path.\n
|
|
Shinya Kitaoka |
120a6e |
//! Call the updatePath(const QPointF &startPos, const QPointF &endPos)
|
|
Shinya Kitaoka |
120a6e |
//! method. The \b start pos and the \b endPos
|
|
Shinya Kitaoka |
120a6e |
//! are taken from the the given \b startPort and \b endPort.
|
|
Shinya Kitaoka |
120a6e |
void updatePath(SchematicPort *startPort, SchematicPort *endPort);
|
|
Shinya Kitaoka |
120a6e |
void updatePath() { updatePath(m_startPort, m_endPort); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Sets the start SchematicPort of the link to \b startPort.
|
|
Shinya Kitaoka |
120a6e |
void setStartPort(SchematicPort *startPort) { m_startPort = startPort; }
|
|
Shinya Kitaoka |
120a6e |
//! Sets the start SchematicPort of the link to \b startPort.
|
|
Shinya Kitaoka |
120a6e |
void setEndPort(SchematicPort *endPort) { m_endPort = endPort; }
|
|
Shinya Kitaoka |
120a6e |
//! Returns the start SchematicPort of the link.
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *getStartPort() const { return m_startPort; }
|
|
Shinya Kitaoka |
120a6e |
//! Returns the end SchematicPort of the link.
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *getEndPort() const { return m_endPort; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*! Returns the other SchematicPort linked to the specified \b port.\n
|
|
Shinya Kitaoka |
120a6e |
Returns 0 if \b port isn't neither the start SchematicPort eihter the end
|
|
Shinya Kitaoka |
120a6e |
SchematicPort of this link.*/
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *getOtherPort(const SchematicPort *port) const;
|
|
Shinya Kitaoka |
120a6e |
/*! Returns the other SchematicNode linked to the specified \b node.\n
|
|
Shinya Kitaoka |
120a6e |
Returns 0 if \b node isn't neither the parent node of the start
|
|
Shinya Kitaoka |
120a6e |
SchematicPort
|
|
Shinya Kitaoka |
120a6e |
eihter the parent node of the end SchematicPort of the link.*/
|
|
Shinya Kitaoka |
120a6e |
SchematicNode *getOtherNode(const SchematicNode *node) const;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Returns true if the link is line shaped.
|
|
Shinya Kitaoka |
120a6e |
bool isLineShaped() { return m_lineShaped; }
|
|
Shinya Kitaoka |
120a6e |
void setLineShaped(bool value) { m_lineShaped = value; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool isHighlighted() { return m_highlighted; }
|
|
Shinya Kitaoka |
120a6e |
void setHighlighted(bool value) { m_highlighted = value; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// class SchematicPort
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Shinya Kitaoka |
120a6e |
\brief The class provides method to draw and andle a SchematicPort.
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
A SchematicPort is a child af a SchematicNode and is used to link a
|
|
Shinya Kitaoka |
120a6e |
parent node to other nodes. It can be an input port,
|
|
Shinya Kitaoka |
120a6e |
or better , a port used to accept link coming from other node. A port
|
|
Shinya Kitaoka |
120a6e |
that isn't an input port cannot accept
|
|
Shinya Kitaoka |
120a6e |
links but can begin to draw links.\n
|
|
Shinya Kitaoka |
120a6e |
A SchematicPort has got a hook thet is a position where links starts or
|
|
Shinya Kitaoka |
120a6e |
ends.\n
|
|
Shinya Kitaoka |
120a6e |
A SchematicPort can be linked to an arbitriary number of links.
|
|
Shinya Kitaoka |
120a6e |
A SchematicPort handles a container of all links to retrieve all linked
|
|
Shinya Kitaoka |
120a6e |
node; each link is indexed using a
|
|
Shinya Kitaoka |
120a6e |
progressive number assigned when the link is inserted to the container.
|
|
Shinya Kitaoka |
120a6e |
\see SchematicNode, SchematicLink.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
class SchematicPort : public QObject, public QGraphicsItem {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Shinya Kitaoka |
120a6e |
Q_INTERFACES(QGraphicsItem)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
Qt::MouseButton m_buttonState;
|
|
Shinya Kitaoka |
120a6e |
SchematicNode *m_node;
|
|
Shinya Kitaoka |
120a6e |
QPointF m_hook;
|
|
Shinya Kitaoka |
120a6e |
bool m_highlighted;
|
|
Shinya Kitaoka |
120a6e |
SchematicLink *m_ghostLink;
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *m_linkingTo;
|
|
Shinya Kitaoka |
120a6e |
QList<schematiclink *=""> m_links;</schematiclink>
|
|
Shinya Kitaoka |
120a6e |
int m_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SchematicPort(QGraphicsItem *parent, SchematicNode *node, int type);
|
|
Shinya Kitaoka |
120a6e |
~SchematicPort();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SchematicNode *getNode() const { return m_node; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QRectF boundingRect() const override { return QRectF(0, 0, 1, 1); };
|
|
Shinya Kitaoka |
473e70 |
|
|
Shinya Kitaoka |
473e70 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
38fd86 |
QWidget *widget = 0) override{};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Add the \b link to the links container.
|
|
Shinya Kitaoka |
120a6e |
void addLink(SchematicLink *link) { m_links.push_back(link); }
|
|
Shinya Kitaoka |
120a6e |
//! Returns the number of the link contained in the links container or, it is
|
|
Shinya Kitaoka |
120a6e |
//! the same, the number of nodes
|
|
Shinya Kitaoka |
120a6e |
//! linked to this SchematicPort
|
|
Shinya Kitaoka |
120a6e |
int getLinkCount() const { return m_links.size(); }
|
|
Shinya Kitaoka |
120a6e |
//! Removes the link form the links container.\n
|
|
Shinya Kitaoka |
120a6e |
//! It doesn't remove the link from the scene and it doesn't delete the link!
|
|
Shinya Kitaoka |
120a6e |
void removeLink(SchematicLink *link);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Removes \b link from the scene and the m_links list; delete it .
|
|
Shinya Kitaoka |
120a6e |
void eraseLink(SchematicLink *link);
|
|
Shinya Kitaoka |
120a6e |
//! Removes all links from the scene and the m_links list; delete them .
|
|
Shinya Kitaoka |
120a6e |
void eraseAllLinks();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Returns the link indexed with \b index.\n
|
|
Shinya Kitaoka |
120a6e |
//!\note A link is indexed with a progressive number when is inserted in the
|
|
Shinya Kitaoka |
38fd86 |
//! container.
|
|
Shinya Kitaoka |
120a6e |
SchematicLink *getLink(int index) const {
|
|
Shinya Kitaoka |
120a6e |
return (index < m_links.size() && index >= 0) ? m_links[index] : 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
//! Returns the node linked with the link \b index.
|
|
Shinya Kitaoka |
120a6e |
SchematicNode *getLinkedNode(int index) const {
|
|
Shinya Kitaoka |
120a6e |
return m_links[index] ? m_links[index]->getOtherNode(m_node) : 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Make a link from this port to the given port.
|
|
Shinya Kitaoka |
120a6e |
virtual SchematicLink *makeLink(SchematicPort *port);
|
|
Shinya Kitaoka |
120a6e |
//! Check and make a connection between the data Objects.
|
|
Shinya Kitaoka |
120a6e |
//! Returns true if it is possible to have a connection between the data
|
|
Shinya Kitaoka |
120a6e |
//! Object represented by this SchematicPort
|
|
Shinya Kitaoka |
120a6e |
//! and that represented by \b port. If check only is false no connections is
|
|
Shinya Kitaoka |
120a6e |
//! created!
|
|
Shinya Kitaoka |
120a6e |
//! \see TFxPort, TStageObject.
|
|
Shinya Kitaoka |
120a6e |
virtual bool linkTo(SchematicPort *port, bool checkOnly = false) = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// !Return the hook poeistion of the port.
|
|
Shinya Kitaoka |
120a6e |
QPointF getHook() const { return m_hook; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Returns true if this SchematicPort is linked to \b port. Otherwise returns
|
|
Shinya Kitaoka |
120a6e |
//! false.
|
|
Shinya Kitaoka |
120a6e |
bool isLinkedTo(SchematicPort *port) const;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void highLight(bool value) { m_highlighted = value; }
|
|
Shinya Kitaoka |
120a6e |
bool isHighlighted() const { return m_highlighted; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Updates all links of the ports.
|
|
Shinya Kitaoka |
120a6e |
void updateLinksGeometry();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Returns the scene position of the link end
|
|
Shinya Kitaoka |
120a6e |
QPointF getLinkEndPoint() const;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//! Returns the type of the port. \see eFxSchematicPortType,
|
|
Shinya Kitaoka |
120a6e |
//! eStageSchematicPortType
|
|
Shinya Kitaoka |
120a6e |
int getType() const { return m_type; }
|
|
Shinya Kitaoka |
120a6e |
//! Set the type of the port.
|
|
Shinya Kitaoka |
120a6e |
void setType(int type) { m_type = type; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
virtual SchematicPort *searchPort(const QPointF &scenePos) = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void hideSnappedLinks() = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void showSnappedLinks() = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
signals:
|
|
Shinya Kitaoka |
120a6e |
void isClicked();
|
|
Shinya Kitaoka |
120a6e |
void isReleased(const QPointF &);
|
|
Shinya Kitaoka |
120a6e |
void sceneChanged();
|
|
Shinya Kitaoka |
120a6e |
void xsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// class SchematicNode
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class SchematicNode : public QObject, public QGraphicsItem {
|
|
Shinya Kitaoka |
120a6e |
Q_OBJECT
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MACOSX
|
|
Shinya Kitaoka |
120a6e |
Q_INTERFACES(QGraphicsItem)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
120a6e |
SchematicScene *m_scene;
|
|
Shinya Kitaoka |
120a6e |
qreal m_width, m_height;
|
|
Shinya Kitaoka |
120a6e |
Qt::MouseButton m_buttonState;
|
|
Shinya Kitaoka |
120a6e |
QMap<int, *="" schematicport=""> m_ports;</int,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
SchematicNode(SchematicScene *scene);
|
|
Shinya Kitaoka |
120a6e |
~SchematicNode();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
473e70 |
QRectF boundingRect() const override;
|
|
Shinya Kitaoka |
120a6e |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
473e70 |
QWidget *widget = 0) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *addPort(int portId, SchematicPort *port);
|
|
Shinya Kitaoka |
120a6e |
void erasePort(int portId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *getPort(int portId) const;
|
|
Shinya Kitaoka |
120a6e |
QList<schematicnode *=""> getLinkedNodes(int portId) const;</schematicnode>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
virtual void setSchematicNodePos(const QPointF &pos) const = 0;
|
|
Shinya Kitaoka |
120a6e |
virtual void setPosition(const QPointF &newPos) = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void updateLinksGeometry();
|
|
Shinya Kitaoka |
120a6e |
virtual void onClicked(){};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
protected:
|
|
Shinya Kitaoka |
473e70 |
void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Shinya Kitaoka |
473e70 |
void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
signals:
|
|
Shinya Kitaoka |
120a6e |
void sceneChanged();
|
|
Shinya Kitaoka |
120a6e |
void xsheetChanged();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // SCHEMATICNODE_H
|