#include #include "EventWidget.hpp" #include "ScenarioWidget.hpp" #include "TimeSyncWidget.hpp" namespace Hardware { TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync, ScenarioWidget* scenario, bugui::container_widget* parent) : ScenarioComponentSpec{timeSync, scenario, parent} { Scenario::ProcessModel* scen{scenario->get_model()}; scen->events.mutable_added.connect<&TimeSyncWidget::on_state_added>(this); scen->events.removing.connect<&TimeSyncWidget::on_state_removed>(this); for(Scenario::EventModel& e : scen->events) if (e.timeSync() == model.id()) add_widget(e, scenario); connect(&model, &Scenario::TimeSyncModel::dateChanged, this, [scenario] (const TimeVal&) { if (scenario->changing) return; scenario->update(); }); } TimeSyncWidget::~TimeSyncWidget() { disconnect(&model, &Scenario::TimeSyncModel::dateChanged, this, 0); } void TimeSyncWidget::set_span() { if (bugui::container_widget::children.empty()) return; int lowest{std::numeric_limits::max()}; int heighest{0}; for(const auto& e : bugui::container_widget::children) { auto e_ptr{static_cast(e.get())}; int sy = e_ptr->get_absolute_y(); int sh = sy + e_ptr->height(); if (sy < lowest) lowest = sy; if (sh > heighest) heighest = sh; } m_y = lowest; m_height = heighest - lowest; for(const auto& e : bugui::container_widget::children) static_cast(e.get())->set_y(); } void TimeSyncWidget::time_propagate(const TimeVal& t) { model.setDate(t); for (auto& s : bugui::container_widget::children) static_cast(s.get())->time_propagate(t); } void TimeSyncWidget::on_state_added(Scenario::EventModel& event) { if (event.timeSync() != model.id()) return; add_widget(event, scenario); } void TimeSyncWidget::on_state_removed(const Scenario::EventModel& event) { if (event.timeSync() != model.id()) return; remove_widget([&event] (const auto& w) { return static_cast*>(w.get())->this_model(event); }); set_span(); update(); } void TimeSyncWidget::paint(bugui::painter& painter) const { if (!press && m_height == 0) return; const auto col = model.metadata().getColor().getBrush().color(); // 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 TimeSyncWidget::contains(int px, int py) const { if (px == 0 && py >= 0 && py <= m_height) return true; return false; } } // namespace Hardware #include W_OBJECT_IMPL(Hardware::TimeSyncWidget);