mirror of
https://github.com/yse/easy_profiler.git
synced 2025-01-14 00:27:55 +08:00
(profiler_gui) Added possibility of changing current scale using mouse wheel on minimap under graphics scene
This commit is contained in:
parent
beadd01c0c
commit
721c145450
@ -1495,9 +1495,13 @@ qreal EasyGraphicsView::setTree(EasyGraphicsItem* _item, const ::profiler::Block
|
||||
|
||||
void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar)
|
||||
{
|
||||
if (m_pScrollbar)
|
||||
auto const prevScrollbar = m_pScrollbar;
|
||||
const bool makeConnect = prevScrollbar == nullptr || prevScrollbar != _scrollbar;
|
||||
|
||||
if (prevScrollbar != nullptr && prevScrollbar != _scrollbar)
|
||||
{
|
||||
disconnect(m_pScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
||||
disconnect(prevScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
||||
disconnect(prevScrollbar, &EasyGraphicsScrollbar::wheeled, this, &This::onWheel);
|
||||
}
|
||||
|
||||
m_pScrollbar = _scrollbar;
|
||||
@ -1506,7 +1510,12 @@ void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar)
|
||||
m_pScrollbar->setRange(0, scene()->width());
|
||||
m_pScrollbar->setSliderWidth(m_visibleSceneRect.width());
|
||||
m_pScrollbar->setValue(0);
|
||||
connect(m_pScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
||||
|
||||
if (makeConnect)
|
||||
{
|
||||
connect(m_pScrollbar, &EasyGraphicsScrollbar::valueChanged, this, &This::onGraphicsScrollbarValueChange);
|
||||
connect(m_pScrollbar, &EasyGraphicsScrollbar::wheeled, this, &This::onWheel);
|
||||
}
|
||||
|
||||
::profiler_gui::EASY_GLOBALS.selected_thread = 0;
|
||||
emit ::profiler_gui::EASY_GLOBALS.events.selectedThreadChanged(0);
|
||||
@ -1575,17 +1584,19 @@ void EasyGraphicsView::scaleTo(qreal _scale)
|
||||
|
||||
void EasyGraphicsView::wheelEvent(QWheelEvent* _event)
|
||||
{
|
||||
if (m_bEmpty)
|
||||
{
|
||||
_event->accept();
|
||||
return;
|
||||
}
|
||||
if (!m_bEmpty)
|
||||
onWheel(mapToScene(_event->pos()).x(), _event->delta());
|
||||
_event->accept();
|
||||
}
|
||||
|
||||
const decltype(m_scale) scaleCoeff = _event->delta() > 0 ? SCALING_COEFFICIENT : SCALING_COEFFICIENT_INV;
|
||||
void EasyGraphicsView::onWheel(qreal _mouseX, int _wheelDelta)
|
||||
{
|
||||
printf("onWheel(%lf)\n", _mouseX);
|
||||
|
||||
const decltype(m_scale) scaleCoeff = _wheelDelta > 0 ? SCALING_COEFFICIENT : SCALING_COEFFICIENT_INV;
|
||||
|
||||
// Remember current mouse position
|
||||
const auto mouseX = mapToScene(_event->pos()).x();
|
||||
const auto mousePosition = m_offset + mouseX / m_scale;
|
||||
const auto mousePosition = m_offset + _mouseX / m_scale;
|
||||
|
||||
// have to limit scale because of Qt's QPainter feature: it doesn't draw text
|
||||
// with very big coordinates (but it draw rectangles with the same coordinates good).
|
||||
@ -1598,7 +1609,7 @@ void EasyGraphicsView::wheelEvent(QWheelEvent* _event)
|
||||
m_pScrollbar->setSliderWidth(windowWidth);
|
||||
|
||||
// Calculate new offset to simulate QGraphicsView::AnchorUnderMouse scaling behavior
|
||||
m_offset = clamp(0., mousePosition - mouseX / m_scale, scene()->width() - windowWidth);
|
||||
m_offset = clamp(0., mousePosition - _mouseX / m_scale, scene()->width() - windowWidth);
|
||||
|
||||
// Update slider position
|
||||
m_bUpdatingRect = true; // To be sure that updateVisibleSceneRect will not be called by scrollbar change
|
||||
@ -1607,7 +1618,6 @@ void EasyGraphicsView::wheelEvent(QWheelEvent* _event)
|
||||
|
||||
updateTimelineStep(windowWidth);
|
||||
updateScene(); // repaint scene
|
||||
_event->accept();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -330,6 +330,7 @@ private slots:
|
||||
|
||||
// Private Slots
|
||||
|
||||
void onWheel(qreal _mouseX, int _wheelDelta);
|
||||
void onScrollbarValueChange(int);
|
||||
void onGraphicsScrollbarValueChange(qreal);
|
||||
void onFlickerTimeout();
|
||||
|
@ -460,6 +460,13 @@ void EasyGraphicsScrollbar::mouseMoveEvent(QMouseEvent* _event)
|
||||
}
|
||||
}
|
||||
|
||||
void EasyGraphicsScrollbar::wheelEvent(QWheelEvent* _event)
|
||||
{
|
||||
setValue(mapToScene(_event->pos()).x() - m_minimumValue - m_slider->halfwidth());
|
||||
emit wheeled(m_slider->halfwidth() * m_windowScale, _event->delta());
|
||||
_event->accept();
|
||||
}
|
||||
|
||||
void EasyGraphicsScrollbar::resizeEvent(QResizeEvent* _event)
|
||||
{
|
||||
onWindowWidthChange(_event->size().width());
|
||||
|
@ -163,6 +163,7 @@ public:
|
||||
void mousePressEvent(QMouseEvent* _event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* _event) override;
|
||||
void mouseMoveEvent(QMouseEvent* _event) override;
|
||||
void wheelEvent(QWheelEvent* _event) override;
|
||||
void resizeEvent(QResizeEvent* _event) override;
|
||||
void contextMenuEvent(QContextMenuEvent* _event) override;
|
||||
|
||||
@ -198,6 +199,7 @@ signals:
|
||||
|
||||
void rangeChanged();
|
||||
void valueChanged(qreal _value);
|
||||
void wheeled(qreal _mouseX, int _wheelDelta);
|
||||
|
||||
private slots:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user