[widget] set height with recursive_change
This commit is contained in:
parent
6375cb1558
commit
590815e7dc
5 changed files with 106 additions and 27 deletions
|
@ -28,12 +28,14 @@ int IntervalWidget::width() const
|
|||
|
||||
void IntervalWidget::change_previous(const Scenario::StateModel& state)
|
||||
{
|
||||
|
||||
model.setHeightPercentage(state.heightPercentage());
|
||||
scenario->change_previous(model);
|
||||
}
|
||||
|
||||
void IntervalWidget::change_next(const Scenario::StateModel& state)
|
||||
{
|
||||
model.setHeightPercentage(state.heightPercentage());
|
||||
scenario->change_next(model);
|
||||
}
|
||||
|
||||
bool IntervalWidget::contains(int px, int py) const
|
||||
|
@ -50,7 +52,9 @@ bool IntervalWidget::contains(int px, int py) const
|
|||
void IntervalWidget::paint(bugui::painter &painter) const
|
||||
{
|
||||
const auto col{model.metadata().getColor().getBrush().color()};
|
||||
// const auto col = skin.TimenodeDefault().color();
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
// painter.set_color(255, 255, 255, 255);
|
||||
|
||||
painter.set_paint_over(false);
|
||||
painter.draw_line(0, 0, width(), 0);
|
||||
|
@ -74,7 +78,13 @@ void IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
|||
|
||||
// prevent dragging out of scenario
|
||||
if (new_height >= 0 && new_height <= 1)
|
||||
{
|
||||
scenario->changing = true;
|
||||
model.setHeightPercentage(new_height);
|
||||
scenario->recursive_change(model);
|
||||
scenario->update();
|
||||
scenario->changing = false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace hardware
|
||||
|
|
|
@ -33,11 +33,11 @@ protected:
|
|||
bugui::container_widget* parent)
|
||||
: T{parent}
|
||||
, scenario{s}
|
||||
, skin{Process::Style::instance()}
|
||||
// , skin{Process::Style::instance()}
|
||||
{ }
|
||||
|
||||
ScenarioWidget* scenario{nullptr};
|
||||
const Process::Style& skin;
|
||||
// const Process::Style& skin;
|
||||
};
|
||||
|
||||
template <typename T, typename Base = bugui::base_widget>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <Hardware/Widgets/IntervalWidget.hpp>
|
||||
#include <Hardware/Widgets/TimeSyncWidget.hpp>
|
||||
#include <Hardware/Widgets/StateWidget.hpp>
|
||||
|
||||
namespace Hardware
|
||||
{
|
||||
|
@ -9,7 +10,6 @@ ScenarioWidget::ScenarioWidget(Scenario::ProcessModel* scenario,
|
|||
bugui::container_widget* parent)
|
||||
: bugui::container_widget{parent}
|
||||
, model{scenario}
|
||||
, skin{Process::Style::instance()}
|
||||
{
|
||||
model->intervals.mutable_added.connect<&ScenarioWidget::on_interval_added>(this);
|
||||
model->intervals.removing.connect<&ScenarioWidget::on_interval_removed>(this);
|
||||
|
@ -38,8 +38,6 @@ void ScenarioWidget::remove_proxy(StateWidget* sw)
|
|||
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
||||
{
|
||||
add_widget<IntervalWidget>(interval, this);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval)
|
||||
|
@ -66,6 +64,32 @@ void ScenarioWidget::on_time_sync_removed(const Scenario::TimeSyncModel& timeSyn
|
|||
}
|
||||
|
||||
void ScenarioWidget::recursive_change(const Scenario::StateModel& state)
|
||||
{
|
||||
change_next(state);
|
||||
change_previous(state);
|
||||
}
|
||||
|
||||
void ScenarioWidget::recursive_change(const Scenario::IntervalModel& interval)
|
||||
{
|
||||
change_next(interval);
|
||||
change_previous(interval);
|
||||
}
|
||||
|
||||
void ScenarioWidget::change_next(const Scenario::IntervalModel& interval)
|
||||
{
|
||||
auto& es{interval.endState()};
|
||||
|
||||
for (const auto& s : states_proxy)
|
||||
{
|
||||
if (s->this_model(es))
|
||||
{
|
||||
s->change_next(interval);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScenarioWidget::change_next(const Scenario::StateModel& state)
|
||||
{
|
||||
auto& ni{state.nextInterval()};
|
||||
|
||||
|
@ -84,12 +108,41 @@ void ScenarioWidget::recursive_change(const Scenario::StateModel& state)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void ScenarioWidget::recursive_change(const Scenario::IntervalModel& interval)
|
||||
void ScenarioWidget::change_previous(const Scenario::IntervalModel& interval)
|
||||
{
|
||||
auto& es{interval.startState()};
|
||||
|
||||
for (const auto& s : states_proxy)
|
||||
{
|
||||
if (s->this_model(es))
|
||||
{
|
||||
s->change_previous(interval);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScenarioWidget::change_previous(const Scenario::StateModel& state)
|
||||
{
|
||||
auto& ni{state.previousInterval()};
|
||||
|
||||
if (ni)
|
||||
{
|
||||
auto& v{ni.value()};
|
||||
|
||||
for (const auto& c : children)
|
||||
{
|
||||
ScenarioComponent<>* s{static_cast<ScenarioComponent<>*>(c.get())};
|
||||
|
||||
if (s->this_model(v))
|
||||
{
|
||||
static_cast<IntervalWidget*>(s)->change_previous(state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -31,6 +31,13 @@ public:
|
|||
void recursive_change(const Scenario::StateModel& state);
|
||||
void recursive_change(const Scenario::IntervalModel& interval);
|
||||
|
||||
void change_previous(const Scenario::IntervalModel& interval);
|
||||
void change_previous(const Scenario::StateModel& state);
|
||||
void change_next(const Scenario::IntervalModel& interval);
|
||||
void change_next(const Scenario::StateModel& state);
|
||||
|
||||
bool changing{false};
|
||||
|
||||
private:
|
||||
void on_interval_added(Scenario::IntervalModel& interval);
|
||||
void on_interval_removed(const Scenario::IntervalModel& interval);
|
||||
|
@ -38,15 +45,10 @@ private:
|
|||
void on_time_sync_added(Scenario::TimeSyncModel& timeSync);
|
||||
void on_time_sync_removed(const Scenario::TimeSyncModel& timeSync);
|
||||
|
||||
void move_previous(const Scenario::IntervalModel& interval);
|
||||
void move_previous(const Scenario::StateModel& interval);
|
||||
void move_next(const Scenario::IntervalModel& interval);
|
||||
void move_next(const Scenario::StateModel& interval);
|
||||
|
||||
std::vector<StateWidget*> states_proxy;
|
||||
|
||||
Scenario::ProcessModel* model{nullptr};
|
||||
const Process::Style& skin;
|
||||
// const Process::Style& skin;
|
||||
};
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -13,15 +13,17 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
|||
{
|
||||
set_absolute_y();
|
||||
|
||||
// con = connect(&model,
|
||||
// &Scenario::StateModel::heightPercentageChanged,
|
||||
// this,
|
||||
// [scenario, this]
|
||||
// {
|
||||
// set_absolute_y();
|
||||
// set_span_recursive();
|
||||
// scenario->update();
|
||||
// });
|
||||
con = connect(&model,
|
||||
&Scenario::StateModel::heightPercentageChanged,
|
||||
this,
|
||||
[scenario, this]
|
||||
{
|
||||
if (scenario->changing) return;
|
||||
|
||||
set_absolute_y();
|
||||
set_span_recursive();
|
||||
scenario->update();
|
||||
});
|
||||
|
||||
scenario->add_proxy(this);
|
||||
}
|
||||
|
@ -34,11 +36,17 @@ StateWidget::~StateWidget()
|
|||
|
||||
void StateWidget::change_previous(const Scenario::IntervalModel& interval)
|
||||
{
|
||||
|
||||
model.setHeightPercentage(interval.heightPercentage());
|
||||
set_absolute_y();
|
||||
set_span_recursive();
|
||||
scenario->change_previous(model);
|
||||
}
|
||||
void StateWidget::change_next(const Scenario::IntervalModel& interval)
|
||||
{
|
||||
|
||||
model.setHeightPercentage(interval.heightPercentage());
|
||||
set_absolute_y();
|
||||
set_span_recursive();
|
||||
scenario->change_next(model);
|
||||
}
|
||||
|
||||
void StateWidget::paint(bugui::painter& painter) const
|
||||
|
@ -46,6 +54,7 @@ void StateWidget::paint(bugui::painter& painter) const
|
|||
const auto col{model.metadata().getColor().getBrush().color()};
|
||||
// const auto col = skin.StateSelected().color();
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
// painter.set_color(255, 255, 255, 255);
|
||||
|
||||
painter.draw_cell(0, 0);
|
||||
}
|
||||
|
@ -76,8 +85,13 @@ void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
|||
// prevent dragging out of scenario
|
||||
if (new_height >= 0 && new_height <= 1)
|
||||
{
|
||||
scenario->changing = true;
|
||||
model.setHeightPercentage(new_height);
|
||||
scenario->recursive_change(model);
|
||||
set_absolute_y();
|
||||
set_span_recursive();
|
||||
scenario->update();
|
||||
scenario->changing = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue