[widgets] first step towards widget system
This commit is contained in:
parent
62e2e2539f
commit
89f1c2af32
6 changed files with 117 additions and 22 deletions
|
@ -22,6 +22,7 @@ set(HDRS
|
|||
"Hardware/Controller.hpp"
|
||||
"Hardware/DocumentPlugin.hpp"
|
||||
"Hardware/ApplicationPlugin.hpp"
|
||||
"Hardware/IntervalWidget.hpp"
|
||||
|
||||
"score_addon_hardware.hpp"
|
||||
)
|
||||
|
@ -34,6 +35,7 @@ set(SRCS
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Controller.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/DocumentPlugin.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/IntervalWidget.cpp"
|
||||
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp"
|
||||
)
|
||||
|
|
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 5641128efec62c92f12ff5082f2bee505c502a17
|
||||
Subproject commit d804bdf0e95b507a081b701bdf4730c518889304
|
|
@ -4,6 +4,7 @@
|
|||
#include <Process/Style/ScenarioStyle.hpp>
|
||||
|
||||
#include "Controller.hpp"
|
||||
#include "Hardware/IntervalWidget.hpp"
|
||||
|
||||
namespace Hardware
|
||||
{
|
||||
|
@ -19,38 +20,59 @@ Controller::Controller(const score::DocumentContext& document,
|
|||
// 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);
|
||||
scnr->intervals.mutable_added.connect<&Controller::on_interval_added>(this);
|
||||
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();
|
||||
}
|
||||
|
||||
void Controller::on_interval_changed(const Scenario::IntervalModel&)
|
||||
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) const
|
||||
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());
|
||||
// // 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());
|
||||
// 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});
|
||||
}
|
||||
// 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)
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
Scenario::IntervalModel& interval,
|
||||
std::string_view device_name);
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
void paint(bugui::painter& painter) override;
|
||||
|
||||
void on_play(bool pressed);
|
||||
void on_stop(bool pressed);
|
||||
|
@ -34,7 +34,9 @@ public:
|
|||
void on_grid(float x, float y, bool pressed);
|
||||
|
||||
private:
|
||||
void on_interval_changed(const Scenario::IntervalModel&);
|
||||
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;
|
||||
const score::DocumentContext& doc;
|
||||
|
|
42
Hardware/IntervalWidget.cpp
Normal file
42
Hardware/IntervalWidget.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "IntervalWidget.hpp"
|
||||
|
||||
namespace Hardware
|
||||
{
|
||||
IntervalWidget::IntervalWidget(base_widget* parent,
|
||||
Scenario::IntervalModel& interval)
|
||||
: bugui::base_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)
|
||||
{
|
||||
// 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()});
|
||||
}
|
||||
|
||||
const Scenario::IntervalModel &IntervalWidget::get_model() const
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
} // namespace hardware
|
27
Hardware/IntervalWidget.hpp
Normal file
27
Hardware/IntervalWidget.hpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <Scenario/Document/Interval/IntervalModel.hpp>
|
||||
#include <Process/Style/ScenarioStyle.hpp>
|
||||
#include <base_widget.hpp>
|
||||
|
||||
namespace Hardware
|
||||
{
|
||||
struct IntervalWidget : bugui::base_widget
|
||||
{
|
||||
explicit IntervalWidget(base_widget* parent,
|
||||
Scenario::IntervalModel& interval);
|
||||
|
||||
int x() const override;
|
||||
int y() const override;
|
||||
int width() const override;
|
||||
|
||||
void paint(bugui::painter& painter) override;
|
||||
|
||||
const Scenario::IntervalModel& get_model() const;
|
||||
|
||||
private:
|
||||
Scenario::IntervalModel& model;
|
||||
const Process::Style& skin;
|
||||
};
|
||||
|
||||
} // namespace Hardware
|
Loading…
Add table
Reference in a new issue