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

80 lines
1.9 KiB
C++

#include <widgets/container_widget.hpp>
#include "IntervalWidget.hpp"
#include "Hardware/Widgets/ScenarioWidget.hpp"
namespace Hardware
{
IntervalWidget::IntervalWidget(Scenario::IntervalModel& interval,
ScenarioWidget* scenario,
bugui::container_widget* parent)
: ScenarioComponentSpec<Scenario::IntervalModel>{interval, scenario, parent}
{ }
int IntervalWidget::x() const
{
return model.date().sec();
}
int IntervalWidget::y() const
{
return model.heightPercentage() * scenario->height();
}
int IntervalWidget::width() const
{
return model.duration.defaultDuration().sec();
}
void IntervalWidget::change_previous(const Scenario::StateModel& state)
{
}
void IntervalWidget::change_next(const Scenario::StateModel& state)
{
model.setHeightPercentage(state.heightPercentage());
}
bool IntervalWidget::contains(int px, int py) const
{
// ignore first and last cell
// so that timesyncs are pressed
// at the extremeties
if (px > 0 && px < width() && py == 0)
return true;
return false;
}
void IntervalWidget::paint(bugui::painter &painter) const
{
const auto col{model.metadata().getColor().getBrush().color()};
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
painter.set_paint_over(false);
painter.draw_line(0, 0, width(), 0);
painter.set_paint_over(true);
}
void IntervalWidget::on_press(int x, int y, bool pressed)
{
qDebug() << "interval pressed";
}
void IntervalWidget::on_double_press(int x, int y)
{
qDebug() << "interval double pressed";
}
void IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
{
double new_height{model.heightPercentage() +
to_y / static_cast<double>(scenario->height())};
// prevent dragging out of scenario
if (new_height >= 0 && new_height <= 1)
model.setHeightPercentage(new_height);
}
} // namespace hardware