1 #include <QApplication>
6 #include "editxlinkdialog.h"
8 #include "exportxhtmldialog.h"
10 #include "geometry.h" // for addBBox
11 #include "mainwindow.h"
12 #include "mapcenterobj.h"
15 #include "selection.h"
18 #include "warningdialog.h"
19 #include "xml-freemind.h"
25 extern Main *mainWindow;
26 extern Settings settings;
27 extern QString tmpVymDir;
29 extern TextEditor *textEditor;
31 extern QString clipboardDir;
32 extern QString clipboardFile;
33 extern bool clipboardEmpty;
35 extern ImageIO imageIO;
37 extern QString vymName;
38 extern QString vymVersion;
39 extern QDir vymBaseDir;
41 extern QDir lastImageDir;
42 extern QDir lastFileDir;
44 extern FlagRowObj *standardFlagsDefault;
46 extern Settings settings;
50 int VymModel::mapNum=0; // make instance
54 // cout << "Const VymModel\n";
61 // cout << "Destr VymModel\n";
62 autosaveTimer->stop();
63 fileChangedTimer->stop();
67 void VymModel::clear()
69 cout << "VymModel::clear rows="<<rowCount(index(rootItem))<<endl;
70 selModel->clearSelection();
73 while (!mapCenters.isEmpty()) // FIXME VM needs to be in treemodel only...
74 delete mapCenters.takeFirst();
76 QModelIndex ri=index(rootItem);
77 removeRows (0, rowCount(ri),ri);
80 void VymModel::init ()
82 // We should have at least one map center to start with
83 // addMapCenter(); FIXME VM create this in MapEditor as long as model is part of that
88 // Also no scene yet (should not be needed anyway) FIXME VM
101 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
102 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
103 mainWindow->updateHistory (undoSet);
106 makeTmpDirectories();
111 fileName=tr("unnamed");
113 blockReposition=false;
114 blockSaveState=false;
116 autosaveTimer=new QTimer (this);
117 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
119 fileChangedTimer=new QTimer (this);
120 fileChangedTimer->start(3000);
121 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
132 animationUse=settings.readBoolEntry("/animation/use",false);
133 animationTicks=settings.readNumEntry("/animation/ticks",10);
134 animationInterval=settings.readNumEntry("/animation/interval",50);
136 animationTimer=new QTimer (this);
137 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
140 defLinkColor=QColor (0,0,255);
141 defXLinkColor=QColor (180,180,180);
142 linkcolorhint=LinkableMapObj::DefaultColor;
143 linkstyle=LinkableMapObj::PolyParabel;
145 defXLinkColor=QColor (230,230,230);
155 // addMapCenter(); FIXME VM create this in MapEditor until BO and MCO are independent of scene
159 void VymModel::makeTmpDirectories()
161 // Create unique temporary directories
162 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
163 histPath = tmpMapDir+"/history";
169 MapEditor* VymModel::getMapEditor() // FIXME VM better return favourite editor here
174 bool VymModel::isRepositionBlocked()
176 return blockReposition;
179 void VymModel::updateActions() // FIXME maybe don't update if blockReposition is set
181 // Tell mainwindow to update states of actions
182 mainWindow->updateActions();
187 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
189 // tmpdir temporary directory to which data will be written
190 // prefix mapname, which will be appended to images etc.
191 // writeflags Only write flags for "real" save of map, not undo
192 // offset offset of bbox of whole map in scene.
193 // Needed for XML export
202 case LinkableMapObj::Line:
205 case LinkableMapObj::Parabel:
208 case LinkableMapObj::PolyLine:
212 ls="StylePolyParabel";
216 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
218 if (linkcolorhint==LinkableMapObj::HeadingColor)
219 colhint=xml.attribut("linkColorHint","HeadingColor");
221 QString mapAttr=xml.attribut("version",vymVersion);
223 mapAttr+= xml.attribut("author",author) +
224 xml.attribut("comment",comment) +
225 xml.attribut("date",getDate()) +
226 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
227 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
228 xml.attribut("linkStyle", ls ) +
229 xml.attribut("linkColor", defLinkColor.name() ) +
230 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
231 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
233 s+=xml.beginElement("vymmap",mapAttr);
236 // Find the used flags while traversing the tree
237 standardFlagsDefault->resetUsedCounter();
239 // Reset the counters before saving
240 // TODO constr. of FIO creates lots of objects, better do this in some other way...
241 FloatImageObj (mapScene).resetSaveCounter();
243 // Build xml recursivly
244 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
245 // Save complete map, if saveSel not set
246 s+=saveToDir(tmpdir,prefix,writeflags,offset);
249 if ( typeid(*saveSel) == typeid(BranchObj) )
251 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
252 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
254 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
257 // Save local settings
258 s+=settings.getDataXML (destPath);
261 if (!selection.isEmpty() && !saveSel )
262 s+=xml.valueElement("select",selection.getSelectString());
265 s+=xml.endElement("vymmap");
268 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
272 void VymModel::setFilePath(QString fpath, QString destname)
274 if (fpath.isEmpty() || fpath=="")
281 filePath=fpath; // becomes absolute path
282 fileName=fpath; // gets stripped of path
283 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
285 // If fpath is not an absolute path, complete it
286 filePath=QDir(fpath).absPath();
287 fileDir=filePath.left (1+filePath.findRev ("/"));
289 // Set short name, too. Search from behind:
290 int i=fileName.findRev("/");
291 if (i>=0) fileName=fileName.remove (0,i+1);
293 // Forget the .vym (or .xml) for name of map
294 mapName=fileName.left(fileName.findRev(".",-1,true) );
298 void VymModel::setFilePath(QString fpath)
300 setFilePath (fpath,fpath);
303 QString VymModel::getFilePath()
308 QString VymModel::getFileName()
313 QString VymModel::getMapName()
318 QString VymModel::getDestPath()
323 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
325 ErrorCode err=success;
327 parseBaseHandler *handler;
331 case VymMap: handler=new parseVYMHandler; break;
332 case FreemindMap : handler=new parseFreemindHandler; break;
334 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
335 "Unknown FileType in VymModel::load()");
339 bool zipped_org=zipped;
343 selModel->clearSelection();
344 // FIXME VM not needed??? model->setMapEditor(this);
345 // (map state is set later at end of load...)
348 BranchObj *bo=getSelectedBranch();
349 if (!bo) return aborted;
350 if (lmode==ImportAdd)
351 saveStateChangingPart(
354 QString("addMapInsert (%1)").arg(fname),
355 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
357 saveStateChangingPart(
360 QString("addMapReplace(%1)").arg(fname),
361 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
365 // Create temporary directory for packing
367 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
370 QMessageBox::critical( 0, tr( "Critical Load Error" ),
371 tr("Couldn't create temporary directory before load\n"));
376 err=unzipDir (tmpZipDir,fname);
386 // Look for mapname.xml
387 xmlfile= fname.left(fname.findRev(".",-1,true));
388 xmlfile=xmlfile.section( '/', -1 );
389 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
390 if (!mfile.exists() )
392 // mapname.xml does not exist, well,
393 // maybe someone renamed the mapname.vym file...
394 // Try to find any .xml in the toplevel
395 // directory of the .vym file
396 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
397 if (flist.count()==1)
399 // Only one entry, take this one
400 xmlfile=tmpZipDir + "/"+flist.first();
403 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
404 *it=tmpZipDir + "/" + *it;
405 // TODO Multiple entries, load all (but only the first one into this ME)
406 //mainWindow->fileLoadFromTmp (flist);
407 //returnCode=1; // Silently forget this attempt to load
408 qWarning ("MainWindow::load (fn) multimap found...");
411 if (flist.isEmpty() )
413 QMessageBox::critical( 0, tr( "Critical Load Error" ),
414 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
417 } //file doesn't exist
419 xmlfile=mfile.name();
422 QFile file( xmlfile);
424 // I am paranoid: file should exist anyway
425 // according to check in mainwindow.
428 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
429 tr(QString("Couldn't open map %1").arg(file.name())));
433 bool blockSaveStateOrg=blockSaveState;
434 blockReposition=true;
436 QXmlInputSource source( file);
437 QXmlSimpleReader reader;
438 reader.setContentHandler( handler );
439 reader.setErrorHandler( handler );
440 handler->setModel ( this);
443 // We need to set the tmpDir in order to load files with rel. path
448 tmpdir=fname.left(fname.findRev("/",-1));
449 handler->setTmpDir (tmpdir);
450 handler->setInputFile (file.name());
451 handler->setLoadMode (lmode);
452 bool ok = reader.parse( source );
453 blockReposition=false;
454 blockSaveState=blockSaveStateOrg;
458 reposition(); // FIXME VM reposition the view instead...
465 autosaveTimer->stop();
468 // Reset timestamp to check for later updates of file
469 fileChangedTime=QFileInfo (destPath).lastModified();
472 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
473 tr( handler->errorProtocol() ) );
475 // Still return "success": the map maybe at least
476 // partially read by the parser
481 removeDir (QDir(tmpZipDir));
483 // Restore original zip state
490 ErrorCode VymModel::save (const SaveMode &savemode)
494 QString safeFilePath;
496 ErrorCode err=success;
500 mapFileName=mapName+".xml";
502 // use name given by user, even if he chooses .doc
503 mapFileName=fileName;
505 // Look, if we should zip the data:
508 QMessageBox mb( vymName,
509 tr("The map %1\ndid not use the compressed "
510 "vym file format.\nWriting it uncompressed will also write images \n"
511 "and flags and thus may overwrite files in the "
512 "given directory\n\nDo you want to write the map").arg(filePath),
513 QMessageBox::Warning,
514 QMessageBox::Yes | QMessageBox::Default,
516 QMessageBox::Cancel | QMessageBox::Escape);
517 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
518 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
519 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
522 case QMessageBox::Yes:
523 // save compressed (default file format)
526 case QMessageBox::No:
530 case QMessageBox::Cancel:
537 // First backup existing file, we
538 // don't want to add to old zip archives
542 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
544 QString backupFileName(destPath + "~");
545 QFile backupFile(backupFileName);
546 if (backupFile.exists() && !backupFile.remove())
548 QMessageBox::warning(0, tr("Save Error"),
549 tr("%1\ncould not be removed before saving").arg(backupFileName));
551 else if (!f.rename(backupFileName))
553 QMessageBox::warning(0, tr("Save Error"),
554 tr("%1\ncould not be renamed before saving").arg(destPath));
561 // Create temporary directory for packing
563 tmpZipDir=makeTmpDir (ok,"vym-zip");
566 QMessageBox::critical( 0, tr( "Critical Load Error" ),
567 tr("Couldn't create temporary directory before save\n"));
571 safeFilePath=filePath;
572 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
575 // Create mapName and fileDir
576 makeSubDirs (fileDir);
579 if (savemode==CompleteMap || selection.isEmpty())
582 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
585 autosaveTimer->stop();
590 if (selectionType()==TreeItem::Image)
593 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch());
594 // TODO take care of multiselections
597 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
600 qWarning ("ME::saveStringToDisk failed!");
606 if (err==success) err=zipDir (tmpZipDir,destPath);
609 removeDir (QDir(tmpZipDir));
611 // Restore original filepath outside of tmp zip dir
612 setFilePath (safeFilePath);
616 fileChangedTime=QFileInfo (destPath).lastModified();
620 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
622 QString pathDir=path.left(path.findRev("/"));
628 // We need to parse saved XML data
629 parseVYMHandler handler;
630 QXmlInputSource source( file);
631 QXmlSimpleReader reader;
632 reader.setContentHandler( &handler );
633 reader.setErrorHandler( &handler );
634 handler.setModel ( this);
635 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
636 if (undoSel.isEmpty())
640 handler.setLoadMode (NewMap);
644 handler.setLoadMode (ImportReplace);
646 blockReposition=true;
647 bool ok = reader.parse( source );
648 blockReposition=false;
651 // This should never ever happen
652 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
653 handler.errorProtocol());
656 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
659 void VymModel::addMapInsertInt (const QString &path, int pos)
661 BranchObj *sel=getSelectedBranch();
664 QString pathDir=path.left(path.findRev("/"));
670 // We need to parse saved XML data
671 parseVYMHandler handler;
672 QXmlInputSource source( file);
673 QXmlSimpleReader reader;
674 reader.setContentHandler( &handler );
675 reader.setErrorHandler( &handler );
676 handler.setModel (this);
677 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
678 handler.setLoadMode (ImportAdd);
679 blockReposition=true;
680 bool ok = reader.parse( source );
681 blockReposition=false;
684 // This should never ever happen
685 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
686 handler.errorProtocol());
688 if (sel->getDepth()>0)
689 sel->getLastBranch()->linkTo (sel,pos);
691 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
695 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
697 BranchObj *bo=getSelectedBranch();
702 fio=bo->getLastFloatImage();
705 // FIXME VM needed? scene()->update();
711 void VymModel::loadFloatImage ()
713 BranchObj *bo=getSelectedBranch();
717 Q3FileDialog *fd=new Q3FileDialog( NULL);
718 fd->setMode (Q3FileDialog::ExistingFiles);
719 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
720 ImagePreview *p =new ImagePreview (fd);
721 fd->setContentsPreviewEnabled( TRUE );
722 fd->setContentsPreview( p, p );
723 fd->setPreviewMode( Q3FileDialog::Contents );
724 fd->setCaption(vymName+" - " +tr("Load image"));
725 fd->setDir (lastImageDir);
728 if ( fd->exec() == QDialog::Accepted )
730 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
731 lastImageDir=QDir (fd->dirPath());
734 for (int j=0; j<fd->selectedFiles().count(); j++)
736 s=fd->selectedFiles().at(j);
737 fio=loadFloatImageInt (s);
740 (LinkableMapObj*)fio,
743 QString ("loadImage (%1)").arg(s ),
744 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
747 // TODO loadFIO error handling
748 qWarning ("Failed to load "+s);
756 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
761 void VymModel::saveFloatImage ()
763 FloatImageObj *fio=selection.getFloatImage();
766 QFileDialog *fd=new QFileDialog( NULL);
767 fd->setFilters (imageIO.getFilters());
768 fd->setCaption(vymName+" - " +tr("Save image"));
769 fd->setFileMode( QFileDialog::AnyFile );
770 fd->setDirectory (lastImageDir);
771 // fd->setSelection (fio->getOriginalFilename());
775 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
777 fn=fd->selectedFiles().at(0);
778 if (QFile (fn).exists() )
780 QMessageBox mb( vymName,
781 tr("The file %1 exists already.\n"
782 "Do you want to overwrite it?").arg(fn),
783 QMessageBox::Warning,
784 QMessageBox::Yes | QMessageBox::Default,
785 QMessageBox::Cancel | QMessageBox::Escape,
786 QMessageBox::NoButton );
788 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
789 mb.setButtonText( QMessageBox::No, tr("Cancel"));
792 case QMessageBox::Yes:
795 case QMessageBox::Cancel:
802 saveFloatImageInt (fio,fd->selectedFilter(),fn );
809 void VymModel::importDirInt(BranchObj *dst, QDir d)
811 BranchObj *bo=getSelectedBranch();
814 // Traverse directories
815 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
816 QFileInfoList list = d.entryInfoList();
819 for (int i = 0; i < list.size(); ++i)
822 if (fi.fileName() != "." && fi.fileName() != ".." )
825 bo=dst->getLastBranch();
826 bo->setHeading (fi.fileName() );
827 bo->setColor (QColor("blue"));
829 if ( !d.cd(fi.fileName()) )
830 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
833 // Recursively add subdirs
840 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
841 list = d.entryInfoList();
843 for (int i = 0; i < list.size(); ++i)
847 bo=dst->getLastBranch();
848 bo->setHeading (fi.fileName() );
849 bo->setColor (QColor("black"));
850 if (fi.fileName().right(4) == ".vym" )
851 bo->setVymLink (fi.filePath());
856 void VymModel::importDirInt (const QString &s)
858 BranchObj *bo=getSelectedBranch();
861 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
868 void VymModel::importDir()
870 BranchObj *bo=getSelectedBranch();
874 filters <<"VYM map (*.vym)";
875 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
876 fd->setMode (QFileDialog::DirectoryOnly);
877 fd->setFilters (filters);
878 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
882 if ( fd->exec() == QDialog::Accepted )
884 importDirInt (fd->selectedFile() );
886 //FIXME VM needed? scene()->update();
892 void VymModel::autosave()
894 QDateTime now=QDateTime().currentDateTime();
896 // Disable autosave, while we have gone back in history
897 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
898 if (redosAvail>0) return;
900 // Also disable autosave for new map without filename
901 if (filePath.isEmpty()) return;
904 if (mapUnsaved &&mapChanged && settings.value ("/autosave/use",true).toBool() )
906 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
907 mainWindow->fileSave (this);
910 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
915 void VymModel::fileChanged()
917 // Check if file on disk has changed meanwhile
918 if (!filePath.isEmpty())
920 QDateTime tmod=QFileInfo (filePath).lastModified();
921 if (tmod>fileChangedTime)
923 // FIXME VM switch to current mapeditor and finish lineedits...
924 QMessageBox mb( vymName,
925 tr("The file of the map on disk has changed:\n\n"
926 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
927 QMessageBox::Question,
929 QMessageBox::Cancel | QMessageBox::Default,
930 QMessageBox::NoButton );
932 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
933 mb.setButtonText( QMessageBox::No, tr("Ignore"));
936 case QMessageBox::Yes:
938 load (filePath,NewMap,fileType);
939 case QMessageBox::Cancel:
940 fileChangedTime=tmod; // allow autosave to overwrite newer file!
946 bool VymModel::isDefault()
951 void VymModel::makeDefault()
957 bool VymModel::hasChanged()
962 void VymModel::setChanged()
965 autosaveTimer->start(settings.value("/autosave/ms/",300000).toInt());
973 QString VymModel::getObjectName (const LinkableMapObj *lmo)
976 if (!lmo) return QString("Error: NULL has no name!");
978 if ((typeid(*lmo) == typeid(BranchObj) ||
979 typeid(*lmo) == typeid(MapCenterObj)))
982 s=(((BranchObj*)lmo)->getHeading());
983 if (s=="") s="unnamed";
984 return QString("branch (%1)").arg(s);
986 if ((typeid(*lmo) == typeid(FloatImageObj) ))
987 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
988 return QString("Unknown type has no name!");
991 void VymModel::redo()
993 // Can we undo at all?
994 if (redosAvail<1) return;
996 bool blockSaveStateOrg=blockSaveState;
1001 if (undosAvail<stepsTotal) undosAvail++;
1003 if (curStep>stepsTotal) curStep=1;
1004 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1005 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1006 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1007 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1008 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1009 QString version=undoSet.readEntry ("/history/version");
1011 /* TODO Maybe check for version, if we save the history
1012 if (!checkVersion(version))
1013 QMessageBox::warning(0,tr("Warning"),
1014 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1017 // Find out current undo directory
1018 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1022 cout << "VymModel::redo() begin\n";
1023 cout << " undosAvail="<<undosAvail<<endl;
1024 cout << " redosAvail="<<redosAvail<<endl;
1025 cout << " curStep="<<curStep<<endl;
1026 cout << " ---------------------------"<<endl;
1027 cout << " comment="<<comment.toStdString()<<endl;
1028 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1029 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1030 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1031 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1032 cout << " ---------------------------"<<endl<<endl;
1035 // select object before redo
1036 if (!redoSelection.isEmpty())
1037 select (redoSelection);
1040 parseAtom (redoCommand);
1043 blockSaveState=blockSaveStateOrg;
1045 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1046 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1047 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1048 undoSet.writeSettings(histPath);
1050 mainWindow->updateHistory (undoSet);
1053 /* TODO remove testing
1054 cout << "ME::redo() end\n";
1055 cout << " undosAvail="<<undosAvail<<endl;
1056 cout << " redosAvail="<<redosAvail<<endl;
1057 cout << " curStep="<<curStep<<endl;
1058 cout << " ---------------------------"<<endl<<endl;
1064 bool VymModel::isRedoAvailable()
1066 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1072 void VymModel::undo()
1074 // Can we undo at all?
1075 if (undosAvail<1) return;
1077 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1079 bool blockSaveStateOrg=blockSaveState;
1080 blockSaveState=true;
1082 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1083 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1084 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1085 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1086 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1087 QString version=undoSet.readEntry ("/history/version");
1089 /* TODO Maybe check for version, if we save the history
1090 if (!checkVersion(version))
1091 QMessageBox::warning(0,tr("Warning"),
1092 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1095 // Find out current undo directory
1096 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1098 // select object before undo
1099 if (!undoSelection.isEmpty())
1100 select (undoSelection);
1104 cout << "VymModel::undo() begin\n";
1105 cout << " undosAvail="<<undosAvail<<endl;
1106 cout << " redosAvail="<<redosAvail<<endl;
1107 cout << " curStep="<<curStep<<endl;
1108 cout << " ---------------------------"<<endl;
1109 cout << " comment="<<comment.toStdString()<<endl;
1110 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1111 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1112 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1113 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1114 cout << " ---------------------------"<<endl<<endl;
1116 parseAtom (undoCommand);
1121 if (curStep<1) curStep=stepsTotal;
1125 blockSaveState=blockSaveStateOrg;
1126 /* TODO remove testing
1127 cout << "VymModel::undo() end\n";
1128 cout << " undosAvail="<<undosAvail<<endl;
1129 cout << " redosAvail="<<redosAvail<<endl;
1130 cout << " curStep="<<curStep<<endl;
1131 cout << " ---------------------------"<<endl<<endl;
1134 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1135 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1136 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1137 undoSet.writeSettings(histPath);
1139 mainWindow->updateHistory (undoSet);
1142 ensureSelectionVisible();
1145 bool VymModel::isUndoAvailable()
1147 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1153 void VymModel::gotoHistoryStep (int i)
1155 // Restore variables
1156 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1157 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1159 if (i<0) i=undosAvail+redosAvail;
1161 // Clicking above current step makes us undo things
1164 for (int j=0; j<undosAvail-i; j++) undo();
1167 // Clicking below current step makes us redo things
1169 for (int j=undosAvail; j<i; j++)
1171 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1175 // And ignore clicking the current row ;-)
1179 QString VymModel::getHistoryPath()
1181 QString histName(QString("history-%1").arg(curStep));
1182 return (tmpMapDir+"/"+histName);
1185 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
1187 sendData(redoCom); //FIXME testing
1192 if (blockSaveState) return;
1194 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1196 // Find out current undo directory
1197 if (undosAvail<stepsTotal) undosAvail++;
1199 if (curStep>stepsTotal) curStep=1;
1201 QString backupXML="";
1202 QString histDir=getHistoryPath();
1203 QString bakMapPath=histDir+"/map.xml";
1205 // Create histDir if not available
1208 makeSubDirs (histDir);
1210 // Save depending on how much needs to be saved
1212 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1214 QString undoCommand="";
1215 if (savemode==UndoCommand)
1217 undoCommand=undoCom;
1219 else if (savemode==PartOfMap )
1221 undoCommand=undoCom;
1222 undoCommand.replace ("PATH",bakMapPath);
1225 if (!backupXML.isEmpty())
1226 // Write XML Data to disk
1227 saveStringToDisk (bakMapPath,backupXML);
1229 // We would have to save all actions in a tree, to keep track of
1230 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1233 // Write the current state to disk
1234 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1235 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1236 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1237 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1238 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1239 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1240 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1241 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1242 undoSet.setEntry (QString("/history/version"),vymVersion);
1243 undoSet.writeSettings(histPath);
1247 // TODO remove after testing
1248 //cout << " into="<< histPath.toStdString()<<endl;
1249 cout << " stepsTotal="<<stepsTotal<<
1250 ", undosAvail="<<undosAvail<<
1251 ", redosAvail="<<redosAvail<<
1252 ", curStep="<<curStep<<endl;
1253 cout << " ---------------------------"<<endl;
1254 cout << " comment="<<comment.toStdString()<<endl;
1255 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1256 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1257 cout << " redoCom="<<redoCom.toStdString()<<endl;
1258 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1259 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1260 cout << " ---------------------------"<<endl;
1263 mainWindow->updateHistory (undoSet);
1269 void VymModel::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
1271 // save the selected part of the map, Undo will replace part of map
1272 QString undoSelection="";
1274 undoSelection=getSelectString(undoSel);
1276 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1277 QString redoSelection="";
1279 redoSelection=getSelectString(undoSel);
1281 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1284 saveState (PartOfMap,
1285 undoSelection, "addMapReplace (\"PATH\")",
1291 void VymModel::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
1295 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1298 QString undoSelection=getSelectString (redoSel->getParObj());
1299 QString redoSelection=getSelectString(redoSel);
1300 if (typeid(*redoSel) == typeid(BranchObj) )
1302 // save the selected branch of the map, Undo will insert part of map
1303 saveState (PartOfMap,
1304 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
1305 redoSelection, "delete ()",
1312 void VymModel::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
1314 // "Normal" savestate: save commands, selections and comment
1315 // so just save commands for undo and redo
1316 // and use current selection
1318 QString redoSelection="";
1319 if (redoSel) redoSelection=getSelectString(redoSel);
1320 QString undoSelection="";
1321 if (undoSel) undoSelection=getSelectString(undoSel);
1323 saveState (UndoCommand,
1330 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1332 // "Normal" savestate: save commands, selections and comment
1333 // so just save commands for undo and redo
1334 // and use current selection
1335 saveState (UndoCommand,
1342 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1344 // "Normal" savestate applied to model (no selection needed):
1345 // save commands and comment
1346 saveState (UndoCommand,
1354 QGraphicsScene* VymModel::getScene ()
1359 BranchObj* VymModel::first()
1361 if (mapCenters.count()>0)
1362 return mapCenters.first();
1367 BranchObj* VymModel::next(BranchObj *bo_start)
1370 BranchObj *bo=bo_start;
1373 // Try to find next branch in current MapCenter
1375 if (rbo) return rbo;
1377 // Try to find MapCenter of bo
1378 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
1380 // Try to find next MapCenter
1381 int i=mapCenters.indexOf ((MapCenterObj*)bo);
1382 if (i+2 > mapCenters.count() || i<0) return NULL;
1383 if (mapCenters.at(i+1)!=bo_start)
1384 return mapCenters.at(i+1);
1389 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
1391 LinkableMapObj *lmo;
1393 for (int i=0;i<mapCenters.count(); i++)
1395 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
1396 if (lmo) return lmo;
1401 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
1403 LinkableMapObj *lmo;
1409 part=s.section(",",0,0);
1411 num=part.right(part.length() - 3);
1412 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
1413 return mapCenters.at(num.toInt() );
1416 for (int i=0; i<mapCenters.count(); i++)
1418 lmo=mapCenters.at(i)->findObjBySelect(s);
1419 if (lmo) return lmo;
1424 LinkableMapObj* VymModel::findID (const QString &s)
1426 LinkableMapObj *lmo;
1427 for (int i=0; i<mapCenters.count(); i++)
1429 lmo=mapCenters.at(i)->findID (s);
1430 if (lmo) return lmo;
1435 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
1439 for (int i=0; i<mapCenters.count(); i++)
1440 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
1444 //////////////////////////////////////////////
1446 //////////////////////////////////////////////
1447 void VymModel::setVersion (const QString &s)
1452 void VymModel::setAuthor (const QString &s)
1455 QString ("setMapAuthor (\"%1\")").arg(author),
1456 QString ("setMapAuthor (\"%1\")").arg(s),
1457 QString ("Set author of map to \"%1\"").arg(s)
1463 QString VymModel::getAuthor()
1468 void VymModel::setComment (const QString &s)
1471 QString ("setMapComment (\"%1\")").arg(comment),
1472 QString ("setMapComment (\"%1\")").arg(s),
1473 QString ("Set comment of map")
1479 QString VymModel::getComment ()
1484 QString VymModel::getDate ()
1486 return QDate::currentDate().toString ("yyyy-MM-dd");
1489 void VymModel::setHeading(const QString &s)
1491 BranchObj *sel=getSelectedBranch();
1496 "setHeading (\""+sel->getHeading()+"\")",
1498 "setHeading (\""+s+"\")",
1499 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1500 sel->setHeading(s );
1501 /* FIXME testing only
1503 TreeItem *ti=getSelectedTreeItem();
1507 //FIXME VM ix is wrong ModelIndex below, ix2 is (hopefully) correct:
1508 //QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) );
1509 //FIXME VM testing only cout <<"VM::setHeading s="<<s.toStdString()<<" ti="<<ti<<" r,c=("<<ti->row()<<","<<ti->column()<<")"<<endl;
1510 QModelIndex ix2=index (ti);
1511 emit (dataChanged ( ix2,ix2));
1515 cout << "Warning: VM::setHeading ti==NULL\n";
1518 //cout <<" (r,c)=("<<ix2.row()<<","<<ix2.column()<<")"<<endl;
1522 ensureSelectionVisible();
1526 void VymModel::setHeadingInt(const QString &s)
1528 BranchObj *bo=getSelectedBranch();
1534 ensureSelectionVisible();
1538 BranchObj* VymModel::findText (QString s, bool cs)
1540 QTextDocument::FindFlags flags=0;
1541 if (cs) flags=QTextDocument::FindCaseSensitively;
1544 { // Nothing found or new find process
1546 // nothing found, start again
1550 bool searching=true;
1551 bool foundNote=false;
1552 while (searching && !EOFind)
1556 // Searching in Note
1557 if (itFind->getNote().contains(s,cs))
1559 if (getSelectedBranch()!=itFind)
1562 ensureSelectionVisible();
1564 if (textEditor->findText(s,flags))
1570 // Searching in Heading
1571 if (searching && itFind->getHeading().contains (s,cs) )
1574 ensureSelectionVisible();
1580 itFind=next(itFind);
1581 if (!itFind) EOFind=true;
1583 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1586 return getSelectedBranch();
1591 void VymModel::findReset()
1592 { // Necessary if text to find changes during a find process
1599 void VymModel::setScene (QGraphicsScene *s)
1601 cout << "VM::setscene scene="<<s<<endl;
1602 mapScene=s; // FIXME VM should not be necessary anymore, move all occurences to MapEditor
1603 //init(); // Here we have a mapScene set,
1604 // which is (still) needed to create MapCenters
1607 void VymModel::setURL(const QString &url)
1609 BranchObj *bo=getSelectedBranch();
1612 QString oldurl=bo->getURL();
1616 QString ("setURL (\"%1\")").arg(oldurl),
1618 QString ("setURL (\"%1\")").arg(url),
1619 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1624 ensureSelectionVisible();
1628 QString VymModel::getURL()
1630 BranchObj *bo=getSelectedBranch();
1632 return bo->getURL();
1637 QStringList VymModel::getURLs()
1640 BranchObj *bo=getSelectedBranch();
1646 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1653 void VymModel::linkFloatImageTo(const QString &dstString)
1655 FloatImageObj *fio=selection.getFloatImage();
1658 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1659 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1660 typeid(*dst)==typeid (MapCenterObj)))
1662 LinkableMapObj *dstPar=dst->getParObj();
1663 QString parString=getSelectString(dstPar);
1664 QString fioPreSelectString=getSelectString(fio);
1665 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1666 ((BranchObj*)dst)->addFloatImage (fio);
1667 selection.unselect();
1668 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1669 fio=((BranchObj*)dst)->getLastFloatImage();
1672 selection.select(fio);
1674 getSelectString(fio),
1675 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1677 QString ("linkTo (\"%1\")").arg(dstString),
1678 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1684 void VymModel::setFrameType(const FrameObj::FrameType &t)
1686 BranchObj *bo=getSelectedBranch();
1689 QString s=bo->getFrameTypeName();
1690 bo->setFrameType (t);
1691 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1692 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1698 void VymModel::setFrameType(const QString &s)
1700 BranchObj *bo=getSelectedBranch();
1703 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1704 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1705 bo->setFrameType (s);
1711 void VymModel::setFramePenColor(const QColor &c)
1713 BranchObj *bo=getSelectedBranch();
1716 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1717 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1718 bo->setFramePenColor (c);
1722 void VymModel::setFrameBrushColor(const QColor &c)
1724 BranchObj *bo=getSelectedBranch();
1727 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1728 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1729 bo->setFrameBrushColor (c);
1733 void VymModel::setFramePadding (const int &i)
1735 BranchObj *bo=getSelectedBranch();
1738 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1739 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1740 bo->setFramePadding (i);
1746 void VymModel::setFrameBorderWidth(const int &i)
1748 BranchObj *bo=getSelectedBranch();
1751 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1752 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1753 bo->setFrameBorderWidth (i);
1759 void VymModel::setIncludeImagesVer(bool b)
1761 BranchObj *bo=getSelectedBranch();
1764 QString u= b ? "false" : "true";
1765 QString r=!b ? "false" : "true";
1769 QString("setIncludeImagesVertically (%1)").arg(u),
1771 QString("setIncludeImagesVertically (%1)").arg(r),
1772 QString("Include images vertically in %1").arg(getObjectName(bo))
1774 bo->setIncludeImagesVer(b);
1779 void VymModel::setIncludeImagesHor(bool b)
1781 BranchObj *bo=getSelectedBranch();
1784 QString u= b ? "false" : "true";
1785 QString r=!b ? "false" : "true";
1789 QString("setIncludeImagesHorizontally (%1)").arg(u),
1791 QString("setIncludeImagesHorizontally (%1)").arg(r),
1792 QString("Include images horizontally in %1").arg(getObjectName(bo))
1794 bo->setIncludeImagesHor(b);
1799 void VymModel::setHideLinkUnselected (bool b)
1801 LinkableMapObj *sel=getSelectedLMO();
1803 (selectionType() == TreeItem::Branch ||
1804 selectionType() == TreeItem::MapCenter ||
1805 selectionType() == TreeItem::Image ))
1807 QString u= b ? "false" : "true";
1808 QString r=!b ? "false" : "true";
1812 QString("setHideLinkUnselected (%1)").arg(u),
1814 QString("setHideLinkUnselected (%1)").arg(r),
1815 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1817 sel->setHideLinkUnselected(b);
1821 void VymModel::setHideExport(bool b)
1823 BranchObj *bo=getSelectedBranch();
1826 bo->setHideInExport (b);
1827 QString u= b ? "false" : "true";
1828 QString r=!b ? "false" : "true";
1832 QString ("setHideExport (%1)").arg(u),
1834 QString ("setHideExport (%1)").arg(r),
1835 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r)
1840 // FIXME VM needed? scene()->update();
1844 void VymModel::toggleHideExport()
1846 BranchObj *bo=getSelectedBranch();
1848 setHideExport ( !bo->hideInExport() );
1852 void VymModel::copy()
1854 LinkableMapObj *sel=getSelectedLMO();
1856 (selectionType() == TreeItem::Branch ||
1857 selectionType() == TreeItem::MapCenter ||
1858 selectionType() == TreeItem::Image ))
1860 if (redosAvail == 0)
1863 QString s=getSelectString(sel);
1864 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1865 curClipboard=curStep;
1868 // Copy also to global clipboard, because we are at last step in history
1869 QString bakMapName(QString("history-%1").arg(curStep));
1870 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1871 copyDir (bakMapDir,clipboardDir );
1873 clipboardEmpty=false;
1879 void VymModel::pasteNoSave(const int &n)
1881 bool old=blockSaveState;
1882 blockSaveState=true;
1883 bool zippedOrg=zipped;
1884 if (redosAvail > 0 || n!=0)
1886 // Use the "historical" buffer
1887 QString bakMapName(QString("history-%1").arg(n));
1888 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1889 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1891 // Use the global buffer
1892 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1897 void VymModel::paste()
1899 BranchObj *sel=getSelectedBranch();
1902 saveStateChangingPart(
1905 QString ("paste (%1)").arg(curClipboard),
1906 QString("Paste to %1").arg( getObjectName(sel))
1913 void VymModel::cut()
1915 LinkableMapObj *sel=getSelectedLMO();
1916 if ( sel && (selectionType() == TreeItem::Branch ||
1917 selectionType()==TreeItem::MapCenter ||
1918 selectionType()==TreeItem::Image))
1920 /* No savestate! savestate is called in cutNoSave
1921 saveStateChangingPart(
1925 QString("Cut %1").arg(getObjectName(sel ))
1934 void VymModel::moveBranchUp()
1936 BranchObj* bo=getSelectedBranch();
1940 if (!bo->canMoveBranchUp()) return;
1941 par=(BranchObj*)(bo->getParObj());
1942 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1943 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1945 //FIXME VM needed? scene()->update();
1947 ensureSelectionVisible();
1951 void VymModel::moveBranchDown()
1953 BranchObj* bo=getSelectedBranch();
1957 if (!bo->canMoveBranchDown()) return;
1958 par=(BranchObj*)(bo->getParObj());
1959 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1960 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1962 //FIXME VM needed? scene()->update();
1964 ensureSelectionVisible();
1968 void VymModel::sortChildren()
1970 BranchObj* bo=getSelectedBranch();
1973 if(bo->countBranches()>1)
1975 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1978 ensureSelectionVisible();
1983 void VymModel::createMapCenter()
1985 MapCenterObj *mco=addMapCenter (QPointF (0,0) );
1989 void VymModel::createBranch()
1991 BranchObj *bo=getSelectedBranch();
1994 BranchObj *newbo=addNewBranchInt (-2); // FIXME VM Old model, merge with below
1997 QList<QVariant> cData;
1998 cData << "VM:createBranch" << "undef"<<"undef";
1999 TreeItem *parti=bo->getTreeItem();
2000 TreeItem *ti=new TreeItem (cData,parti);
2002 ti->setType (TreeItem::Branch);
2003 parti->appendChild (ti);
2007 newbo->setTreeItem (ti);
2008 select (newbo); // FIXME VM really needed here?
2013 MapCenterObj* VymModel::addMapCenter ()
2015 MapCenterObj *mco=addMapCenter (contextPos);
2016 cout <<"VM::addMCO () mapScene="<<mapScene<<endl;
2017 selection.select (mco);
2019 ensureSelectionVisible();
2024 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2025 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2030 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
2032 MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
2033 mapCenter->setMapEditor(mapEditor); //FIXME VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2034 mapCenter->move (absPos);
2035 mapCenter->setVisibility (true);
2036 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2037 mapCenters.append(mapCenter);
2040 QList<QVariant> cData;
2041 cData << "VM:addMapCenter" << "undef"<<"undef";
2042 TreeItem *ti=new TreeItem (cData,rootItem);
2043 ti->setLMO (mapCenter);
2044 ti->setType (TreeItem::MapCenter);
2045 mapCenter->setTreeItem (ti);
2046 rootItem->appendChild (ti);
2051 MapCenterObj* VymModel::removeMapCenter(MapCenterObj* mco)
2053 int i=mapCenters.indexOf (mco);
2056 mapCenters.removeAt (i);
2058 if (i>0) return mapCenters.at(i-1); // Return previous MCO
2063 MapCenterObj* VymModel::getLastMapCenter()
2065 if (mapCenters.size()>0)
2066 return mapCenters.last();
2073 BranchObj* VymModel::addNewBranchInt(int num)
2075 // Depending on pos:
2076 // -3 insert in children of parent above selection
2077 // -2 add branch to selection
2078 // -1 insert in children of parent below selection
2079 // 0..n insert in children of parent at pos
2080 BranchObj *newbo=NULL;
2081 BranchObj *bo=getSelectedBranch();
2086 // save scroll state. If scrolled, automatically select
2087 // new branch in order to tmp unscroll parent...
2088 newbo=bo->addBranch();
2093 bo=(BranchObj*)bo->getParObj();
2094 if (bo) newbo=bo->insertBranch(num);
2098 bo=(BranchObj*)bo->getParObj();
2099 if (bo) newbo=bo->insertBranch(num);
2101 if (!newbo) return NULL;
2106 BranchObj* VymModel::addNewBranch(int pos)
2108 // Different meaning than num in addNewBranchInt!
2112 BranchObj *bo = getSelectedBranch();
2113 BranchObj *newbo=NULL;
2117 // FIXME VM do we still need this in model? setCursor (Qt::ArrowCursor);
2119 newbo=addNewBranchInt (pos-2);
2127 QString ("addBranch (%1)").arg(pos),
2128 QString ("Add new branch to %1").arg(getObjectName(bo)));
2132 latestSelectionString=getSelectString(newbo);
2133 // In Network mode, the client needs to know where the new branch is,
2134 // so we have to pass on this information via saveState.
2135 // TODO: Get rid of this positioning workaround
2136 QString ps=qpointfToString (newbo->getAbsPos());
2137 sendData ("selectLatestAdded ()");
2138 sendData (QString("move %1").arg(ps));
2146 BranchObj* VymModel::addNewBranchBefore()
2148 BranchObj *newbo=NULL;
2149 BranchObj *bo = getSelectedBranch();
2150 if (bo && selectionType()==TreeItem::Branch)
2151 // We accept no MapCenterObj here, so we _have_ a parent
2153 QPointF p=bo->getRelPos();
2156 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2158 // add below selection
2159 newbo=parbo->insertBranch(bo->getNum()+1);
2162 newbo->move2RelPos (p);
2164 // Move selection to new branch
2165 bo->linkTo (newbo,-1);
2167 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2168 QString ("Add branch before %1").arg(getObjectName(bo)));
2174 latestSelectionString=selection.getSelectString();
2178 void VymModel::deleteSelection()
2180 BranchObj *bo = getSelectedBranch();
2182 if (bo && selectionType()==TreeItem::MapCenter)
2184 // BranchObj* par=(BranchObj*)(bo->getParObj());
2185 selection.unselect();
2186 /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!)
2187 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2189 bo=removeMapCenter ((MapCenterObj*)bo);
2192 selection.select (bo);
2193 ensureSelectionVisible();
2199 if (bo && selectionType()==TreeItem::Branch)
2201 QModelIndex ix=getSelectedIndex();
2203 BranchObj* par=(BranchObj*)bo->getParObj();
2205 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2206 par->removeBranch(bo);
2208 ensureSelectionVisible();
2213 FloatImageObj *fio=selection.getFloatImage();
2216 BranchObj* par=(BranchObj*)fio->getParObj();
2217 saveStateChangingPart(
2221 QString("Delete %1").arg(getObjectName(fio))
2224 par->removeFloatImage(fio);
2228 ensureSelectionVisible();
2233 void VymModel::deleteKeepChildren()
2235 BranchObj *bo=getSelectedBranch();
2239 par=(BranchObj*)(bo->getParObj());
2241 // Don't use this on mapcenter
2244 // Check if we have childs at all to keep
2245 if (bo->countBranches()==0)
2251 QPointF p=bo->getRelPos();
2252 saveStateChangingPart(
2255 "deleteKeepChildren ()",
2256 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2259 QString sel=getSelectString(bo);
2261 par->removeBranchHere(bo);
2264 getSelectedBranch()->move2RelPos (p);
2269 void VymModel::deleteChildren()
2271 BranchObj *bo=getSelectedBranch();
2274 saveStateChangingPart(
2277 "deleteChildren ()",
2278 QString( "Remove children of branch %1").arg(getObjectName(bo))
2280 bo->removeChildren();
2286 bool VymModel::scrollBranch(BranchObj *bo)
2290 if (bo->isScrolled()) return false;
2291 if (bo->countBranches()==0) return false;
2292 if (bo->getDepth()==0) return false;
2298 QString ("%1 ()").arg(u),
2300 QString ("%1 ()").arg(r),
2301 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2305 // FIXME VM needed? scene()->update();
2311 bool VymModel::unscrollBranch(BranchObj *bo)
2315 if (!bo->isScrolled()) return false;
2316 if (bo->countBranches()==0) return false;
2317 if (bo->getDepth()==0) return false;
2323 QString ("%1 ()").arg(u),
2325 QString ("%1 ()").arg(r),
2326 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2330 // FIXME VM needed? scene()->update();
2336 void VymModel::toggleScroll()
2338 BranchObj *bo=getSelectedBranch();
2339 if (selectionType()==TreeItem::Branch )
2341 if (bo->isScrolled())
2342 unscrollBranch (bo);
2348 void VymModel::unscrollChildren()
2350 BranchObj *bo=getSelectedBranch();
2356 if (bo->isScrolled()) unscrollBranch (bo);
2361 void VymModel::addFloatImage (const QPixmap &img)
2363 BranchObj *bo=getSelectedBranch();
2366 FloatImageObj *fio=bo->addFloatImage();
2368 fio->setOriginalFilename("No original filename (image added by dropevent)");
2369 QString s=getSelectString(bo);
2370 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2371 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2373 // FIXME VM needed? scene()->update();
2378 void VymModel::colorBranch (QColor c)
2380 BranchObj *bo=getSelectedBranch();
2385 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2387 QString ("colorBranch (\"%1\")").arg(c.name()),
2388 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2390 bo->setColor(c); // color branch
2394 void VymModel::colorSubtree (QColor c)
2396 BranchObj *bo=getSelectedBranch();
2399 saveStateChangingPart(
2402 QString ("colorSubtree (\"%1\")").arg(c.name()),
2403 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2405 bo->setColorSubtree (c); // color links, color children
2409 QColor VymModel::getCurrentHeadingColor()
2411 BranchObj *bo=getSelectedBranch();
2412 if (bo) return bo->getColor();
2414 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2420 void VymModel::editURL()
2422 BranchObj *bo=getSelectedBranch();
2426 QString text = QInputDialog::getText(
2427 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2428 bo->getURL(), &ok, NULL);
2430 // user entered something and pressed OK
2435 void VymModel::editLocalURL()
2437 BranchObj *bo=getSelectedBranch();
2440 QStringList filters;
2441 filters <<"All files (*)";
2442 filters << tr("Text","Filedialog") + " (*.txt)";
2443 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2444 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2445 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2446 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2447 fd->setFilters (filters);
2448 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2449 fd->setDirectory (lastFileDir);
2450 if (! bo->getVymLink().isEmpty() )
2451 fd->selectFile( bo->getURL() );
2454 if ( fd->exec() == QDialog::Accepted )
2456 lastFileDir=QDir (fd->directory().path());
2457 setURL (fd->selectedFile() );
2463 void VymModel::editHeading2URL()
2465 BranchObj *bo=getSelectedBranch();
2467 setURL (bo->getHeading());
2470 void VymModel::editBugzilla2URL()
2472 BranchObj *bo=getSelectedBranch();
2475 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2480 void VymModel::editFATE2URL()
2482 BranchObj *bo=getSelectedBranch();
2485 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2488 "setURL (\""+bo->getURL()+"\")",
2490 "setURL (\""+url+"\")",
2491 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2498 void VymModel::editVymLink()
2500 BranchObj *bo=getSelectedBranch();
2503 QStringList filters;
2504 filters <<"VYM map (*.vym)";
2505 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2506 fd->setFilters (filters);
2507 fd->setCaption(vymName+" - " +tr("Link to another map"));
2508 fd->setDirectory (lastFileDir);
2509 if (! bo->getVymLink().isEmpty() )
2510 fd->selectFile( bo->getVymLink() );
2514 if ( fd->exec() == QDialog::Accepted )
2516 lastFileDir=QDir (fd->directory().path());
2519 "setVymLink (\""+bo->getVymLink()+"\")",
2521 "setVymLink (\""+fd->selectedFile()+"\")",
2522 QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile())
2524 setVymLink (fd->selectedFile() ); // FIXME ok?
2529 void VymModel::setVymLink (const QString &s)
2531 // Internal function, no saveState needed
2532 BranchObj *bo=getSelectedBranch();
2539 ensureSelectionVisible();
2543 void VymModel::deleteVymLink()
2545 BranchObj *bo=getSelectedBranch();
2550 "setVymLink (\""+bo->getVymLink()+"\")",
2552 "setVymLink (\"\")",
2553 QString("Unset vymlink of %1").arg(getObjectName(bo))
2555 bo->setVymLink ("" );
2558 // FIXME VM needed? scene()->update();
2562 QString VymModel::getVymLink()
2564 BranchObj *bo=getSelectedBranch();
2566 return bo->getVymLink();
2572 QStringList VymModel::getVymLinks()
2575 BranchObj *bo=getSelectedBranch();
2581 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2589 void VymModel::followXLink(int i)
2591 BranchObj *bo=getSelectedBranch();
2594 bo=bo->XLinkTargetAt(i);
2597 selection.select(bo);
2598 ensureSelectionVisible();
2603 void VymModel::editXLink(int i) // FIXME VM missing saveState
2605 BranchObj *bo=getSelectedBranch();
2608 XLinkObj *xlo=bo->XLinkAt(i);
2611 EditXLinkDialog dia;
2613 dia.setSelection(bo);
2614 if (dia.exec() == QDialog::Accepted)
2616 if (dia.useSettingsGlobal() )
2618 setMapDefXLinkColor (xlo->getColor() );
2619 setMapDefXLinkWidth (xlo->getWidth() );
2621 if (dia.deleteXLink())
2622 bo->deleteXLinkAt(i);
2632 //////////////////////////////////////////////
2634 //////////////////////////////////////////////
2636 void VymModel::parseAtom(const QString &atom)
2638 BranchObj *selb=getSelectedBranch();
2644 // Split string s into command and parameters
2645 parser.parseAtom (atom);
2646 QString com=parser.getCommand();
2648 // External commands
2649 /////////////////////////////////////////////////////////////////////
2650 if (com=="addBranch")
2652 if (selection.isEmpty())
2654 parser.setError (Aborted,"Nothing selected");
2657 parser.setError (Aborted,"Type of selection is not a branch");
2662 if (parser.checkParCount(pl))
2664 if (parser.parCount()==0)
2668 n=parser.parInt (ok,0);
2669 if (ok ) addNewBranch (n);
2673 /////////////////////////////////////////////////////////////////////
2674 } else if (com=="addBranchBefore")
2676 if (selection.isEmpty())
2678 parser.setError (Aborted,"Nothing selected");
2681 parser.setError (Aborted,"Type of selection is not a branch");
2684 if (parser.parCount()==0)
2686 addNewBranchBefore ();
2689 /////////////////////////////////////////////////////////////////////
2690 } else if (com==QString("addMapCenter"))
2692 if (parser.checkParCount(2))
2694 x=parser.parDouble (ok,0);
2697 y=parser.parDouble (ok,1);
2698 if (ok) addMapCenter (QPointF(x,y));
2701 /////////////////////////////////////////////////////////////////////
2702 } else if (com==QString("addMapReplace"))
2704 if (selection.isEmpty())
2706 parser.setError (Aborted,"Nothing selected");
2709 parser.setError (Aborted,"Type of selection is not a branch");
2710 } else if (parser.checkParCount(1))
2712 //s=parser.parString (ok,0); // selection
2713 t=parser.parString (ok,0); // path to map
2714 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2715 addMapReplaceInt(getSelectString(selb),t);
2717 /////////////////////////////////////////////////////////////////////
2718 } else if (com==QString("addMapInsert"))
2720 if (selection.isEmpty())
2722 parser.setError (Aborted,"Nothing selected");
2725 parser.setError (Aborted,"Type of selection is not a branch");
2728 if (parser.checkParCount(2))
2730 t=parser.parString (ok,0); // path to map
2731 n=parser.parInt(ok,1); // position
2732 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2733 addMapInsertInt(t,n);
2736 /////////////////////////////////////////////////////////////////////
2737 } else if (com=="clearFlags")
2739 if (selection.isEmpty() )
2741 parser.setError (Aborted,"Nothing selected");
2744 parser.setError (Aborted,"Type of selection is not a branch");
2745 } else if (parser.checkParCount(0))
2747 selb->clearStandardFlags();
2748 selb->updateFlagsToolbar();
2750 /////////////////////////////////////////////////////////////////////
2751 } else if (com=="colorBranch")
2753 if (selection.isEmpty())
2755 parser.setError (Aborted,"Nothing selected");
2758 parser.setError (Aborted,"Type of selection is not a branch");
2759 } else if (parser.checkParCount(1))
2761 QColor c=parser.parColor (ok,0);
2762 if (ok) colorBranch (c);
2764 /////////////////////////////////////////////////////////////////////
2765 } else if (com=="colorSubtree")
2767 if (selection.isEmpty())
2769 parser.setError (Aborted,"Nothing selected");
2772 parser.setError (Aborted,"Type of selection is not a branch");
2773 } else if (parser.checkParCount(1))
2775 QColor c=parser.parColor (ok,0);
2776 if (ok) colorSubtree (c);
2778 /////////////////////////////////////////////////////////////////////
2779 } else if (com=="copy")
2781 if (selection.isEmpty())
2783 parser.setError (Aborted,"Nothing selected");
2786 parser.setError (Aborted,"Type of selection is not a branch");
2787 } else if (parser.checkParCount(0))
2789 //FIXME missing action for copy
2791 /////////////////////////////////////////////////////////////////////
2792 } else if (com=="cut")
2794 if (selection.isEmpty())
2796 parser.setError (Aborted,"Nothing selected");
2797 } else if ( selectionType()!=TreeItem::Branch &&
2798 selectionType()!=TreeItem::MapCenter &&
2799 selectionType()!=TreeItem::Image )
2801 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2802 } else if (parser.checkParCount(0))
2806 /////////////////////////////////////////////////////////////////////
2807 } else if (com=="delete")
2809 if (selection.isEmpty())
2811 parser.setError (Aborted,"Nothing selected");
2813 /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image )
2815 parser.setError (Aborted,"Type of selection is wrong.");
2818 else if (parser.checkParCount(0))
2822 /////////////////////////////////////////////////////////////////////
2823 } else if (com=="deleteKeepChildren")
2825 if (selection.isEmpty())
2827 parser.setError (Aborted,"Nothing selected");
2830 parser.setError (Aborted,"Type of selection is not a branch");
2831 } else if (parser.checkParCount(0))
2833 deleteKeepChildren();
2835 /////////////////////////////////////////////////////////////////////
2836 } else if (com=="deleteChildren")
2838 if (selection.isEmpty())
2840 parser.setError (Aborted,"Nothing selected");
2843 parser.setError (Aborted,"Type of selection is not a branch");
2844 } else if (parser.checkParCount(0))
2848 /////////////////////////////////////////////////////////////////////
2849 } else if (com=="exportASCII")
2853 if (parser.parCount()>=1)
2854 // Hey, we even have a filename
2855 fname=parser.parString(ok,0);
2858 parser.setError (Aborted,"Could not read filename");
2861 exportASCII (fname,false);
2863 /////////////////////////////////////////////////////////////////////
2864 } else if (com=="exportImage")
2868 if (parser.parCount()>=2)
2869 // Hey, we even have a filename
2870 fname=parser.parString(ok,0);
2873 parser.setError (Aborted,"Could not read filename");
2876 QString format="PNG";
2877 if (parser.parCount()>=2)
2879 format=parser.parString(ok,1);
2881 exportImage (fname,false,format);
2883 /////////////////////////////////////////////////////////////////////
2884 } else if (com=="exportXHTML")
2888 if (parser.parCount()>=2)
2889 // Hey, we even have a filename
2890 fname=parser.parString(ok,1);
2893 parser.setError (Aborted,"Could not read filename");
2896 exportXHTML (fname,false);
2898 /////////////////////////////////////////////////////////////////////
2899 } else if (com=="exportXML")
2903 if (parser.parCount()>=2)
2904 // Hey, we even have a filename
2905 fname=parser.parString(ok,1);
2908 parser.setError (Aborted,"Could not read filename");
2911 exportXML (fname,false);
2913 /////////////////////////////////////////////////////////////////////
2914 } else if (com=="importDir")
2916 if (selection.isEmpty())
2918 parser.setError (Aborted,"Nothing selected");
2921 parser.setError (Aborted,"Type of selection is not a branch");
2922 } else if (parser.checkParCount(1))
2924 s=parser.parString(ok,0);
2925 if (ok) importDirInt(s);
2927 /////////////////////////////////////////////////////////////////////
2928 } else if (com=="linkTo")
2930 if (selection.isEmpty())
2932 parser.setError (Aborted,"Nothing selected");
2935 if (parser.checkParCount(4))
2937 // 0 selectstring of parent
2938 // 1 num in parent (for branches)
2939 // 2,3 x,y of mainbranch or mapcenter
2940 s=parser.parString(ok,0);
2941 LinkableMapObj *dst=findObjBySelect (s);
2944 if (typeid(*dst) == typeid(BranchObj) )
2946 // Get number in parent
2947 n=parser.parInt (ok,1);
2950 selb->linkTo ((BranchObj*)(dst),n);
2953 } else if (typeid(*dst) == typeid(MapCenterObj) )
2955 selb->linkTo ((BranchObj*)(dst),-1);
2956 // Get coordinates of mainbranch
2957 x=parser.parDouble(ok,2);
2960 y=parser.parDouble(ok,3);
2970 } else if ( selectionType() == TreeItem::Image)
2972 if (parser.checkParCount(1))
2974 // 0 selectstring of parent
2975 s=parser.parString(ok,0);
2976 LinkableMapObj *dst=findObjBySelect (s);
2979 if (typeid(*dst) == typeid(BranchObj) ||
2980 typeid(*dst) == typeid(MapCenterObj))
2981 linkFloatImageTo (getSelectString(dst));
2983 parser.setError (Aborted,"Destination is not a branch");
2986 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
2987 /////////////////////////////////////////////////////////////////////
2988 } else if (com=="loadImage")
2990 if (selection.isEmpty())
2992 parser.setError (Aborted,"Nothing selected");
2995 parser.setError (Aborted,"Type of selection is not a branch");
2996 } else if (parser.checkParCount(1))
2998 s=parser.parString(ok,0);
2999 if (ok) loadFloatImageInt (s);
3001 /////////////////////////////////////////////////////////////////////
3002 } else if (com=="moveBranchUp")
3004 if (selection.isEmpty() )
3006 parser.setError (Aborted,"Nothing selected");
3009 parser.setError (Aborted,"Type of selection is not a branch");
3010 } else if (parser.checkParCount(0))
3014 /////////////////////////////////////////////////////////////////////
3015 } else if (com=="moveBranchDown")
3017 if (selection.isEmpty() )
3019 parser.setError (Aborted,"Nothing selected");
3022 parser.setError (Aborted,"Type of selection is not a branch");
3023 } else if (parser.checkParCount(0))
3027 /////////////////////////////////////////////////////////////////////
3028 } else if (com=="move")
3030 if (selection.isEmpty() )
3032 parser.setError (Aborted,"Nothing selected");
3033 } else if ( selectionType()!=TreeItem::Branch &&
3034 selectionType()!=TreeItem::MapCenter &&
3035 selectionType()!=TreeItem::Image )
3037 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3038 } else if (parser.checkParCount(2))
3040 x=parser.parDouble (ok,0);
3043 y=parser.parDouble (ok,1);
3047 /////////////////////////////////////////////////////////////////////
3048 } else if (com=="moveRel")
3050 if (selection.isEmpty() )
3052 parser.setError (Aborted,"Nothing selected");
3053 } else if ( selectionType()!=TreeItem::Branch &&
3054 selectionType()!=TreeItem::MapCenter &&
3055 selectionType()!=TreeItem::Image )
3057 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3058 } else if (parser.checkParCount(2))
3060 x=parser.parDouble (ok,0);
3063 y=parser.parDouble (ok,1);
3064 if (ok) moveRel (x,y);
3067 /////////////////////////////////////////////////////////////////////
3068 } else if (com=="nop")
3070 /////////////////////////////////////////////////////////////////////
3071 } else if (com=="paste")
3073 if (selection.isEmpty() )
3075 parser.setError (Aborted,"Nothing selected");
3078 parser.setError (Aborted,"Type of selection is not a branch");
3079 } else if (parser.checkParCount(1))
3081 n=parser.parInt (ok,0);
3082 if (ok) pasteNoSave(n);
3084 /////////////////////////////////////////////////////////////////////
3085 } else if (com=="qa")
3087 if (selection.isEmpty() )
3089 parser.setError (Aborted,"Nothing selected");
3092 parser.setError (Aborted,"Type of selection is not a branch");
3093 } else if (parser.checkParCount(4))
3096 c=parser.parString (ok,0);
3099 parser.setError (Aborted,"No comment given");
3102 s=parser.parString (ok,1);
3105 parser.setError (Aborted,"First parameter is not a string");
3108 t=parser.parString (ok,2);
3111 parser.setError (Aborted,"Condition is not a string");
3114 u=parser.parString (ok,3);
3117 parser.setError (Aborted,"Third parameter is not a string");
3122 parser.setError (Aborted,"Unknown type: "+s);
3127 parser.setError (Aborted,"Unknown operator: "+t);
3132 parser.setError (Aborted,"Type of selection is not a branch");
3135 if (selb->getHeading() == u)
3137 cout << "PASSED: " << qPrintable (c) << endl;
3140 cout << "FAILED: " << qPrintable (c) << endl;
3150 /////////////////////////////////////////////////////////////////////
3151 } else if (com=="saveImage")
3153 FloatImageObj *fio=selection.getFloatImage();
3156 parser.setError (Aborted,"Type of selection is not an image");
3157 } else if (parser.checkParCount(2))
3159 s=parser.parString(ok,0);
3162 t=parser.parString(ok,1);
3163 if (ok) saveFloatImageInt (fio,t,s);
3166 /////////////////////////////////////////////////////////////////////
3167 } else if (com=="scroll")
3169 if (selection.isEmpty() )
3171 parser.setError (Aborted,"Nothing selected");
3174 parser.setError (Aborted,"Type of selection is not a branch");
3175 } else if (parser.checkParCount(0))
3177 if (!scrollBranch (selb))
3178 parser.setError (Aborted,"Could not scroll branch");
3180 /////////////////////////////////////////////////////////////////////
3181 } else if (com=="select")
3183 if (parser.checkParCount(1))
3185 s=parser.parString(ok,0);
3188 /////////////////////////////////////////////////////////////////////
3189 } else if (com=="selectLastBranch")
3191 if (selection.isEmpty() )
3193 parser.setError (Aborted,"Nothing selected");
3196 parser.setError (Aborted,"Type of selection is not a branch");
3197 } else if (parser.checkParCount(0))
3199 BranchObj *bo=selb->getLastBranch();
3201 parser.setError (Aborted,"Could not select last branch");
3205 /////////////////////////////////////////////////////////////////////
3206 } else if (com=="selectLastImage")
3208 if (selection.isEmpty() )
3210 parser.setError (Aborted,"Nothing selected");
3213 parser.setError (Aborted,"Type of selection is not a branch");
3214 } else if (parser.checkParCount(0))
3216 FloatImageObj *fio=selb->getLastFloatImage();
3218 parser.setError (Aborted,"Could not select last image");
3222 /////////////////////////////////////////////////////////////////////
3223 } else if (com=="selectLatestAdded")
3225 if (latestSelectionString.isEmpty() )
3227 parser.setError (Aborted,"No latest added object");
3230 if (!select (latestSelectionString))
3231 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3233 /////////////////////////////////////////////////////////////////////
3234 } else if (com=="setFrameType")
3236 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3238 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3240 else if (parser.checkParCount(1))
3242 s=parser.parString(ok,0);
3243 if (ok) setFrameType (s);
3245 /////////////////////////////////////////////////////////////////////
3246 } else if (com=="setFramePenColor")
3248 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3250 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3252 else if (parser.checkParCount(1))
3254 QColor c=parser.parColor(ok,0);
3255 if (ok) setFramePenColor (c);
3257 /////////////////////////////////////////////////////////////////////
3258 } else if (com=="setFrameBrushColor")
3260 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3262 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3264 else if (parser.checkParCount(1))
3266 QColor c=parser.parColor(ok,0);
3267 if (ok) setFrameBrushColor (c);
3269 /////////////////////////////////////////////////////////////////////
3270 } else if (com=="setFramePadding")
3272 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3274 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3276 else if (parser.checkParCount(1))
3278 n=parser.parInt(ok,0);
3279 if (ok) setFramePadding(n);
3281 /////////////////////////////////////////////////////////////////////
3282 } else if (com=="setFrameBorderWidth")
3284 if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3286 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3288 else if (parser.checkParCount(1))
3290 n=parser.parInt(ok,0);
3291 if (ok) setFrameBorderWidth (n);
3293 /////////////////////////////////////////////////////////////////////
3294 } else if (com=="setMapAuthor")
3296 if (parser.checkParCount(1))
3298 s=parser.parString(ok,0);
3299 if (ok) setAuthor (s);
3301 /////////////////////////////////////////////////////////////////////
3302 } else if (com=="setMapComment")
3304 if (parser.checkParCount(1))
3306 s=parser.parString(ok,0);
3307 if (ok) setComment(s);
3309 /////////////////////////////////////////////////////////////////////
3310 } else if (com=="setMapBackgroundColor")
3312 if (selection.isEmpty() )
3314 parser.setError (Aborted,"Nothing selected");
3315 } else if (! getSelectedBranch() )
3317 parser.setError (Aborted,"Type of selection is not a branch");
3318 } else if (parser.checkParCount(1))
3320 QColor c=parser.parColor (ok,0);
3321 if (ok) setMapBackgroundColor (c);
3323 /////////////////////////////////////////////////////////////////////
3324 } else if (com=="setMapDefLinkColor")
3326 if (selection.isEmpty() )
3328 parser.setError (Aborted,"Nothing selected");
3331 parser.setError (Aborted,"Type of selection is not a branch");
3332 } else if (parser.checkParCount(1))
3334 QColor c=parser.parColor (ok,0);
3335 if (ok) setMapDefLinkColor (c);
3337 /////////////////////////////////////////////////////////////////////
3338 } else if (com=="setMapLinkStyle")
3340 if (parser.checkParCount(1))
3342 s=parser.parString (ok,0);
3343 if (ok) setMapLinkStyle(s);
3345 /////////////////////////////////////////////////////////////////////
3346 } else if (com=="setHeading")
3348 if (selection.isEmpty() )
3350 parser.setError (Aborted,"Nothing selected");
3353 parser.setError (Aborted,"Type of selection is not a branch");
3354 } else if (parser.checkParCount(1))
3356 s=parser.parString (ok,0);
3360 /////////////////////////////////////////////////////////////////////
3361 } else if (com=="setHideExport")
3363 if (selection.isEmpty() )
3365 parser.setError (Aborted,"Nothing selected");
3366 } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image)
3368 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3369 } else if (parser.checkParCount(1))
3371 b=parser.parBool(ok,0);
3372 if (ok) setHideExport (b);
3374 /////////////////////////////////////////////////////////////////////
3375 } else if (com=="setIncludeImagesHorizontally")
3377 if (selection.isEmpty() )
3379 parser.setError (Aborted,"Nothing selected");
3382 parser.setError (Aborted,"Type of selection is not a branch");
3383 } else if (parser.checkParCount(1))
3385 b=parser.parBool(ok,0);
3386 if (ok) setIncludeImagesHor(b);
3388 /////////////////////////////////////////////////////////////////////
3389 } else if (com=="setIncludeImagesVertically")
3391 if (selection.isEmpty() )
3393 parser.setError (Aborted,"Nothing selected");
3396 parser.setError (Aborted,"Type of selection is not a branch");
3397 } else if (parser.checkParCount(1))
3399 b=parser.parBool(ok,0);
3400 if (ok) setIncludeImagesVer(b);
3402 /////////////////////////////////////////////////////////////////////
3403 } else if (com=="setHideLinkUnselected")
3405 if (selection.isEmpty() )
3407 parser.setError (Aborted,"Nothing selected");
3408 } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image)
3410 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3411 } else if (parser.checkParCount(1))
3413 b=parser.parBool(ok,0);
3414 if (ok) setHideLinkUnselected(b);
3416 /////////////////////////////////////////////////////////////////////
3417 } else if (com=="setSelectionColor")
3419 if (parser.checkParCount(1))
3421 QColor c=parser.parColor (ok,0);
3422 if (ok) setSelectionColorInt (c);
3424 /////////////////////////////////////////////////////////////////////
3425 } else if (com=="setURL")
3427 if (selection.isEmpty() )
3429 parser.setError (Aborted,"Nothing selected");
3432 parser.setError (Aborted,"Type of selection is not a branch");
3433 } else if (parser.checkParCount(1))
3435 s=parser.parString (ok,0);
3438 /////////////////////////////////////////////////////////////////////
3439 } else if (com=="setVymLink")
3441 if (selection.isEmpty() )
3443 parser.setError (Aborted,"Nothing selected");
3446 parser.setError (Aborted,"Type of selection is not a branch");
3447 } else if (parser.checkParCount(1))
3449 s=parser.parString (ok,0);
3450 if (ok) setVymLink(s);
3453 /////////////////////////////////////////////////////////////////////
3454 else if (com=="setFlag")
3456 if (selection.isEmpty() )
3458 parser.setError (Aborted,"Nothing selected");
3461 parser.setError (Aborted,"Type of selection is not a branch");
3462 } else if (parser.checkParCount(1))
3464 s=parser.parString(ok,0);
3467 selb->activateStandardFlag(s);
3468 selb->updateFlagsToolbar();
3471 /////////////////////////////////////////////////////////////////////
3472 } else if (com=="setFrameType")
3474 if (selection.isEmpty() )
3476 parser.setError (Aborted,"Nothing selected");
3479 parser.setError (Aborted,"Type of selection is not a branch");
3480 } else if (parser.checkParCount(1))
3482 s=parser.parString(ok,0);
3486 /////////////////////////////////////////////////////////////////////
3487 } else if (com=="sortChildren")
3489 if (selection.isEmpty() )
3491 parser.setError (Aborted,"Nothing selected");
3494 parser.setError (Aborted,"Type of selection is not a branch");
3495 } else if (parser.checkParCount(0))
3499 /////////////////////////////////////////////////////////////////////
3500 } else if (com=="toggleFlag")
3502 if (selection.isEmpty() )
3504 parser.setError (Aborted,"Nothing selected");
3507 parser.setError (Aborted,"Type of selection is not a branch");
3508 } else if (parser.checkParCount(1))
3510 s=parser.parString(ok,0);
3513 selb->toggleStandardFlag(s);
3514 selb->updateFlagsToolbar();
3517 /////////////////////////////////////////////////////////////////////
3518 } else if (com=="unscroll")
3520 if (selection.isEmpty() )
3522 parser.setError (Aborted,"Nothing selected");
3525 parser.setError (Aborted,"Type of selection is not a branch");
3526 } else if (parser.checkParCount(0))
3528 if (!unscrollBranch (selb))
3529 parser.setError (Aborted,"Could not unscroll branch");
3531 /////////////////////////////////////////////////////////////////////
3532 } else if (com=="unscrollChildren")
3534 if (selection.isEmpty() )
3536 parser.setError (Aborted,"Nothing selected");
3539 parser.setError (Aborted,"Type of selection is not a branch");
3540 } else if (parser.checkParCount(0))
3542 unscrollChildren ();
3544 /////////////////////////////////////////////////////////////////////
3545 } else if (com=="unsetFlag")
3547 if (selection.isEmpty() )
3549 parser.setError (Aborted,"Nothing selected");
3552 parser.setError (Aborted,"Type of selection is not a branch");
3553 } else if (parser.checkParCount(1))
3555 s=parser.parString(ok,0);
3558 selb->deactivateStandardFlag(s);
3559 selb->updateFlagsToolbar();
3563 parser.setError (Aborted,"Unknown command");
3566 if (parser.errorLevel()==NoError)
3568 // setChanged(); FIXME should not be called e.g. for export?!
3573 // TODO Error handling
3574 qWarning("VymModel::parseAtom: Error!");
3575 qWarning(parser.errorMessage());
3579 void VymModel::runScript (QString script)
3581 parser.setScript (script);
3583 while (parser.next() )
3584 parseAtom(parser.getAtom());
3587 void VymModel::setExportMode (bool b)
3589 // should be called before and after exports
3590 // depending on the settings
3591 if (b && settings.value("/export/useHideExport","true")=="true")
3592 setHideTmpMode (HideExport);
3594 setHideTmpMode (HideNone);
3597 void VymModel::exportImage(QString fname, bool askName, QString format)
3601 fname=getMapName()+".png";
3608 QFileDialog *fd=new QFileDialog (NULL);
3609 fd->setCaption (tr("Export map as image"));
3610 fd->setDirectory (lastImageDir);
3611 fd->setFileMode(QFileDialog::AnyFile);
3612 fd->setFilters (imageIO.getFilters() );
3615 fl=fd->selectedFiles();
3617 format=imageIO.getType(fd->selectedFilter());
3621 setExportMode (true);
3622 QPixmap pix (getPixmap());
3623 pix.save(fname, format);
3624 setExportMode (false);
3628 void VymModel::exportXML(QString dir, bool askForName)
3632 dir=browseDirectory(NULL,tr("Export XML to directory"));
3633 if (dir =="" && !reallyWriteDirectory(dir) )
3637 // Hide stuff during export, if settings want this
3638 setExportMode (true);
3640 // Create subdirectories
3643 // write to directory
3644 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3647 file.setName ( dir + "/"+mapName+".xml");
3648 if ( !file.open( QIODevice::WriteOnly ) )
3650 // This should neverever happen
3651 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3655 // Write it finally, and write in UTF8, no matter what
3656 QTextStream ts( &file );
3657 ts.setEncoding (QTextStream::UnicodeUTF8);
3661 // Now write image, too
3662 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3664 setExportMode (false);
3667 void VymModel::exportASCII(QString fname,bool askName)
3672 ex.setFile (mapName+".txt");
3678 //ex.addFilter ("TXT (*.txt)");
3679 ex.setDir(lastImageDir);
3680 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3685 setExportMode(true);
3687 setExportMode(false);
3691 void VymModel::exportXHTML (const QString &dir, bool askForName)
3693 ExportXHTMLDialog dia(NULL);
3694 dia.setFilePath (filePath );
3695 dia.setMapName (mapName );
3697 if (dir!="") dia.setDir (dir);
3703 if (dia.exec()!=QDialog::Accepted)
3707 QDir d (dia.getDir());
3708 // Check, if warnings should be used before overwriting
3709 // the output directory
3710 if (d.exists() && d.count()>0)
3713 warn.showCancelButton (true);
3714 warn.setText(QString(
3715 "The directory %1 is not empty.\n"
3716 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3717 warn.setCaption("Warning: Directory not empty");
3718 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3720 if (warn.exec()!=QDialog::Accepted) ok=false;
3727 exportXML (dia.getDir(),false );
3728 dia.doExport(mapName );
3729 //if (dia.hasChanged()) setChanged();
3733 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3738 if (ex.setConfigFile(cf))
3740 setExportMode (true);
3741 ex.exportPresentation();
3742 setExportMode (false);
3749 //////////////////////////////////////////////
3751 //////////////////////////////////////////////
3753 void VymModel::registerEditor(QWidget *me)
3755 mapEditor=(MapEditor*)me;
3756 for (int i=0; i<mapCenters.count(); i++)
3757 mapCenters.at(i)->setMapEditor(mapEditor);
3760 void VymModel::unregisterEditor(QWidget *)
3765 void VymModel::setContextPos(QPointF p)
3770 void VymModel::unsetContextPos()
3772 contextPos=QPointF();
3775 void VymModel::updateNoteFlag()
3778 BranchObj *bo=getSelectedBranch();
3781 bo->updateNoteFlag();
3782 mainWindow->updateActions();
3786 void VymModel::updateRelPositions()
3788 for (int i=0; i<mapCenters.count(); i++)
3789 mapCenters.at(i)->updateRelPositions();
3792 void VymModel::reposition()
3794 for (int i=0;i<mapCenters.count(); i++)
3795 mapCenters.at(i)->reposition(); // for positioning heading
3798 QPolygonF VymModel::shape(BranchObj *bo)
3800 // Creating (arbitrary) shapes
3803 QRectF rb=bo->getBBox();
3804 if (bo->getDepth()==0)
3806 // Just take BBox of this mapCenter
3807 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3811 // Take union of BBox and TotalBBox
3813 QRectF ra=bo->getTotalBBox();
3814 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3817 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3820 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3822 p <<ra.bottomRight()
3824 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3827 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3832 void VymModel::moveAway(LinkableMapObj *lmo)
3836 // Move all branches and MapCenters away from lmo
3837 // to avoid collisions
3842 BranchObj *boA=(BranchObj*)lmo;
3844 for (int i=0; i<mapCenters.count(); i++)
3846 boB=mapCenters.at(i);
3849 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3852 <<" ("<<qPrintable(boA->getHeading() )<<")"
3853 <<" with ("<< qPrintable (boB->getHeading() )
3856 <<" minT="<<r.minTranslation<<endl<<endl;
3860 QPixmap VymModel::getPixmap()
3862 QRectF mapRect=getTotalBBox();
3863 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3866 pp.setRenderHints(mapEditor->renderHints());
3868 // Don't print the visualisation of selection
3869 selection.unselect();
3871 mapScene->render ( &pp,
3872 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3873 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3875 // Restore selection
3876 selection.reselect();
3882 void VymModel::setMapLinkStyle (const QString & s)
3887 case LinkableMapObj::Line :
3890 case LinkableMapObj::Parabel:
3891 snow="StyleParabel";
3893 case LinkableMapObj::PolyLine:
3894 snow="StylePolyLine";
3896 case LinkableMapObj::PolyParabel:
3897 snow="StylePolyParabel";
3900 snow="UndefinedStyle";
3905 QString("setMapLinkStyle (\"%1\")").arg(s),
3906 QString("setMapLinkStyle (\"%1\")").arg(snow),
3907 QString("Set map link style (\"%1\")").arg(s)
3911 linkstyle=LinkableMapObj::Line;
3912 else if (s=="StyleParabel")
3913 linkstyle=LinkableMapObj::Parabel;
3914 else if (s=="StylePolyLine")
3915 linkstyle=LinkableMapObj::PolyLine;
3916 else if (s=="StylePolyParabel")
3917 linkstyle=LinkableMapObj::PolyParabel;
3919 linkstyle=LinkableMapObj::UndefinedStyle;
3926 bo->setLinkStyle(bo->getDefLinkStyle());
3932 LinkableMapObj::Style VymModel::getMapLinkStyle ()
3937 void VymModel::setMapDefLinkColor(QColor col)
3939 if ( !col.isValid() ) return;
3941 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3942 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3943 QString("Set map link color to %1").arg(col.name())
3957 void VymModel::setMapLinkColorHintInt()
3959 // called from setMapLinkColorHint(lch) or at end of parse
3969 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3972 setMapLinkColorHintInt();
3975 void VymModel::toggleMapLinkColorHint()
3977 if (linkcolorhint==LinkableMapObj::HeadingColor)
3978 linkcolorhint=LinkableMapObj::DefaultColor;
3980 linkcolorhint=LinkableMapObj::HeadingColor;
3990 void VymModel::selectMapBackgroundImage ()
3992 Q3FileDialog *fd=new Q3FileDialog( NULL);
3993 fd->setMode (Q3FileDialog::ExistingFile);
3994 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3995 ImagePreview *p =new ImagePreview (fd);
3996 fd->setContentsPreviewEnabled( TRUE );
3997 fd->setContentsPreview( p, p );
3998 fd->setPreviewMode( Q3FileDialog::Contents );
3999 fd->setCaption(vymName+" - " +tr("Load background image"));
4000 fd->setDir (lastImageDir);
4003 if ( fd->exec() == QDialog::Accepted )
4005 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4006 lastImageDir=QDir (fd->dirPath());
4007 setMapBackgroundImage (fd->selectedFile());
4011 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
4013 QColor oldcol=mapScene->backgroundBrush().color();
4017 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4019 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4020 QString("Set background color of map to %1").arg(col.name()));
4023 brush.setTextureImage (QPixmap (fn));
4024 mapScene->setBackgroundBrush(brush);
4027 void VymModel::selectMapBackgroundColor()
4029 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4030 if ( !col.isValid() ) return;
4031 setMapBackgroundColor( col );
4035 void VymModel::setMapBackgroundColor(QColor col)
4037 QColor oldcol=mapScene->backgroundBrush().color();
4039 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4040 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4041 QString("Set background color of map to %1").arg(col.name()));
4042 mapScene->setBackgroundBrush(col);
4045 QColor VymModel::getMapBackgroundColor()
4047 return mapScene->backgroundBrush().color();
4051 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint()
4053 return linkcolorhint;
4056 QColor VymModel::getMapDefLinkColor()
4058 return defLinkColor;
4061 void VymModel::setMapDefXLinkColor(QColor col)
4066 QColor VymModel::getMapDefXLinkColor()
4068 return defXLinkColor;
4071 void VymModel::setMapDefXLinkWidth (int w)
4076 int VymModel::getMapDefXLinkWidth()
4078 return defXLinkWidth;
4081 void VymModel::move(const double &x, const double &y)
4083 BranchObj *bo = getSelectedBranch();
4085 (selectionType()==TreeItem::Branch ||
4086 selectionType()==TreeItem::MapCenter ||
4087 selectionType()==TreeItem::Image
4090 QPointF ap(bo->getAbsPos());
4094 QString ps=qpointfToString(ap);
4095 QString s=getSelectString();
4098 s, "move "+qpointfToString(to),
4099 QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
4107 void VymModel::moveRel (const double &x, const double &y)
4109 BranchObj *bo = getSelectedBranch();
4111 (selectionType()==TreeItem::Branch ||
4112 selectionType()==TreeItem::MapCenter ||
4113 selectionType()==TreeItem::Image
4117 QPointF rp(bo->getRelPos());
4121 QString ps=qpointfToString (bo->getRelPos());
4122 QString s=getSelectString(bo);
4125 s, "moveRel "+qpointfToString(to),
4126 QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
4127 ((OrnamentedObj*)bo)->move2RelPos (x,y);
4136 void VymModel::animate()
4138 animationTimer->stop();
4141 while (i<animObjList.size() )
4143 bo=(BranchObj*)animObjList.at(i);
4148 animObjList.removeAt(i);
4155 QItemSelection sel=selModel->selection();
4156 emit (selectionChanged(sel,sel));
4159 if (!animObjList.isEmpty()) animationTimer->start();
4163 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4165 if (bo && bo->getDepth()>0)
4168 ap.setStart (start);
4170 ap.setTicks (animationTicks);
4171 ap.setAnimated (true);
4172 bo->setAnimation (ap);
4173 animObjList.append( bo );
4174 animationTimer->setSingleShot (true);
4175 animationTimer->start(animationInterval);
4179 void VymModel::stopAnimation (MapObj *mo)
4181 int i=animObjList.indexOf(mo);
4183 animObjList.removeAt (i);
4186 void VymModel::sendSelection()
4188 if (netstate!=Server) return;
4189 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4192 void VymModel::newServer()
4196 tcpServer = new QTcpServer(this);
4197 if (!tcpServer->listen(QHostAddress::Any,port)) {
4198 QMessageBox::critical(NULL, "vym server",
4199 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4200 //FIXME needed? we are no widget any longer... close();
4203 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4205 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4208 void VymModel::connectToServer()
4211 server="salam.suse.de";
4213 clientSocket = new QTcpSocket (this);
4214 clientSocket->abort();
4215 clientSocket->connectToHost(server ,port);
4216 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4217 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4218 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4220 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4225 void VymModel::newClient()
4227 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4228 connect(newClient, SIGNAL(disconnected()),
4229 newClient, SLOT(deleteLater()));
4231 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4233 clientList.append (newClient);
4237 void VymModel::sendData(const QString &s)
4239 if (clientList.size()==0) return;
4241 // Create bytearray to send
4243 QDataStream out(&block, QIODevice::WriteOnly);
4244 out.setVersion(QDataStream::Qt_4_0);
4246 // Reserve some space for blocksize
4249 // Write sendCounter
4250 out << sendCounter++;
4255 // Go back and write blocksize so far
4256 out.device()->seek(0);
4257 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4261 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4263 for (int i=0; i<clientList.size(); ++i)
4265 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4266 clientList.at(i)->write (block);
4270 void VymModel::readData ()
4272 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4275 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4279 QDataStream in(clientSocket);
4280 in.setVersion(QDataStream::Qt_4_0);
4288 cout << " t="<<qPrintable (t)<<endl;
4294 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4296 switch (socketError) {
4297 case QAbstractSocket::RemoteHostClosedError:
4299 case QAbstractSocket::HostNotFoundError:
4300 QMessageBox::information(NULL, vymName +" Network client",
4301 "The host was not found. Please check the "
4302 "host name and port settings.");
4304 case QAbstractSocket::ConnectionRefusedError:
4305 QMessageBox::information(NULL, vymName + " Network client",
4306 "The connection was refused by the peer. "
4307 "Make sure the fortune server is running, "
4308 "and check that the host name and port "
4309 "settings are correct.");
4312 QMessageBox::information(NULL, vymName + " Network client",
4313 QString("The following error occurred: %1.")
4314 .arg(clientSocket->errorString()));
4321 void VymModel::selectMapSelectionColor()
4323 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4324 setSelectionColor (col);
4327 void VymModel::setSelectionColorInt (QColor col)
4329 if ( !col.isValid() ) return;
4331 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4332 QString("setSelectionColor (%1)").arg(col.name()),
4333 QString("Set color of selection box to %1").arg(col.name())
4336 mapEditor->setSelectionColor (col);
4339 void VymModel::updateSelection()
4341 cout << "VM::updateSelection ()\n";
4342 QItemSelection newsel=selModel->selection();
4343 updateSelection (newsel);
4346 void VymModel::updateSelection(const QItemSelection &oldsel)
4348 QItemSelection newsel=selModel->selection();
4349 cout << "VM::updateSelection new=";
4350 if (!newsel.indexes().isEmpty() )
4351 cout << newsel.indexes().first().row()<<"," << newsel.indexes().first().column();
4353 if (!oldsel.indexes().isEmpty() )
4354 cout << oldsel.indexes().first().row()<<"," << oldsel.indexes().first().column();
4356 //emit (selectionChanged(newsel,oldsel));
4357 ensureSelectionVisible();
4361 void VymModel::setSelectionColor(QColor col)
4363 if ( !col.isValid() ) return;
4365 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4366 QString("setSelectionColor (%1)").arg(col.name()),
4367 QString("Set color of selection box to %1").arg(col.name())
4369 setSelectionColorInt (col);
4372 QColor VymModel::getSelectionColor()
4374 return mapEditor->getSelectionColor();
4377 void VymModel::setHideTmpMode (HideTmpMode mode)
4380 for (int i=0;i<mapCenters.count(); i++)
4381 mapCenters.at(i)->setHideTmp (mode);
4383 // FIXME needed? scene()->update();
4387 QRectF VymModel::getTotalBBox()
4390 for (int i=0;i<mapCenters.count(); i++)
4391 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4395 //////////////////////////////////////////////
4396 // Selection related
4397 //////////////////////////////////////////////
4399 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4402 cout << "VM::setSelModel selModel="<<selModel<<endl;
4405 QItemSelectionModel* VymModel::getSelectionModel()
4410 void VymModel::setSelectionBlocked (bool b)
4415 selection.unblock();
4418 bool VymModel::isSelectionBlocked()
4420 return selection.isBlocked();
4423 bool VymModel::select ()
4425 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4427 TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
4428 return select (item->getLMO() );
4431 bool VymModel::select (const QString &s)
4433 LinkableMapObj *lmo=findObjBySelect(s);
4435 // Finally select the found object
4445 bool VymModel::select (LinkableMapObj *lmo)
4447 QItemSelection oldsel=selModel->selection();
4451 TreeItem *ti=lmo->getTreeItem();
4452 QModelIndex ix=index(ti);
4453 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4454 //updateSelection(oldsel);
4460 void VymModel::unselect()
4462 selModel->clearSelection();
4465 void VymModel::reselect()
4467 selection.reselect();
4470 void VymModel::ensureSelectionVisible()
4472 LinkableMapObj *lmo=getSelectedLMO();
4473 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4477 void VymModel::selectInt (LinkableMapObj *lmo)
4479 if (selection.select(lmo))
4481 //selection.update();
4482 sendSelection (); // FIXME VM use signal
4487 void VymModel::selectNextBranchInt()
4489 // Increase number of branch
4490 LinkableMapObj *sel=getSelectedBranch();
4493 QString s=getSelectString();
4499 part=s.section(",",-1);
4501 num=part.right(part.length() - 3);
4503 s=s.left (s.length() -num.length());
4506 num=QString ("%1").arg(num.toUInt()+1);
4510 // Try to select this one
4511 if (select (s)) return;
4513 // We have no direct successor,
4514 // try to increase the parental number in order to
4515 // find a successor with same depth
4517 int d=getSelectedLMO()->getDepth();
4522 while (!found && d>0)
4524 s=s.section (",",0,d-1);
4525 // replace substring of current depth in s with "1"
4526 part=s.section(",",-1);
4528 num=part.right(part.length() - 3);
4532 // increase number of parent
4533 num=QString ("%1").arg(num.toUInt()+1);
4534 s=s.section (",",0,d-2) + ","+ typ+num;
4537 // Special case, look at orientation
4538 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)
4539 num=QString ("%1").arg(num.toUInt()+1);
4541 num=QString ("%1").arg(num.toUInt()-1);
4546 // pad to oldDepth, select the first branch for each depth
4547 for (i=d;i<oldDepth;i++)
4552 if ( getSelectedBranch()->countBranches()>0)
4560 // try to select the freshly built string
4568 void VymModel::selectPrevBranchInt()
4570 // Decrease number of branch
4571 BranchObj *bo=getSelectedBranch();
4574 QString s=selection.getSelectString();
4580 part=s.section(",",-1);
4582 num=part.right(part.length() - 3);
4584 s=s.left (s.length() -num.length());
4586 int n=num.toInt()-1;
4589 num=QString ("%1").arg(n);
4592 // Try to select this one
4593 if (n>=0 && select (s)) return;
4595 // We have no direct precessor,
4596 // try to decrease the parental number in order to
4597 // find a precessor with same depth
4599 int d=getSelectedLMO()->getDepth();
4604 while (!found && d>0)
4606 s=s.section (",",0,d-1);
4607 // replace substring of current depth in s with "1"
4608 part=s.section(",",-1);
4610 num=part.right(part.length() - 3);
4614 // decrease number of parent
4615 num=QString ("%1").arg(num.toInt()-1);
4616 s=s.section (",",0,d-2) + ","+ typ+num;
4619 // Special case, look at orientation
4620 if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter)
4621 num=QString ("%1").arg(num.toInt()-1);
4623 num=QString ("%1").arg(num.toInt()+1);
4628 // pad to oldDepth, select the last branch for each depth
4629 for (i=d;i<oldDepth;i++)
4633 if ( getSelectedBranch()->countBranches()>0)
4634 s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 );
4641 // try to select the freshly built string
4649 void VymModel::selectUpperBranch()
4651 if (selection.isBlocked() ) return;
4653 BranchObj *bo=getSelectedBranch();
4654 if (bo && selectionType()==TreeItem::Branch)
4656 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4657 selectPrevBranchInt();
4659 if (bo->getDepth()==1)
4660 selectNextBranchInt();
4662 selectPrevBranchInt();
4666 void VymModel::selectLowerBranch()
4668 if (selection.isBlocked() ) return;
4670 BranchObj *bo=getSelectedBranch();
4671 if (bo && selectionType()==TreeItem::Branch)
4673 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4674 selectNextBranchInt();
4676 if (bo->getDepth()==1)
4677 selectPrevBranchInt();
4679 selectNextBranchInt();
4684 void VymModel::selectLeftBranch()
4686 if (selection.isBlocked() ) return;
4688 QItemSelection oldsel=selModel->selection();
4691 LinkableMapObj *sel=getSelectedBranch();
4694 if (selectionType()== TreeItem::MapCenter)
4696 QModelIndex ix=getSelectedIndex();
4697 selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect );
4700 par=(BranchObj*)(sel->getParObj());
4701 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4704 if (selectionType() == TreeItem::Branch ||
4705 selectionType() == TreeItem::Image)
4707 QModelIndex ix=getSelectedIndex();
4709 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4714 if (selectionType() == TreeItem::Branch )
4716 selectLastSelectedBranch();
4721 updateSelection (oldsel);
4725 void VymModel::selectRightBranch()
4727 if (selection.isBlocked() ) return;
4729 QItemSelection oldsel=selModel->selection();
4733 LinkableMapObj *sel=getSelectedBranch();
4736 if (selectionType()==TreeItem::MapCenter)
4738 par=getSelectedBranch();
4739 bo=par->getLastSelectedBranch();
4742 // Workaround for reselecting on left and right side
4743 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4744 bo=par->getFirstBranch();
4747 selection.select(bo);
4748 //selection.update();
4749 //ensureSelectionVisible();
4755 par=(BranchObj*)(getSelectedLMO()->getParObj());
4756 if (getSelectedLMO()->getOrientation()==LinkableMapObj::LeftOfCenter)
4758 if (selectionType() == TreeItem::Branch ||
4759 selectionType() == TreeItem::Image)
4761 QModelIndex ix=getSelectedIndex();
4763 selModel->select (ix,QItemSelectionModel::ClearAndSelect );
4767 if (selectionType() == TreeItem::Branch)
4769 bo=getSelectedBranch()->getLastSelectedBranch();
4772 selection.select(bo);
4773 //selection.update();
4774 //ensureSelectionVisible();
4780 QItemSelection newsel=selModel->selection();
4781 emit (selectionChanged(newsel,oldsel));
4782 ensureSelectionVisible();
4787 void VymModel::selectFirstBranch()
4789 BranchObj *bo1=getSelectedBranch();
4794 par=(BranchObj*)(bo1->getParObj());
4796 bo2=par->getFirstBranch();
4798 selection.select(bo2);
4800 ensureSelectionVisible();
4806 void VymModel::selectLastBranch()
4808 BranchObj *bo1=getSelectedBranch();
4813 par=(BranchObj*)(bo1->getParObj());
4815 bo2=par->getLastBranch();
4818 selection.select(bo2);
4820 ensureSelectionVisible();
4826 void VymModel::selectLastSelectedBranch()
4828 QItemSelection oldsel=selModel->selection();
4830 BranchObj *bo1=getSelectedBranch();
4834 cout << "bo1="<<bo1->getHeading().toStdString()<<endl;
4835 bo2=bo1->getLastSelectedBranch();
4838 cout << "bo2="<<bo2->getHeading().toStdString()<<endl;
4844 void VymModel::selectParent()
4846 LinkableMapObj *lmo=getSelectedLMO();
4850 par=(BranchObj*)(lmo->getParObj());
4854 ensureSelectionVisible();
4859 TreeItem::Type VymModel::selectionType()
4861 QModelIndexList list=selModel->selectedIndexes();
4862 if (list.isEmpty()) return TreeItem::Undefined;
4863 TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
4864 return ti->getType();
4868 LinkableMapObj* VymModel::getSelectedLMO()
4870 QModelIndexList list=selModel->selectedIndexes();
4871 if (!list.isEmpty() )
4873 TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
4874 TreeItem::Type type=ti->getType();
4875 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
4877 return ti->getLMO();
4883 BranchObj* VymModel::getSelectedBranch()
4885 QModelIndexList list=selModel->selectedIndexes();
4886 if (!list.isEmpty() )
4888 TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
4889 TreeItem::Type type=ti->getType();
4890 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
4892 return (BranchObj*)ti->getLMO();
4899 TreeItem* VymModel::getSelectedTreeItem()
4901 // FIXME this may not only be branch, but also float etc...
4902 BranchObj* bo=getSelectedBranch();
4903 if (bo) return bo->getTreeItem(); // FIXME VM get directly from treemodl
4907 QModelIndex VymModel::getSelectedIndex()
4909 QModelIndexList list=selModel->selectedIndexes();
4910 if (list.isEmpty() )
4911 return QModelIndex();
4913 return list.first();
4916 FloatImageObj* VymModel::getSelectedFloatImage()
4918 return selection.getFloatImage();
4921 QString VymModel::getSelectString ()
4923 return selection.getSelectString();
4926 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME VM needs to use TreeModel
4930 if (typeid(*lmo)==typeid(BranchObj) ||
4931 typeid(*lmo)==typeid(MapCenterObj) )
4933 LinkableMapObj *par=lmo->getParObj();
4936 if (lmo->getDepth() ==1)
4937 // Mainbranch, return
4938 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4940 // Branch, call myself recursively
4941 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4945 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
4946 if (i>=0) s=QString("mc:%1").arg(i);