diff -r 5f576e56ad99 -r 497fab7d1404 mapeditor.cpp --- a/mapeditor.cpp Tue Jun 19 14:20:29 2007 +0000 +++ b/mapeditor.cpp Tue Jun 19 14:20:30 2007 +0000 @@ -483,6 +483,7 @@ QString com=parser.getCommand(); // External commands + ///////////////////////////////////////////////////////////////////// if (com=="addBranch") { if (xelection.isEmpty()) @@ -495,9 +496,9 @@ { QList pl; pl << 0 <<1; - if (parser.checkParamCount(pl)) + if (parser.checkParCount(pl)) { - if (parser.paramCount()==0) + if (parser.parCount()==0) addNewBranchInt (-2); else { @@ -506,6 +507,7 @@ } } } + ///////////////////////////////////////////////////////////////////// } else if (com=="addBranchBefore") { if (xelection.isEmpty()) @@ -516,11 +518,12 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else { - if (parser.paramCount()==0) + if (parser.parCount()==0) { addNewBranchBefore (); } } + ///////////////////////////////////////////////////////////////////// } else if (com==QString("addMapReplace")) { if (xelection.isEmpty()) @@ -529,13 +532,14 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { //s=parser.parString (ok,0); // selection t=parser.parString (ok,0); // path to map if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); addMapReplaceInt(selb->getSelectString(),t); } + ///////////////////////////////////////////////////////////////////// } else if (com==QString("addMapInsert")) { if (xelection.isEmpty()) @@ -546,7 +550,7 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else { - if (parser.checkParamCount(2)) + if (parser.checkParCount(2)) { t=parser.parString (ok,0); // path to map y=parser.parInt(ok,1); // position @@ -554,6 +558,7 @@ addMapInsertInt(t,y); } } + ///////////////////////////////////////////////////////////////////// } else if (com=="clearFlags") { if (xelection.isEmpty() ) @@ -562,11 +567,12 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { selb->clearStandardFlags(); selb->updateFlagsToolbar(); } + ///////////////////////////////////////////////////////////////////// } else if (com=="colorBranch") { if (xelection.isEmpty()) @@ -575,11 +581,12 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { QColor c=parser.parColor (ok,0); if (ok) colorBranch (c); } + ///////////////////////////////////////////////////////////////////// } else if (com=="colorSubtree") { if (xelection.isEmpty()) @@ -588,11 +595,12 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { QColor c=parser.parColor (ok,0); if (ok) colorSubtree (c); } + ///////////////////////////////////////////////////////////////////// } else if (com=="copy") { if (xelection.isEmpty()) @@ -601,10 +609,11 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { //FIXME missing action for copy } + ///////////////////////////////////////////////////////////////////// } else if (com=="cut") { if (xelection.isEmpty()) @@ -615,10 +624,11 @@ xelection.type()!=Selection::FloatImage ) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { cut(); } + ///////////////////////////////////////////////////////////////////// } else if (com=="delete") { if (xelection.isEmpty()) @@ -627,10 +637,11 @@ } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage ) { parser.setError (Aborted,"Type of selection is wrong."); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { deleteSelection(); } + ///////////////////////////////////////////////////////////////////// } else if (com=="deleteKeepChilds") { if (xelection.isEmpty()) @@ -639,10 +650,11 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { deleteKeepChilds(); } + ///////////////////////////////////////////////////////////////////// } else if (com=="deleteChilds") { if (xelection.isEmpty()) @@ -651,10 +663,63 @@ } else if (! selb) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { deleteChilds(); } + ///////////////////////////////////////////////////////////////////// + } else if (com=="export") + { + /* + if (xelection.isEmpty()) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selb) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else + */ + if (parser.parCount()==0) + { + parser.setError (Aborted,"No output format given"); + } else + { + // At least one parameter, which is the outFormat + QString outFormat=parser.parString (ok,0); + if (!ok) + { + parser.setError (Aborted,QString("Unknown export type: %1").arg(outFormat)); + } else + { + QString fname=""; + ok=true; + if (parser.parCount()>=2) + // Hey, we even have a filename + fname=parser.parString(ok,1); + if (!ok) + { + parser.setError (Aborted,"Could not read filename"); + } else + { + if (outFormat == "ascii") + { + exportASCII (fname,false); + } else if (outFormat == "image") + { + QString format="PNG"; + if (parser.parCount()>2) + { + format=parser.parString(ok,2); + } + exportImage (fname,false,format); + } else + { + parser.setError (Aborted,QString("Unknown export type: %1").arg(outFormat)); + } + } + } + } + ///////////////////////////////////////////////////////////////////// } else if (com=="importDir") { if (xelection.isEmpty()) @@ -663,11 +728,12 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) importDirInt(s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="linkTo") { if (xelection.isEmpty()) @@ -675,7 +741,7 @@ parser.setError (Aborted,"Nothing selected"); } else if ( selb) { - if (parser.checkParamCount(4)) + if (parser.checkParCount(4)) { // 0 selectstring of parent // 1 num in parent (for branches) @@ -705,7 +771,7 @@ } } else if ( xelection.type() == Selection::FloatImage) { - if (parser.checkParamCount(1)) + if (parser.checkParCount(1)) { // 0 selectstring of parent s=parser.parString(ok,0); @@ -720,6 +786,7 @@ } } else parser.setError (Aborted,"Type of selection is not a floatimage or branch"); + ///////////////////////////////////////////////////////////////////// } else if (com=="loadImage") { if (xelection.isEmpty()) @@ -728,11 +795,12 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) loadFloatImageInt (s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="moveBranchUp") { if (xelection.isEmpty() ) @@ -741,10 +809,11 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { moveBranchUp(); } + ///////////////////////////////////////////////////////////////////// } else if (com=="moveBranchDown") { if (xelection.isEmpty() ) @@ -753,10 +822,11 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { moveBranchDown(); } + ///////////////////////////////////////////////////////////////////// } else if (com=="move") { if (xelection.isEmpty() ) @@ -767,7 +837,7 @@ xelection.type()!=Selection::FloatImage ) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParamCount(2)) + } else if (parser.checkParCount(2)) { x=parser.parInt (ok,0); if (ok) @@ -776,6 +846,7 @@ if (ok) move (x,y); } } + ///////////////////////////////////////////////////////////////////// } else if (com=="moveRel") { if (xelection.isEmpty() ) @@ -786,7 +857,7 @@ xelection.type()!=Selection::Selection::FloatImage ) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParamCount(2)) + } else if (parser.checkParCount(2)) { x=parser.parInt (ok,0); if (ok) @@ -795,8 +866,10 @@ if (ok) moveRel (x,y); } } + ///////////////////////////////////////////////////////////////////// } else if (com=="nop") { + ///////////////////////////////////////////////////////////////////// } else if (com=="paste") { if (xelection.isEmpty() ) @@ -805,7 +878,7 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { x=parser.parInt (ok,0); if (ok) pasteNoSave(x); @@ -819,7 +892,7 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(4)) + } else if (parser.checkParCount(4)) { QString c,u; c=parser.parString (ok,0); @@ -876,13 +949,14 @@ } } } + ///////////////////////////////////////////////////////////////////// } else if (com=="saveImage") { FloatImageObj *fio=xelection.getFloatImage(); if (!fio) { parser.setError (Aborted,"Type of selection is not an image"); - } else if (parser.checkParamCount(2)) + } else if (parser.checkParCount(2)) { s=parser.parString(ok,0); if (ok) @@ -891,6 +965,7 @@ if (ok) saveFloatImageInt (fio,t,s); } } + ///////////////////////////////////////////////////////////////////// } else if (com=="scroll") { if (xelection.isEmpty() ) @@ -899,18 +974,20 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { if (!scrollBranch (selb)) parser.setError (Aborted,"Could not scroll branch"); } + ///////////////////////////////////////////////////////////////////// } else if (com=="select") { - if (parser.checkParamCount(1)) + if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) select (s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="selectLastBranch") { if (xelection.isEmpty() ) @@ -919,7 +996,7 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { BranchObj *bo=selb->getLastBranch(); if (!bo) @@ -927,6 +1004,7 @@ selectInt (bo); } + ///////////////////////////////////////////////////////////////////// } else if (com=="selectLastImage") { if (xelection.isEmpty() ) @@ -935,7 +1013,7 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { FloatImageObj *fio=selb->getLastFloatImage(); if (!fio) @@ -943,75 +1021,83 @@ selectInt (fio); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameType") { if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) { parser.setError (Aborted,"Type of selection does not allow setting frame type"); } - else if (parser.checkParamCount(1)) + else if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) setFrameType (s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setFramePenColor") { if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) { parser.setError (Aborted,"Type of selection does not allow setting of pen color"); } - else if (parser.checkParamCount(1)) + else if (parser.checkParCount(1)) { QColor c=parser.parColor(ok,0); if (ok) setFramePenColor (c); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameBrushColor") { if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) { parser.setError (Aborted,"Type of selection does not allow setting brush color"); } - else if (parser.checkParamCount(1)) + else if (parser.checkParCount(1)) { QColor c=parser.parColor(ok,0); if (ok) setFrameBrushColor (c); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setFramePadding") { if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) { parser.setError (Aborted,"Type of selection does not allow setting frame padding"); } - else if (parser.checkParamCount(1)) + else if (parser.checkParCount(1)) { x=parser.parInt(ok,0); if (ok) setFramePadding(x); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameBorderWidth") { if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) { parser.setError (Aborted,"Type of selection does not allow setting frame border width"); } - else if (parser.checkParamCount(1)) + else if (parser.checkParCount(1)) { x=parser.parInt(ok,0); if (ok) setFrameBorderWidth (x); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setMapAuthor") { - if (parser.checkParamCount(1)) + if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) setMapAuthor (s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setMapComment") { - if (parser.checkParamCount(1)) + if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) setMapComment(s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setMapBackgroundColor") { if (xelection.isEmpty() ) @@ -1020,11 +1106,12 @@ } else if (! xelection.getBranch() ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { QColor c=parser.parColor (ok,0); if (ok) setMapBackgroundColor (c); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setMapDefLinkColor") { if (xelection.isEmpty() ) @@ -1033,18 +1120,20 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { QColor c=parser.parColor (ok,0); if (ok) setMapDefLinkColor (c); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setMapLinkStyle") { - if (parser.checkParamCount(1)) + if (parser.checkParCount(1)) { s=parser.parString (ok,0); if (ok) setMapLinkStyle(s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setHeading") { if (xelection.isEmpty() ) @@ -1053,12 +1142,13 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString (ok,0); if (ok) setHeading (s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setHideExport") { if (xelection.isEmpty() ) @@ -1067,11 +1157,12 @@ } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { b=parser.parBool(ok,0); if (ok) setHideExport (b); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setIncludeImagesHorizontally") { if (xelection.isEmpty() ) @@ -1080,11 +1171,12 @@ } else if (! selb) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { b=parser.parBool(ok,0); if (ok) setIncludeImagesHor(b); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setIncludeImagesVertically") { if (xelection.isEmpty() ) @@ -1093,11 +1185,12 @@ } else if (! selb) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { b=parser.parBool(ok,0); if (ok) setIncludeImagesVer(b); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setHideLinkUnselected") { if (xelection.isEmpty() ) @@ -1106,18 +1199,20 @@ } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) { parser.setError (Aborted,"Type of selection does not allow hiding the link"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { b=parser.parBool(ok,0); if (ok) setHideLinkUnselected(b); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setSelectionColor") { - if (parser.checkParamCount(1)) + if (parser.checkParCount(1)) { QColor c=parser.parColor (ok,0); if (ok) setSelectionColorInt (c); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setURL") { if (xelection.isEmpty() ) @@ -1126,11 +1221,12 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString (ok,0); if (ok) setURL(s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="setVymLink") { if (xelection.isEmpty() ) @@ -1139,12 +1235,13 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString (ok,0); if (ok) setVymLinkInt(s); } } + ///////////////////////////////////////////////////////////////////// else if (com=="setFlag") { if (xelection.isEmpty() ) @@ -1153,7 +1250,7 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) @@ -1162,6 +1259,7 @@ selb->updateFlagsToolbar(); } } + ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameType") { if (xelection.isEmpty() ) @@ -1170,12 +1268,13 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) setFrameType (s); } + ///////////////////////////////////////////////////////////////////// } else if (com=="toggleFlag") { if (xelection.isEmpty() ) @@ -1184,7 +1283,7 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) @@ -1193,6 +1292,7 @@ selb->updateFlagsToolbar(); } } + ///////////////////////////////////////////////////////////////////// } else if (com=="unscroll") { if (xelection.isEmpty() ) @@ -1201,11 +1301,12 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { if (!unscrollBranch (selb)) parser.setError (Aborted,"Could not unscroll branch"); } + ///////////////////////////////////////////////////////////////////// } else if (com=="unscrollChilds") { if (xelection.isEmpty() ) @@ -1214,10 +1315,11 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(0)) + } else if (parser.checkParCount(0)) { unscrollChilds (); } + ///////////////////////////////////////////////////////////////////// } else if (com=="unsetFlag") { if (xelection.isEmpty() ) @@ -1226,7 +1328,7 @@ } else if (! selb ) { parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParamCount(1)) + } else if (parser.checkParCount(1)) { s=parser.parString(ok,0); if (ok) @@ -1616,14 +1718,6 @@ return hidemode; } -void MapEditor::exportImage(QString fn) -{ - setExportMode (true); - QPixmap pix (getPixmap()); - pix.save(fn, "PNG"); - setExportMode (false); -} - void MapEditor::setExportMode (bool b) { // should be called before and after exports @@ -1634,11 +1728,57 @@ setHideTmpMode (BranchObj::HideNone); } -void MapEditor::exportImage(QString fn, QString format) +void MapEditor::exportASCII(QString fname,bool askName) { + ExportASCII ex; + ex.setMapCenter(mapCenter); + if (fname=="") + ex.setFile (mapName+".txt"); + else + ex.setFile (fname); + + if (askName) + { + //ex.addFilter ("TXT (*.txt)"); + ex.setDir(lastImageDir); + //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)")); + ex.execDialog() ; + } + if (!ex.canceled()) + { + setExportMode(true); + ex.doExport(); + setExportMode(false); + } +} + +void MapEditor::exportImage(QString fname, bool askName, QString format) +{ + if (fname=="") + { + fname=mapName+".png"; + format="PNG"; + } + + if (askName) + { + QStringList fl; + QFileDialog *fd=new QFileDialog (this); + fd->setCaption (tr("Export map as image")); + fd->setDirectory (lastImageDir); + fd->setFileMode(QFileDialog::AnyFile); + fd->setFilters (imageIO.getFilters() ); + if (fd->exec()) + { + fl=fd->selectedFiles(); + fname=fl.first(); + format=imageIO.getType(fd->selectedFilter()); + } + } + setExportMode (true); QPixmap pix (getPixmap()); - pix.save(fn, format); + pix.save(fname, format); setExportMode (false); } @@ -1684,7 +1824,7 @@ file.close(); // Now write image, too - exportImage (dir+"/images/"+mapName+".png"); + exportImage (dir+"/images/"+mapName+".png","PNG"); setExportMode (false); }