|
|
|
|
@@ -65,6 +65,7 @@ void BlockView::_init() {
|
|
|
|
|
smode = BlockView::MultiSelection;
|
|
|
|
|
cur_scl = thumb_scl = 1.;
|
|
|
|
|
_talpha = 0.;
|
|
|
|
|
ae_enabled = true;
|
|
|
|
|
thumb_size = QSizeF(200, 200);
|
|
|
|
|
sel_rect.setZValue(999.);
|
|
|
|
|
sel_rect.hide();
|
|
|
|
|
@@ -471,7 +472,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
|
|
|
|
if (moved) {
|
|
|
|
|
moved = false;
|
|
|
|
|
reconnectAll();
|
|
|
|
|
emit actionEvent(BlockItemBase::BlockCopy, ai);
|
|
|
|
|
emitActionEvent(BlockItemBase::BlockCopy, ai);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (new_branch) {
|
|
|
|
|
@@ -482,7 +483,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
|
|
|
|
foreach (QGraphicsItem * b, sel_items)
|
|
|
|
|
if (b->data(1006) == "item")
|
|
|
|
|
ci << b;
|
|
|
|
|
emit actionEvent(BlockItemBase::BlockMove, ci);
|
|
|
|
|
emitActionEvent(BlockItemBase::BlockMove, ci);
|
|
|
|
|
reconnectAll();
|
|
|
|
|
}
|
|
|
|
|
moved = mm_copy = false;
|
|
|
|
|
@@ -494,7 +495,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) {
|
|
|
|
|
addItem(nb);
|
|
|
|
|
} else {
|
|
|
|
|
if (connectTmpToBus(match_bus)) {
|
|
|
|
|
emit actionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << match_bus);
|
|
|
|
|
emitActionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << match_bus);
|
|
|
|
|
emit connectionsChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -677,6 +678,12 @@ void BlockView::deleteCopyTemp() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BlockView::emitActionEvent(BlockItemBase::Action action, QList<QGraphicsItem * > items) {
|
|
|
|
|
if (!ae_enabled) return;
|
|
|
|
|
emit actionEvent(action, items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BlockView::drawThumb() {
|
|
|
|
|
if (!minimap) return;
|
|
|
|
|
QPainter p(&widget_thumb);
|
|
|
|
|
@@ -765,13 +772,13 @@ void BlockView::addItem(QGraphicsItem * item) {
|
|
|
|
|
if (item->data(1005) == "connection") {
|
|
|
|
|
loadBus(qgraphicsitem_cast<BlockBusItem*>(item));
|
|
|
|
|
connect((BlockBusItem*)item, SIGNAL(destroyed(QObject*)), this, SLOT(removedBus(QObject*)), Qt::UniqueConnection);
|
|
|
|
|
emit actionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << item);
|
|
|
|
|
emitActionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << item);
|
|
|
|
|
emit connectionsChanged();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (item->data(1006) == "item") {
|
|
|
|
|
connect((BlockItem*)item, SIGNAL(destroyed(QObject*)), this, SLOT(removedBlock(QObject*)), Qt::UniqueConnection);
|
|
|
|
|
emit actionEvent(BlockItemBase::BlockAdd, QList<QGraphicsItem*>() << item);
|
|
|
|
|
emitActionEvent(BlockItemBase::BlockAdd, QList<QGraphicsItem*>() << item);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
item->setData(1009, "decor");
|
|
|
|
|
@@ -900,7 +907,7 @@ bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
reconnectAll();
|
|
|
|
|
emit actionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << nb);
|
|
|
|
|
emitActionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << nb);
|
|
|
|
|
emit connectionsChanged();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@@ -1226,15 +1233,25 @@ QList<BlockBusItem * > BlockView::internalBuses(const QList<BlockItem * > & item
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<BlockItem * > BlockView::selectedBlocks() {
|
|
|
|
|
QList<BlockItem * > BlockView::selectedBlocks() const {
|
|
|
|
|
QList<BlockItem * > ret;
|
|
|
|
|
foreach (QGraphicsItem * b, sel_items)
|
|
|
|
|
QList<QGraphicsItem * > sil = scene()->selectedItems();
|
|
|
|
|
foreach (QGraphicsItem * b, sil)
|
|
|
|
|
if (b->data(1006) == "item")
|
|
|
|
|
ret << qgraphicsitem_cast<BlockItem*>(b);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<QGraphicsItem * > BlockView::selectedDecors() const {
|
|
|
|
|
QList<QGraphicsItem * > ret, sil = decors();
|
|
|
|
|
foreach (QGraphicsItem * b, sil)
|
|
|
|
|
if (b->isSelected())
|
|
|
|
|
ret << b;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BlockView::adjustThumb() {
|
|
|
|
|
if (!scene()) return;
|
|
|
|
|
QSizeF sr = sceneRect().size(), tr;
|
|
|
|
|
@@ -1310,7 +1327,7 @@ void BlockView::newBranchAccept(BlockBusItem * item) {
|
|
|
|
|
match_bus = 0;
|
|
|
|
|
}
|
|
|
|
|
item->updateGeometry();
|
|
|
|
|
emit actionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << item);
|
|
|
|
|
emitActionEvent(BlockItemBase::BusAdd, QList<QGraphicsItem*>() << item);
|
|
|
|
|
emit connectionsChanged();
|
|
|
|
|
tmp_bus.clear();
|
|
|
|
|
}
|
|
|
|
|
@@ -1330,14 +1347,14 @@ void BlockView::removedBus(QObject * o) {
|
|
|
|
|
reconnectAll();
|
|
|
|
|
BlockBusItem * bus = (BlockBusItem*)o;
|
|
|
|
|
if (bus->property("_nodelete_").toBool()) return;
|
|
|
|
|
emit actionEvent(BlockItemBase::BusRemove, QList<QGraphicsItem*>() << bus);
|
|
|
|
|
emitActionEvent(BlockItemBase::BusRemove, QList<QGraphicsItem*>() << bus);
|
|
|
|
|
emit connectionsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BlockView::removedBlock(QObject * o) {
|
|
|
|
|
emit blockRemoved((BlockItem*)o);
|
|
|
|
|
emit actionEvent(BlockItemBase::BlockRemove, QList<QGraphicsItem*>() << qgraphicsitem_cast<QGraphicsItem*>((BlockItem*)o));
|
|
|
|
|
emitActionEvent(BlockItemBase::BlockRemove, QList<QGraphicsItem*>() << qgraphicsitem_cast<QGraphicsItem*>((BlockItem*)o));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1420,29 +1437,60 @@ void BlockView::zoomReset() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BlockView::copySelected() {
|
|
|
|
|
void BlockView::copyToClipboard() {
|
|
|
|
|
QList<BlockItem*> bll = selectedBlocks();
|
|
|
|
|
if (bll.isEmpty()) return;
|
|
|
|
|
QList<QGraphicsItem*> del = selectedDecors();
|
|
|
|
|
qDebug() << "copy" << bll.size() << del.size();
|
|
|
|
|
if (bll.isEmpty() && del.isEmpty()) return;
|
|
|
|
|
QList<BlockBusItem*> bul = internalBuses(bll);
|
|
|
|
|
QByteArray ba;
|
|
|
|
|
QDataStream s(&ba, QIODevice::ReadWrite);
|
|
|
|
|
s << bll << bul;
|
|
|
|
|
s << uint(0x89abcdef) << bll << bul << del;
|
|
|
|
|
QMimeData * mime = new QMimeData();
|
|
|
|
|
mime->setData(_BlockView_Mime_, ba);
|
|
|
|
|
QApplication::clipboard()->setMimeData(mime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BlockView::pasteSelected() {
|
|
|
|
|
void BlockView::pasteFromClipboard() {
|
|
|
|
|
const QMimeData * mime = QApplication::clipboard()->mimeData();
|
|
|
|
|
if (!mime) return;
|
|
|
|
|
if (!mime->hasFormat(_BlockView_Mime_)) return;
|
|
|
|
|
QByteArray ba = mime->data(_BlockView_Mime_);
|
|
|
|
|
qDebug() << "paste" << ba.size();
|
|
|
|
|
if (ba.isEmpty()) return;
|
|
|
|
|
QList<BlockItem*> bll;
|
|
|
|
|
QList<BlockBusItem*> bul;
|
|
|
|
|
QList<QGraphicsItem*> del, gl;
|
|
|
|
|
uint hdr = 0;
|
|
|
|
|
QDataStream s(ba);
|
|
|
|
|
s >> bll >> bul;
|
|
|
|
|
s >> hdr;
|
|
|
|
|
if (hdr != 0x89abcdef) return;
|
|
|
|
|
s >> bll >> bul >> del;
|
|
|
|
|
int all = bll.size() + bul.size() + del.size();
|
|
|
|
|
if (all == 0) return;
|
|
|
|
|
QRectF br;
|
|
|
|
|
foreach (BlockItem * b, bll) {
|
|
|
|
|
br |= b->boundingRect().translated(b->pos());
|
|
|
|
|
gl << b;
|
|
|
|
|
}
|
|
|
|
|
foreach (BlockBusItem * b, bul)
|
|
|
|
|
gl << b;
|
|
|
|
|
foreach (QGraphicsItem * b, del)
|
|
|
|
|
br |= b->boundingRect().translated(b->pos());
|
|
|
|
|
gl << del;
|
|
|
|
|
QPointF copy_dp;
|
|
|
|
|
if (underMouse()) copy_dp = mapToScene(mapFromGlobal(QCursor::pos()));
|
|
|
|
|
else copy_dp = mapToScene(rect().center());
|
|
|
|
|
copy_dp -= br.center();
|
|
|
|
|
ae_enabled = false;
|
|
|
|
|
if (!bll.isEmpty()) copyBlocks(bll, copy_dp);
|
|
|
|
|
if (!bul.isEmpty()) copyBuses(bul, copy_dp);
|
|
|
|
|
foreach (QGraphicsItem * i, del)
|
|
|
|
|
i->setPos(i->pos() + copy_dp);
|
|
|
|
|
addItems(del);
|
|
|
|
|
ae_enabled = true;
|
|
|
|
|
emitActionEvent(BlockItemBase::Paste, gl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1487,7 +1535,7 @@ void BlockView::removeSelected() {
|
|
|
|
|
blockSignals(false);
|
|
|
|
|
foreach (QGraphicsItem * i, ai)
|
|
|
|
|
emit blockRemoved((BlockItem*)i);
|
|
|
|
|
emit actionEvent(BlockItemBase::BlockRemove, ai);
|
|
|
|
|
emitActionEvent(BlockItemBase::BlockRemove, ai);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|