ecfixedvoltage.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2004 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 "ecfixedvoltage.h"
00012 
00013 #include "ecnode.h"
00014 #include "voltagepoint.h"
00015 #include "libraryitem.h"
00016 
00017 #include <klocale.h>
00018 #include <qpainter.h>
00019 
00020 Item* ECFixedVoltage::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00021 {
00022         return new ECFixedVoltage( (ICNDocument*)itemDocument, newItem, id );
00023 }
00024 LibraryItem* ECFixedVoltage::libraryItem()
00025 {
00026         return new LibraryItem(
00027                 "ec/fixed_voltage",
00028                 i18n("Fixed Voltage"),
00029                 i18n("Sources"),
00030                 "voltage.png",
00031                 LibraryItem::lit_component,
00032                 ECFixedVoltage::construct );
00033 }
00034 
00035 ECFixedVoltage::ECFixedVoltage( ICNDocument *icnDocument, bool newItem, const char *id )
00036         : Component( icnDocument, newItem, id ? id : "fixed_voltage" )
00037 {
00038         m_name = i18n("Fixed Voltage");
00039         m_desc = i18n("Provides a fixed voltage point to connect components to.");
00040         setSize( -8, -8, 16, 16 );
00041         
00042         init1PinRight();
00043         m_voltagePoint = createVoltagePoint( m_pPNode[0], 5.0 );
00044         
00045         addDisplayText( "voltage", QRect( -24, -20, width()+32, 12 ), "" );
00046         
00047         createProperty( "voltage", Variant::Type::Double );
00048         property("voltage")->setUnit("V");
00049         property("voltage")->setCaption( i18n("Voltage") );
00050         property("voltage")->setMinValue(-1e15);
00051         property("voltage")->setMaxValue(1e15);
00052         property("voltage")->setValue(5.0);
00053 }
00054 
00055 ECFixedVoltage::~ECFixedVoltage()
00056 {
00057 }
00058 
00059 void ECFixedVoltage::dataChanged()
00060 {
00061         const double voltage = dataDouble("voltage");
00062         QString display = QString::number( voltage / getMultiplier(voltage), 'g', 3 ) + getNumberMag(voltage) + "V";
00063         setDisplayText( "voltage", display );
00064         m_voltagePoint->setVoltage(voltage);
00065 }
00066 
00067 void ECFixedVoltage::drawShape( QPainter &p )
00068 {
00069         initPainter(p);
00070         int _x = int(x());
00071         int _y = int(y());
00072         p.drawEllipse( _x-4, _y-4, 8, 8 );
00073         p.setPen( m_pPNode[0]->isSelected() ? m_selectedCol : Qt::black );
00074         p.drawLine( _x+4, _y, _x+8, _y );
00075         deinitPainter(p);
00076 }
00077 

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