#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); set_recursive_height(); } int EventWidget::y() const { return m_y; } int EventWidget::height() const { return m_height; } void EventWidget::set_recursive_y(int state_y) { static_cast(bugui::base_widget::parent)->set_y(state_y); int relative_y{state_y - bugui::base_widget::parent->y()}; if (children.size() <= 1) m_y = relative_y; else { if (relative_y < m_y) m_y = relative_y; else { int lowest{std::numeric_limits::max()}; for(const auto& s : bugui::container_widget::children) { int sy = s->y(); if (sy < lowest) lowest = sy; } m_y = lowest; } } } void EventWidget::set_recursive_height() { if (children.size() <= 1) m_height = 0; else { int heighest{std::numeric_limits::lowest()}; for(const auto& s : bugui::container_widget::children) { int sy = s->y(); if (sy > heighest) heighest = sy; } m_height = heighest; } static_cast(bugui::base_widget::parent)->set_height(); } void EventWidget::set_recursive_y_height() { m_y = std::numeric_limits::max(); m_height = std::numeric_limits::lowest(); for(const auto& s : bugui::container_widget::children) { int sy = s->y(); if (sy < m_y) m_y = sy; if (sy > m_height) m_height = sy; } static_cast(bugui::base_widget::parent)->set_y( bugui::base_widget::parent->y() + m_height); } void EventWidget::paint(bugui::painter& painter) const { const auto col = skin.StateSelected().color(); painter.set_color(col.red(), col.green(), col.blue(), col.alpha()); painter.draw_line(0, 0, 0, m_height); } 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_recursive_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_recursive_y_height(); update(); } void EventWidget::on_press(int x, int y, bool pressed) { qDebug() << "event pressed"; } void EventWidget::on_double_press(int x, int y, bool pressed) { qDebug() << "event double pressed"; } } // namespace Hardware