File indexing completed on 2024-12-22 04:17:34
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2011 Joshua Netterfield * 0004 * joshua.netterfield@gmail.com * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "labelscriptinterface.h" 0014 0015 #include <QStringBuilder> 0016 0017 namespace Kst { 0018 0019 struct LabelTabSI { 0020 LabelItem* item; 0021 QByteArrayList commands() { 0022 QByteArrayList ba; 0023 ba<<"setLabel("<<"setLabelColor("<<"setLabelColor("<<"checkLabelItalic()"<<"uncheckLabelItalic()"<< 0024 "checkLabelBold()"<<"checkLabelBold()"<<"setFontSize("<<"setFontFamily("; 0025 return ba; 0026 } 0027 QString doCommand(QString x) { 0028 if(x.startsWith("setLabel(")) { 0029 x.remove("setLabel(").chop(1); 0030 item->setLabelText(x); 0031 return "Done"; 0032 } else if(x.startsWith("setLabelColor(")) { 0033 item->setLabelColor(QColor(x.remove("setLabelColor(").remove(')'))); 0034 } else if(x.contains("Italic")) { 0035 QFont f=item->labelFont(); 0036 f.setItalic(!x.contains("un")); 0037 item->setLabelFont(f); 0038 return "Done"; 0039 } else if(x.contains("Bold")) { 0040 QFont f=item->labelFont(); 0041 f.setBold(!x.contains("un")); 0042 item->setLabelFont(f); 0043 return "Done"; 0044 } else if(x.contains("setFont")) { 0045 QFont f=item->labelFont(); 0046 if(x.contains("Size")) { 0047 item->setLabelScale(x.remove("setFontSize(").remove(')').toInt()); 0048 } else if(x.contains("Family")) { 0049 f.setFamily(x.remove("setFontFamily(").remove(')')); 0050 } else { 0051 return ""; 0052 } 0053 item->setLabelFont(f); 0054 return "Done"; 0055 } 0056 return ""; 0057 } 0058 }; 0059 0060 LabelSI::LabelSI(LabelItem *it) : layout(new LayoutTabSI), dim(new DimensionTabSI), lab(new LabelTabSI) { 0061 layout->vi=it; 0062 dim->item=it; 0063 lab->item=it; 0064 } 0065 0066 QString LabelSI::doCommand(QString x) { 0067 0068 QString v=doNamedObjectCommand(x, dim->item); 0069 0070 if (v.isEmpty()) { 0071 v=layout->doCommand(x); 0072 } 0073 if (v.isEmpty()) { 0074 v=dim->doCommand(x); 0075 } 0076 if (v.isEmpty()) { 0077 v=lab->doCommand(x); 0078 } 0079 return v.isEmpty()?"No command":v; 0080 } 0081 0082 bool LabelSI::isValid() { 0083 return dim->item; 0084 } 0085 0086 ScriptInterface* LabelSI::newLabel() { 0087 LabelItem* bi=new LabelItem(kstApp->mainWindow()->tabWidget()->currentView(),""); 0088 kstApp->mainWindow()->tabWidget()->currentView()->scene()->addItem(bi); 0089 return new LabelSI(bi); 0090 } 0091 0092 0093 }