#include #include "TimeSyncWidget.hpp" #include "StateWidget.hpp" #include "ScenarioWidget.hpp" #include "EventWidget.hpp" namespace Hardware { EventWidget::EventWidget(Scenario::EventModel& event, ScenarioWidget* scenario, bugui::container_widget* parent) : ScenarioComponentSpec{event, scenario, parent} { 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(s, scenario); } int EventWidget::y() const { return m_y; } int EventWidget::height() const { return m_height; } void EventWidget::set_y_height(int state_y) { static_cast(parent)->set_y_height(state_y); if (state_y < m_y) m_y = state_y - parent->y(); if (state_y > m_height) m_height = state_y - parent->y(); } void EventWidget::set_y_height() { static_cast(parent)->set_y_height(); m_y = std::numeric_limits::max(); m_height = std::numeric_limits::lowest(); for(const auto& s : children) { int sy = s->y(); if (sy < m_y) m_y = sy; int sh = s->height(); if (sh > m_height) m_height = sh; } } 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; } void EventWidget::on_state_added(Scenario::StateModel& state) { if (state.eventId() != model.id()) return; add_widget(state, scenario); set_y_height(); } void EventWidget::on_state_removed(const Scenario::StateModel& state) { if (state.eventId() != model.id()) return; remove_widget([&state] (const auto& w) { return static_cast*>(w.get())->this_model(state); }); set_y_height(); } void EventWidget::on_press(int x, int y, bool pressed) { qDebug() << "is inside!"; } }