git-svn-id: svn://db.shs.com.ru/libs@299 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2017-10-21 15:41:12 +00:00
parent c3c0bcd1fb
commit 7a43895b07
4 changed files with 90 additions and 32 deletions

View File

@@ -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);
}