From 055b8a9480f3f27319688f26993f7498fa39213f Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Fri, 14 Aug 2020 14:08:31 +0300 Subject: [PATCH] bus joint paint now configured with BlockView::setBusSquareNodes(), square or round. By default round --- qad/blockview/blockbusitem.cpp | 17 ++++++++++++++--- qad/blockview/blockbusitem.h | 3 ++- qad/blockview/blockview.cpp | 17 ++++++++++++++--- qad/blockview/blockview.h | 5 ++++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/qad/blockview/blockbusitem.cpp b/qad/blockview/blockbusitem.cpp index 5d17bf3..28276e6 100644 --- a/qad/blockview/blockbusitem.cpp +++ b/qad/blockview/blockbusitem.cpp @@ -16,6 +16,7 @@ BlockBusItem::BlockBusItem(const BlockBusItem & other): QGraphicsObject(), Prope setPen(other.pen()); setBrush(other.brush()); setBusType(other.busType()); + square_node = other.square_node; max_ep = other.max_ep; pol = other.pol; segments = other.segments; @@ -46,6 +47,7 @@ void BlockBusItem::_init() { bu.setColor(Qt::darkGray); } setPen(pu); setBrush(bu); + square_node = false; max_ep = 0; selPoint = selSegment = state_ = -1; pen_width = 2.; @@ -219,6 +221,12 @@ void BlockBusItem::setColor(const QColor & c) { } +void BlockBusItem::setSquareNodes(bool yes) { + square_node = yes; + update(); +} + + void BlockBusItem::markAsInput() { mark_in = true; mark_out = false; @@ -299,7 +307,7 @@ QList BlockBusItem::connectedBlocks() const { QSet ret; foreach (BlockItemPin * p, pins) ret << p->parent(); - return ret.toList(); + return ret.values(); } @@ -678,7 +686,7 @@ void BlockBusItem::mouseMoveEvent(QGraphicsSceneMouseEvent * e) { void BlockBusItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * e) { - mm_mods = 0; + mm_mods = Qt::KeyboardModifiers(); int btncnt = 0; if (e->buttons().testFlag(Qt::LeftButton)) btncnt++; if (e->buttons().testFlag(Qt::RightButton)) btncnt++; @@ -727,7 +735,10 @@ void BlockBusItem::paint(QPainter * p, const QStyleOptionGraphicsItem * o, QWidg p->setPen(_pen); p->drawLine(pol[segments[i].first], pol[segments[i].second]); if (pointSegmentsCount(segments[i].first) > 2) { - p->drawEllipse(pol[segments[i].first], pen_width*0.7, pen_width*0.7); + _pen.setWidthF(pen_width * 1.8 + 2.); + _pen.setCapStyle(square_node ? Qt::SquareCap : Qt::RoundCap); + p->setPen(_pen); + p->drawPoint(pol[segments[i].first]); } } p->setPen(_pen); diff --git a/qad/blockview/blockbusitem.h b/qad/blockview/blockbusitem.h index 776a644..61eed85 100644 --- a/qad/blockview/blockbusitem.h +++ b/qad/blockview/blockbusitem.h @@ -64,6 +64,7 @@ public: double width() const {return pen_width;} void setWidth(const double & w); void setColor(const QColor & c); + void setSquareNodes(bool yes); int addPoint(const QPointF & point, bool update = true); int segmentPointPair(int point, int * seg = 0) const; void removePoint(int index); @@ -122,7 +123,7 @@ protected: QImage im_bus, im_end; QPolygonF pol, bpol, pol_s; Qt::KeyboardModifiers mm_mods; - bool temp_; + bool temp_, square_node; 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; diff --git a/qad/blockview/blockview.cpp b/qad/blockview/blockview.cpp index 8a44783..418c5f7 100644 --- a/qad/blockview/blockview.cpp +++ b/qad/blockview/blockview.cpp @@ -8,6 +8,7 @@ #include #include #include +#include const QString _BlockView_Mime_ = "_BlockView_copypaste_"; @@ -45,9 +46,9 @@ void BlockView::_init() { smode = BlockView::MultiSelection; cur_scl = thumb_scl = prev_app_scale = 1.; _talpha = 0.; - ae_enabled = is_block_anim = true; - is_nav_anim = true; + ae_enabled = is_block_anim = is_nav_anim = true; nav_prev_aa = nav_prev_imaa = nav_prev_grid = true; + square_node = false; thumb_size = QSizeF(200, 200); if (scene() == 0) { scene_ = new QGraphicsScene; @@ -938,6 +939,7 @@ void BlockView::addItem(QGraphicsItem * item, bool emit_action) { applyGridStep(); if (item->data(1005) == "connection") { loadBus(qgraphicsitem_cast(item)); + ((BlockBusItem*)item)->setSquareNodes(square_node); connect((BlockBusItem*)item, SIGNAL(destroyed(QObject*)), this, SLOT(removedBus(QObject*)), Qt::UniqueConnection); if (emit_action) emitActionEvent(BlockItemBase::BusAdd, QList() << item); emit connectionsChanged(); @@ -1236,7 +1238,7 @@ void BlockView::trace(QPointF scene_pos_from, QPointF scene_pos_to, BlockBusItem int dx = sr.left() / grid_step, dy = sr.top() / grid_step; //qDebug() << dp; QPoint dp(-dx, -dy), qpt = quantize(scene_pos_to, grid_step).toPoint() / grid_step + dp; - QTime tm; + QElapsedTimer tm; tm.restart(); wavetrace.resize(sr.size() / grid_step); wavetrace.fill(BlockViewWavetrace::Empty); @@ -1719,6 +1721,15 @@ void BlockView::checkPaste(bool queued) { } +void BlockView::setBusSquareNodes(bool yes) { + square_node = yes; + QList sbl = buses(); + foreach (BlockBusItem * b, sbl) { + b->setSquareNodes(square_node); + } +} + + void BlockView::newBranchTrace(BlockBusItem * item, QPointF to) { trace(item->press_pos, to, &tmp_bus); diff --git a/qad/blockview/blockview.h b/qad/blockview/blockview.h index 8cbeb0b..0602ced 100644 --- a/qad/blockview/blockview.h +++ b/qad/blockview/blockview.h @@ -57,6 +57,7 @@ class QAD_EXPORT BlockView: public QGraphicsView Q_PROPERTY(bool pinMulticonnect READ isPinMulticonnectEnabled WRITE setPinMulticonnectEnabled) Q_PROPERTY(bool miniMap READ isMiniMapEnabled WRITE setMiniMapEnabled) Q_PROPERTY(bool zoomWheelOnly READ isZoomWheelOnly WRITE setZoomWheelOnly) + Q_PROPERTY(bool busSquareNodes READ isBusSquareNodes WRITE setBusSquareNodes) Q_PROPERTY(double _thumb READ _thumb WRITE _setThumb DESIGNABLE false SCRIPTABLE false) Q_PROPERTY(QRectF _nav READ _nav WRITE _setNav DESIGNABLE false SCRIPTABLE false) @@ -84,6 +85,7 @@ public: bool isPinMulticonnectEnabled() const {return m_pin_mc;} bool isMiniMapEnabled() const {return minimap;} bool isZoomWheelOnly() const {return wheel_zoom;} + bool isBusSquareNodes() const {return square_node;} double gridStep() const {return grid_step;} double gridPointsWidth() const {return grid_points;} SelectionMode selectionMode() const {return smode;} @@ -195,7 +197,7 @@ protected: int timer_thumb, thumb_hide_delay, thick; bool mm_drag, new_bus, new_branch, moved, mm_cancel, iconnect, mm_copy, mm_thumb, ae_enabled, is_nav_anim, is_block_anim, move_bus_point; bool grid_visible, grid_snap, pm_connect, navigation, m_connect, m_trace_with_buses, m_pin_mc, minimap, prev_tcb, wheel_zoom; - bool nav_prev_aa, nav_prev_imaa, nav_prev_grid; + bool nav_prev_aa, nav_prev_imaa, nav_prev_grid, square_node; double grid_step, grid_points, cur_scl, _talpha, thumb_scl; double prev_app_scale; @@ -235,6 +237,7 @@ public slots: void setPinMulticonnectEnabled(bool on) {m_pin_mc = on;} void setMiniMapEnabled(bool on) {minimap = on;} void setZoomWheelOnly(bool on) {wheel_zoom = on;} + void setBusSquareNodes(bool yes); void zoom(double factor); void zoomIn() {zoom(1.2);}