[Widgets] WIP on set_recursive_y & set_recursive_height
This commit is contained in:
parent
94135cbb43
commit
2c8186bb55
9 changed files with 95 additions and 67 deletions
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 0a04a681f6f1baf201c48ce2c27ff848b2101ed2
|
||||
Subproject commit 6a0c86674d0f1513c92140530d2221051ed05ee5
|
|
@ -36,8 +36,6 @@ DocumentPlugin::DocumentPlugin(const score::DocumentContext& doc, QObject* paren
|
|||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
DocumentPlugin::~DocumentPlugin() { }
|
||||
|
||||
void DocumentPlugin::on_documentClosing()
|
||||
{
|
||||
cleanup();
|
||||
|
@ -62,4 +60,5 @@ void DocumentPlugin::cleanup()
|
|||
delete ctrlr;
|
||||
ctrlr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -17,7 +17,6 @@ class SCORE_ADDON_HARDWARE_EXPORT DocumentPlugin : public score::DocumentPlugin
|
|||
{
|
||||
public:
|
||||
DocumentPlugin(const score::DocumentContext& doc, QObject* parent);
|
||||
~DocumentPlugin();
|
||||
|
||||
void on_documentClosing() override;
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ EventWidget::EventWidget(Scenario::EventModel& event,
|
|||
for(Scenario::StateModel& s : scen->states)
|
||||
if (s.eventId() == model.id())
|
||||
add_widget<StateWidget>(s, scenario);
|
||||
|
||||
set_recursive_height();
|
||||
}
|
||||
|
||||
int EventWidget::y() const
|
||||
|
@ -33,19 +35,55 @@ int EventWidget::height() const
|
|||
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();
|
||||
if (sy < m_y) m_y = sy;
|
||||
if (sy > m_height) m_height = sy;
|
||||
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()};
|
||||
|
||||
for(const auto& s : bugui::container_widget::children)
|
||||
{
|
||||
int sy = s->y();
|
||||
if (sy < lowest) lowest = sy;
|
||||
}
|
||||
|
||||
void EventWidget::set_y_height()
|
||||
{
|
||||
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y_height();
|
||||
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;
|
||||
}
|
||||
|
||||
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_height = std::numeric_limits<int>::lowest();
|
||||
|
||||
|
@ -53,18 +91,19 @@ void EventWidget::set_y_height()
|
|||
{
|
||||
int sy = s->y();
|
||||
if (sy < m_y) m_y = sy;
|
||||
|
||||
int sh = s->height();
|
||||
if (sh > m_height) m_height = sh;
|
||||
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
|
||||
{
|
||||
// const auto col = skin.StateDot().color();
|
||||
// painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
const auto col = skin.StateSelected().color();
|
||||
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
|
||||
|
@ -81,9 +120,7 @@ void EventWidget::on_state_added(Scenario::StateModel& state)
|
|||
|
||||
add_widget<StateWidget>(state, scenario);
|
||||
|
||||
// FIXME: workaround for update() not working
|
||||
// in the constructor of StateWidget
|
||||
update();
|
||||
set_recursive_height();
|
||||
}
|
||||
|
||||
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)
|
||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(state); });
|
||||
|
||||
set_y_height();
|
||||
set_recursive_y_height();
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@ struct EventWidget final : Nano::Observer
|
|||
int y() const override;
|
||||
int height() const override;
|
||||
|
||||
void set_y_height(int state_y);
|
||||
void set_y_height();
|
||||
void set_recursive_y(int state_y);
|
||||
void set_recursive_height();
|
||||
void set_recursive_y_height();
|
||||
|
||||
private:
|
||||
bool contains(int px, int py) const override;
|
||||
|
@ -30,8 +31,8 @@ private:
|
|||
void on_state_added(Scenario::StateModel& state);
|
||||
void on_state_removed(const Scenario::StateModel& state);
|
||||
|
||||
int m_y{std::numeric_limits<int>::max()};
|
||||
int m_height{std::numeric_limits<int>::lowest()};
|
||||
int m_y{0};
|
||||
int m_height{0};
|
||||
};
|
||||
|
||||
} //namespace Hardware
|
||||
|
|
|
@ -16,32 +16,36 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
|||
this,
|
||||
[this]
|
||||
{
|
||||
set_y();
|
||||
update();
|
||||
set_recursive_y();
|
||||
|
||||
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
|
||||
// disconnect(&model,
|
||||
// &Scenario::StateModel::heightPercentageChanged,
|
||||
// this, 0);
|
||||
}
|
||||
// }
|
||||
|
||||
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
|
||||
{
|
||||
const auto col = skin.StateSelected().color();
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
// const auto col = skin.StateSelected().color();
|
||||
// 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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
void StateWidget::set_y()
|
||||
void StateWidget::set_recursive_y()
|
||||
{
|
||||
static_cast<EventWidget*>(bugui::base_widget::parent)->set_y_height(
|
||||
model.heightPercentage() * scenario->height());
|
||||
absolute_y = 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();
|
||||
|
||||
|
||||
// FIXME : update dosen't work here for the constructor
|
||||
// curently moved to EventWidget::on_state_added
|
||||
static_cast<EventWidget*>(bugui::base_widget::parent)
|
||||
->set_recursive_y(absolute_y);
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -12,13 +12,15 @@ struct StateWidget final : QObject
|
|||
ScenarioWidget* scenario,
|
||||
bugui::container_widget* parent);
|
||||
|
||||
~StateWidget() override;
|
||||
// ~StateWidget() override;
|
||||
|
||||
int y() const override;
|
||||
|
||||
private:
|
||||
W_OBJECT(StateWidget)
|
||||
|
||||
void set_recursive_y();
|
||||
|
||||
void paint(bugui::painter& painter) 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_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||
|
||||
void set_y();
|
||||
|
||||
int m_y;
|
||||
int absolute_y;
|
||||
};
|
||||
|
||||
} //namespace Hardware
|
||||
|
|
|
@ -34,7 +34,7 @@ TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync,
|
|||
(const auto& w)
|
||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(eventId); });
|
||||
|
||||
set_y_height();
|
||||
set_height();
|
||||
update();
|
||||
});
|
||||
|
||||
|
@ -75,25 +75,20 @@ int TimeSyncWidget::height() const
|
|||
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_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)
|
||||
{
|
||||
int ey = e->y();
|
||||
if (ey < m_y) m_y = ey;
|
||||
|
||||
int eh = e->height();
|
||||
if (eh > m_height) m_height = eh;
|
||||
int span = e->y() + e->height();
|
||||
if (span > m_height) m_height = span;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TimeSyncWidget::paint(bugui::painter& painter) const
|
||||
|
|
|
@ -20,8 +20,8 @@ struct TimeSyncWidget final : QObject
|
|||
int y() const override;
|
||||
int height() const override;
|
||||
|
||||
void set_y_height(int event_y);
|
||||
void set_y_height();
|
||||
void set_y(int event_y);
|
||||
void set_height();
|
||||
|
||||
private:
|
||||
W_OBJECT(TimeSyncWidget)
|
||||
|
@ -31,8 +31,8 @@ private:
|
|||
void paint(bugui::painter& painter) const override;
|
||||
void on_press(int x, int y, bool pressed) override;
|
||||
|
||||
int m_y{std::numeric_limits<int>::max()};
|
||||
int m_height{std::numeric_limits<int>::lowest()};
|
||||
int m_y{0};
|
||||
int m_height{0};
|
||||
};
|
||||
|
||||
} //namespace Hardware
|
||||
|
|
Loading…
Add table
Reference in a new issue