[widgets] fix contain functions
This commit is contained in:
parent
45d3059b08
commit
294e23cc9b
11 changed files with 55 additions and 75 deletions
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 6a0c86674d0f1513c92140530d2221051ed05ee5
|
||||
Subproject commit 3c63860f760d7ec20f09f0d4f6293381fc08e876
|
|
@ -46,19 +46,27 @@ void EventWidget::set_span_recursive()
|
|||
static_cast<TimeSyncWidget*>(bugui::base_widget::parent)->set_span();
|
||||
|
||||
m_y = m_absolute_y - parent->y();
|
||||
|
||||
for(const auto& s : bugui::container_widget::children)
|
||||
static_cast<StateWidget*>(s.get())->set_y();
|
||||
}
|
||||
|
||||
void EventWidget::paint(bugui::painter& painter) const
|
||||
{
|
||||
// const auto col = skin.StateSelected().color();
|
||||
// painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
if (!press) return;
|
||||
|
||||
// painter.draw_line(0, 0, 0, m_height);
|
||||
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.draw_line(0, 0, 0, m_height);
|
||||
}
|
||||
|
||||
bool EventWidget::contains(int px, int py) const
|
||||
{
|
||||
if (px == x() && py == y())
|
||||
if (px == 0 &&
|
||||
py >= 0 &&
|
||||
py <= m_height)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -88,12 +96,7 @@ void EventWidget::on_state_removed(const Scenario::StateModel& state)
|
|||
|
||||
void EventWidget::on_press(int x, int y, bool pressed)
|
||||
{
|
||||
qDebug() << "event pressed";
|
||||
}
|
||||
|
||||
void EventWidget::on_double_press(int x, int y, bool pressed)
|
||||
{
|
||||
qDebug() << "event double pressed";
|
||||
press = pressed;
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -25,11 +25,12 @@ private:
|
|||
void paint(bugui::painter& painter) const override;
|
||||
|
||||
void on_press(int x, int y, bool pressed) override;
|
||||
void on_double_press(int x, int y, bool pressed);
|
||||
|
||||
void on_state_added(Scenario::StateModel& state);
|
||||
void on_state_removed(const Scenario::StateModel& state);
|
||||
|
||||
bool press{false};
|
||||
|
||||
int m_absolute_y{0};
|
||||
int m_y{0};
|
||||
int m_height{0};
|
||||
|
|
|
@ -38,6 +38,16 @@ bool IntervalWidget::contains(int px, int py) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void IntervalWidget::paint(bugui::painter &painter) const
|
||||
{
|
||||
const auto col{model.metadata().getColor().getBrush().color()};
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
|
||||
painter.set_paint_over(false);
|
||||
painter.draw_line(0, 0, width(), 0);
|
||||
painter.set_paint_over(true);
|
||||
}
|
||||
|
||||
void IntervalWidget::on_press(int x, int y, bool pressed)
|
||||
{
|
||||
qDebug() << "interval pressed";
|
||||
|
|
|
@ -20,6 +20,8 @@ struct IntervalWidget final : ScenarioComponentSpec<Scenario::IntervalModel>
|
|||
private:
|
||||
bool contains(int px, int py) const override;
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
|
||||
void on_press(int x, int y, bool pressed) override;
|
||||
void on_double_press(int x, int y) override;
|
||||
void on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||
|
|
|
@ -24,45 +24,6 @@ ScenarioWidget::ScenarioWidget(Scenario::ProcessModel* scenario,
|
|||
add_widget<TimeSyncWidget>(t, this);
|
||||
}
|
||||
|
||||
int ScenarioWidget::x() const
|
||||
{
|
||||
return bugui::base_widget::parent->x();
|
||||
}
|
||||
|
||||
int ScenarioWidget::y() const
|
||||
{
|
||||
return bugui::base_widget::parent->y();
|
||||
}
|
||||
|
||||
int ScenarioWidget::width() const
|
||||
{
|
||||
return std::numeric_limits<int>::max();
|
||||
}
|
||||
|
||||
int ScenarioWidget::height() const
|
||||
{
|
||||
return 15;
|
||||
}
|
||||
|
||||
Scenario::ProcessModel *ScenarioWidget::get_model() const
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
void ScenarioWidget::paint(bugui::painter& painter) const
|
||||
{
|
||||
const auto col = skin.IntervalBase().color();
|
||||
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||
|
||||
for (const auto& i : model->intervals)
|
||||
{
|
||||
int y{static_cast<int>(i.heightPercentage() * height())};
|
||||
int st{static_cast<int>(i.date().sec())};
|
||||
|
||||
painter.draw_line(st, y, st + i.duration.defaultDuration().sec(), y);
|
||||
}
|
||||
}
|
||||
|
||||
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
||||
{
|
||||
add_widget<IntervalWidget>(interval, this);
|
||||
|
|
|
@ -13,16 +13,17 @@ public:
|
|||
explicit ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||
bugui::container_widget* parent);
|
||||
|
||||
int x() const override;
|
||||
int y() const override;
|
||||
int width() const override;
|
||||
int height() const override;
|
||||
int x() const override
|
||||
{ return bugui::base_widget::parent->x(); }
|
||||
int y() const override
|
||||
{ return bugui::base_widget::parent->y(); }
|
||||
int width() const override
|
||||
{ return std::numeric_limits<int>::max(); }
|
||||
int height() const override { return 15; }
|
||||
|
||||
Scenario::ProcessModel* get_model() const;
|
||||
Scenario::ProcessModel* get_model() const { return model; }
|
||||
|
||||
private:
|
||||
void paint(bugui::painter& painter) const override;
|
||||
|
||||
void on_interval_added(Scenario::IntervalModel& interval);
|
||||
void on_interval_removed(const Scenario::IntervalModel& interval);
|
||||
|
||||
|
|
|
@ -24,22 +24,18 @@ StateWidget::StateWidget(Scenario::StateModel& state,
|
|||
});
|
||||
}
|
||||
|
||||
StateWidget::~StateWidget()
|
||||
{
|
||||
disconnect(con);
|
||||
}
|
||||
|
||||
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(col.red(), col.green(), col.blue(), col.alpha());
|
||||
|
||||
// painter.draw_cell(0, 0);
|
||||
painter.draw_cell(0, 0);
|
||||
}
|
||||
|
||||
bool StateWidget::contains(int px, int py) const
|
||||
{
|
||||
if (px == x() && py == y())
|
||||
if (px == 0 && py == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -47,7 +43,7 @@ bool StateWidget::contains(int px, int py) const
|
|||
|
||||
void StateWidget::on_press(int x, int y, bool pressed)
|
||||
{
|
||||
qDebug() << "state pressed";
|
||||
update();
|
||||
}
|
||||
|
||||
void StateWidget::on_double_press(int x, int y)
|
||||
|
@ -77,8 +73,6 @@ void StateWidget::set_span_recursive()
|
|||
{
|
||||
static_cast<EventWidget*>(bugui::base_widget::parent)
|
||||
->set_span_recursive();
|
||||
|
||||
set_y();
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -12,7 +12,7 @@ struct StateWidget final : QObject
|
|||
ScenarioWidget* scenario,
|
||||
bugui::container_widget* parent);
|
||||
|
||||
~StateWidget() override;
|
||||
~StateWidget() override { disconnect(con); }
|
||||
|
||||
int y() const override { return m_y; }
|
||||
int get_absolute_y() { return m_absolute_y; };
|
||||
|
|
|
@ -70,8 +70,9 @@ void TimeSyncWidget::set_span()
|
|||
|
||||
for(const auto& e : bugui::container_widget::children)
|
||||
{
|
||||
int sy = static_cast<EventWidget*>(e.get())->get_absolute_y();
|
||||
int sh = sy + static_cast<EventWidget*>(e.get())->height();
|
||||
auto e_ptr{static_cast<EventWidget*>(e.get())};
|
||||
int sy = e_ptr->get_absolute_y();
|
||||
int sh = sy + e_ptr->height();
|
||||
if (sy < lowest) lowest = sy;
|
||||
if (sh > heighest) heighest = sh;
|
||||
}
|
||||
|
@ -82,7 +83,10 @@ void TimeSyncWidget::set_span()
|
|||
|
||||
void TimeSyncWidget::paint(bugui::painter& painter) const
|
||||
{
|
||||
const auto col = skin.StateSelected().color();
|
||||
if (!press) return;
|
||||
|
||||
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.draw_line(0, 0, 0, m_height);
|
||||
|
@ -90,7 +94,9 @@ void TimeSyncWidget::paint(bugui::painter& painter) const
|
|||
|
||||
bool TimeSyncWidget::contains(int px, int py) const
|
||||
{
|
||||
if (px == x() && py == y())
|
||||
if (px == 0 &&
|
||||
py >= 0 &&
|
||||
py <= m_height)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -98,7 +104,7 @@ bool TimeSyncWidget::contains(int px, int py) const
|
|||
|
||||
void TimeSyncWidget::on_press(int x, int y, bool pressed)
|
||||
{
|
||||
qDebug() << "timeSync pressed";
|
||||
press = pressed;
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
|
|
|
@ -30,6 +30,8 @@ private:
|
|||
void paint(bugui::painter& painter) const override;
|
||||
void on_press(int x, int y, bool pressed) override;
|
||||
|
||||
bool press{false};
|
||||
|
||||
int m_y{0};
|
||||
int m_height{0};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue