|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/schematicnode.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <qgraphicsscenemouseevent></qgraphicsscenemouseevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <qstyleoptiongraphicsitem></qstyleoptiongraphicsitem>
|
|
Toshihiro Shimizu |
890ddd |
#include <qkeyevent></qkeyevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <algorithm></algorithm>
|
|
Toshihiro Shimizu |
890ddd |
#include <qapplication></qapplication>
|
|
Toshihiro Shimizu |
890ddd |
#include <qtextdocument></qtextdocument>
|
|
Toshihiro Shimizu |
890ddd |
#include <qtextcursor></qtextcursor>
|
|
Toshihiro Shimizu |
890ddd |
#include <qtextblock></qtextblock>
|
|
Toshihiro Shimizu |
890ddd |
#include <qmenubar></qmenubar>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpolygonf></qpolygonf>
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/menubarcommand.h"
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// StageSchematicName
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
SchematicName::SchematicName(QGraphicsItem *parent, double width, double height)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsTextItem("", parent), m_width(width), m_height(height) {
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsFocusable, true);
|
|
Shinya Kitaoka |
120a6e |
setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
connect(document(), SIGNAL(contentsChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onContentsChanged()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicName::~SchematicName() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicName::setName(const QString &name) { setPlainText(name); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicName::onContentsChanged() {
|
|
Shinya Kitaoka |
120a6e |
QString text = document()->toPlainText();
|
|
Shinya Kitaoka |
120a6e |
QTextCursor cursor = textCursor();
|
|
Shinya Kitaoka |
120a6e |
int position = cursor.position();
|
|
Shinya Kitaoka |
120a6e |
if (position > 0 && text.at(position - 1) == '\n') {
|
|
Shinya Kitaoka |
120a6e |
text.remove("\n");
|
|
Shinya Kitaoka |
120a6e |
setPlainText(text);
|
|
Shinya Kitaoka |
120a6e |
;
|
|
Shinya Kitaoka |
120a6e |
emit focusOut();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicName::focusOutEvent(QFocusEvent *fe) {
|
|
Shinya Kitaoka |
120a6e |
qApp->removeEventFilter(this);
|
|
Shinya Kitaoka |
120a6e |
if (fe->reason() == Qt::MouseFocusReason) emit focusOut();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicName::keyPressEvent(QKeyEvent *ke) {
|
|
Shinya Kitaoka |
120a6e |
if (ke->key() == Qt::Key_Left || ke->key() == Qt::Key_Right) {
|
|
Shinya Kitaoka |
120a6e |
QTextCursor cursor = textCursor();
|
|
Shinya Kitaoka |
120a6e |
int currentPos = cursor.position();
|
|
Shinya Kitaoka |
120a6e |
if (ke->key() == Qt::Key_Left)
|
|
Shinya Kitaoka |
120a6e |
cursor.setPosition(currentPos - 1);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
cursor.setPosition(currentPos + 1);
|
|
Shinya Kitaoka |
120a6e |
setTextCursor(cursor);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
QGraphicsTextItem::keyPressEvent(ke);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool SchematicName::eventFilter(QObject *object, QEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (event->type() == QEvent::Shortcut ||
|
|
Shinya Kitaoka |
120a6e |
event->type() == QEvent::ShortcutOverride) {
|
|
Shinya Kitaoka |
120a6e |
if (!object->inherits("QGraphicsView")) {
|
|
Shinya Kitaoka |
120a6e |
event->accept();
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicName::focusInEvent(QFocusEvent *fe) {
|
|
Shinya Kitaoka |
120a6e |
QGraphicsTextItem::focusInEvent(fe);
|
|
Shinya Kitaoka |
120a6e |
qApp->installEventFilter(this);
|
|
Shinya Kitaoka |
120a6e |
QTextDocument *doc = document();
|
|
Shinya Kitaoka |
120a6e |
QTextCursor cursor(doc->begin());
|
|
Shinya Kitaoka |
120a6e |
cursor.select(QTextCursor::Document);
|
|
Shinya Kitaoka |
120a6e |
setTextCursor(cursor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// class SchematicThumbnailToggle
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicThumbnailToggle::SchematicThumbnailToggle(SchematicNode *parent,
|
|
Shinya Kitaoka |
120a6e |
bool isOpened)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent), m_isDown(!isOpened) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicThumbnailToggle::~SchematicThumbnailToggle() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QRectF SchematicThumbnailToggle::boundingRect() const {
|
|
Shinya Kitaoka |
120a6e |
return QRectF(0, 0, 14, 14);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicThumbnailToggle::paint(QPainter *painter,
|
|
Shinya Kitaoka |
120a6e |
const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
120a6e |
QWidget *widget) {
|
|
Shinya Kitaoka |
120a6e |
QPixmap onPixmap(":Resources/schematic_thumbtoggle_on.png");
|
|
Shinya Kitaoka |
120a6e |
QPixmap offPixmap(":Resources/schematic_thumbtoggle_off.png");
|
|
Shinya Kitaoka |
120a6e |
QRect rect(3, 3, 8, 8);
|
|
Shinya Kitaoka |
120a6e |
if (m_isDown) {
|
|
Shinya Kitaoka |
120a6e |
painter->drawPixmap(rect, offPixmap);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
painter->drawPixmap(rect, onPixmap);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicThumbnailToggle::setIsDown(bool value) {
|
|
Shinya Kitaoka |
120a6e |
m_isDown = value;
|
|
Shinya Kitaoka |
120a6e |
emit(toggled(!m_isDown));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicThumbnailToggle::mousePressEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
m_isDown = !m_isDown;
|
|
Shinya Kitaoka |
120a6e |
emit(toggled(!m_isDown));
|
|
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 |
SchematicToggle::SchematicToggle(SchematicNode *parent, const QPixmap &pixmap,
|
|
Shinya Kitaoka |
120a6e |
int flags, bool isLargeScaled)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_pixmap1(pixmap)
|
|
Shinya Kitaoka |
120a6e |
, m_pixmap2()
|
|
Shinya Kitaoka |
120a6e |
, m_state(0)
|
|
Shinya Kitaoka |
120a6e |
, m_flags(flags)
|
|
Shinya Kitaoka |
120a6e |
, m_width(isLargeScaled ? 18 : 30)
|
|
Shinya Kitaoka |
120a6e |
, m_height(isLargeScaled ? 7 : 5) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SchematicToggle::SchematicToggle(SchematicNode *parent, const QPixmap &pixmap1,
|
|
Shinya Kitaoka |
120a6e |
const QPixmap &pixmap2, int flags,
|
|
Shinya Kitaoka |
120a6e |
bool isLargeScaled)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_pixmap1(pixmap1)
|
|
Shinya Kitaoka |
120a6e |
, m_pixmap2(pixmap2)
|
|
Shinya Kitaoka |
120a6e |
, m_state(0)
|
|
Shinya Kitaoka |
120a6e |
, m_flags(flags)
|
|
Shinya Kitaoka |
120a6e |
, m_width(isLargeScaled ? 18 : 30)
|
|
Shinya Kitaoka |
120a6e |
, m_height(isLargeScaled ? 7 : 5) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SchematicToggle::~SchematicToggle() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QRectF SchematicToggle::boundingRect() const {
|
|
Shinya Kitaoka |
120a6e |
return QRectF(0, 0, m_width, m_height);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void SchematicToggle::paint(QPainter *painter,
|
|
Shinya Kitaoka |
120a6e |
const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
120a6e |
QWidget *widget) {
|
|
Shinya Kitaoka |
120a6e |
if (m_state != 0) {
|
|
Shinya Kitaoka |
120a6e |
QPixmap &pix =
|
|
Shinya Kitaoka |
120a6e |
(m_state == 2 && !m_pixmap2.isNull()) ? m_pixmap2 : m_pixmap1;
|
|
Shinya Kitaoka |
120a6e |
painter->drawPixmap(boundingRect().toRect(), pix);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void SchematicToggle::mousePressEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (me->button() == Qt::LeftButton) {
|
|
Shinya Kitaoka |
120a6e |
if (m_pixmap2.isNull()) {
|
|
Shinya Kitaoka |
120a6e |
m_state = 1 - m_state;
|
|
Shinya Kitaoka |
120a6e |
emit(toggled(m_state != 0));
|
|
Shinya Kitaoka |
120a6e |
} else if (m_flags & eEnableNullState) {
|
|
Shinya Kitaoka |
120a6e |
m_state = (m_state + 1) % 3;
|
|
Shinya Kitaoka |
120a6e |
emit(stateChanged(m_state));
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_state = 3 - m_state;
|
|
Shinya Kitaoka |
120a6e |
emit(stateChanged(m_state));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (me->button() == Qt::RightButton) {
|
|
Shinya Kitaoka |
120a6e |
SchematicNode *parent = dynamic_cast<schematicnode *="">(this->parentItem());</schematicnode>
|
|
Shinya Kitaoka |
120a6e |
if (parent) parent->onClicked();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void SchematicToggle::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
|
|
Shinya Kitaoka |
120a6e |
if (!(m_flags & eIsParentColumn)) return;
|
|
Shinya Kitaoka |
120a6e |
if (m_pixmap2.isNull()) {
|
|
Shinya Kitaoka |
120a6e |
QMenu *menu = new QMenu(0);
|
|
Shinya Kitaoka |
120a6e |
CommandManager *cmdManager = CommandManager::instance();
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_EnableThisColumnOnly"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_EnableSelectedColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_EnableAllColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_DisableAllColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_DisableSelectedColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_SwapEnabledColumns"));
|
|
Shinya Kitaoka |
120a6e |
QAction *action = menu->exec(cme->screenPos());
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
QMenu *menu = new QMenu(0);
|
|
Shinya Kitaoka |
120a6e |
CommandManager *cmdManager = CommandManager::instance();
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_ActivateThisColumnOnly"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_ActivateSelectedColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_ActivateAllColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_DeactivateAllColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_DeactivateSelectedColumns"));
|
|
Shinya Kitaoka |
120a6e |
menu->addAction(cmdManager->getAction("MI_ToggleColumnsActivation"));
|
|
Shinya Kitaoka |
120a6e |
QAction *action = menu->exec(cme->screenPos());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! for Spline Aim and CP toggles
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void SchematicToggle_SplineOptions::paint(
|
|
Shinya Kitaoka |
120a6e |
QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
120a6e |
QWidget *widget) {
|
|
Shinya Kitaoka |
120a6e |
QRectF rect = boundingRect();
|
|
Shinya Kitaoka |
120a6e |
painter->fillRect(rect, Qt::white);
|
|
Shinya Kitaoka |
120a6e |
if (m_state != 0) {
|
|
Shinya Kitaoka |
120a6e |
QPixmap &pix =
|
|
Shinya Kitaoka |
120a6e |
(m_state == 2 && !m_pixmap2.isNull()) ? m_pixmap2 : m_pixmap1;
|
|
Shinya Kitaoka |
120a6e |
painter->drawPixmap(boundingRect().toRect(), pix);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
painter->setBrush(Qt::NoBrush);
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(QColor(180, 180, 180, 255));
|
|
Shinya Kitaoka |
120a6e |
painter->drawRect(rect);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! for Spline Aim and CP toggles
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void SchematicToggle_SplineOptions::mousePressEvent(
|
|
Shinya Kitaoka |
120a6e |
QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
SchematicToggle::mousePressEvent(me);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
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 |
|
|
Toshihiro Shimizu |
890ddd |
SchematicHandleSpinBox::SchematicHandleSpinBox(QGraphicsItem *parent)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent), m_buttonState(Qt::NoButton), m_delta(0) {
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
|
Shinya Kitaoka |
120a6e |
m_pixmap = QPixmap(":Resources/schematic_spin_arrows.svg");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicHandleSpinBox::~SchematicHandleSpinBox() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QRectF SchematicHandleSpinBox::boundingRect() const {
|
|
Shinya Kitaoka |
120a6e |
return QRectF(0, 0, 10, 10);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void SchematicHandleSpinBox::paint(QPainter *painter,
|
|
Shinya Kitaoka |
120a6e |
const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
120a6e |
QWidget *widget) {
|
|
Shinya Kitaoka |
120a6e |
QRectF rect = boundingRect();
|
|
Shinya Kitaoka |
120a6e |
painter->drawPixmap(rect.toRect(), m_pixmap);
|
|
Shinya Kitaoka |
120a6e |
painter->setBrush(QColor(0, 0, 0, 0));
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(QColor(128, 128, 128, 255));
|
|
Shinya Kitaoka |
120a6e |
painter->drawRect(rect);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicHandleSpinBox::mouseMoveEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (m_buttonState == Qt::LeftButton) {
|
|
Shinya Kitaoka |
120a6e |
bool increase = false;
|
|
Shinya Kitaoka |
120a6e |
int delta = me->screenPos().y() - me->lastScreenPos().y();
|
|
Shinya Kitaoka |
120a6e |
if (delta < 0) increase = true;
|
|
Shinya Kitaoka |
120a6e |
m_delta += abs(delta);
|
|
Shinya Kitaoka |
120a6e |
if (m_delta > 5) {
|
|
Shinya Kitaoka |
120a6e |
if (increase)
|
|
Shinya Kitaoka |
120a6e |
emit(modifyHandle(1));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
emit(modifyHandle(-1));
|
|
Shinya Kitaoka |
120a6e |
m_delta = 0;
|
|
Shinya Kitaoka |
120a6e |
emit sceneChanged();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicHandleSpinBox::mousePressEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
m_buttonState = me->button();
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->beginBlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicHandleSpinBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
m_buttonState = Qt::NoButton;
|
|
Shinya Kitaoka |
120a6e |
m_delta = 0;
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->endBlock();
|
|
Shinya Kitaoka |
120a6e |
emit handleReleased();
|
|
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 |
SchematicLink::SchematicLink(QGraphicsItem *parent, QGraphicsScene *scene)
|
|
Toshihiro Shimizu |
890ddd |
#if QT_VERSION >= 0x050000
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent)
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent, scene)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
, m_startPort(0)
|
|
Shinya Kitaoka |
120a6e |
, m_endPort(0)
|
|
Shinya Kitaoka |
120a6e |
, m_path()
|
|
Shinya Kitaoka |
120a6e |
, m_hitPath()
|
|
Shinya Kitaoka |
120a6e |
, m_lineShaped(false)
|
|
Shinya Kitaoka |
120a6e |
, m_highlighted(false) {
|
|
Toshihiro Shimizu |
890ddd |
#if QT_VERSION >= 0x050000
|
|
Shinya Kitaoka |
120a6e |
scene->addItem(this);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsMovable, false);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
|
Shinya Kitaoka |
120a6e |
setZValue(0.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicLink::~SchematicLink() { m_startPort = m_endPort = 0; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QRectF SchematicLink::boundingRect() const {
|
|
Shinya Kitaoka |
120a6e |
return m_hitPath.boundingRect().adjusted(-5, -5, 5, 5);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QPainterPath SchematicLink::shape() const { return m_hitPath; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicLink::paint(QPainter *painter,
|
|
Shinya Kitaoka |
120a6e |
const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
120a6e |
QWidget *widget) {
|
|
Shinya Kitaoka |
120a6e |
if (getStartPort() && (getStartPort()->getType() == 100 // eStageSplinePort
|
|
Shinya Kitaoka |
120a6e |
|| getStartPort()->getType() == 202)) { // eFxLinkPort
|
|
Shinya Kitaoka |
120a6e |
if (isSelected() || isHighlighted())
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(QColor(255, 255, 10));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(QColor(50, 255, 50, 128));
|
|
Shinya Kitaoka |
120a6e |
} else if (isSelected() || isHighlighted())
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(QPen(Qt::cyan));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
else if (!m_lineShaped)
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(QPen(Qt::white));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(QPen(QColor(170, 170, 10), 0, Qt::DashLine));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
Shinya Kitaoka |
120a6e |
painter->drawPath(m_path);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicLink::updatePath(const QPointF &startPos, const QPointF &endPos) {
|
|
Shinya Kitaoka |
120a6e |
prepareGeometryChange();
|
|
Shinya Kitaoka |
120a6e |
setPos(startPos);
|
|
Shinya Kitaoka |
120a6e |
if (!m_lineShaped) {
|
|
Shinya Kitaoka |
120a6e |
QPointF p0((endPos.x() - startPos.x()) * 0.5, 0);
|
|
Shinya Kitaoka |
120a6e |
QPointF p1(p0.x(), endPos.y() - startPos.y());
|
|
Shinya Kitaoka |
120a6e |
QPointF p2(endPos - startPos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_path = QPainterPath(QPointF(0, 0));
|
|
Shinya Kitaoka |
120a6e |
m_path.cubicTo(p0, p1, p2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QPointF h(0, 5);
|
|
Shinya Kitaoka |
120a6e |
QPointF p = h;
|
|
Shinya Kitaoka |
120a6e |
if (p2.y() > 0)
|
|
Shinya Kitaoka |
120a6e |
p.setX(p2.x() > 0 ? -5 : 5);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
p.setX(p2.x() > 0 ? 5 : -5);
|
|
Shinya Kitaoka |
120a6e |
m_hitPath = QPainterPath(QPointF(0, 0));
|
|
Shinya Kitaoka |
120a6e |
m_hitPath.lineTo(h);
|
|
Shinya Kitaoka |
120a6e |
m_hitPath.cubicTo(p0 + p, p1 + p, p2 + h);
|
|
Shinya Kitaoka |
120a6e |
m_hitPath.lineTo(p2 - h);
|
|
Shinya Kitaoka |
120a6e |
m_hitPath.cubicTo(p1 - p, p0 - p, -h);
|
|
Shinya Kitaoka |
120a6e |
m_hitPath.lineTo(0, 0);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_path = QPainterPath(QPointF(0, 0));
|
|
Shinya Kitaoka |
120a6e |
m_path.lineTo(endPos - startPos);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_hitPath = QPainterPath(QPointF(0, 0));
|
|
Shinya Kitaoka |
120a6e |
m_hitPath.lineTo(endPos - startPos);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicLink::updatePath(SchematicPort *startPort,
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *endPort) {
|
|
Shinya Kitaoka |
120a6e |
updatePath(startPort->getLinkEndPoint(), endPort->getLinkEndPoint());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *SchematicLink::getOtherPort(const SchematicPort *port) const {
|
|
Shinya Kitaoka |
120a6e |
if (port == m_startPort)
|
|
Shinya Kitaoka |
120a6e |
return m_endPort;
|
|
Shinya Kitaoka |
120a6e |
else if (port == m_endPort)
|
|
Shinya Kitaoka |
120a6e |
return m_startPort;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicNode *SchematicLink::getOtherNode(const SchematicNode *node) const {
|
|
Shinya Kitaoka |
120a6e |
if (node == m_startPort->getNode())
|
|
Shinya Kitaoka |
120a6e |
return m_endPort->getNode();
|
|
Shinya Kitaoka |
120a6e |
else if (node == m_endPort->getNode())
|
|
Shinya Kitaoka |
120a6e |
return m_startPort->getNode();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicLink::mousePressEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
QPointF pos = me->scenePos();
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *startPort = getStartPort();
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *endPort = getEndPort();
|
|
Shinya Kitaoka |
120a6e |
if (startPort && endPort) {
|
|
Shinya Kitaoka |
120a6e |
QRectF startRect = startPort->boundingRect();
|
|
Shinya Kitaoka |
120a6e |
startRect.moveTopLeft(startPort->scenePos());
|
|
Shinya Kitaoka |
120a6e |
QRectF endRect = endPort->boundingRect();
|
|
Shinya Kitaoka |
120a6e |
endRect.moveTopLeft(endPort->scenePos());
|
|
Shinya Kitaoka |
120a6e |
if (startRect.contains(pos) || endRect.contains(pos)) {
|
|
Shinya Kitaoka |
120a6e |
me->ignore();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QMatrix matrix = scene()->views()[0]->matrix();
|
|
Toshihiro Shimizu |
890ddd |
#if QT_VERSION >= 0x050000
|
|
Shinya Kitaoka |
120a6e |
double scaleFactor = sqrt(matrix.determinant());
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
double scaleFactor = sqrt(matrix.det());
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QPointF startPos = getStartPort()->getLinkEndPoint();
|
|
Shinya Kitaoka |
120a6e |
QPointF endPos = getEndPort()->getLinkEndPoint();
|
|
Shinya Kitaoka |
120a6e |
QPointF p0((endPos.x() - startPos.x()) * 0.5, 0);
|
|
Shinya Kitaoka |
120a6e |
QPointF p1(p0.x(), endPos.y() - startPos.y());
|
|
Shinya Kitaoka |
120a6e |
QPointF p2(endPos - startPos);
|
|
Campbell Barton |
f49389 |
double sensitivity = 5 / scaleFactor;
|
|
Campbell Barton |
f49389 |
QPointF h(0, sensitivity);
|
|
Shinya Kitaoka |
120a6e |
QPointF p = h;
|
|
Shinya Kitaoka |
120a6e |
if (p2.y() > 0)
|
|
Campbell Barton |
f49389 |
p.setX(p2.x() > 0 ? -sensitivity : sensitivity);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Campbell Barton |
f49389 |
p.setX(p2.x() > 0 ? sensitivity : -sensitivity);
|
|
Shinya Kitaoka |
120a6e |
QPainterPath path(QPointF(0, 0));
|
|
Shinya Kitaoka |
120a6e |
path.lineTo(h);
|
|
Shinya Kitaoka |
120a6e |
path.cubicTo(p0 + p, p1 + p, p2 + h);
|
|
Shinya Kitaoka |
120a6e |
path.lineTo(p2 - h);
|
|
Shinya Kitaoka |
120a6e |
path.cubicTo(p1 - p, p0 - p, -h);
|
|
Shinya Kitaoka |
120a6e |
path.lineTo(0, 0);
|
|
Shinya Kitaoka |
120a6e |
if (!path.contains(me->scenePos() - scenePos())) {
|
|
Shinya Kitaoka |
120a6e |
me->ignore();
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!isSelected()) {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() != Qt::ControlModifier) scene()->clearSelection();
|
|
Shinya Kitaoka |
120a6e |
if (me->button() == Qt::LeftButton || me->button() == Qt::RightButton)
|
|
Shinya Kitaoka |
120a6e |
setSelected(true);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() == Qt::ControlModifier &&
|
|
Shinya Kitaoka |
120a6e |
me->button() == Qt::LeftButton)
|
|
Shinya Kitaoka |
120a6e |
setSelected(false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void SchematicLink::mouseReleaseEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() != Qt::ControlModifier && me->button() != Qt::RightButton)
|
|
Shinya Kitaoka |
120a6e |
QGraphicsItem::mouseReleaseEvent(me);
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
SchematicPort::SchematicPort(QGraphicsItem *parent, SchematicNode *node,
|
|
Shinya Kitaoka |
120a6e |
int type)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_node(node)
|
|
Shinya Kitaoka |
120a6e |
, m_buttonState(Qt::NoButton)
|
|
Shinya Kitaoka |
120a6e |
, m_highlighted(false)
|
|
Shinya Kitaoka |
120a6e |
, m_ghostLink(0)
|
|
Shinya Kitaoka |
120a6e |
, m_linkingTo(0)
|
|
Shinya Kitaoka |
120a6e |
, m_hook(0, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_type(type) {
|
|
Toshihiro Shimizu |
890ddd |
#if QT_VERSION >= 0x050000
|
|
Shinya Kitaoka |
120a6e |
setAcceptHoverEvents(false);
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
setAcceptsHoverEvents(false);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
SchematicPort::~SchematicPort() { m_links.clear(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void SchematicPort::mouseMoveEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (m_buttonState != Qt::LeftButton) return;
|
|
Shinya Kitaoka |
120a6e |
if (!m_ghostLink) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_linkingTo) {
|
|
Shinya Kitaoka |
120a6e |
showSnappedLinks();
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// Snapping
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *linkingTo = searchPort(me->scenePos());
|
|
Shinya Kitaoka |
120a6e |
if (!linkingTo) {
|
|
Shinya Kitaoka |
120a6e |
if (m_linkingTo) {
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo->highLight(false);
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo->update();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_ghostLink->updatePath(this->getLinkEndPoint(), me->scenePos());
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo = linkingTo;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// if to be connected something
|
|
Shinya Kitaoka |
120a6e |
else if (linkingTo != this) {
|
|
Shinya Kitaoka |
120a6e |
m_ghostLink->updatePath(this, linkingTo);
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo = linkingTo;
|
|
Shinya Kitaoka |
120a6e |
hideSnappedLinks();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// autopan
|
|
Shinya Kitaoka |
120a6e |
QGraphicsView *viewer = scene()->views()[0];
|
|
Shinya Kitaoka |
120a6e |
viewer->setInteractive(false);
|
|
Shinya Kitaoka |
120a6e |
viewer->ensureVisible(QRectF(me->scenePos(), QSizeF(1, 1)), 5, 5);
|
|
Shinya Kitaoka |
120a6e |
viewer->setInteractive(true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicPort::mousePressEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (!isSelected()) {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() != Qt::ControlModifier) scene()->clearSelection();
|
|
Shinya Kitaoka |
120a6e |
if (me->button() == Qt::LeftButton || me->button() == Qt::RightButton)
|
|
Shinya Kitaoka |
120a6e |
getNode()->setSelected(true);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() == Qt::ControlModifier &&
|
|
Shinya Kitaoka |
120a6e |
me->button() == Qt::LeftButton)
|
|
Shinya Kitaoka |
120a6e |
getNode()->setSelected(false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
getNode()->onClicked();
|
|
Shinya Kitaoka |
120a6e |
if (me->button() == Qt::LeftButton && getType() != 202 // eFxLinkPort
|
|
Shinya Kitaoka |
120a6e |
&& getType() != 203 // eFxGroupedInPort
|
|
Shinya Kitaoka |
120a6e |
&& getType() != 204 // eFxGroupedOutPort
|
|
Shinya Kitaoka |
120a6e |
&& getType() != 103 // eStageSplineGroupPort
|
|
Shinya Kitaoka |
120a6e |
&& getType() != 104 // eStageParentGroupPort
|
|
Shinya Kitaoka |
120a6e |
&& getType() != 105) // eStageChildGroupPort
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_buttonState = Qt::LeftButton;
|
|
Shinya Kitaoka |
120a6e |
QPointF endPos(me->pos());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_ghostLink = new SchematicLink(0, scene());
|
|
Shinya Kitaoka |
120a6e |
m_ghostLink->setZValue(3.0);
|
|
Shinya Kitaoka |
120a6e |
m_ghostLink->updatePath(this->getLinkEndPoint(), me->scenePos());
|
|
Shinya Kitaoka |
120a6e |
emit(isClicked());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicPort::mouseReleaseEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() != Qt::ControlModifier && me->button() != Qt::RightButton)
|
|
Shinya Kitaoka |
120a6e |
QGraphicsItem::mouseReleaseEvent(me);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_ghostLink) m_ghostLink->hide();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (m_buttonState == Qt::LeftButton) emit(isReleased(me->scenePos()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// The link is added to the scene only if the user released the left mouse
|
|
Shinya Kitaoka |
120a6e |
// button over
|
|
Shinya Kitaoka |
120a6e |
// a SchematicPort different from SchematicPort of the parent node.
|
|
Shinya Kitaoka |
120a6e |
if (m_buttonState == Qt::LeftButton && m_linkingTo &&
|
|
Shinya Kitaoka |
120a6e |
!isLinkedTo(m_linkingTo) && linkTo(m_linkingTo, true)) {
|
|
Shinya Kitaoka |
120a6e |
linkTo(m_linkingTo);
|
|
Shinya Kitaoka |
120a6e |
m_buttonState = Qt::NoButton;
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo = 0;
|
|
Shinya Kitaoka |
120a6e |
emit sceneChanged();
|
|
Shinya Kitaoka |
120a6e |
emit xsheetChanged();
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
showSnappedLinks();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicPort::removeLink(SchematicLink *link) { m_links.removeAll(link); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicPort::eraseLink(SchematicLink *link) {
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *otherPort = link->getOtherPort(this);
|
|
Shinya Kitaoka |
120a6e |
if (otherPort) otherPort->removeLink(link);
|
|
Shinya Kitaoka |
120a6e |
removeLink(link);
|
|
Shinya Kitaoka |
120a6e |
if (link->scene()) link->scene()->removeItem(link);
|
|
Shinya Kitaoka |
120a6e |
delete link;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicPort::eraseAllLinks() {
|
|
Shinya Kitaoka |
120a6e |
while (!m_links.empty()) eraseLink(m_links[0]);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicLink *SchematicPort::makeLink(SchematicPort *port) {
|
|
Shinya Kitaoka |
120a6e |
if (isLinkedTo(port) || !port) return 0;
|
|
Shinya Kitaoka |
120a6e |
SchematicLink *link = new SchematicLink(0, scene());
|
|
Shinya Kitaoka |
120a6e |
if (getType() == 202 && port->getType() == 202) link->setLineShaped(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
link->setStartPort(this);
|
|
Shinya Kitaoka |
120a6e |
link->setEndPort(port);
|
|
Shinya Kitaoka |
120a6e |
addLink(link);
|
|
Shinya Kitaoka |
120a6e |
port->addLink(link);
|
|
Shinya Kitaoka |
120a6e |
link->updatePath();
|
|
Shinya Kitaoka |
120a6e |
return link;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool SchematicPort::isLinkedTo(SchematicPort *port) const {
|
|
Shinya Kitaoka |
120a6e |
if (m_links.size() == 0) return false;
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < m_links.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
SchematicLink *link = m_links[i];
|
|
Shinya Kitaoka |
120a6e |
if (((link->getStartPort() == this && link->getEndPort() == port) ||
|
|
Shinya Kitaoka |
120a6e |
(link->getEndPort() == this && link->getStartPort() == port)) &&
|
|
Shinya Kitaoka |
120a6e |
link->isVisible())
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicPort::updateLinksGeometry() {
|
|
Shinya Kitaoka |
120a6e |
int linkCount = getLinkCount();
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < linkCount; i++) {
|
|
Shinya Kitaoka |
120a6e |
SchematicLink *link = getLink(i);
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *startPort = link->getStartPort();
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *endPort = link->getEndPort();
|
|
Shinya Kitaoka |
120a6e |
if (startPort && endPort) {
|
|
Shinya Kitaoka |
120a6e |
link->updatePath(startPort, endPort);
|
|
Shinya Kitaoka |
120a6e |
link->setPos(startPort->getLinkEndPoint());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
QPointF SchematicPort::getLinkEndPoint() const { return scenePos() + m_hook; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Shinya Kitaoka |
120a6e |
// class SchematicNode
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
//========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \class SchematicNode schematicnode.h "../inlcude/toonzqt/schematicnode.h"
|
|
Shinya Kitaoka |
120a6e |
\brief The class provides methods to draw and handle a node item in the
|
|
Shinya Kitaoka |
120a6e |
SchematicScene.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \fn SchematicPort *SchematicNode::getInputPort() const
|
|
Shinya Kitaoka |
120a6e |
Returns the input SchematicPort of the node.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \fn SchematicPort *SchematicNode::getOutputPort() const
|
|
Shinya Kitaoka |
120a6e |
Returns the output SchematicPort of the node.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! \fn SchematicScene* SchematicNode::getScene() const
|
|
Shinya Kitaoka |
120a6e |
Returns the scene where the node is placed.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
SchematicNode::SchematicNode(SchematicScene *scene)
|
|
Toshihiro Shimizu |
890ddd |
#if QT_VERSION >= 0x050000
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(0)
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(0, scene)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
, m_scene(scene)
|
|
Shinya Kitaoka |
120a6e |
, m_width(0)
|
|
Shinya Kitaoka |
120a6e |
, m_height(0)
|
|
Shinya Kitaoka |
120a6e |
, m_buttonState(Qt::NoButton) {
|
|
Toshihiro Shimizu |
890ddd |
#if QT_VERSION >= 0x050000
|
|
Shinya Kitaoka |
120a6e |
scene->addItem(this);
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsMovable, false);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
|
Shinya Kitaoka |
120a6e |
setZValue(1.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
SchematicNode::~SchematicNode() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Reimplements the pure virtual QGraphicsItem::boundingRect() method.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
QRectF SchematicNode::boundingRect() const { return QRectF(0, 0, 1, 1); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! Reimplements the pure virtual QGraphicsItem::paint() method.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::paint(QPainter *painter,
|
|
Shinya Kitaoka |
120a6e |
const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
120a6e |
QWidget *widget) {
|
|
Shinya Kitaoka |
120a6e |
QPen pen;
|
|
Shinya Kitaoka |
120a6e |
if (isSelected()) {
|
|
Shinya Kitaoka |
120a6e |
painter->setBrush(QColor(0, 0, 0, 0));
|
|
Shinya Kitaoka |
120a6e |
pen.setColor(QColor(255, 255, 255, 255));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
pen.setWidth(4.0);
|
|
Shinya Kitaoka |
120a6e |
pen.setJoinStyle(Qt::RoundJoin);
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(pen);
|
|
Shinya Kitaoka |
120a6e |
painter->drawRect(-2, -2, m_width + 4, m_height + 4);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
pen.setColor(QColor(0, 0, 0, 255));
|
|
Shinya Kitaoka |
120a6e |
pen.setWidth(0);
|
|
Shinya Kitaoka |
120a6e |
painter->setPen(pen);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! Reimplements the QGraphicsItem::mouseMoveEvent() method.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::mouseMoveEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
QList<qgraphicsitem *=""> items = scene()->selectedItems();</qgraphicsitem>
|
|
Shinya Kitaoka |
120a6e |
if (items.empty()) return;
|
|
Shinya Kitaoka |
120a6e |
QPointF delta = me->scenePos() - me->lastScenePos();
|
|
Shinya Kitaoka |
120a6e |
QGraphicsView *viewer = scene()->views()[0];
|
|
Shinya Kitaoka |
120a6e |
for (auto const &item : items) {
|
|
Shinya Kitaoka |
120a6e |
SchematicNode *node = dynamic_cast<schematicnode *="">(item);</schematicnode>
|
|
Shinya Kitaoka |
120a6e |
if (node) {
|
|
Shinya Kitaoka |
120a6e |
node->setPosition(node->scenePos() + delta);
|
|
Shinya Kitaoka |
120a6e |
node->setSchematicNodePos(node->scenePos());
|
|
Shinya Kitaoka |
120a6e |
node->updateLinksGeometry();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
viewer->setInteractive(false);
|
|
Shinya Kitaoka |
120a6e |
viewer->ensureVisible(QRectF(me->scenePos(), QSizeF(1, 1)), 5, 5);
|
|
Shinya Kitaoka |
120a6e |
viewer->setInteractive(true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::mousePressEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (!isSelected()) {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() != Qt::ControlModifier) scene()->clearSelection();
|
|
Shinya Kitaoka |
120a6e |
if (me->button() == Qt::LeftButton || me->button() == Qt::RightButton)
|
|
Shinya Kitaoka |
120a6e |
setSelected(true);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() == Qt::ControlModifier &&
|
|
Shinya Kitaoka |
120a6e |
me->button() == Qt::LeftButton)
|
|
Shinya Kitaoka |
120a6e |
setSelected(false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
onClicked();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::mouseReleaseEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
if (me->modifiers() != Qt::ControlModifier && me->button() != Qt::RightButton)
|
|
Shinya Kitaoka |
120a6e |
QGraphicsItem::mouseReleaseEvent(me);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/* Add a pair (portId, SchematicPort*port) in the mapping
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *SchematicNode::addPort(int portId, SchematicPort *port) {
|
|
Shinya Kitaoka |
120a6e |
QMap<int, *="" schematicport="">::iterator it;</int,>
|
|
Shinya Kitaoka |
120a6e |
it = m_ports.find(portId);
|
|
Shinya Kitaoka |
120a6e |
if (it != m_ports.end() && m_ports[portId] != port) {
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *oldPort = m_ports[portId];
|
|
Shinya Kitaoka |
120a6e |
m_ports.erase(it);
|
|
Shinya Kitaoka |
120a6e |
scene()->removeItem(oldPort);
|
|
Shinya Kitaoka |
120a6e |
delete oldPort;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_ports[portId] = port;
|
|
Shinya Kitaoka |
120a6e |
return port;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Erase the pair (portId, SchematicPort*port) from the mapping*/
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::erasePort(int portId) {
|
|
Shinya Kitaoka |
120a6e |
QMap<int, *="" schematicport="">::iterator it = m_ports.find(portId);</int,>
|
|
Shinya Kitaoka |
120a6e |
if (it != m_ports.end()) {
|
|
Shinya Kitaoka |
120a6e |
delete it.value();
|
|
Shinya Kitaoka |
120a6e |
m_ports.erase(it);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*! Returns a pointer to the SchematicPort mapped from \b portId.\n
|
|
Toshihiro Shimizu |
890ddd |
Returns 0 if \b portId doesn't map no SchematicPort.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *SchematicNode::getPort(int portId) const {
|
|
Shinya Kitaoka |
120a6e |
QMap<int, *="" schematicport="">::const_iterator it = m_ports.find(portId);</int,>
|
|
Shinya Kitaoka |
120a6e |
if (it != m_ports.end()) return it.value();
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/*! Returns a list of all node connected by links to a SchematicPort identified
|
|
Shinya Kitaoka |
120a6e |
* by \b portId.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
QList<schematicnode *=""> SchematicNode::getLinkedNodes(int portId) const {</schematicnode>
|
|
Shinya Kitaoka |
120a6e |
QList<schematicnode *=""> list;</schematicnode>
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *port = getPort(portId);
|
|
Shinya Kitaoka |
120a6e |
if (port) {
|
|
Shinya Kitaoka |
120a6e |
int linkCount = port->getLinkCount();
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < linkCount; i++) list.push_back(port->getLinkedNode(i));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
return list;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::updateLinksGeometry() {
|
|
Shinya Kitaoka |
120a6e |
QMap<int, *="" schematicport="">::iterator it;</int,>
|
|
Shinya Kitaoka |
120a6e |
for (it = m_ports.begin(); it != m_ports.end(); ++it)
|
|
Shinya Kitaoka |
120a6e |
it.value()->updateLinksGeometry();
|
|
Toshihiro Shimizu |
890ddd |
}
|