git-svn-id: svn://db.shs.com.ru/libs@169 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -48,8 +48,8 @@ public:
|
||||
BusPointRemove,
|
||||
BusSegmentAdd,
|
||||
BusSegmentMove,
|
||||
BusSegmentRemove
|
||||
|
||||
BusSegmentRemove,
|
||||
Paste
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<QString, QList<BlockItem::Property> > _p;
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: setPos(cs.getData<QPointF>()); break;
|
||||
case 2: setRotation(cs.getData<qreal>()); break;
|
||||
case 3: props = cs.getData<QList<BlockItem::Property> >(); break;
|
||||
case 5:
|
||||
_p = cs.getData<QMap<QString, QList<BlockItem::Property> > >();
|
||||
foreach (BlockItemPin * p, pins())
|
||||
if (_p.contains(p->text()))
|
||||
p->properties() = _p[p->text()];
|
||||
break;
|
||||
case 1: setPos(cs.getData<QPointF>()); break;
|
||||
case 2: setRotation(cs.getData<qreal>()); break;
|
||||
case 3: props = cs.getData<QList<BlockItem::Property> >(); break;
|
||||
case 5:
|
||||
_p = cs.getData<QMap<QString, QList<BlockItem::Property> > >();
|
||||
foreach (BlockItemPin * p, pins())
|
||||
if (_p.contains(p->text()))
|
||||
p->properties() = _p[p->text()];
|
||||
break;
|
||||
case 6: setSize(cs.getData<QSizeF>()); break;
|
||||
case 10: setData(2000, cs.getData<QVariant>()); break;
|
||||
case 11: setData(2001, cs.getData<QVariant>()); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -100,10 +100,12 @@ protected:
|
||||
void unmarkPins(bool to_normal = false);
|
||||
void moveBuses(const QList<QGraphicsItem * > & items, QPointF dp);
|
||||
QList<BlockBusItem * > internalBuses(const QList<BlockItem * > & items);
|
||||
QList<BlockItem * > selectedBlocks();
|
||||
QList<BlockItem * > selectedBlocks() const;
|
||||
QList<QGraphicsItem * > selectedDecors() const;
|
||||
double _thumb() const {return _talpha;}
|
||||
void scrollFromThumb();
|
||||
void deleteCopyTemp();
|
||||
void emitActionEvent(BlockItemBase::Action action, QList<QGraphicsItem * > items);
|
||||
|
||||
virtual void loadBus(BlockBusItem * bus) {}
|
||||
virtual void copyBlocks(QList<BlockItem * > 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();
|
||||
|
||||
Reference in New Issue
Block a user