git-svn-id: svn://db.shs.com.ru/libs@39 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -74,6 +74,7 @@ void BlockItemPin::hoverLeaveEvent(QGraphicsSceneHoverEvent * e) {
|
||||
restoreState();
|
||||
}
|
||||
|
||||
#define BLOCKITEM_DEFAULT_PIN_MARGIN 20
|
||||
|
||||
BlockItem::BlockItem(QGraphicsItem * parent): QGraphicsObject(parent), PropertyStorage(),
|
||||
g_main(this), g_selection(this) {
|
||||
@@ -93,6 +94,7 @@ g_main(this), g_selection(this) {
|
||||
p.setCosmetic(true);
|
||||
g_selection.setPen(p);
|
||||
g_selection.setBrush(QColor(128, 128, 255, 32));
|
||||
pins_margin = BLOCKITEM_DEFAULT_PIN_MARGIN;
|
||||
//g_main.setBrush(QColor(128, 128, 128, 64));
|
||||
/*
|
||||
BlockItemPin * pin = new BlockItemPin(Qt::AlignRight, 0, this);
|
||||
@@ -249,7 +251,7 @@ QByteArray BlockItem::saveModel() {
|
||||
foreach (QGraphicsItem * i, decors_)
|
||||
s << i;*/
|
||||
ChunkStream cs;
|
||||
cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, size()) << cs.chunk(4, color()) << cs.chunk(5, pins()) << cs.chunk(6, decors_);
|
||||
cs << cs.chunk(1, pos()) << cs.chunk(2, rotation()) << cs.chunk(3, size()) << cs.chunk(4, color()) << cs.chunk(5, pins()) << cs.chunk(6, decors_) << cs.chunk(7, pins_margin);
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
@@ -299,6 +301,7 @@ void BlockItem::loadModel(const QByteArray & data) {
|
||||
dl = cs.getData<QList<QGraphicsItem * > >();
|
||||
foreach (QGraphicsItem * d, dl) addDecor(d);
|
||||
break;
|
||||
case 7: setPinsMargin(cs.getData<int>()); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,6 +345,7 @@ BlockItem * BlockItem::copy() const {
|
||||
ret->setColor(color());
|
||||
ret->setSelected(false);
|
||||
ret->props = props;
|
||||
ret->setPinsMargin(pinsMargin());
|
||||
QVector<BlockItemPin * > mp = pins();
|
||||
foreach (BlockItemPin * p, mp) {
|
||||
BlockItemPin * np = new BlockItemPin();
|
||||
@@ -398,8 +402,7 @@ void BlockItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event) {
|
||||
//QGraphicsItem::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
|
||||
#define _POS (i - ((cp.size() - 1) / 2)) * 20
|
||||
#define _POS(m) (i - ((cp.size() - 1) / 2)) * m
|
||||
|
||||
void BlockItem::arrangePins() {
|
||||
//double w = g_main.rect().width(), h = g_main.rect().height();
|
||||
@@ -408,13 +411,13 @@ void BlockItem::arrangePins() {
|
||||
foreach (BlockItemPin * p, pl)
|
||||
pins_[p->alignment()] << p;
|
||||
QList<BlockItemPin * > cp = pins_.value(Qt::AlignBottom);
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(_POS, bottom());
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(_POS(pins_margin), bottom());
|
||||
cp = pins_.value(Qt::AlignTop);
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(_POS, top());
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(_POS(pins_margin), top());
|
||||
cp = pins_.value(Qt::AlignLeft);
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(left(), _POS);
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(left(), _POS(pins_margin));
|
||||
cp = pins_.value(Qt::AlignRight);
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(right(), _POS);
|
||||
for (int i = 0; i < cp.size(); ++i) cp[i]->setPos(right(), _POS(pins_margin));
|
||||
}
|
||||
|
||||
#undef _POS
|
||||
|
||||
@@ -138,11 +138,13 @@ public:
|
||||
QSizeF size() const {return g_main.rect().size();}
|
||||
qreal width() const {return size().width();}
|
||||
qreal height() const {return size().height();}
|
||||
int pinsMargin() const {return pins_margin;}
|
||||
void setSize(QSizeF s) {_resize(s);}
|
||||
void setSize(qreal w, qreal h) {setSize(QSizeF(w, h));}
|
||||
void setWidth(qreal w) {setSize(QSizeF(w, size().height()));}
|
||||
void setHeight(qreal h) {setSize(QSizeF(size().width(), h));}
|
||||
|
||||
void setPinsMargin(int marg) {if (marg > 1 && marg < 256) pins_margin = marg; arrangePins();}
|
||||
|
||||
QByteArray saveModel();
|
||||
void loadModel(const QByteArray & data);
|
||||
QByteArray save();
|
||||
@@ -164,6 +166,7 @@ protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant & value);
|
||||
|
||||
QGraphicsRectItem g_main, g_selection;
|
||||
int pins_margin;
|
||||
QColor col;
|
||||
QMap<Qt::Alignment, QList<BlockItemPin * > > pins_;
|
||||
QList<QGraphicsItem * > decors_;
|
||||
|
||||
Reference in New Issue
Block a user