git-svn-id: svn://db.shs.com.ru/libs@299 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -350,8 +350,10 @@ void BlockBusItem::updateGeometry() {
|
||||
}
|
||||
|
||||
|
||||
void BlockBusItem::checkDelete() {
|
||||
if (pol.size() < 2 || segments.size() < 1) deleteLater();
|
||||
bool BlockBusItem::checkDelete() {
|
||||
if (pol.size() >= 2 && segments.size() >= 1) return false;
|
||||
deleteLater();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -551,13 +553,13 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) {
|
||||
if (selPoint >= 0 && selPoint <= pol.size() - 1) {
|
||||
removePoint(selPoint);
|
||||
simplify();
|
||||
emitAction(BlockItemBase::BusPointRemove);
|
||||
if (!checkDelete()) emitAction(BlockItemBase::BusPointRemove);
|
||||
return;
|
||||
}
|
||||
if (selSegment >= 0 && selSegment <= segments.size() - 1) {
|
||||
removeSegment(selSegment);
|
||||
simplify();
|
||||
emitAction(BlockItemBase::BusSegmentRemove);
|
||||
if (!checkDelete()) emitAction(BlockItemBase::BusSegmentRemove);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ protected:
|
||||
void _init();
|
||||
void reconnect();
|
||||
void updateGeometry();
|
||||
void checkDelete();
|
||||
bool checkDelete();
|
||||
void emitAction(BlockItemBase::Action a);
|
||||
QVector<int> endpoints() const;
|
||||
QVector<int> endpointLine(int ep, double angle) const;
|
||||
|
||||
@@ -27,6 +27,22 @@ BlockView::~BlockView() {
|
||||
|
||||
|
||||
void BlockView::_init() {
|
||||
grid_visible = grid_snap = pm_connect = navigation = m_connect = m_trace_with_buses = minimap = true;
|
||||
mm_drag = moved = new_branch = new_bus = mm_cancel = iconnect = mm_copy = m_pin_mc = mm_thumb = false;
|
||||
match_bus = bus_from = 0;
|
||||
mm_ci = 0;
|
||||
hpin = 0;
|
||||
grid_step = 10.;
|
||||
grid_points = 1;
|
||||
grid_pen = QPen(Qt::lightGray, 1, Qt::NoPen);
|
||||
thick = 1;
|
||||
thumb_hide_delay = 500;
|
||||
timer_thumb = 0;
|
||||
smode = BlockView::MultiSelection;
|
||||
cur_scl = thumb_scl = 1.;
|
||||
_talpha = 0.;
|
||||
ae_enabled = is_nav_anim = true;
|
||||
thumb_size = QSizeF(200, 200);
|
||||
if (scene() == 0) {
|
||||
scene_ = new QGraphicsScene;
|
||||
setScene(scene_);
|
||||
@@ -46,6 +62,10 @@ void BlockView::_init() {
|
||||
thumb_anim.setTargetObject(this);
|
||||
thumb_anim.setPropertyName("_thumb");
|
||||
thumb_anim.setEasingCurve(QEasingCurve::InCubic);
|
||||
nav_anim.setTargetObject(this);
|
||||
nav_anim.setPropertyName("_nav");
|
||||
nav_anim.setEasingCurve(QEasingCurve::InQuad);
|
||||
nav_anim.setDuration(200);
|
||||
connect(scene_, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(adjustThumb()));
|
||||
connect(scene_, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged()));
|
||||
centerOn(scene_->sceneRect().center());
|
||||
@@ -55,21 +75,6 @@ void BlockView::_init() {
|
||||
setRenderHint(QPainter::Antialiasing);
|
||||
setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
setMouseTracking(true);
|
||||
grid_visible = grid_snap = pm_connect = navigation = m_connect = m_trace_with_buses = minimap = true;
|
||||
mm_drag = moved = new_branch = new_bus = mm_cancel = iconnect = mm_copy = m_pin_mc = mm_thumb = false;
|
||||
match_bus = bus_from = 0;
|
||||
mm_ci = 0;
|
||||
timer_thumb = 0;
|
||||
hpin = 0;
|
||||
grid_step = 10.;
|
||||
grid_points = 1;
|
||||
grid_pen = QPen(Qt::lightGray, 1, Qt::NoPen);
|
||||
thumb_hide_delay = 500;
|
||||
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();
|
||||
QColor sc = palette().color(QPalette::Highlight);
|
||||
@@ -590,14 +595,21 @@ void BlockView::timerEvent(QTimerEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void BlockView::wheelEvent(QWheelEvent * event) {
|
||||
void BlockView::wheelEvent(QWheelEvent * e) {
|
||||
if (!navigation) return;
|
||||
if (event->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
double scl = 1. + event->delta() / 500.;
|
||||
scale(scl, scl);
|
||||
if (e->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
double scl = 1. - e->delta() / 500.;
|
||||
//scale(scl, scl);
|
||||
QRectF r = nav_target;
|
||||
double cx = double(e->pos().x()) / viewport()->width(), cy = double(e->pos().y()) / viewport()->height();
|
||||
double pw = r.width(), ph = r.height();
|
||||
r.setWidth(r.width() * scl);
|
||||
r.setHeight(r.height() * scl);
|
||||
r.translate(cx * (pw - r.width()), cy * (ph - r.height()));
|
||||
animateNav(r);
|
||||
return;
|
||||
}
|
||||
QGraphicsView::wheelEvent(event);
|
||||
QGraphicsView::wheelEvent(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -614,6 +626,7 @@ void BlockView::mouseMoveEvent(QMouseEvent * event) {
|
||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + dp.x());
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->value() + dp.y());
|
||||
press_point = event->pos();
|
||||
nav_target = _nav();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -639,7 +652,9 @@ void BlockView::keyPressEvent(QKeyEvent * e) {
|
||||
|
||||
void BlockView::resizeEvent(QResizeEvent * event) {
|
||||
QGraphicsView::resizeEvent(event);
|
||||
thick = qMax<int>(qRound(fontMetrics().size(0, "0").height() / 15.), 1);
|
||||
adjustThumb();
|
||||
nav_target = _nav();
|
||||
}
|
||||
|
||||
|
||||
@@ -648,7 +663,7 @@ void BlockView::scrollContentsBy(int dx, int dy) {
|
||||
if (isHidden()) return;
|
||||
thumbShow();
|
||||
restartTimer(timer_thumb, thumb_hide_delay);
|
||||
QMetaObject::invokeMethod(&widget_thumb, "repaint", Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(&widget_thumb, "update", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
|
||||
@@ -668,7 +683,7 @@ void BlockView::drawBackground(QPainter * painter, const QRectF & rect) {
|
||||
ry = quantize(rect.top(), sy);
|
||||
bool gp = grid_points > 0.5;
|
||||
if (gp) {
|
||||
QPen pp(grid_pen.color(), grid_points, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
||||
QPen pp(grid_pen.color(), qMax<int>(grid_points, thick), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
|
||||
pp.setCosmetic(true);
|
||||
painter->setPen(pp);
|
||||
for(int i = 0; i < qCeil(rect.width() / sx) + 1; ++i)
|
||||
@@ -676,6 +691,8 @@ void BlockView::drawBackground(QPainter * painter, const QRectF & rect) {
|
||||
painter->drawPoint(rx + i * sx, ry + j * sy);
|
||||
}
|
||||
if (grid_pen.style() == Qt::NoPen) return;
|
||||
QPen pen = grid_pen;
|
||||
pen.setWidth(qMax<int>(pen.width(), thick));
|
||||
painter->setPen(grid_pen);
|
||||
for(int i = 0; i < qCeil(rect.width() / sx) + 1; ++i) {
|
||||
double cx = rx + i * sx;
|
||||
@@ -1330,6 +1347,23 @@ QList<QGraphicsItem * > BlockView::selectedDecors() const {
|
||||
}
|
||||
|
||||
|
||||
QRectF BlockView::_nav() const {
|
||||
return mapToScene(viewport()->rect()).boundingRect();
|
||||
}
|
||||
|
||||
|
||||
void BlockView::animateNav(QRectF d) {
|
||||
nav_target = d;
|
||||
if (is_nav_anim) {
|
||||
nav_anim.stop();
|
||||
nav_anim.setStartValue(_nav());
|
||||
nav_anim.setEndValue(d);
|
||||
nav_anim.start();
|
||||
} else
|
||||
_setNav(d);
|
||||
}
|
||||
|
||||
|
||||
void BlockView::adjustThumb() {
|
||||
if (!scene()) return;
|
||||
QSizeF sr = sceneRect().size(), tr;
|
||||
@@ -1462,6 +1496,11 @@ void BlockView::_setThumb(double v) {
|
||||
}
|
||||
|
||||
|
||||
void BlockView::_setNav(QRectF v) {
|
||||
fitInView(v);
|
||||
}
|
||||
|
||||
|
||||
void BlockView::reconnectAll() {
|
||||
//qDebug() << "reconnect";
|
||||
removeJunk();
|
||||
@@ -1505,7 +1544,16 @@ void BlockView::reconnectAll() {
|
||||
|
||||
|
||||
void BlockView::zoom(double factor) {
|
||||
scale(factor, factor);
|
||||
QRectF r = nav_target;
|
||||
QPoint mp;
|
||||
if (underMouse()) mp = mapFromGlobal(QCursor::pos());
|
||||
else mp = QPoint(viewport()->width() / 2, viewport()->height() / 2);
|
||||
double cx = double(mp.x()) / viewport()->width(), cy = double(mp.y()) / viewport()->height();
|
||||
double pw = r.width(), ph = r.height();
|
||||
r.setWidth(r.width() / factor);
|
||||
r.setHeight(r.height() / factor);
|
||||
r.translate(cx * (pw - r.width()), cy * (ph - r.height()));
|
||||
animateNav(r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,11 +30,13 @@ class BlockView: public QGraphicsView
|
||||
Q_PROPERTY(bool postMoveConnect READ isPostMoveConnectEnabled WRITE setPostMoveConnectEnabled)
|
||||
Q_PROPERTY(bool connectByMouse READ isConnectByMouseEnabled WRITE setConnectByMouseEnabled)
|
||||
Q_PROPERTY(bool navigationEnabled READ isNavigationEnabled WRITE setNavigationEnabled)
|
||||
Q_PROPERTY(bool navigateAnimationEnabled READ isNavigateAnimationEnabled WRITE setNavigateAnimationEnabled)
|
||||
Q_PROPERTY(bool traceConsiderBuses READ isTraceConsiderBuses WRITE setTraceConsiderBuses)
|
||||
Q_PROPERTY(bool pinMulticonnect READ isPinMulticonnectEnabled WRITE setPinMulticonnectEnabled)
|
||||
Q_PROPERTY(bool miniMap READ isMiniMapEnabled WRITE setMiniMapEnabled)
|
||||
|
||||
Q_PROPERTY(double _thumb READ _thumb WRITE _setThumb DESIGNABLE false SCRIPTABLE false)
|
||||
Q_PROPERTY(QRectF _nav READ _nav WRITE _setNav DESIGNABLE false SCRIPTABLE false)
|
||||
|
||||
public:
|
||||
BlockView(QWidget * parent = 0);
|
||||
@@ -52,6 +54,7 @@ public:
|
||||
bool isSnapToGrid() const {return grid_snap;}
|
||||
bool isPostMoveConnectEnabled() const {return pm_connect;}
|
||||
bool isNavigationEnabled() const {return navigation;}
|
||||
bool isNavigateAnimationEnabled() const {return is_nav_anim;}
|
||||
bool isConnectByMouseEnabled() const {return m_connect;}
|
||||
bool isTraceConsiderBuses() const {return m_trace_with_buses;}
|
||||
bool isPinMulticonnectEnabled() const {return m_pin_mc;}
|
||||
@@ -77,7 +80,7 @@ protected:
|
||||
void stopTimer(int & tid);
|
||||
void restartTimer(int & tid, int msecs);
|
||||
void timerEvent(QTimerEvent * e);
|
||||
void wheelEvent(QWheelEvent * event);
|
||||
void wheelEvent(QWheelEvent * e);
|
||||
void mousePressEvent(QMouseEvent * event);
|
||||
void mouseMoveEvent(QMouseEvent * event);
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
@@ -108,6 +111,8 @@ protected:
|
||||
QList<BlockItem * > selectedBlocks() const;
|
||||
QList<QGraphicsItem * > selectedDecors() const;
|
||||
double _thumb() const {return _talpha;}
|
||||
QRectF _nav() const;
|
||||
void animateNav(QRectF d);
|
||||
void scrollFromThumb();
|
||||
void deleteCopyTemp();
|
||||
void emitActionEvent(BlockItemBase::Action action, QList<QGraphicsItem * > items);
|
||||
@@ -129,15 +134,16 @@ protected:
|
||||
QPoint press_point, screen_point, thumb_press;
|
||||
QPointF scene_point, trace_from, last_trace_from, trace_to, copy_dp;
|
||||
QRect thumb_sr, thumb_vr;
|
||||
QRectF nav_target;
|
||||
QSizeF thumb_size;
|
||||
QPen grid_pen;
|
||||
SelectionMode smode;
|
||||
QImage im_scene;
|
||||
QWidget widget_thumb;
|
||||
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, ae_enabled;
|
||||
QPropertyAnimation thumb_anim, nav_anim;
|
||||
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;
|
||||
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;
|
||||
|
||||
@@ -153,6 +159,7 @@ protected slots:
|
||||
void removeJunk();
|
||||
void sceneSelectionChanged();
|
||||
void _setThumb(double v);
|
||||
void _setNav(QRectF v);
|
||||
|
||||
public slots:
|
||||
void setGridPen(const QPen & pen) {grid_pen = pen; _updateBack();}
|
||||
@@ -162,6 +169,7 @@ public slots:
|
||||
void setGridPointsWidth(double width_) {grid_points = width_; _updateBack();}
|
||||
void setPostMoveConnectEnabled(bool on) {pm_connect = on;}
|
||||
void setNavigationEnabled(bool on) {navigation = on;}
|
||||
void setNavigateAnimationEnabled(bool on) {is_nav_anim = on;}
|
||||
void setConnectByMouseEnabled(bool on) {m_connect = on;}
|
||||
void setTraceConsiderBuses(bool on) {m_trace_with_buses = on;}
|
||||
void setPinMulticonnectEnabled(bool on) {m_pin_mc = on;}
|
||||
|
||||
Reference in New Issue
Block a user