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

#100 [UI] Implemented zoom-in button

This commit is contained in:
Victor Zarubkin 2018-03-18 03:12:10 +03:00
parent bc0d351522
commit 212502578f
6 changed files with 119 additions and 1 deletions

View File

@ -854,7 +854,7 @@ qreal BlocksGraphicsView::mapToDiagram(qreal x) const
void BlocksGraphicsView::onWheel(qreal _scenePos, int _wheelDelta)
{
const decltype(m_scale) scaleCoeff = _wheelDelta > 0 ? ::profiler_gui::SCALING_COEFFICIENT : ::profiler_gui::SCALING_COEFFICIENT_INV;
const decltype(m_scale) scaleCoeff = _wheelDelta > 0 ? profiler_gui::SCALING_COEFFICIENT : profiler_gui::SCALING_COEFFICIENT_INV;
// Remember current mouse position
_scenePos = clamp(0., _scenePos, m_sceneWidth);
@ -1124,6 +1124,88 @@ void BlocksGraphicsView::mouseReleaseEvent(QMouseEvent* _event)
//////////////////////////////////////////////////////////////////////////
void BlocksGraphicsView::addSelectionToHierarchy()
{
if (!m_selectionItem->isVisible())
return;
//printf("INTERVAL: {%lf, %lf} ms\n", m_selectionItem->left(), m_selectionItem->right());
bool changedSelection = false;
if (!m_selectedBlocks.empty())
{
changedSelection = true;
m_selectedBlocks.clear();
}
for (auto item : m_items)
{
if (!EASY_GLOBALS.only_current_thread_hierarchy || item->threadId() == EASY_GLOBALS.selected_thread)
item->getBlocks(m_selectionItem->left(), m_selectionItem->right(), m_selectedBlocks);
}
if (!m_selectedBlocks.empty())
{
changedSelection = true;
}
if (changedSelection)
{
emit intervalChanged(m_selectedBlocks, m_beginTime, position2time(m_selectionItem->left()), position2time(m_selectionItem->right()), m_selectionItem->reverse());
}
}
void BlocksGraphicsView::onZoomSelection()
{
auto deltaScale = m_visibleRegionWidth / m_selectionItem->width();
if (fabs(deltaScale - 1) < 1e-6)
{
// Restore scale value multiple to SCALING_COEFFICIENT
const int steps = static_cast<int>(log(m_scale / MIN_SCALE) / log(profiler_gui::SCALING_COEFFICIENT));
const auto desiredScale = MIN_SCALE * pow(profiler_gui::SCALING_COEFFICIENT, steps);
deltaScale = desiredScale / m_scale;
}
m_offset = m_selectionItem->left() + (m_selectionItem->width() - m_visibleRegionWidth / deltaScale) * 0.5;
m_scale = clamp(MIN_SCALE, m_scale * deltaScale, MAX_SCALE);
// Update slider width for scrollbar
notifyVisibleRegionSizeChange();
// Update slider position
profiler_gui::BoolFlagGuard guard(m_bUpdatingRect, true); // To be sure that updateVisibleSceneRect will not be called by scrollbar change
notifyVisibleRegionPosChange();
guard.restore();
updateVisibleSceneRect(); // Update scene rect
updateTimelineStep(m_visibleRegionWidth);
repaintScene(); // repaint scene
}
void BlocksGraphicsView::onInspectCurrentView(bool _strict)
{
if (m_bEmpty)
return;
if (!m_selectionItem->isVisible())
{
m_selectionItem->setReverse(_strict);
m_selectionItem->setLeftRight(m_offset, m_offset + m_visibleRegionWidth);
m_selectionItem->show();
m_pScrollbar->setSelectionPos(m_selectionItem->left(), m_selectionItem->right());
m_pScrollbar->showSelectionIndicator();
addSelectionToHierarchy();
}
else
{
onZoomSelection();
}
}
//////////////////////////////////////////////////////////////////////////
bool BlocksGraphicsView::moveChrono(GraphicsRulerItem* _chronometerItem, qreal _mouseX)
{
if (_chronometerItem->reverse())

View File

@ -187,6 +187,10 @@ public:
const Items& getItems() const;
void inspectCurrentView(bool _strict) {
onInspectCurrentView(_strict);
}
signals:
// Signals
@ -218,6 +222,8 @@ private:
void onWheel(qreal _scenePos, int _wheelDelta);
qreal setTree(BlocksGraphicsItem* _item, const ::profiler::BlocksTree::children_t& _children, qreal& _height, uint32_t& _maxDepthChild, qreal _y, short _level);
void addSelectionToHierarchy();
private slots:
// Private Slots
@ -233,6 +239,8 @@ private slots:
void onSelectedBlockChange(unsigned int _block_index);
void onRefreshRequired();
void onThreadViewChanged();
void onZoomSelection();
void onInspectCurrentView(bool _strict);
public:

View File

@ -25,6 +25,7 @@ default/search-next.svg - Icon made by Freepik from www.flaticon.com
default/settings.svg - Icon made by Freepik from www.flaticon.com
default/check.svg - Icon made by Kirill Kazachek from www.flaticon.com
default/check-disabled.svg - Icon made by Kirill Kazachek from www.flaticon.com
default/binoculars.svg - Icon made by Gregor Cresnar from www.flaticon.com
default/close-white.svg - Icon made by Cole Bemis from www.flaticon.com
default/close-white-hover.svg - Icon made by Cole Bemis from www.flaticon.com
default/close-white-pressed.svg - Icon made by Cole Bemis from www.flaticon.com

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 488.1 488.1" style="enable-background:new 0 0 488.1 488.1;" xml:space="preserve">
<g>
<path fill="#f44336" d="M115.5,80.2c8.3-2.1,17.2-3.2,26.3-3.2c15.9,0,32.1,3.5,46.2,9.8c3.1,1.4,6.6-0.8,6.8-4.2l1-16c0-16.7-21.5-30.2-44-30.2
c-21.9,0-40.1,12.9-41.2,28.9l0,0l-1.2,9.6C109,78.2,112.1,81.1,115.5,80.2z"/>
<path fill="#f44336" d="M299.9,86.8c14.2-6.3,30.3-9.8,46.2-9.8c9.2,0,18,1.1,26.3,3.2c3.3,0.8,6.5-2,6-5.4l-1.2-9.6l0,0
c-1-16-19.3-28.9-41.2-28.9c-22.5,0-44,13.5-44,30.2l1,16C293.3,86,296.8,88.2,299.9,86.8z"/>
<path fill="#484848" d="M487.3,361.9l-0.5-2.9c0-0.2-0.1-0.4-0.1-0.6l-18.5-94c-2.4-21.7-18.2-40.6-41.2-52.3l-8.8-68.3c0-29-32.8-52.7-72.1-52.7
s-76.7,23.5-76.7,52.6c0,1.4,0.1,2.9,0.3,4.3l0.5,7.4c-7.8-2.8-16.7-4.4-26.1-4.4c-9.5,0-18.4,1.6-26.3,4.5l0.5-7.5
c0.2-1.4,0.3-2.8,0.3-4.3c0-29-37.5-52.6-76.7-52.6c-39.3,0-72.1,23.7-72.1,52.7L61,212.1c-23,11.6-38.8,30.6-41.2,52.3l-18.5,94
c0,0.2-0.1,0.4-0.1,0.6l-0.5,2.9l0,0c-0.4,3-0.7,6-0.7,9.1c0,44.6,46.7,80.8,104.2,80.8s104.2-36.2,104.2-80.8l0,0l0,0v-37
c10.3,4.8,22.6,7.5,35.7,7.5s25.3-2.7,35.6-7.4V371l0,0l0,0c0,44.6,46.7,80.8,104.2,80.8c57.4,0,104.2-36.2,104.2-80.8
C488,367.9,487.7,364.9,487.3,361.9z M104.2,422.7c-40.7,0-75.1-23.7-75.1-51.7c0-28.1,34.4-51.7,75.1-51.7s75.1,23.7,75.1,51.7
C179.3,399,144.9,422.7,104.2,422.7z M244.1,315.9c-17.1,0-31-9.7-31-21.6s13.9-21.6,31-21.6s31,9.7,31,21.6
C275.1,306.2,261.2,315.9,244.1,315.9z M383.8,422.7c-40.7,0-75.1-23.7-75.1-51.7c0-28.1,34.4-51.7,75.1-51.7s75.1,23.7,75.1,51.7
S424.5,422.7,383.8,422.7z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -367,6 +367,12 @@ MainWindow::MainWindow() : Parent(), m_theme("default"), m_lastAddress("localhos
toolbar->addAction(QIcon(imagePath("expand")), "Expand all", this, SLOT(onExpandAllClicked(bool)));
toolbar->addAction(QIcon(imagePath("collapse")), "Collapse all", this, SLOT(onCollapseAllClicked(bool)));
action = toolbar->addAction(QIcon(imagePath("binoculars")), "See blocks hierarchy");
action->setToolTip("Build blocks hierarchy\nfor current visible area\nor zoom to current selected area.");
connect(action, &QAction::triggered, [this] (bool) {
static_cast<DiagramWidget*>(m_graphicsView->widget())->view()->inspectCurrentView(true);
});
toolbar->addSeparator();
auto menu = new QMenu("Settings", this);
menu->setToolTipsVisible(true);

View File

@ -6,6 +6,7 @@
<file alias="logo">images/logo.svg</file>
</qresource>
<qresource prefix="/images/default">
<file alias="binoculars">images/default/binoculars.svg</file>
<file alias="exit">images/default/off.svg</file>
<file alias="open">images/default/open-folder2.svg</file>
<file alias="reload">images/default/reload.svg</file>