1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +00:00

Profiler: Migrate mouse events to TimelineView

This change allows for continuous mouse events when hovering the
layout spaces between tracks.
This commit is contained in:
Carlos César Neves Enumo 2021-05-08 03:27:13 -03:00 committed by Andreas Kling
parent 99f141522a
commit 325d9445fd
5 changed files with 76 additions and 57 deletions

View file

@ -5,11 +5,13 @@
*/
#include "TimelineView.h"
#include "Profile.h"
#include <LibGUI/BoxLayout.h>
namespace Profiler {
TimelineView::TimelineView()
TimelineView::TimelineView(Profile& profile)
: m_profile(profile)
{
set_layout<GUI::VerticalBoxLayout>();
set_shrink_to_fit(true);
@ -19,4 +21,45 @@ TimelineView::~TimelineView()
{
}
u64 TimelineView::timestamp_at_x(int x) const
{
float column_width = (float)width() / (float)m_profile.length_in_ms();
float ms_into_profile = (float)x / column_width;
return m_profile.first_timestamp() + (u64)ms_into_profile;
}
void TimelineView::mousedown_event(GUI::MouseEvent& event)
{
if (event.button() != GUI::MouseButton::Left)
return;
set_selecting(true);
set_select_start_time(timestamp_at_x(event.x()));
set_select_end_time(select_start_time());
m_profile.set_timestamp_filter_range(select_start_time(), select_end_time());
update();
}
void TimelineView::mousemove_event(GUI::MouseEvent& event)
{
set_hover_time(timestamp_at_x(event.x()));
if (is_selecting()) {
set_select_end_time(hover_time());
m_profile.set_timestamp_filter_range(select_start_time(), select_end_time());
}
update();
}
void TimelineView::mouseup_event(GUI::MouseEvent& event)
{
if (event.button() != GUI::MouseButton::Left)
return;
set_selecting(false);
if (select_start_time() == select_end_time())
m_profile.clear_timestamp_filter_range();
}
}