File indexing completed on 2024-05-19 09:39:03
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2004 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "ecfixedvoltage.h" 0012 0013 #include "ecnode.h" 0014 #include "libraryitem.h" 0015 #include "voltagepoint.h" 0016 0017 #include <KLocalizedString> 0018 #include <QPainter> 0019 0020 Item *ECFixedVoltage::construct(ItemDocument *itemDocument, bool newItem, const char *id) 0021 { 0022 return new ECFixedVoltage(static_cast<ICNDocument *>(itemDocument), newItem, id); 0023 } 0024 LibraryItem *ECFixedVoltage::libraryItem() 0025 { 0026 return new LibraryItem(QStringList(QString("ec/fixed_voltage")), i18n("Fixed Voltage"), i18n("Sources"), "voltage.png", LibraryItem::lit_component, ECFixedVoltage::construct); 0027 } 0028 0029 ECFixedVoltage::ECFixedVoltage(ICNDocument *icnDocument, bool newItem, const char *id) 0030 : Component(icnDocument, newItem, id ? id : "fixed_voltage") 0031 { 0032 m_name = i18n("Fixed Voltage"); 0033 setSize(-8, -8, 16, 16); 0034 0035 init1PinRight(); 0036 m_pPNode[0]->setLength(11); 0037 m_voltagePoint = createVoltagePoint(m_pPNode[0], 5.0); 0038 0039 addDisplayText("voltage", QRect(-24, -20, width() + 32, 12), ""); 0040 0041 createProperty("voltage", Variant::Type::Double); 0042 property("voltage")->setUnit("V"); 0043 property("voltage")->setCaption(i18n("Voltage")); 0044 property("voltage")->setMinValue(-1e15); 0045 property("voltage")->setMaxValue(1e15); 0046 property("voltage")->setValue(5.0); 0047 } 0048 0049 ECFixedVoltage::~ECFixedVoltage() 0050 { 0051 } 0052 0053 void ECFixedVoltage::dataChanged() 0054 { 0055 const double voltage = dataDouble("voltage"); 0056 QString display = QString::number(voltage / getMultiplier(voltage), 'g', 3) + getNumberMag(voltage) + "V"; 0057 setDisplayText("voltage", display); 0058 m_voltagePoint->setVoltage(voltage); 0059 } 0060 0061 void ECFixedVoltage::drawShape(QPainter &p) 0062 { 0063 initPainter(p); 0064 p.drawEllipse(int(x() - 4), int(y() - 4), 9, 9); 0065 deinitPainter(p); 0066 }