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

This commit is contained in:
2019-03-04 14:10:52 +00:00
parent fd6865125c
commit 8874a626c1
3 changed files with 46 additions and 16 deletions

View File

@@ -315,6 +315,12 @@
</item>
<item>
<widget class="BlockView" name="blockView">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="navigateAnimationEnabled">
<bool>true</bool>
</property>

View File

@@ -70,7 +70,7 @@ void BlockView::_init() {
thumb_anim.setEasingCurve(QEasingCurve::InCubic);
nav_anim.setTargetObject(this);
nav_anim.setPropertyName("_nav");
nav_anim.setEasingCurve(QEasingCurve::InQuad);
nav_anim.setEasingCurve(QEasingCurve::Linear);
nav_anim.setDuration(200);
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(checkPaste()));
connect(&nav_anim, SIGNAL(finished()), this, SLOT(_navFinished()));
@@ -79,7 +79,7 @@ void BlockView::_init() {
centerOn(scene_->sceneRect().center());
setCacheMode(CacheBackground);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
setResizeAnchor(QGraphicsView::AnchorViewCenter);
setRenderHint(QPainter::Antialiasing);
setRenderHint(QPainter::SmoothPixmapTransform);
setMouseTracking(true);
@@ -656,7 +656,6 @@ void BlockView::wheelEvent(QWheelEvent * e) {
if (!navigation) return;
if (wheel_zoom || e->modifiers().testFlag(Qt::ControlModifier)) {
double scl = 1. - e->delta() / 500.;
//scale(scl, scl);
if (!is_nav_anim || (nav_anim.state() != QPropertyAnimation::Running))
nav_target = _nav();
QRectF r = nav_target;
@@ -664,11 +663,9 @@ void BlockView::wheelEvent(QWheelEvent * e) {
double cx = double(e->pos().x()) / vw, cy = double(e->pos().y()) / vh;
double pw = r.width(), ph = r.height();
r.setWidth(r.width() * scl);
//r.setHeight(r.height() * scl);
r.setHeight(r.width() * vh / vw);
r.translate(cx * (pw - r.width()), cy * (ph - r.height()));
animateNav(r, scl);
//_setNav(r);
return;
}
if (!wheel_zoom) QGraphicsView::wheelEvent(e);
@@ -693,6 +690,13 @@ void BlockView::mouseReleaseEvent(QMouseEvent * event) {
}
void BlockView::updateNavRect() {
QPointF t = mapToScene(viewport()->rect().topLeft());
QPointF b = mapToScene(viewport()->rect().bottomRight());
nav_rect = QRectF(t, b);
}
void BlockView::mouseMoveEvent(QMouseEvent * event) {
if (navigation) {
if (event->buttons().testFlag(Qt::MidButton) || event->buttons().testFlag(Qt::RightButton)) {
@@ -700,7 +704,10 @@ void BlockView::mouseMoveEvent(QMouseEvent * event) {
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + dp.x());
verticalScrollBar()->setValue(verticalScrollBar()->value() + dp.y());
press_point = event->pos();
nav_target = _nav();
updateNavRect();
QRectF nr = nav_anim.endValue().toRectF();
nr.moveCenter(_nav().center());
nav_anim.setEndValue(nr);
return;
}
}
@@ -708,6 +715,15 @@ void BlockView::mouseMoveEvent(QMouseEvent * event) {
}
void BlockView::mouseDoubleClickEvent(QMouseEvent * event) {
if (event->buttons().testFlag(Qt::MidButton) || event->buttons().testFlag(Qt::RightButton)) {
fitInView();
return;
}
QGraphicsView::mouseDoubleClickEvent(event);
}
void BlockView::keyPressEvent(QKeyEvent * e) {
BlockItemPin * pin = getPin(items(mapFromGlobal(QCursor::pos())));
if (pin) {
@@ -761,6 +777,7 @@ void BlockView::resizeEvent(QResizeEvent * event) {
QGraphicsView::resizeEvent(event);
thick = lineThickness();
adjustThumb();
updateNavRect();
nav_target = _nav();
}
@@ -1084,42 +1101,49 @@ bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) {
void BlockView::setTransform(const QTransform & matrix, bool combine) {
QGraphicsView::setTransform(matrix, combine);
updateNavRect();
nav_target = _nav();
}
void BlockView::centerOn(const QPointF & pos) {
QGraphicsView::centerOn(pos);
updateNavRect();
nav_target = _nav();
}
void BlockView::centerOn(qreal x, qreal y) {
QGraphicsView::centerOn(x, y);
updateNavRect();
nav_target = _nav();
}
void BlockView::centerOn(const QGraphicsItem * item) {
QGraphicsView::centerOn(item);
updateNavRect();
nav_target = _nav();
}
void BlockView::fitInView(const QRectF & rect, Qt::AspectRatioMode aspectRatioMode) {
QGraphicsView::fitInView(rect, aspectRatioMode);
updateNavRect();
nav_target = _nav();
}
void BlockView::fitInView(qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode aspectRatioMode) {
QGraphicsView::fitInView(x, y, w, h, aspectRatioMode);
updateNavRect();
nav_target = _nav();
}
void BlockView::fitInView(const QGraphicsItem * item, Qt::AspectRatioMode aspectRatioMode) {
QGraphicsView::fitInView(item, aspectRatioMode);
updateNavRect();
nav_target = _nav();
}
@@ -1127,8 +1151,10 @@ void BlockView::fitInView(const QGraphicsItem * item, Qt::AspectRatioMode aspect
void BlockView::fitInView() {
QRectF r = _nav();
QGraphicsView::fitInView(itemsBoundingRect(), Qt::KeepAspectRatio);
updateNavRect();
QRectF t = _nav();
QGraphicsView::fitInView(r, Qt::KeepAspectRatio);
updateNavRect();
animateNav(t);
}
@@ -1142,7 +1168,6 @@ QRectF BlockView::itemsBoundingRect() const {
if (i->isVisible() && (i != &tmp_bus) && !tmp_buses.contains((BlockBusItem*)i)) {
if ((i->data(1007) != "item_selection") && !i->data(1008).toBool()) {
QRectF br = i->mapRectToScene(i->boundingRect());
//qDebug() << br << i;
if (br.width() <= 1 || br.height() <= 1) continue;
if (f) ret = br;
else ret |= br;
@@ -1624,13 +1649,12 @@ QList<QGraphicsItem * > BlockView::selectedDecors() const {
void BlockView::animateNav(QRectF d, double scl) {
nav_target = d;
if (is_nav_anim) {
if (anim_el.elapsed() < 10 || (qAbs<double>(scl - 1.) <= 0.1)) {
if (qAbs<double>(scl - 1.) <= 0.1) {
if (nav_anim.state() == QAbstractAnimation::Running) {
nav_anim.stop();
_navFinished();
}
_setNav(d);
anim_el.restart();
return;
}
if (nav_anim.state() != QAbstractAnimation::Running) {
@@ -1645,7 +1669,6 @@ void BlockView::animateNav(QRectF d, double scl) {
nav_anim.setStartValue(_nav());
nav_anim.setEndValue(d);
nav_anim.start();
anim_el.restart();
} else
_setNav(d);
}
@@ -1821,7 +1844,6 @@ void BlockView::_setThumb(double v) {
void BlockView::_setNav(QRectF v) {
//QGraphicsView::fitInView(v);
double vw = viewport()->width(), vh = viewport()->height();
if (vw < 1. || vh < 1. || v.isEmpty()) return;
QTransform matrix;
@@ -1829,14 +1851,14 @@ void BlockView::_setNav(QRectF v) {
double ascl = appScale(this);
scl = qMin(qMax(scl, 0.02 * ascl), 50. * ascl);
matrix.scale(scl, scl);
//qDebug() << scl;
nav_rect = v;
QGraphicsView::setTransform(matrix);
QGraphicsView::centerOn(v.center());
QGraphicsView::centerOn(nav_rect.center());
}
QRectF BlockView::_nav() const {
return mapToScene(viewport()->rect()).boundingRect();
return nav_rect;
}

View File

@@ -58,6 +58,8 @@ class BlockView: public QGraphicsView
Q_PROPERTY(double _thumb READ _thumb WRITE _setThumb DESIGNABLE false SCRIPTABLE false)
Q_PROPERTY(QRectF _nav READ _nav WRITE _setNav DESIGNABLE false SCRIPTABLE false)
void updateNavRect();
public:
BlockView(QWidget * parent = 0);
BlockView(QGraphicsScene * scene, QWidget * parent = 0);
@@ -121,6 +123,7 @@ protected:
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent * event);
void mouseDoubleClickEvent(QMouseEvent * event);
void keyPressEvent(QKeyEvent * event);
void keyReleaseEvent(QKeyEvent * e);
void resizeEvent(QResizeEvent * event);
@@ -180,7 +183,7 @@ 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;
QRectF nav_target, nav_rect;
QSizeF thumb_size;
QPen grid_pen;
SelectionMode smode;
@@ -188,7 +191,6 @@ protected:
QWidget widget_thumb;
Qt::KeyboardModifiers mm_mods;
QPropertyAnimation thumb_anim, nav_anim;
QTime anim_el;
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;