[Span] getting there with setting span recursively
This commit is contained in:
parent
2c8186bb55
commit
c0edb88f4b
6 changed files with 61 additions and 131 deletions
|
@ -22,80 +22,27 @@ EventWidget::EventWidget(Scenario::EventModel& event,
|
||||||
if (s.eventId() == model.id())
|
if (s.eventId() == model.id())
|
||||||
add_widget<StateWidget>(s, scenario);
|
add_widget<StateWidget>(s, scenario);
|
||||||
|
|
||||||
set_recursive_height();
|
set_span_recursive();
|
||||||
}
|
}
|
||||||
|
|
||||||
int EventWidget::y() const
|
void EventWidget::set_span_recursive()
|
||||||
{
|
|
||||||
return m_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
int EventWidget::height() const
|
|
||||||
{
|
|
||||||
return m_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventWidget::set_recursive_y(int state_y)
|
|
||||||
{
|
|
||||||
static_cast<TimeSyncWidget*>(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<int>::max()};
|
int lowest{std::numeric_limits<int>::max()};
|
||||||
|
int heighest{0};
|
||||||
|
|
||||||
for(const auto& s : bugui::container_widget::children)
|
for(const auto& s : bugui::container_widget::children)
|
||||||
{
|
{
|
||||||
int sy = s->y();
|
int sy = static_cast<StateWidget*>(s.get())->get_absolute_y();
|
||||||
if (sy < lowest) lowest = sy;
|
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<int>::lowest()};
|
|
||||||
|
|
||||||
for(const auto& s : bugui::container_widget::children)
|
|
||||||
{
|
|
||||||
int sy = s->y();
|
|
||||||
if (sy > heighest) heighest = sy;
|
if (sy > heighest) heighest = sy;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_height = heighest;
|
m_absolute_y = lowest;
|
||||||
}
|
m_height = heighest - lowest;
|
||||||
|
|
||||||
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_height();
|
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_span();
|
||||||
}
|
|
||||||
|
|
||||||
void EventWidget::set_recursive_y_height()
|
m_y = m_absolute_y - parent->y();
|
||||||
{
|
|
||||||
m_y = std::numeric_limits<int>::max();
|
|
||||||
m_height = std::numeric_limits<int>::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<TimeSyncWidget*>(bugui::base_widget::parent)->set_y(
|
|
||||||
bugui::base_widget::parent->y() + m_height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventWidget::paint(bugui::painter& painter) const
|
void EventWidget::paint(bugui::painter& painter) const
|
||||||
|
@ -120,7 +67,7 @@ void EventWidget::on_state_added(Scenario::StateModel& state)
|
||||||
|
|
||||||
add_widget<StateWidget>(state, scenario);
|
add_widget<StateWidget>(state, scenario);
|
||||||
|
|
||||||
set_recursive_height();
|
set_span_recursive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
||||||
|
@ -131,7 +78,7 @@ void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
||||||
(const auto& w)
|
(const auto& w)
|
||||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(state); });
|
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(state); });
|
||||||
|
|
||||||
set_recursive_y_height();
|
set_span_recursive();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,11 @@ struct EventWidget final : Nano::Observer
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
int y() const override;
|
int y() const override { return m_y; }
|
||||||
int height() const override;
|
int get_absolute_y() { return m_absolute_y; };
|
||||||
|
int height() const override { return m_height; }
|
||||||
|
|
||||||
void set_recursive_y(int state_y);
|
void set_span_recursive();
|
||||||
void set_recursive_height();
|
|
||||||
void set_recursive_y_height();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool contains(int px, int py) const override;
|
bool contains(int px, int py) const override;
|
||||||
|
@ -31,6 +30,7 @@ private:
|
||||||
void on_state_added(Scenario::StateModel& state);
|
void on_state_added(Scenario::StateModel& state);
|
||||||
void on_state_removed(const Scenario::StateModel& state);
|
void on_state_removed(const Scenario::StateModel& state);
|
||||||
|
|
||||||
|
int m_absolute_y{0};
|
||||||
int m_y{0};
|
int m_y{0};
|
||||||
int m_height{0};
|
int m_height{0};
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,33 +11,20 @@ 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}
|
||||||
{
|
{
|
||||||
connect(&model,
|
con = connect(&model,
|
||||||
&Scenario::StateModel::heightPercentageChanged,
|
&Scenario::StateModel::heightPercentageChanged,
|
||||||
this,
|
this,
|
||||||
[this]
|
[scenario, this]
|
||||||
{
|
{
|
||||||
set_recursive_y();
|
m_absolute_y = model.heightPercentage() * scenario->height();
|
||||||
|
set_recursive_span();
|
||||||
static_cast<EventWidget*>(bugui::base_widget::parent)
|
scenario->update();
|
||||||
->set_recursive_height();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
set_recursive_y();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateWidget::~StateWidget()
|
StateWidget::~StateWidget()
|
||||||
// {
|
|
||||||
// FIXME : this disconnect seem to cause crashes
|
|
||||||
// disconnect(&model,
|
|
||||||
// &Scenario::StateModel::heightPercentageChanged,
|
|
||||||
// this, 0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
int StateWidget::y() const
|
|
||||||
{
|
{
|
||||||
return absolute_y -
|
disconnect(con);
|
||||||
bugui::base_widget::parent->get_parent()->y() -
|
|
||||||
bugui::base_widget::parent->y();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateWidget::paint(bugui::painter& painter) const
|
void StateWidget::paint(bugui::painter& painter) const
|
||||||
|
@ -72,12 +59,19 @@ void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||||
model.setHeightPercentage(model.heightPercentage() + increment);
|
model.setHeightPercentage(model.heightPercentage() + increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateWidget::set_recursive_y()
|
void StateWidget::set_absolute_y()
|
||||||
{
|
{
|
||||||
absolute_y = model.heightPercentage() * scenario->height();
|
m_absolute_y = model.heightPercentage() * scenario->height();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateWidget::set_recursive_span()
|
||||||
|
{
|
||||||
static_cast<EventWidget*>(bugui::base_widget::parent)
|
static_cast<EventWidget*>(bugui::base_widget::parent)
|
||||||
->set_recursive_y(absolute_y);
|
->set_span_recursive();
|
||||||
|
|
||||||
|
m_y = m_absolute_y -
|
||||||
|
bugui::base_widget::parent->get_parent()->y() -
|
||||||
|
bugui::base_widget::parent->y();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Hardware
|
} // namespace Hardware
|
||||||
|
|
|
@ -12,14 +12,17 @@ struct StateWidget final : QObject
|
||||||
ScenarioWidget* scenario,
|
ScenarioWidget* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
// ~StateWidget() override;
|
~StateWidget() override;
|
||||||
|
|
||||||
int y() const override;
|
int y() const override { return m_y; }
|
||||||
|
int get_absolute_y() { return m_absolute_y; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
W_OBJECT(StateWidget)
|
W_OBJECT(StateWidget)
|
||||||
|
|
||||||
void set_recursive_y();
|
QMetaObject::Connection con;
|
||||||
|
|
||||||
|
void set_recursive_span();
|
||||||
|
|
||||||
void paint(bugui::painter& painter) const override;
|
void paint(bugui::painter& painter) const override;
|
||||||
|
|
||||||
|
@ -29,7 +32,9 @@ private:
|
||||||
void on_double_press(int x, int y) 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 on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||||
|
|
||||||
int absolute_y;
|
void set_absolute_y();
|
||||||
|
int m_absolute_y;
|
||||||
|
int m_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace Hardware
|
} //namespace Hardware
|
||||||
|
|
|
@ -34,7 +34,7 @@ TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync,
|
||||||
(const auto& w)
|
(const auto& w)
|
||||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(eventId); });
|
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(eventId); });
|
||||||
|
|
||||||
set_height();
|
set_span();
|
||||||
update();
|
update();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -60,35 +60,20 @@ TimeSyncWidget::~TimeSyncWidget()
|
||||||
this, 0);
|
this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TimeSyncWidget::x() const
|
void TimeSyncWidget::set_span()
|
||||||
{
|
{
|
||||||
return model.date().sec();
|
int lowest{std::numeric_limits<int>::max()};
|
||||||
}
|
int heighest{0};
|
||||||
|
|
||||||
int TimeSyncWidget::y() const
|
|
||||||
{
|
|
||||||
return m_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TimeSyncWidget::height() const
|
|
||||||
{
|
|
||||||
return m_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeSyncWidget::set_y(int event_y)
|
|
||||||
{
|
|
||||||
if (event_y < m_y) m_y = event_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeSyncWidget::set_height()
|
|
||||||
{
|
|
||||||
for(const auto& e : bugui::container_widget::children)
|
for(const auto& e : bugui::container_widget::children)
|
||||||
{
|
{
|
||||||
int span = e->y() + e->height();
|
int sy = static_cast<EventWidget*>(e.get())->get_absolute_y();
|
||||||
if (span > m_height) m_height = span;
|
if (sy < lowest) lowest = sy;
|
||||||
|
if (sy > heighest) heighest = sy;
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
m_y = lowest;
|
||||||
|
m_height = heighest - lowest;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeSyncWidget::paint(bugui::painter& painter) const
|
void TimeSyncWidget::paint(bugui::painter& painter) const
|
||||||
|
|
|
@ -16,12 +16,11 @@ struct TimeSyncWidget final : QObject
|
||||||
|
|
||||||
~TimeSyncWidget() override;
|
~TimeSyncWidget() override;
|
||||||
|
|
||||||
int x() const override;
|
int x() const override { return model.date().sec(); }
|
||||||
int y() const override;
|
int y() const override { return m_y; }
|
||||||
int height() const override;
|
int height() const override { return m_height; }
|
||||||
|
|
||||||
void set_y(int event_y);
|
void set_span();
|
||||||
void set_height();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
W_OBJECT(TimeSyncWidget)
|
W_OBJECT(TimeSyncWidget)
|
||||||
|
|
Loading…
Add table
Reference in a new issue