score-addon-hardware/Hardware/Widgets/EventWidget.cpp

103 lines
2.3 KiB
C++
Raw Normal View History

#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);
}
int EventWidget::y() const
{
return m_y;
}
int EventWidget::height() const
{
return m_height;
}
2025-01-14 00:04:35 +00:00
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()
{
2025-01-14 00:04:35 +00:00
static_cast<TimeSyncWidget*>(parent)->set_y_height();
m_y = std::numeric_limits<int>::max();
m_height = std::numeric_limits<int>::lowest();
for(const auto& s : children)
{
int sy = s->y();
if (sy < m_y) m_y = sy;
int sh = s->height();
if (sh > m_height) m_height = sh;
}
}
void EventWidget::paint(bugui::painter& painter) const
{
// const auto col = skin.StateDot().color();
// painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
// painter.draw_cell(0, 0);
}
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_y_height();
}
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_y_height();
}
void EventWidget::on_press(int x, int y, bool pressed)
{
qDebug() << "is inside!";
}
}