File indexing completed on 2024-12-08 11:06:53

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 "interrupt.h"
0012 
0013 #include "flowcode.h"
0014 #include "libraryitem.h"
0015 #include "icndocument.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 Item *Interrupt::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new Interrupt(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *Interrupt::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("flow/interrupt")), i18n("Interrupt"), i18n("Common"), "interrupt.png", LibraryItem::lit_flowpart, Interrupt::construct);
0027 }
0028 
0029 Interrupt::Interrupt(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : FlowContainer(icnDocument, newItem, id ? id : "interrupt")
0031 {
0032     m_name = i18n("Interrupt");
0033 
0034     QStringList interruptTypes;
0035     interruptTypes.append("changed");
0036     interruptTypes.append("external");
0037     interruptTypes.append("timer");
0038     interruptTypes.append("trigger");
0039 
0040     createProperty("interrupt", Variant::Type::Select);
0041     property("interrupt")->setAllowed(interruptTypes);
0042     property("interrupt")->setCaption(i18n("Interrupt"));
0043     property("interrupt")->setValue("trigger");
0044 }
0045 
0046 Interrupt::~Interrupt()
0047 {
0048 }
0049 
0050 void Interrupt::dataChanged()
0051 {
0052     setCaption(i18n("Interrupt %1", dataString("interrupt")));
0053 }
0054 
0055 void Interrupt::generateMicrobe(FlowCode *code)
0056 {
0057     code->addCode("\ninterrupt " + dataString("interrupt") + "\n{");
0058     code->addCodeBranch(outputPart("int_in"));
0059     code->addCode("}");
0060 }