|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/schematicnode.h"
|
|
manongjohn |
d6e3cc |
#include "toonzqt/stageschematicscene.h"
|
|
Kite |
521c84 |
#include "toonzqt/fxschematicscene.h"
|
|
manongjohn |
d6e3cc |
|
|
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>
|
|
shun_iwasawa |
3cc41f |
#include <qdesktopwidget></qdesktopwidget>
|
|
justburner |
5053be |
#include <qclipboard></qclipboard>
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/menubarcommand.h"
|
|
shun_iwasawa |
3cc41f |
#include "toonzqt/gutil.h"
|
|
shun_iwasawa |
3cc41f |
|
|
justburner |
5053be |
#define ACCEL_KEY(k) \
|
|
justburner |
5053be |
(!QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) \
|
|
justburner |
5053be |
? QLatin1Char('\t') + \
|
|
justburner |
5053be |
QKeySequence(k).toString(QKeySequence::NativeText) \
|
|
justburner |
5053be |
: QString())
|
|
justburner |
5053be |
|
|
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)
|
|
justburner |
5053be |
: QGraphicsTextItem("", parent)
|
|
justburner |
5053be |
, m_width(width)
|
|
justburner |
5053be |
, m_height(height)
|
|
justburner |
5053be |
, m_defName("")
|
|
justburner |
5053be |
, m_curName("")
|
|
justburner |
5053be |
, m_refocus(false) {
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
|
Shinya Kitaoka |
120a6e |
setFlag(QGraphicsItem::ItemIsFocusable, true);
|
|
Shinya Kitaoka |
120a6e |
setTextInteractionFlags(Qt::TextEditorInteraction);
|
|
Toshihiro Shimizu |
890ddd |
|
|
justburner |
5053be |
popup = new QMenu();
|
|
justburner |
5053be |
popup->setObjectName(QLatin1String("qt_edit_menu"));
|
|
justburner |
5053be |
|
|
shun-iwasawa |
f2e168 |
actionCut = popup->addAction(tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut), this,
|
|
shun-iwasawa |
f2e168 |
SLOT(onCut()));
|
|
justburner |
5053be |
actionCut->setObjectName(QStringLiteral("edit-cut"));
|
|
justburner |
5053be |
|
|
justburner |
5053be |
actionCopy = popup->addAction(tr("&Copy") + ACCEL_KEY(QKeySequence::Copy),
|
|
shun-iwasawa |
f2e168 |
this, SLOT(onCopy()));
|
|
justburner |
5053be |
actionCopy->setObjectName(QStringLiteral("edit-copy"));
|
|
justburner |
5053be |
|
|
shun-iwasawa |
f2e168 |
actionPaste = popup->addAction(tr("&Paste") + ACCEL_KEY(QKeySequence::Paste),
|
|
shun-iwasawa |
f2e168 |
this, SLOT(onPaste()));
|
|
justburner |
5053be |
actionPaste->setObjectName(QStringLiteral("edit-paste"));
|
|
justburner |
5053be |
|
|
justburner |
5053be |
actionDelete = popup->addAction(
|
|
justburner |
5053be |
tr("&Delete") + ACCEL_KEY(QKeySequence::Delete), this, SLOT(onDelete()));
|
|
justburner |
5053be |
actionDelete->setObjectName(QStringLiteral("edit-delete"));
|
|
justburner |
5053be |
|
|
justburner |
5053be |
popup->addSeparator();
|
|
justburner |
5053be |
|
|
justburner |
5053be |
actionSelectAll =
|
|
justburner |
5053be |
popup->addAction(tr("Select &All") + ACCEL_KEY(QKeySequence::SelectAll),
|
|
shun-iwasawa |
f2e168 |
this, SLOT(onSelectAll()));
|
|
justburner |
5053be |
actionSelectAll->setObjectName(QStringLiteral("select-all"));
|
|
justburner |
5053be |
|
|
Shinya Kitaoka |
120a6e |
connect(document(), SIGNAL(contentsChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(onContentsChanged()));
|
|
justburner |
5053be |
connect(popup, SIGNAL(aboutToHide()), this, SLOT(onPopupHide()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
justburner |
5053be |
SchematicName::~SchematicName() { delete popup; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
justburner |
5053be |
void SchematicName::setName(const QString &name) {
|
|
justburner |
5053be |
m_defName = name;
|
|
justburner |
5053be |
setPlainText(name);
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
|
|
justburner |
5053be |
//--------------------------------------------------------
|
|
justburner |
5053be |
|
|
justburner |
5053be |
void SchematicName::acceptName(const QString &name) {
|
|
justburner |
5053be |
m_curName = name;
|
|
justburner |
5053be |
m_curName.remove(QRegExp("[\\n\\r]")); // remove all newlines
|
|
justburner |
5053be |
setPlainText(m_curName);
|
|
justburner |
5053be |
}
|
|
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");
|
|
justburner |
5053be |
if (text.isEmpty()) text = m_defName;
|
|
justburner |
5053be |
acceptName(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);
|
|
justburner |
5053be |
if (fe->reason() == Qt::MouseFocusReason) {
|
|
justburner |
5053be |
acceptName(toPlainText());
|
|
justburner |
5053be |
emit focusOut();
|
|
justburner |
5053be |
}
|
|
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);
|
|
justburner |
5053be |
} else if (ke->key() == Qt::Key_Escape) {
|
|
justburner |
5053be |
setPlainText(m_curName);
|
|
justburner |
5053be |
emit focusOut();
|
|
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);
|
|
justburner |
5053be |
if (!m_refocus) {
|
|
justburner |
5053be |
QTextDocument *doc = document();
|
|
justburner |
5053be |
QTextCursor cursor(doc->begin());
|
|
justburner |
5053be |
cursor.select(QTextCursor::Document);
|
|
justburner |
5053be |
setTextCursor(cursor);
|
|
justburner |
5053be |
m_curName = toPlainText();
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
|
|
justburner |
5053be |
//--------------------------------------------------------
|
|
justburner |
5053be |
|
|
justburner |
5053be |
void SchematicName::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
|
|
justburner |
5053be |
QClipboard *clipboard = QApplication::clipboard();
|
|
justburner |
5053be |
QTextCursor cursor = textCursor();
|
|
justburner |
5053be |
|
|
justburner |
5053be |
actionCut->setEnabled(cursor.hasSelection());
|
|
justburner |
5053be |
actionCopy->setEnabled(cursor.hasSelection());
|
|
justburner |
5053be |
actionPaste->setEnabled(!clipboard->text().isEmpty());
|
|
justburner |
5053be |
actionDelete->setEnabled(cursor.hasSelection());
|
|
justburner |
5053be |
actionSelectAll->setEnabled(cursor.selectedText() != toPlainText());
|
|
justburner |
5053be |
|
|
justburner |
5053be |
popup->popup(cme->screenPos());
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
|
|
justburner |
5053be |
//--------------------------------------------------------
|
|
justburner |
5053be |
|
|
justburner |
5053be |
void SchematicName::onPopupHide() {
|
|
justburner |
5053be |
m_refocus = true;
|
|
justburner |
5053be |
setFocus();
|
|
justburner |
5053be |
m_refocus = false;
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
|
|
justburner |
5053be |
//--------------------------------------------------------
|
|
justburner |
5053be |
|
|
justburner |
5053be |
void SchematicName::onCut() {
|
|
justburner |
5053be |
QClipboard *clipboard = QApplication::clipboard();
|
|
justburner |
5053be |
QTextCursor cursor = textCursor();
|
|
justburner |
5053be |
QString plainText = toPlainText();
|
|
justburner |
5053be |
|
|
justburner |
5053be |
if (cursor.hasSelection()) {
|
|
shun-iwasawa |
f2e168 |
int p = cursor.selectionStart();
|
|
shun-iwasawa |
f2e168 |
int n = cursor.selectionEnd() - p;
|
|
justburner |
5053be |
QString selection = plainText.mid(p, n);
|
|
justburner |
5053be |
clipboard->setText(selection);
|
|
justburner |
5053be |
plainText.remove(p, n);
|
|
justburner |
5053be |
acceptName(plainText);
|
|
justburner |
5053be |
cursor.setPosition(p);
|
|
justburner |
5053be |
setTextCursor(cursor);
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
|
|
justburner |
5053be |
//--------------------------------------------------------
|
|
justburner |
5053be |
|
|
justburner |
5053be |
void SchematicName::onCopy() {
|
|
justburner |
5053be |
QClipboard *clipboard = QApplication::clipboard();
|
|
justburner |
5053be |
QTextCursor cursor = textCursor();
|
|
justburner |
5053be |
QString plainText = toPlainText();
|
|
justburner |
5053be |
|
|
justburner |
5053be |
if (cursor.hasSelection()) {
|
|
justburner |
5053be |
int p = cursor.selectionStart();
|
|
justburner |
5053be |
int n = cursor.selectionEnd() - p;
|
|
justburner |
5053be |
clipboard->setText(plainText.mid(p, n));
|
|
justburner |
5053be |
} else {
|
|
justburner |
5053be |
clipboard->setText(plainText);
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
|
|
justburner |
5053be |
//--------------------------------------------------------
|
|
justburner |
5053be |
|
|
justburner |
5053be |
void SchematicName::onPaste() {
|
|
justburner |
5053be |
QClipboard *clipboard = QApplication::clipboard();
|
|
justburner |
5053be |
QTextCursor cursor = textCursor();
|
|
justburner |
5053be |
QString plainText = toPlainText();
|
|
justburner |
5053be |
QString clipboardText = clipboard->text();
|
|
shun-iwasawa |
f2e168 |
clipboardText.remove(QRegExp("[\\n\\r]")); // remove all newlines
|
|
justburner |
5053be |
|
|
justburner |
5053be |
int n, p = cursor.position();
|
|
justburner |
5053be |
if (cursor.hasSelection()) {
|
|
justburner |
5053be |
p = cursor.selectionStart();
|
|
justburner |
5053be |
n = cursor.selectionEnd() - p;
|
|
justburner |
5053be |
plainText.remove(p, n);
|
|
justburner |
5053be |
plainText.insert(p, clipboardText);
|
|
justburner |
5053be |
} else {
|
|
justburner |
5053be |
plainText.insert(p, clipboardText);
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
acceptName(plainText);
|
|
justburner |
5053be |
cursor.setPosition(p + clipboardText.length());
|
|
Shinya Kitaoka |
120a6e |
setTextCursor(cursor);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
justburner |
2a0406 |
//--------------------------------------------------------
|
|
justburner |
2a0406 |
|
|
justburner |
5053be |
void SchematicName::onDelete() {
|
|
justburner |
5053be |
QClipboard *clipboard = QApplication::clipboard();
|
|
justburner |
5053be |
QTextCursor cursor = textCursor();
|
|
justburner |
5053be |
QString plainText = toPlainText();
|
|
justburner |
5053be |
|
|
justburner |
5053be |
if (cursor.hasSelection()) {
|
|
shun-iwasawa |
f2e168 |
int p = cursor.selectionStart();
|
|
shun-iwasawa |
f2e168 |
int n = cursor.selectionEnd() - p;
|
|
justburner |
5053be |
plainText.remove(p, n);
|
|
justburner |
5053be |
acceptName(plainText);
|
|
justburner |
5053be |
cursor.setPosition(p);
|
|
justburner |
5053be |
setTextCursor(cursor);
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
}
|
|
justburner |
5053be |
|
|
justburner |
5053be |
//--------------------------------------------------------
|
|
justburner |
5053be |
|
|
justburner |
5053be |
void SchematicName::onSelectAll() {
|
|
justburner |
5053be |
QTextDocument *doc = document();
|
|
justburner |
5053be |
QTextCursor cursor(doc->begin());
|
|
justburner |
5053be |
cursor.select(QTextCursor::Document);
|
|
justburner |
5053be |
setTextCursor(cursor);
|
|
justburner |
5053be |
}
|
|
justburner |
2a0406 |
|
|
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 |
QRect rect(3, 3, 8, 8);
|
|
shun-iwasawa |
443318 |
QRect sourceRect = scene()->views()[0]->transform().mapRect(rect);
|
|
shun_iwasawa |
3cc41f |
static QIcon onIcon(":Resources/schematic_thumbtoggle_on.svg");
|
|
shun_iwasawa |
3cc41f |
static QIcon offIcon(":Resources/schematic_thumbtoggle_off.svg");
|
|
shun_iwasawa |
3cc41f |
QPixmap pixmap;
|
|
shun_iwasawa |
3cc41f |
if (m_isDown)
|
|
shun_iwasawa |
3cc41f |
pixmap = offIcon.pixmap(sourceRect.size());
|
|
shun_iwasawa |
3cc41f |
else
|
|
shun-iwasawa |
f2e168 |
pixmap = onIcon.pixmap(sourceRect.size());
|
|
shun-iwasawa |
f2e168 |
painter->drawPixmap(rect, pixmap);
|
|
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 |
|
|
manongjohn |
d6e3cc |
SchematicToggle::SchematicToggle(SchematicNode *parent, const QIcon &imageOn,
|
|
manongjohn |
d6e3cc |
QColor colorOn, int flags,
|
|
manongjohn |
d6e3cc |
bool isNormalIconView)
|
|
manongjohn |
d6e3cc |
: QGraphicsItem(parent)
|
|
manongjohn |
d6e3cc |
, m_imageOn(imageOn)
|
|
manongjohn |
d6e3cc |
, m_imageOn2()
|
|
manongjohn |
d6e3cc |
, m_imageOff()
|
|
manongjohn |
d6e3cc |
, m_state(0)
|
|
manongjohn |
d6e3cc |
, m_flags(flags)
|
|
manongjohn |
d6e3cc |
, m_width(isNormalIconView ? 18 : 30)
|
|
manongjohn |
d6e3cc |
, m_height(isNormalIconView ? 7 : 5)
|
|
manongjohn |
d6e3cc |
, m_colorOn(colorOn)
|
|
manongjohn |
d6e3cc |
, m_colorOff(QColor(0, 0, 0, 0)) {}
|
|
manongjohn |
d6e3cc |
|
|
manongjohn |
d6e3cc |
//--------------------------------------------------------
|
|
manongjohn |
d6e3cc |
|
|
manongjohn |
d6e3cc |
SchematicToggle::SchematicToggle(SchematicNode *parent, const QIcon &imageOn,
|
|
manongjohn |
d6e3cc |
QColor colorOn, const QIcon &imageOff,
|
|
manongjohn |
d6e3cc |
QColor colorOff, int flags,
|
|
manongjohn |
d6e3cc |
bool isNormalIconView)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent)
|
|
manongjohn |
d6e3cc |
, m_imageOn(imageOn)
|
|
manongjohn |
d6e3cc |
, m_imageOn2()
|
|
manongjohn |
d6e3cc |
, m_imageOff(imageOff)
|
|
Shinya Kitaoka |
120a6e |
, m_state(0)
|
|
Shinya Kitaoka |
120a6e |
, m_flags(flags)
|
|
manongjohn |
d6e3cc |
, m_width(isNormalIconView ? 18 : 30)
|
|
manongjohn |
d6e3cc |
, m_height(isNormalIconView ? 7 : 5)
|
|
manongjohn |
d6e3cc |
, m_colorOn(colorOn)
|
|
manongjohn |
d6e3cc |
, m_colorOff(colorOff) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//--------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
|
|
manongjohn |
d6e3cc |
SchematicToggle::SchematicToggle(SchematicNode *parent, const QIcon &imageOn,
|
|
manongjohn |
d6e3cc |
const QIcon &imageOn2, QColor colorOn,
|
|
manongjohn |
d6e3cc |
int flags, bool isNormalIconView)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent)
|
|
manongjohn |
d6e3cc |
, m_imageOn(imageOn)
|
|
manongjohn |
d6e3cc |
, m_imageOn2(imageOn2)
|
|
manongjohn |
d6e3cc |
, m_imageOff()
|
|
Shinya Kitaoka |
120a6e |
, m_state(0)
|
|
Shinya Kitaoka |
120a6e |
, m_flags(flags)
|
|
manongjohn |
d6e3cc |
, m_width(isNormalIconView ? 18 : 30)
|
|
manongjohn |
d6e3cc |
, m_height(isNormalIconView ? 7 : 5)
|
|
manongjohn |
d6e3cc |
, m_colorOn(colorOn)
|
|
manongjohn |
d6e3cc |
, m_colorOff(QColor(0, 0, 0, 0)) {}
|
|
manongjohn |
d6e3cc |
|
|
manongjohn |
d6e3cc |
//--------------------------------------------------------
|
|
manongjohn |
d6e3cc |
|
|
manongjohn |
d6e3cc |
SchematicToggle::SchematicToggle(SchematicNode *parent, const QIcon &imageOn,
|
|
manongjohn |
d6e3cc |
const QIcon &imageOn2, QColor colorOn,
|
|
manongjohn |
d6e3cc |
const QIcon &imageOff, QColor colorOff,
|
|
manongjohn |
d6e3cc |
int flags, bool isNormalIconView)
|
|
manongjohn |
d6e3cc |
: QGraphicsItem(parent)
|
|
manongjohn |
d6e3cc |
, m_imageOn(imageOn)
|
|
manongjohn |
d6e3cc |
, m_imageOn2(imageOn2)
|
|
manongjohn |
d6e3cc |
, m_imageOff(imageOff)
|
|
manongjohn |
d6e3cc |
, m_state(0)
|
|
manongjohn |
d6e3cc |
, m_flags(flags)
|
|
manongjohn |
d6e3cc |
, m_width(isNormalIconView ? 18 : 30)
|
|
manongjohn |
d6e3cc |
, m_height(isNormalIconView ? 7 : 5)
|
|
manongjohn |
d6e3cc |
, m_colorOn(colorOn)
|
|
manongjohn |
d6e3cc |
, m_colorOff(colorOff) {}
|
|
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) {
|
|
manongjohn |
d6e3cc |
int rectHeight = boundingRect().height();
|
|
manongjohn |
d6e3cc |
int rectWidth = boundingRect().width();
|
|
manongjohn |
d6e3cc |
int rectX = boundingRect().left();
|
|
manongjohn |
d6e3cc |
int rectY = boundingRect().top();
|
|
manongjohn |
d6e3cc |
|
|
manongjohn |
d6e3cc |
QRect rect =
|
|
manongjohn |
d6e3cc |
QRect(0, 0, rectHeight, rectHeight)
|
|
manongjohn |
d6e3cc |
.translated(rectX + (rectWidth / 2) - (rectHeight / 2), rectY);
|
|
manongjohn |
d6e3cc |
|
|
Shinya Kitaoka |
120a6e |
if (m_state != 0) {
|
|
manongjohn |
d6e3cc |
QIcon &pix =
|
|
manongjohn |
d6e3cc |
(m_state == 2 && !m_imageOn2.isNull()) ? m_imageOn2 : m_imageOn;
|
|
manongjohn |
d6e3cc |
painter->fillRect(boundingRect().toRect(), m_colorOn);
|
|
manongjohn |
d6e3cc |
QRect sourceRect =
|
|
shun-iwasawa |
443318 |
scene()->views()[0]->transform().mapRect(QRect(0, 0, 18, 17));
|
|
manongjohn |
d6e3cc |
QPixmap redPm = pix.pixmap(sourceRect.size());
|
|
shun-iwasawa |
f2e168 |
painter->drawPixmap(rect, redPm);
|
|
manongjohn |
d6e3cc |
} else if (!m_imageOff.isNull()) {
|
|
shun-iwasawa |
045b61 |
QPen pen(m_colorOn);
|
|
shun-iwasawa |
045b61 |
pen.setWidthF(0.5);
|
|
shun-iwasawa |
045b61 |
painter->setPen(pen);
|
|
shun-iwasawa |
045b61 |
painter->setBrush(m_colorOff);
|
|
shun-iwasawa |
045b61 |
double d = pen.widthF() / 2.0;
|
|
shun-iwasawa |
045b61 |
painter->drawRect(boundingRect().adjusted(d, d, -d, -d));
|
|
manongjohn |
d6e3cc |
QRect sourceRect =
|
|
shun-iwasawa |
443318 |
scene()->views()[0]->transform().mapRect(QRect(0, 0, 18, 17));
|
|
manongjohn |
d6e3cc |
QPixmap redPm = m_imageOff.pixmap(sourceRect.size());
|
|
shun-iwasawa |
f2e168 |
painter->drawPixmap(rect, redPm);
|
|
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) {
|
|
manongjohn |
d6e3cc |
if (m_imageOn2.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;
|
|
manongjohn |
d6e3cc |
if (m_imageOn2.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
|
|
shun-iwasawa |
f2e168 |
*/
|
|
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) {
|
|
manongjohn |
d6e3cc |
QIcon &pix =
|
|
manongjohn |
d6e3cc |
(m_state == 2 && !m_imageOn2.isNull()) ? m_imageOn2 : m_imageOn;
|
|
shun-iwasawa |
443318 |
QRect sourceRect = scene()->views()[0]->transform().mapRect(rect.toRect());
|
|
manongjohn |
7b18ae |
QPixmap redPm = pix.pixmap(sourceRect.size());
|
|
shun-iwasawa |
f2e168 |
painter->drawPixmap(rect.toRect(), redPm);
|
|
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
|
|
shun-iwasawa |
f2e168 |
*/
|
|
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) {
|
|
shun-iwasawa |
f2e168 |
bool increase = false;
|
|
shun-iwasawa |
f2e168 |
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)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(parent)
|
|
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) {
|
|
Shinya Kitaoka |
120a6e |
scene->addItem(this);
|
|
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) {
|
|
Kite |
521c84 |
SchematicViewer *viewer;
|
|
Kite |
521c84 |
FxSchematicScene *fxScene = dynamic_cast<fxschematicscene *="">(scene());</fxschematicscene>
|
|
Kite |
521c84 |
StageSchematicScene *stageScene =
|
|
Kite |
521c84 |
dynamic_cast<stageschematicscene *="">(scene());</stageschematicscene>
|
|
Kite |
521c84 |
if (fxScene) {
|
|
Kite |
521c84 |
viewer = fxScene->getSchematicViewer();
|
|
Kite |
521c84 |
} else if (stageScene) {
|
|
Kite |
521c84 |
viewer = stageScene->getSchematicViewer();
|
|
Kite |
521c84 |
} else {
|
|
Kite |
521c84 |
return;
|
|
Kite |
521c84 |
}
|
|
Kite |
521c84 |
|
|
Shinya Kitaoka |
120a6e |
if (getStartPort() && (getStartPort()->getType() == 100 // eStageSplinePort
|
|
Shinya Kitaoka |
120a6e |
|| getStartPort()->getType() == 202)) { // eFxLinkPort
|
|
Shinya Kitaoka |
120a6e |
if (isSelected() || isHighlighted())
|
|
Kite |
521c84 |
painter->setPen(QPen(viewer->getMotionPathSelectedLinkColor()));
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Kite |
521c84 |
painter->setPen(QColor(viewer->getMotionPathLinkColor()));
|
|
Shinya Kitaoka |
120a6e |
} else if (isSelected() || isHighlighted())
|
|
Kite |
521c84 |
painter->setPen(QPen(viewer->getSelectedLinkColor()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
else if (!m_lineShaped)
|
|
Kite |
521c84 |
painter->setPen(QPen(viewer->getLinkColor()));
|
|
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 |
|
|
shun-iwasawa |
21e838 |
void SchematicLink::updateEndPos(const QPointF &endPos) {
|
|
shun-iwasawa |
21e838 |
if (m_startPort) updatePath(m_startPort->getLinkEndPoint(), endPos);
|
|
shun-iwasawa |
21e838 |
}
|
|
shun-iwasawa |
21e838 |
|
|
shun-iwasawa |
21e838 |
//--------------------------------------------------------
|
|
shun-iwasawa |
21e838 |
|
|
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();
|
|
manongjohn |
cd6e9e |
|
|
manongjohn |
cd6e9e |
if (!startPort || !endPort) {
|
|
manongjohn |
cd6e9e |
me->ignore();
|
|
manongjohn |
cd6e9e |
return;
|
|
manongjohn |
cd6e9e |
}
|
|
manongjohn |
cd6e9e |
|
|
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 |
|
|
shun-iwasawa |
443318 |
QTransform transform = scene()->views()[0]->transform();
|
|
shun-iwasawa |
443318 |
double scaleFactor = sqrt(transform.determinant());
|
|
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_linkingTo(0)
|
|
Shinya Kitaoka |
120a6e |
, m_hook(0, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_type(type) {
|
|
Shinya Kitaoka |
120a6e |
setAcceptHoverEvents(false);
|
|
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;
|
|
shun-iwasawa |
21e838 |
if (m_ghostLinks.isEmpty()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Snapping
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *linkingTo = searchPort(me->scenePos());
|
|
shun-iwasawa |
edafeb |
|
|
Shinya Kitaoka |
120a6e |
if (!linkingTo) {
|
|
shun-iwasawa |
21e838 |
for (SchematicLink *ghostLink : m_ghostLinks) {
|
|
shun-iwasawa |
21e838 |
ghostLink->updateEndPos(me->scenePos());
|
|
shun-iwasawa |
21e838 |
ghostLink->getStartPort()->showSnappedLinks(m_linkingTo);
|
|
shun-iwasawa |
21e838 |
}
|
|
Shinya Kitaoka |
120a6e |
if (m_linkingTo) {
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo->highLight(false);
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo->update();
|
|
shun-iwasawa |
21e838 |
m_linkingTo = nullptr;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
edafeb |
// if to be connected something new
|
|
shun-iwasawa |
edafeb |
else if (linkingTo != this && m_linkingTo != linkingTo) {
|
|
shun-iwasawa |
edafeb |
if (m_linkingTo) {
|
|
shun-iwasawa |
edafeb |
m_linkingTo->highLight(false);
|
|
shun-iwasawa |
edafeb |
m_linkingTo->update();
|
|
shun-iwasawa |
edafeb |
}
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo = linkingTo;
|
|
shun-iwasawa |
21e838 |
for (SchematicLink *ghostLink : m_ghostLinks) {
|
|
shun-iwasawa |
21e838 |
ghostLink->updatePath(ghostLink->getStartPort(), linkingTo);
|
|
shun-iwasawa |
21e838 |
ghostLink->getStartPort()->hideSnappedLinks(m_linkingTo);
|
|
shun-iwasawa |
21e838 |
}
|
|
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 |
|
|
shun-iwasawa |
21e838 |
// Enable to connect multiple links from all selected nodes
|
|
shun-iwasawa |
21e838 |
// only when ( Ctrl + ) dragging from the eStageParentPort.
|
|
shun-iwasawa |
21e838 |
if (getType() == 101) { // eStageParentPort
|
|
shun-iwasawa |
21e838 |
QList<qgraphicsitem *=""> items = scene()->selectedItems();</qgraphicsitem>
|
|
shun-iwasawa |
21e838 |
if (items.empty()) return;
|
|
shun-iwasawa |
21e838 |
for (auto const &item : items) {
|
|
shun-iwasawa |
21e838 |
SchematicNode *node = dynamic_cast<schematicnode *="">(item);</schematicnode>
|
|
shun-iwasawa |
21e838 |
if (node) {
|
|
shun-iwasawa |
21e838 |
SchematicPort *parentPort =
|
|
shun-iwasawa |
21e838 |
node->getPort(0); // id 0 is for parent port.
|
|
shun-iwasawa |
21e838 |
if (parentPort) {
|
|
shun-iwasawa |
21e838 |
SchematicLink *ghostLink = new SchematicLink(0, scene());
|
|
shun-iwasawa |
21e838 |
ghostLink->setStartPort(parentPort);
|
|
shun-iwasawa |
21e838 |
ghostLink->setZValue(3.0);
|
|
shun-iwasawa |
21e838 |
ghostLink->updateEndPos(me->scenePos());
|
|
shun-iwasawa |
21e838 |
m_ghostLinks.push_back(ghostLink);
|
|
shun-iwasawa |
21e838 |
}
|
|
shun-iwasawa |
21e838 |
}
|
|
shun-iwasawa |
21e838 |
}
|
|
shun-iwasawa |
21e838 |
} else {
|
|
shun-iwasawa |
21e838 |
SchematicLink *ghostLink = new SchematicLink(0, scene());
|
|
shun-iwasawa |
21e838 |
ghostLink->setStartPort(this);
|
|
shun-iwasawa |
21e838 |
ghostLink->setZValue(3.0);
|
|
shun-iwasawa |
21e838 |
ghostLink->updateEndPos(me->scenePos());
|
|
shun-iwasawa |
21e838 |
m_ghostLinks.push_back(ghostLink);
|
|
shun-iwasawa |
21e838 |
}
|
|
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_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.
|
|
shun-iwasawa |
21e838 |
bool somethingChanged = false;
|
|
shun-iwasawa |
21e838 |
if (m_buttonState == Qt::LeftButton && m_linkingTo) {
|
|
shun-iwasawa |
21e838 |
TUndoManager::manager()->beginBlock();
|
|
shun-iwasawa |
21e838 |
for (SchematicLink *ghostLink : m_ghostLinks) {
|
|
shun-iwasawa |
21e838 |
SchematicPort *port = ghostLink->getStartPort();
|
|
shun-iwasawa |
21e838 |
if (!port) continue;
|
|
shun-iwasawa |
21e838 |
if (!port->isLinkedTo(m_linkingTo) && port->linkTo(m_linkingTo, true)) {
|
|
shun-iwasawa |
21e838 |
port->linkTo(m_linkingTo);
|
|
shun-iwasawa |
21e838 |
somethingChanged = true;
|
|
shun-iwasawa |
21e838 |
} else
|
|
shun-iwasawa |
21e838 |
port->showSnappedLinks(m_linkingTo);
|
|
shun-iwasawa |
21e838 |
}
|
|
Shinya Kitaoka |
120a6e |
m_buttonState = Qt::NoButton;
|
|
Shinya Kitaoka |
120a6e |
m_linkingTo = 0;
|
|
shun-iwasawa |
21e838 |
TUndoManager::manager()->endBlock();
|
|
shun-iwasawa |
21e838 |
}
|
|
shun-iwasawa |
21e838 |
|
|
shun-iwasawa |
21e838 |
if (!m_ghostLinks.isEmpty()) {
|
|
shun-iwasawa |
21e838 |
for (SchematicLink *ghostLink : m_ghostLinks)
|
|
shun-iwasawa |
21e838 |
scene()->removeItem(ghostLink);
|
|
shun-iwasawa |
21e838 |
qDeleteAll(m_ghostLinks.begin(), m_ghostLinks.end());
|
|
shun-iwasawa |
21e838 |
m_ghostLinks.clear();
|
|
shun-iwasawa |
21e838 |
}
|
|
shun-iwasawa |
21e838 |
|
|
shun-iwasawa |
21e838 |
if (somethingChanged) {
|
|
Shinya Kitaoka |
120a6e |
emit sceneChanged();
|
|
Shinya Kitaoka |
120a6e |
emit xsheetChanged();
|
|
shun-iwasawa |
21e838 |
}
|
|
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 |
|
|
|
7e85db |
/*! \class SchematicNode schematicnode.h <toonzqt schematicnode.h=""></toonzqt>
|
|
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)
|
|
Shinya Kitaoka |
120a6e |
: QGraphicsItem(0)
|
|
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) {
|
|
Shinya Kitaoka |
120a6e |
scene->addItem(this);
|
|
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.
|
|
shun-iwasawa |
f2e168 |
*/
|
|
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.
|
|
shun-iwasawa |
f2e168 |
*/
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::paint(QPainter *painter,
|
|
Shinya Kitaoka |
120a6e |
const QStyleOptionGraphicsItem *option,
|
|
Shinya Kitaoka |
120a6e |
QWidget *widget) {
|
|
Kite |
521c84 |
SchematicViewer *viewer;
|
|
Kite |
521c84 |
FxSchematicScene *fxScene = dynamic_cast<fxschematicscene *="">(scene());</fxschematicscene>
|
|
Kite |
521c84 |
StageSchematicScene *stageScene =
|
|
Kite |
521c84 |
dynamic_cast<stageschematicscene *="">(scene());</stageschematicscene>
|
|
Kite |
521c84 |
if (fxScene) {
|
|
Kite |
521c84 |
viewer = fxScene->getSchematicViewer();
|
|
Kite |
521c84 |
} else if (stageScene) {
|
|
Kite |
521c84 |
viewer = stageScene->getSchematicViewer();
|
|
Kite |
521c84 |
} else {
|
|
Kite |
521c84 |
return;
|
|
Kite |
521c84 |
}
|
|
Kite |
521c84 |
|
|
Shinya Kitaoka |
120a6e |
QPen pen;
|
|
Shinya Kitaoka |
120a6e |
if (isSelected()) {
|
|
Shinya Kitaoka |
120a6e |
painter->setBrush(QColor(0, 0, 0, 0));
|
|
Kite |
521c84 |
pen.setColor(QColor(viewer->getSelectedBorderColor()));
|
|
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.
|
|
shun-iwasawa |
f2e168 |
*/
|
|
Shinya Kitaoka |
120a6e |
void SchematicNode::mouseMoveEvent(QGraphicsSceneMouseEvent *me) {
|
|
Shinya Kitaoka |
120a6e |
QList<qgraphicsitem *=""> items = scene()->selectedItems();</qgraphicsitem>
|
|
Shinya Kitaoka |
120a6e |
if (items.empty()) return;
|
|
shun-iwasawa |
57ba4e |
QPointF delta = me->scenePos() - m_scene->mousePos();
|
|
shun-iwasawa |
57ba4e |
// QPointF delta = me->scenePos() - me->lastScenePos();
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
if (me->modifiers() & Qt::ShiftModifier) {
|
|
shun-iwasawa |
57ba4e |
QPointF deltaFromStart = me->scenePos() - m_scene->clickedPos();
|
|
shun-iwasawa |
57ba4e |
if (std::abs(deltaFromStart.x()) > std::abs(deltaFromStart.y()))
|
|
shun-iwasawa |
57ba4e |
deltaFromStart.setY(0.0);
|
|
shun-iwasawa |
57ba4e |
else
|
|
shun-iwasawa |
57ba4e |
deltaFromStart.setX(0.0);
|
|
shun-iwasawa |
57ba4e |
delta = m_scene->clickedPos() + deltaFromStart - m_scene->mousePos();
|
|
shun-iwasawa |
57ba4e |
}
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
// snap to neighbor nodes
|
|
shun-iwasawa |
57ba4e |
bool ctrlPressed = me->modifiers() & Qt::ControlModifier;
|
|
shun-iwasawa |
57ba4e |
dynamic_cast<schematicscene *="">(scene())->computeSnap(this, delta,</schematicscene>
|
|
shun-iwasawa |
57ba4e |
ctrlPressed);
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
m_scene->setMousePos(m_scene->mousePos() + delta);
|
|
shun-iwasawa |
57ba4e |
|
|
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();
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
m_scene->setMousePos(me->scenePos());
|
|
shun-iwasawa |
57ba4e |
m_scene->setClickedPos(me->scenePos());
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
m_scene->updateSnapTarget(this);
|
|
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);
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
m_scene->updateSnapTarget(nullptr);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/* Add a pair (portId, SchematicPort*port) in the mapping
|
|
shun-iwasawa |
f2e168 |
*/
|
|
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.
|
|
shun-iwasawa |
f2e168 |
*/
|
|
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 |
}
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
//========================================================
|
|
shun-iwasawa |
57ba4e |
//
|
|
shun-iwasawa |
57ba4e |
// class SnapTargetItem
|
|
shun-iwasawa |
57ba4e |
//
|
|
shun-iwasawa |
57ba4e |
//========================================================
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
SnapTargetItem::SnapTargetItem(const QPointF &pos, const QRectF &rect,
|
|
shun-iwasawa |
57ba4e |
const QPointF &theOtherEndPos,
|
|
shun-iwasawa |
57ba4e |
const QPointF &portEndOffset)
|
|
shun-iwasawa |
57ba4e |
: m_rect(rect)
|
|
shun-iwasawa |
57ba4e |
, m_theOtherEndPos(theOtherEndPos)
|
|
shun-iwasawa |
57ba4e |
, m_portEndOffset(portEndOffset) {
|
|
shun-iwasawa |
57ba4e |
setFlag(QGraphicsItem::ItemIsMovable, false);
|
|
shun-iwasawa |
57ba4e |
setFlag(QGraphicsItem::ItemIsSelectable, false);
|
|
shun-iwasawa |
57ba4e |
setFlag(QGraphicsItem::ItemIsFocusable, false);
|
|
shun-iwasawa |
57ba4e |
setZValue(3.0);
|
|
shun-iwasawa |
57ba4e |
setPos(pos);
|
|
shun-iwasawa |
57ba4e |
setVisible(false);
|
|
shun-iwasawa |
57ba4e |
}
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
QRectF SnapTargetItem::boundingRect() const {
|
|
shun-iwasawa |
57ba4e |
QRectF linkRect(m_theOtherEndPos - scenePos(), m_portEndOffset);
|
|
shun-iwasawa |
57ba4e |
return m_rect.united(linkRect);
|
|
shun-iwasawa |
57ba4e |
}
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
void SnapTargetItem::paint(QPainter *painter,
|
|
shun-iwasawa |
57ba4e |
const QStyleOptionGraphicsItem *option,
|
|
shun-iwasawa |
57ba4e |
QWidget *widget) {
|
|
shun-iwasawa |
57ba4e |
painter->setPen(QPen(Qt::magenta, 1, Qt::DashDotLine));
|
|
shun-iwasawa |
57ba4e |
painter->drawRect(m_rect);
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
QPointF startPos = m_theOtherEndPos - scenePos();
|
|
shun-iwasawa |
57ba4e |
QPointF endPos = m_portEndOffset;
|
|
shun-iwasawa |
57ba4e |
QPointF p0((endPos.x() + startPos.x()) * 0.5, startPos.y());
|
|
shun-iwasawa |
57ba4e |
QPointF p1(p0.x(), endPos.y());
|
|
shun-iwasawa |
57ba4e |
QPointF p2(endPos);
|
|
shun-iwasawa |
57ba4e |
|
|
shun-iwasawa |
57ba4e |
QPainterPath path(startPos);
|
|
shun-iwasawa |
57ba4e |
path.cubicTo(p0, p1, p2);
|
|
shun-iwasawa |
57ba4e |
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
shun-iwasawa |
57ba4e |
painter->drawPath(path);
|
|
|
7e85db |
}
|