2025-01-04 21:05:36 +00:00
|
|
|
#include <widgets/container_widget.hpp>
|
|
|
|
|
2024-12-27 11:04:40 +00:00
|
|
|
#include "IntervalWidget.hpp"
|
2025-01-11 11:56:26 +00:00
|
|
|
#include "Hardware/Widgets/ScenarioWidget.hpp"
|
2024-12-27 11:04:40 +00:00
|
|
|
|
|
|
|
namespace Hardware
|
|
|
|
{
|
2025-01-03 23:27:19 +00:00
|
|
|
IntervalWidget::IntervalWidget(Scenario::IntervalModel& interval,
|
2025-01-11 11:56:26 +00:00
|
|
|
ScenarioWidget* scenario,
|
2025-01-04 21:05:36 +00:00
|
|
|
bugui::container_widget* parent)
|
2025-01-11 11:56:26 +00:00
|
|
|
: ScenarioComponentSpec<Scenario::IntervalModel>{interval, scenario, parent}
|
2025-01-16 13:10:52 +00:00
|
|
|
{ }
|
2024-12-27 11:04:40 +00:00
|
|
|
|
|
|
|
int IntervalWidget::x() const
|
|
|
|
{
|
|
|
|
return model.date().sec();
|
|
|
|
}
|
|
|
|
|
|
|
|
int IntervalWidget::y() const
|
|
|
|
{
|
2025-01-11 11:56:26 +00:00
|
|
|
return model.heightPercentage() * scenario->height();
|
2024-12-27 11:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int IntervalWidget::width() const
|
|
|
|
{
|
|
|
|
return model.duration.defaultDuration().sec();
|
|
|
|
}
|
|
|
|
|
2025-01-21 00:10:21 +00:00
|
|
|
void IntervalWidget::change_previous(const Scenario::StateModel& state)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntervalWidget::change_next(const Scenario::StateModel& state)
|
|
|
|
{
|
|
|
|
model.setHeightPercentage(state.heightPercentage());
|
|
|
|
}
|
|
|
|
|
2025-01-03 23:27:19 +00:00
|
|
|
bool IntervalWidget::contains(int px, int py) const
|
2024-12-29 23:23:03 +00:00
|
|
|
{
|
2025-01-16 13:10:52 +00:00
|
|
|
// ignore first and last cell
|
|
|
|
// so that timesyncs are pressed
|
|
|
|
// at the extremeties
|
2025-01-20 13:12:05 +00:00
|
|
|
if (px > 0 && px < width() && py == 0)
|
2024-12-29 23:23:03 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-01-19 19:11:10 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2025-01-04 21:05:36 +00:00
|
|
|
void IntervalWidget::on_press(int x, int y, bool pressed)
|
2024-12-29 23:23:03 +00:00
|
|
|
{
|
2025-01-16 13:10:52 +00:00
|
|
|
qDebug() << "interval pressed";
|
2024-12-29 23:23:03 +00:00
|
|
|
}
|
|
|
|
|
2025-01-04 21:05:36 +00:00
|
|
|
void IntervalWidget::on_double_press(int x, int y)
|
2024-12-29 23:23:03 +00:00
|
|
|
{
|
2025-01-16 13:10:52 +00:00
|
|
|
qDebug() << "interval double pressed";
|
2024-12-29 23:23:03 +00:00
|
|
|
}
|
|
|
|
|
2025-01-04 21:05:36 +00:00
|
|
|
void IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
2024-12-30 12:32:54 +00:00
|
|
|
{
|
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)
|
|
|
|
model.setHeightPercentage(new_height);
|
2024-12-30 12:32:54 +00:00
|
|
|
}
|
|
|
|
|
2024-12-27 11:04:40 +00:00
|
|
|
} // namespace hardware
|