Skip to content

Commit

Permalink
Assign triggers to inputs and add labels to 7 segment displays.
Browse files Browse the repository at this point in the history
  • Loading branch information
lellisls committed Mar 1, 2016
1 parent f1dce8a commit d3938e3
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 210 deletions.
21 changes: 21 additions & 0 deletions app/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QMimeData>
#include <QSettings>
#include <QtMath>
#include <input.h>
#include <iostream>
#include <nodes/qneconnection.h>

Expand Down Expand Up @@ -697,12 +698,32 @@ bool Editor::eventFilter( QObject *obj, QEvent *evt ) {
if( keyEvt && ( keyEvt->key( ) == Qt::Key_Control ) ) {
mControlKeyPressed = true;
}
else {
for( GraphicElement *elm : scene->getElements( ) ) {
if( elm->hasTrigger( ) && !elm->getTrigger( ).isEmpty( ) ) {
Input *in = dynamic_cast< Input* >( elm );
if( in && elm->getTrigger( ).matches( keyEvt->key( ) ) ) {
in->setOn( true );
}
}
}
}
break;
}
case QEvent::KeyRelease: {
if( keyEvt && ( keyEvt->key( ) == Qt::Key_Control ) ) {
mControlKeyPressed = false;
}
else {
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 );
}
}
}
}
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions app/element/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Display::Display(QGraphicsItem * parent) : GraphicElement(8,8,0,0,parent) {
updatePorts();
setBottomPosition(58);
setTopPosition(6);
setHasLabel(true);

setPixmap(QPixmap(":/output/counter/counter_off.png"));
a = QPixmap(":/output/counter/counter_a.png");
Expand Down
12 changes: 12 additions & 0 deletions app/element/input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef INPUT_H
#define INPUT_H


class Input {
public:
virtual bool getOn( ) const = 0;
virtual void setOn( bool value ) = 0;

};

#endif /* INPUT_H */
67 changes: 41 additions & 26 deletions app/element/inputbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,57 @@

#include <QDebug>
#include <QGraphicsSceneMouseEvent>
InputButton::InputButton(QGraphicsItem * parent) : GraphicElement(0,0,1,1,parent) {
setOutputsOnTop(false);
setPixmap(QPixmap(":/input/buttonOff.png"));
setRotatable(false);
outputs().first()->setValue(0);
on = false;
setHasLabel(true);
setObjectName("Button");
InputButton::InputButton( QGraphicsItem *parent ) : GraphicElement( 0, 0, 1, 1, parent ) {
setOutputsOnTop( false );
setPixmap( QPixmap( ":/input/buttonOff.png" ) );
setRotatable( false );
outputs( ).first( )->setValue( 0 );
setOn( false );
setHasLabel( true );
setHasTrigger( true );
setObjectName( "Button" );
}

InputButton::~InputButton() {
InputButton::~InputButton( ) {

}

void InputButton::mousePressEvent(QGraphicsSceneMouseEvent * event) {
if(event->button() == Qt::LeftButton) {
setPixmap(QPixmap(":/input/buttonOn.png"));
on = true;
setChanged(true);
event->accept();
void InputButton::mousePressEvent( QGraphicsSceneMouseEvent *event ) {
if( event->button( ) == Qt::LeftButton ) {
setOn( true );
setChanged( true );
event->accept( );
}
QGraphicsItem::mousePressEvent(event);
QGraphicsItem::mousePressEvent( event );
}

void InputButton::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
if(event->button() == Qt::LeftButton) {
setPixmap(QPixmap(":/input/buttonOff.png"));
on = false;
setChanged(true);
event->accept();
void InputButton::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) {
if( event->button( ) == Qt::LeftButton ) {

setOn( false );
setChanged( true );
event->accept( );
}
GraphicElement::mouseReleaseEvent( event );
}

void InputButton::updateLogic( ) {
if( !disabled( ) ) {
outputs( ).first( )->setValue( on );
}
GraphicElement::mouseReleaseEvent(event);
}

void InputButton::updateLogic() {
if(!disabled()){
outputs().first()->setValue(on);
bool InputButton::getOn( ) const {
return( on );
}

void InputButton::setOn( bool value ) {
on = value;
if( on ) {
setPixmap( QPixmap( ":/input/buttonOn.png" ) );
}
else {
setPixmap( QPixmap( ":/input/buttonOff.png" ) );
}
updateLogic( );
}
34 changes: 20 additions & 14 deletions app/element/inputbutton.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
#ifndef INPUT_H
#define INPUT_H
#ifndef INPUTBUTTON_H
#define INPUTBUTTON_H

#include "graphicelement.h"
#include "input.h"

class InputButton : public GraphicElement {
class InputButton : public GraphicElement, public Input {
public:
explicit InputButton(QGraphicsItem * parent);
virtual ~InputButton();
explicit InputButton( QGraphicsItem *parent );
virtual ~InputButton( );
bool on;

// QGraphicsItem interface
/* QGraphicsItem interface */
protected:
void mousePressEvent(QGraphicsSceneMouseEvent * event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
void mousePressEvent( QGraphicsSceneMouseEvent *event );
void mouseReleaseEvent( QGraphicsSceneMouseEvent *event );

// GraphicElement interface
public:
virtual ElementType elementType() {
return ElementType::BUTTON;
/* GraphicElement interface */
public:
virtual ElementType elementType( ) {
return( ElementType::BUTTON );
}
void updateLogic();
void updateLogic( );

// Input interface
public:
bool getOn() const;
void setOn(bool value);
};

#endif // INPUT_H
#endif /* INPUTBUTTON_H */
2 changes: 2 additions & 0 deletions app/element/inputswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ InputSwitch::InputSwitch( QGraphicsItem *parent ) : GraphicElement( 0, 0, 1, 1,
setPixmap( QPixmap( ":/input/switchOff.png" ) );
on = false;
setHasLabel( true );
setHasTrigger( true );
setObjectName( "Switch" );
}

Expand All @@ -21,6 +22,7 @@ bool InputSwitch::getOn( ) const {

void InputSwitch::setOn( bool value ) {
on = value;
updateLogic();
}

void InputSwitch::mousePressEvent( QGraphicsSceneMouseEvent *event ) {
Expand Down
7 changes: 4 additions & 3 deletions app/element/inputswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#define INPUTSWITCH_H

#include "graphicelement.h"
#include "input.h"

class InputSwitch : public GraphicElement {
class InputSwitch : public GraphicElement, public Input {
public:
explicit InputSwitch( QGraphicsItem *parent = 0);
virtual ~InputSwitch( );
Expand All @@ -25,8 +26,8 @@ class InputSwitch : public GraphicElement {
public:
void save( QDataStream &ds );
void load( QDataStream &ds, QMap< quint64, QNEPort* > &portMap, double version );
bool getOn( ) const;
void setOn( bool value );
virtual bool getOn( ) const;
virtual void setOn( bool value );
};

#endif /* INPUTSWITCH_H */
25 changes: 23 additions & 2 deletions app/elementeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ ElementEditor::ElementEditor( QWidget *parent ) : QWidget( parent ), ui( new Ui:
ui->setupUi( this );
setEnabled( false );
setVisible( false );

ui->trigger->addItem( QString( tr( "None" ) ) );
for( int i = 0; i < 5; i++ ) {
ui->trigger->addItem( QKeySequence( QString( "%1" ).arg( i ) ).toString( ) );
}
for( char i = 'A'; i < 'F'; i++ ) {
ui->trigger->addItem( QKeySequence( QString( "%1" ).arg( i ) ).toString( ) );
}
}

ElementEditor::~ElementEditor( ) {
Expand Down Expand Up @@ -52,10 +60,16 @@ void ElementEditor::setCurrentElement( GraphicElement *elm ) {
ui->comboBoxInputSz->setCurrentText( inputSz );
hasSomething |= ( ui->comboBoxInputSz->count( ) >= 2 );
/* Trigger */
ui->keySequenceEdit->setVisible( element->hasTrigger( ) );
ui->trigger->setVisible( element->hasTrigger( ) );
ui->label_trigger->setVisible( element->hasTrigger( ) );

ui->trigger->setCurrentIndex( 0 );
if( element->hasTrigger( ) ) {
ui->trigger->setCurrentText( element->getTrigger( ).toString( ) );
}
hasSomething |= ( element->hasTrigger( ) );
setEnabled( true );
setEnabled( hasSomething );
setVisible( hasSomething );
}
else {
setVisible( false );
Expand Down Expand Up @@ -99,6 +113,9 @@ void ElementEditor::apply( ) {
if( element->hasFrequency( ) ) {
element->setFrequency( ui->doubleSpinBoxFrequency->value( ) );
}
if( element->hasTrigger( ) ) {
element->setTrigger( QKeySequence( ui->trigger->currentText() ) );
}
emit elementUpdated( element, itemData );
}

Expand All @@ -119,3 +136,7 @@ void ElementEditor::on_comboBoxColor_currentIndexChanged( int index ) {
Q_UNUSED( index );
apply( );
}

void ElementEditor::on_trigger_currentIndexChanged(const QString &){
apply();
}
2 changes: 2 additions & 0 deletions app/elementeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ private slots:

void on_comboBoxColor_currentIndexChanged(int index);

void on_trigger_currentIndexChanged(const QString &arg1);

private:
void setCurrentElement( GraphicElement *element );
void apply();
Expand Down
78 changes: 39 additions & 39 deletions app/elementeditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,40 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QComboBox" name="comboBoxInputSz"/>
<item row="5" column="0">
<widget class="QDoubleSpinBox" name="doubleSpinBoxFrequency">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.500000000000000</double>
</property>
<property name="maximum">
<double>30.000000000000000</double>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_color">
<item row="4" column="0">
<widget class="QLabel" name="label_frequency">
<property name="text">
<string>Color:</string>
<string>Frequency:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="lineEditElementLabel"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_trigger">
<property name="text">
<string>Trigger</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_inputs">
<property name="text">
<string>Input Ports:</string>
</property>
</widget>
</item>
Expand All @@ -31,12 +58,6 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QKeySequenceEdit" name="keySequenceEdit"/>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="lineEditElementLabel"/>
</item>
<item row="7" column="0">
<widget class="QComboBox" name="comboBoxColor">
<item>
Expand Down Expand Up @@ -96,39 +117,18 @@
</item>
</widget>
</item>
<item row="5" column="0">
<widget class="QDoubleSpinBox" name="doubleSpinBoxFrequency">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.500000000000000</double>
</property>
<property name="maximum">
<double>30.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_frequency">
<property name="text">
<string>Frequency:</string>
</property>
</widget>
<item row="3" column="0">
<widget class="QComboBox" name="comboBoxInputSz"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_inputs">
<item row="6" column="0">
<widget class="QLabel" name="label_color">
<property name="text">
<string>Input Ports:</string>
<string>Color:</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_trigger">
<property name="text">
<string>Trigger</string>
</property>
</widget>
<item row="9" column="0">
<widget class="QComboBox" name="trigger"/>
</item>
</layout>
</widget>
Expand Down
Loading

0 comments on commit d3938e3

Please sign in to comment.