67 lines
1.4 KiB
C++
67 lines
1.4 KiB
C++
#include <widgets/container_widget.hpp>
|
|
|
|
#include "IntervalWidget.hpp"
|
|
|
|
namespace Hardware
|
|
{
|
|
IntervalWidget::IntervalWidget(Scenario::IntervalModel& interval,
|
|
bugui::container_widget* parent)
|
|
: ScenarioComponentSpec<Scenario::IntervalModel>{interval, parent}
|
|
{ }
|
|
|
|
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(0, 0, width(), 0);
|
|
}
|
|
|
|
bool IntervalWidget::contains(int px, int py) const
|
|
{
|
|
if (px >= 0 &&
|
|
px <= width() &&
|
|
py == 0)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
void IntervalWidget::on_press(int x, int y, bool pressed)
|
|
{
|
|
qDebug() << "is inside!";
|
|
}
|
|
|
|
void IntervalWidget::on_double_press(int x, int y)
|
|
{
|
|
qDebug() << "double pressed !";
|
|
}
|
|
|
|
void IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
|
{
|
|
double increment{to_y / static_cast<double>(parent->height())};
|
|
model.requestHeightChange(model.heightPercentage() + increment);
|
|
}
|
|
|
|
const Scenario::IntervalModel& IntervalWidget::get_model() const
|
|
{
|
|
return model;
|
|
}
|
|
|
|
} // namespace hardware
|