#include "IntervalWidget.hpp" namespace Hardware { IntervalWidget::IntervalWidget(Scenario::IntervalModel& interval, container_widget* parent) : 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(); } 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()}); } bool IntervalWidget::contains(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 (!contains(x, y)) return false; qDebug() << "is inside!"; return true; } bool IntervalWidget::on_double_press(int x, int y) { if (!contains(x, y)) return false; qDebug() << "double pressed !"; return true; } bool IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y) { if (!contains(from_x, from_y)) return false; if (from_y != to_y) model.requestHeightChange(to_y / static_cast(parent->height())); return true; } const Scenario::IntervalModel& IntervalWidget::get_model() const { return model; } } // namespace hardware