#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} { connect(&model, &Scenario::TimeSyncModel::dateChanged, this, [scenario] (const TimeVal&) { scenario->update(); }); connect(&model, &Scenario::TimeSyncModel::newEvent, this, [scenario, this] (const Id& eventId) { add_widget(scenario->get_model()->events.at(eventId), scenario); }); connect(&model, &Scenario::TimeSyncModel::eventRemoved, this, [scenario, this] (const Id& eventId) { remove_widget([&eventId] (const auto& w) { return static_cast*>(w.get())->this_model(eventId); }); set_span(); update(); }); Scenario::ProcessModel* scen{scenario->get_model()}; for(Scenario::EventModel& e : scen->events) if (e.timeSync() == model.id()) add_widget(e, scenario); } TimeSyncWidget::~TimeSyncWidget() { disconnect(&model, &Scenario::TimeSyncModel::dateChanged, this, 0); disconnect(&model, &Scenario::TimeSyncModel::newEvent, this, 0); disconnect(&model, &Scenario::TimeSyncModel::eventRemoved, 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) { int sy = static_cast(e.get())->get_absolute_y(); int sh = sy + static_cast(e.get())->height(); if (sy < lowest) lowest = sy; if (sh > heighest) heighest = sh; } m_y = lowest; m_height = heighest - lowest; } void TimeSyncWidget::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 TimeSyncWidget::contains(int px, int py) const { if (px == x() && py == y()) return true; return false; } void TimeSyncWidget::on_press(int x, int y, bool pressed) { qDebug() << "timeSync pressed"; } } // namespace Hardware #include W_OBJECT_IMPL(Hardware::TimeSyncWidget);