diff --git a/qad_blockview/blockbase.h b/qad_blockview/blockbase.h index 685e17c..7b19ef7 100644 --- a/qad_blockview/blockbase.h +++ b/qad_blockview/blockbase.h @@ -48,8 +48,8 @@ public: BusPointRemove, BusSegmentAdd, BusSegmentMove, - BusSegmentRemove - + BusSegmentRemove, + Paste }; }; diff --git a/qad_blockview/blockbusitem.cpp b/qad_blockview/blockbusitem.cpp index c6512e2..067108e 100644 --- a/qad_blockview/blockbusitem.cpp +++ b/qad_blockview/blockbusitem.cpp @@ -13,6 +13,8 @@ BlockBusItem::BlockBusItem(const BlockBusItem & other): QGraphicsObject(), Prope temp_ = false; _init(); setData(1005, "connection"); + setPen(other.pen()); + setBrush(other.brush()); setBusType(other.busType()); max_ep = other.max_ep; pol = other.pol; diff --git a/qad_blockview/blockitem.cpp b/qad_blockview/blockitem.cpp index e4af171..f6c3561 100644 --- a/qad_blockview/blockitem.cpp +++ b/qad_blockview/blockitem.cpp @@ -315,7 +315,8 @@ QByteArray BlockItem::save() const { foreach (BlockItemPin * p, pins()) { pp[p->text()] = p->properties(); } - cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, props) << cs.chunk(5, pp); + cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, props) << cs.chunk(5, pp) << cs.chunk(6, size()); + cs << cs.chunk(10, data(2000)) << cs.chunk(11, data(2001)); return cs.data(); } @@ -326,15 +327,18 @@ void BlockItem::load(const QByteArray & data) { QMap > _p; while (!cs.atEnd()) { switch (cs.read()) { - case 1: setPos(cs.getData()); break; - case 2: setRotation(cs.getData()); break; - case 3: props = cs.getData >(); break; - case 5: - _p = cs.getData > >(); - foreach (BlockItemPin * p, pins()) - if (_p.contains(p->text())) - p->properties() = _p[p->text()]; - break; + case 1: setPos(cs.getData()); break; + case 2: setRotation(cs.getData()); break; + case 3: props = cs.getData >(); break; + case 5: + _p = cs.getData > >(); + foreach (BlockItemPin * p, pins()) + if (_p.contains(p->text())) + p->properties() = _p[p->text()]; + break; + case 6: setSize(cs.getData()); break; + case 10: setData(2000, cs.getData()); break; + case 11: setData(2001, cs.getData()); break; } } } diff --git a/qad_blockview/blockview.cpp b/qad_blockview/blockview.cpp index 005a7b4..33e0679 100644 --- a/qad_blockview/blockview.cpp +++ b/qad_blockview/blockview.cpp @@ -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() << match_bus); + emitActionEvent(BlockItemBase::BusAdd, QList() << match_bus); emit connectionsChanged(); } } @@ -677,6 +678,12 @@ void BlockView::deleteCopyTemp() { } +void BlockView::emitActionEvent(BlockItemBase::Action action, QList 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(item)); connect((BlockBusItem*)item, SIGNAL(destroyed(QObject*)), this, SLOT(removedBus(QObject*)), Qt::UniqueConnection); - emit actionEvent(BlockItemBase::BusAdd, QList() << item); + emitActionEvent(BlockItemBase::BusAdd, QList() << 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() << item); + emitActionEvent(BlockItemBase::BlockAdd, QList() << item); return; } item->setData(1009, "decor"); @@ -900,7 +907,7 @@ bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) { } } reconnectAll(); - emit actionEvent(BlockItemBase::BusAdd, QList() << nb); + emitActionEvent(BlockItemBase::BusAdd, QList() << nb); emit connectionsChanged(); return true; } @@ -1226,15 +1233,25 @@ QList BlockView::internalBuses(const QList & item } -QList BlockView::selectedBlocks() { +QList BlockView::selectedBlocks() const { QList ret; - foreach (QGraphicsItem * b, sel_items) + QList sil = scene()->selectedItems(); + foreach (QGraphicsItem * b, sil) if (b->data(1006) == "item") ret << qgraphicsitem_cast(b); return ret; } +QList BlockView::selectedDecors() const { + QList 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() << item); + emitActionEvent(BlockItemBase::BusAdd, QList() << 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() << bus); + emitActionEvent(BlockItemBase::BusRemove, QList() << bus); emit connectionsChanged(); } void BlockView::removedBlock(QObject * o) { emit blockRemoved((BlockItem*)o); - emit actionEvent(BlockItemBase::BlockRemove, QList() << qgraphicsitem_cast((BlockItem*)o)); + emitActionEvent(BlockItemBase::BlockRemove, QList() << qgraphicsitem_cast((BlockItem*)o)); } @@ -1420,29 +1437,60 @@ void BlockView::zoomReset() { } -void BlockView::copySelected() { +void BlockView::copyToClipboard() { QList bll = selectedBlocks(); - if (bll.isEmpty()) return; + QList del = selectedDecors(); + qDebug() << "copy" << bll.size() << del.size(); + if (bll.isEmpty() && del.isEmpty()) return; QList 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 bll; QList bul; + QList 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); } diff --git a/qad_blockview/blockview.h b/qad_blockview/blockview.h index 9a87c11..e7ecdf4 100644 --- a/qad_blockview/blockview.h +++ b/qad_blockview/blockview.h @@ -100,10 +100,12 @@ protected: void unmarkPins(bool to_normal = false); void moveBuses(const QList & items, QPointF dp); QList internalBuses(const QList & items); - QList selectedBlocks(); + QList selectedBlocks() const; + QList selectedDecors() const; double _thumb() const {return _talpha;} void scrollFromThumb(); void deleteCopyTemp(); + void emitActionEvent(BlockItemBase::Action action, QList items); virtual void loadBus(BlockBusItem * bus) {} virtual void copyBlocks(QList items, QPointF offset) {} @@ -129,7 +131,7 @@ protected: Qt::KeyboardModifiers mm_mods; QPropertyAnimation thumb_anim; int timer_thumb, thumb_hide_delay; - bool mm_drag, new_bus, new_branch, moved, mm_cancel, iconnect, mm_copy, mm_thumb; + bool mm_drag, new_bus, new_branch, moved, mm_cancel, iconnect, mm_copy, mm_thumb, ae_enabled; bool grid_visible, grid_snap, pm_connect, navigation, m_connect, m_trace_with_buses, m_pin_mc, minimap; double grid_step, grid_points, cur_scl, _talpha, thumb_scl; @@ -164,8 +166,8 @@ public slots: void zoomOut() {zoom(1. / 1.2);} void zoomReset(); - void copySelected(); - void pasteSelected(); + void copyToClipboard(); + void pasteFromClipboard(); void reconnectAll(); void selectNone();