nx button: draw gray if not enabled

Dieser Commit ist enthalten in:
Reinder Feenstra 2023-11-05 16:37:15 +01:00
Ursprung 7b3da355d1
Commit 84ef8713cd
7 geänderte Dateien mit 69 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -162,6 +162,7 @@ void BoardAreaWidget::tileObjectAdded(int16_t x, int16_t y, const ObjectPtr& obj
break; break;
case TileId::RailNXButton: case TileId::RailNXButton:
tryConnect("enabled");
if(auto* nxButton = dynamic_cast<NXButtonRailTile*>(object.get())) /*[[likely]]*/ if(auto* nxButton = dynamic_cast<NXButtonRailTile*>(object.get())) /*[[likely]]*/
{ {
connect(nxButton, &NXButtonRailTile::isPressedChanged, this, handler); connect(nxButton, &NXButtonRailTile::isPressedChanged, this, handler);
@ -335,6 +336,15 @@ DecouplerState BoardAreaWidget::getDecouplerState(const TileLocation& l) const
return DecouplerState::Deactivated; return DecouplerState::Deactivated;
} }
bool BoardAreaWidget::getNXButtonEnabled(const TileLocation& l) const
{
if(auto object = std::dynamic_pointer_cast<NXButtonRailTile>(m_board.board().getTileObject(l)))
{
return object->getPropertyValueBool("enabled", false);
}
return false;
}
bool BoardAreaWidget::getNXButtonPressed(const TileLocation& l) const bool BoardAreaWidget::getNXButtonPressed(const TileLocation& l) const
{ {
if(auto object = std::dynamic_pointer_cast<NXButtonRailTile>(m_board.board().getTileObject(l))) if(auto object = std::dynamic_pointer_cast<NXButtonRailTile>(m_board.board().getTileObject(l)))
@ -585,7 +595,7 @@ void BoardAreaWidget::paintEvent(QPaintEvent* event)
break; break;
case TileId::RailNXButton: case TileId::RailNXButton:
tilePainter.drawRailNX(r, a, isReserved, getNXButtonPressed(it.first)); tilePainter.drawRailNX(r, a, isReserved, getNXButtonEnabled(it.first), getNXButtonPressed(it.first));
break; break;
case TileId::None: case TileId::None:

Datei anzeigen

@ -102,6 +102,7 @@ class BoardAreaWidget : public QWidget
SignalAspect getSignalAspect(const TileLocation& l) const; SignalAspect getSignalAspect(const TileLocation& l) const;
Color getColor(const TileLocation& l) const; Color getColor(const TileLocation& l) const;
DecouplerState getDecouplerState(const TileLocation& l) const; DecouplerState getDecouplerState(const TileLocation& l) const;
bool getNXButtonEnabled(const TileLocation& l) const;
bool getNXButtonPressed(const TileLocation& l) const; bool getNXButtonPressed(const TileLocation& l) const;
TileLocation pointToTileLocation(const QPoint& p); TileLocation pointToTileLocation(const QPoint& p);

Datei anzeigen

@ -394,11 +394,35 @@ BoardWidget::BoardWidget(std::shared_ptr<Board> object, QWidget* parent) :
m_statusBarCoords->setText(QString::number(x) + ", " + QString::number(y)); m_statusBarCoords->setText(QString::number(x) + ", " + QString::number(y));
const auto tileId = m_object->getTileId(tl); const auto tileId = m_object->getTileId(tl);
if((!m_toolbarEdit->isVisible() && (isRailTurnout(tileId) || isRailSignal(tileId) || tileId == TileId::RailDirectionControl || tileId == TileId::RailDecoupler || tileId == TileId::PushButton || tileId == TileId::RailNXButton)) || auto cursorShape = Qt::ArrowCursor;
(m_toolbarEdit->isVisible() && isActive(tileId) && m_editActions->checkedAction() == m_editActionNone))
setCursor(Qt::PointingHandCursor); if(m_toolbarEdit->isVisible()) // Edit mode
else {
setCursor(Qt::ArrowCursor); if(isActive(tileId) && m_editActions->checkedAction() == m_editActionNone)
{
cursorShape = Qt::PointingHandCursor;
}
}
else // Operate mode
{
if(isRailTurnout(tileId) ||
isRailSignal(tileId) ||
tileId == TileId::RailDirectionControl ||
tileId == TileId::RailDecoupler ||
tileId == TileId::PushButton)
{
cursorShape = Qt::PointingHandCursor;
}
else if(tileId == TileId::RailNXButton)
{
if(auto nxButton = m_object->getTileObject(tl); nxButton && nxButton->getPropertyValueBool("enabled", false))
{
cursorShape = Qt::PointingHandCursor;
}
}
}
setCursor(cursorShape);
} }
else else
m_statusBarCoords->setText(""); m_statusBarCoords->setText("");
@ -597,6 +621,11 @@ void BoardWidget::tileClicked(int16_t x, int16_t y)
{ {
if(auto nxButton = std::dynamic_pointer_cast<NXButtonRailTile>(obj)) /*[[likely]]*/ if(auto nxButton = std::dynamic_pointer_cast<NXButtonRailTile>(obj)) /*[[likely]]*/
{ {
if(!nxButton->getPropertyValueBool("enabled", false))
{
return; // not enabled, no action
}
if(nxButton->isPressed()) if(nxButton->isPressed())
{ {
releaseNXButton(nxButton); releaseNXButton(nxButton);

Datei anzeigen

@ -1289,9 +1289,9 @@ void TilePainter::drawRailDecoupler(const QRectF& r, TileRotate rotate, bool isR
m_painter.restore(); m_painter.restore();
} }
void TilePainter::drawRailNX(const QRectF& r, TileRotate rotate, bool isReserved, bool pressed) void TilePainter::drawRailNX(const QRectF& r, TileRotate rotate, bool isReserved, bool isEnabled, bool pressed)
{ {
setTrackPen(isReserved); setTrackPen(isReserved);
drawStraight(r, rotate); drawStraight(r, rotate);
drawPushButton(r, pressed ? Color::White : Color::Blue); drawPushButton(r, pressed ? Color::White : (isEnabled ? Color::Blue : Color::Gray));
} }

Datei anzeigen

@ -110,7 +110,7 @@ class TilePainter
void drawRailDecoupler(const QRectF& r, TileRotate rotate, bool isReserved = false, DecouplerState active = DecouplerState::Deactivated); void drawRailDecoupler(const QRectF& r, TileRotate rotate, bool isReserved = false, DecouplerState active = DecouplerState::Deactivated);
void drawRailNX(const QRectF& r, TileRotate rotate, bool isReserved = false, bool pressed = false); void drawRailNX(const QRectF& r, TileRotate rotate, bool isReserved = false, bool isEnabled = false, bool pressed = false);
}; };
#endif #endif

Datei anzeigen

@ -49,6 +49,7 @@ NXButtonRailTile::NXButtonRailTile(World& world, std::string_view id_)
: StraightRailTile(world, id_, TileId::RailNXButton) : StraightRailTile(world, id_, TileId::RailNXButton)
, m_node{*this, 2} , m_node{*this, 2}
, name{this, "name", std::string{id_}, PropertyFlags::ReadWrite | PropertyFlags::Store} , name{this, "name", std::string{id_}, PropertyFlags::ReadWrite | PropertyFlags::Store}
, enabled{this, "enabled", false, PropertyFlags::ReadOnly | PropertyFlags::NoStore}
, block{this, "block", nullptr, PropertyFlags::ReadOnly | PropertyFlags::NoStore} , block{this, "block", nullptr, PropertyFlags::ReadOnly | PropertyFlags::NoStore}
, input{this, "input", nullptr, PropertyFlags::ReadWrite | PropertyFlags::Store, nullptr, , input{this, "input", nullptr, PropertyFlags::ReadWrite | PropertyFlags::Store, nullptr,
[this](const std::shared_ptr<Input>& value) [this](const std::shared_ptr<Input>& value)
@ -70,6 +71,9 @@ NXButtonRailTile::NXButtonRailTile(World& world, std::string_view id_)
Attributes::addDisplayName(name, DisplayName::Object::name); Attributes::addDisplayName(name, DisplayName::Object::name);
m_interfaceItems.add(name); m_interfaceItems.add(name);
Attributes::addObjectEditor(enabled, false);
m_interfaceItems.add(enabled);
m_interfaceItems.add(block); m_interfaceItems.add(block);
Attributes::addEnabled(input, editable); Attributes::addEnabled(input, editable);
@ -91,6 +95,8 @@ void NXButtonRailTile::loaded()
if(input) if(input)
connectInput(*input); connectInput(*input);
updateEnabled();
} }
void NXButtonRailTile::destroying() void NXButtonRailTile::destroying()
@ -107,6 +113,8 @@ void NXButtonRailTile::worldEvent(WorldState worldState, WorldEvent worldEvent)
Attributes::setEnabled(name, editable); Attributes::setEnabled(name, editable);
Attributes::setEnabled(input, editable); Attributes::setEnabled(input, editable);
updateEnabled();
} }
void NXButtonRailTile::boardModified() void NXButtonRailTile::boardModified()
@ -132,6 +140,8 @@ void NXButtonRailTile::boardModified()
block.setValueInternal(nullptr); block.setValueInternal(nullptr);
Log::log(*this, LogMessage::W3002_NX_BUTTON_NOT_CONNECTED_TO_ANY_BLOCK); Log::log(*this, LogMessage::W3002_NX_BUTTON_NOT_CONNECTED_TO_ANY_BLOCK);
} }
updateEnabled();
} }
void NXButtonRailTile::connectInput(Input& object) void NXButtonRailTile::connectInput(Input& object)
@ -146,9 +156,9 @@ void NXButtonRailTile::connectInput(Input& object)
m_inputValueChanged = object.onValueChanged.connect( m_inputValueChanged = object.onValueChanged.connect(
[this](bool value, const std::shared_ptr<Input>& /*input*/) [this](bool value, const std::shared_ptr<Input>& /*input*/)
{ {
if(!block) if(!enabled)
{ {
return; // no block, no action return; // not enabled, no action
} }
if(value) if(value)
@ -168,3 +178,8 @@ void NXButtonRailTile::disconnectInput(Input& object)
m_inputDestroying.disconnect(); m_inputDestroying.disconnect();
object.consumers.removeInternal(shared_from_this()); object.consumers.removeInternal(shared_from_this());
} }
void NXButtonRailTile::updateEnabled()
{
enabled.setValueInternal(block && contains(m_world.state, WorldState::Run));
}

Datei anzeigen

@ -45,6 +45,8 @@ class NXButtonRailTile final : public StraightRailTile
void connectInput(Input& object); void connectInput(Input& object);
void disconnectInput(Input& object); void disconnectInput(Input& object);
void updateEnabled();
protected: protected:
void loaded() final; void loaded() final;
void destroying() final; void destroying() final;
@ -53,6 +55,7 @@ class NXButtonRailTile final : public StraightRailTile
public: public:
Property<std::string> name; Property<std::string> name;
Property<bool> enabled;
ObjectProperty<BlockRailTile> block; ObjectProperty<BlockRailTile> block;
ObjectProperty<Input> input; ObjectProperty<Input> input;