1
/***************************************************************************
2
* Copyright (C) 2012 by santiago González *
3
* santigoro@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, see <http://www.gnu.org/licenses/>. *
18
***************************************************************************/
21
#include "circuitwidget.h"
22
#include "connector.h"
23
#include "simulator.h"
26
static const char* LedBase_properties[] = {
27
QT_TRANSLATE_NOOP("App::Property","MaxCurrent"),
28
QT_TRANSLATE_NOOP("App::Property","Grounded")
31
LedBase::LedBase( QObject* parent, QString type, QString id )
32
: Component( parent, type, id )
35
Q_UNUSED( LedBase_properties );
38
m_overCurrent = false;
44
m_color = QColor( Qt::black );
47
m_valLabel->setEnabled( false );
48
m_valLabel->setVisible( false );
50
Simulator::self()->addToUpdateList( this );
52
LedBase::~LedBase() {}
54
void LedBase::initialize()
60
void LedBase::updateStep()
62
uint bright = m_bright;
65
if( m_bright > 255+75 )
73
m_overCurrent = !m_overCurrent;
77
else if( m_overCurrent )
79
m_overCurrent = false;
83
else if( bright != m_bright ) update();
86
bool LedBase::grounded()
91
void LedBase::setGrounded( bool grounded )
93
if( grounded == m_grounded ) return;
95
if( Simulator::self()->isRunning() ) CircuitWidget::self()->powerCircOff();
99
Pin* pin1 = (static_cast<Pin*>(m_ePin[1]));
100
if( m_ePin[1]->isConnected() ) pin1->connector()->remove();
101
pin1->setEnabled( false );
102
pin1->setVisible( false );
106
m_scrEnode = new eNode( m_id+"Gnod" );
107
m_scrEnode->setNodeNumber(0);
108
Simulator::self()->remFromEnodeList( m_scrEnode, /*delete=*/ false );
110
m_ePin[1]->setEnode( m_scrEnode );
114
Pin* pin1 = (static_cast<Pin*>(m_ePin[1]));
116
pin1->setEnabled( true );
117
pin1->setVisible( true );
119
m_ePin[1]->setEnode( 0l );
121
m_grounded = grounded;
124
void LedBase::remove()
126
if( m_grounded ) m_ePin[1]->setEnode( 0l );
127
//if( m_scrEnode ) delete m_scrEnode;
128
Simulator::self()->remFromUpdateList( this );
133
void LedBase::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget )
135
Component::paint( p, option, widget );
137
QPen pen(Qt::black, 4, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
141
if( m_overCurrent ) // Max Current
144
p->setBrush( Qt::white );
145
color = QColor( Qt::white );
146
pen.setColor( color );
154
m_bright += 15; // Set a Minimun Bright
158
overBight += m_bright-255;
163
color = QColor( m_bright, m_bright, overBight ); // Default = yellow
165
if ( m_ledColor == red ) color = QColor( m_bright, m_bright/3, overBight );
166
else if( m_ledColor == green ) color = QColor( overBight, m_bright, m_bright*2/3 );
167
else if( m_ledColor == blue ) color = QColor( overBight, m_bright/2, m_bright );
168
else if( m_ledColor == orange ) color = QColor( m_bright, m_bright*2/3, overBight );
169
else if( m_ledColor == purple ) color = QColor( m_bright, overBight, m_bright*2/3 );
174
pen.setColor( color );
177
p->setBrush( color );
182
#include "moc_ledbase.cpp"