[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)
|
||||
{
|
||||
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();
|
||||
if (state_y > m_height) m_height = state_y - parent->y();
|
||||
int sy = state_y - bugui::base_widget::parent->y();
|
||||
if (sy < m_y) m_y = sy;
|
||||
if (sy > m_height) m_height = sy;
|
||||
}
|
||||
|
||||
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();
|
||||
m_height = std::numeric_limits<int>::lowest();
|
||||
|
||||
for(const auto& s : children)
|
||||
for(const auto& s : bugui::container_widget::children)
|
||||
{
|
||||
int sy = s->y();
|
||||
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;
|
||||
|
||||
add_widget<StateWidget>(state, scenario);
|
||||
|
||||
set_y_height();
|
||||
}
|
||||
|
||||
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); });
|
||||
|
||||
set_y_height();
|
||||
update();
|
||||
}
|
||||
|
||||
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!";
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -13,14 +13,13 @@ struct EventWidget final : Nano::Observer
|
|||
ScenarioWidget* scenario,
|
||||
bugui::container_widget* parent);
|
||||
|
||||
|
||||
int y() const override;
|
||||
int height() const override;
|
||||
|
||||
void set_y_height(int state_y);
|
||||
void set_y_height();
|
||||
|
||||
protected:
|
||||
private:
|
||||
bool contains(int px, int py) const override;
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
|
|
|
@ -6,9 +6,8 @@
|
|||
|
||||
namespace Hardware
|
||||
{
|
||||
class ScenarioWidget final
|
||||
: public bugui::container_widget
|
||||
, public Nano::Observer
|
||||
class ScenarioWidget final : public bugui::container_widget
|
||||
, public Nano::Observer
|
||||
{
|
||||
public:
|
||||
explicit ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||
|
|
|
@ -14,33 +14,22 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
|||
connect(&model,
|
||||
&Scenario::StateModel::heightPercentageChanged,
|
||||
this,
|
||||
[parent, scenario, this]
|
||||
{
|
||||
static_cast<EventWidget*>(parent)->set_y_height(
|
||||
model.heightPercentage() * scenario->height());
|
||||
});
|
||||
&StateWidget::set_y);
|
||||
|
||||
static_cast<EventWidget*>(parent)->set_y_height(
|
||||
model.heightPercentage() * scenario->height());
|
||||
|
||||
update();
|
||||
set_y();
|
||||
}
|
||||
|
||||
StateWidget::~StateWidget()
|
||||
{
|
||||
disconnect(&model,
|
||||
&Scenario::StateModel::heightPercentageChanged,
|
||||
this, 0);
|
||||
|
||||
update();
|
||||
// disconnect(&model,
|
||||
// &Scenario::StateModel::heightPercentageChanged,
|
||||
// this,
|
||||
// &StateWidget::set_y);
|
||||
}
|
||||
|
||||
int StateWidget::y() const
|
||||
{
|
||||
// FIXME : this seems very dirty !
|
||||
return model.heightPercentage() * scenario->height() -
|
||||
bugui::base_widget::parent->get_parent()->y() -
|
||||
bugui::base_widget::parent->y();
|
||||
return m_y;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#include <wobjectimpl.h>
|
||||
|
|
|
@ -26,6 +26,10 @@ private:
|
|||
void on_press(int x, int y, bool pressed) 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 set_y();
|
||||
|
||||
int m_y;
|
||||
};
|
||||
|
||||
} //namespace Hardware
|
||||
|
|
|
@ -32,6 +32,12 @@ TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync,
|
|||
(const auto& w)
|
||||
{ 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()
|
||||
|
@ -72,9 +78,6 @@ void TimeSyncWidget::set_y_height(int event_y)
|
|||
|
||||
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)
|
||||
{
|
||||
int ey = e->y();
|
||||
|
|
Loading…
Add table
Reference in a new issue