83 lines
1.9 KiB
C++
83 lines
1.9 KiB
C++
#include <Scenario/Document/State/StateModel.hpp>
|
|
|
|
#include "ScenarioWidget.hpp"
|
|
#include "EventWidget.hpp"
|
|
#include "StateWidget.hpp"
|
|
|
|
namespace Hardware
|
|
{
|
|
StateWidget::StateWidget(Scenario::StateModel& state,
|
|
ScenarioWidget* scenario,
|
|
bugui::container_widget* parent)
|
|
: ScenarioComponentSpec<Scenario::StateModel>{state, scenario, parent}
|
|
{
|
|
connect(&model,
|
|
&Scenario::StateModel::heightPercentageChanged,
|
|
this,
|
|
&StateWidget::set_y);
|
|
|
|
set_y();
|
|
}
|
|
|
|
StateWidget::~StateWidget()
|
|
{
|
|
// disconnect(&model,
|
|
// &Scenario::StateModel::heightPercentageChanged,
|
|
// this,
|
|
// &StateWidget::set_y);
|
|
}
|
|
|
|
int StateWidget::y() const
|
|
{
|
|
return m_y;
|
|
}
|
|
|
|
void StateWidget::paint(bugui::painter& painter) const
|
|
{
|
|
const auto col = skin.StateDot().color();
|
|
painter.set_color(col.red(), col.green(), col.blue(), col.alpha());
|
|
|
|
painter.draw_cell(0, 0);
|
|
}
|
|
|
|
bool StateWidget::contains(int px, int py) const
|
|
{
|
|
if (px == x() && py == y())
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
void StateWidget::on_press(int x, int y, bool pressed)
|
|
{
|
|
qDebug() << "is inside!";
|
|
}
|
|
|
|
void StateWidget::on_double_press(int x, int y)
|
|
{
|
|
qDebug() << "double pressed !";
|
|
}
|
|
|
|
void StateWidget::on_drag(int from_x, int from_y, int to_x, int to_y)
|
|
{
|
|
double increment{to_y / static_cast<double>(scenario->height())};
|
|
model.setHeightPercentage(model.heightPercentage() + increment);
|
|
}
|
|
|
|
void StateWidget::set_y()
|
|
{
|
|
static_cast<EventWidget*>(bugui::base_widget::parent)->set_y_height(
|
|
model.heightPercentage() * scenario->height());
|
|
|
|
// FIXME : this seems very dirty !
|
|
m_y = model.heightPercentage() * scenario->height() -
|
|
bugui::base_widget::parent->get_parent()->y() -
|
|
bugui::base_widget::parent->y();
|
|
|
|
update();
|
|
}
|
|
|
|
} // namespace Hardware
|
|
|
|
#include <wobjectimpl.h>
|
|
W_OBJECT_IMPL(Hardware::StateWidget)
|