File indexing completed on 2024-12-22 04:17:25
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2014 Barth Netterfield * 0004 * netterfield@astro.utoronto.ca * 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 "arrowscriptinterface.h" 0014 0015 #include <QStringBuilder> 0016 0017 namespace Kst { 0018 0019 struct ArrowTabSI { 0020 ArrowItem* item; 0021 QByteArrayList commands() { 0022 QByteArrayList ba; 0023 ba<<"arrowAtStart("<<"arrowAtEnd("<<"arrowHeadScale("; 0024 return ba; 0025 } 0026 QString doCommand(QString x) { 0027 if (x.startsWith("arrowAtStart(")) { 0028 x.remove("arrowAtStart(").chop(1); 0029 item->setStartArrowHead(x.toLower()=="true"); 0030 return "Done"; 0031 } else if (x.startsWith("arrowAtEnd(")) { 0032 x.remove("arrowAtEnd(").chop(1); 0033 item->setEndArrowHead(x.toLower()=="true"); 0034 return "Done"; 0035 } else if (x.startsWith("arrowHeadScale(")) { 0036 x.remove("arrowHeadScale(").chop(1); 0037 double scale = qMax(3.0, x.toDouble()); 0038 item->setEndArrowScale(scale); 0039 item->setStartArrowScale(scale); 0040 return "Done"; 0041 } 0042 return ""; 0043 } 0044 }; 0045 0046 ArrowSI::ArrowSI(ArrowItem *it) : _dim(new DimensionTabSI), _fill(new FillTabSI), _stroke(new StrokeTabSI), _arrow(new ArrowTabSI) { 0047 _dim->item=it; 0048 _fill->item=it; 0049 _stroke->item=it; 0050 _arrow->item=it; 0051 } 0052 0053 QString ArrowSI::doCommand(QString x) { 0054 0055 QString v=doNamedObjectCommand(x, _dim->item); 0056 0057 if(v.isEmpty()) { 0058 v =_dim->doCommand(x); 0059 } 0060 if(v.isEmpty()) { 0061 v=_fill->doCommand(x); 0062 } 0063 if(v.isEmpty()) { 0064 v=_stroke->doCommand(x); 0065 } 0066 if(v.isEmpty()) { 0067 v=_arrow->doCommand(x); 0068 } 0069 return v.isEmpty()?"No command":v; 0070 } 0071 0072 bool ArrowSI::isValid() { 0073 return _dim->item; 0074 } 0075 0076 ScriptInterface* ArrowSI::newArrow() { 0077 ArrowItem* bi=new ArrowItem(kstApp->mainWindow()->tabWidget()->currentView()); 0078 kstApp->mainWindow()->tabWidget()->currentView()->scene()->addItem(bi); 0079 return new ArrowSI(bi); 0080 } 0081 0082 0083 }