Skip to content

Commit

Permalink
Switch input triggers.
Browse files Browse the repository at this point in the history
  • Loading branch information
lellisls committed Mar 1, 2016
1 parent 6bf92ae commit d428f69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
13 changes: 10 additions & 3 deletions app/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,12 @@ bool Editor::eventFilter( QObject *obj, QEvent *evt ) {
if( elm->hasTrigger( ) && !elm->getTrigger( ).isEmpty( ) ) {
Input *in = dynamic_cast< Input* >( elm );
if( in && elm->getTrigger( ).matches( keyEvt->key( ) ) ) {
in->setOn( true );
if( elm->elementType( ) == ElementType::SWITCH ) {
in->setOn( !in->getOn( ) );
}
else {
in->setOn( true );
}
}
}
}
Expand All @@ -718,8 +723,10 @@ bool Editor::eventFilter( QObject *obj, QEvent *evt ) {
for( GraphicElement *elm : scene->getElements( ) ) {
if( elm->hasTrigger( ) && !elm->getTrigger( ).isEmpty( ) ) {
Input *in = dynamic_cast< Input* >( elm );
if( in && elm->getTrigger( ).matches( keyEvt->key( ) ) == QKeySequence::ExactMatch ) {
in->setOn( false );
if( in && ( elm->getTrigger( ).matches( keyEvt->key( ) ) == QKeySequence::ExactMatch ) ) {
if( elm->elementType( ) != ElementType::SWITCH ) {
in->setOn( false );
}
}
}
}
Expand Down
17 changes: 8 additions & 9 deletions app/element/inputswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ bool InputSwitch::getOn( ) const {

void InputSwitch::setOn( bool value ) {
on = value;
updateLogic();
updateLogic( );
if( on ) {
setPixmap( QPixmap( ":/input/switchOn.png" ) );
}
else {
setPixmap( QPixmap( ":/input/switchOff.png" ) );
}
}

void InputSwitch::mousePressEvent( QGraphicsSceneMouseEvent *event ) {
if( event->button( ) == Qt::LeftButton ) {
if( on ) {
on = false;
setPixmap( QPixmap( ":/input/switchOff.png" ) );
}
else {
on = true;
setPixmap( QPixmap( ":/input/switchOn.png" ) );
}
setOn( !on );
setChanged( true );
event->accept( );
}
Expand Down

0 comments on commit d428f69

Please sign in to comment.