2025-01-04 21:05:36 +00:00
|
|
|
#include <widgets/container_widget.hpp>
|
|
|
|
|
2024-12-27 11:04:40 +00:00
|
|
|
#include "IntervalWidget.hpp"
|
|
|
|
|
|
|
|
namespace Hardware
|
|
|
|
{
|
2025-01-03 23:27:19 +00:00
|
|
|
IntervalWidget::IntervalWidget(Scenario::IntervalModel& interval,
|
2025-01-04 21:05:36 +00:00
|
|
|
bugui::container_widget* parent)
|
|
|
|
: bugui::base_widget{parent}
|
2024-12-27 11:04:40 +00:00
|
|
|
, model{interval}
|
|
|
|
, skin{Process::Style::instance()}
|
2025-01-03 23:27:19 +00:00
|
|
|
{ }
|
2024-12-27 11:04:40 +00:00
|
|
|
|
|
|
|
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
|
2024-12-27 11:04:40 +00:00
|
|
|
{
|
|
|
|
// Copied from MiniscenarioView
|
|
|
|
const auto col = skin.IntervalBase().color();
|
|
|
|
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
|
|
|
|
2025-01-04 22:46:27 +00:00
|
|
|
painter.draw_line({0, 0}, {width(), 0});
|
2024-12-27 11:04:40 +00:00
|
|
|
}
|
|
|
|
|
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-04 22:46:27 +00:00
|
|
|
if (px >= 0 &&
|
|
|
|
px <= width() &&
|
|
|
|
py == 0)
|
2024-12-29 23:23:03 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
qDebug() << "is inside!";
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
qDebug() << "double pressed !";
|
|
|
|
}
|
|
|
|
|
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-04 22:46:27 +00:00
|
|
|
double increment{to_y / static_cast<double>(parent->height())};
|
|
|
|
model.requestHeightChange(model.heightPercentage() + increment);
|
2024-12-30 12:32:54 +00:00
|
|
|
}
|
|
|
|
|
2025-01-03 23:27:19 +00:00
|
|
|
const Scenario::IntervalModel& IntervalWidget::get_model() const
|
2024-12-27 11:04:40 +00:00
|
|
|
{
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace hardware
|