File indexing completed on 2024-05-05 05:46:09

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 "resistor.h"
0012 
0013 #include "libraryitem.h"
0014 #include "resistance.h"
0015 
0016 #include <KLocalizedString>
0017 #include <QPainter>
0018 
0019 Item *Resistor::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new Resistor(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *Resistor::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("ec/resistor")), i18n("Resistor"), i18n("Passive"), "resistor.png", LibraryItem::lit_component, Resistor::construct);
0027 }
0028 
0029 Resistor::Resistor(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : Component(icnDocument, newItem, id ? id : "resistor")
0031 {
0032     m_name = i18n("Resistor");
0033     setSize(-16, -8, 32, 16);
0034 
0035     init1PinLeft();
0036     init1PinRight();
0037     m_resistance = createResistance(m_pPNode[0], m_pNNode[0], 1.);
0038 
0039     createProperty("resistance", Variant::Type::Double);
0040     property("resistance")->setCaption(i18n("Resistance"));
0041     property("resistance")->setUnit(QChar(0x3a9));
0042     property("resistance")->setValue(1e4);
0043     property("resistance")->setMinValue(1e-6);
0044 
0045     addDisplayText("res", QRect(-16, -22, 32, 12), "", false);
0046 }
0047 
0048 Resistor::~Resistor()
0049 {
0050 }
0051 
0052 void Resistor::dataChanged()
0053 {
0054     double resistance = dataDouble("resistance");
0055 
0056     QString display = QString::number(resistance / getMultiplier(resistance), 'g', 3) + getNumberMag(resistance) + QChar(0x3a9);
0057     setDisplayText("res", display);
0058 
0059     m_resistance->setResistance(resistance);
0060 }
0061 
0062 void Resistor::drawShape(QPainter &p)
0063 {
0064     initPainter(p);
0065     p.drawRect(int(x()) - 16, int(y()) - 6, width(), 12);
0066     deinitPainter(p);
0067 }