2024-10-06 15:16:11 +01:00
|
|
|
#include <score/application/ApplicationContext.hpp>
|
|
|
|
#include <score/actions/ActionManager.hpp>
|
|
|
|
#include <Scenario/Application/ScenarioActions.hpp>
|
2024-10-15 21:00:53 +01:00
|
|
|
#include <Process/Style/ScenarioStyle.hpp>
|
2024-10-06 15:16:11 +01:00
|
|
|
|
2024-10-03 23:50:15 +01:00
|
|
|
#include "Controller.hpp"
|
|
|
|
|
2024-10-06 15:16:11 +01:00
|
|
|
namespace Hardware
|
|
|
|
{
|
|
|
|
Controller::Controller(const score::DocumentContext& doc)
|
2024-10-17 17:39:36 +01:00
|
|
|
: bugui::controller{[&doc, this]
|
2024-11-20 00:13:57 +00:00
|
|
|
(bugui::commands com, bool shift)
|
2024-10-08 16:12:35 +01:00
|
|
|
{
|
2024-10-06 15:16:11 +01:00
|
|
|
switch (com)
|
|
|
|
{
|
2024-10-16 23:25:53 +01:00
|
|
|
case bugui::Play:
|
|
|
|
if (shift)
|
|
|
|
doc.app.actions.action<Actions::PlayGlobal>().action()->trigger();
|
|
|
|
else
|
|
|
|
doc.app.actions.action<Actions::Play>().action()->trigger();
|
|
|
|
break;
|
|
|
|
case bugui::Stop:
|
|
|
|
if (shift)
|
|
|
|
doc.app.actions.action<Actions::Reinitialize>().action()->trigger();
|
|
|
|
else
|
|
|
|
doc.app.actions.action<Actions::Stop>().action()->trigger();
|
|
|
|
break;
|
|
|
|
case bugui::Up:
|
|
|
|
if (shift)
|
2024-10-06 15:16:11 +01:00
|
|
|
{
|
2024-10-16 23:25:53 +01:00
|
|
|
v_zoom += .2;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
2024-10-16 23:25:53 +01:00
|
|
|
else
|
2024-10-06 15:16:11 +01:00
|
|
|
{
|
2024-10-16 23:25:53 +01:00
|
|
|
v_ofset += .02;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
2024-10-16 23:25:53 +01:00
|
|
|
break;
|
|
|
|
case bugui::Down:
|
|
|
|
if (shift)
|
2024-10-06 15:16:11 +01:00
|
|
|
{
|
2024-10-16 23:25:53 +01:00
|
|
|
if (v_zoom > .2)
|
|
|
|
{
|
|
|
|
v_zoom -= .2;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-16 23:25:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v_ofset -= .02;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-16 23:25:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case bugui::Left:
|
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
if (h_zoom > .02)
|
|
|
|
{
|
|
|
|
h_zoom -= .02;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-16 23:25:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (h_ofset > 0)
|
|
|
|
{
|
|
|
|
h_ofset -= .02;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-16 23:25:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case bugui::Right:
|
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
h_zoom += .02;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-16 23:25:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
h_ofset += .02;
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
2024-10-16 23:25:53 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// qDebug() << "v_ofset: " << v_ofset;
|
|
|
|
// qDebug() << "v_zoom: " << v_zoom;
|
|
|
|
// qDebug() << "h_ofset: " << h_ofset;
|
|
|
|
// qDebug() << "h_zoom: " << h_ofset;
|
2024-10-08 16:12:35 +01:00
|
|
|
}
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
2024-10-08 16:12:35 +01:00
|
|
|
{}
|
2024-10-06 15:16:11 +01:00
|
|
|
|
|
|
|
void Controller::setup_scenario(Scenario::ProcessModel* s)
|
|
|
|
{
|
|
|
|
scenar = s;
|
|
|
|
|
|
|
|
// Connet interval signals
|
|
|
|
// adapted from
|
|
|
|
// src/plugins/score-plugin-scenario/Scenario/Process/MiniScenarioView.cpp#18
|
|
|
|
scenar->intervals.added.connect<&Controller::on_interval_changed>(this);
|
|
|
|
scenar->intervals.removed.connect<&Controller::on_interval_changed>(this);
|
|
|
|
|
|
|
|
connect(scenar,
|
|
|
|
&Scenario::ProcessModel::intervalMoved,
|
2024-10-17 17:39:36 +01:00
|
|
|
[this] { update(); });
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
|
|
|
|
2024-11-28 23:33:24 +00:00
|
|
|
void Controller::on_interval_changed(const Scenario::IntervalModel&)
|
2024-10-06 15:16:11 +01:00
|
|
|
{
|
2024-10-17 17:39:36 +01:00
|
|
|
update();
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
|
|
|
|
2024-11-28 23:33:24 +00:00
|
|
|
void Controller::paint(bugui::painter& painter)
|
2024-10-06 15:16:11 +01:00
|
|
|
{
|
2024-10-17 17:39:36 +01:00
|
|
|
if (!scenar) return;
|
2024-10-06 15:16:11 +01:00
|
|
|
|
2024-10-15 21:00:53 +01:00
|
|
|
// Copied from MiniscenarioView
|
|
|
|
auto& skin = Process::Style::instance();
|
2024-10-16 23:25:53 +01:00
|
|
|
const auto col = skin.IntervalBase().color();
|
2024-11-28 23:33:24 +00:00
|
|
|
painter.set_color(col.red(), col.green(), col.black(), col.alpha());
|
2024-10-15 21:00:53 +01:00
|
|
|
|
2024-10-06 15:16:11 +01:00
|
|
|
for(const Scenario::IntervalModel& c : scenar->intervals)
|
|
|
|
{
|
|
|
|
auto def = c.duration.defaultDuration().sec() * h_zoom;
|
|
|
|
auto st = (c.date().sec() * h_zoom) - h_ofset;
|
|
|
|
auto y = (c.heightPercentage() * v_zoom) + v_ofset;
|
2024-10-17 17:39:36 +01:00
|
|
|
painter.draw_line({st, y}, {st + def, y});
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
|
|
|
}
|
2024-10-08 16:12:35 +01:00
|
|
|
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
|
|
|
|
2024-10-08 16:12:35 +01:00
|
|
|
#include <wobjectimpl.h>
|
2024-10-06 15:16:11 +01:00
|
|
|
W_OBJECT_IMPL(Hardware::Controller)
|