[widgets] WIP on scenario hierarchy
This commit is contained in:
parent
7468c290b6
commit
aac3b19c00
8 changed files with 45 additions and 20 deletions
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit cdb5364672da1c0669c68020d7e5df418093c421
|
||||
Subproject commit a35f73f5e0600726458454c23ffcf1e1ceb98d8e
|
|
@ -21,9 +21,6 @@ EventWidget::EventWidget(Scenario::EventModel& event,
|
|||
for(Scenario::StateModel& s : scen->states)
|
||||
if (s.eventId() == model.id())
|
||||
add_widget<StateWidget>(s, scenario);
|
||||
|
||||
set_y_height();
|
||||
update();
|
||||
}
|
||||
|
||||
int EventWidget::y() const
|
||||
|
@ -36,8 +33,18 @@ int EventWidget::height() const
|
|||
return m_height;
|
||||
}
|
||||
|
||||
void EventWidget::set_y_height(int state_y)
|
||||
{
|
||||
static_cast<TimeSyncWidget*>(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();
|
||||
}
|
||||
|
||||
void EventWidget::set_y_height()
|
||||
{
|
||||
static_cast<TimeSyncWidget*>(parent)->set_y_height();
|
||||
|
||||
m_y = std::numeric_limits<int>::max();
|
||||
m_height = std::numeric_limits<int>::lowest();
|
||||
|
||||
|
@ -49,8 +56,6 @@ void EventWidget::set_y_height()
|
|||
int sh = s->height();
|
||||
if (sh > m_height) m_height = sh;
|
||||
}
|
||||
|
||||
static_cast<TimeSyncWidget*>(parent)->set_y_height();
|
||||
}
|
||||
|
||||
void EventWidget::paint(bugui::painter& painter) const
|
||||
|
|
|
@ -17,6 +17,7 @@ struct EventWidget final : Nano::Observer
|
|||
int y() const override;
|
||||
int height() const override;
|
||||
|
||||
void set_y_height(int state_y);
|
||||
void set_y_height();
|
||||
|
||||
protected:
|
||||
|
@ -28,8 +29,8 @@ protected:
|
|||
void on_state_added(Scenario::StateModel& state);
|
||||
void on_state_removed(const Scenario::StateModel& state);
|
||||
|
||||
int m_y;
|
||||
int m_height;
|
||||
int m_y{std::numeric_limits<int>::max()};
|
||||
int m_height{std::numeric_limits<int>::lowest()};
|
||||
};
|
||||
|
||||
} //namespace Hardware
|
||||
|
|
|
@ -23,10 +23,10 @@ struct IntervalWidget final : ScenarioComponentSpec<Scenario::IntervalModel>
|
|||
private:
|
||||
W_OBJECT(IntervalWidget)
|
||||
|
||||
bool contains(int px, int py) const override;
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
|
||||
bool contains(int px, int py) const override;
|
||||
|
||||
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;
|
||||
|
|
|
@ -14,7 +14,16 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
|||
connect(&model,
|
||||
&Scenario::StateModel::heightPercentageChanged,
|
||||
this,
|
||||
[parent] { static_cast<EventWidget*>(parent)->set_y_height(); });
|
||||
[parent, scenario, this]
|
||||
{
|
||||
static_cast<EventWidget*>(parent)->set_y_height(
|
||||
model.heightPercentage() * scenario->height());
|
||||
});
|
||||
|
||||
static_cast<EventWidget*>(parent)->set_y_height(
|
||||
model.heightPercentage() * scenario->height());
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
StateWidget::~StateWidget()
|
||||
|
@ -22,11 +31,16 @@ StateWidget::~StateWidget()
|
|||
disconnect(&model,
|
||||
&Scenario::StateModel::heightPercentageChanged,
|
||||
this, 0);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
int StateWidget::y() const
|
||||
{
|
||||
return model.heightPercentage() * scenario->height();
|
||||
// FIXME : this seems very dirty !
|
||||
return model.heightPercentage() * scenario->height() -
|
||||
bugui::base_widget::parent->get_parent()->y() -
|
||||
bugui::base_widget::parent->y();
|
||||
}
|
||||
|
||||
void StateWidget::paint(bugui::painter& painter) const
|
||||
|
|
|
@ -19,13 +19,13 @@ struct StateWidget final : QObject
|
|||
private:
|
||||
W_OBJECT(StateWidget)
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
|
||||
bool contains(int px, int py) const override;
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
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;
|
||||
};
|
||||
|
||||
} //namespace Hardware
|
||||
|
||||
|
|
|
@ -64,6 +64,12 @@ int TimeSyncWidget::height() const
|
|||
return m_height;
|
||||
}
|
||||
|
||||
void TimeSyncWidget::set_y_height(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()
|
||||
{
|
||||
m_y = std::numeric_limits<int>::max();
|
||||
|
@ -72,13 +78,11 @@ void TimeSyncWidget::set_y_height()
|
|||
for(const auto& e : bugui::container_widget::children)
|
||||
{
|
||||
int ey = e->y();
|
||||
if (ey <= m_y) m_y = ey;
|
||||
if (ey < m_y) m_y = ey;
|
||||
|
||||
int eh = e->height();
|
||||
if (eh >= m_height) m_height = eh;
|
||||
if (eh > m_height) m_height = eh;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TimeSyncWidget::paint(bugui::painter& painter) const
|
||||
|
|
|
@ -20,6 +20,7 @@ struct TimeSyncWidget final : QObject
|
|||
int y() const override;
|
||||
int height() const override;
|
||||
|
||||
void set_y_height(int event_y);
|
||||
void set_y_height();
|
||||
|
||||
private:
|
||||
|
@ -30,8 +31,8 @@ private:
|
|||
void paint(bugui::painter& painter) const override;
|
||||
void on_press(int x, int y, bool pressed) override;
|
||||
|
||||
int m_y;
|
||||
int m_height;
|
||||
int m_y{std::numeric_limits<int>::max()};
|
||||
int m_height{std::numeric_limits<int>::lowest()};
|
||||
};
|
||||
|
||||
} //namespace Hardware
|
||||
|
|
Loading…
Add table
Reference in a new issue