diff --git a/Hardware/Widgets/EventWidget.cpp b/Hardware/Widgets/EventWidget.cpp index acb565a..d12a395 100644 --- a/Hardware/Widgets/EventWidget.cpp +++ b/Hardware/Widgets/EventWidget.cpp @@ -35,20 +35,18 @@ int EventWidget::height() const void EventWidget::set_y_height(int state_y) { - static_cast(parent)->set_y_height(state_y); + static_cast(bugui::base_widget::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(); + int sy = state_y - bugui::base_widget::parent->y(); + if (sy < m_y) m_y = sy; + if (sy > m_height) m_height = sy; } void EventWidget::set_y_height() { - static_cast(parent)->set_y_height(); + static_cast(bugui::base_widget::parent)->set_y_height(); - m_y = std::numeric_limits::max(); - m_height = std::numeric_limits::lowest(); - - for(const auto& s : children) + for(const auto& s : bugui::container_widget::children) { int sy = s->y(); if (sy < m_y) m_y = sy; @@ -79,8 +77,6 @@ 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) @@ -92,6 +88,7 @@ void EventWidget::on_state_removed(const Scenario::StateModel& state) { return static_cast*>(w.get())->this_model(state); }); set_y_height(); + update(); } void EventWidget::on_press(int x, int y, bool pressed) @@ -99,4 +96,4 @@ void EventWidget::on_press(int x, int y, bool pressed) qDebug() << "is inside!"; } -} +} // namespace Hardware diff --git a/Hardware/Widgets/EventWidget.hpp b/Hardware/Widgets/EventWidget.hpp index 4bd48bd..0145c14 100644 --- a/Hardware/Widgets/EventWidget.hpp +++ b/Hardware/Widgets/EventWidget.hpp @@ -13,14 +13,13 @@ struct EventWidget final : Nano::Observer ScenarioWidget* scenario, bugui::container_widget* parent); - int y() const override; int height() const override; void set_y_height(int state_y); void set_y_height(); -protected: +private: bool contains(int px, int py) const override; void paint(bugui::painter& painter) const override; diff --git a/Hardware/Widgets/ScenarioWidget.hpp b/Hardware/Widgets/ScenarioWidget.hpp index 581e7f9..2fde41b 100644 --- a/Hardware/Widgets/ScenarioWidget.hpp +++ b/Hardware/Widgets/ScenarioWidget.hpp @@ -6,9 +6,8 @@ namespace Hardware { -class ScenarioWidget final - : public bugui::container_widget - , public Nano::Observer +class ScenarioWidget final : public bugui::container_widget + , public Nano::Observer { public: explicit ScenarioWidget(Scenario::ProcessModel* scenario, diff --git a/Hardware/Widgets/StateWidget.cpp b/Hardware/Widgets/StateWidget.cpp index f3b2135..2a0c31e 100644 --- a/Hardware/Widgets/StateWidget.cpp +++ b/Hardware/Widgets/StateWidget.cpp @@ -14,33 +14,22 @@ StateWidget::StateWidget(Scenario::StateModel& state, connect(&model, &Scenario::StateModel::heightPercentageChanged, this, - [parent, scenario, this] - { - static_cast(parent)->set_y_height( - model.heightPercentage() * scenario->height()); - }); + &StateWidget::set_y); - static_cast(parent)->set_y_height( - model.heightPercentage() * scenario->height()); - - update(); + set_y(); } StateWidget::~StateWidget() { - disconnect(&model, - &Scenario::StateModel::heightPercentageChanged, - this, 0); - - update(); + // disconnect(&model, + // &Scenario::StateModel::heightPercentageChanged, + // this, + // &StateWidget::set_y); } int StateWidget::y() const { - // FIXME : this seems very dirty ! - return model.heightPercentage() * scenario->height() - - bugui::base_widget::parent->get_parent()->y() - - bugui::base_widget::parent->y(); + return m_y; } void StateWidget::paint(bugui::painter& painter) const @@ -75,6 +64,19 @@ void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y) model.setHeightPercentage(model.heightPercentage() + increment); } +void StateWidget::set_y() +{ + static_cast(bugui::base_widget::parent)->set_y_height( + model.heightPercentage() * scenario->height()); + + // FIXME : this seems very dirty ! + m_y = model.heightPercentage() * scenario->height() - + bugui::base_widget::parent->get_parent()->y() - + bugui::base_widget::parent->y(); + + update(); +} + } // namespace Hardware #include diff --git a/Hardware/Widgets/StateWidget.hpp b/Hardware/Widgets/StateWidget.hpp index bdb89c0..bbc18ed 100644 --- a/Hardware/Widgets/StateWidget.hpp +++ b/Hardware/Widgets/StateWidget.hpp @@ -26,6 +26,10 @@ private: void on_press(int x, int y, bool pressed) override; void on_double_press(int x, int y) override; void on_drag(int from_x, int from_y, int to_x, int to_y) override; + + void set_y(); + + int m_y; }; } //namespace Hardware diff --git a/Hardware/Widgets/TimeSyncWidget.cpp b/Hardware/Widgets/TimeSyncWidget.cpp index 494c1a1..c2698d7 100644 --- a/Hardware/Widgets/TimeSyncWidget.cpp +++ b/Hardware/Widgets/TimeSyncWidget.cpp @@ -32,6 +32,12 @@ TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync, (const auto& w) { return static_cast*>(w.get())->this_model(eventId); }); }); + + Scenario::ProcessModel* scen{scenario->get_model()}; + + for(Scenario::EventModel& e : scen->events) + if (e.timeSync() == model.id()) + add_widget(e, scenario); } TimeSyncWidget::~TimeSyncWidget() @@ -72,9 +78,6 @@ void TimeSyncWidget::set_y_height(int event_y) void TimeSyncWidget::set_y_height() { - m_y = std::numeric_limits::max(); - m_height = std::numeric_limits::lowest(); - for(const auto& e : bugui::container_widget::children) { int ey = e->y();