[widgets] csenario widget
This commit is contained in:
parent
89f1c2af32
commit
f0c64864eb
8 changed files with 120 additions and 68 deletions
|
@ -22,7 +22,9 @@ set(HDRS
|
||||||
"Hardware/Controller.hpp"
|
"Hardware/Controller.hpp"
|
||||||
"Hardware/DocumentPlugin.hpp"
|
"Hardware/DocumentPlugin.hpp"
|
||||||
"Hardware/ApplicationPlugin.hpp"
|
"Hardware/ApplicationPlugin.hpp"
|
||||||
"Hardware/IntervalWidget.hpp"
|
|
||||||
|
"Hardware/Widgets/ScenarioWidget.hpp"
|
||||||
|
"Hardware/Widgets/IntervalWidget.hpp"
|
||||||
|
|
||||||
"score_addon_hardware.hpp"
|
"score_addon_hardware.hpp"
|
||||||
)
|
)
|
||||||
|
@ -35,7 +37,9 @@ set(SRCS
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Controller.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Controller.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/DocumentPlugin.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/DocumentPlugin.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/IntervalWidget.cpp"
|
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Widgets/ScenarioWidget.cpp"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Widgets/IntervalWidget.cpp"
|
||||||
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp"
|
||||||
)
|
)
|
||||||
|
|
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit d804bdf0e95b507a081b701bdf4730c518889304
|
Subproject commit 465dfda542cae212d2f06298f1d7e0136f2e66c2
|
|
@ -4,7 +4,7 @@
|
||||||
#include <Process/Style/ScenarioStyle.hpp>
|
#include <Process/Style/ScenarioStyle.hpp>
|
||||||
|
|
||||||
#include "Controller.hpp"
|
#include "Controller.hpp"
|
||||||
#include "Hardware/IntervalWidget.hpp"
|
#include <Hardware/Widgets/ScenarioWidget.hpp>
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
|
@ -15,66 +15,13 @@ Controller::Controller(const score::DocumentContext& document,
|
||||||
, doc{document}
|
, doc{document}
|
||||||
, interval{&interval}
|
, 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());
|
auto scnr = qobject_cast<Scenario::ProcessModel*>(&*interval.processes.begin());
|
||||||
|
|
||||||
scnr->intervals.mutable_added.connect<&Controller::on_interval_added>(this);
|
if (scnr) widgets.emplace_back(std::make_unique<ScenarioWidget>(this, scnr));
|
||||||
scnr->intervals.removed.connect<&Controller::on_interval_removed>(this);
|
|
||||||
|
|
||||||
connect(scnr,
|
|
||||||
&Scenario::ProcessModel::intervalMoved,
|
|
||||||
[this] { update(); });
|
|
||||||
|
|
||||||
for(Scenario::IntervalModel& c : scnr->intervals)
|
|
||||||
widgets.emplace_back(std::make_unique<IntervalWidget>(this, interval));
|
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::on_interval_added(Scenario::IntervalModel &interval)
|
|
||||||
{
|
|
||||||
widgets.emplace_back(std::make_unique<IntervalWidget>(this, interval));
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::on_interval_removed(const Scenario::IntervalModel& interval)
|
|
||||||
{
|
|
||||||
std::erase_if(widgets,
|
|
||||||
[&interval]
|
|
||||||
(auto& w)
|
|
||||||
{ return static_cast<IntervalWidget*>(w.get())->get_model().id() == interval.id(); });
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::on_interval_changed(const Scenario::IntervalModel &)
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::paint(bugui::painter& painter)
|
|
||||||
{
|
|
||||||
// // 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)
|
void Controller::on_grid(float x, float y, bool pressed)
|
||||||
{
|
{
|
||||||
qDebug() << "x: " << x << " y: " << y << " pressed: " << pressed;
|
qDebug() << "x: " << x << " y: " << y << " pressed: " << pressed;
|
||||||
|
|
|
@ -21,8 +21,6 @@ public:
|
||||||
Scenario::IntervalModel& interval,
|
Scenario::IntervalModel& interval,
|
||||||
std::string_view device_name);
|
std::string_view device_name);
|
||||||
|
|
||||||
void paint(bugui::painter& painter) override;
|
|
||||||
|
|
||||||
void on_play(bool pressed);
|
void on_play(bool pressed);
|
||||||
void on_stop(bool pressed);
|
void on_stop(bool pressed);
|
||||||
void on_shift(bool pressed);
|
void on_shift(bool pressed);
|
||||||
|
@ -34,10 +32,6 @@ public:
|
||||||
void on_grid(float x, float y, bool pressed);
|
void on_grid(float x, float y, bool pressed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void on_interval_added(Scenario::IntervalModel& interval);
|
|
||||||
void on_interval_removed(const Scenario::IntervalModel &interval);
|
|
||||||
void on_interval_changed(const Scenario::IntervalModel &);
|
|
||||||
|
|
||||||
Scenario::IntervalModel* interval;
|
Scenario::IntervalModel* interval;
|
||||||
const score::DocumentContext& doc;
|
const score::DocumentContext& doc;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ int IntervalWidget::width() const
|
||||||
return model.duration.defaultDuration().sec();
|
return model.duration.defaultDuration().sec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntervalWidget::paint(bugui::painter& painter)
|
void IntervalWidget::paint(bugui::painter& painter) const
|
||||||
{
|
{
|
||||||
// Copied from MiniscenarioView
|
// Copied from MiniscenarioView
|
||||||
const auto col = skin.IntervalBase().color();
|
const auto col = skin.IntervalBase().color();
|
|
@ -6,17 +6,17 @@
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
struct IntervalWidget : bugui::base_widget
|
struct IntervalWidget final : bugui::base_widget
|
||||||
{
|
{
|
||||||
explicit IntervalWidget(base_widget* parent,
|
explicit IntervalWidget(base_widget* parent,
|
||||||
Scenario::IntervalModel& interval);
|
Scenario::IntervalModel& interval);
|
||||||
|
|
||||||
|
void paint(bugui::painter& painter) const override;
|
||||||
|
|
||||||
int x() const override;
|
int x() const override;
|
||||||
int y() const override;
|
int y() const override;
|
||||||
int width() const override;
|
int width() const override;
|
||||||
|
|
||||||
void paint(bugui::painter& painter) override;
|
|
||||||
|
|
||||||
const Scenario::IntervalModel& get_model() const;
|
const Scenario::IntervalModel& get_model() const;
|
||||||
|
|
||||||
private:
|
private:
|
71
Hardware/Widgets/ScenarioWidget.cpp
Normal file
71
Hardware/Widgets/ScenarioWidget.cpp
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
#include "ScenarioWidget.hpp"
|
||||||
|
#include <Hardware/Widgets/IntervalWidget.hpp>
|
||||||
|
|
||||||
|
namespace Hardware
|
||||||
|
{
|
||||||
|
ScenarioWidget::ScenarioWidget(base_widget* parent,
|
||||||
|
Scenario::ProcessModel* scenario)
|
||||||
|
: bugui::base_widget{parent}
|
||||||
|
, model{scenario}
|
||||||
|
{
|
||||||
|
model->intervals.mutable_added.connect<&ScenarioWidget::on_interval_added>(this);
|
||||||
|
model->intervals.removed.connect<&ScenarioWidget::on_interval_removed>(this);
|
||||||
|
|
||||||
|
connect(model,
|
||||||
|
&Scenario::ProcessModel::intervalMoved,
|
||||||
|
[this] { update(); });
|
||||||
|
|
||||||
|
for(Scenario::IntervalModel& s : model->intervals)
|
||||||
|
widgets.emplace_back(std::make_unique<IntervalWidget>(this, s));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScenarioWidget::paint(bugui::painter &painter) const
|
||||||
|
{
|
||||||
|
for (const auto& w : widgets) w->paint(painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScenarioWidget::x() const
|
||||||
|
{
|
||||||
|
return bugui::base_widget::parent->x();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScenarioWidget::y() const
|
||||||
|
{
|
||||||
|
return bugui::base_widget::parent->x();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScenarioWidget::width() const
|
||||||
|
{
|
||||||
|
return bugui::base_widget::parent->width();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScenarioWidget::height() const
|
||||||
|
{
|
||||||
|
return bugui::base_widget::parent->height();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
||||||
|
{
|
||||||
|
widgets.emplace_back(std::make_unique<IntervalWidget>(this, interval));
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval)
|
||||||
|
{
|
||||||
|
std::erase_if(widgets,
|
||||||
|
[&interval]
|
||||||
|
(auto& w)
|
||||||
|
{ return static_cast<IntervalWidget*>(w.get())->get_model().id() == interval.id(); });
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScenarioWidget::on_interval_changed(const Scenario::IntervalModel &)
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Hardware
|
||||||
|
|
||||||
|
#include "wobjectimpl.h"
|
||||||
|
W_OBJECT_IMPL(Hardware::ScenarioWidget)
|
36
Hardware/Widgets/ScenarioWidget.hpp
Normal file
36
Hardware/Widgets/ScenarioWidget.hpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <wobjectdefs.h>
|
||||||
|
|
||||||
|
#include <Scenario/Process/ScenarioModel.hpp>
|
||||||
|
#include <base_widget.hpp>
|
||||||
|
|
||||||
|
namespace Hardware
|
||||||
|
{
|
||||||
|
class ScenarioWidget final
|
||||||
|
: public bugui::base_widget
|
||||||
|
, public QObject
|
||||||
|
{
|
||||||
|
W_OBJECT(ScenarioWidget)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ScenarioWidget(bugui::base_widget* parent,
|
||||||
|
Scenario::ProcessModel* scenario);
|
||||||
|
|
||||||
|
void paint(bugui::painter& painter) const override;
|
||||||
|
|
||||||
|
int x() const override;
|
||||||
|
int y() const override;
|
||||||
|
int width() const override;
|
||||||
|
int height() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void on_interval_added(Scenario::IntervalModel& interval);
|
||||||
|
void on_interval_removed(const Scenario::IntervalModel& interval);
|
||||||
|
void on_interval_changed(const Scenario::IntervalModel&);
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<base_widget>> widgets;
|
||||||
|
Scenario::ProcessModel* model;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Hardware
|
Loading…
Add table
Reference in a new issue