2025-01-10 01:38:58 +00:00
|
|
|
#include <Scenario/Document/TimeSync/TimeSyncModel.hpp>
|
|
|
|
|
2025-01-13 18:49:21 +00:00
|
|
|
#include "EventWidget.hpp"
|
2025-01-11 11:56:26 +00:00
|
|
|
#include "ScenarioWidget.hpp"
|
2025-01-10 01:38:58 +00:00
|
|
|
#include "TimeSyncWidget.hpp"
|
|
|
|
|
|
|
|
namespace Hardware
|
|
|
|
{
|
|
|
|
TimeSyncWidget::TimeSyncWidget(Scenario::TimeSyncModel& timeSync,
|
2025-01-11 11:56:26 +00:00
|
|
|
ScenarioWidget* scenario,
|
2025-01-10 01:38:58 +00:00
|
|
|
bugui::container_widget* parent)
|
2025-01-10 10:12:29 +00:00
|
|
|
: ScenarioComponentSpec<Scenario::TimeSyncModel,
|
2025-01-11 11:56:26 +00:00
|
|
|
bugui::container_widget>{timeSync, scenario, parent}
|
|
|
|
{
|
2025-01-13 18:49:21 +00:00
|
|
|
connect(&model,
|
|
|
|
&Scenario::TimeSyncModel::dateChanged,
|
|
|
|
this,
|
|
|
|
[scenario] (const TimeVal&) { scenario->update(); });
|
|
|
|
|
|
|
|
connect(&model,
|
|
|
|
&Scenario::TimeSyncModel::newEvent,
|
|
|
|
this,
|
|
|
|
[scenario, this] (const Id<Scenario::EventModel>& eventId)
|
2025-01-16 02:00:26 +00:00
|
|
|
{
|
|
|
|
add_widget<EventWidget>(scenario->get_model()->events.at(eventId), scenario);
|
|
|
|
});
|
2025-01-13 18:49:21 +00:00
|
|
|
|
|
|
|
connect(&model,
|
|
|
|
&Scenario::TimeSyncModel::eventRemoved,
|
|
|
|
this,
|
|
|
|
[scenario, this] (const Id<Scenario::EventModel>& eventId)
|
|
|
|
{
|
|
|
|
remove_widget([&eventId]
|
|
|
|
(const auto& w)
|
|
|
|
{ return static_cast<ScenarioComponent<>*>(w.get())->this_model(eventId); });
|
2025-01-16 02:00:26 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
set_span();
|
2025-01-16 02:00:26 +00:00
|
|
|
update();
|
2025-01-13 18:49:21 +00:00
|
|
|
});
|
2025-01-14 23:41:30 +00:00
|
|
|
|
|
|
|
Scenario::ProcessModel* scen{scenario->get_model()};
|
|
|
|
|
|
|
|
for(Scenario::EventModel& e : scen->events)
|
|
|
|
if (e.timeSync() == model.id())
|
|
|
|
add_widget<EventWidget>(e, scenario);
|
2025-01-13 18:49:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TimeSyncWidget::~TimeSyncWidget()
|
|
|
|
{
|
|
|
|
disconnect(&model,
|
|
|
|
&Scenario::TimeSyncModel::dateChanged,
|
|
|
|
this, 0);
|
2025-01-11 11:56:26 +00:00
|
|
|
|
2025-01-13 18:49:21 +00:00
|
|
|
disconnect(&model,
|
|
|
|
&Scenario::TimeSyncModel::newEvent,
|
|
|
|
this, 0);
|
2025-01-11 11:56:26 +00:00
|
|
|
|
2025-01-13 18:49:21 +00:00
|
|
|
disconnect(&model,
|
|
|
|
&Scenario::TimeSyncModel::eventRemoved,
|
|
|
|
this, 0);
|
2025-01-11 11:56:26 +00:00
|
|
|
}
|
2025-01-10 01:38:58 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
void TimeSyncWidget::set_span()
|
2025-01-10 01:38:58 +00:00
|
|
|
{
|
2025-01-19 00:14:26 +00:00
|
|
|
if (bugui::container_widget::children.empty())
|
|
|
|
return;
|
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
int lowest{std::numeric_limits<int>::max()};
|
|
|
|
int heighest{0};
|
2025-01-10 01:38:58 +00:00
|
|
|
|
2025-01-13 18:49:21 +00:00
|
|
|
for(const auto& e : bugui::container_widget::children)
|
2025-01-11 11:56:26 +00:00
|
|
|
{
|
2025-01-18 12:05:17 +00:00
|
|
|
int sy = static_cast<EventWidget*>(e.get())->get_absolute_y();
|
2025-01-19 00:14:26 +00:00
|
|
|
int sh = sy + static_cast<EventWidget*>(e.get())->height();
|
2025-01-18 12:05:17 +00:00
|
|
|
if (sy < lowest) lowest = sy;
|
2025-01-19 00:14:26 +00:00
|
|
|
if (sh > heighest) heighest = sh;
|
2025-01-11 11:56:26 +00:00
|
|
|
}
|
2025-01-17 22:16:43 +00:00
|
|
|
|
2025-01-18 12:05:17 +00:00
|
|
|
m_y = lowest;
|
|
|
|
m_height = heighest - lowest;
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TimeSyncWidget::paint(bugui::painter& painter) const
|
|
|
|
{
|
2025-01-19 00:14:26 +00:00
|
|
|
const auto col = skin.StateSelected().color();
|
|
|
|
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
2025-01-10 01:38:58 +00:00
|
|
|
|
2025-01-19 00:14:26 +00:00
|
|
|
painter.draw_line(0, 0, 0, m_height);
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TimeSyncWidget::contains(int px, int py) const
|
|
|
|
{
|
|
|
|
if (px == x() && py == y())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2025-01-11 11:56:26 +00:00
|
|
|
void TimeSyncWidget::on_press(int x, int y, bool pressed)
|
|
|
|
{
|
2025-01-16 13:10:52 +00:00
|
|
|
qDebug() << "timeSync pressed";
|
2025-01-10 01:38:58 +00:00
|
|
|
}
|
2025-01-11 11:56:26 +00:00
|
|
|
|
|
|
|
} // namespace Hardware
|
2025-01-13 18:49:21 +00:00
|
|
|
|
|
|
|
#include <wobjectimpl.h>
|
|
|
|
W_OBJECT_IMPL(Hardware::TimeSyncWidget);
|