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

106 lines
2.3 KiB
C++
Raw Normal View History

#include <Scenario/Document/State/StateModel.hpp>
#include "ScenarioWidget.hpp"
#include "EventWidget.hpp"
#include "StateWidget.hpp"
namespace Hardware
{
StateWidget::StateWidget(Scenario::StateModel& state,
ScenarioWidget* scenario,
bugui::container_widget* parent)
: ScenarioComponentSpec<Scenario::StateModel>{state, scenario, parent}
{
set_absolute_y();
2025-01-21 00:10:21 +00:00
// con = connect(&model,
// &Scenario::StateModel::heightPercentageChanged,
// this,
// [scenario, this]
// {
// set_absolute_y();
// set_span_recursive();
// scenario->update();
// });
scenario->add_proxy(this);
}
StateWidget::~StateWidget()
{
disconnect(con);
scenario->remove_proxy(this);
}
void StateWidget::change_previous(const Scenario::IntervalModel& interval)
{
}
void StateWidget::change_next(const Scenario::IntervalModel& interval)
{
}
void StateWidget::paint(bugui::painter& painter) const
{
2025-01-19 19:11:10 +00:00
const auto col{model.metadata().getColor().getBrush().color()};
// const auto col = skin.StateSelected().color();
2025-01-19 19:11:10 +00:00
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
2025-01-19 19:11:10 +00:00
painter.draw_cell(0, 0);
}
bool StateWidget::contains(int px, int py) const
{
2025-01-19 19:11:10 +00:00
if (px == 0 && py == 0)
return true;
return false;
}
2025-01-04 21:05:36 +00:00
void StateWidget::on_press(int x, int y, bool pressed)
{
2025-01-21 00:10:21 +00:00
// update();
}
2025-01-04 21:05:36 +00:00
void StateWidget::on_double_press(int x, int y)
{
2025-01-16 13:10:52 +00:00
qDebug() << "state double pressed";
}
2025-01-04 21:05:36 +00:00
void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
{
2025-01-20 13:12:05 +00:00
double new_height{model.heightPercentage() +
to_y / static_cast<double>(scenario->height())};
// prevent dragging out of scenario
if (new_height >= 0 && new_height <= 1)
2025-01-21 00:10:21 +00:00
{
2025-01-20 13:12:05 +00:00
model.setHeightPercentage(new_height);
2025-01-21 00:10:21 +00:00
scenario->recursive_change(model);
}
}
void StateWidget::set_absolute_y()
{
m_absolute_y = model.heightPercentage() * scenario->height();
}
2025-01-16 02:00:26 +00:00
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();
}
} // namespace Hardware
#include <wobjectimpl.h>
W_OBJECT_IMPL(Hardware::StateWidget)