[widgets] span working for timesyncs too
This commit is contained in:
parent
c0edb88f4b
commit
45d3059b08
5 changed files with 35 additions and 16 deletions
|
@ -23,6 +23,9 @@ EventWidget::EventWidget(Scenario::EventModel& event,
|
|||
add_widget<StateWidget>(s, scenario);
|
||||
|
||||
set_span_recursive();
|
||||
|
||||
for(auto& s : children)
|
||||
static_cast<StateWidget*>(s.get())->set_y();
|
||||
}
|
||||
|
||||
void EventWidget::set_span_recursive()
|
||||
|
@ -47,10 +50,10 @@ void EventWidget::set_span_recursive()
|
|||
|
||||
void EventWidget::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_line(0, 0, 0, m_height);
|
||||
// painter.draw_line(0, 0, 0, m_height);
|
||||
}
|
||||
|
||||
bool EventWidget::contains(int px, int py) const
|
||||
|
@ -68,6 +71,7 @@ void EventWidget::on_state_added(Scenario::StateModel& state)
|
|||
add_widget<StateWidget>(state, scenario);
|
||||
|
||||
set_span_recursive();
|
||||
update();
|
||||
}
|
||||
|
||||
void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
||||
|
|
|
@ -66,6 +66,7 @@ void ScenarioWidget::paint(bugui::painter& painter) const
|
|||
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
||||
{
|
||||
add_widget<IntervalWidget>(interval, this);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -74,13 +75,13 @@ void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval
|
|||
remove_widget([&interval]
|
||||
(const auto& w)
|
||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(interval); });
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ScenarioWidget::on_time_sync_added(Scenario::TimeSyncModel& timeSync)
|
||||
{
|
||||
add_widget<TimeSyncWidget>(timeSync, this);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ScenarioWidget::on_time_sync_removed(const Scenario::TimeSyncModel& timeSync)
|
||||
|
@ -88,6 +89,8 @@ void ScenarioWidget::on_time_sync_removed(const Scenario::TimeSyncModel& timeSyn
|
|||
remove_widget([&timeSync]
|
||||
(const auto& w)
|
||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(timeSync); });
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -11,13 +11,15 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
|||
bugui::container_widget* parent)
|
||||
: ScenarioComponentSpec<Scenario::StateModel>{state, scenario, parent}
|
||||
{
|
||||
set_absolute_y();
|
||||
|
||||
con = connect(&model,
|
||||
&Scenario::StateModel::heightPercentageChanged,
|
||||
this,
|
||||
[scenario, this]
|
||||
{
|
||||
m_absolute_y = model.heightPercentage() * scenario->height();
|
||||
set_recursive_span();
|
||||
set_absolute_y();
|
||||
set_span_recursive();
|
||||
scenario->update();
|
||||
});
|
||||
}
|
||||
|
@ -64,14 +66,19 @@ void StateWidget::set_absolute_y()
|
|||
m_absolute_y = model.heightPercentage() * scenario->height();
|
||||
}
|
||||
|
||||
void StateWidget::set_recursive_span()
|
||||
void StateWidget::set_y()
|
||||
{
|
||||
m_y = m_absolute_y -
|
||||
bugui::base_widget::parent->y() -
|
||||
bugui::base_widget::parent->get_parent()->y();
|
||||
}
|
||||
|
||||
void StateWidget::set_span_recursive()
|
||||
{
|
||||
static_cast<EventWidget*>(bugui::base_widget::parent)
|
||||
->set_span_recursive();
|
||||
|
||||
m_y = m_absolute_y -
|
||||
bugui::base_widget::parent->get_parent()->y() -
|
||||
bugui::base_widget::parent->y();
|
||||
set_y();
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -16,13 +16,14 @@ struct StateWidget final : QObject
|
|||
|
||||
int y() const override { return m_y; }
|
||||
int get_absolute_y() { return m_absolute_y; };
|
||||
void set_y();
|
||||
|
||||
private:
|
||||
W_OBJECT(StateWidget)
|
||||
|
||||
QMetaObject::Connection con;
|
||||
|
||||
void set_recursive_span();
|
||||
void set_span_recursive();
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
|
||||
|
|
|
@ -62,14 +62,18 @@ TimeSyncWidget::~TimeSyncWidget()
|
|||
|
||||
void TimeSyncWidget::set_span()
|
||||
{
|
||||
if (bugui::container_widget::children.empty())
|
||||
return;
|
||||
|
||||
int lowest{std::numeric_limits<int>::max()};
|
||||
int heighest{0};
|
||||
|
||||
for(const auto& e : bugui::container_widget::children)
|
||||
{
|
||||
int sy = static_cast<EventWidget*>(e.get())->get_absolute_y();
|
||||
int sh = sy + static_cast<EventWidget*>(e.get())->height();
|
||||
if (sy < lowest) lowest = sy;
|
||||
if (sy > heighest) heighest = sy;
|
||||
if (sh > heighest) heighest = sh;
|
||||
}
|
||||
|
||||
m_y = lowest;
|
||||
|
@ -78,10 +82,10 @@ void TimeSyncWidget::set_span()
|
|||
|
||||
void TimeSyncWidget::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 TimeSyncWidget::contains(int px, int py) const
|
||||
|
|
Loading…
Add table
Reference in a new issue