git-svn-id: svn://db.shs.com.ru/libs@510 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -315,6 +315,12 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="BlockView" name="blockView">
|
<widget class="BlockView" name="blockView">
|
||||||
|
<property name="verticalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
|
<property name="horizontalScrollBarPolicy">
|
||||||
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
</property>
|
||||||
<property name="navigateAnimationEnabled">
|
<property name="navigateAnimationEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ void BlockView::_init() {
|
|||||||
thumb_anim.setEasingCurve(QEasingCurve::InCubic);
|
thumb_anim.setEasingCurve(QEasingCurve::InCubic);
|
||||||
nav_anim.setTargetObject(this);
|
nav_anim.setTargetObject(this);
|
||||||
nav_anim.setPropertyName("_nav");
|
nav_anim.setPropertyName("_nav");
|
||||||
nav_anim.setEasingCurve(QEasingCurve::InQuad);
|
nav_anim.setEasingCurve(QEasingCurve::Linear);
|
||||||
nav_anim.setDuration(200);
|
nav_anim.setDuration(200);
|
||||||
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(checkPaste()));
|
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(checkPaste()));
|
||||||
connect(&nav_anim, SIGNAL(finished()), this, SLOT(_navFinished()));
|
connect(&nav_anim, SIGNAL(finished()), this, SLOT(_navFinished()));
|
||||||
@@ -79,7 +79,7 @@ void BlockView::_init() {
|
|||||||
centerOn(scene_->sceneRect().center());
|
centerOn(scene_->sceneRect().center());
|
||||||
setCacheMode(CacheBackground);
|
setCacheMode(CacheBackground);
|
||||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
setResizeAnchor(QGraphicsView::AnchorViewCenter);
|
||||||
setRenderHint(QPainter::Antialiasing);
|
setRenderHint(QPainter::Antialiasing);
|
||||||
setRenderHint(QPainter::SmoothPixmapTransform);
|
setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
@@ -656,7 +656,6 @@ void BlockView::wheelEvent(QWheelEvent * e) {
|
|||||||
if (!navigation) return;
|
if (!navigation) return;
|
||||||
if (wheel_zoom || e->modifiers().testFlag(Qt::ControlModifier)) {
|
if (wheel_zoom || e->modifiers().testFlag(Qt::ControlModifier)) {
|
||||||
double scl = 1. - e->delta() / 500.;
|
double scl = 1. - e->delta() / 500.;
|
||||||
//scale(scl, scl);
|
|
||||||
if (!is_nav_anim || (nav_anim.state() != QPropertyAnimation::Running))
|
if (!is_nav_anim || (nav_anim.state() != QPropertyAnimation::Running))
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
QRectF r = nav_target;
|
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 cx = double(e->pos().x()) / vw, cy = double(e->pos().y()) / vh;
|
||||||
double pw = r.width(), ph = r.height();
|
double pw = r.width(), ph = r.height();
|
||||||
r.setWidth(r.width() * scl);
|
r.setWidth(r.width() * scl);
|
||||||
//r.setHeight(r.height() * scl);
|
|
||||||
r.setHeight(r.width() * vh / vw);
|
r.setHeight(r.width() * vh / vw);
|
||||||
r.translate(cx * (pw - r.width()), cy * (ph - r.height()));
|
r.translate(cx * (pw - r.width()), cy * (ph - r.height()));
|
||||||
animateNav(r, scl);
|
animateNav(r, scl);
|
||||||
//_setNav(r);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!wheel_zoom) QGraphicsView::wheelEvent(e);
|
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) {
|
void BlockView::mouseMoveEvent(QMouseEvent * event) {
|
||||||
if (navigation) {
|
if (navigation) {
|
||||||
if (event->buttons().testFlag(Qt::MidButton) || event->buttons().testFlag(Qt::RightButton)) {
|
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());
|
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + dp.x());
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->value() + dp.y());
|
verticalScrollBar()->setValue(verticalScrollBar()->value() + dp.y());
|
||||||
press_point = event->pos();
|
press_point = event->pos();
|
||||||
nav_target = _nav();
|
updateNavRect();
|
||||||
|
QRectF nr = nav_anim.endValue().toRectF();
|
||||||
|
nr.moveCenter(_nav().center());
|
||||||
|
nav_anim.setEndValue(nr);
|
||||||
return;
|
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) {
|
void BlockView::keyPressEvent(QKeyEvent * e) {
|
||||||
BlockItemPin * pin = getPin(items(mapFromGlobal(QCursor::pos())));
|
BlockItemPin * pin = getPin(items(mapFromGlobal(QCursor::pos())));
|
||||||
if (pin) {
|
if (pin) {
|
||||||
@@ -761,6 +777,7 @@ void BlockView::resizeEvent(QResizeEvent * event) {
|
|||||||
QGraphicsView::resizeEvent(event);
|
QGraphicsView::resizeEvent(event);
|
||||||
thick = lineThickness();
|
thick = lineThickness();
|
||||||
adjustThumb();
|
adjustThumb();
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1084,42 +1101,49 @@ bool BlockView::connectPins(BlockItemPin * p0, BlockItemPin * p1) {
|
|||||||
|
|
||||||
void BlockView::setTransform(const QTransform & matrix, bool combine) {
|
void BlockView::setTransform(const QTransform & matrix, bool combine) {
|
||||||
QGraphicsView::setTransform(matrix, combine);
|
QGraphicsView::setTransform(matrix, combine);
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockView::centerOn(const QPointF & pos) {
|
void BlockView::centerOn(const QPointF & pos) {
|
||||||
QGraphicsView::centerOn(pos);
|
QGraphicsView::centerOn(pos);
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockView::centerOn(qreal x, qreal y) {
|
void BlockView::centerOn(qreal x, qreal y) {
|
||||||
QGraphicsView::centerOn(x, y);
|
QGraphicsView::centerOn(x, y);
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockView::centerOn(const QGraphicsItem * item) {
|
void BlockView::centerOn(const QGraphicsItem * item) {
|
||||||
QGraphicsView::centerOn(item);
|
QGraphicsView::centerOn(item);
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockView::fitInView(const QRectF & rect, Qt::AspectRatioMode aspectRatioMode) {
|
void BlockView::fitInView(const QRectF & rect, Qt::AspectRatioMode aspectRatioMode) {
|
||||||
QGraphicsView::fitInView(rect, aspectRatioMode);
|
QGraphicsView::fitInView(rect, aspectRatioMode);
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockView::fitInView(qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode aspectRatioMode) {
|
void BlockView::fitInView(qreal x, qreal y, qreal w, qreal h, Qt::AspectRatioMode aspectRatioMode) {
|
||||||
QGraphicsView::fitInView(x, y, w, h, aspectRatioMode);
|
QGraphicsView::fitInView(x, y, w, h, aspectRatioMode);
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockView::fitInView(const QGraphicsItem * item, Qt::AspectRatioMode aspectRatioMode) {
|
void BlockView::fitInView(const QGraphicsItem * item, Qt::AspectRatioMode aspectRatioMode) {
|
||||||
QGraphicsView::fitInView(item, aspectRatioMode);
|
QGraphicsView::fitInView(item, aspectRatioMode);
|
||||||
|
updateNavRect();
|
||||||
nav_target = _nav();
|
nav_target = _nav();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1127,8 +1151,10 @@ void BlockView::fitInView(const QGraphicsItem * item, Qt::AspectRatioMode aspect
|
|||||||
void BlockView::fitInView() {
|
void BlockView::fitInView() {
|
||||||
QRectF r = _nav();
|
QRectF r = _nav();
|
||||||
QGraphicsView::fitInView(itemsBoundingRect(), Qt::KeepAspectRatio);
|
QGraphicsView::fitInView(itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||||
|
updateNavRect();
|
||||||
QRectF t = _nav();
|
QRectF t = _nav();
|
||||||
QGraphicsView::fitInView(r, Qt::KeepAspectRatio);
|
QGraphicsView::fitInView(r, Qt::KeepAspectRatio);
|
||||||
|
updateNavRect();
|
||||||
animateNav(t);
|
animateNav(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1142,7 +1168,6 @@ QRectF BlockView::itemsBoundingRect() const {
|
|||||||
if (i->isVisible() && (i != &tmp_bus) && !tmp_buses.contains((BlockBusItem*)i)) {
|
if (i->isVisible() && (i != &tmp_bus) && !tmp_buses.contains((BlockBusItem*)i)) {
|
||||||
if ((i->data(1007) != "item_selection") && !i->data(1008).toBool()) {
|
if ((i->data(1007) != "item_selection") && !i->data(1008).toBool()) {
|
||||||
QRectF br = i->mapRectToScene(i->boundingRect());
|
QRectF br = i->mapRectToScene(i->boundingRect());
|
||||||
//qDebug() << br << i;
|
|
||||||
if (br.width() <= 1 || br.height() <= 1) continue;
|
if (br.width() <= 1 || br.height() <= 1) continue;
|
||||||
if (f) ret = br;
|
if (f) ret = br;
|
||||||
else ret |= br;
|
else ret |= br;
|
||||||
@@ -1624,13 +1649,12 @@ QList<QGraphicsItem * > BlockView::selectedDecors() const {
|
|||||||
void BlockView::animateNav(QRectF d, double scl) {
|
void BlockView::animateNav(QRectF d, double scl) {
|
||||||
nav_target = d;
|
nav_target = d;
|
||||||
if (is_nav_anim) {
|
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) {
|
if (nav_anim.state() == QAbstractAnimation::Running) {
|
||||||
nav_anim.stop();
|
nav_anim.stop();
|
||||||
_navFinished();
|
_navFinished();
|
||||||
}
|
}
|
||||||
_setNav(d);
|
_setNav(d);
|
||||||
anim_el.restart();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nav_anim.state() != QAbstractAnimation::Running) {
|
if (nav_anim.state() != QAbstractAnimation::Running) {
|
||||||
@@ -1645,7 +1669,6 @@ void BlockView::animateNav(QRectF d, double scl) {
|
|||||||
nav_anim.setStartValue(_nav());
|
nav_anim.setStartValue(_nav());
|
||||||
nav_anim.setEndValue(d);
|
nav_anim.setEndValue(d);
|
||||||
nav_anim.start();
|
nav_anim.start();
|
||||||
anim_el.restart();
|
|
||||||
} else
|
} else
|
||||||
_setNav(d);
|
_setNav(d);
|
||||||
}
|
}
|
||||||
@@ -1821,7 +1844,6 @@ void BlockView::_setThumb(double v) {
|
|||||||
|
|
||||||
|
|
||||||
void BlockView::_setNav(QRectF v) {
|
void BlockView::_setNav(QRectF v) {
|
||||||
//QGraphicsView::fitInView(v);
|
|
||||||
double vw = viewport()->width(), vh = viewport()->height();
|
double vw = viewport()->width(), vh = viewport()->height();
|
||||||
if (vw < 1. || vh < 1. || v.isEmpty()) return;
|
if (vw < 1. || vh < 1. || v.isEmpty()) return;
|
||||||
QTransform matrix;
|
QTransform matrix;
|
||||||
@@ -1829,14 +1851,14 @@ void BlockView::_setNav(QRectF v) {
|
|||||||
double ascl = appScale(this);
|
double ascl = appScale(this);
|
||||||
scl = qMin(qMax(scl, 0.02 * ascl), 50. * ascl);
|
scl = qMin(qMax(scl, 0.02 * ascl), 50. * ascl);
|
||||||
matrix.scale(scl, scl);
|
matrix.scale(scl, scl);
|
||||||
//qDebug() << scl;
|
nav_rect = v;
|
||||||
QGraphicsView::setTransform(matrix);
|
QGraphicsView::setTransform(matrix);
|
||||||
QGraphicsView::centerOn(v.center());
|
QGraphicsView::centerOn(nav_rect.center());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QRectF BlockView::_nav() const {
|
QRectF BlockView::_nav() const {
|
||||||
return mapToScene(viewport()->rect()).boundingRect();
|
return nav_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ class BlockView: public QGraphicsView
|
|||||||
Q_PROPERTY(double _thumb READ _thumb WRITE _setThumb DESIGNABLE false SCRIPTABLE false)
|
Q_PROPERTY(double _thumb READ _thumb WRITE _setThumb DESIGNABLE false SCRIPTABLE false)
|
||||||
Q_PROPERTY(QRectF _nav READ _nav WRITE _setNav DESIGNABLE false SCRIPTABLE false)
|
Q_PROPERTY(QRectF _nav READ _nav WRITE _setNav DESIGNABLE false SCRIPTABLE false)
|
||||||
|
|
||||||
|
void updateNavRect();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BlockView(QWidget * parent = 0);
|
BlockView(QWidget * parent = 0);
|
||||||
BlockView(QGraphicsScene * scene, QWidget * parent = 0);
|
BlockView(QGraphicsScene * scene, QWidget * parent = 0);
|
||||||
@@ -121,6 +123,7 @@ protected:
|
|||||||
void mousePressEvent(QMouseEvent * event);
|
void mousePressEvent(QMouseEvent * event);
|
||||||
void mouseReleaseEvent(QMouseEvent * event);
|
void mouseReleaseEvent(QMouseEvent * event);
|
||||||
void mouseMoveEvent(QMouseEvent * event);
|
void mouseMoveEvent(QMouseEvent * event);
|
||||||
|
void mouseDoubleClickEvent(QMouseEvent * event);
|
||||||
void keyPressEvent(QKeyEvent * event);
|
void keyPressEvent(QKeyEvent * event);
|
||||||
void keyReleaseEvent(QKeyEvent * e);
|
void keyReleaseEvent(QKeyEvent * e);
|
||||||
void resizeEvent(QResizeEvent * event);
|
void resizeEvent(QResizeEvent * event);
|
||||||
@@ -180,7 +183,7 @@ protected:
|
|||||||
QPoint press_point, screen_point, thumb_press;
|
QPoint press_point, screen_point, thumb_press;
|
||||||
QPointF scene_point, trace_from, last_trace_from, trace_to, copy_dp;
|
QPointF scene_point, trace_from, last_trace_from, trace_to, copy_dp;
|
||||||
QRect thumb_sr, thumb_vr;
|
QRect thumb_sr, thumb_vr;
|
||||||
QRectF nav_target;
|
QRectF nav_target, nav_rect;
|
||||||
QSizeF thumb_size;
|
QSizeF thumb_size;
|
||||||
QPen grid_pen;
|
QPen grid_pen;
|
||||||
SelectionMode smode;
|
SelectionMode smode;
|
||||||
@@ -188,7 +191,6 @@ protected:
|
|||||||
QWidget widget_thumb;
|
QWidget widget_thumb;
|
||||||
Qt::KeyboardModifiers mm_mods;
|
Qt::KeyboardModifiers mm_mods;
|
||||||
QPropertyAnimation thumb_anim, nav_anim;
|
QPropertyAnimation thumb_anim, nav_anim;
|
||||||
QTime anim_el;
|
|
||||||
int timer_thumb, thumb_hide_delay, thick;
|
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 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 grid_visible, grid_snap, pm_connect, navigation, m_connect, m_trace_with_buses, m_pin_mc, minimap, prev_tcb, wheel_zoom;
|
||||||
|
|||||||
Reference in New Issue
Block a user