#include #include "ScenarioWidget.hpp" #include "EventWidget.hpp" #include "StateWidget.hpp" namespace Hardware { StateWidget::StateWidget(Scenario::StateModel& state, ScenarioWidget* scenario, bugui::container_widget* parent) : ScenarioComponentSpec{state, scenario, parent} { set_absolute_y(); con = connect(&model, &Scenario::StateModel::heightPercentageChanged, this, [scenario, this] { set_absolute_y(); set_span_recursive(); scenario->update(); }); } void StateWidget::paint(bugui::painter& painter) const { const auto col{model.metadata().getColor().getBrush().color()}; // const auto col = skin.StateSelected().color(); painter.set_color(col.red(), col.green(), col.blue(), col.alpha()); painter.draw_cell(0, 0); } bool StateWidget::contains(int px, int py) const { if (px == 0 && py == 0) return true; return false; } void StateWidget::on_press(int x, int y, bool pressed) { update(); } void StateWidget::on_double_press(int x, int y) { qDebug() << "state double pressed"; } void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y) { double increment{to_y / static_cast(scenario->height())}; model.setHeightPercentage(model.heightPercentage() + increment); } void StateWidget::set_absolute_y() { m_absolute_y = model.heightPercentage() * scenario->height(); } 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(bugui::base_widget::parent) ->set_span_recursive(); } } // namespace Hardware #include W_OBJECT_IMPL(Hardware::StateWidget)