[widgets] varius updates + widget ofset
This commit is contained in:
parent
d52e74eb27
commit
3255c144d1
9 changed files with 153 additions and 39 deletions
|
@ -24,6 +24,7 @@ set(HDRS
|
||||||
"Hardware/ApplicationPlugin.hpp"
|
"Hardware/ApplicationPlugin.hpp"
|
||||||
|
|
||||||
"Hardware/Widgets/ScenarioWidget.hpp"
|
"Hardware/Widgets/ScenarioWidget.hpp"
|
||||||
|
"Hardware/Widgets/StateWidget.hpp"
|
||||||
"Hardware/Widgets/IntervalWidget.hpp"
|
"Hardware/Widgets/IntervalWidget.hpp"
|
||||||
|
|
||||||
"score_addon_hardware.hpp"
|
"score_addon_hardware.hpp"
|
||||||
|
@ -39,6 +40,7 @@ set(SRCS
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/ApplicationPlugin.cpp"
|
||||||
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Widgets/ScenarioWidget.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Widgets/ScenarioWidget.cpp"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Widgets/StateWidget.cpp"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Widgets/IntervalWidget.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/Hardware/Widgets/IntervalWidget.cpp"
|
||||||
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp"
|
"${CMAKE_CURRENT_SOURCE_DIR}/score_addon_hardware.cpp"
|
||||||
|
|
2
Hardware/3rdparty/bugui
vendored
2
Hardware/3rdparty/bugui
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit dfa356a6fe5d8fd215fae4e59d0b662938b17d7b
|
Subproject commit 586572a187266d3752e735774a6de62e1463af27
|
|
@ -17,9 +17,7 @@ Controller::Controller(const score::DocumentContext& document,
|
||||||
{
|
{
|
||||||
auto scnr = qobject_cast<Scenario::ProcessModel*>(&*interval.processes.begin());
|
auto scnr = qobject_cast<Scenario::ProcessModel*>(&*interval.processes.begin());
|
||||||
|
|
||||||
if (scnr)
|
if (scnr) add_widget<ScenarioWidget>(scnr);
|
||||||
bugui::container_widget::children.emplace_back(
|
|
||||||
std::make_unique<ScenarioWidget>(this, scnr));
|
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -47,65 +45,74 @@ void Controller::on_shift(bool pressed)
|
||||||
|
|
||||||
void Controller::on_up(bool pressed)
|
void Controller::on_up(bool pressed)
|
||||||
{
|
{
|
||||||
|
if (!pressed) return;
|
||||||
|
|
||||||
if (m_shift)
|
if (m_shift)
|
||||||
{
|
{
|
||||||
v_scale += .2;
|
vertical_scale += .2;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
v_ofset += .02;
|
if (vertical_ofset > -1) return;
|
||||||
|
|
||||||
|
vertical_ofset += 1;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::on_down(bool pressed)
|
void Controller::on_down(bool pressed)
|
||||||
{
|
{
|
||||||
|
if (!pressed) return;
|
||||||
|
|
||||||
if (m_shift)
|
if (m_shift)
|
||||||
{
|
{
|
||||||
if (v_scale > .2)
|
if (vertical_scale > .2)
|
||||||
{
|
{
|
||||||
v_scale -= .2;
|
vertical_scale -= .2;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
v_ofset -= .02;
|
vertical_ofset -= 1;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::on_left(bool pressed)
|
void Controller::on_left(bool pressed)
|
||||||
{
|
{
|
||||||
|
if (!pressed) return;
|
||||||
|
|
||||||
if (m_shift)
|
if (m_shift)
|
||||||
{
|
{
|
||||||
if (h_scale > .02)
|
if (horizontal_scale > .02)
|
||||||
{
|
{
|
||||||
h_scale -= .02;
|
horizontal_scale -= .02;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (h_ofset > 0)
|
if (horizontal_ofset > -1) return;
|
||||||
{
|
|
||||||
h_ofset -= .02;
|
horizontal_ofset += 1;
|
||||||
update();
|
update();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::on_right(bool pressed)
|
void Controller::on_right(bool pressed)
|
||||||
{
|
{
|
||||||
|
if (!pressed) return;
|
||||||
|
|
||||||
if (m_shift)
|
if (m_shift)
|
||||||
{
|
{
|
||||||
h_scale += .02;
|
horizontal_scale += .02;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
h_ofset += .02;
|
horizontal_ofset -= 1;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
IntervalWidget::IntervalWidget(container_widget *parent,
|
IntervalWidget::IntervalWidget(Scenario::IntervalModel& interval,
|
||||||
Scenario::IntervalModel& interval)
|
container_widget* parent)
|
||||||
: bugui::container_widget{parent}
|
: bugui::container_widget{parent}
|
||||||
, model{interval}
|
, model{interval}
|
||||||
, skin{Process::Style::instance()}
|
, skin{Process::Style::instance()}
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
int IntervalWidget::x() const
|
int IntervalWidget::x() const
|
||||||
{
|
{
|
||||||
|
@ -34,7 +33,7 @@ void IntervalWidget::paint(bugui::painter& painter) const
|
||||||
painter.draw_line({x(), y()}, {x() + width(), y()});
|
painter.draw_line({x(), y()}, {x() + width(), y()});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IntervalWidget::is_inside(int px, int py) const
|
bool IntervalWidget::contains(int px, int py) const
|
||||||
{
|
{
|
||||||
if (px >= x() &&
|
if (px >= x() &&
|
||||||
px <= (x() + width()) &&
|
px <= (x() + width()) &&
|
||||||
|
@ -46,7 +45,7 @@ bool IntervalWidget::is_inside(int px, int py) const
|
||||||
|
|
||||||
bool IntervalWidget::on_press(int x, int y, bool pressed)
|
bool IntervalWidget::on_press(int x, int y, bool pressed)
|
||||||
{
|
{
|
||||||
if (!is_inside(x, y)) return false;
|
if (!contains(x, y)) return false;
|
||||||
|
|
||||||
qDebug() << "is inside!";
|
qDebug() << "is inside!";
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ bool IntervalWidget::on_press(int x, int y, bool pressed)
|
||||||
|
|
||||||
bool IntervalWidget::on_double_press(int x, int y)
|
bool IntervalWidget::on_double_press(int x, int y)
|
||||||
{
|
{
|
||||||
if (!is_inside(x, y)) return false;
|
if (!contains(x, y)) return false;
|
||||||
|
|
||||||
qDebug() << "double pressed !";
|
qDebug() << "double pressed !";
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ bool IntervalWidget::on_double_press(int x, int y)
|
||||||
|
|
||||||
bool IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
bool IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||||
{
|
{
|
||||||
if (!is_inside(from_x, from_y)) return false;
|
if (!contains(from_x, from_y)) return false;
|
||||||
|
|
||||||
if (from_y != to_y)
|
if (from_y != to_y)
|
||||||
model.requestHeightChange(to_y / static_cast<double>(parent->height()));
|
model.requestHeightChange(to_y / static_cast<double>(parent->height()));
|
||||||
|
@ -72,7 +71,7 @@ bool IntervalWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Scenario::IntervalModel &IntervalWidget::get_model() const
|
const Scenario::IntervalModel& IntervalWidget::get_model() const
|
||||||
{
|
{
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ namespace Hardware
|
||||||
{
|
{
|
||||||
struct IntervalWidget final : bugui::container_widget
|
struct IntervalWidget final : bugui::container_widget
|
||||||
{
|
{
|
||||||
explicit IntervalWidget(container_widget* parent,
|
explicit IntervalWidget(Scenario::IntervalModel& interval,
|
||||||
Scenario::IntervalModel& interval);
|
container_widget* parent);
|
||||||
|
|
||||||
void paint(bugui::painter& painter) const override;
|
void paint(bugui::painter& painter) const override;
|
||||||
bool on_press(int x, int y, bool pressed) override;
|
bool on_press(int x, int y, bool pressed) override;
|
||||||
|
@ -23,7 +23,7 @@ struct IntervalWidget final : bugui::container_widget
|
||||||
const Scenario::IntervalModel& get_model() const;
|
const Scenario::IntervalModel& get_model() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool is_inside(int px, int py) const override;
|
bool contains(int px, int py) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Scenario::IntervalModel& model;
|
Scenario::IntervalModel& model;
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
namespace Hardware
|
namespace Hardware
|
||||||
{
|
{
|
||||||
ScenarioWidget::ScenarioWidget(bugui::container_widget* parent,
|
ScenarioWidget::ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||||
Scenario::ProcessModel* scenario)
|
bugui::container_widget* parent)
|
||||||
: bugui::container_widget{parent}
|
: bugui::container_widget{parent}
|
||||||
, model{scenario}
|
, model{scenario}
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ ScenarioWidget::ScenarioWidget(bugui::container_widget* parent,
|
||||||
[this] { update(); });
|
[this] { update(); });
|
||||||
|
|
||||||
for(Scenario::IntervalModel& s : model->intervals)
|
for(Scenario::IntervalModel& s : model->intervals)
|
||||||
bugui::container_widget::children.emplace_back(std::make_unique<IntervalWidget>(this, s));
|
add_widget<IntervalWidget>(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScenarioWidget::x() const
|
int ScenarioWidget::x() const
|
||||||
|
@ -26,7 +26,7 @@ int ScenarioWidget::x() const
|
||||||
|
|
||||||
int ScenarioWidget::y() const
|
int ScenarioWidget::y() const
|
||||||
{
|
{
|
||||||
return bugui::base_widget::parent->x();
|
return bugui::base_widget::parent->y();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScenarioWidget::width() const
|
int ScenarioWidget::width() const
|
||||||
|
@ -41,14 +41,13 @@ int ScenarioWidget::height() const
|
||||||
|
|
||||||
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
void ScenarioWidget::on_interval_added(Scenario::IntervalModel& interval)
|
||||||
{
|
{
|
||||||
bugui::container_widget::children.emplace_back(std::make_unique<IntervalWidget>(this, interval));
|
add_widget<IntervalWidget>(interval);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval)
|
void ScenarioWidget::on_interval_removed(const Scenario::IntervalModel& interval)
|
||||||
{
|
{
|
||||||
std::erase_if(bugui::container_widget::children,
|
remove_widget([&interval]
|
||||||
[&interval]
|
|
||||||
(const auto& w)
|
(const auto& w)
|
||||||
{
|
{
|
||||||
auto ntrvl = static_cast<IntervalWidget*>(w.get());
|
auto ntrvl = static_cast<IntervalWidget*>(w.get());
|
||||||
|
|
|
@ -14,8 +14,8 @@ class ScenarioWidget final
|
||||||
W_OBJECT(ScenarioWidget)
|
W_OBJECT(ScenarioWidget)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ScenarioWidget(bugui::container_widget* parent,
|
explicit ScenarioWidget(Scenario::ProcessModel* scenario,
|
||||||
Scenario::ProcessModel* scenario);
|
bugui::container_widget* parent);
|
||||||
|
|
||||||
int x() const override;
|
int x() const override;
|
||||||
int y() const override;
|
int y() const override;
|
||||||
|
|
74
Hardware/Widgets/StateWidget.cpp
Normal file
74
Hardware/Widgets/StateWidget.cpp
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#include "StateWidget.hpp"
|
||||||
|
|
||||||
|
namespace Hardware
|
||||||
|
{
|
||||||
|
StateWidget::StateWidget(Scenario::StateModel& state,
|
||||||
|
container_widget* parent)
|
||||||
|
: bugui::container_widget{parent}
|
||||||
|
, model{state}
|
||||||
|
, skin{Process::Style::instance()}
|
||||||
|
{ }
|
||||||
|
|
||||||
|
int StateWidget::x() const
|
||||||
|
{
|
||||||
|
return parent->x();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StateWidget::y() const
|
||||||
|
{
|
||||||
|
return model.heightPercentage() * parent->height();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StateWidget::paint(bugui::painter& painter) const
|
||||||
|
{
|
||||||
|
// Copied from MiniscenarioView
|
||||||
|
const auto col = skin.IntervalBase().color();
|
||||||
|
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
||||||
|
|
||||||
|
painter.draw_line({x(), y()}, {x() + width(), y()});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StateWidget::contains(int px, int py) const
|
||||||
|
{
|
||||||
|
if (px >= x() &&
|
||||||
|
px <= (x() + width()) &&
|
||||||
|
py == y())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StateWidget::on_press(int x, int y, bool pressed)
|
||||||
|
{
|
||||||
|
if (!contains(x, y)) return false;
|
||||||
|
|
||||||
|
qDebug() << "is inside!";
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StateWidget::on_double_press(int x, int y)
|
||||||
|
{
|
||||||
|
if (!contains(x, y)) return false;
|
||||||
|
|
||||||
|
qDebug() << "double pressed !";
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
||||||
|
{
|
||||||
|
if (!contains(from_x, from_y)) return false;
|
||||||
|
|
||||||
|
if (from_y != to_y)
|
||||||
|
model.setHeightPercentage(to_y / static_cast<double>(parent->height()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Scenario::StateModel& StateWidget::get_model() const
|
||||||
|
{
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
Hardware/Widgets/StateWidget.hpp
Normal file
33
Hardware/Widgets/StateWidget.hpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Scenario/Document/State/StateModel.hpp>
|
||||||
|
#include <Process/Style/ScenarioStyle.hpp>
|
||||||
|
#include <widgets/container_widget.hpp>
|
||||||
|
|
||||||
|
namespace Hardware
|
||||||
|
{
|
||||||
|
struct StateWidget final : bugui::container_widget
|
||||||
|
{
|
||||||
|
explicit StateWidget(Scenario::StateModel& state,
|
||||||
|
container_widget* parent);
|
||||||
|
|
||||||
|
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;
|
||||||
|
bool on_drag(int from_x, int from_y, int to_x, int to_y) override;
|
||||||
|
|
||||||
|
int x() const override;
|
||||||
|
int y() const override;
|
||||||
|
|
||||||
|
const Scenario::StateModel& get_model() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool contains(int px, int py) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Scenario::StateModel& model;
|
||||||
|
const Process::Style& skin;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace Hardware
|
||||||
|
|
Loading…
Add table
Reference in a new issue