File indexing completed on 2024-12-08 11:06:52
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 "embed.h" 0012 0013 #include "flowcode.h" 0014 #include "libraryitem.h" 0015 #include "icndocument.h" 0016 0017 #include <KLocalizedString> 0018 0019 Item *Embed::construct(ItemDocument *itemDocument, bool newItem, const char *id) 0020 { 0021 return new Embed(static_cast<ICNDocument *>(itemDocument), newItem, id); 0022 } 0023 0024 LibraryItem *Embed::libraryItem() 0025 { 0026 return new LibraryItem(QStringList(QString("flow/embed")), i18n("Embed"), i18n("Common"), "embed.png", LibraryItem::lit_flowpart, Embed::construct); 0027 } 0028 0029 Embed::Embed(ICNDocument *icnDocument, bool newItem, const char *id) 0030 : FlowPart(icnDocument, newItem, id ? id : "embed") 0031 { 0032 m_name = i18n("Embed"); 0033 initProcessSymbol(); 0034 createStdInput(); 0035 createStdOutput(); 0036 0037 createProperty("type", Variant::Type::Select); 0038 property("type")->setAllowed((QStringList("Microbe") << "Assembly")); 0039 property("type")->setValue("Microbe"); 0040 property("type")->setCaption(i18n("Type")); // TODO: replace this with i18n( "the type", "Type" ); 0041 0042 createProperty("code", Variant::Type::Multiline); 0043 property("code")->setCaption(i18n("Code")); 0044 property("code")->setValue(i18n("// Embedded code:")); 0045 } 0046 0047 Embed::~Embed() 0048 { 0049 } 0050 0051 void Embed::dataChanged() 0052 { 0053 const QString sample = dataString("code").left(10).replace("\n", " "); 0054 setCaption(i18n("%1: %2...", dataString("type"), sample)); 0055 } 0056 0057 bool Embed::typeIsMicrobe() const 0058 { 0059 return dataString("type") == "Microbe"; 0060 } 0061 0062 void Embed::generateMicrobe(FlowCode *code) 0063 { 0064 if (typeIsMicrobe()) 0065 code->addCode(dataString("code")); 0066 0067 else { 0068 // Is assembly code, we need to microbe as such 0069 code->addCode("asm\n{"); 0070 code->addCode(dataString("code")); 0071 code->addCode("}"); 0072 } 0073 0074 code->addCodeBranch(outputPart("stdoutput")); 0075 }