[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)
|
void IntervalWidget::change_previous(const Scenario::StateModel& state)
|
||||||
{
|
{
|
||||||
|
model.setHeightPercentage(state.heightPercentage());
|
||||||
|
scenario->change_previous(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntervalWidget::change_next(const Scenario::StateModel& state)
|
void IntervalWidget::change_next(const Scenario::StateModel& state)
|
||||||
{
|
{
|
||||||
model.setHeightPercentage(state.heightPercentage());
|
model.setHeightPercentage(state.heightPercentage());
|
||||||
|
scenario->change_next(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntervalWidget::contains(int px, int py) const
|
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
|
void IntervalWidget::paint(bugui::painter &painter) const
|
||||||
{
|
{
|
||||||
const auto col{model.metadata().getColor().getBrush().color()};
|
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(col.red(), col.green(), col.blue(), col.alpha());
|
||||||
|
// painter.set_color(255, 255, 255, 255);
|
||||||
|
|
||||||
painter.set_paint_over(false);
|
painter.set_paint_over(false);
|
||||||
painter.draw_line(0, 0, width(), 0);
|
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
|
// prevent dragging out of scenario
|
||||||
if (new_height >= 0 && new_height <= 1)
|
if (new_height >= 0 && new_height <= 1)
|
||||||
|
{
|
||||||
|
scenario->changing = true;
|
||||||
model.setHeightPercentage(new_height);
|
model.setHeightPercentage(new_height);
|
||||||
|
scenario->recursive_change(model);
|
||||||
|
scenario->update();
|
||||||
|
scenario->changing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
|
|
|
@ -33,11 +33,11 @@ protected:
|
||||||
bugui::container_widget* parent)
|
bugui::container_widget* parent)
|
||||||
: T{parent}
|
: T{parent}
|
||||||
, scenario{s}
|
, scenario{s}
|
||||||
, skin{Process::Style::instance()}
|
// , skin{Process::Style::instance()}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
ScenarioWidget* scenario{nullptr};
|
ScenarioWidget* scenario{nullptr};
|
||||||
const Process::Style& skin;
|
// const Process::Style& skin;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename Base = bugui::base_widget>
|
template <typename T, typename Base = bugui::base_widget>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <Hardware/Widgets/IntervalWidget.hpp>
|
#include <Hardware/Widgets/IntervalWidget.hpp>
|
||||||
#include <Hardware/Widgets/TimeSyncWidget.hpp>
|
#include <Hardware/Widgets/TimeSyncWidget.hpp>
|
||||||
|
#include <Hardware/Widgets/StateWidget.hpp>
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,6 @@ ScenarioWidget::ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||||
bugui::container_widget* parent)
|
bugui::container_widget* parent)
|
||||||
: bugui::container_widget{parent}
|
: bugui::container_widget{parent}
|
||||||
, model{scenario}
|
, model{scenario}
|
||||||
, skin{Process::Style::instance()}
|
|
||||||
{
|
{
|
||||||
model->intervals.mutable_added.connect<&ScenarioWidget::on_interval_added>(this);
|
model->intervals.mutable_added.connect<&ScenarioWidget::on_interval_added>(this);
|
||||||
model->intervals.removing.connect<&ScenarioWidget::on_interval_removed>(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)
|
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
||||||
{
|
{
|
||||||
add_widget<IntervalWidget>(interval, this);
|
add_widget<IntervalWidget>(interval, this);
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval)
|
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)
|
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()};
|
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
|
} // namespace Hardware
|
||||||
|
|
|
@ -10,7 +10,7 @@ struct StateWidget;
|
||||||
|
|
||||||
class ScenarioWidget final : public bugui::container_widget
|
class ScenarioWidget final : public bugui::container_widget
|
||||||
, public Nano::Observer
|
, public Nano::Observer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ScenarioWidget(Scenario::ProcessModel* scenario,
|
explicit ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||||
bugui::container_widget* parent);
|
bugui::container_widget* parent);
|
||||||
|
@ -31,6 +31,13 @@ public:
|
||||||
void recursive_change(const Scenario::StateModel& state);
|
void recursive_change(const Scenario::StateModel& state);
|
||||||
void recursive_change(const Scenario::IntervalModel& interval);
|
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:
|
private:
|
||||||
void on_interval_added(Scenario::IntervalModel& interval);
|
void on_interval_added(Scenario::IntervalModel& interval);
|
||||||
void on_interval_removed(const 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_added(Scenario::TimeSyncModel& timeSync);
|
||||||
void on_time_sync_removed(const 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;
|
std::vector<StateWidget*> states_proxy;
|
||||||
|
|
||||||
Scenario::ProcessModel* model{nullptr};
|
Scenario::ProcessModel* model{nullptr};
|
||||||
const Process::Style& skin;
|
// const Process::Style& skin;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Hardware
|
} // namespace Hardware
|
||||||
|
|
|
@ -13,15 +13,17 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
||||||
{
|
{
|
||||||
set_absolute_y();
|
set_absolute_y();
|
||||||
|
|
||||||
// con = connect(&model,
|
con = connect(&model,
|
||||||
// &Scenario::StateModel::heightPercentageChanged,
|
&Scenario::StateModel::heightPercentageChanged,
|
||||||
// this,
|
this,
|
||||||
// [scenario, this]
|
[scenario, this]
|
||||||
// {
|
{
|
||||||
// set_absolute_y();
|
if (scenario->changing) return;
|
||||||
// set_span_recursive();
|
|
||||||
// scenario->update();
|
set_absolute_y();
|
||||||
// });
|
set_span_recursive();
|
||||||
|
scenario->update();
|
||||||
|
});
|
||||||
|
|
||||||
scenario->add_proxy(this);
|
scenario->add_proxy(this);
|
||||||
}
|
}
|
||||||
|
@ -34,11 +36,17 @@ StateWidget::~StateWidget()
|
||||||
|
|
||||||
void StateWidget::change_previous(const Scenario::IntervalModel& interval)
|
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)
|
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
|
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{model.metadata().getColor().getBrush().color()};
|
||||||
// const auto col = skin.StateSelected().color();
|
// const auto col = skin.StateSelected().color();
|
||||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||||
|
// painter.set_color(255, 255, 255, 255);
|
||||||
|
|
||||||
painter.draw_cell(0, 0);
|
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
|
// prevent dragging out of scenario
|
||||||
if (new_height >= 0 && new_height <= 1)
|
if (new_height >= 0 && new_height <= 1)
|
||||||
{
|
{
|
||||||
|
scenario->changing = true;
|
||||||
model.setHeightPercentage(new_height);
|
model.setHeightPercentage(new_height);
|
||||||
scenario->recursive_change(model);
|
scenario->recursive_change(model);
|
||||||
|
set_absolute_y();
|
||||||
|
set_span_recursive();
|
||||||
|
scenario->update();
|
||||||
|
scenario->changing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue