BlockView right-click, ctrl+left-click fixes

This commit is contained in:
2020-09-10 19:00:46 +03:00
parent d35be49a57
commit d65f09b1c5
2 changed files with 34 additions and 14 deletions

View File

@@ -520,10 +520,16 @@ void BlockBusItem::hoverMoveEvent(QGraphicsSceneHoverEvent * e) {
int ps = selSegment; int ps = selSegment;
bool empt = !(selPoint >= 0 || selSegment >= 0); bool empt = !(selPoint >= 0 || selSegment >= 0);
testPoint(sp, &selPoint, &selSegment); testPoint(sp, &selPoint, &selSegment);
BlockView * bv = 0;
if (!scene()->views().isEmpty()) {
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 (((BlockView *)scene()->views().back())->isBlockAnimationEnabled()) { if (bv) {
if (bv->isBlockAnimationEnabled()) {
setPointSize(0); setPointSize(0);
anim_point_size.start(); anim_point_size.start();
}
} else setPointSize(anim_point_size.endValue().toDouble()); } else setPointSize(anim_point_size.endValue().toDouble());
} }
@@ -536,8 +542,10 @@ void BlockBusItem::hoverMoveEvent(QGraphicsSceneHoverEvent * e) {
} }
setToolTip(tt); setToolTip(tt);
update(); update();
if (bv) bv->cur_bus = this;
return; return;
} }
if (bv) bv->cur_bus = 0;
setToolTip(QString()); 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; bil << this;
@@ -572,6 +580,13 @@ void BlockBusItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) { void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
if (temp_) return; if (temp_) return;
lp = quantize(e->scenePos(), grid_step); lp = quantize(e->scenePos(), grid_step);
if (e->button() != Qt::RightButton)
bpol = pol;
BlockView * bv = 0;
if (!scene()->views().isEmpty()) {
bv = qobject_cast<BlockView*>(scene()->views().back());
}
if (bv) bv->cur_bus = this;
if (new_segment) { if (new_segment) {
QMetaObject::invokeMethod(scene()->views().back(), "newBranchCancel"); QMetaObject::invokeMethod(scene()->views().back(), "newBranchCancel");
} }
@@ -582,7 +597,6 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
} }
int btncnt = 0; int btncnt = 0;
if ((e->button() == Qt::LeftButton) && e->modifiers().testFlag(Qt::ShiftModifier)) { if ((e->button() == Qt::LeftButton) && e->modifiers().testFlag(Qt::ShiftModifier)) {
bpol = pol;
if (endpoints().contains(selPoint)) if (endpoints().contains(selPoint))
QMetaObject::invokeMethod(scene()->views().back(), "startBusPointMove", Q_ARG(int, busType())); QMetaObject::invokeMethod(scene()->views().back(), "startBusPointMove", Q_ARG(int, busType()));
} }
@@ -594,7 +608,7 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
//qDebug() << "bus revert"; //qDebug() << "bus revert";
mm_cancel = true; mm_cancel = true;
moved = false; moved = false;
QPointF lp = qp - press_pos; /*QPointF lp = qp - press_pos;
//qDebug() << lp; //qDebug() << lp;
if (selPoint >= 0 && selPoint <= pol.size() - 1) { if (selPoint >= 0 && selPoint <= pol.size() - 1) {
pol[selPoint] += lp; pol[selPoint] += lp;
@@ -603,7 +617,8 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
pol[segments[selSegment].first] += lp; pol[segments[selSegment].first] += lp;
pol[segments[selSegment].second] += lp; pol[segments[selSegment].second] += lp;
} }
moved = true; moved = true;*/
pol = bpol;
prepareGeometryChange(); prepareGeometryChange();
return; return;
} }
@@ -629,6 +644,7 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
deleteLater(); deleteLater();
} }
if (e->modifiers().testFlag(Qt::ControlModifier)) { if (e->modifiers().testFlag(Qt::ControlModifier)) {
//qDebug() << "remove" << selPoint << selSegment;
if (e->buttons().testFlag(Qt::RightButton)) { if (e->buttons().testFlag(Qt::RightButton)) {
if (selPoint >= 0 && selPoint <= pol.size() - 1) { if (selPoint >= 0 && selPoint <= pol.size() - 1) {
removePoint(selPoint); removePoint(selPoint);
@@ -677,7 +693,6 @@ void BlockBusItem::mouseMoveEvent(QGraphicsSceneMouseEvent * e) {
new_end = qp; new_end = qp;
prepareGeometryChange(); prepareGeometryChange();
} else { } else {
if (bv) bv->cur_bus = this;
if (e->buttons().testFlag(Qt::LeftButton)) { if (e->buttons().testFlag(Qt::LeftButton)) {
lm_point = selPoint >= 0; lm_point = selPoint >= 0;
if (selPoint >= 0 && selPoint <= pol.size() - 1) if (selPoint >= 0 && selPoint <= pol.size() - 1)
@@ -687,6 +702,7 @@ void BlockBusItem::mouseMoveEvent(QGraphicsSceneMouseEvent * e) {
pol[segments[selSegment].second] += lp; pol[segments[selSegment].second] += lp;
} }
moved = true; moved = true;
//if (bv) bv->bus_moved = true;
prepareGeometryChange(); prepareGeometryChange();
} }
} }

View File

@@ -1,4 +1,5 @@
#include "blockview.h" #include "blockview.h"
#include "qad_types.h"
#include <qmath.h> #include <qmath.h>
#include <QScrollBar> #include <QScrollBar>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
@@ -229,12 +230,11 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
block_emit_selection = false; block_emit_selection = false;
emit selectionChanged(); emit selectionChanged();
} }
if (mm_cancel) { //qDebug() << cur_bus;
if (cur_bus) { if (cur_bus) {
cur_bus->pol = cur_bus->bpol; return false;
cur_bus->prepareGeometryChange();
cur_bus = 0;
} }
if (mm_cancel) {
if (mm_copy) { if (mm_copy) {
deleteCopyTemp(); deleteCopyTemp();
mm_copy = moved = false; mm_copy = moved = false;
@@ -357,6 +357,9 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
/*if (ghost_) { /*if (ghost_) {
ghost_->setPos(quantize(me->scenePos(), grid_step)); ghost_->setPos(quantize(me->scenePos(), grid_step));
}*/ }*/
if (cur_bus) {
return false;
}
if (mm_ci) if (mm_ci)
if (mm_ci->data(bvidInvalidItem).toBool()) { if (mm_ci->data(bvidInvalidItem).toBool()) {
mm_ci = 0; mm_ci = 0;
@@ -518,6 +521,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
if (me->buttons().testFlag(Qt::LeftButton)) btncnt++; if (me->buttons().testFlag(Qt::LeftButton)) btncnt++;
if (me->buttons().testFlag(Qt::RightButton)) btncnt++; if (me->buttons().testFlag(Qt::RightButton)) btncnt++;
if (me->buttons().testFlag(Qt::MidButton)) btncnt++; if (me->buttons().testFlag(Qt::MidButton)) btncnt++;
cur_bus = 0;
mm_cancel = btncnt > 0; mm_cancel = btncnt > 0;
if (mm_cancel || (me->button() == Qt::MidButton) || (me->button() == Qt::RightButton)) { if (mm_cancel || (me->button() == Qt::MidButton) || (me->button() == Qt::RightButton)) {
mm_ci = 0; mm_ci = 0;