diff --git a/profiler_gui/blocks_graphics_view.cpp b/profiler_gui/blocks_graphics_view.cpp index 0fc323b..6ab6dbe 100644 --- a/profiler_gui/blocks_graphics_view.cpp +++ b/profiler_gui/blocks_graphics_view.cpp @@ -663,7 +663,10 @@ void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar) m_pScrollbar = _scrollbar; m_pScrollbar->clear(); m_pScrollbar->setRange(0, m_sceneWidth); - m_pScrollbar->setSliderWidth(m_visibleSceneRect.width()); + + auto vbar = verticalScrollBar(); + const int vbar_width = (vbar != nullptr && vbar->isVisible() ? vbar->width() + 2 : 0); + m_pScrollbar->setSliderWidth(m_visibleSceneRect.width() + vbar_width); if (makeConnect) { @@ -677,14 +680,19 @@ void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar) ////////////////////////////////////////////////////////////////////////// -void EasyGraphicsView::updateVisibleSceneRect() +int EasyGraphicsView::updateVisibleSceneRect() { m_visibleSceneRect = mapToScene(rect()).boundingRect(); auto vbar = verticalScrollBar(); + int vbar_width = 0; if (vbar && vbar->isVisible()) - m_visibleSceneRect.setWidth(m_visibleSceneRect.width() - vbar->width() - 2); + vbar_width = vbar->width() + 2; + + m_visibleSceneRect.setWidth(m_visibleSceneRect.width() - vbar_width); m_visibleSceneRect.setHeight(m_visibleSceneRect.height() - TIMELINE_ROW_SIZE); + + return vbar_width; } void EasyGraphicsView::updateTimelineStep(qreal _windowWidth) @@ -727,10 +735,10 @@ void EasyGraphicsView::scaleTo(qreal _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). m_scale = clamp(MIN_SCALE, _scale, MAX_SCALE); - updateVisibleSceneRect(); + const int vbar_width = updateVisibleSceneRect(); // Update slider width for scrollbar - const auto windowWidth = m_visibleSceneRect.width() / m_scale; + const auto windowWidth = (m_visibleSceneRect.width() + vbar_width) / m_scale; m_pScrollbar->setSliderWidth(windowWidth); updateTimelineStep(windowWidth); @@ -785,7 +793,9 @@ void EasyGraphicsView::onWheel(qreal _mouseX, int _wheelDelta) //updateVisibleSceneRect(); // Update scene rect // Update slider width for scrollbar - const auto windowWidth = m_visibleSceneRect.width() / m_scale; + auto vbar = verticalScrollBar(); + const int vbar_width = (vbar != nullptr && vbar->isVisible() ? vbar->width() + 2 : 0); + const auto windowWidth = (m_visibleSceneRect.width() + vbar_width) / m_scale; m_pScrollbar->setSliderWidth(windowWidth); // Calculate new offset to simulate QGraphicsView::AnchorUnderMouse scaling behavior @@ -1206,10 +1216,10 @@ void EasyGraphicsView::resizeEvent(QResizeEvent* _event) Parent::resizeEvent(_event); const QRectF previousRect = m_visibleSceneRect; - updateVisibleSceneRect(); // Update scene visible rect only once + const int vbar_width = updateVisibleSceneRect(); // Update scene visible rect only once // Update slider width for scrollbar - const auto windowWidth = m_visibleSceneRect.width() / m_scale; + const auto windowWidth = (m_visibleSceneRect.width() + vbar_width) / m_scale; m_pScrollbar->setSliderWidth(windowWidth); // Calculate new offset to save old screen center diff --git a/profiler_gui/blocks_graphics_view.h b/profiler_gui/blocks_graphics_view.h index 27a24fd..99ed503 100644 --- a/profiler_gui/blocks_graphics_view.h +++ b/profiler_gui/blocks_graphics_view.h @@ -188,7 +188,7 @@ private: EasyChronometerItem* createChronometer(bool _main = true); bool moveChrono(EasyChronometerItem* _chronometerItem, qreal _mouseX); void initMode(); - void updateVisibleSceneRect(); + int updateVisibleSceneRect(); void updateTimelineStep(qreal _windowWidth); void scaleTo(qreal _scale); void scrollTo(const EasyGraphicsItem* _item); diff --git a/profiler_gui/easy_graphics_scrollbar.cpp b/profiler_gui/easy_graphics_scrollbar.cpp index a0b142b..2e28e60 100644 --- a/profiler_gui/easy_graphics_scrollbar.cpp +++ b/profiler_gui/easy_graphics_scrollbar.cpp @@ -506,7 +506,7 @@ void EasyHystogramItem::paintById(QPainter* _painter) minimum *= 1e3; const auto maximum = minimum + range * 1e3; const auto realScale = currentScale * slider_k; - const auto offset = minimum * realScale + 9e3; + const auto offset = minimum * realScale; auto first = ::std::lower_bound(items.begin(), items.end(), minimum + EASY_GLOBALS.begin_time, [](::profiler::block_index_t _item, qreal _value) {