code format
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
#include "blockview.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
BlockBusItem::BlockBusItem(bool temp): QGraphicsObject(), PropertyStorage() {
|
||||
temp_ = temp;
|
||||
_init();
|
||||
if (!temp) setData(bvidType, bvitBus);
|
||||
else hide();
|
||||
if (!temp)
|
||||
setData(bvidType, bvitBus);
|
||||
else
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +20,12 @@ BlockBusItem::BlockBusItem(const BlockBusItem & other): QGraphicsObject(), Prope
|
||||
setPen(other.pen());
|
||||
setBrush(other.brush());
|
||||
setBusType(other.busType());
|
||||
square_node = other.square_node;
|
||||
max_ep = other.max_ep;
|
||||
pol = other.pol;
|
||||
segments = other.segments;
|
||||
im_bus = other.im_bus;
|
||||
im_end = other.im_end;
|
||||
square_node = other.square_node;
|
||||
max_ep = other.max_ep;
|
||||
pol = other.pol;
|
||||
segments = other.segments;
|
||||
im_bus = other.im_bus;
|
||||
im_end = other.im_end;
|
||||
im_bus_scale = other.im_bus_scale;
|
||||
im_end_scale = other.im_end_scale;
|
||||
updateGeometry();
|
||||
@@ -33,26 +36,34 @@ void BlockBusItem::_init() {
|
||||
setZValue(1.);
|
||||
setBusType(-1);
|
||||
setAcceptHoverEvents(true);
|
||||
ph.setColor(Qt::blue); ph.setJoinStyle(Qt::MiterJoin);
|
||||
bh.setColor(Qt::blue); bh.setStyle(Qt::SolidPattern);
|
||||
pu = pa = pr = ph; bu = ba = br = bh;
|
||||
grid_step = 10.;
|
||||
ph.setColor(Qt::blue);
|
||||
ph.setJoinStyle(Qt::MiterJoin);
|
||||
bh.setColor(Qt::blue);
|
||||
bh.setStyle(Qt::SolidPattern);
|
||||
pu = pa = pr = ph;
|
||||
bu = ba = br = bh;
|
||||
grid_step = 10.;
|
||||
pu.setWidth(1);
|
||||
pu.setColor(Qt::black); bu.setColor(Qt::black);
|
||||
pa.setColor(Qt::darkGreen); ba.setColor(Qt::darkGreen);
|
||||
pr.setColor(Qt::darkRed); br.setColor(Qt::darkRed);
|
||||
pn.setColor(Qt::gray); pn.setStyle(Qt::DashLine);
|
||||
pu.setColor(Qt::black);
|
||||
bu.setColor(Qt::black);
|
||||
pa.setColor(Qt::darkGreen);
|
||||
ba.setColor(Qt::darkGreen);
|
||||
pr.setColor(Qt::darkRed);
|
||||
br.setColor(Qt::darkRed);
|
||||
pn.setColor(Qt::gray);
|
||||
pn.setStyle(Qt::DashLine);
|
||||
if (temp_) {
|
||||
pu.setStyle(Qt::DashLine);
|
||||
pu.setColor(Qt::darkGray);
|
||||
bu.setColor(Qt::darkGray);
|
||||
}
|
||||
setPen(pu); setBrush(bu);
|
||||
setPen(pu);
|
||||
setBrush(bu);
|
||||
square_node = false;
|
||||
max_ep = 0;
|
||||
max_ep = 0;
|
||||
selPoint = selSegment = state_ = -1;
|
||||
pen_width = 2.;
|
||||
point_size = 3.;
|
||||
pen_width = 2.;
|
||||
point_size = 3.;
|
||||
im_bus_scale = im_end_scale = 1.;
|
||||
moved = deleted = mark_in = mark_out = new_segment = mm_cancel = lm_point = false;
|
||||
anim_point_size.setTargetObject(this);
|
||||
@@ -68,19 +79,19 @@ void BlockBusItem::reconnect() {
|
||||
if (temp_) return;
|
||||
if (!scene()) return;
|
||||
if (scene()->views().isEmpty()) return;
|
||||
qobject_cast<BlockView*>(scene()->views().back())->reconnectAll();
|
||||
qobject_cast<BlockView *>(scene()->views().back())->reconnectAll();
|
||||
}
|
||||
|
||||
|
||||
bool BlockBusItem::sceneEvent(QEvent * e) {
|
||||
if (temp_) return QGraphicsObject::sceneEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::GraphicsSceneHoverEnter: hoverEnterEvent((QGraphicsSceneHoverEvent * )e); break;
|
||||
case QEvent::GraphicsSceneHoverMove: hoverMoveEvent((QGraphicsSceneHoverEvent * )e); break;
|
||||
case QEvent::GraphicsSceneHoverLeave: hoverLeaveEvent((QGraphicsSceneHoverEvent * )e); break;
|
||||
case QEvent::GraphicsSceneMousePress: mousePressEvent((QGraphicsSceneMouseEvent * )e); break;
|
||||
case QEvent::GraphicsSceneMouseMove: mouseMoveEvent((QGraphicsSceneMouseEvent * )e); break;
|
||||
case QEvent::GraphicsSceneMouseRelease: mouseReleaseEvent((QGraphicsSceneMouseEvent * )e); break;
|
||||
case QEvent::GraphicsSceneHoverEnter: hoverEnterEvent((QGraphicsSceneHoverEvent *)e); break;
|
||||
case QEvent::GraphicsSceneHoverMove: hoverMoveEvent((QGraphicsSceneHoverEvent *)e); break;
|
||||
case QEvent::GraphicsSceneHoverLeave: hoverLeaveEvent((QGraphicsSceneHoverEvent *)e); break;
|
||||
case QEvent::GraphicsSceneMousePress: mousePressEvent((QGraphicsSceneMouseEvent *)e); break;
|
||||
case QEvent::GraphicsSceneMouseMove: mouseMoveEvent((QGraphicsSceneMouseEvent *)e); break;
|
||||
case QEvent::GraphicsSceneMouseRelease: mouseReleaseEvent((QGraphicsSceneMouseEvent *)e); break;
|
||||
default: break;
|
||||
}
|
||||
return QGraphicsObject::sceneEvent(e);
|
||||
@@ -95,7 +106,7 @@ int BlockBusItem::addPoint(const QPointF & point, bool update) {
|
||||
selPoint = pol.size() - 1;
|
||||
segments << QPair<int, int>(selPoint, segments[selSegment].second);
|
||||
segments[selSegment].second = selPoint;
|
||||
selSegment = -1;
|
||||
selSegment = -1;
|
||||
updateGeometry();
|
||||
if (scene() != 0 && update) scene()->update();
|
||||
return pol.size() - 1;
|
||||
@@ -122,32 +133,33 @@ void BlockBusItem::removePoint(int index) {
|
||||
if (index < 0 || index > pol.size() - 1) return;
|
||||
int sc = 0, fs = -1, ss = -1;
|
||||
for (int i = 0; i < segments.size(); ++i)
|
||||
if (segments[i].first == index ||
|
||||
segments[i].second == index) {
|
||||
sc++;
|
||||
if (fs < 0) fs = i;
|
||||
else ss = i;
|
||||
if (segments[i].first == index || segments[i].second == index) {
|
||||
sc++;
|
||||
if (fs < 0)
|
||||
fs = i;
|
||||
else
|
||||
ss = i;
|
||||
}
|
||||
int ei(0);
|
||||
switch (sc) {
|
||||
case 1:
|
||||
segments.removeAt(fs);
|
||||
break;
|
||||
case 1: segments.removeAt(fs); break;
|
||||
case 2:
|
||||
if (segments[ss].first == index) ei = segments[ss].second;
|
||||
else ei = segments[ss].first;
|
||||
if (segments[fs].first == index) segments[fs].first = ei;
|
||||
else segments[fs].second = ei;
|
||||
if (segments[ss].first == index)
|
||||
ei = segments[ss].second;
|
||||
else
|
||||
ei = segments[ss].first;
|
||||
if (segments[fs].first == index)
|
||||
segments[fs].first = ei;
|
||||
else
|
||||
segments[fs].second = ei;
|
||||
segments.removeAt(ss);
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
pol.remove(index);
|
||||
for (int i = 0; i < segments.size(); ++i) {
|
||||
if (segments[i].first >= index)
|
||||
segments[i].first--;
|
||||
if (segments[i].second >= index)
|
||||
segments[i].second--;
|
||||
if (segments[i].first >= index) segments[i].first--;
|
||||
if (segments[i].second >= index) segments[i].second--;
|
||||
}
|
||||
selPoint = -1;
|
||||
checkDelete();
|
||||
@@ -162,25 +174,19 @@ void BlockBusItem::removeSegment(int index) {
|
||||
if (pif > pis) qSwap<int>(pif, pis);
|
||||
int scf = 0, scs = 0;
|
||||
for (int i = 0; i < segments.size(); ++i) {
|
||||
if (segments[i].first == pif ||
|
||||
segments[i].second == pif)
|
||||
scf++;
|
||||
if (segments[i].first == pis ||
|
||||
segments[i].second == pis)
|
||||
scs++;
|
||||
if (segments[i].first == pif || segments[i].second == pif) scf++;
|
||||
if (segments[i].first == pis || segments[i].second == pis) scs++;
|
||||
}
|
||||
if (scs <= 2) removePoint(pis);
|
||||
if (scf <= 2) removePoint(pif);
|
||||
if (scs <= 2 || scf <= 2) selSegment = -1;
|
||||
if (scene() != 0) scene()->update();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::appendPoint(const QPointF & p) {
|
||||
pol << p;
|
||||
if (pol.size() > 1)
|
||||
segments << QPair<int, int>(pol.size() - 2, pol.size() - 1);
|
||||
if (pol.size() > 1) segments << QPair<int, int>(pol.size() - 2, pol.size() - 1);
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
@@ -229,13 +235,13 @@ void BlockBusItem::setSquareNodes(bool yes) {
|
||||
|
||||
|
||||
void BlockBusItem::markAsInput() {
|
||||
mark_in = true;
|
||||
mark_in = true;
|
||||
mark_out = false;
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::markAsOutput() {
|
||||
mark_in = false;
|
||||
mark_in = false;
|
||||
mark_out = true;
|
||||
}
|
||||
|
||||
@@ -266,17 +272,23 @@ void BlockBusItem::simplify(bool full) {
|
||||
int s0 = segs[0], s1 = segs[1];
|
||||
QPointF cp = pol[p], sp[2];
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (segments[segs[i]].first == p) sp[i] = pol[segments[segs[i]].second];
|
||||
else sp[i] = pol[segments[segs[i]].first];
|
||||
if (segments[segs[i]].first == p)
|
||||
sp[i] = pol[segments[segs[i]].second];
|
||||
else
|
||||
sp[i] = pol[segments[segs[i]].first];
|
||||
}
|
||||
QLineF l0(sp[0], cp), l1(cp, sp[1]);
|
||||
if (qAbs(l0.angle() - l1.angle()) > 0.1) continue;
|
||||
if (segments[s0].first == p) {
|
||||
if (segments[s1].first == p) segments[s0].first = segments[s1].second;
|
||||
else segments[s0].first = segments[s1].first;
|
||||
if (segments[s1].first == p)
|
||||
segments[s0].first = segments[s1].second;
|
||||
else
|
||||
segments[s0].first = segments[s1].first;
|
||||
} else {
|
||||
if (segments[s1].first == p) segments[s0].second = segments[s1].second;
|
||||
else segments[s0].second = segments[s1].first;
|
||||
if (segments[s1].first == p)
|
||||
segments[s0].second = segments[s1].second;
|
||||
else
|
||||
segments[s0].second = segments[s1].first;
|
||||
}
|
||||
segments.removeAt(s1);
|
||||
pol.remove(p);
|
||||
@@ -292,8 +304,7 @@ void BlockBusItem::simplify(bool full) {
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::adjustLine() {
|
||||
}
|
||||
void BlockBusItem::adjustLine() {}
|
||||
|
||||
|
||||
int BlockBusItem::endpointCount() const {
|
||||
@@ -301,16 +312,16 @@ int BlockBusItem::endpointCount() const {
|
||||
}
|
||||
|
||||
|
||||
QList<BlockItem * > BlockBusItem::connectedBlocks() const {
|
||||
QList<BlockItemPin * > pins = connections_.values();
|
||||
QSet<BlockItem * > ret;
|
||||
foreach (BlockItemPin * p, pins)
|
||||
QList<BlockItem *> BlockBusItem::connectedBlocks() const {
|
||||
QList<BlockItemPin *> pins = connections_.values();
|
||||
QSet<BlockItem *> ret;
|
||||
foreach(BlockItemPin * p, pins)
|
||||
ret << p->parent();
|
||||
return ret.values();
|
||||
}
|
||||
|
||||
|
||||
QList<BlockItemPin * > BlockBusItem::connectedPins() const {
|
||||
QList<BlockItemPin *> BlockBusItem::connectedPins() const {
|
||||
return connections_.values();
|
||||
}
|
||||
|
||||
@@ -318,14 +329,14 @@ QList<BlockItemPin * > BlockBusItem::connectedPins() const {
|
||||
BlockBusItem::PointInfo BlockBusItem::pointInfo(QPointF pos) const {
|
||||
PointInfo ret;
|
||||
int pi = -1, si = -1;
|
||||
testPoint(pos, &pi, & si);
|
||||
testPoint(pos, &pi, &si);
|
||||
if (pi < 0 && si < 0) return ret;
|
||||
if (si >= 0) {
|
||||
ret.type = PointInfo::Type::Segment;
|
||||
} else {
|
||||
if (endpoints().contains(pi)) {
|
||||
ret.type = PointInfo::Type::Endpoint;
|
||||
ret.pin = connections_.value(pi, nullptr);
|
||||
ret.pin = connections_.value(pi, nullptr);
|
||||
} else
|
||||
ret.type = PointInfo::Type::Node;
|
||||
}
|
||||
@@ -350,9 +361,8 @@ void BlockBusItem::clearBusState() {
|
||||
|
||||
QByteArray BlockBusItem::save() const {
|
||||
ChunkStream cs;
|
||||
cs << cs.chunk(1, busType()) << cs.chunk(2, busName()) << cs.chunk(3, width()) << cs.chunk(4, pen())
|
||||
<< cs.chunk(5, brush()) << cs.chunk(6, pol) << cs.chunk(7, segments) << cs.chunk(8, props)
|
||||
<< cs.chunk(9, im_bus_scale) << cs.chunk(10, im_end_scale);
|
||||
cs << cs.chunk(1, busType()) << cs.chunk(2, busName()) << cs.chunk(3, width()) << cs.chunk(4, pen()) << cs.chunk(5, brush())
|
||||
<< cs.chunk(6, pol) << cs.chunk(7, segments) << cs.chunk(8, props) << cs.chunk(9, im_bus_scale) << cs.chunk(10, im_end_scale);
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
@@ -369,9 +379,9 @@ void BlockBusItem::load(const QByteArray & data) {
|
||||
case 4: setPen(cs.getData<QPen>()); break;
|
||||
case 5: setBrush(cs.getData<QBrush>()); break;
|
||||
case 6: pol = cs.getData<QPolygonF>(); break;
|
||||
case 7: segments = cs.getData<QList<QPair<int, int> > >(); break;
|
||||
case 8: props = cs.getData<QList<BlockItem::Property> >(); break;
|
||||
case 9: im_bus_scale = cs.getData<double>(); break;
|
||||
case 7: segments = cs.getData<QList<QPair<int, int>>>(); break;
|
||||
case 8: props = cs.getData<QList<BlockItem::Property>>(); break;
|
||||
case 9: im_bus_scale = cs.getData<double>(); break;
|
||||
case 10: im_end_scale = cs.getData<double>(); break;
|
||||
}
|
||||
}
|
||||
@@ -387,16 +397,16 @@ BlockBusItem * BlockBusItem::copy() const {
|
||||
void BlockBusItem::saveState() {
|
||||
segments_s = segments;
|
||||
ends_ind_s = ends_ind;
|
||||
ends_s = ends;
|
||||
pol_s = pol;
|
||||
ends_s = ends;
|
||||
pol_s = pol;
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::restoreState() {
|
||||
segments = segments_s;
|
||||
ends_ind = ends_ind_s;
|
||||
ends = ends_s;
|
||||
pol = pol_s;
|
||||
ends = ends_s;
|
||||
pol = pol_s;
|
||||
}
|
||||
|
||||
|
||||
@@ -429,8 +439,8 @@ bool BlockBusItem::checkDelete() {
|
||||
|
||||
|
||||
void BlockBusItem::emitAction(BlockItemBase::Action a) {
|
||||
qobject_cast<BlockView*>(scene()->views().back())->schemeAction(a, QList<QGraphicsItem*>() << this);
|
||||
qobject_cast<BlockView*>(scene()->views().back())->connectionsChanged();
|
||||
qobject_cast<BlockView *>(scene()->views().back())->schemeAction(a, QList<QGraphicsItem *>() << this);
|
||||
qobject_cast<BlockView *>(scene()->views().back())->connectionsChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -441,8 +451,7 @@ QVector<int> BlockBusItem::endpoints() const {
|
||||
counts[segments[i].second]++;
|
||||
}
|
||||
for (int i = 0; i < counts.size(); ++i) {
|
||||
if (counts[i] == 1)
|
||||
ret << i;
|
||||
if (counts[i] == 1) ret << i;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -455,16 +464,16 @@ QVector<int> BlockBusItem::endpointLine(int ep, double angle) const {
|
||||
if (ep < 0 || np < 0) return ret;
|
||||
if (pol[np] == pol[ep]) return ret;
|
||||
QLineF l(pol[ep], pol[np]);
|
||||
//qDebug() << "first" << l.angle() << angle << (l.angle() != angle);
|
||||
// qDebug() << "first" << l.angle() << angle << (l.angle() != angle);
|
||||
if (qAbs(l.angle() - angle) > 0.1) return ret;
|
||||
//qDebug() << "check next" << segments.size();
|
||||
// qDebug() << "check next" << segments.size();
|
||||
for (int i = 0; i < segments.size(); ++i) {
|
||||
//qDebug() << i << np << pointSegmentsCount(np);
|
||||
// qDebug() << i << np << pointSegmentsCount(np);
|
||||
if (np < 0) break;
|
||||
if (pointSegmentsCount(np) != 2) break;
|
||||
if (i > 0) {
|
||||
QLineF l(pol[pp], pol[np]);
|
||||
//qDebug() << i << l.angle() << angle;
|
||||
// qDebug() << i << l.angle() << angle;
|
||||
if (qAbs(l.angle() - angle) > 0.1) break;
|
||||
}
|
||||
ret << np;
|
||||
@@ -472,7 +481,6 @@ QVector<int> BlockBusItem::endpointLine(int ep, double angle) const {
|
||||
np = neighborSegmentPoint(np, &seg);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -492,8 +500,14 @@ int BlockBusItem::neighborSegmentPoint(int point, int * seg) const {
|
||||
if (point < 0 || !seg) return -1;
|
||||
for (int i = 0; i < segments.size(); ++i) {
|
||||
if (i == *seg) continue;
|
||||
if (segments[i].first == point) {*seg = i; return segments[i].second;}
|
||||
if (segments[i].second == point) {*seg = i; return segments[i].first ;}
|
||||
if (segments[i].first == point) {
|
||||
*seg = i;
|
||||
return segments[i].second;
|
||||
}
|
||||
if (segments[i].second == point) {
|
||||
*seg = i;
|
||||
return segments[i].first;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -502,57 +516,58 @@ int BlockBusItem::neighborSegmentPoint(int point, int * seg) const {
|
||||
void BlockBusItem::testPoint(QPointF pos, int * sel_point, int * sel_segment, bool for_trace) const {
|
||||
for (int i = 0; i < pol.size(); ++i) {
|
||||
if ((pol[i] - pos).manhattanLength() <= (for_trace ? 5. : 10.)) { // Point
|
||||
*sel_point = i;
|
||||
*sel_point = i;
|
||||
*sel_segment = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < segments.size(); ++i) {
|
||||
if (distPointToLine(pol[segments[i].first], pol[segments[i].second], pos) <= (for_trace ? 5. : 7.)) { // Segment
|
||||
*sel_point = -1;
|
||||
*sel_point = -1;
|
||||
*sel_segment = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
*sel_point = -1;
|
||||
*sel_point = -1;
|
||||
*sel_segment = -1;
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::hoverEnterEvent(QGraphicsSceneHoverEvent * e) {
|
||||
tt = bus_name + (bus_name.isEmpty() ? "" : "\n\n")
|
||||
+ tr("Add point: Ctrl + LeftClick\n"
|
||||
"Remove point\\segment: Ctrl + RightClick\n"
|
||||
"Remove connection: Shift + RightClick\n"
|
||||
"Move point\\segment: Shift + LeftPress\n"
|
||||
"Change trace mode: press Shift, when mouse move");
|
||||
tt = bus_name + (bus_name.isEmpty() ? "" : "\n\n") +
|
||||
tr("Add point: Ctrl + LeftClick\n"
|
||||
"Remove point\\segment: Ctrl + RightClick\n"
|
||||
"Remove connection: Shift + RightClick\n"
|
||||
"Move point\\segment: Shift + LeftPress\n"
|
||||
"Change trace mode: press Shift, when mouse move");
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::hoverMoveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
if (temp_) return;
|
||||
QPointF sp = e->scenePos();
|
||||
int pp = selPoint;
|
||||
int ps = selSegment;
|
||||
bool empt = !(selPoint >= 0 || selSegment >= 0);
|
||||
int pp = selPoint;
|
||||
int ps = selSegment;
|
||||
bool empt = !(selPoint >= 0 || selSegment >= 0);
|
||||
testPoint(sp, &selPoint, &selSegment);
|
||||
BlockView * bv = 0;
|
||||
if (!scene()->views().isEmpty()) {
|
||||
bv = qobject_cast<BlockView*>(scene()->views().back());
|
||||
bv = qobject_cast<BlockView *>(scene()->views().back());
|
||||
}
|
||||
if ((selPoint >= 0 && pp != selPoint) || (selSegment >= 0 && ps != selSegment)) {
|
||||
if ((selPoint >= 0 && pp != selPoint) || (selSegment >= 0 && ps != selSegment)) {
|
||||
if (bv) {
|
||||
if (bv->isBlockAnimationEnabled()) {
|
||||
setPointSize(0);
|
||||
anim_point_size.start();
|
||||
}
|
||||
} else setPointSize(anim_point_size.endValue().toDouble());
|
||||
} else
|
||||
setPointSize(anim_point_size.endValue().toDouble());
|
||||
}
|
||||
|
||||
if (selPoint >= 0 || selSegment >= 0) {
|
||||
if (empt) {
|
||||
QList<BlockItemPin * > pins = connectedPins();
|
||||
foreach (BlockItemPin * p, pins) {
|
||||
QList<BlockItemPin *> pins = connectedPins();
|
||||
foreach(BlockItemPin * p, pins) {
|
||||
p->animAccept();
|
||||
}
|
||||
}
|
||||
@@ -563,15 +578,15 @@ void BlockBusItem::hoverMoveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
}
|
||||
if (bv) bv->cur_bus = 0;
|
||||
setToolTip(QString());
|
||||
QList<QGraphicsItem * > il = scene()->items(sp, Qt::ContainsItemBoundingRect, Qt::DescendingOrder), bil;
|
||||
QList<QGraphicsItem *> il = scene()->items(sp, Qt::ContainsItemBoundingRect, Qt::DescendingOrder), bil;
|
||||
bil << this;
|
||||
for (int i = 0; i < il.size(); ++i) {
|
||||
QGraphicsItem * b = il[i];
|
||||
if ((b->data(bvidType).toInt() == bvitBus) && b != this) {
|
||||
int tp = -1, ts = -1;
|
||||
((BlockBusItem*)b)->testPoint(sp, &tp, &ts);
|
||||
((BlockBusItem *)b)->testPoint(sp, &tp, &ts);
|
||||
if (tp >= 0 || ts >= 0) {
|
||||
foreach (QGraphicsItem * b2, bil)
|
||||
foreach(QGraphicsItem * b2, bil)
|
||||
b2->stackBefore(b);
|
||||
break;
|
||||
}
|
||||
@@ -585,14 +600,13 @@ void BlockBusItem::hoverMoveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
void BlockBusItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
if (temp_) return;
|
||||
selPoint = selSegment = -1;
|
||||
setPen(pu); setBrush(bu);
|
||||
setPen(pu);
|
||||
setBrush(bu);
|
||||
setToolTip(QString());
|
||||
anim_point_size.stop();
|
||||
BlockView * bv = 0;
|
||||
if (!scene()->views().isEmpty())
|
||||
bv = qobject_cast<BlockView*>(scene()->views().back());
|
||||
if (bv && (QApplication::mouseButtons() == 0))
|
||||
bv->cur_bus = 0;
|
||||
if (!scene()->views().isEmpty()) bv = qobject_cast<BlockView *>(scene()->views().back());
|
||||
if (bv && (QApplication::mouseButtons() == 0)) bv->cur_bus = 0;
|
||||
update();
|
||||
QGraphicsObject::hoverLeaveEvent(e);
|
||||
}
|
||||
@@ -601,18 +615,16 @@ void BlockBusItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
if (temp_) return;
|
||||
lp = quantize(e->scenePos(), grid_step);
|
||||
if (e->button() != Qt::RightButton)
|
||||
bpol = pol;
|
||||
if (e->button() != Qt::RightButton) bpol = pol;
|
||||
BlockView * bv = 0;
|
||||
if (!scene()->views().isEmpty()) {
|
||||
bv = qobject_cast<BlockView*>(scene()->views().back());
|
||||
bv = qobject_cast<BlockView *>(scene()->views().back());
|
||||
}
|
||||
if (bv) {
|
||||
if (selPoint >= 0 || selSegment >= 0)
|
||||
bv->cur_bus = this;
|
||||
if (selPoint >= 0 || selSegment >= 0) bv->cur_bus = this;
|
||||
}
|
||||
if (new_segment) {
|
||||
qobject_cast<BlockView*>(scene()->views().back())->newBranchCancel();
|
||||
qobject_cast<BlockView *>(scene()->views().back())->newBranchCancel();
|
||||
}
|
||||
new_segment = false;
|
||||
if ((selPoint < 0 || selPoint > pol.size() - 1) && (selSegment < 0) && e->modifiers().testFlag(Qt::ShiftModifier)) {
|
||||
@@ -621,23 +633,24 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
}
|
||||
int btncnt = 0;
|
||||
if ((e->button() == Qt::LeftButton) && e->modifiers().testFlag(Qt::ShiftModifier)) {
|
||||
if (endpoints().contains(selPoint)) qobject_cast<BlockView*>(scene()->views().back())->startBusPointMove(bus_type);
|
||||
if (endpoints().contains(selPoint)) qobject_cast<BlockView *>(scene()->views().back())->startBusPointMove(bus_type);
|
||||
}
|
||||
if (e->buttons().testFlag(Qt::LeftButton )) btncnt++;
|
||||
if (e->buttons().testFlag(Qt::LeftButton)) btncnt++;
|
||||
if (e->buttons().testFlag(Qt::RightButton)) btncnt++;
|
||||
if (e->buttons().testFlag(QT_MID_BUTTON )) btncnt++;
|
||||
if (e->buttons().testFlag(QT_MID_BUTTON)) btncnt++;
|
||||
if (btncnt > 0) mm_mods = e->modifiers();
|
||||
if (btncnt >= 2 && e->button() == Qt::RightButton) {
|
||||
//qDebug() << "bus revert";
|
||||
// qDebug() << "bus revert";
|
||||
mm_cancel = true;
|
||||
moved = false;
|
||||
pol = bpol;
|
||||
moved = false;
|
||||
pol = bpol;
|
||||
prepareGeometryChange();
|
||||
return;
|
||||
}
|
||||
if (e->buttons().testFlag(Qt::LeftButton) && e->modifiers().testFlag(Qt::NoModifier)) {
|
||||
if (selSegment >= 0)
|
||||
press_pos = quantize(nearestPointOnLine(pol[segments[selSegment].first], pol[segments[selSegment].second], e->scenePos()), grid_step);
|
||||
press_pos =
|
||||
quantize(nearestPointOnLine(pol[segments[selSegment].first], pol[segments[selSegment].second], e->scenePos()), grid_step);
|
||||
else {
|
||||
if (selPoint >= 0)
|
||||
press_pos = pol[selPoint];
|
||||
@@ -646,10 +659,9 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
}
|
||||
if (max_ep >= 2) {
|
||||
if (endpointCount() >= max_ep)
|
||||
if (pointSegmentsCount(selPoint) >= 2 || selSegment >= 0)
|
||||
return;
|
||||
if (pointSegmentsCount(selPoint) >= 2 || selSegment >= 0) return;
|
||||
}
|
||||
qobject_cast<BlockView*>(scene()->views().back())->newBranch(this);
|
||||
qobject_cast<BlockView *>(scene()->views().back())->newBranch(this);
|
||||
new_segment = true;
|
||||
return;
|
||||
}
|
||||
@@ -657,7 +669,7 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
deleteLater();
|
||||
}
|
||||
if (e->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
//qDebug() << "remove" << selPoint << selSegment;
|
||||
// qDebug() << "remove" << selPoint << selSegment;
|
||||
if (e->buttons().testFlag(Qt::RightButton)) {
|
||||
if (selPoint >= 0 && selPoint <= pol.size() - 1) {
|
||||
removePoint(selPoint);
|
||||
@@ -673,8 +685,7 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
}
|
||||
}
|
||||
if (e->buttons().testFlag(Qt::LeftButton) && selSegment >= 0) {
|
||||
if (addPoint(e->scenePos()) >= 0)
|
||||
emitAction(BlockItemBase::BusPointAdd);
|
||||
if (addPoint(e->scenePos()) >= 0) emitAction(BlockItemBase::BusPointAdd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -693,12 +704,12 @@ void BlockBusItem::mouseMoveEvent(QGraphicsSceneMouseEvent * e) {
|
||||
}
|
||||
BlockView * bv = 0;
|
||||
if (!scene()->views().isEmpty()) {
|
||||
bv = qobject_cast<BlockView*>(scene()->views().back());
|
||||
bv = qobject_cast<BlockView *>(scene()->views().back());
|
||||
}
|
||||
qp = quantize(e->scenePos(), grid_step);
|
||||
lp = qp - lp;
|
||||
if (e->buttons().testFlag(Qt::LeftButton) && mm_mods.testFlag(Qt::NoModifier) && new_segment) {
|
||||
if (bv) qobject_cast<BlockView*>(scene()->views().back())->newBranchTrace(this, e->scenePos());
|
||||
if (bv) qobject_cast<BlockView *>(scene()->views().back())->newBranchTrace(this, e->scenePos());
|
||||
return;
|
||||
}
|
||||
if (new_segment) {
|
||||
@@ -707,8 +718,7 @@ void BlockBusItem::mouseMoveEvent(QGraphicsSceneMouseEvent * e) {
|
||||
} else {
|
||||
if (e->buttons().testFlag(Qt::LeftButton)) {
|
||||
lm_point = selPoint >= 0;
|
||||
if (selPoint >= 0 && selPoint <= pol.size() - 1)
|
||||
pol[selPoint] += lp;
|
||||
if (selPoint >= 0 && selPoint <= pol.size() - 1) pol[selPoint] += lp;
|
||||
if (selSegment >= 0 && selSegment <= segments.size() - 1) {
|
||||
pol[segments[selSegment].first] += lp;
|
||||
pol[segments[selSegment].second] += lp;
|
||||
@@ -722,14 +732,14 @@ void BlockBusItem::mouseMoveEvent(QGraphicsSceneMouseEvent * e) {
|
||||
|
||||
|
||||
void BlockBusItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * e) {
|
||||
mm_mods = Qt::KeyboardModifiers();
|
||||
mm_mods = Qt::KeyboardModifiers();
|
||||
int btncnt = 0;
|
||||
if (e->buttons().testFlag(Qt::LeftButton )) btncnt++;
|
||||
if (e->buttons().testFlag(Qt::LeftButton)) btncnt++;
|
||||
if (e->buttons().testFlag(Qt::RightButton)) btncnt++;
|
||||
if (e->buttons().testFlag(QT_MID_BUTTON )) btncnt++;
|
||||
if (e->buttons().testFlag(QT_MID_BUTTON)) btncnt++;
|
||||
if (btncnt == 0) mm_cancel = false;
|
||||
if (new_segment) {
|
||||
qobject_cast<BlockView*>(scene()->views().back())->newBranchAccept(this);
|
||||
qobject_cast<BlockView *>(scene()->views().back())->newBranchAccept(this);
|
||||
updateGeometry();
|
||||
selPoint = selSegment = -1;
|
||||
}
|
||||
@@ -739,7 +749,7 @@ void BlockBusItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * e) {
|
||||
emitAction(BlockItemBase::BusPointMove);
|
||||
} else {
|
||||
reconnect();
|
||||
emitAction( BlockItemBase::BusSegmentMove);
|
||||
emitAction(BlockItemBase::BusSegmentMove);
|
||||
}
|
||||
}
|
||||
moved = new_segment = false;
|
||||
|
||||
Reference in New Issue
Block a user