eccapacitor.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "capacitance.h"
00012 #include "eccapacitor.h"
00013 #include "ecnode.h"
00014 #include "libraryitem.h"
00015 
00016 #include <klocale.h>
00017 #include <qpainter.h>
00018 
00019 Item* ECCapacitor::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00020 {
00021         return new ECCapacitor( (ICNDocument*)itemDocument, newItem, id );
00022 }
00023 
00024 LibraryItem* ECCapacitor::libraryItem()
00025 {
00026         return new LibraryItem(
00027                 "ec/capacitor",
00028                 i18n("Capacitor"),
00029                 i18n("Discrete"),
00030                 "capacitor.png",
00031                 LibraryItem::lit_component,
00032                 ECCapacitor::construct
00033                         );
00034 }
00035 
00036 ECCapacitor::ECCapacitor( ICNDocument *icnDocument, bool newItem, const char *id )
00037         : Component( icnDocument, newItem, id ? id : "capacitor" )
00038 {
00039         m_name = i18n("Capacitor");
00040         m_desc = i18n("Stores electrical charge.<br><br>"
00041                                    "The voltage across the capacitor and capacitance are related by <i>Charge = Capacitance x Voltage</i>.");
00042         setSize( -8, -8, 16, 16 );
00043         
00044         init1PinLeft();
00045         init1PinRight();
00046         
00047         m_capacitance = createCapacitance( m_pNNode[0], m_pPNode[0], 0.001 );
00048         
00049         createProperty( "Capacitance", Variant::Type::Double );
00050         property("Capacitance")->setCaption( i18n("Capacitance") );
00051         property("Capacitance")->setUnit("F");
00052         property("Capacitance")->setMinValue(1e-12);
00053         property("Capacitance")->setMaxValue(1e12);
00054         property("Capacitance")->setValue(1e-3);
00055         
00056         addDisplayText( "capacitance", QRect( -8, -24, 16, 16 ), "", false );
00057 }
00058 
00059 ECCapacitor::~ECCapacitor()
00060 {
00061 }
00062 
00063 void ECCapacitor::dataChanged()
00064 {
00065         double capacitance = dataDouble("Capacitance");
00066         
00067         QString display = QString::number( capacitance / getMultiplier(capacitance), 'g', 3 ) + getNumberMag(capacitance) + "F";
00068         setDisplayText( "capacitance", display );
00069         
00070         m_capacitance->setCapacitance(capacitance);
00071 }
00072 
00073 void ECCapacitor::drawShape( QPainter &p )
00074 {
00075         initPainter(p);
00076         
00077         int _y = (int)y()-8;
00078         int _x = (int)x()-8;
00079         
00080         QPen pen;
00081         pen.setWidth(1);
00082         pen.setColor( p.pen().color() );
00083         p.setPen(pen);
00084         p.drawRect( _x, _y, 5, 16 );
00085         p.drawRect( _x+11, _y, 5, 16 );
00086         
00087         
00088         deinitPainter(p);
00089 //      p.drawPolyline( areaPoints() );
00090 }
00091 
00092 

Generated on Tue May 8 17:05:29 2007 for KTechLab by  doxygen 1.5.1