[widgets] almost there on scenario hierarchy
This commit is contained in:
parent
aac3b19c00
commit
81e3a81bbd
6 changed files with 41 additions and 37 deletions
|
@ -35,20 +35,18 @@ int EventWidget::height() const
|
||||||
|
|
||||||
void EventWidget::set_y_height(int state_y)
|
void EventWidget::set_y_height(int state_y)
|
||||||
{
|
{
|
||||||
static_cast<TimeSyncWidget*>(parent)->set_y_height(state_y);
|
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y_height(state_y);
|
||||||
|
|
||||||
if (state_y < m_y) m_y = state_y - parent->y();
|
int sy = state_y - bugui::base_widget::parent->y();
|
||||||
if (state_y > m_height) m_height = state_y - parent->y();
|
if (sy < m_y) m_y = sy;
|
||||||
|
if (sy > m_height) m_height = sy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventWidget::set_y_height()
|
void EventWidget::set_y_height()
|
||||||
{
|
{
|
||||||
static_cast<TimeSyncWidget*>(parent)->set_y_height();
|
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_y_height();
|
||||||
|
|
||||||
m_y = std::numeric_limits<int>::max();
|
for(const auto& s : bugui::container_widget::children)
|
||||||
m_height = std::numeric_limits<int>::lowest();
|
|
||||||
|
|
||||||
for(const auto& s : children)
|
|
||||||
{
|
{
|
||||||
int sy = s->y();
|
int sy = s->y();
|
||||||
if (sy < m_y) m_y = sy;
|
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;
|
if (state.eventId() != model.id()) return;
|
||||||
|
|
||||||
add_widget<StateWidget>(state, scenario);
|
add_widget<StateWidget>(state, scenario);
|
||||||
|
|
||||||
set_y_height();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
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<ScenarioComponent<>*>(w.get())->this_model(state); });
|
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(state); });
|
||||||
|
|
||||||
set_y_height();
|
set_y_height();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventWidget::on_press(int x, int y, bool pressed)
|
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!";
|
qDebug() << "is inside!";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Hardware
|
||||||
|
|
|
@ -13,14 +13,13 @@ 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;
|
||||||
int height() const override;
|
int height() const override;
|
||||||
|
|
||||||
void set_y_height(int state_y);
|
void set_y_height(int state_y);
|
||||||
void set_y_height();
|
void set_y_height();
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
bool contains(int px, int py) const override;
|
bool contains(int px, int py) const override;
|
||||||
|
|
||||||
void paint(bugui::painter& painter) const override;
|
void paint(bugui::painter& painter) const override;
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
class ScenarioWidget final
|
class ScenarioWidget final : public bugui::container_widget
|
||||||
: public bugui::container_widget
|
|
||||||
, public Nano::Observer
|
, public Nano::Observer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -14,33 +14,22 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
||||||
connect(&model,
|
connect(&model,
|
||||||
&Scenario::StateModel::heightPercentageChanged,
|
&Scenario::StateModel::heightPercentageChanged,
|
||||||
this,
|
this,
|
||||||
[parent, scenario, this]
|
&StateWidget::set_y);
|
||||||
{
|
|
||||||
static_cast<EventWidget*>(parent)->set_y_height(
|
|
||||||
model.heightPercentage() * scenario->height());
|
|
||||||
});
|
|
||||||
|
|
||||||
static_cast<EventWidget*>(parent)->set_y_height(
|
set_y();
|
||||||
model.heightPercentage() * scenario->height());
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StateWidget::~StateWidget()
|
StateWidget::~StateWidget()
|
||||||
{
|
{
|
||||||
disconnect(&model,
|
// disconnect(&model,
|
||||||
&Scenario::StateModel::heightPercentageChanged,
|
// &Scenario::StateModel::heightPercentageChanged,
|
||||||
this, 0);
|
// this,
|
||||||
|
// &StateWidget::set_y);
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int StateWidget::y() const
|
int StateWidget::y() const
|
||||||
{
|
{
|
||||||
// FIXME : this seems very dirty !
|
return m_y;
|
||||||
return model.heightPercentage() * scenario->height() -
|
|
||||||
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
|
||||||
|
@ -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);
|
model.setHeightPercentage(model.heightPercentage() + increment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StateWidget::set_y()
|
||||||
|
{
|
||||||
|
static_cast<EventWidget*>(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
|
} // namespace Hardware
|
||||||
|
|
||||||
#include <wobjectimpl.h>
|
#include <wobjectimpl.h>
|
||||||
|
|
|
@ -26,6 +26,10 @@ private:
|
||||||
void on_press(int x, int y, bool pressed) override;
|
void on_press(int x, int y, bool pressed) override;
|
||||||
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 m_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace Hardware
|
} //namespace Hardware
|
||||||
|
|
|
@ -32,6 +32,12 @@ 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); });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Scenario::ProcessModel* scen{scenario->get_model()};
|
||||||
|
|
||||||
|
for(Scenario::EventModel& e : scen->events)
|
||||||
|
if (e.timeSync() == model.id())
|
||||||
|
add_widget<EventWidget>(e, scenario);
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeSyncWidget::~TimeSyncWidget()
|
TimeSyncWidget::~TimeSyncWidget()
|
||||||
|
@ -72,9 +78,6 @@ void TimeSyncWidget::set_y_height(int event_y)
|
||||||
|
|
||||||
void TimeSyncWidget::set_y_height()
|
void TimeSyncWidget::set_y_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 ey = e->y();
|
||||||
|
|
Loading…
Add table
Reference in a new issue