diff --git a/qad/blockview/blockbusitem.cpp b/qad/blockview/blockbusitem.cpp index 1b62ae4..aeb8625 100644 --- a/qad/blockview/blockbusitem.cpp +++ b/qad/blockview/blockbusitem.cpp @@ -19,6 +19,10 @@ BlockBusItem::BlockBusItem(const BlockBusItem & other): QGraphicsObject(), Prope max_ep = other.max_ep; pol = other.pol; segments = other.segments; + im_bus = other.im_bus; + im_end = other.im_end; + im_bus_scale = other.im_bus_scale; + im_end_scale = other.im_end_scale; updateGeometry(); } @@ -45,6 +49,7 @@ void BlockBusItem::_init() { selPoint = selSegment = state_ = -1; pen_width = 2.; point_size = 3.; + im_bus_scale = im_end_scale = 1.; moved = deleted = mark_in = mark_out = new_segment = mm_cancel = lm_point = false; anim_point_size.setTargetObject(this); anim_point_size.setPropertyName("pointSize"); @@ -320,7 +325,8 @@ void BlockBusItem::clearBusState() { QByteArray BlockBusItem::save() const { ChunkStream cs; cs << cs.chunk(1, busType()) << cs.chunk(2, busName()) << cs.chunk(3, width()) << cs.chunk(4, pen()) - << cs.chunk(5, brush()) << cs.chunk(6, pol) << cs.chunk(7, segments) << cs.chunk(8, props); + << cs.chunk(5, brush()) << cs.chunk(6, pol) << cs.chunk(7, segments) << cs.chunk(8, props) + << cs.chunk(9, im_bus_scale) << cs.chunk(10, im_end_scale); return cs.data(); } @@ -331,14 +337,16 @@ void BlockBusItem::load(const QByteArray & data) { ChunkStream cs(data); while (!cs.atEnd()) { switch (cs.read()) { - case 1: setBusType(cs.getData()); break; - case 2: setBusName(cs.getData()); break; - case 3: setWidth(cs.getData()); break; - case 4: setPen(cs.getData()); break; - case 5: setBrush(cs.getData()); break; - case 6: pol = cs.getData(); break; - case 7: segments = cs.getData > >(); break; - case 8: props = cs.getData >(); break; + case 1: setBusType(cs.getData()); break; + case 2: setBusName(cs.getData()); break; + case 3: setWidth(cs.getData()); break; + case 4: setPen(cs.getData()); break; + case 5: setBrush(cs.getData()); break; + case 6: pol = cs.getData(); break; + case 7: segments = cs.getData > >(); break; + case 8: props = cs.getData >(); break; + case 9: im_bus_scale = cs.getData(); break; + case 10: im_end_scale = cs.getData(); break; } } updateGeometry(); @@ -722,7 +730,8 @@ void BlockBusItem::paint(QPainter * p, const QStyleOptionGraphicsItem * o, QWidg QTransform tf; tf.translate(sp.x(), sp.y()); tf.rotate(-QLineF(sp, ep).angle()); - tf.translate(0., -im_bus.height() / 2.); + tf.translate(0., -im_bus.height() / 2. * im_bus_scale); + tf.scale(im_bus_scale, im_bus_scale); /* br.setTransform(tf); p->setPen(QPen(br, im_bus.height(), Qt::SolidLine, Qt::FlatCap, Qt::BevelJoin)); @@ -733,7 +742,7 @@ void BlockBusItem::paint(QPainter * p, const QStyleOptionGraphicsItem * o, QWidg p->setPen(Qt::NoPen); p->setBrush(br); //p->drawLine(QPointF(0., 0.), QPointF(QLineF(sp, ep).length(), 0.)); - p->drawRect(QRectF(0., 0., QLineF(sp, ep).length(), im_bus.height())); + p->drawRect(QRectF(0., 0., QLineF(sp, ep).length() / qMax(im_bus_scale, 1E-3), im_bus.height())); p->restore(); } } @@ -743,7 +752,8 @@ void BlockBusItem::paint(QPainter * p, const QStyleOptionGraphicsItem * o, QWidg QTransform tf; tf.translate(sp.x(), sp.y()); tf.rotate(-QLineF(sp, ep).angle()); - tf.translate(-pen_width, -im_end.height() / 2.); + tf.translate(-pen_width, -im_end.height() / 2. * im_end_scale); + tf.scale(im_end_scale, im_end_scale); p->save(); p->setTransform(tf, true); p->drawImage(0, 0, im_end); diff --git a/qad/blockview/blockbusitem.h b/qad/blockview/blockbusitem.h index 95ad312..d453e31 100644 --- a/qad/blockview/blockbusitem.h +++ b/qad/blockview/blockbusitem.h @@ -30,11 +30,15 @@ public: void setGridStep(double gs) {grid_step = gs;} void setEndpointsNumber(int num) {max_ep = num;} - void setImages(const QImage & bus, const QImage & end = QImage()) {im_bus = bus; im_end = end;} + void setImages(const QImage & bus, const QImage & end = QImage()) {im_bus = bus; im_end = end; update();} + void setBusImageScale(double s) {im_bus_scale = s; update();} + void setEndpointImageScale(double s) {im_end_scale = s; update();} void setBusType(int type_) {bus_type = type_;} void setBusName(const QString & name) {bus_name = name;} int busType() const {return bus_type;} QString busName() const {return bus_name;} + double busImageScale() const {return im_bus_scale;} + double endpointImageScale() const {return im_end_scale;} void appendPoint(const QPointF & p); void appendPoint(qreal x, qreal y); void testPoint(QPointF pos, int * sel_point, int * sel_segment); @@ -114,7 +118,7 @@ protected: QPolygonF pol, bpol, pol_s; Qt::KeyboardModifiers mm_mods; bool temp_; - double pen_width, grid_step; + double pen_width, grid_step, im_bus_scale, im_end_scale; int selPoint, selSegment, max_ep, bus_type, state_; bool moved, deleted, mark_in, mark_out, new_segment, mm_cancel, lm_point;