[Widgets] WIP on set_recursive_y & set_recursive_height

This commit is contained in:
thibaud keller 2025-01-17 22:16:43 +00:00
parent 94135cbb43
commit 2c8186bb55
9 changed files with 95 additions and 67 deletions

@ -1 +1 @@
Subproject commit 0a04a681f6f1baf201c48ce2c27ff848b2101ed2 Subproject commit 6a0c86674d0f1513c92140530d2221051ed05ee5

View file

@ -36,8 +36,6 @@ DocumentPlugin::DocumentPlugin(const score::DocumentContext& doc, QObject* paren
Qt::QueuedConnection); Qt::QueuedConnection);
} }
DocumentPlugin::~DocumentPlugin() { }
void DocumentPlugin::on_documentClosing() void DocumentPlugin::on_documentClosing()
{ {
cleanup(); cleanup();
@ -62,4 +60,5 @@ void DocumentPlugin::cleanup()
delete ctrlr; delete ctrlr;
ctrlr = nullptr; ctrlr = nullptr;
} }
}
} // namespace Hardware

View file

@ -17,7 +17,6 @@ class SCORE_ADDON_HARDWARE_EXPORT DocumentPlugin : public score::DocumentPlugin
{ {
public: public:
DocumentPlugin(const score::DocumentContext& doc, QObject* parent); DocumentPlugin(const score::DocumentContext& doc, QObject* parent);
~DocumentPlugin();
void on_documentClosing() override; void on_documentClosing() override;

View file

@ -21,6 +21,8 @@ EventWidget::EventWidget(Scenario::EventModel& event,
for(Scenario::StateModel& s : scen->states) for(Scenario::StateModel& s : scen->states)
if (s.eventId() == model.id()) if (s.eventId() == model.id())
add_widget<StateWidget>(s, scenario); add_widget<StateWidget>(s, scenario);
set_recursive_height();
} }
int EventWidget::y() const int EventWidget::y() const
@ -33,19 +35,55 @@ int EventWidget::height() const
return m_height; return m_height;
} }
void EventWidget::set_y_height(int state_y) void EventWidget::set_recursive_y(int state_y)
{ {
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y_height(state_y); static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y(state_y);
int sy = state_y - bugui::base_widget::parent->y(); int relative_y{state_y - bugui::base_widget::parent->y()};
if (sy < m_y) m_y = sy;
if (sy > m_height) m_height = sy; 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()};
for(const auto& s : bugui::container_widget::children)
{
int sy = s->y();
if (sy < lowest) lowest = sy;
}
m_y = lowest;
}
}
} }
void EventWidget::set_y_height() void EventWidget::set_recursive_height()
{ {
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y_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;
}
m_height = heighest;
}
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_height();
}
void EventWidget::set_recursive_y_height()
{
m_y = std::numeric_limits<int>::max(); m_y = std::numeric_limits<int>::max();
m_height = std::numeric_limits<int>::lowest(); m_height = std::numeric_limits<int>::lowest();
@ -53,18 +91,19 @@ void EventWidget::set_y_height()
{ {
int sy = s->y(); int sy = s->y();
if (sy < m_y) m_y = sy; if (sy < m_y) m_y = sy;
if (sy > m_height) m_height = sy;
int sh = s->height();
if (sh > m_height) m_height = sh;
} }
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
{ {
// 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 EventWidget::contains(int px, int py) const bool EventWidget::contains(int px, int py) const
@ -81,9 +120,7 @@ void EventWidget::on_state_added(Scenario::StateModel& state)
add_widget<StateWidget>(state, scenario); add_widget<StateWidget>(state, scenario);
// FIXME: workaround for update() not working set_recursive_height();
// in the constructor of StateWidget
update();
} }
void EventWidget::on_state_removed(const Scenario::StateModel& state) void EventWidget::on_state_removed(const Scenario::StateModel& state)
@ -94,7 +131,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_y_height(); set_recursive_y_height();
update(); update();
} }

View file

@ -16,8 +16,9 @@ struct EventWidget final : Nano::Observer
int y() const override; int y() const override;
int height() const override; int height() const override;
void set_y_height(int state_y); void set_recursive_y(int state_y);
void set_y_height(); 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;
@ -30,8 +31,8 @@ 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_y{std::numeric_limits<int>::max()}; int m_y{0};
int m_height{std::numeric_limits<int>::lowest()}; int m_height{0};
}; };
} //namespace Hardware } //namespace Hardware

View file

@ -16,32 +16,36 @@ StateWidget::StateWidget(Scenario::StateModel& state,
this, this,
[this] [this]
{ {
set_y(); set_recursive_y();
update();
static_cast<EventWidget*>(bugui::base_widget::parent)
->set_recursive_height();
}); });
set_y(); set_recursive_y();
} }
StateWidget::~StateWidget() // StateWidget::~StateWidget()
{ // {
// FIXME : this disconnect seem to cause crashes // FIXME : this disconnect seem to cause crashes
// disconnect(&model, // disconnect(&model,
// &Scenario::StateModel::heightPercentageChanged, // &Scenario::StateModel::heightPercentageChanged,
// this, 0); // this, 0);
} // }
int StateWidget::y() const int StateWidget::y() const
{ {
return m_y; return absolute_y -
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
{ {
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_cell(0, 0); // painter.draw_cell(0, 0);
} }
bool StateWidget::contains(int px, int py) const bool StateWidget::contains(int px, int py) const
@ -68,19 +72,12 @@ 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_y() void StateWidget::set_recursive_y()
{ {
static_cast<EventWidget*>(bugui::base_widget::parent)->set_y_height( absolute_y = model.heightPercentage() * scenario->height();
model.heightPercentage() * scenario->height());
// FIXME : this seems very dirty ! static_cast<EventWidget*>(bugui::base_widget::parent)
m_y = model.heightPercentage() * scenario->height() - ->set_recursive_y(absolute_y);
bugui::base_widget::parent->get_parent()->y() -
bugui::base_widget::parent->y();
// FIXME : update dosen't work here for the constructor
// curently moved to EventWidget::on_state_added
} }
} // namespace Hardware } // namespace Hardware

View file

@ -12,13 +12,15 @@ 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;
private: private:
W_OBJECT(StateWidget) W_OBJECT(StateWidget)
void set_recursive_y();
void paint(bugui::painter& painter) const override; void paint(bugui::painter& painter) const override;
bool contains(int px, int py) const override; bool contains(int px, int py) const override;
@ -27,9 +29,7 @@ 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;
void set_y(); int absolute_y;
int m_y;
}; };
} //namespace Hardware } //namespace Hardware

View file

@ -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_y_height(); set_height();
update(); update();
}); });
@ -75,25 +75,20 @@ int TimeSyncWidget::height() const
return m_height; return m_height;
} }
void TimeSyncWidget::set_y_height(int event_y) void TimeSyncWidget::set_y(int event_y)
{ {
if (event_y < m_y) m_y = event_y; if (event_y < m_y) m_y = event_y;
if (event_y > m_height) m_height = event_y;
} }
void TimeSyncWidget::set_y_height() void TimeSyncWidget::set_height()
{ {
m_y = std::numeric_limits<int>::max();
m_height = std::numeric_limits<int>::lowest();
for(const auto& e : bugui::container_widget::children) for(const auto& e : bugui::container_widget::children)
{ {
int ey = e->y(); int span = e->y() + e->height();
if (ey < m_y) m_y = ey; if (span > m_height) m_height = span;
int eh = e->height();
if (eh > m_height) m_height = eh;
} }
update();
} }
void TimeSyncWidget::paint(bugui::painter& painter) const void TimeSyncWidget::paint(bugui::painter& painter) const

View file

@ -20,8 +20,8 @@ struct TimeSyncWidget final : QObject
int y() const override; int y() const override;
int height() const override; int height() const override;
void set_y_height(int event_y); void set_y(int event_y);
void set_y_height(); void set_height();
private: private:
W_OBJECT(TimeSyncWidget) W_OBJECT(TimeSyncWidget)
@ -31,8 +31,8 @@ private:
void paint(bugui::painter& painter) const override; void paint(bugui::painter& painter) const override;
void on_press(int x, int y, bool pressed) override; void on_press(int x, int y, bool pressed) override;
int m_y{std::numeric_limits<int>::max()}; int m_y{0};
int m_height{std::numeric_limits<int>::lowest()}; int m_height{0};
}; };
} //namespace Hardware } //namespace Hardware