code brush

This commit is contained in:
Бычков Андрей
2022-07-01 17:30:34 +03:00
parent 2fb937a090
commit 883612e835
15 changed files with 49 additions and 260 deletions

View File

@@ -61,8 +61,6 @@ void BlockView::_init() {
scene_->installEventFilter(this);
scene_->addItem(&tmp_bus);
widget_thumb.setParent(this);
//widget_thumb.setAutoFillBackground(true);
//widget_thumb.setStyleSheet("background-color: rgb(255, 0, 0);");
widget_thumb.installEventFilter(this);
widget_thumb.setMouseTracking(true);
widget_thumb.show();
@@ -171,45 +169,23 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
foreach (QGraphicsItem * i, mil) {
if (i->data(bvidTmpItem).toBool()) continue;
if (i->data(bvidType).toInt() == bvitBlock) {
//emit blockDoubleClicked((BlockItem * )i);
QMetaObject::invokeMethod(this, "blockDoubleClicked", Qt::QueuedConnection, Q_ARG(BlockItem * , (BlockItem*)i));
QMetaObject::invokeMethod(this, [this, i](){blockDoubleClicked(qgraphicsitem_cast<BlockItem*>(i));}, Qt::QueuedConnection);
return true;
}
if (i->data(bvidType).toInt() == bvitBus) {
if (qgraphicsitem_cast<BlockBusItem*>(i)->isBusSelected()) {
//emit busDoubleClicked(qgraphicsitem_cast<BlockBusItem*>(i));
QMetaObject::invokeMethod(this, "busDoubleClicked", Qt::QueuedConnection, Q_ARG(BlockBusItem * , (BlockBusItem*)i));
QMetaObject::invokeMethod(this, [this, i](){busDoubleClicked(qgraphicsitem_cast<BlockBusItem*>(i));}, Qt::QueuedConnection);
return true;
}
}
}
//return true;
break;
/*case QEvent::GraphicsSceneHoverMove:
mil = scene_->items(scene_point);
mm_ci = (mil.isEmpty() ? 0 : mil.front());
if (mm_ci != 0) {
while (mm_ci->data(bvidType).toInt() == bvitBus) {
if (qgraphicsitem_cast<BlockBusItem*>(mm_ci))
if (qgraphicsitem_cast<BlockBusItem*>(mm_ci)->isBusSelected())
break;
if (mil.size() > 1) {
mm_ci = mil[1];
mil.pop_front();
} else {
mm_ci = 0;
break;
}
}
}
break;*/
case QEvent::GraphicsSceneMousePress:
if (mm_ci != 0) {
if (mm_ci->data(bvidTmpItem).toBool()) {
mm_ci = 0;
break;
}
//if (mm_ci->data(bvidItemSelection).toBool()) break;
}
if (me->buttons().testFlag(Qt::LeftButton )) btncnt++;
if (me->buttons().testFlag(Qt::RightButton)) btncnt++;
@@ -347,14 +323,9 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
}
}
cur_scl = qSqrt(transform().determinant());
//return true;
break;
case QEvent::GraphicsSceneMouseMove:
//qDebug() << "move" << (mm_ci != 0 ? mm_ci : 0) << mm_mods << mm_cancel << mm_drag;
/*if (ghost_) {
ghost_->setPos(quantize(me->scenePos(), grid_step));
}*/
//qDebug() << "move cur_bus" << cur_bus;
if (cur_bus) {
return false;
}
@@ -515,7 +486,6 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
if (me->modifiers().testFlag(Qt::ControlModifier) && me->buttons() != 0 && mm_ci == 0)
return true;
//qDebug() << "scene mouse";
//return true;
break;
case QEvent::GraphicsSceneMouseRelease:
if (me->buttons().testFlag(Qt::LeftButton)) btncnt++;
@@ -574,12 +544,15 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
if (match_bus == 0) {
BlockBusItem * nb = new BlockBusItem(tmp_bus);
addItem(nb, tmp_buses.isEmpty());
newBusCreated(nb);
foreach (BlockBusItem * b, tmp_buses) {
nb = new BlockBusItem(*b);
addItem(nb, b == tmp_buses.back());
newBusCreated(nb);
}
} else {
if (connectTmpToBus(match_bus)) {
newBusCreated(match_bus);
emitActionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << match_bus);
emit connectionsChanged();
}
@@ -589,8 +562,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
hideTmpBuses();
reconnectAll();
BlockItemPin * pin = getPin(scene_->items(me->scenePos()));
if (pin)
pin->hoverEnterEvent(0);
if (pin) pin->hoverEnterEvent(0);
m_trace_with_buses = prev_tcb;
}
clearBusStates();
@@ -689,7 +661,6 @@ void BlockView::mousePressEvent(QMouseEvent * event) {
press_point = event->pos();
if (event->buttons().testFlag(QT_MID_BUTTON) || event->buttons().testFlag(Qt::RightButton)) {
setCursor(Qt::ClosedHandCursor);
//sel_rect.hide();
if (sel_rect.scene())
scene_->removeItem(&sel_rect);
}
@@ -809,12 +780,12 @@ void BlockView::scrollContentsBy(int dx, int dy) {
if (isHidden()) return;
thumbShow();
restartTimer(timer_thumb, thumb_hide_delay);
QMetaObject::invokeMethod(&widget_thumb, "update", Qt::QueuedConnection);
QWidget * w = &widget_thumb;
QMetaObject::invokeMethod(this, [w](){w->update();}, Qt::QueuedConnection);
}
void BlockView::drawBackground(QPainter * painter, const QRectF & rect) {
// QGraphicsView::drawBackground(painter, rect);
if (mm_thumb) return;
float rx, ry, sx = grid_step, sy = grid_step;
double scl = qRound(1. / qSqrt(transform().determinant()));
@@ -889,6 +860,11 @@ void BlockView::clearGhost() {
}
void BlockView::getPinMC(bool * v) {
if (v) *v = m_pin_mc;
}
void BlockView::drawThumb() {
if (!minimap) return;
QPainter p(&widget_thumb);
@@ -945,7 +921,6 @@ void BlockView::thumbHide() {
thumb_anim.setEndValue(0.);
thumb_anim.start();
//qDebug() << "hide" << thumb_anim.startValue() << thumb_anim.endValue();
//widget_thumb.hide();
}
@@ -953,13 +928,8 @@ void BlockView::thumbShow() {
if (!minimap) return;
if (widget_thumb.isHidden() || (_talpha < 0.1)) drawSceneThumb();
thumb_anim.stop();
/*thumb_anim.setDuration(100);
thumb_anim.setStartValue(_thumb());
thumb_anim.setEndValue(1.);
thumb_anim.start();*/
_setThumb(1.);
//qDebug() << "show" << thumb_anim.startValue() << thumb_anim.endValue();
//widget_thumb.show();
}
@@ -1070,7 +1040,6 @@ bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) {
if (!(QList2QSet(bl0) & QList2QSet(bl1)).isEmpty()) return true;
BlockBusItem * nb = new BlockBusItem();
nb->setBusType(p0->busType());
//nb->setEndpointsNumber(3);
loadBus(nb);
if (!bl0.isEmpty() && !bl1.isEmpty()) { // connect two existing buses
} else {
@@ -1122,6 +1091,7 @@ bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) {
}
}
reconnectAll();
newBusCreated(nb);
emitActionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << nb);
emit connectionsChanged();
return true;
@@ -1286,7 +1256,6 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem
}
QRect sr = scene_->sceneRect().toRect();
int dx = sr.left() / grid_step, dy = sr.top() / grid_step;
//qDebug() << dp;
QPoint dp(-dx, -dy), qpt = quantize(scene_pos_to, grid_step).toPoint() / grid_step + dp;
QElapsedTimer tm;
tm.restart();
@@ -1359,8 +1328,6 @@ void BlockView::clearBusStates() {
if (i->data(bvidType).toInt() == bvitBus) {
BlockBusItem * b = qgraphicsitem_cast<BlockBusItem*>(i);
b->clearBusState();
// if (i != bus_from && i != match_bus)
//b->selPoint = b->selSegment = -1;
}
}
@@ -1436,7 +1403,6 @@ void BlockView::matchBus() {
}
}
}
//b->press_point = point;
iconnect = true;
b->setBusState(true);
b->selPoint = sp;
@@ -1479,8 +1445,6 @@ void BlockView::markPins(int bus_type) {
if (p->busType() == bus_type) {
if (p->state() == BlockItemPin::Disconnected)
p->setState(BlockItemPin::Accept);
// else
// p->animAccept();
}
}
}
@@ -1550,22 +1514,6 @@ void BlockView::moveBuses(const QList<QGraphicsItem * > & items, QPointF dp) {
foreach (BlockItemPin * p, pins) {
QList<int> ends = b->connections_.keys(p);
for (int i = 0; i < ends.size(); ++i) {
/*int isp = b->segmentPointPair(ends[i]);
QPointF sdp;
if (isp >= 0 && b->pol.size() > 2) {
sdp = b->pol[isp] - b->pol[ends[i]];
if (!sdp.isNull()) {
if (sdp.x() == 0. && dp.x() != 0.)
b->movePoint(isp, QPointF(dp.x(), 0.));
if (sdp.y() == 0. && dp.y() != 0.)
b->movePoint(isp, QPointF(0., dp.y()));
} else {
if (p->alignment() == Qt::AlignTop || p->alignment() == Qt::AlignBottom)
b->movePoint(isp, QPointF(dp.x(), 0.));
if (p->alignment() == Qt::AlignLeft || p->alignment() == Qt::AlignRight)
b->movePoint(isp, QPointF(0., dp.y()));
}
}*/
QPointF pdp = dp;
double ang = 0.;
switch (p->alignment()) {
@@ -1753,13 +1701,6 @@ void BlockView::startBusPointMove(int bus_type) {
}
void BlockView::endBusPointMove() {
move_bus_point = false;
unmarkPins();
reconnectAll();
}
void BlockView::pinHoverInOut(BlockItemPin * pin) {
//qDebug() << "pinHoverInOut" << pin << pin->state();
highlightNearPins(pin, QApplication::keyboardModifiers());
@@ -1771,7 +1712,7 @@ void BlockView::checkPaste(bool queued) {
bool ret = false;
if (mime)
ret = mime->hasFormat(_BlockView_Mime_);
if (queued) QMetaObject::invokeMethod(this, "pasteEnabledChanged", Qt::QueuedConnection, Q_ARG(bool, ret));
if (queued) QMetaObject::invokeMethod(this, [this, ret](){pasteEnabledChanged(ret);}, Qt::QueuedConnection);
else emit pasteEnabledChanged(ret);
}
@@ -1833,6 +1774,7 @@ void BlockView::newBranchAccept(BlockBusItem * item) {
match_bus = 0;
}
item->updateGeometry();
newBusCreated(item);
emitActionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << item);
emit connectionsChanged();
tmp_bus.clear();
@@ -1886,7 +1828,8 @@ void BlockView::sceneSelectionChanged() {
void BlockView::_setThumb(double v) {
_talpha = v;
QMetaObject::invokeMethod(&widget_thumb, "update", Qt::QueuedConnection);
QWidget * w = &widget_thumb;
QMetaObject::invokeMethod(this, [w](){w->update();}, Qt::QueuedConnection);
if (_talpha <= 0.01) widget_thumb.hide();
else widget_thumb.show();
}
@@ -2071,8 +2014,6 @@ void BlockView::removeSelected() {
QList<QGraphicsItem*> gi = scene_->selectedItems(), ai;
blockSignals(true);
QList<BlockBusItem * > sbuses = buses(), dbuses, wbuses = wrongConnectedBuses();
//foreach (BlockBusItem * i, wbuses)
// sbuses.removeOne(i);
foreach (BlockBusItem * i, sbuses)
if (i->connectedBlocks().isEmpty())
dbuses << i;