git-svn-id: svn://db.shs.com.ru/libs@316 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "blockbusitem.h"
|
||||
#include "blockview.h"
|
||||
|
||||
|
||||
BlockBusItem::BlockBusItem(bool temp): QGraphicsObject(), PropertyStorage() {
|
||||
@@ -44,7 +44,14 @@ void BlockBusItem::_init() {
|
||||
max_ep = 0;
|
||||
selPoint = selSegment = state_ = -1;
|
||||
pen_width = 2.;
|
||||
point_size = 3.;
|
||||
moved = deleted = mark_in = mark_out = new_segment = mm_cancel = lm_point = false;
|
||||
anim_point_size.setTargetObject(this);
|
||||
anim_point_size.setPropertyName("pointSize");
|
||||
anim_point_size.setStartValue(0);
|
||||
anim_point_size.setEasingCurve(QEasingCurve::OutQuad);
|
||||
anim_point_size.setEndValue(point_size);
|
||||
anim_point_size.setDuration(200);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +176,11 @@ void BlockBusItem::appendPoint(const QPointF & p) {
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::appendPoint(qreal x, qreal y) {
|
||||
appendPoint(QPointF(x, y));
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::clear() {
|
||||
pol.clear();
|
||||
segments.clear();
|
||||
@@ -176,6 +188,31 @@ void BlockBusItem::clear() {
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::movePolyline(const QPointF & dp) {
|
||||
pol.translate(dp);
|
||||
prepareGeometryChange();
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::movePoint(int index, const QPointF & dp) {
|
||||
pol[index] += dp;
|
||||
prepareGeometryChange();
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::setWidth(const double & w) {
|
||||
pen_width = w;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::setColor(const QColor & c) {
|
||||
pu.setColor(c);
|
||||
bu.setColor(c);
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::markAsInput() {
|
||||
mark_in = true;
|
||||
mark_out = false;
|
||||
@@ -457,7 +494,15 @@ void BlockBusItem::hoverEnterEvent(QGraphicsSceneHoverEvent * e) {
|
||||
void BlockBusItem::hoverMoveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
if (temp_) return;
|
||||
QPointF sp = e->scenePos();
|
||||
int pp = selPoint;
|
||||
testPoint(sp, &selPoint, &selSegment);
|
||||
if (selPoint >= 0 && pp < 0) {
|
||||
if (((BlockView *)scene()->views().back())->isBlockAnimationEnabled()) {
|
||||
setPointSize(0);
|
||||
anim_point_size.start();
|
||||
} else setPointSize(anim_point_size.endValue().toDouble());
|
||||
}
|
||||
|
||||
if (selPoint >= 0 || selSegment >= 0) {
|
||||
setToolTip(tt);
|
||||
update();
|
||||
@@ -488,6 +533,7 @@ void BlockBusItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
selPoint = selSegment = -1;
|
||||
setPen(pu); setBrush(bu);
|
||||
setToolTip(QString());
|
||||
anim_point_size.stop();
|
||||
update();
|
||||
QGraphicsObject::hoverLeaveEvent(e);
|
||||
}
|
||||
@@ -505,6 +551,8 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
return;
|
||||
}
|
||||
int btncnt = 0;
|
||||
if (endpoints().contains(selPoint) && e->button() == Qt::LeftButton)
|
||||
QMetaObject::invokeMethod(scene()->views().back(), "startBusPointMove", Q_ARG(int, busType()));
|
||||
if (e->buttons().testFlag(Qt::LeftButton)) btncnt++;
|
||||
if (e->buttons().testFlag(Qt::RightButton)) btncnt++;
|
||||
if (e->buttons().testFlag(Qt::MidButton)) btncnt++;
|
||||
@@ -515,8 +563,9 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
moved = false;
|
||||
QPointF lp = qp - press_pos;
|
||||
//qDebug() << lp;
|
||||
if (selPoint >= 0 && selPoint <= pol.size() - 1)
|
||||
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;
|
||||
@@ -624,11 +673,16 @@ void BlockBusItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * e) {
|
||||
}
|
||||
if (moved) {
|
||||
simplify(false);
|
||||
reconnect();
|
||||
emitAction(lm_point ? BlockItemBase::BusPointMove : BlockItemBase::BusSegmentMove);
|
||||
if (lm_point) {
|
||||
QMetaObject::invokeMethod(scene()->views().back(), "endBusPointMove", Qt::QueuedConnection);
|
||||
emitAction(BlockItemBase::BusPointMove);
|
||||
} else {
|
||||
reconnect();
|
||||
emitAction( BlockItemBase::BusSegmentMove);
|
||||
}
|
||||
}
|
||||
moved = new_segment = false;
|
||||
QGraphicsObject::mouseReleaseEvent(e);
|
||||
QGraphicsObject::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -716,7 +770,7 @@ void BlockBusItem::paint(QPainter * p, const QStyleOptionGraphicsItem * o, QWidg
|
||||
p->setPen(ph);
|
||||
p->setBrush(bh);
|
||||
p->translate(pol[selPoint]);
|
||||
p->drawEllipse(QPointF(0, 0), 3, 3);
|
||||
p->drawEllipse(QPointF(0, 0), point_size, point_size);
|
||||
p->restore();
|
||||
}
|
||||
if (selSegment >= 0) {
|
||||
@@ -728,6 +782,12 @@ void BlockBusItem::paint(QPainter * p, const QStyleOptionGraphicsItem * o, QWidg
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::setPointSize(double s) {
|
||||
point_size = s;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
QRectF BlockBusItem::boundingRect() const {
|
||||
QPolygonF p(pol);
|
||||
if (new_segment) p << new_end;
|
||||
|
||||
Reference in New Issue
Block a user