2024-12-27 11:04:40 +00:00
|
|
|
#include "IntervalWidget.hpp"
|
|
|
|
|
|
|
|
namespace Hardware
|
|
|
|
{
|
|
|
|
IntervalWidget::IntervalWidget(base_widget* parent,
|
|
|
|
Scenario::IntervalModel& interval)
|
|
|
|
: bugui::base_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
|
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());
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
double new_percentage{(1 / static_cast<double>(parent->height())) * to_y};
|
|
|
|
model.requestHeightChange(new_percentage);
|
|
|
|
parent->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-12-27 11:04:40 +00:00
|
|
|
const Scenario::IntervalModel &IntervalWidget::get_model() const
|
|
|
|
{
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace hardware
|