[widgets] span working for timesyncs too

This commit is contained in:
thibaud keller 2025-01-19 00:14:26 +00:00
parent c0edb88f4b
commit 45d3059b08
5 changed files with 35 additions and 16 deletions

View file

@ -23,6 +23,9 @@ EventWidget::EventWidget(Scenario::EventModel& event,
add_widget<StateWidget>(s, scenario); add_widget<StateWidget>(s, scenario);
set_span_recursive(); set_span_recursive();
for(auto& s : children)
static_cast<StateWidget*>(s.get())->set_y();
} }
void EventWidget::set_span_recursive() void EventWidget::set_span_recursive()
@ -47,10 +50,10 @@ void EventWidget::set_span_recursive()
void EventWidget::paint(bugui::painter& painter) const void EventWidget::paint(bugui::painter& painter) const
{ {
const auto col = skin.StateSelected().color(); // const auto col = skin.StateSelected().color();
painter.set_color(col.red(), col.green(), col.blue(), col.alpha()); // painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
painter.draw_line(0, 0, 0, m_height); // painter.draw_line(0, 0, 0, m_height);
} }
bool EventWidget::contains(int px, int py) const bool EventWidget::contains(int px, int py) const
@ -68,6 +71,7 @@ void EventWidget::on_state_added(Scenario::StateModel& state)
add_widget<StateWidget>(state, scenario); add_widget<StateWidget>(state, scenario);
set_span_recursive(); set_span_recursive();
update();
} }
void EventWidget::on_state_removed(const Scenario::StateModel& state) void EventWidget::on_state_removed(const Scenario::StateModel& state)

View file

@ -66,6 +66,7 @@ void ScenarioWidget::paint(bugui::painter& painter) const
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval) void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
{ {
add_widget<IntervalWidget>(interval, this); add_widget<IntervalWidget>(interval, this);
update(); update();
} }
@ -74,13 +75,13 @@ void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval
remove_widget([&interval] remove_widget([&interval]
(const auto& w) (const auto& w)
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(interval); }); { return static_cast<ScenarioComponent<>*>(w.get())->this_model(interval); });
update();
} }
void ScenarioWidget::on_time_sync_added(Scenario::TimeSyncModel& timeSync) void ScenarioWidget::on_time_sync_added(Scenario::TimeSyncModel& timeSync)
{ {
add_widget<TimeSyncWidget>(timeSync, this); add_widget<TimeSyncWidget>(timeSync, this);
update();
} }
void ScenarioWidget::on_time_sync_removed(const Scenario::TimeSyncModel& timeSync) void ScenarioWidget::on_time_sync_removed(const Scenario::TimeSyncModel& timeSync)
@ -88,6 +89,8 @@ void ScenarioWidget::on_time_sync_removed(const Scenario::TimeSyncModel& timeSyn
remove_widget([&timeSync] remove_widget([&timeSync]
(const auto& w) (const auto& w)
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(timeSync); }); { return static_cast<ScenarioComponent<>*>(w.get())->this_model(timeSync); });
update();
} }
} // namespace Hardware } // namespace Hardware

View file

@ -11,13 +11,15 @@ StateWidget::StateWidget(Scenario::StateModel& state,
bugui::container_widget* parent) bugui::container_widget* parent)
: ScenarioComponentSpec<Scenario::StateModel>{state, scenario, parent} : ScenarioComponentSpec<Scenario::StateModel>{state, scenario, parent}
{ {
set_absolute_y();
con = connect(&model, con = connect(&model,
&Scenario::StateModel::heightPercentageChanged, &Scenario::StateModel::heightPercentageChanged,
this, this,
[scenario, this] [scenario, this]
{ {
m_absolute_y = model.heightPercentage() * scenario->height(); set_absolute_y();
set_recursive_span(); set_span_recursive();
scenario->update(); scenario->update();
}); });
} }
@ -64,14 +66,19 @@ void StateWidget::set_absolute_y()
m_absolute_y = model.heightPercentage() * scenario->height(); m_absolute_y = model.heightPercentage() * scenario->height();
} }
void StateWidget::set_recursive_span() void StateWidget::set_y()
{
m_y = m_absolute_y -
bugui::base_widget::parent->y() -
bugui::base_widget::parent->get_parent()->y();
}
void StateWidget::set_span_recursive()
{ {
static_cast<EventWidget*>(bugui::base_widget::parent) static_cast<EventWidget*>(bugui::base_widget::parent)
->set_span_recursive(); ->set_span_recursive();
m_y = m_absolute_y - set_y();
bugui::base_widget::parent->get_parent()->y() -
bugui::base_widget::parent->y();
} }
} // namespace Hardware } // namespace Hardware

View file

@ -16,13 +16,14 @@ struct StateWidget final : QObject
int y() const override { return m_y; } int y() const override { return m_y; }
int get_absolute_y() { return m_absolute_y; }; int get_absolute_y() { return m_absolute_y; };
void set_y();
private: private:
W_OBJECT(StateWidget) W_OBJECT(StateWidget)
QMetaObject::Connection con; QMetaObject::Connection con;
void set_recursive_span(); void set_span_recursive();
void paint(bugui::painter& painter) const override; void paint(bugui::painter& painter) const override;

View file

@ -62,14 +62,18 @@ TimeSyncWidget::~TimeSyncWidget()
void TimeSyncWidget::set_span() void TimeSyncWidget::set_span()
{ {
if (bugui::container_widget::children.empty())
return;
int lowest{std::numeric_limits<int>::max()}; int lowest{std::numeric_limits<int>::max()};
int heighest{0}; int heighest{0};
for(const auto& e : bugui::container_widget::children) for(const auto& e : bugui::container_widget::children)
{ {
int sy = static_cast<EventWidget*>(e.get())->get_absolute_y(); int sy = static_cast<EventWidget*>(e.get())->get_absolute_y();
int sh = sy + static_cast<EventWidget*>(e.get())->height();
if (sy < lowest) lowest = sy; if (sy < lowest) lowest = sy;
if (sy > heighest) heighest = sy; if (sh > heighest) heighest = sh;
} }
m_y = lowest; m_y = lowest;
@ -78,10 +82,10 @@ void TimeSyncWidget::set_span()
void TimeSyncWidget::paint(bugui::painter& painter) const void TimeSyncWidget::paint(bugui::painter& painter) const
{ {
// const auto col = skin.StateDot().color(); const auto col = skin.StateSelected().color();
// painter.set_color(col.red(), col.green(), col.blue(), col.alpha()); painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
// painter.draw_cell(0, 0); painter.draw_line(0, 0, 0, m_height);
} }
bool TimeSyncWidget::contains(int px, int py) const bool TimeSyncWidget::contains(int px, int py) const