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

81 lines
1.6 KiB
C++
Raw Normal View History

#include "IntervalWidget.hpp"
namespace Hardware
{
2024-12-31 16:11:11 +00:00
IntervalWidget::IntervalWidget(container_widget *parent,
Scenario::IntervalModel& interval)
2024-12-31 16:11:11 +00:00
: bugui::container_widget{parent}
, model{interval}
, skin{Process::Style::instance()}
{
}
int IntervalWidget::x() const
{
return model.date().sec();
}
int IntervalWidget::y() const
{
return model.heightPercentage() * parent->height();
}
int IntervalWidget::width() const
{
return model.duration.defaultDuration().sec();
}
2024-12-28 17:53:59 +00:00
void IntervalWidget::paint(bugui::painter& painter) const
{
// Copied from MiniscenarioView
const auto col = skin.IntervalBase().color();
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
painter.draw_line({x(), y()}, {x() + width(), y()});
}
2024-12-29 23:23:03 +00:00
bool IntervalWidget::is_inside(int px, int py) const
{
if (px >= x() &&
px <= (x() + width()) &&
py == y())
return true;
return false;
}
bool IntervalWidget::on_press(int x, int y, bool pressed)
{
if (!is_inside(x, y)) return false;
qDebug() << "is inside!";
return true;
}
bool IntervalWidget::on_double_press(int x, int y)
{
if (!is_inside(x, y)) return false;
qDebug() << "double pressed !";
return true;
}
2024-12-30 12:32:54 +00:00
bool IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
{
if (!is_inside(from_x, from_y)) return false;
if (from_y != to_y)
2024-12-30 17:08:14 +00:00
model.requestHeightChange(to_y / static_cast<double>(parent->height()));
2024-12-30 12:32:54 +00:00
return true;
}
const Scenario::IntervalModel &IntervalWidget::get_model() const
{
return model;
}
} // namespace hardware