95 lines
2.3 KiB
C++
95 lines
2.3 KiB
C++
#include <Scenario/Document/Event/EventModel.hpp>
|
|
|
|
#include "TimeSyncWidget.hpp"
|
|
#include "StateWidget.hpp"
|
|
#include "ScenarioWidget.hpp"
|
|
#include "EventWidget.hpp"
|
|
|
|
namespace Hardware
|
|
{
|
|
EventWidget::EventWidget(Scenario::EventModel& event,
|
|
ScenarioWidget* scenario,
|
|
bugui::container_widget* parent)
|
|
: ScenarioComponentSpec<Scenario::EventModel,
|
|
bugui::container_widget>{event, scenario, parent}
|
|
{
|
|
Scenario::ProcessModel* scen{scenario->get_model()};
|
|
|
|
scen->states.mutable_added.connect<&EventWidget::on_state_added>(this);
|
|
scen->states.removed.connect<&EventWidget::on_state_removed>(this);
|
|
|
|
for(Scenario::StateModel& s : scen->states)
|
|
if (s.eventId() == model.id())
|
|
add_widget<StateWidget>(s, scenario);
|
|
|
|
set_span_recursive();
|
|
}
|
|
|
|
void EventWidget::set_span_recursive()
|
|
{
|
|
int lowest{std::numeric_limits<int>::max()};
|
|
int heighest{0};
|
|
|
|
for(const auto& s : bugui::container_widget::children)
|
|
{
|
|
int sy = static_cast<StateWidget*>(s.get())->get_absolute_y();
|
|
if (sy < lowest) lowest = sy;
|
|
if (sy > heighest) heighest = sy;
|
|
}
|
|
|
|
m_absolute_y = lowest;
|
|
m_height = heighest - lowest;
|
|
|
|
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_span();
|
|
|
|
m_y = m_absolute_y - parent->y();
|
|
}
|
|
|
|
void EventWidget::paint(bugui::painter& painter) const
|
|
{
|
|
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);
|
|
}
|
|
|
|
bool EventWidget::contains(int px, int py) const
|
|
{
|
|
if (px == x() && py == y())
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
void EventWidget::on_state_added(Scenario::StateModel& state)
|
|
{
|
|
if (state.eventId() != model.id()) return;
|
|
|
|
add_widget<StateWidget>(state, scenario);
|
|
|
|
set_span_recursive();
|
|
}
|
|
|
|
void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
|
{
|
|
if (state.eventId() != model.id()) return;
|
|
|
|
remove_widget([&state]
|
|
(const auto& w)
|
|
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(state); });
|
|
|
|
set_span_recursive();
|
|
update();
|
|
}
|
|
|
|
void EventWidget::on_press(int x, int y, bool pressed)
|
|
{
|
|
qDebug() << "event pressed";
|
|
}
|
|
|
|
void EventWidget::on_double_press(int x, int y, bool pressed)
|
|
{
|
|
qDebug() << "event double pressed";
|
|
}
|
|
|
|
} // namespace Hardware
|