[widgets] various fixes
This commit is contained in:
parent
81e3a81bbd
commit
9887ab6f8d
6 changed files with 47 additions and 9 deletions
|
@ -46,6 +46,9 @@ void EventWidget::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 : bugui::container_widget::children)
|
||||
{
|
||||
int sy = s->y();
|
||||
|
@ -77,6 +80,10 @@ void EventWidget::on_state_added(Scenario::StateModel& state)
|
|||
if (state.eventId() != model.id()) return;
|
||||
|
||||
add_widget<StateWidget>(state, scenario);
|
||||
|
||||
// FIXME: workaround for update() not working
|
||||
// in the constructor of StateWidget
|
||||
update();
|
||||
}
|
||||
|
||||
void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
||||
|
|
|
@ -50,10 +50,10 @@ int IntervalWidget::width() const
|
|||
void IntervalWidget::paint(bugui::painter& painter) const
|
||||
{
|
||||
// Copied from MiniscenarioView
|
||||
const auto col = skin.IntervalBase().color();
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
// const auto col = skin.IntervalBase().color();
|
||||
// painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
|
||||
painter.draw_line(0, 0, width(), 0);
|
||||
// painter.draw_line(0, 0, width(), 0);
|
||||
}
|
||||
|
||||
bool IntervalWidget::contains(int px, int py) const
|
||||
|
|
|
@ -9,6 +9,7 @@ ScenarioWidget::ScenarioWidget(Scenario::ProcessModel* scenario,
|
|||
bugui::container_widget* parent)
|
||||
: bugui::container_widget{parent}
|
||||
, model{scenario}
|
||||
, skin{Process::Style::instance()}
|
||||
{
|
||||
model->intervals.mutable_added.connect<&ScenarioWidget::on_interval_added>(this);
|
||||
model->intervals.removed.connect<&ScenarioWidget::on_interval_removed>(this);
|
||||
|
@ -48,6 +49,20 @@ Scenario::ProcessModel *ScenarioWidget::get_model() const
|
|||
return model;
|
||||
}
|
||||
|
||||
void ScenarioWidget::paint(bugui::painter& painter) const
|
||||
{
|
||||
const auto col = skin.IntervalBase().color();
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
|
||||
for (const auto& i : model->intervals)
|
||||
{
|
||||
int y{static_cast<int>(i.heightPercentage() * height())};
|
||||
int st{static_cast<int>(i.date().sec())};
|
||||
|
||||
painter.draw_line(st, y, st + i.duration.defaultDuration().sec(), y);
|
||||
}
|
||||
}
|
||||
|
||||
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
||||
{
|
||||
add_widget<IntervalWidget>(interval, this);
|
||||
|
|
|
@ -21,6 +21,8 @@ public:
|
|||
Scenario::ProcessModel* get_model() const;
|
||||
|
||||
private:
|
||||
void paint(bugui::painter& painter) const override;
|
||||
|
||||
void on_interval_added(Scenario::IntervalModel& interval);
|
||||
void on_interval_removed(const Scenario::IntervalModel& interval);
|
||||
|
||||
|
@ -28,6 +30,7 @@ private:
|
|||
void on_time_sync_removed(const Scenario::TimeSyncModel& timeSync);
|
||||
|
||||
Scenario::ProcessModel* model{nullptr};
|
||||
const Process::Style& skin;
|
||||
};
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -14,7 +14,11 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
|||
connect(&model,
|
||||
&Scenario::StateModel::heightPercentageChanged,
|
||||
this,
|
||||
&StateWidget::set_y);
|
||||
[this]
|
||||
{
|
||||
set_y();
|
||||
update();
|
||||
});
|
||||
|
||||
set_y();
|
||||
}
|
||||
|
@ -23,8 +27,7 @@ StateWidget::~StateWidget()
|
|||
{
|
||||
// disconnect(&model,
|
||||
// &Scenario::StateModel::heightPercentageChanged,
|
||||
// this,
|
||||
// &StateWidget::set_y);
|
||||
// this, 0);
|
||||
}
|
||||
|
||||
int StateWidget::y() const
|
||||
|
@ -34,7 +37,7 @@ int StateWidget::y() const
|
|||
|
||||
void StateWidget::paint(bugui::painter& painter) const
|
||||
{
|
||||
const auto col = skin.StateDot().color();
|
||||
const auto col = skin.StateSelected().color();
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
|
||||
painter.draw_cell(0, 0);
|
||||
|
@ -74,7 +77,9 @@ void StateWidget::set_y()
|
|||
bugui::base_widget::parent->get_parent()->y() -
|
||||
bugui::base_widget::parent->y();
|
||||
|
||||
update();
|
||||
|
||||
// FIXME : update dosen't work here for the constructor
|
||||
// curently moved to EventWidget::on_state_added
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -21,7 +21,9 @@ TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync,
|
|||
&Scenario::TimeSyncModel::newEvent,
|
||||
this,
|
||||
[scenario, this] (const Id<Scenario::EventModel>& eventId)
|
||||
{ add_widget<EventWidget>(scenario->get_model()->events.at(eventId), scenario); });
|
||||
{
|
||||
add_widget<EventWidget>(scenario->get_model()->events.at(eventId), scenario);
|
||||
});
|
||||
|
||||
connect(&model,
|
||||
&Scenario::TimeSyncModel::eventRemoved,
|
||||
|
@ -31,6 +33,9 @@ TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync,
|
|||
remove_widget([&eventId]
|
||||
(const auto& w)
|
||||
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(eventId); });
|
||||
|
||||
set_y_height();
|
||||
update();
|
||||
});
|
||||
|
||||
Scenario::ProcessModel* scen{scenario->get_model()};
|
||||
|
@ -78,6 +83,9 @@ 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