[widgets] handle on_double_press
This commit is contained in:
parent
f0c64864eb
commit
b0081c70de
7 changed files with 78 additions and 6 deletions
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 465dfda542cae212d2f06298f1d7e0136f2e66c2
|
||||
Subproject commit d1cdce9329c01e98343d798adbe76c7df0013aec
|
|
@ -22,9 +22,22 @@ Controller::Controller(const score::DocumentContext& document,
|
|||
update();
|
||||
}
|
||||
|
||||
void Controller::on_grid(float x, float y, bool pressed)
|
||||
bool Controller::on_press(int x, int y, bool pressed)
|
||||
{
|
||||
qDebug() << "x: " << x << " y: " << y << " pressed: " << pressed;
|
||||
for (auto& w : widgets)
|
||||
if (w->on_press(x, y, pressed))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Controller::on_double_press(int x, int y)
|
||||
{
|
||||
for (auto& w : widgets)
|
||||
if (w->on_double_press(x, y))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controller::on_play(bool pressed)
|
||||
|
|
|
@ -29,7 +29,8 @@ public:
|
|||
void on_left(bool pressed);
|
||||
void on_right(bool pressed);
|
||||
|
||||
void on_grid(float x, float y, bool pressed);
|
||||
bool on_press(int x, int y, bool pressed) override;
|
||||
bool on_double_press(int x, int y) override;
|
||||
|
||||
private:
|
||||
Scenario::IntervalModel* interval;
|
||||
|
|
|
@ -34,6 +34,34 @@ void IntervalWidget::paint(bugui::painter& painter) const
|
|||
painter.draw_line({x(), y()}, {x() + width(), y()});
|
||||
}
|
||||
|
||||
bool IntervalWidget::is_inside(int px, int py) const
|
||||
{
|
||||
if (px >= x() &&
|
||||
px <= (x() + width()) &&
|
||||
py == y())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IntervalWidget::on_press(int x, int y, bool pressed)
|
||||
{
|
||||
if (!is_inside(x, y)) return false;
|
||||
|
||||
qDebug() << "is inside!";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IntervalWidget::on_double_press(int x, int y)
|
||||
{
|
||||
if (!is_inside(x, y)) return false;
|
||||
|
||||
qDebug() << "double pressed !";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const Scenario::IntervalModel &IntervalWidget::get_model() const
|
||||
{
|
||||
return model;
|
||||
|
|
|
@ -12,6 +12,8 @@ struct IntervalWidget final : bugui::base_widget
|
|||
Scenario::IntervalModel& interval);
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
bool on_press(int x, int y, bool pressed) override;
|
||||
bool on_double_press(int x, int y) override;
|
||||
|
||||
int x() const override;
|
||||
int y() const override;
|
||||
|
@ -19,6 +21,9 @@ struct IntervalWidget final : bugui::base_widget
|
|||
|
||||
const Scenario::IntervalModel& get_model() const;
|
||||
|
||||
protected:
|
||||
bool is_inside(int px, int py) const override;
|
||||
|
||||
private:
|
||||
Scenario::IntervalModel& model;
|
||||
const Process::Style& skin;
|
||||
|
|
|
@ -19,11 +19,31 @@ ScenarioWidget::ScenarioWidget(base_widget* parent,
|
|||
widgets.emplace_back(std::make_unique<IntervalWidget>(this, s));
|
||||
}
|
||||
|
||||
void ScenarioWidget::paint(bugui::painter &painter) const
|
||||
void ScenarioWidget::paint(bugui::painter& painter) const
|
||||
{
|
||||
for (const auto& w : widgets) w->paint(painter);
|
||||
}
|
||||
|
||||
bool ScenarioWidget::on_press(int x, int y, bool pressed)
|
||||
{
|
||||
if (!is_inside(x, y)) return false;
|
||||
|
||||
for (auto& w : widgets)
|
||||
if (w->on_press(x, y, pressed)) return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScenarioWidget::on_double_press(int x, int y)
|
||||
{
|
||||
if (!is_inside(x, y)) return false;
|
||||
|
||||
for (auto& w : widgets)
|
||||
if (w->on_double_press(x, y)) return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScenarioWidget::x() const
|
||||
{
|
||||
return bugui::base_widget::parent->x();
|
||||
|
@ -55,7 +75,10 @@ void ScenarioWidget::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(); });
|
||||
{
|
||||
auto ntrvl = static_cast<IntervalWidget*>(w.get());
|
||||
return ntrvl->get_model().id() == interval.id();
|
||||
});
|
||||
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ public:
|
|||
Scenario::ProcessModel* scenario);
|
||||
|
||||
void paint(bugui::painter& painter) const override;
|
||||
bool on_press(int x, int y, bool pressed) override;
|
||||
bool on_double_press(int x, int y) override;
|
||||
|
||||
int x() const override;
|
||||
int y() const override;
|
||||
|
|
Loading…
Add table
Reference in a new issue