2025-01-10 01:38:58 +00:00
|
|
|
#include <Scenario/Document/Event/EventModel.hpp>
|
|
|
|
|
2025-01-11 11:56:26 +00:00
|
|
|
#include "TimeSyncWidget.hpp"
|
|
|
|
#include "StateWidget.hpp"
|
|
|
|
#include "ScenarioWidget.hpp"
|
2025-01-10 01:38:58 +00:00
|
|
|
#include "EventWidget.hpp"
|
|
|
|
|
|
|
|
namespace Hardware
|
|
|
|
{
|
|
|
|
EventWidget::EventWidget(Scenario::EventModel& event,
|
2025-01-11 11:56:26 +00:00
|
|
|
ScenarioWidget* scenario,
|
2025-01-10 01:38:58 +00:00
|
|
|
bugui::container_widget* parent)
|
2025-01-11 11:56:26 +00:00
|
|
|
: ScenarioComponentSpec<Scenario::EventModel,
|
|
|
|
bugui::container_widget>{event, scenario, parent}
|
2025-01-10 01:38:58 +00:00
|
|
|
{
|
2025-01-11 11:56:26 +00:00
|
|
|
Scenario::ProcessModel* scen{scenario->get_model()};
|
|
|
|
|
|
|
|
scen->states.mutable_added.connect<&EventWidget::on_state_added>(this);
|
|
|
|
scen->states.removed.connect<&EventWidget::on_state_removed>(this);
|
|
|
|
|
|
|
|
for(Scenario::StateModel& s : scen->states)
|
|
|
|
if (s.eventId() == model.id())
|
|
|
|
add_widget<StateWidget>(s, scenario);
|
2025-01-17 22:16:43 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
set_span_recursive();
|
2025-01-19 00:14:26 +00:00
|
|
|
|
|
|
|
for(auto& s : children)
|
|
|
|
static_cast<StateWidget*>(s.get())->set_y();
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
void EventWidget::set_span_recursive()
|
2025-01-10 01:38:58 +00:00
|
|
|
{
|
2025-01-18 12:05:17 +00:00
|
|
|
int lowest{std::numeric_limits<int>::max()};
|
|
|
|
int heighest{0};
|
2025-01-14 00:04:35 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
for(const auto& s : bugui::container_widget::children)
|
2025-01-17 22:16:43 +00:00
|
|
|
{
|
2025-01-18 12:05:17 +00:00
|
|
|
int sy = static_cast<StateWidget*>(s.get())->get_absolute_y();
|
|
|
|
if (sy < lowest) lowest = sy;
|
|
|
|
if (sy > heighest) heighest = sy;
|
2025-01-17 22:16:43 +00:00
|
|
|
}
|
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
m_absolute_y = lowest;
|
|
|
|
m_height = heighest - lowest;
|
2025-01-16 02:00:26 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_span();
|
2025-01-17 22:16:43 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
m_y = m_absolute_y - parent->y();
|
2025-01-19 19:11:10 +00:00
|
|
|
|
|
|
|
for(const auto& s : bugui::container_widget::children)
|
|
|
|
static_cast<StateWidget*>(s.get())->set_y();
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventWidget::paint(bugui::painter& painter) const
|
|
|
|
{
|
2025-01-19 19:11:10 +00:00
|
|
|
if (!press) return;
|
|
|
|
|
|
|
|
const auto col = model.metadata().getColor().getBrush().color();
|
2025-01-19 00:14:26 +00:00
|
|
|
// const auto col = skin.StateSelected().color();
|
2025-01-19 19:11:10 +00:00
|
|
|
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
2025-01-10 01:38:58 +00:00
|
|
|
|
2025-01-19 19:11:10 +00:00
|
|
|
painter.draw_line(0, 0, 0, m_height);
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool EventWidget::contains(int px, int py) const
|
|
|
|
{
|
2025-01-19 19:11:10 +00:00
|
|
|
if (px == 0 &&
|
|
|
|
py >= 0 &&
|
|
|
|
py <= m_height)
|
2025-01-10 01:38:58 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-01-11 11:56:26 +00:00
|
|
|
void EventWidget::on_state_added(Scenario::StateModel& state)
|
2025-01-10 01:38:58 +00:00
|
|
|
{
|
2025-01-11 11:56:26 +00:00
|
|
|
if (state.eventId() != model.id()) return;
|
|
|
|
|
|
|
|
add_widget<StateWidget>(state, scenario);
|
2025-01-16 02:00:26 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
set_span_recursive();
|
2025-01-19 00:14:26 +00:00
|
|
|
update();
|
2025-01-11 11:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
|
|
|
{
|
2025-01-11 21:13:44 +00:00
|
|
|
if (state.eventId() != model.id()) return;
|
2025-01-11 11:56:26 +00:00
|
|
|
|
|
|
|
remove_widget([&state]
|
|
|
|
(const auto& w)
|
|
|
|
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(state); });
|
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
set_span_recursive();
|
2025-01-14 23:41:30 +00:00
|
|
|
update();
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
2025-01-11 11:56:26 +00:00
|
|
|
void EventWidget::on_press(int x, int y, bool pressed)
|
2025-01-10 01:38:58 +00:00
|
|
|
{
|
2025-01-19 19:11:10 +00:00
|
|
|
press = pressed;
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
2025-01-14 23:41:30 +00:00
|
|
|
} // namespace Hardware
|