Skip to content

Commit d3938e3

Browse files
committed
Assign triggers to inputs and add labels to 7 segment displays.
1 parent f1dce8a commit d3938e3

14 files changed

+318
-210
lines changed

app/editor.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QMimeData>
2121
#include <QSettings>
2222
#include <QtMath>
23+
#include <input.h>
2324
#include <iostream>
2425
#include <nodes/qneconnection.h>
2526

@@ -697,12 +698,32 @@ bool Editor::eventFilter( QObject *obj, QEvent *evt ) {
697698
if( keyEvt && ( keyEvt->key( ) == Qt::Key_Control ) ) {
698699
mControlKeyPressed = true;
699700
}
701+
else {
702+
for( GraphicElement *elm : scene->getElements( ) ) {
703+
if( elm->hasTrigger( ) && !elm->getTrigger( ).isEmpty( ) ) {
704+
Input *in = dynamic_cast< Input* >( elm );
705+
if( in && elm->getTrigger( ).matches( keyEvt->key( ) ) ) {
706+
in->setOn( true );
707+
}
708+
}
709+
}
710+
}
700711
break;
701712
}
702713
case QEvent::KeyRelease: {
703714
if( keyEvt && ( keyEvt->key( ) == Qt::Key_Control ) ) {
704715
mControlKeyPressed = false;
705716
}
717+
else {
718+
for( GraphicElement *elm : scene->getElements( ) ) {
719+
if( elm->hasTrigger( ) && !elm->getTrigger( ).isEmpty( ) ) {
720+
Input *in = dynamic_cast< Input* >( elm );
721+
if( in && elm->getTrigger( ).matches( keyEvt->key( ) ) == QKeySequence::ExactMatch ) {
722+
in->setOn( false );
723+
}
724+
}
725+
}
726+
}
706727
break;
707728
}
708729
}

app/element/display.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Display::Display(QGraphicsItem * parent) : GraphicElement(8,8,0,0,parent) {
1010
updatePorts();
1111
setBottomPosition(58);
1212
setTopPosition(6);
13+
setHasLabel(true);
1314

1415
setPixmap(QPixmap(":/output/counter/counter_off.png"));
1516
a = QPixmap(":/output/counter/counter_a.png");

app/element/input.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef INPUT_H
2+
#define INPUT_H
3+
4+
5+
class Input {
6+
public:
7+
virtual bool getOn( ) const = 0;
8+
virtual void setOn( bool value ) = 0;
9+
10+
};
11+
12+
#endif /* INPUT_H */

app/element/inputbutton.cpp

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,57 @@
22

33
#include <QDebug>
44
#include <QGraphicsSceneMouseEvent>
5-
InputButton::InputButton(QGraphicsItem * parent) : GraphicElement(0,0,1,1,parent) {
6-
setOutputsOnTop(false);
7-
setPixmap(QPixmap(":/input/buttonOff.png"));
8-
setRotatable(false);
9-
outputs().first()->setValue(0);
10-
on = false;
11-
setHasLabel(true);
12-
setObjectName("Button");
5+
InputButton::InputButton( QGraphicsItem *parent ) : GraphicElement( 0, 0, 1, 1, parent ) {
6+
setOutputsOnTop( false );
7+
setPixmap( QPixmap( ":/input/buttonOff.png" ) );
8+
setRotatable( false );
9+
outputs( ).first( )->setValue( 0 );
10+
setOn( false );
11+
setHasLabel( true );
12+
setHasTrigger( true );
13+
setObjectName( "Button" );
1314
}
1415

15-
InputButton::~InputButton() {
16+
InputButton::~InputButton( ) {
1617

1718
}
1819

19-
void InputButton::mousePressEvent(QGraphicsSceneMouseEvent * event) {
20-
if(event->button() == Qt::LeftButton) {
21-
setPixmap(QPixmap(":/input/buttonOn.png"));
22-
on = true;
23-
setChanged(true);
24-
event->accept();
20+
void InputButton::mousePressEvent( QGraphicsSceneMouseEvent *event ) {
21+
if( event->button( ) == Qt::LeftButton ) {
22+
setOn( true );
23+
setChanged( true );
24+
event->accept( );
2525
}
26-
QGraphicsItem::mousePressEvent(event);
26+
QGraphicsItem::mousePressEvent( event );
2727
}
2828

29-
void InputButton::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) {
30-
if(event->button() == Qt::LeftButton) {
31-
setPixmap(QPixmap(":/input/buttonOff.png"));
32-
on = false;
33-
setChanged(true);
34-
event->accept();
29+
void InputButton::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) {
30+
if( event->button( ) == Qt::LeftButton ) {
31+
32+
setOn( false );
33+
setChanged( true );
34+
event->accept( );
35+
}
36+
GraphicElement::mouseReleaseEvent( event );
37+
}
38+
39+
void InputButton::updateLogic( ) {
40+
if( !disabled( ) ) {
41+
outputs( ).first( )->setValue( on );
3542
}
36-
GraphicElement::mouseReleaseEvent(event);
3743
}
3844

39-
void InputButton::updateLogic() {
40-
if(!disabled()){
41-
outputs().first()->setValue(on);
45+
bool InputButton::getOn( ) const {
46+
return( on );
47+
}
48+
49+
void InputButton::setOn( bool value ) {
50+
on = value;
51+
if( on ) {
52+
setPixmap( QPixmap( ":/input/buttonOn.png" ) );
53+
}
54+
else {
55+
setPixmap( QPixmap( ":/input/buttonOff.png" ) );
4256
}
57+
updateLogic( );
4358
}

app/element/inputbutton.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
#ifndef INPUT_H
2-
#define INPUT_H
1+
#ifndef INPUTBUTTON_H
2+
#define INPUTBUTTON_H
33

44
#include "graphicelement.h"
5+
#include "input.h"
56

6-
class InputButton : public GraphicElement {
7+
class InputButton : public GraphicElement, public Input {
78
public:
8-
explicit InputButton(QGraphicsItem * parent);
9-
virtual ~InputButton();
9+
explicit InputButton( QGraphicsItem *parent );
10+
virtual ~InputButton( );
1011
bool on;
1112

12-
// QGraphicsItem interface
13+
/* QGraphicsItem interface */
1314
protected:
14-
void mousePressEvent(QGraphicsSceneMouseEvent * event);
15-
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
15+
void mousePressEvent( QGraphicsSceneMouseEvent *event );
16+
void mouseReleaseEvent( QGraphicsSceneMouseEvent *event );
1617

17-
// GraphicElement interface
18-
public:
19-
virtual ElementType elementType() {
20-
return ElementType::BUTTON;
18+
/* GraphicElement interface */
19+
public:
20+
virtual ElementType elementType( ) {
21+
return( ElementType::BUTTON );
2122
}
22-
void updateLogic();
23+
void updateLogic( );
24+
25+
// Input interface
26+
public:
27+
bool getOn() const;
28+
void setOn(bool value);
2329
};
2430

25-
#endif // INPUT_H
31+
#endif /* INPUTBUTTON_H */

app/element/inputswitch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ InputSwitch::InputSwitch( QGraphicsItem *parent ) : GraphicElement( 0, 0, 1, 1,
88
setPixmap( QPixmap( ":/input/switchOff.png" ) );
99
on = false;
1010
setHasLabel( true );
11+
setHasTrigger( true );
1112
setObjectName( "Switch" );
1213
}
1314

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

2223
void InputSwitch::setOn( bool value ) {
2324
on = value;
25+
updateLogic();
2426
}
2527

2628
void InputSwitch::mousePressEvent( QGraphicsSceneMouseEvent *event ) {

app/element/inputswitch.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#define INPUTSWITCH_H
33

44
#include "graphicelement.h"
5+
#include "input.h"
56

6-
class InputSwitch : public GraphicElement {
7+
class InputSwitch : public GraphicElement, public Input {
78
public:
89
explicit InputSwitch( QGraphicsItem *parent = 0);
910
virtual ~InputSwitch( );
@@ -25,8 +26,8 @@ class InputSwitch : public GraphicElement {
2526
public:
2627
void save( QDataStream &ds );
2728
void load( QDataStream &ds, QMap< quint64, QNEPort* > &portMap, double version );
28-
bool getOn( ) const;
29-
void setOn( bool value );
29+
virtual bool getOn( ) const;
30+
virtual void setOn( bool value );
3031
};
3132

3233
#endif /* INPUTSWITCH_H */

app/elementeditor.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ ElementEditor::ElementEditor( QWidget *parent ) : QWidget( parent ), ui( new Ui:
77
ui->setupUi( this );
88
setEnabled( false );
99
setVisible( false );
10+
11+
ui->trigger->addItem( QString( tr( "None" ) ) );
12+
for( int i = 0; i < 5; i++ ) {
13+
ui->trigger->addItem( QKeySequence( QString( "%1" ).arg( i ) ).toString( ) );
14+
}
15+
for( char i = 'A'; i < 'F'; i++ ) {
16+
ui->trigger->addItem( QKeySequence( QString( "%1" ).arg( i ) ).toString( ) );
17+
}
1018
}
1119

1220
ElementEditor::~ElementEditor( ) {
@@ -52,10 +60,16 @@ void ElementEditor::setCurrentElement( GraphicElement *elm ) {
5260
ui->comboBoxInputSz->setCurrentText( inputSz );
5361
hasSomething |= ( ui->comboBoxInputSz->count( ) >= 2 );
5462
/* Trigger */
55-
ui->keySequenceEdit->setVisible( element->hasTrigger( ) );
63+
ui->trigger->setVisible( element->hasTrigger( ) );
5664
ui->label_trigger->setVisible( element->hasTrigger( ) );
65+
66+
ui->trigger->setCurrentIndex( 0 );
67+
if( element->hasTrigger( ) ) {
68+
ui->trigger->setCurrentText( element->getTrigger( ).toString( ) );
69+
}
5770
hasSomething |= ( element->hasTrigger( ) );
58-
setEnabled( true );
71+
setEnabled( hasSomething );
72+
setVisible( hasSomething );
5973
}
6074
else {
6175
setVisible( false );
@@ -99,6 +113,9 @@ void ElementEditor::apply( ) {
99113
if( element->hasFrequency( ) ) {
100114
element->setFrequency( ui->doubleSpinBoxFrequency->value( ) );
101115
}
116+
if( element->hasTrigger( ) ) {
117+
element->setTrigger( QKeySequence( ui->trigger->currentText() ) );
118+
}
102119
emit elementUpdated( element, itemData );
103120
}
104121

@@ -119,3 +136,7 @@ void ElementEditor::on_comboBoxColor_currentIndexChanged( int index ) {
119136
Q_UNUSED( index );
120137
apply( );
121138
}
139+
140+
void ElementEditor::on_trigger_currentIndexChanged(const QString &){
141+
apply();
142+
}

app/elementeditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ private slots:
3333

3434
void on_comboBoxColor_currentIndexChanged(int index);
3535

36+
void on_trigger_currentIndexChanged(const QString &arg1);
37+
3638
private:
3739
void setCurrentElement( GraphicElement *element );
3840
void apply();

app/elementeditor.ui

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,40 @@
1414
<string>Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="3" column="0">
18-
<widget class="QComboBox" name="comboBoxInputSz"/>
17+
<item row="5" column="0">
18+
<widget class="QDoubleSpinBox" name="doubleSpinBoxFrequency">
19+
<property name="decimals">
20+
<number>1</number>
21+
</property>
22+
<property name="minimum">
23+
<double>0.500000000000000</double>
24+
</property>
25+
<property name="maximum">
26+
<double>30.000000000000000</double>
27+
</property>
28+
</widget>
1929
</item>
20-
<item row="6" column="0">
21-
<widget class="QLabel" name="label_color">
30+
<item row="4" column="0">
31+
<widget class="QLabel" name="label_frequency">
2232
<property name="text">
23-
<string>Color:</string>
33+
<string>Frequency:</string>
34+
</property>
35+
</widget>
36+
</item>
37+
<item row="1" column="0">
38+
<widget class="QLineEdit" name="lineEditElementLabel"/>
39+
</item>
40+
<item row="8" column="0">
41+
<widget class="QLabel" name="label_trigger">
42+
<property name="text">
43+
<string>Trigger</string>
44+
</property>
45+
</widget>
46+
</item>
47+
<item row="2" column="0">
48+
<widget class="QLabel" name="label_inputs">
49+
<property name="text">
50+
<string>Input Ports:</string>
2451
</property>
2552
</widget>
2653
</item>
@@ -31,12 +58,6 @@
3158
</property>
3259
</widget>
3360
</item>
34-
<item row="9" column="0">
35-
<widget class="QKeySequenceEdit" name="keySequenceEdit"/>
36-
</item>
37-
<item row="1" column="0">
38-
<widget class="QLineEdit" name="lineEditElementLabel"/>
39-
</item>
4061
<item row="7" column="0">
4162
<widget class="QComboBox" name="comboBoxColor">
4263
<item>
@@ -96,39 +117,18 @@
96117
</item>
97118
</widget>
98119
</item>
99-
<item row="5" column="0">
100-
<widget class="QDoubleSpinBox" name="doubleSpinBoxFrequency">
101-
<property name="decimals">
102-
<number>1</number>
103-
</property>
104-
<property name="minimum">
105-
<double>0.500000000000000</double>
106-
</property>
107-
<property name="maximum">
108-
<double>30.000000000000000</double>
109-
</property>
110-
</widget>
111-
</item>
112-
<item row="4" column="0">
113-
<widget class="QLabel" name="label_frequency">
114-
<property name="text">
115-
<string>Frequency:</string>
116-
</property>
117-
</widget>
120+
<item row="3" column="0">
121+
<widget class="QComboBox" name="comboBoxInputSz"/>
118122
</item>
119-
<item row="2" column="0">
120-
<widget class="QLabel" name="label_inputs">
123+
<item row="6" column="0">
124+
<widget class="QLabel" name="label_color">
121125
<property name="text">
122-
<string>Input Ports:</string>
126+
<string>Color:</string>
123127
</property>
124128
</widget>
125129
</item>
126-
<item row="8" column="0">
127-
<widget class="QLabel" name="label_trigger">
128-
<property name="text">
129-
<string>Trigger</string>
130-
</property>
131-
</widget>
130+
<item row="9" column="0">
131+
<widget class="QComboBox" name="trigger"/>
132132
</item>
133133
</layout>
134134
</widget>

0 commit comments

Comments
 (0)