0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-28 01:04:41 +08:00

(GUI) Fixed wrong window size calculation for hystogram window

This commit is contained in:
Victor Zarubkin 2016-12-21 22:40:06 +03:00
parent e9bed4c839
commit 6d59c53f7a
3 changed files with 20 additions and 10 deletions

View File

@ -663,7 +663,10 @@ void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar)
m_pScrollbar = _scrollbar; m_pScrollbar = _scrollbar;
m_pScrollbar->clear(); m_pScrollbar->clear();
m_pScrollbar->setRange(0, m_sceneWidth); 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) if (makeConnect)
{ {
@ -677,14 +680,19 @@ void EasyGraphicsView::setScrollbar(EasyGraphicsScrollbar* _scrollbar)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void EasyGraphicsView::updateVisibleSceneRect() int EasyGraphicsView::updateVisibleSceneRect()
{ {
m_visibleSceneRect = mapToScene(rect()).boundingRect(); m_visibleSceneRect = mapToScene(rect()).boundingRect();
auto vbar = verticalScrollBar(); auto vbar = verticalScrollBar();
int vbar_width = 0;
if (vbar && vbar->isVisible()) 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); m_visibleSceneRect.setHeight(m_visibleSceneRect.height() - TIMELINE_ROW_SIZE);
return vbar_width;
} }
void EasyGraphicsView::updateTimelineStep(qreal _windowWidth) 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 // 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). // with very big coordinates (but it draw rectangles with the same coordinates good).
m_scale = clamp(MIN_SCALE, _scale, MAX_SCALE); m_scale = clamp(MIN_SCALE, _scale, MAX_SCALE);
updateVisibleSceneRect(); const int vbar_width = updateVisibleSceneRect();
// Update slider width for scrollbar // 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); m_pScrollbar->setSliderWidth(windowWidth);
updateTimelineStep(windowWidth); updateTimelineStep(windowWidth);
@ -785,7 +793,9 @@ void EasyGraphicsView::onWheel(qreal _mouseX, int _wheelDelta)
//updateVisibleSceneRect(); // Update scene rect //updateVisibleSceneRect(); // Update scene rect
// Update slider width for scrollbar // 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); m_pScrollbar->setSliderWidth(windowWidth);
// Calculate new offset to simulate QGraphicsView::AnchorUnderMouse scaling behavior // Calculate new offset to simulate QGraphicsView::AnchorUnderMouse scaling behavior
@ -1206,10 +1216,10 @@ void EasyGraphicsView::resizeEvent(QResizeEvent* _event)
Parent::resizeEvent(_event); Parent::resizeEvent(_event);
const QRectF previousRect = m_visibleSceneRect; 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 // 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); m_pScrollbar->setSliderWidth(windowWidth);
// Calculate new offset to save old screen center // Calculate new offset to save old screen center

View File

@ -188,7 +188,7 @@ private:
EasyChronometerItem* createChronometer(bool _main = true); EasyChronometerItem* createChronometer(bool _main = true);
bool moveChrono(EasyChronometerItem* _chronometerItem, qreal _mouseX); bool moveChrono(EasyChronometerItem* _chronometerItem, qreal _mouseX);
void initMode(); void initMode();
void updateVisibleSceneRect(); int updateVisibleSceneRect();
void updateTimelineStep(qreal _windowWidth); void updateTimelineStep(qreal _windowWidth);
void scaleTo(qreal _scale); void scaleTo(qreal _scale);
void scrollTo(const EasyGraphicsItem* _item); void scrollTo(const EasyGraphicsItem* _item);

View File

@ -506,7 +506,7 @@ void EasyHystogramItem::paintById(QPainter* _painter)
minimum *= 1e3; minimum *= 1e3;
const auto maximum = minimum + range * 1e3; const auto maximum = minimum + range * 1e3;
const auto realScale = currentScale * slider_k; 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) auto first = ::std::lower_bound(items.begin(), items.end(), minimum + EASY_GLOBALS.begin_time, [](::profiler::block_index_t _item, qreal _value)
{ {