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-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EventWidget::y() const
|
|
|
|
{
|
2025-01-11 11:56:26 +00:00
|
|
|
return m_y;
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int EventWidget::height() const
|
|
|
|
{
|
2025-01-11 11:56:26 +00:00
|
|
|
return m_height;
|
|
|
|
}
|
|
|
|
|
2025-01-14 00:04:35 +00:00
|
|
|
void EventWidget::set_y_height(int state_y)
|
|
|
|
{
|
2025-01-14 23:41:30 +00:00
|
|
|
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y_height(state_y);
|
2025-01-14 00:04:35 +00:00
|
|
|
|
2025-01-14 23:41:30 +00:00
|
|
|
int sy = state_y - bugui::base_widget::parent->y();
|
|
|
|
if (sy < m_y) m_y = sy;
|
|
|
|
if (sy > m_height) m_height = sy;
|
2025-01-14 00:04:35 +00:00
|
|
|
}
|
|
|
|
|
2025-01-11 11:56:26 +00:00
|
|
|
void EventWidget::set_y_height()
|
|
|
|
{
|
2025-01-14 23:41:30 +00:00
|
|
|
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y_height();
|
2025-01-14 00:04:35 +00:00
|
|
|
|
2025-01-16 02:00:26 +00:00
|
|
|
m_y = std::numeric_limits<int>::max();
|
|
|
|
m_height = std::numeric_limits<int>::lowest();
|
|
|
|
|
2025-01-14 23:41:30 +00:00
|
|
|
for(const auto& s : bugui::container_widget::children)
|
2025-01-11 11:56:26 +00:00
|
|
|
{
|
|
|
|
int sy = s->y();
|
|
|
|
if (sy < m_y) m_y = sy;
|
|
|
|
|
|
|
|
int sh = s->height();
|
|
|
|
if (sh > m_height) m_height = sh;
|
|
|
|
}
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventWidget::paint(bugui::painter& painter) const
|
|
|
|
{
|
|
|
|
// const auto col = skin.StateDot().color();
|
|
|
|
// painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
|
|
|
|
|
|
|
// painter.draw_cell(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EventWidget::contains(int px, int py) const
|
|
|
|
{
|
|
|
|
if (px == x() && py == y())
|
|
|
|
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
|
|
|
|
|
|
|
// FIXME: workaround for update() not working
|
|
|
|
// in the constructor of StateWidget
|
|
|
|
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); });
|
|
|
|
|
|
|
|
set_y_height();
|
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-11 11:56:26 +00:00
|
|
|
qDebug() << "is inside!";
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
2025-01-14 23:41:30 +00:00
|
|
|
} // namespace Hardware
|