File indexing completed on 2024-05-05 05:46:03
0001 /*************************************************************************** 0002 * Copyright (C) 2003 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 "capacitor.h" 0012 #include "capacitance.h" 0013 #include "ecnode.h" 0014 #include "libraryitem.h" 0015 0016 #include <KLocalizedString> 0017 #include <QPainter> 0018 0019 Item *Capacitor::construct(ItemDocument *itemDocument, bool newItem, const char *id) 0020 { 0021 return new Capacitor(static_cast<ICNDocument *>(itemDocument), newItem, id); 0022 } 0023 0024 LibraryItem *Capacitor::libraryItem() 0025 { 0026 return new LibraryItem(QStringList(QString("ec/capacitor")), i18n("Capacitor"), i18n("Passive"), "capacitor.png", LibraryItem::lit_component, Capacitor::construct); 0027 } 0028 0029 Capacitor::Capacitor(ICNDocument *icnDocument, bool newItem, const char *id) 0030 : Component(icnDocument, newItem, id ? id : "capacitor") 0031 { 0032 m_name = i18n("Capacitor"); 0033 setSize(-8, -8, 16, 16); 0034 0035 init1PinLeft(); 0036 init1PinRight(); 0037 0038 m_capacitance = createCapacitance(m_pNNode[0], m_pPNode[0], 0.001); 0039 0040 createProperty("Capacitance", Variant::Type::Double); 0041 property("Capacitance")->setCaption(i18n("Capacitance")); 0042 property("Capacitance")->setUnit("F"); 0043 property("Capacitance")->setMinValue(1e-12); 0044 property("Capacitance")->setMaxValue(1e12); 0045 property("Capacitance")->setValue(1e-3); 0046 0047 addDisplayText("capacitance", QRect(-8, -24, 16, 16), "", false); 0048 } 0049 0050 Capacitor::~Capacitor() 0051 { 0052 } 0053 0054 void Capacitor::dataChanged() 0055 { 0056 double capacitance = dataDouble("Capacitance"); 0057 0058 QString display = QString::number(capacitance / getMultiplier(capacitance), 'g', 3) + getNumberMag(capacitance) + "F"; 0059 setDisplayText("capacitance", display); 0060 0061 m_capacitance->setCapacitance(capacitance); 0062 } 0063 0064 void Capacitor::drawShape(QPainter &p) 0065 { 0066 initPainter(p); 0067 0068 int _y = int(y()) - 8; 0069 int _x = int(x()) - 8; 0070 0071 QPen pen; 0072 pen.setWidth(1); 0073 pen.setColor(p.pen().color()); 0074 p.setPen(pen); 0075 p.drawRect(_x, _y, 5, 16); 0076 p.drawRect(_x + 11, _y, 5, 16); 0077 0078 deinitPainter(p); 0079 }