150 lines
3.2 KiB
C++
150 lines
3.2 KiB
C++
#include <score/application/GUIApplicationContext.hpp>
|
|
#include <score/actions/ActionManager.hpp>
|
|
#include <Scenario/Application/ScenarioActions.hpp>
|
|
#include <Process/Style/ScenarioStyle.hpp>
|
|
|
|
#include "Controller.hpp"
|
|
|
|
namespace Hardware
|
|
{
|
|
Controller::Controller(const score::DocumentContext& document,
|
|
Scenario::IntervalModel& interval,
|
|
std::string_view device_name)
|
|
: bugui::controller<Controller>{device_name}
|
|
, doc{document}
|
|
, interval{&interval}
|
|
{
|
|
// Connet interval signals
|
|
// adapted from
|
|
// src/plugins/score-plugin-scenario/Scenario/Process/MiniScenarioView.cpp#18
|
|
auto scnr = qobject_cast<Scenario::ProcessModel*>(&*interval.processes.begin());
|
|
|
|
scnr->intervals.added.connect<&Controller::on_interval_changed>(this);
|
|
scnr->intervals.removed.connect<&Controller::on_interval_changed>(this);
|
|
|
|
connect(scnr,
|
|
&Scenario::ProcessModel::intervalMoved,
|
|
[this] { update(); });
|
|
}
|
|
|
|
void Controller::on_interval_changed(const Scenario::IntervalModel&)
|
|
{
|
|
update();
|
|
}
|
|
|
|
void Controller::paint(bugui::painter& painter) const
|
|
{
|
|
// Copied from MiniscenarioView
|
|
auto& skin = Process::Style::instance();
|
|
const auto col = skin.IntervalBase().color();
|
|
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
|
|
|
auto scnr = qobject_cast<Scenario::ProcessModel*>(&*interval->processes.begin());
|
|
|
|
for(const Scenario::IntervalModel& c : scnr->intervals)
|
|
{
|
|
int def = c.duration.defaultDuration().sec();
|
|
// auto def = c.duration.defaultDuration().sec() * h_zoom;
|
|
int st = c.date().sec() - h_ofset;
|
|
// auto st = (c.date().sec() * h_zoom) - h_ofset;
|
|
int y = (c.heightPercentage() * height()) + v_ofset;
|
|
// auto y = (c.heightPercentage() * v_zoom) + v_ofset;
|
|
painter.draw_line({st, y}, {st + def, y});
|
|
}
|
|
}
|
|
|
|
void Controller::on_grid(float x, float y, bool pressed)
|
|
{
|
|
qDebug() << "x: " << x << " y: " << y << " pressed: " << pressed;
|
|
}
|
|
|
|
void Controller::on_play(bool pressed)
|
|
{
|
|
if (m_shift)
|
|
doc.app.actions.action<Actions::PlayGlobal>().action()->trigger();
|
|
else
|
|
doc.app.actions.action<Actions::Play>().action()->trigger();
|
|
}
|
|
|
|
void Controller::on_stop(bool pressed)
|
|
{
|
|
if (m_shift)
|
|
doc.app.actions.action<Actions::Reinitialize>().action()->trigger();
|
|
else
|
|
doc.app.actions.action<Actions::Stop>().action()->trigger();
|
|
}
|
|
|
|
void Controller::on_shift(bool pressed)
|
|
{
|
|
m_shift = pressed;
|
|
}
|
|
|
|
void Controller::on_up(bool pressed)
|
|
{
|
|
if (m_shift)
|
|
{
|
|
v_scale += .2;
|
|
update();
|
|
}
|
|
else
|
|
{
|
|
v_ofset += .02;
|
|
update();
|
|
}
|
|
}
|
|
|
|
void Controller::on_down(bool pressed)
|
|
{
|
|
if (m_shift)
|
|
{
|
|
if (v_scale > .2)
|
|
{
|
|
v_scale -= .2;
|
|
update();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
v_ofset -= .02;
|
|
update();
|
|
}
|
|
}
|
|
|
|
void Controller::on_left(bool pressed)
|
|
{
|
|
if (m_shift)
|
|
{
|
|
if (h_scale > .02)
|
|
{
|
|
h_scale -= .02;
|
|
update();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (h_ofset > 0)
|
|
{
|
|
h_ofset -= .02;
|
|
update();
|
|
}
|
|
}
|
|
}
|
|
|
|
void Controller::on_right(bool pressed)
|
|
{
|
|
if (m_shift)
|
|
{
|
|
h_scale += .02;
|
|
update();
|
|
}
|
|
else
|
|
{
|
|
h_ofset += .02;
|
|
update();
|
|
}
|
|
}
|
|
|
|
} // namespace hardware
|
|
|
|
#include <wobjectimpl.h>
|
|
W_OBJECT_IMPL(Hardware::Controller)
|