|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/schematicnode.h"
|
|
manongjohn |
d6e3cc |
#include "toonzqt/stageschematicscene.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>
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/menubarcommand.h"
|
|
shun_iwasawa |
3cc41f |
#include "toonzqt/gutil.h"
|
|
shun_iwasawa |
3cc41f |
|
|
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 |
QRect rect(3, 3, 8, 8);
|
|
shun_iwasawa |
3cc41f |
QRect sourceRect = scene()->views()[0]->matrix().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 |
3cc41f |
pixmap = onIcon.pixmap(sourceRect.size());
|
|
shun_iwasawa |
3cc41f |
sourceRect = QRect(0, 0, sourceRect.width() * getDevPixRatio(),
|
|
shun_iwasawa |
3cc41f |
sourceRect.height() * getDevPixRatio());
|
|
shun_iwasawa |
3cc41f |
painter->drawPixmap(rect, pixmap, sourceRect);
|
|
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 =
|
|
manongjohn |
d6e3cc |
scene()->views()[0]->matrix().mapRect(QRect(0, 0, 18, 17));
|
|
manongjohn |
d6e3cc |
QPixmap redPm = pix.pixmap(sourceRect.size());
|
|
manongjohn |
d6e3cc |
QRect newRect = QRect(0, 0, sourceRect.width() * getDevPixRatio(),
|
|
manongjohn |
d6e3cc |
sourceRect.height() * getDevPixRatio());
|
|
manongjohn |
d6e3cc |
painter->drawPixmap(rect, redPm, newRect);
|
|
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 =
|
|
manongjohn |
d6e3cc |
scene()->views()[0]->matrix().mapRect(QRect(0, 0, 18, 17));
|
|
manongjohn |
d6e3cc |
QPixmap redPm = m_imageOff.pixmap(sourceRect.size());
|
|
manongjohn |
d6e3cc |
QRect newRect = QRect(0, 0, sourceRect.width() * getDevPixRatio(),
|
|
manongjohn |
d6e3cc |
sourceRect.height() * getDevPixRatio());
|
|
manongjohn |
d6e3cc |
painter->drawPixmap(rect, redPm, newRect);
|
|
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
|
|
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) {
|
|
manongjohn |
d6e3cc |
QIcon &pix =
|
|
manongjohn |
d6e3cc |
(m_state == 2 && !m_imageOn2.isNull()) ? m_imageOn2 : m_imageOn;
|
|
manongjohn |
7b18ae |
QRect sourceRect = scene()->views()[0]->matrix().mapRect(rect.toRect());
|
|
manongjohn |
7b18ae |
QPixmap redPm = pix.pixmap(sourceRect.size());
|
|
manongjohn |
7b18ae |
QRect newRect = QRect(0, 0, sourceRect.width() * getDevPixRatio(),
|
|
manongjohn |
d6e3cc |
sourceRect.height() * getDevPixRatio());
|
|
manongjohn |
d6e3cc |
painter->drawPixmap(rect, redPm, newRect);
|
|
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 |
|
|
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 |
|
|
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_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;
|
|
shun-iwasawa |
21e838 |
if (m_ghostLinks.isEmpty()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Snapping
|
|
Shinya Kitaoka |
120a6e |
SchematicPort *linkingTo = searchPort(me->scenePos());
|
|
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 |
}
|
|
Shinya Kitaoka |
120a6e |
// if to be connected something
|
|
Shinya Kitaoka |
120a6e |
else if (linkingTo != this) {
|
|
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 |
|
|
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 |
}
|