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"
24 extern Main *mainWindow;
25 extern Settings settings;
26 extern QString tmpVymDir;
28 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()
71 while (!mapCenters.isEmpty())
72 delete mapCenters.takeFirst();
75 void VymModel::init ()
77 // We should have at least one map center to start with
78 // addMapCenter(); FIXME create this in MapEditor as long as model is part of that
90 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
91 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
92 mainWindow->updateHistory (undoSet);
100 fileName=tr("unnamed");
102 blockReposition=false;
103 blockSaveState=false;
105 autosaveTimer=new QTimer (this);
106 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
108 fileChangedTimer=new QTimer (this);
109 fileChangedTimer->start(3000);
110 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
114 selection.setModel (this);
115 selection.unselect();
122 animationUse=settings.readBoolEntry("/animation/use",false);
123 animationTicks=settings.readNumEntry("/animation/ticks",10);
124 animationInterval=settings.readNumEntry("/animation/interval",50);
126 animationTimer=new QTimer (this);
127 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
130 defLinkColor=QColor (0,0,255);
131 defXLinkColor=QColor (180,180,180);
132 linkcolorhint=LinkableMapObj::DefaultColor;
133 linkstyle=LinkableMapObj::PolyParabel;
135 defXLinkColor=QColor (230,230,230);
145 // addMapCenter(); FIXME create this in MapEditor until BO and MCO are independent of scene
149 void VymModel::makeTmpDirectories()
151 // Create unique temporary directories
152 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
153 histPath = tmpMapDir+"/history";
159 MapEditor* VymModel::getMapEditor() // FIXME better return favourite editor here
164 bool VymModel::isRepositionBlocked()
166 return blockReposition;
169 void VymModel::updateActions() // FIXME maybe don't update if blockReposition is set
171 // Tell mainwindow to update states of actions
172 mainWindow->updateActions();
177 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
179 // tmpdir temporary directory to which data will be written
180 // prefix mapname, which will be appended to images etc.
181 // writeflags Only write flags for "real" save of map, not undo
182 // offset offset of bbox of whole map in scene.
183 // Needed for XML export
189 case LinkableMapObj::Line:
192 case LinkableMapObj::Parabel:
195 case LinkableMapObj::PolyLine:
199 ls="StylePolyParabel";
203 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
205 if (linkcolorhint==LinkableMapObj::HeadingColor)
206 colhint=attribut("linkColorHint","HeadingColor");
208 QString mapAttr=attribut("version",vymVersion);
210 mapAttr+= attribut("author",author) +
211 attribut("comment",comment) +
212 attribut("date",getDate()) +
213 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
214 attribut("selectionColor", selection.getColor().name() ) +
215 attribut("linkStyle", ls ) +
216 attribut("linkColor", defLinkColor.name() ) +
217 attribut("defXLinkColor", defXLinkColor.name() ) +
218 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
220 s+=beginElement("vymmap",mapAttr);
223 // Find the used flags while traversing the tree
224 standardFlagsDefault->resetUsedCounter();
226 // Reset the counters before saving
227 // TODO constr. of FIO creates lots of objects, better do this in some other way...
228 FloatImageObj (mapScene).resetSaveCounter();
230 // Build xml recursivly
231 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
232 // Save complete map, if saveSel not set
233 s+=saveToDir(tmpdir,prefix,writeflags,offset);
236 if ( typeid(*saveSel) == typeid(BranchObj) )
238 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
239 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
241 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
244 // Save local settings
245 s+=settings.getDataXML (destPath);
248 if (!selection.isEmpty() && !saveSel )
249 s+=valueElement("select",selection.getSelectString());
252 s+=endElement("vymmap");
255 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
259 void VymModel::setFilePath(QString fpath, QString destname)
261 if (fpath.isEmpty() || fpath=="")
268 filePath=fpath; // becomes absolute path
269 fileName=fpath; // gets stripped of path
270 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
272 // If fpath is not an absolute path, complete it
273 filePath=QDir(fpath).absPath();
274 fileDir=filePath.left (1+filePath.findRev ("/"));
276 // Set short name, too. Search from behind:
277 int i=fileName.findRev("/");
278 if (i>=0) fileName=fileName.remove (0,i+1);
280 // Forget the .vym (or .xml) for name of map
281 mapName=fileName.left(fileName.findRev(".",-1,true) );
285 void VymModel::setFilePath(QString fpath)
287 setFilePath (fpath,fpath);
290 QString VymModel::getFilePath()
295 QString VymModel::getFileName()
300 QString VymModel::getMapName()
305 QString VymModel::getDestPath()
310 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
312 ErrorCode err=success;
314 parseBaseHandler *handler;
318 case VymMap: handler=new parseVYMHandler; break;
319 case FreemindMap : handler=new parseFreemindHandler; break;
321 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
322 "Unknown FileType in VymModel::load()");
328 // FIXME not needed??? model->setMapEditor(this);
329 // (map state is set later at end of load...)
332 BranchObj *bo=selection.getBranch();
333 if (!bo) return aborted;
334 if (lmode==ImportAdd)
335 saveStateChangingPart(
338 QString("addMapInsert (%1)").arg(fname),
339 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
341 saveStateChangingPart(
344 QString("addMapReplace(%1)").arg(fname),
345 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
349 // Create temporary directory for packing
351 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
354 QMessageBox::critical( 0, tr( "Critical Load Error" ),
355 tr("Couldn't create temporary directory before load\n"));
360 err=unzipDir (tmpZipDir,fname);
370 // Look for mapname.xml
371 xmlfile= fname.left(fname.findRev(".",-1,true));
372 xmlfile=xmlfile.section( '/', -1 );
373 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
374 if (!mfile.exists() )
376 // mapname.xml does not exist, well,
377 // maybe someone renamed the mapname.vym file...
378 // Try to find any .xml in the toplevel
379 // directory of the .vym file
380 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
381 if (flist.count()==1)
383 // Only one entry, take this one
384 xmlfile=tmpZipDir + "/"+flist.first();
387 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
388 *it=tmpZipDir + "/" + *it;
389 // TODO Multiple entries, load all (but only the first one into this ME)
390 //mainWindow->fileLoadFromTmp (flist);
391 //returnCode=1; // Silently forget this attempt to load
392 qWarning ("MainWindow::load (fn) multimap found...");
395 if (flist.isEmpty() )
397 QMessageBox::critical( 0, tr( "Critical Load Error" ),
398 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
401 } //file doesn't exist
403 xmlfile=mfile.name();
406 QFile file( xmlfile);
408 // I am paranoid: file should exist anyway
409 // according to check in mainwindow.
412 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
413 tr(QString("Couldn't open map %1").arg(file.name())));
417 bool blockSaveStateOrg=blockSaveState;
418 blockReposition=true;
420 QXmlInputSource source( file);
421 QXmlSimpleReader reader;
422 reader.setContentHandler( handler );
423 reader.setErrorHandler( handler );
424 handler->setModel ( this);
427 // We need to set the tmpDir in order to load files with rel. path
432 tmpdir=fname.left(fname.findRev("/",-1));
433 handler->setTmpDir (tmpdir);
434 handler->setInputFile (file.name());
435 handler->setLoadMode (lmode);
436 bool ok = reader.parse( source );
437 blockReposition=false;
438 blockSaveState=blockSaveStateOrg;
442 reposition(); // FIXME reposition the view instead...
449 autosaveTimer->stop();
452 // Reset timestamp to check for later updates of file
453 fileChangedTime=QFileInfo (destPath).lastModified();
456 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
457 tr( handler->errorProtocol() ) );
459 // Still return "success": the map maybe at least
460 // partially read by the parser
465 removeDir (QDir(tmpZipDir));
472 ErrorCode VymModel::save (const SaveMode &savemode)
476 QString safeFilePath;
478 ErrorCode err=success;
482 mapFileName=mapName+".xml";
484 // use name given by user, even if he chooses .doc
485 mapFileName=fileName;
487 // Look, if we should zip the data:
490 QMessageBox mb( vymName,
491 tr("The map %1\ndid not use the compressed "
492 "vym file format.\nWriting it uncompressed will also write images \n"
493 "and flags and thus may overwrite files in the "
494 "given directory\n\nDo you want to write the map").arg(filePath),
495 QMessageBox::Warning,
496 QMessageBox::Yes | QMessageBox::Default,
498 QMessageBox::Cancel | QMessageBox::Escape);
499 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
500 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
501 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
504 case QMessageBox::Yes:
505 // save compressed (default file format)
508 case QMessageBox::No:
512 case QMessageBox::Cancel:
519 // First backup existing file, we
520 // don't want to add to old zip archives
524 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
526 QString backupFileName(destPath + "~");
527 QFile backupFile(backupFileName);
528 if (backupFile.exists() && !backupFile.remove())
530 QMessageBox::warning(0, tr("Save Error"),
531 tr("%1\ncould not be removed before saving").arg(backupFileName));
533 else if (!f.rename(backupFileName))
535 QMessageBox::warning(0, tr("Save Error"),
536 tr("%1\ncould not be renamed before saving").arg(destPath));
543 // Create temporary directory for packing
545 tmpZipDir=makeTmpDir (ok,"vym-zip");
548 QMessageBox::critical( 0, tr( "Critical Load Error" ),
549 tr("Couldn't create temporary directory before save\n"));
553 safeFilePath=filePath;
554 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
557 // Create mapName and fileDir
558 makeSubDirs (fileDir);
561 if (savemode==CompleteMap || selection.isEmpty())
564 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
567 autosaveTimer->stop();
572 if (selection.type()==Selection::FloatImage)
575 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),selection.getBranch());
576 // TODO take care of multiselections
579 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
582 qWarning ("ME::saveStringToDisk failed!");
588 if (err==success) err=zipDir (tmpZipDir,destPath);
591 removeDir (QDir(tmpZipDir));
593 // Restore original filepath outside of tmp zip dir
594 setFilePath (safeFilePath);
598 fileChangedTime=QFileInfo (destPath).lastModified();
602 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
604 QString pathDir=path.left(path.findRev("/"));
610 // We need to parse saved XML data
611 parseVYMHandler handler;
612 QXmlInputSource source( file);
613 QXmlSimpleReader reader;
614 reader.setContentHandler( &handler );
615 reader.setErrorHandler( &handler );
616 handler.setModel ( this);
617 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
618 if (undoSel.isEmpty())
622 handler.setLoadMode (NewMap);
626 handler.setLoadMode (ImportReplace);
628 blockReposition=true;
629 bool ok = reader.parse( source );
630 blockReposition=false;
633 // This should never ever happen
634 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
635 handler.errorProtocol());
638 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
641 void VymModel::addMapInsertInt (const QString &path, int pos)
643 BranchObj *sel=selection.getBranch();
646 QString pathDir=path.left(path.findRev("/"));
652 // We need to parse saved XML data
653 parseVYMHandler handler;
654 QXmlInputSource source( file);
655 QXmlSimpleReader reader;
656 reader.setContentHandler( &handler );
657 reader.setErrorHandler( &handler );
658 handler.setModel (this);
659 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
660 handler.setLoadMode (ImportAdd);
661 blockReposition=true;
662 bool ok = reader.parse( source );
663 blockReposition=false;
666 // This should never ever happen
667 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
668 handler.errorProtocol());
670 if (sel->getDepth()>0)
671 sel->getLastBranch()->linkTo (sel,pos);
673 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
677 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
679 BranchObj *bo=selection.getBranch();
684 fio=bo->getLastFloatImage();
687 // FIXME needed? scene()->update();
693 void VymModel::loadFloatImage ()
695 BranchObj *bo=selection.getBranch();
699 Q3FileDialog *fd=new Q3FileDialog( NULL);
700 fd->setMode (Q3FileDialog::ExistingFiles);
701 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
702 ImagePreview *p =new ImagePreview (fd);
703 fd->setContentsPreviewEnabled( TRUE );
704 fd->setContentsPreview( p, p );
705 fd->setPreviewMode( Q3FileDialog::Contents );
706 fd->setCaption(vymName+" - " +tr("Load image"));
707 fd->setDir (lastImageDir);
710 if ( fd->exec() == QDialog::Accepted )
712 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
713 lastImageDir=QDir (fd->dirPath());
716 for (int j=0; j<fd->selectedFiles().count(); j++)
718 s=fd->selectedFiles().at(j);
719 fio=loadFloatImageInt (s);
722 (LinkableMapObj*)fio,
725 QString ("loadImage (%1)").arg(s ),
726 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
729 // TODO loadFIO error handling
730 qWarning ("Failed to load "+s);
738 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
743 void VymModel::saveFloatImage ()
745 FloatImageObj *fio=selection.getFloatImage();
748 QFileDialog *fd=new QFileDialog( NULL);
749 fd->setFilters (imageIO.getFilters());
750 fd->setCaption(vymName+" - " +tr("Save image"));
751 fd->setFileMode( QFileDialog::AnyFile );
752 fd->setDirectory (lastImageDir);
753 // fd->setSelection (fio->getOriginalFilename());
757 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
759 fn=fd->selectedFiles().at(0);
760 if (QFile (fn).exists() )
762 QMessageBox mb( vymName,
763 tr("The file %1 exists already.\n"
764 "Do you want to overwrite it?").arg(fn),
765 QMessageBox::Warning,
766 QMessageBox::Yes | QMessageBox::Default,
767 QMessageBox::Cancel | QMessageBox::Escape,
768 QMessageBox::NoButton );
770 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
771 mb.setButtonText( QMessageBox::No, tr("Cancel"));
774 case QMessageBox::Yes:
777 case QMessageBox::Cancel:
784 saveFloatImageInt (fio,fd->selectedFilter(),fn );
791 void VymModel::importDirInt(BranchObj *dst, QDir d)
793 BranchObj *bo=selection.getBranch();
796 // Traverse directories
797 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
798 QFileInfoList list = d.entryInfoList();
801 for (int i = 0; i < list.size(); ++i)
804 if (fi.fileName() != "." && fi.fileName() != ".." )
807 bo=dst->getLastBranch();
808 bo->setHeading (fi.fileName() );
809 bo->setColor (QColor("blue"));
811 if ( !d.cd(fi.fileName()) )
812 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
815 // Recursively add subdirs
822 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
823 list = d.entryInfoList();
825 for (int i = 0; i < list.size(); ++i)
829 bo=dst->getLastBranch();
830 bo->setHeading (fi.fileName() );
831 bo->setColor (QColor("black"));
832 if (fi.fileName().right(4) == ".vym" )
833 bo->setVymLink (fi.filePath());
838 void VymModel::importDirInt (const QString &s)
840 BranchObj *bo=selection.getBranch();
843 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
850 void VymModel::importDir()
852 BranchObj *bo=selection.getBranch();
856 filters <<"VYM map (*.vym)";
857 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
858 fd->setMode (QFileDialog::DirectoryOnly);
859 fd->setFilters (filters);
860 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
864 if ( fd->exec() == QDialog::Accepted )
866 importDirInt (fd->selectedFile() );
868 //FIXME needed? scene()->update();
874 void VymModel::autosave()
876 QDateTime now=QDateTime().currentDateTime();
878 // Disable autosave, while we have gone back in history
879 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
880 if (redosAvail>0) return;
882 // Also disable autosave for new map without filename
883 if (filePath.isEmpty()) return;
886 if (mapUnsaved &&mapChanged && settings.value ("/autosave/use",true).toBool() )
888 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
889 mainWindow->fileSave (this);
892 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
897 void VymModel::fileChanged()
899 // Check if file on disk has changed meanwhile
900 if (!filePath.isEmpty())
902 QDateTime tmod=QFileInfo (filePath).lastModified();
903 if (tmod>fileChangedTime)
905 // FIXME switch to current mapeditor and finish lineedits...
906 QMessageBox mb( vymName,
907 tr("The file of the map on disk has changed:\n\n"
908 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
909 QMessageBox::Question,
911 QMessageBox::Cancel | QMessageBox::Default,
912 QMessageBox::NoButton );
914 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
915 mb.setButtonText( QMessageBox::No, tr("Ignore"));
918 case QMessageBox::Yes:
920 load (filePath,NewMap,fileType);
921 case QMessageBox::Cancel:
922 fileChangedTime=tmod; // allow autosave to overwrite newer file!
928 bool VymModel::isDefault()
933 void VymModel::makeDefault()
939 bool VymModel::hasChanged()
944 void VymModel::setChanged()
947 autosaveTimer->start(settings.value("/autosave/ms/",300000).toInt());
955 QString VymModel::getObjectName (const LinkableMapObj *lmo)
958 if (!lmo) return QString("Error: NULL has no name!");
960 if ((typeid(*lmo) == typeid(BranchObj) ||
961 typeid(*lmo) == typeid(MapCenterObj)))
964 s=(((BranchObj*)lmo)->getHeading());
965 if (s=="") s="unnamed";
966 return QString("branch (%1)").arg(s);
968 if ((typeid(*lmo) == typeid(FloatImageObj) ))
969 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
970 return QString("Unknown type has no name!");
973 void VymModel::redo()
975 // Can we undo at all?
976 if (redosAvail<1) return;
978 bool blockSaveStateOrg=blockSaveState;
983 if (undosAvail<stepsTotal) undosAvail++;
985 if (curStep>stepsTotal) curStep=1;
986 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
987 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
988 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
989 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
990 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
991 QString version=undoSet.readEntry ("/history/version");
993 /* TODO Maybe check for version, if we save the history
994 if (!checkVersion(version))
995 QMessageBox::warning(0,tr("Warning"),
996 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
999 // Find out current undo directory
1000 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1004 cout << "VymModel::redo() begin\n";
1005 cout << " undosAvail="<<undosAvail<<endl;
1006 cout << " redosAvail="<<redosAvail<<endl;
1007 cout << " curStep="<<curStep<<endl;
1008 cout << " ---------------------------"<<endl;
1009 cout << " comment="<<comment.toStdString()<<endl;
1010 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1011 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1012 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1013 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1014 cout << " ---------------------------"<<endl<<endl;
1017 // select object before redo
1018 if (!redoSelection.isEmpty())
1019 select (redoSelection);
1022 parseAtom (redoCommand);
1025 blockSaveState=blockSaveStateOrg;
1027 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1028 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1029 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1030 undoSet.writeSettings(histPath);
1032 mainWindow->updateHistory (undoSet);
1035 /* TODO remove testing
1036 cout << "ME::redo() end\n";
1037 cout << " undosAvail="<<undosAvail<<endl;
1038 cout << " redosAvail="<<redosAvail<<endl;
1039 cout << " curStep="<<curStep<<endl;
1040 cout << " ---------------------------"<<endl<<endl;
1046 bool VymModel::isRedoAvailable()
1048 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1054 void VymModel::undo()
1056 // Can we undo at all?
1057 if (undosAvail<1) return;
1059 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1061 bool blockSaveStateOrg=blockSaveState;
1062 blockSaveState=true;
1064 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1065 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1066 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1067 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1068 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1069 QString version=undoSet.readEntry ("/history/version");
1071 /* TODO Maybe check for version, if we save the history
1072 if (!checkVersion(version))
1073 QMessageBox::warning(0,tr("Warning"),
1074 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1077 // Find out current undo directory
1078 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1080 // select object before undo
1081 if (!undoSelection.isEmpty())
1082 select (undoSelection);
1086 cout << "VymModel::undo() begin\n";
1087 cout << " undosAvail="<<undosAvail<<endl;
1088 cout << " redosAvail="<<redosAvail<<endl;
1089 cout << " curStep="<<curStep<<endl;
1090 cout << " ---------------------------"<<endl;
1091 cout << " comment="<<comment.toStdString()<<endl;
1092 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1093 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1094 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1095 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1096 cout << " ---------------------------"<<endl<<endl;
1098 parseAtom (undoCommand);
1103 if (curStep<1) curStep=stepsTotal;
1107 blockSaveState=blockSaveStateOrg;
1108 /* TODO remove testing
1109 cout << "VymModel::undo() end\n";
1110 cout << " undosAvail="<<undosAvail<<endl;
1111 cout << " redosAvail="<<redosAvail<<endl;
1112 cout << " curStep="<<curStep<<endl;
1113 cout << " ---------------------------"<<endl<<endl;
1116 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1117 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1118 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1119 undoSet.writeSettings(histPath);
1121 mainWindow->updateHistory (undoSet);
1124 ensureSelectionVisible();
1127 bool VymModel::isUndoAvailable()
1129 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1135 void VymModel::gotoHistoryStep (int i)
1137 // Restore variables
1138 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1139 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1141 if (i<0) i=undosAvail+redosAvail;
1143 // Clicking above current step makes us undo things
1146 for (int j=0; j<undosAvail-i; j++) undo();
1149 // Clicking below current step makes us redo things
1151 for (int j=undosAvail; j<i; j++)
1153 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1157 // And ignore clicking the current row ;-)
1161 QString VymModel::getHistoryPath()
1163 QString histName(QString("history-%1").arg(curStep));
1164 return (tmpMapDir+"/"+histName);
1167 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
1169 sendData(redoCom); //FIXME testing
1174 if (blockSaveState) return;
1176 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1178 // Find out current undo directory
1179 if (undosAvail<stepsTotal) undosAvail++;
1181 if (curStep>stepsTotal) curStep=1;
1183 QString backupXML="";
1184 QString histDir=getHistoryPath();
1185 QString bakMapPath=histDir+"/map.xml";
1187 // Create histDir if not available
1190 makeSubDirs (histDir);
1192 // Save depending on how much needs to be saved
1194 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1196 QString undoCommand="";
1197 if (savemode==UndoCommand)
1199 undoCommand=undoCom;
1201 else if (savemode==PartOfMap )
1203 undoCommand=undoCom;
1204 undoCommand.replace ("PATH",bakMapPath);
1207 if (!backupXML.isEmpty())
1208 // Write XML Data to disk
1209 saveStringToDisk (bakMapPath,backupXML);
1211 // We would have to save all actions in a tree, to keep track of
1212 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1215 // Write the current state to disk
1216 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1217 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1218 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1219 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1220 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1221 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1222 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1223 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1224 undoSet.setEntry (QString("/history/version"),vymVersion);
1225 undoSet.writeSettings(histPath);
1229 // TODO remove after testing
1230 //cout << " into="<< histPath.toStdString()<<endl;
1231 cout << " stepsTotal="<<stepsTotal<<
1232 ", undosAvail="<<undosAvail<<
1233 ", redosAvail="<<redosAvail<<
1234 ", curStep="<<curStep<<endl;
1235 cout << " ---------------------------"<<endl;
1236 cout << " comment="<<comment.toStdString()<<endl;
1237 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1238 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1239 cout << " redoCom="<<redoCom.toStdString()<<endl;
1240 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1241 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1242 cout << " ---------------------------"<<endl;
1245 mainWindow->updateHistory (undoSet);
1251 void VymModel::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
1253 // save the selected part of the map, Undo will replace part of map
1254 QString undoSelection="";
1256 undoSelection=getSelectString(undoSel);
1258 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1259 QString redoSelection="";
1261 redoSelection=getSelectString(undoSel);
1263 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1266 saveState (PartOfMap,
1267 undoSelection, "addMapReplace (\"PATH\")",
1273 void VymModel::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
1277 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1280 QString undoSelection=getSelectString (redoSel->getParObj());
1281 QString redoSelection=getSelectString(redoSel);
1282 if (typeid(*redoSel) == typeid(BranchObj) )
1284 // save the selected branch of the map, Undo will insert part of map
1285 saveState (PartOfMap,
1286 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
1287 redoSelection, "delete ()",
1294 void VymModel::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
1296 // "Normal" savestate: save commands, selections and comment
1297 // so just save commands for undo and redo
1298 // and use current selection
1300 QString redoSelection="";
1301 if (redoSel) redoSelection=getSelectString(redoSel);
1302 QString undoSelection="";
1303 if (undoSel) undoSelection=getSelectString(undoSel);
1305 saveState (UndoCommand,
1312 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &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
1317 saveState (UndoCommand,
1324 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1326 // "Normal" savestate applied to model (no selection needed):
1327 // save commands and comment
1328 saveState (UndoCommand,
1336 QGraphicsScene* VymModel::getScene ()
1341 BranchObj* VymModel::first()
1343 if (mapCenters.count()>0)
1344 return mapCenters.first();
1349 BranchObj* VymModel::next(BranchObj *bo_start)
1352 BranchObj *bo=bo_start;
1355 // Try to find next branch in current MapCenter
1357 if (rbo) return rbo;
1359 // Try to find MapCenter of bo
1360 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
1362 // Try to find next MapCenter
1363 int i=mapCenters.indexOf ((MapCenterObj*)bo);
1364 if (i+2 > mapCenters.count() || i<0) return NULL;
1365 if (mapCenters.at(i+1)!=bo_start)
1366 return mapCenters.at(i+1);
1371 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
1373 LinkableMapObj *lmo;
1375 for (int i=0;i<mapCenters.count(); i++)
1377 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
1378 if (lmo) return lmo;
1383 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
1385 LinkableMapObj *lmo;
1391 part=s.section(",",0,0);
1393 num=part.right(part.length() - 3);
1394 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
1395 return mapCenters.at(num.toInt() );
1398 for (int i=0; i<mapCenters.count(); i++)
1400 lmo=mapCenters.at(i)->findObjBySelect(s);
1401 if (lmo) return lmo;
1406 LinkableMapObj* VymModel::findID (const QString &s)
1408 LinkableMapObj *lmo;
1409 for (int i=0; i<mapCenters.count(); i++)
1411 lmo=mapCenters.at(i)->findID (s);
1412 if (lmo) return lmo;
1417 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
1421 for (int i=0; i<mapCenters.count(); i++)
1422 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
1426 //////////////////////////////////////////////
1428 //////////////////////////////////////////////
1429 void VymModel::setVersion (const QString &s)
1434 void VymModel::setAuthor (const QString &s)
1437 QString ("setMapAuthor (\"%1\")").arg(author),
1438 QString ("setMapAuthor (\"%1\")").arg(s),
1439 QString ("Set author of map to \"%1\"").arg(s)
1445 QString VymModel::getAuthor()
1450 void VymModel::setComment (const QString &s)
1453 QString ("setMapComment (\"%1\")").arg(comment),
1454 QString ("setMapComment (\"%1\")").arg(s),
1455 QString ("Set comment of map")
1461 QString VymModel::getComment ()
1466 QString VymModel::getDate ()
1468 return QDate::currentDate().toString ("yyyy-MM-dd");
1471 void VymModel::setHeading(const QString &s)
1473 BranchObj *sel=selection.getBranch();
1478 "setHeading (\""+sel->getHeading()+"\")",
1480 "setHeading (\""+s+"\")",
1481 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1482 sel->setHeading(s );
1485 ensureSelectionVisible();
1489 QString VymModel::getHeading(bool &ok, QPoint &p)
1491 BranchObj *bo=selection.getBranch();
1495 //p=scene->mapFromScene(bo->getAbsPos()); // FIXME this is view-dependant!!!
1496 return bo->getHeading();
1503 void VymModel::setHeadingInt(const QString &s)
1505 BranchObj *bo=selection.getBranch();
1511 ensureSelectionVisible();
1515 BranchObj* VymModel::findText (QString s, bool cs)
1517 QTextDocument::FindFlags flags=0;
1518 if (cs) flags=QTextDocument::FindCaseSensitively;
1521 { // Nothing found or new find process
1523 // nothing found, start again
1527 bool searching=true;
1528 bool foundNote=false;
1529 while (searching && !EOFind)
1533 // Searching in Note
1534 if (itFind->getNote().contains(s,cs))
1536 if (selection.single()!=itFind)
1538 selection.select(itFind);
1539 ensureSelectionVisible();
1541 if (textEditor->findText(s,flags))
1547 // Searching in Heading
1548 if (searching && itFind->getHeading().contains (s,cs) )
1550 selection.select(itFind);
1551 ensureSelectionVisible();
1557 itFind=next(itFind);
1558 if (!itFind) EOFind=true;
1560 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1563 return selection.getBranch();
1568 void VymModel::findReset()
1569 { // Necessary if text to find changes during a find process
1576 void VymModel::setScene (QGraphicsScene *s)
1579 init(); // Here we have a mapScene set,
1580 // which is (still) needed to create MapCenters
1583 void VymModel::setURL(const QString &url)
1585 BranchObj *bo=selection.getBranch();
1588 QString oldurl=bo->getURL();
1592 QString ("setURL (\"%1\")").arg(oldurl),
1594 QString ("setURL (\"%1\")").arg(url),
1595 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1600 ensureSelectionVisible();
1604 QString VymModel::getURL()
1606 BranchObj *bo=selection.getBranch();
1608 return bo->getURL();
1613 QStringList VymModel::getURLs()
1616 BranchObj *bo=selection.getBranch();
1622 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1629 void VymModel::linkFloatImageTo(const QString &dstString)
1631 FloatImageObj *fio=selection.getFloatImage();
1634 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1635 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1636 typeid(*dst)==typeid (MapCenterObj)))
1638 LinkableMapObj *dstPar=dst->getParObj();
1639 QString parString=getSelectString(dstPar);
1640 QString fioPreSelectString=getSelectString(fio);
1641 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1642 ((BranchObj*)dst)->addFloatImage (fio);
1643 selection.unselect();
1644 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1645 fio=((BranchObj*)dst)->getLastFloatImage();
1648 selection.select(fio);
1650 getSelectString(fio),
1651 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1653 QString ("linkTo (\"%1\")").arg(dstString),
1654 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1660 void VymModel::setFrameType(const FrameObj::FrameType &t)
1662 BranchObj *bo=selection.getBranch();
1665 QString s=bo->getFrameTypeName();
1666 bo->setFrameType (t);
1667 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1668 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1674 void VymModel::setFrameType(const QString &s)
1676 BranchObj *bo=selection.getBranch();
1679 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1680 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1681 bo->setFrameType (s);
1687 void VymModel::setFramePenColor(const QColor &c)
1689 BranchObj *bo=selection.getBranch();
1692 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1693 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1694 bo->setFramePenColor (c);
1698 void VymModel::setFrameBrushColor(const QColor &c)
1700 BranchObj *bo=selection.getBranch();
1703 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1704 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1705 bo->setFrameBrushColor (c);
1709 void VymModel::setFramePadding (const int &i)
1711 BranchObj *bo=selection.getBranch();
1714 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1715 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1716 bo->setFramePadding (i);
1722 void VymModel::setFrameBorderWidth(const int &i)
1724 BranchObj *bo=selection.getBranch();
1727 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1728 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1729 bo->setFrameBorderWidth (i);
1735 void VymModel::setIncludeImagesVer(bool b)
1737 BranchObj *bo=selection.getBranch();
1740 QString u= b ? "false" : "true";
1741 QString r=!b ? "false" : "true";
1745 QString("setIncludeImagesVertically (%1)").arg(u),
1747 QString("setIncludeImagesVertically (%1)").arg(r),
1748 QString("Include images vertically in %1").arg(getObjectName(bo))
1750 bo->setIncludeImagesVer(b);
1755 void VymModel::setIncludeImagesHor(bool b)
1757 BranchObj *bo=selection.getBranch();
1760 QString u= b ? "false" : "true";
1761 QString r=!b ? "false" : "true";
1765 QString("setIncludeImagesHorizontally (%1)").arg(u),
1767 QString("setIncludeImagesHorizontally (%1)").arg(r),
1768 QString("Include images horizontally in %1").arg(getObjectName(bo))
1770 bo->setIncludeImagesHor(b);
1775 void VymModel::setHideLinkUnselected (bool b)
1777 LinkableMapObj *sel=selection.single();
1779 (selection.type() == Selection::Branch ||
1780 selection.type() == Selection::MapCenter ||
1781 selection.type() == Selection::FloatImage ))
1783 QString u= b ? "false" : "true";
1784 QString r=!b ? "false" : "true";
1788 QString("setHideLinkUnselected (%1)").arg(u),
1790 QString("setHideLinkUnselected (%1)").arg(r),
1791 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1793 sel->setHideLinkUnselected(b);
1797 void VymModel::setHideExport(bool b)
1799 BranchObj *bo=selection.getBranch();
1802 bo->setHideInExport (b);
1803 QString u= b ? "false" : "true";
1804 QString r=!b ? "false" : "true";
1808 QString ("setHideExport (%1)").arg(u),
1810 QString ("setHideExport (%1)").arg(r),
1811 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r)
1816 // FIXME needed? scene()->update();
1820 void VymModel::toggleHideExport()
1822 BranchObj *bo=selection.getBranch();
1824 setHideExport ( !bo->hideInExport() );
1828 void VymModel::copy()
1830 LinkableMapObj *sel=selection.single();
1833 if (redosAvail == 0)
1836 QString s=getSelectString(sel);
1837 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1838 curClipboard=curStep;
1841 // Copy also to global clipboard, because we are at last step in history
1842 QString bakMapName(QString("history-%1").arg(curStep));
1843 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1844 copyDir (bakMapDir,clipboardDir );
1846 clipboardEmpty=false;
1852 void VymModel::pasteNoSave(const int &n)
1854 bool old=blockSaveState;
1855 blockSaveState=true;
1856 bool zippedOrg=zipped;
1857 if (redosAvail > 0 || n!=0)
1859 // Use the "historical" buffer
1860 QString bakMapName(QString("history-%1").arg(n));
1861 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1862 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1864 // Use the global buffer
1865 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1870 void VymModel::paste()
1872 BranchObj *sel=selection.getBranch();
1875 saveStateChangingPart(
1878 QString ("paste (%1)").arg(curClipboard),
1879 QString("Paste to %1").arg( getObjectName(sel))
1886 void VymModel::cut()
1888 LinkableMapObj *sel=selection.single();
1889 if ( sel && (selection.type() == Selection::Branch ||
1890 selection.type()==Selection::MapCenter ||
1891 selection.type()==Selection::FloatImage))
1893 /* No savestate! savestate is called in cutNoSave
1894 saveStateChangingPart(
1898 QString("Cut %1").arg(getObjectName(sel ))
1907 void VymModel::moveBranchUp()
1909 BranchObj* bo=selection.getBranch();
1913 if (!bo->canMoveBranchUp()) return;
1914 par=(BranchObj*)(bo->getParObj());
1915 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1916 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1918 //FIXME needed? scene()->update();
1920 ensureSelectionVisible();
1924 void VymModel::moveBranchDown()
1926 BranchObj* bo=selection.getBranch();
1930 if (!bo->canMoveBranchDown()) return;
1931 par=(BranchObj*)(bo->getParObj());
1932 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1933 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1935 //FIXME needed? scene()->update();
1937 ensureSelectionVisible();
1941 void VymModel::sortChildren()
1943 BranchObj* bo=selection.getBranch();
1946 if(bo->countBranches()>1)
1948 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1951 ensureSelectionVisible();
1956 MapCenterObj* VymModel::addMapCenter ()
1958 MapCenterObj *mco=addMapCenter (contextPos);
1959 selection.select (mco);
1961 ensureSelectionVisible();
1966 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
1967 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
1972 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
1974 MapCenterObj *mapCenter = new MapCenterObj(mapScene);
1975 mapCenter->move (absPos);
1976 mapCenter->setVisibility (true);
1977 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
1978 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
1979 mapCenters.append(mapCenter);
1983 MapCenterObj* VymModel::removeMapCenter(MapCenterObj* mco)
1985 int i=mapCenters.indexOf (mco);
1988 mapCenters.removeAt (i);
1990 if (i>0) return mapCenters.at(i-1); // Return previous MCO
1995 MapCenterObj* VymModel::getLastMapCenter()
1997 if (mapCenters.size()>0)
1998 return mapCenters.last();
2005 BranchObj* VymModel::addNewBranchInt(int num)
2007 // Depending on pos:
2008 // -3 insert in children of parent above selection
2009 // -2 add branch to selection
2010 // -1 insert in children of parent below selection
2011 // 0..n insert in children of parent at pos
2012 BranchObj *newbo=NULL;
2013 BranchObj *bo=selection.getBranch();
2018 // save scroll state. If scrolled, automatically select
2019 // new branch in order to tmp unscroll parent...
2020 newbo=bo->addBranch();
2025 bo=(BranchObj*)bo->getParObj();
2026 if (bo) newbo=bo->insertBranch(num);
2030 bo=(BranchObj*)bo->getParObj();
2031 if (bo) newbo=bo->insertBranch(num);
2033 if (!newbo) return NULL;
2038 BranchObj* VymModel::addNewBranch(int pos)
2040 // Different meaning than num in addNewBranchInt!
2044 BranchObj *bo = selection.getBranch();
2045 BranchObj *newbo=NULL;
2049 // FIXME do we still need this in model? setCursor (Qt::ArrowCursor);
2051 newbo=addNewBranchInt (pos-2);
2059 QString ("addBranch (%1)").arg(pos),
2060 QString ("Add new branch to %1").arg(getObjectName(bo)));
2064 latestSelectionString=getSelectString(newbo);
2065 // In Network mode, the client needs to know where the new branch is,
2066 // so we have to pass on this information via saveState.
2067 // TODO: Get rid of this positioning workaround
2068 QString ps=qpointfToString (newbo->getAbsPos());
2069 sendData ("selectLatestAdded ()");
2070 sendData (QString("move %1").arg(ps));
2078 BranchObj* VymModel::addNewBranchBefore()
2080 BranchObj *newbo=NULL;
2081 BranchObj *bo = selection.getBranch();
2082 if (bo && selection.type()==Selection::Branch)
2083 // We accept no MapCenterObj here, so we _have_ a parent
2085 QPointF p=bo->getRelPos();
2088 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2090 // add below selection
2091 newbo=parbo->insertBranch(bo->getNum()+1);
2094 newbo->move2RelPos (p);
2096 // Move selection to new branch
2097 bo->linkTo (newbo,-1);
2099 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2100 QString ("Add branch before %1").arg(getObjectName(bo)));
2106 latestSelectionString=selection.getSelectString();
2110 void VymModel::deleteSelection()
2112 BranchObj *bo = selection.getBranch();
2113 if (bo && selection.type()==Selection::MapCenter)
2115 // BranchObj* par=(BranchObj*)(bo->getParObj());
2116 selection.unselect();
2117 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2118 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2120 bo=removeMapCenter ((MapCenterObj*)bo);
2123 selection.select (bo);
2124 ensureSelectionVisible();
2130 if (bo && selection.type()==Selection::Branch)
2132 //FIXME need to check if any animObj is part of Branch, remove from animated obj list then
2137 BranchObj* par=(BranchObj*)bo->getParObj();
2138 selection.unselect();
2139 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2140 par->removeBranch(bo);
2141 selection.select (par);
2142 ensureSelectionVisible();
2147 FloatImageObj *fio=selection.getFloatImage();
2150 BranchObj* par=(BranchObj*)fio->getParObj();
2151 saveStateChangingPart(
2155 QString("Delete %1").arg(getObjectName(fio))
2157 selection.unselect();
2158 par->removeFloatImage(fio);
2159 selection.select (par);
2162 ensureSelectionVisible();
2167 void VymModel::deleteKeepChildren()
2169 BranchObj *bo=selection.getBranch();
2173 par=(BranchObj*)(bo->getParObj());
2174 QPointF p=bo->getRelPos();
2175 saveStateChangingPart(
2178 "deleteKeepChildren ()",
2179 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2182 QString sel=getSelectString(bo);
2184 par->removeBranchHere(bo);
2187 selection.getBranch()->move2RelPos (p);
2192 void VymModel::deleteChildren()
2194 BranchObj *bo=selection.getBranch();
2197 saveStateChangingPart(
2200 "deleteChildren ()",
2201 QString( "Remove children of branch %1").arg(getObjectName(bo))
2203 bo->removeChildren();
2209 bool VymModel::scrollBranch(BranchObj *bo)
2213 if (bo->isScrolled()) return false;
2214 if (bo->countBranches()==0) return false;
2215 if (bo->getDepth()==0) return false;
2221 QString ("%1 ()").arg(u),
2223 QString ("%1 ()").arg(r),
2224 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2228 // FIXME needed? scene()->update();
2234 bool VymModel::unscrollBranch(BranchObj *bo)
2238 if (!bo->isScrolled()) return false;
2239 if (bo->countBranches()==0) return false;
2240 if (bo->getDepth()==0) return false;
2246 QString ("%1 ()").arg(u),
2248 QString ("%1 ()").arg(r),
2249 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2253 // FIXME needed? scene()->update();
2259 void VymModel::toggleScroll()
2261 BranchObj *bo=selection.getBranch();
2262 if (selection.type()==Selection::Branch )
2264 if (bo->isScrolled())
2265 unscrollBranch (bo);
2271 void VymModel::unscrollChildren()
2273 BranchObj *bo=selection.getBranch();
2279 if (bo->isScrolled()) unscrollBranch (bo);
2284 void VymModel::addFloatImage (const QPixmap &img)
2286 BranchObj *bo=selection.getBranch();
2289 FloatImageObj *fio=bo->addFloatImage();
2291 fio->setOriginalFilename("No original filename (image added by dropevent)");
2292 QString s=getSelectString(bo);
2293 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2294 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2296 // FIXME needed? scene()->update();
2301 void VymModel::colorBranch (QColor c)
2303 BranchObj *bo=selection.getBranch();
2308 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2310 QString ("colorBranch (\"%1\")").arg(c.name()),
2311 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2313 bo->setColor(c); // color branch
2317 void VymModel::colorSubtree (QColor c)
2319 BranchObj *bo=selection.getBranch();
2322 saveStateChangingPart(
2325 QString ("colorSubtree (\"%1\")").arg(c.name()),
2326 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2328 bo->setColorSubtree (c); // color links, color children
2332 QColor VymModel::getCurrentHeadingColor()
2334 BranchObj *bo=selection.getBranch();
2335 if (bo) return bo->getColor();
2337 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2343 void VymModel::editURL()
2345 BranchObj *bo=selection.getBranch();
2349 QString text = QInputDialog::getText(
2350 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2351 bo->getURL(), &ok, NULL);
2353 // user entered something and pressed OK
2358 void VymModel::editLocalURL()
2360 BranchObj *bo=selection.getBranch();
2363 QStringList filters;
2364 filters <<"All files (*)";
2365 filters << tr("Text","Filedialog") + " (*.txt)";
2366 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2367 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2368 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2369 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2370 fd->setFilters (filters);
2371 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2372 fd->setDirectory (lastFileDir);
2373 if (! bo->getVymLink().isEmpty() )
2374 fd->selectFile( bo->getURL() );
2377 if ( fd->exec() == QDialog::Accepted )
2379 lastFileDir=QDir (fd->directory().path());
2380 setURL (fd->selectedFile() );
2386 void VymModel::editHeading2URL()
2388 BranchObj *bo=selection.getBranch();
2390 setURL (bo->getHeading());
2393 void VymModel::editBugzilla2URL()
2395 BranchObj *bo=selection.getBranch();
2398 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2403 void VymModel::editFATE2URL()
2405 BranchObj *bo=selection.getBranch();
2408 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2411 "setURL (\""+bo->getURL()+"\")",
2413 "setURL (\""+url+"\")",
2414 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2421 void VymModel::editVymLink()
2423 BranchObj *bo=selection.getBranch();
2426 QStringList filters;
2427 filters <<"VYM map (*.vym)";
2428 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2429 fd->setFilters (filters);
2430 fd->setCaption(vymName+" - " +tr("Link to another map"));
2431 fd->setDirectory (lastFileDir);
2432 if (! bo->getVymLink().isEmpty() )
2433 fd->selectFile( bo->getVymLink() );
2437 if ( fd->exec() == QDialog::Accepted )
2439 lastFileDir=QDir (fd->directory().path());
2442 "setVymLink (\""+bo->getVymLink()+"\")",
2444 "setVymLink (\""+fd->selectedFile()+"\")",
2445 QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile())
2447 setVymLink (fd->selectedFile() ); // FIXME ok?
2452 void VymModel::setVymLink (const QString &s)
2454 // Internal function, no saveState needed
2455 BranchObj *bo=selection.getBranch();
2462 ensureSelectionVisible();
2466 void VymModel::deleteVymLink()
2468 BranchObj *bo=selection.getBranch();
2473 "setVymLink (\""+bo->getVymLink()+"\")",
2475 "setVymLink (\"\")",
2476 QString("Unset vymlink of %1").arg(getObjectName(bo))
2478 bo->setVymLink ("" );
2481 // FIXME needed? scene()->update();
2485 QString VymModel::getVymLink()
2487 BranchObj *bo=selection.getBranch();
2489 return bo->getVymLink();
2495 QStringList VymModel::getVymLinks()
2498 BranchObj *bo=selection.getBranch();
2504 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2512 void VymModel::followXLink(int i)
2514 BranchObj *bo=selection.getBranch();
2517 bo=bo->XLinkTargetAt(i);
2520 selection.select(bo);
2521 ensureSelectionVisible();
2526 void VymModel::editXLink(int i) // FIXME missing saveState
2528 BranchObj *bo=selection.getBranch();
2531 XLinkObj *xlo=bo->XLinkAt(i);
2534 EditXLinkDialog dia;
2536 dia.setSelection(bo);
2537 if (dia.exec() == QDialog::Accepted)
2539 if (dia.useSettingsGlobal() )
2541 setMapDefXLinkColor (xlo->getColor() );
2542 setMapDefXLinkWidth (xlo->getWidth() );
2544 if (dia.deleteXLink())
2545 bo->deleteXLinkAt(i);
2555 //////////////////////////////////////////////
2557 //////////////////////////////////////////////
2559 void VymModel::parseAtom(const QString &atom)
2561 BranchObj *selb=selection.getBranch();
2567 // Split string s into command and parameters
2568 parser.parseAtom (atom);
2569 QString com=parser.getCommand();
2571 // External commands
2572 /////////////////////////////////////////////////////////////////////
2573 if (com=="addBranch")
2575 if (selection.isEmpty())
2577 parser.setError (Aborted,"Nothing selected");
2580 parser.setError (Aborted,"Type of selection is not a branch");
2585 if (parser.checkParCount(pl))
2587 if (parser.parCount()==0)
2591 n=parser.parInt (ok,0);
2592 if (ok ) addNewBranch (n);
2596 /////////////////////////////////////////////////////////////////////
2597 } else if (com=="addBranchBefore")
2599 if (selection.isEmpty())
2601 parser.setError (Aborted,"Nothing selected");
2604 parser.setError (Aborted,"Type of selection is not a branch");
2607 if (parser.parCount()==0)
2609 addNewBranchBefore ();
2612 /////////////////////////////////////////////////////////////////////
2613 } else if (com==QString("addMapCenter"))
2615 if (parser.checkParCount(2))
2617 x=parser.parDouble (ok,0);
2620 y=parser.parDouble (ok,1);
2621 if (ok) addMapCenter (QPointF(x,y));
2624 /////////////////////////////////////////////////////////////////////
2625 } else if (com==QString("addMapReplace"))
2627 if (selection.isEmpty())
2629 parser.setError (Aborted,"Nothing selected");
2632 parser.setError (Aborted,"Type of selection is not a branch");
2633 } else if (parser.checkParCount(1))
2635 //s=parser.parString (ok,0); // selection
2636 t=parser.parString (ok,0); // path to map
2637 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2638 addMapReplaceInt(getSelectString(selb),t);
2640 /////////////////////////////////////////////////////////////////////
2641 } else if (com==QString("addMapInsert"))
2643 if (selection.isEmpty())
2645 parser.setError (Aborted,"Nothing selected");
2648 parser.setError (Aborted,"Type of selection is not a branch");
2651 if (parser.checkParCount(2))
2653 t=parser.parString (ok,0); // path to map
2654 n=parser.parInt(ok,1); // position
2655 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2656 addMapInsertInt(t,n);
2659 /////////////////////////////////////////////////////////////////////
2660 } else if (com=="clearFlags")
2662 if (selection.isEmpty() )
2664 parser.setError (Aborted,"Nothing selected");
2667 parser.setError (Aborted,"Type of selection is not a branch");
2668 } else if (parser.checkParCount(0))
2670 selb->clearStandardFlags();
2671 selb->updateFlagsToolbar();
2673 /////////////////////////////////////////////////////////////////////
2674 } else if (com=="colorBranch")
2676 if (selection.isEmpty())
2678 parser.setError (Aborted,"Nothing selected");
2681 parser.setError (Aborted,"Type of selection is not a branch");
2682 } else if (parser.checkParCount(1))
2684 QColor c=parser.parColor (ok,0);
2685 if (ok) colorBranch (c);
2687 /////////////////////////////////////////////////////////////////////
2688 } else if (com=="colorSubtree")
2690 if (selection.isEmpty())
2692 parser.setError (Aborted,"Nothing selected");
2695 parser.setError (Aborted,"Type of selection is not a branch");
2696 } else if (parser.checkParCount(1))
2698 QColor c=parser.parColor (ok,0);
2699 if (ok) colorSubtree (c);
2701 /////////////////////////////////////////////////////////////////////
2702 } else if (com=="copy")
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(0))
2712 //FIXME missing action for copy
2714 /////////////////////////////////////////////////////////////////////
2715 } else if (com=="cut")
2717 if (selection.isEmpty())
2719 parser.setError (Aborted,"Nothing selected");
2720 } else if ( selection.type()!=Selection::Branch &&
2721 selection.type()!=Selection::MapCenter &&
2722 selection.type()!=Selection::FloatImage )
2724 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2725 } else if (parser.checkParCount(0))
2729 /////////////////////////////////////////////////////////////////////
2730 } else if (com=="delete")
2732 if (selection.isEmpty())
2734 parser.setError (Aborted,"Nothing selected");
2736 /*else if (selection.type() != Selection::Branch && selection.type() != Selection::FloatImage )
2738 parser.setError (Aborted,"Type of selection is wrong.");
2741 else if (parser.checkParCount(0))
2745 /////////////////////////////////////////////////////////////////////
2746 } else if (com=="deleteKeepChildren")
2748 if (selection.isEmpty())
2750 parser.setError (Aborted,"Nothing selected");
2753 parser.setError (Aborted,"Type of selection is not a branch");
2754 } else if (parser.checkParCount(0))
2756 deleteKeepChildren();
2758 /////////////////////////////////////////////////////////////////////
2759 } else if (com=="deleteChildren")
2761 if (selection.isEmpty())
2763 parser.setError (Aborted,"Nothing selected");
2766 parser.setError (Aborted,"Type of selection is not a branch");
2767 } else if (parser.checkParCount(0))
2771 /////////////////////////////////////////////////////////////////////
2772 } else if (com=="exportASCII")
2776 if (parser.parCount()>=1)
2777 // Hey, we even have a filename
2778 fname=parser.parString(ok,0);
2781 parser.setError (Aborted,"Could not read filename");
2784 exportASCII (fname,false);
2786 /////////////////////////////////////////////////////////////////////
2787 } else if (com=="exportImage")
2791 if (parser.parCount()>=2)
2792 // Hey, we even have a filename
2793 fname=parser.parString(ok,0);
2796 parser.setError (Aborted,"Could not read filename");
2799 QString format="PNG";
2800 if (parser.parCount()>=2)
2802 format=parser.parString(ok,1);
2804 exportImage (fname,false,format);
2806 /////////////////////////////////////////////////////////////////////
2807 } else if (com=="exportXHTML")
2811 if (parser.parCount()>=2)
2812 // Hey, we even have a filename
2813 fname=parser.parString(ok,1);
2816 parser.setError (Aborted,"Could not read filename");
2819 exportXHTML (fname,false);
2821 /////////////////////////////////////////////////////////////////////
2822 } else if (com=="exportXML")
2826 if (parser.parCount()>=2)
2827 // Hey, we even have a filename
2828 fname=parser.parString(ok,1);
2831 parser.setError (Aborted,"Could not read filename");
2834 exportXML (fname,false);
2836 /////////////////////////////////////////////////////////////////////
2837 } else if (com=="importDir")
2839 if (selection.isEmpty())
2841 parser.setError (Aborted,"Nothing selected");
2844 parser.setError (Aborted,"Type of selection is not a branch");
2845 } else if (parser.checkParCount(1))
2847 s=parser.parString(ok,0);
2848 if (ok) importDirInt(s);
2850 /////////////////////////////////////////////////////////////////////
2851 } else if (com=="linkTo")
2853 if (selection.isEmpty())
2855 parser.setError (Aborted,"Nothing selected");
2858 if (parser.checkParCount(4))
2860 // 0 selectstring of parent
2861 // 1 num in parent (for branches)
2862 // 2,3 x,y of mainbranch or mapcenter
2863 s=parser.parString(ok,0);
2864 LinkableMapObj *dst=findObjBySelect (s);
2867 if (typeid(*dst) == typeid(BranchObj) )
2869 // Get number in parent
2870 n=parser.parInt (ok,1);
2873 selb->linkTo ((BranchObj*)(dst),n);
2876 } else if (typeid(*dst) == typeid(MapCenterObj) )
2878 selb->linkTo ((BranchObj*)(dst),-1);
2879 // Get coordinates of mainbranch
2880 x=parser.parDouble(ok,2);
2883 y=parser.parDouble(ok,3);
2893 } else if ( selection.type() == Selection::FloatImage)
2895 if (parser.checkParCount(1))
2897 // 0 selectstring of parent
2898 s=parser.parString(ok,0);
2899 LinkableMapObj *dst=findObjBySelect (s);
2902 if (typeid(*dst) == typeid(BranchObj) ||
2903 typeid(*dst) == typeid(MapCenterObj))
2904 linkFloatImageTo (getSelectString(dst));
2906 parser.setError (Aborted,"Destination is not a branch");
2909 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
2910 /////////////////////////////////////////////////////////////////////
2911 } else if (com=="loadImage")
2913 if (selection.isEmpty())
2915 parser.setError (Aborted,"Nothing selected");
2918 parser.setError (Aborted,"Type of selection is not a branch");
2919 } else if (parser.checkParCount(1))
2921 s=parser.parString(ok,0);
2922 if (ok) loadFloatImageInt (s);
2924 /////////////////////////////////////////////////////////////////////
2925 } else if (com=="moveBranchUp")
2927 if (selection.isEmpty() )
2929 parser.setError (Aborted,"Nothing selected");
2932 parser.setError (Aborted,"Type of selection is not a branch");
2933 } else if (parser.checkParCount(0))
2937 /////////////////////////////////////////////////////////////////////
2938 } else if (com=="moveBranchDown")
2940 if (selection.isEmpty() )
2942 parser.setError (Aborted,"Nothing selected");
2945 parser.setError (Aborted,"Type of selection is not a branch");
2946 } else if (parser.checkParCount(0))
2950 /////////////////////////////////////////////////////////////////////
2951 } else if (com=="move")
2953 if (selection.isEmpty() )
2955 parser.setError (Aborted,"Nothing selected");
2956 } else if ( selection.type()!=Selection::Branch &&
2957 selection.type()!=Selection::MapCenter &&
2958 selection.type()!=Selection::FloatImage )
2960 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2961 } else if (parser.checkParCount(2))
2963 x=parser.parDouble (ok,0);
2966 y=parser.parDouble (ok,1);
2970 /////////////////////////////////////////////////////////////////////
2971 } else if (com=="moveRel")
2973 if (selection.isEmpty() )
2975 parser.setError (Aborted,"Nothing selected");
2976 } else if ( selection.type()!=Selection::Branch &&
2977 selection.type()!=Selection::MapCenter &&
2978 selection.type()!=Selection::FloatImage )
2980 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2981 } else if (parser.checkParCount(2))
2983 x=parser.parDouble (ok,0);
2986 y=parser.parDouble (ok,1);
2987 if (ok) moveRel (x,y);
2990 /////////////////////////////////////////////////////////////////////
2991 } else if (com=="nop")
2993 /////////////////////////////////////////////////////////////////////
2994 } else if (com=="paste")
2996 if (selection.isEmpty() )
2998 parser.setError (Aborted,"Nothing selected");
3001 parser.setError (Aborted,"Type of selection is not a branch");
3002 } else if (parser.checkParCount(1))
3004 n=parser.parInt (ok,0);
3005 if (ok) pasteNoSave(n);
3007 /////////////////////////////////////////////////////////////////////
3008 } else if (com=="qa")
3010 if (selection.isEmpty() )
3012 parser.setError (Aborted,"Nothing selected");
3015 parser.setError (Aborted,"Type of selection is not a branch");
3016 } else if (parser.checkParCount(4))
3019 c=parser.parString (ok,0);
3022 parser.setError (Aborted,"No comment given");
3025 s=parser.parString (ok,1);
3028 parser.setError (Aborted,"First parameter is not a string");
3031 t=parser.parString (ok,2);
3034 parser.setError (Aborted,"Condition is not a string");
3037 u=parser.parString (ok,3);
3040 parser.setError (Aborted,"Third parameter is not a string");
3045 parser.setError (Aborted,"Unknown type: "+s);
3050 parser.setError (Aborted,"Unknown operator: "+t);
3055 parser.setError (Aborted,"Type of selection is not a branch");
3058 if (selb->getHeading() == u)
3060 cout << "PASSED: " << qPrintable (c) << endl;
3063 cout << "FAILED: " << qPrintable (c) << endl;
3073 /////////////////////////////////////////////////////////////////////
3074 } else if (com=="saveImage")
3076 FloatImageObj *fio=selection.getFloatImage();
3079 parser.setError (Aborted,"Type of selection is not an image");
3080 } else if (parser.checkParCount(2))
3082 s=parser.parString(ok,0);
3085 t=parser.parString(ok,1);
3086 if (ok) saveFloatImageInt (fio,t,s);
3089 /////////////////////////////////////////////////////////////////////
3090 } else if (com=="scroll")
3092 if (selection.isEmpty() )
3094 parser.setError (Aborted,"Nothing selected");
3097 parser.setError (Aborted,"Type of selection is not a branch");
3098 } else if (parser.checkParCount(0))
3100 if (!scrollBranch (selb))
3101 parser.setError (Aborted,"Could not scroll branch");
3103 /////////////////////////////////////////////////////////////////////
3104 } else if (com=="select")
3106 if (parser.checkParCount(1))
3108 s=parser.parString(ok,0);
3111 /////////////////////////////////////////////////////////////////////
3112 } else if (com=="selectLastBranch")
3114 if (selection.isEmpty() )
3116 parser.setError (Aborted,"Nothing selected");
3119 parser.setError (Aborted,"Type of selection is not a branch");
3120 } else if (parser.checkParCount(0))
3122 BranchObj *bo=selb->getLastBranch();
3124 parser.setError (Aborted,"Could not select last branch");
3128 /////////////////////////////////////////////////////////////////////
3129 } else if (com=="selectLastImage")
3131 if (selection.isEmpty() )
3133 parser.setError (Aborted,"Nothing selected");
3136 parser.setError (Aborted,"Type of selection is not a branch");
3137 } else if (parser.checkParCount(0))
3139 FloatImageObj *fio=selb->getLastFloatImage();
3141 parser.setError (Aborted,"Could not select last image");
3145 /////////////////////////////////////////////////////////////////////
3146 } else if (com=="selectLatestAdded")
3148 if (latestSelectionString.isEmpty() )
3150 parser.setError (Aborted,"No latest added object");
3153 if (!select (latestSelectionString))
3154 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3156 /////////////////////////////////////////////////////////////////////
3157 } else if (com=="setFrameType")
3159 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3161 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3163 else if (parser.checkParCount(1))
3165 s=parser.parString(ok,0);
3166 if (ok) setFrameType (s);
3168 /////////////////////////////////////////////////////////////////////
3169 } else if (com=="setFramePenColor")
3171 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3173 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3175 else if (parser.checkParCount(1))
3177 QColor c=parser.parColor(ok,0);
3178 if (ok) setFramePenColor (c);
3180 /////////////////////////////////////////////////////////////////////
3181 } else if (com=="setFrameBrushColor")
3183 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3185 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3187 else if (parser.checkParCount(1))
3189 QColor c=parser.parColor(ok,0);
3190 if (ok) setFrameBrushColor (c);
3192 /////////////////////////////////////////////////////////////////////
3193 } else if (com=="setFramePadding")
3195 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3197 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3199 else if (parser.checkParCount(1))
3201 n=parser.parInt(ok,0);
3202 if (ok) setFramePadding(n);
3204 /////////////////////////////////////////////////////////////////////
3205 } else if (com=="setFrameBorderWidth")
3207 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3209 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3211 else if (parser.checkParCount(1))
3213 n=parser.parInt(ok,0);
3214 if (ok) setFrameBorderWidth (n);
3216 /////////////////////////////////////////////////////////////////////
3217 } else if (com=="setMapAuthor")
3219 if (parser.checkParCount(1))
3221 s=parser.parString(ok,0);
3222 if (ok) setAuthor (s);
3224 /////////////////////////////////////////////////////////////////////
3225 } else if (com=="setMapComment")
3227 if (parser.checkParCount(1))
3229 s=parser.parString(ok,0);
3230 if (ok) setComment(s);
3232 /////////////////////////////////////////////////////////////////////
3233 } else if (com=="setMapBackgroundColor")
3235 if (selection.isEmpty() )
3237 parser.setError (Aborted,"Nothing selected");
3238 } else if (! selection.getBranch() )
3240 parser.setError (Aborted,"Type of selection is not a branch");
3241 } else if (parser.checkParCount(1))
3243 QColor c=parser.parColor (ok,0);
3244 if (ok) setMapBackgroundColor (c);
3246 /////////////////////////////////////////////////////////////////////
3247 } else if (com=="setMapDefLinkColor")
3249 if (selection.isEmpty() )
3251 parser.setError (Aborted,"Nothing selected");
3254 parser.setError (Aborted,"Type of selection is not a branch");
3255 } else if (parser.checkParCount(1))
3257 QColor c=parser.parColor (ok,0);
3258 if (ok) setMapDefLinkColor (c);
3260 /////////////////////////////////////////////////////////////////////
3261 } else if (com=="setMapLinkStyle")
3263 if (parser.checkParCount(1))
3265 s=parser.parString (ok,0);
3266 if (ok) setMapLinkStyle(s);
3268 /////////////////////////////////////////////////////////////////////
3269 } else if (com=="setHeading")
3271 if (selection.isEmpty() )
3273 parser.setError (Aborted,"Nothing selected");
3276 parser.setError (Aborted,"Type of selection is not a branch");
3277 } else if (parser.checkParCount(1))
3279 s=parser.parString (ok,0);
3283 /////////////////////////////////////////////////////////////////////
3284 } else if (com=="setHideExport")
3286 if (selection.isEmpty() )
3288 parser.setError (Aborted,"Nothing selected");
3289 } else if (selection.type()!=Selection::Branch && selection.type() != Selection::MapCenter &&selection.type()!=Selection::FloatImage)
3291 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3292 } else if (parser.checkParCount(1))
3294 b=parser.parBool(ok,0);
3295 if (ok) setHideExport (b);
3297 /////////////////////////////////////////////////////////////////////
3298 } else if (com=="setIncludeImagesHorizontally")
3300 if (selection.isEmpty() )
3302 parser.setError (Aborted,"Nothing selected");
3305 parser.setError (Aborted,"Type of selection is not a branch");
3306 } else if (parser.checkParCount(1))
3308 b=parser.parBool(ok,0);
3309 if (ok) setIncludeImagesHor(b);
3311 /////////////////////////////////////////////////////////////////////
3312 } else if (com=="setIncludeImagesVertically")
3314 if (selection.isEmpty() )
3316 parser.setError (Aborted,"Nothing selected");
3319 parser.setError (Aborted,"Type of selection is not a branch");
3320 } else if (parser.checkParCount(1))
3322 b=parser.parBool(ok,0);
3323 if (ok) setIncludeImagesVer(b);
3325 /////////////////////////////////////////////////////////////////////
3326 } else if (com=="setHideLinkUnselected")
3328 if (selection.isEmpty() )
3330 parser.setError (Aborted,"Nothing selected");
3331 } else if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3333 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3334 } else if (parser.checkParCount(1))
3336 b=parser.parBool(ok,0);
3337 if (ok) setHideLinkUnselected(b);
3339 /////////////////////////////////////////////////////////////////////
3340 } else if (com=="setSelectionColor")
3342 if (parser.checkParCount(1))
3344 QColor c=parser.parColor (ok,0);
3345 if (ok) setSelectionColorInt (c);
3347 /////////////////////////////////////////////////////////////////////
3348 } else if (com=="setURL")
3350 if (selection.isEmpty() )
3352 parser.setError (Aborted,"Nothing selected");
3355 parser.setError (Aborted,"Type of selection is not a branch");
3356 } else if (parser.checkParCount(1))
3358 s=parser.parString (ok,0);
3361 /////////////////////////////////////////////////////////////////////
3362 } else if (com=="setVymLink")
3364 if (selection.isEmpty() )
3366 parser.setError (Aborted,"Nothing selected");
3369 parser.setError (Aborted,"Type of selection is not a branch");
3370 } else if (parser.checkParCount(1))
3372 s=parser.parString (ok,0);
3373 if (ok) setVymLink(s);
3376 /////////////////////////////////////////////////////////////////////
3377 else if (com=="setFlag")
3379 if (selection.isEmpty() )
3381 parser.setError (Aborted,"Nothing selected");
3384 parser.setError (Aborted,"Type of selection is not a branch");
3385 } else if (parser.checkParCount(1))
3387 s=parser.parString(ok,0);
3390 selb->activateStandardFlag(s);
3391 selb->updateFlagsToolbar();
3394 /////////////////////////////////////////////////////////////////////
3395 } else if (com=="setFrameType")
3397 if (selection.isEmpty() )
3399 parser.setError (Aborted,"Nothing selected");
3402 parser.setError (Aborted,"Type of selection is not a branch");
3403 } else if (parser.checkParCount(1))
3405 s=parser.parString(ok,0);
3409 /////////////////////////////////////////////////////////////////////
3410 } else if (com=="sortChildren")
3412 if (selection.isEmpty() )
3414 parser.setError (Aborted,"Nothing selected");
3417 parser.setError (Aborted,"Type of selection is not a branch");
3418 } else if (parser.checkParCount(0))
3422 /////////////////////////////////////////////////////////////////////
3423 } else if (com=="toggleFlag")
3425 if (selection.isEmpty() )
3427 parser.setError (Aborted,"Nothing selected");
3430 parser.setError (Aborted,"Type of selection is not a branch");
3431 } else if (parser.checkParCount(1))
3433 s=parser.parString(ok,0);
3436 selb->toggleStandardFlag(s);
3437 selb->updateFlagsToolbar();
3440 /////////////////////////////////////////////////////////////////////
3441 } else if (com=="unscroll")
3443 if (selection.isEmpty() )
3445 parser.setError (Aborted,"Nothing selected");
3448 parser.setError (Aborted,"Type of selection is not a branch");
3449 } else if (parser.checkParCount(0))
3451 if (!unscrollBranch (selb))
3452 parser.setError (Aborted,"Could not unscroll branch");
3454 /////////////////////////////////////////////////////////////////////
3455 } else if (com=="unscrollChildren")
3457 if (selection.isEmpty() )
3459 parser.setError (Aborted,"Nothing selected");
3462 parser.setError (Aborted,"Type of selection is not a branch");
3463 } else if (parser.checkParCount(0))
3465 unscrollChildren ();
3467 /////////////////////////////////////////////////////////////////////
3468 } else if (com=="unsetFlag")
3470 if (selection.isEmpty() )
3472 parser.setError (Aborted,"Nothing selected");
3475 parser.setError (Aborted,"Type of selection is not a branch");
3476 } else if (parser.checkParCount(1))
3478 s=parser.parString(ok,0);
3481 selb->deactivateStandardFlag(s);
3482 selb->updateFlagsToolbar();
3486 parser.setError (Aborted,"Unknown command");
3489 if (parser.errorLevel()==NoError)
3491 // setChanged(); FIXME should not be called e.g. for export?!
3496 // TODO Error handling
3497 qWarning("VymModel::parseAtom: Error!");
3498 qWarning(parser.errorMessage());
3502 void VymModel::runScript (QString script)
3504 parser.setScript (script);
3506 while (parser.next() )
3507 parseAtom(parser.getAtom());
3510 void VymModel::setExportMode (bool b)
3512 // should be called before and after exports
3513 // depending on the settings
3514 if (b && settings.value("/export/useHideExport","true")=="true")
3515 setHideTmpMode (HideExport);
3517 setHideTmpMode (HideNone);
3520 void VymModel::exportImage(QString fname, bool askName, QString format)
3524 fname=getMapName()+".png";
3531 QFileDialog *fd=new QFileDialog (NULL);
3532 fd->setCaption (tr("Export map as image"));
3533 fd->setDirectory (lastImageDir);
3534 fd->setFileMode(QFileDialog::AnyFile);
3535 fd->setFilters (imageIO.getFilters() );
3538 fl=fd->selectedFiles();
3540 format=imageIO.getType(fd->selectedFilter());
3544 setExportMode (true);
3545 QPixmap pix (getPixmap());
3546 pix.save(fname, format);
3547 setExportMode (false);
3551 void VymModel::exportXML(QString dir, bool askForName)
3555 dir=browseDirectory(NULL,tr("Export XML to directory"));
3556 if (dir =="" && !reallyWriteDirectory(dir) )
3560 // Hide stuff during export, if settings want this
3561 setExportMode (true);
3563 // Create subdirectories
3566 // write to directory
3567 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3570 file.setName ( dir + "/"+mapName+".xml");
3571 if ( !file.open( QIODevice::WriteOnly ) )
3573 // This should neverever happen
3574 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3578 // Write it finally, and write in UTF8, no matter what
3579 QTextStream ts( &file );
3580 ts.setEncoding (QTextStream::UnicodeUTF8);
3584 // Now write image, too
3585 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3587 setExportMode (false);
3590 void VymModel::exportASCII(QString fname,bool askName)
3595 ex.setFile (mapName+".txt");
3601 //ex.addFilter ("TXT (*.txt)");
3602 ex.setDir(lastImageDir);
3603 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3608 setExportMode(true);
3610 setExportMode(false);
3614 void VymModel::exportXHTML (const QString &dir, bool askForName)
3616 ExportXHTMLDialog dia(NULL);
3617 dia.setFilePath (filePath );
3618 dia.setMapName (mapName );
3620 if (dir!="") dia.setDir (dir);
3626 if (dia.exec()!=QDialog::Accepted)
3630 QDir d (dia.getDir());
3631 // Check, if warnings should be used before overwriting
3632 // the output directory
3633 if (d.exists() && d.count()>0)
3636 warn.showCancelButton (true);
3637 warn.setText(QString(
3638 "The directory %1 is not empty.\n"
3639 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3640 warn.setCaption("Warning: Directory not empty");
3641 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3643 if (warn.exec()!=QDialog::Accepted) ok=false;
3650 exportXML (dia.getDir(),false );
3651 dia.doExport(mapName );
3652 //if (dia.hasChanged()) setChanged();
3656 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3661 if (ex.setConfigFile(cf))
3663 setExportMode (true);
3664 ex.exportPresentation();
3665 setExportMode (false);
3672 //////////////////////////////////////////////
3674 //////////////////////////////////////////////
3676 void VymModel::registerEditor(QWidget *me)
3678 mapEditor=(MapEditor*)me;
3679 for (int i=0; i<mapCenters.count(); i++)
3680 mapCenters.at(i)->setMapEditor(mapEditor);
3683 void VymModel::unregisterEditor(QWidget *)
3688 void VymModel::setContextPos(QPointF p)
3693 void VymModel::unsetContextPos()
3695 contextPos=QPointF();
3698 void VymModel::updateNoteFlag()
3701 BranchObj *bo=selection.getBranch();
3704 bo->updateNoteFlag();
3705 mainWindow->updateActions();
3709 void VymModel::updateRelPositions()
3711 for (int i=0; i<mapCenters.count(); i++)
3712 mapCenters.at(i)->updateRelPositions();
3715 void VymModel::reposition()
3717 for (int i=0;i<mapCenters.count(); i++)
3718 mapCenters.at(i)->reposition(); // for positioning heading
3721 QPolygonF VymModel::shape(BranchObj *bo)
3723 // Creating (arbitrary) shapes
3726 QRectF rb=bo->getBBox();
3727 if (bo->getDepth()==0)
3729 // Just take BBox of this mapCenter
3730 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3734 // Take union of BBox and TotalBBox
3736 QRectF ra=bo->getTotalBBox();
3737 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3740 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3743 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3745 p <<ra.bottomRight()
3747 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3750 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3755 void VymModel::moveAway(LinkableMapObj *lmo)
3759 // Move all branches and MapCenters away from lmo
3760 // to avoid collisions
3765 BranchObj *boA=(BranchObj*)lmo;
3767 for (int i=0; i<mapCenters.count(); i++)
3769 boB=mapCenters.at(i);
3772 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3775 <<" ("<<qPrintable(boA->getHeading() )<<")"
3776 <<" with ("<< qPrintable (boB->getHeading() )
3779 <<" minT="<<r.minTranslation<<endl<<endl;
3783 QPixmap VymModel::getPixmap()
3785 QRectF mapRect=getTotalBBox();
3786 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3789 pp.setRenderHints(mapEditor->renderHints());
3791 // Don't print the visualisation of selection
3792 selection.unselect();
3794 mapScene->render ( &pp,
3795 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3796 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3798 // Restore selection
3799 selection.reselect();
3805 void VymModel::setMapLinkStyle (const QString & s)
3808 if (linkstyle==LinkableMapObj::Line)
3810 else if (linkstyle==LinkableMapObj::Parabel)
3811 snow="StyleParabel";
3812 else if (linkstyle==LinkableMapObj::PolyLine)
3813 snow="StylePolyLine";
3814 else if (linkstyle==LinkableMapObj::PolyParabel)
3815 snow="StyleParabel";
3818 QString("setMapLinkStyle (\"%1\")").arg(s),
3819 QString("setMapLinkStyle (\"%1\")").arg(snow),
3820 QString("Set map link style (\"%1\")").arg(s)
3824 linkstyle=LinkableMapObj::Line;
3825 else if (s=="StyleParabel")
3826 linkstyle=LinkableMapObj::Parabel;
3827 else if (s=="StylePolyLine")
3828 linkstyle=LinkableMapObj::PolyLine;
3830 linkstyle=LinkableMapObj::PolyParabel;
3837 bo->setLinkStyle(bo->getDefLinkStyle());
3843 LinkableMapObj::Style VymModel::getMapLinkStyle ()
3848 void VymModel::setMapDefLinkColor(QColor col)
3850 if ( !col.isValid() ) return;
3852 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3853 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3854 QString("Set map link color to %1").arg(col.name())
3868 void VymModel::setMapLinkColorHintInt()
3870 // called from setMapLinkColorHint(lch) or at end of parse
3880 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3883 setMapLinkColorHintInt();
3886 void VymModel::toggleMapLinkColorHint()
3888 if (linkcolorhint==LinkableMapObj::HeadingColor)
3889 linkcolorhint=LinkableMapObj::DefaultColor;
3891 linkcolorhint=LinkableMapObj::HeadingColor;
3901 void VymModel::selectMapBackgroundImage ()
3903 Q3FileDialog *fd=new Q3FileDialog( NULL);
3904 fd->setMode (Q3FileDialog::ExistingFile);
3905 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3906 ImagePreview *p =new ImagePreview (fd);
3907 fd->setContentsPreviewEnabled( TRUE );
3908 fd->setContentsPreview( p, p );
3909 fd->setPreviewMode( Q3FileDialog::Contents );
3910 fd->setCaption(vymName+" - " +tr("Load background image"));
3911 fd->setDir (lastImageDir);
3914 if ( fd->exec() == QDialog::Accepted )
3916 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3917 lastImageDir=QDir (fd->dirPath());
3918 setMapBackgroundImage (fd->selectedFile());
3922 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3924 QColor oldcol=mapScene->backgroundBrush().color();
3928 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3930 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3931 QString("Set background color of map to %1").arg(col.name()));
3934 brush.setTextureImage (QPixmap (fn));
3935 mapScene->setBackgroundBrush(brush);
3938 void VymModel::selectMapBackgroundColor()
3940 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
3941 if ( !col.isValid() ) return;
3942 setMapBackgroundColor( col );
3946 void VymModel::setMapBackgroundColor(QColor col)
3948 QColor oldcol=mapScene->backgroundBrush().color();
3950 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3951 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3952 QString("Set background color of map to %1").arg(col.name()));
3953 mapScene->setBackgroundBrush(col);
3956 QColor VymModel::getMapBackgroundColor()
3958 return mapScene->backgroundBrush().color();
3962 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint()
3964 return linkcolorhint;
3967 QColor VymModel::getMapDefLinkColor()
3969 return defLinkColor;
3972 void VymModel::setMapDefXLinkColor(QColor col)
3977 QColor VymModel::getMapDefXLinkColor()
3979 return defXLinkColor;
3982 void VymModel::setMapDefXLinkWidth (int w)
3987 int VymModel::getMapDefXLinkWidth()
3989 return defXLinkWidth;
3992 void VymModel::move(const double &x, const double &y)
3994 LinkableMapObj *sel=selection.single();
3997 QPointF ap(sel->getAbsPos());
4001 QString ps=qpointfToString(ap);
4002 QString s=selection.getSelectString();
4005 s, "move "+qpointfToString(to),
4006 QString("Move %1 to %2").arg(getObjectName(sel)).arg(ps));
4014 void VymModel::moveRel (const double &x, const double &y)
4016 LinkableMapObj *sel=selection.single();
4019 QPointF rp(sel->getRelPos());
4023 QString ps=qpointfToString (sel->getRelPos());
4024 QString s=getSelectString(sel);
4027 s, "moveRel "+qpointfToString(to),
4028 QString("Move %1 to relative position %2").arg(getObjectName(sel)).arg(ps));
4029 ((OrnamentedObj*)sel)->move2RelPos (x,y);
4038 void VymModel::animate()
4040 animationTimer->stop();
4043 while (i<animObjList.size() )
4045 bo=(BranchObj*)animObjList.at(i);
4050 animObjList.removeAt(i);
4057 mapEditor->updateSelection();
4059 if (!animObjList.isEmpty()) animationTimer->start();
4063 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4065 if (bo && bo->getDepth()>0)
4068 ap.setStart (start);
4070 ap.setTicks (animationTicks);
4071 ap.setAnimated (true);
4072 bo->setAnimation (ap);
4073 animObjList.append( bo );
4074 animationTimer->setSingleShot (true);
4075 animationTimer->start(animationInterval);
4079 void VymModel::stopAnimation (MapObj *mo)
4081 int i=animObjList.indexOf(mo);
4083 animObjList.removeAt (i);
4086 void VymModel::sendSelection()
4088 if (netstate!=Server) return;
4089 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4092 void VymModel::newServer()
4096 tcpServer = new QTcpServer(this);
4097 if (!tcpServer->listen(QHostAddress::Any,port)) {
4098 QMessageBox::critical(NULL, "vym server",
4099 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4100 //FIXME needed? we are no widget any longer... close();
4103 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4105 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4108 void VymModel::connectToServer()
4111 server="salam.suse.de";
4113 clientSocket = new QTcpSocket (this);
4114 clientSocket->abort();
4115 clientSocket->connectToHost(server ,port);
4116 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4117 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4118 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4120 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4125 void VymModel::newClient()
4127 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4128 connect(newClient, SIGNAL(disconnected()),
4129 newClient, SLOT(deleteLater()));
4131 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4133 clientList.append (newClient);
4137 void VymModel::sendData(const QString &s)
4139 if (clientList.size()==0) return;
4141 // Create bytearray to send
4143 QDataStream out(&block, QIODevice::WriteOnly);
4144 out.setVersion(QDataStream::Qt_4_0);
4146 // Reserve some space for blocksize
4149 // Write sendCounter
4150 out << sendCounter++;
4155 // Go back and write blocksize so far
4156 out.device()->seek(0);
4157 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4161 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4163 for (int i=0; i<clientList.size(); ++i)
4165 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4166 clientList.at(i)->write (block);
4170 void VymModel::readData ()
4172 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4175 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4179 QDataStream in(clientSocket);
4180 in.setVersion(QDataStream::Qt_4_0);
4188 cout << " t="<<qPrintable (t)<<endl;
4194 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4196 switch (socketError) {
4197 case QAbstractSocket::RemoteHostClosedError:
4199 case QAbstractSocket::HostNotFoundError:
4200 QMessageBox::information(NULL, vymName +" Network client",
4201 "The host was not found. Please check the "
4202 "host name and port settings.");
4204 case QAbstractSocket::ConnectionRefusedError:
4205 QMessageBox::information(NULL, vymName + " Network client",
4206 "The connection was refused by the peer. "
4207 "Make sure the fortune server is running, "
4208 "and check that the host name and port "
4209 "settings are correct.");
4212 QMessageBox::information(NULL, vymName + " Network client",
4213 QString("The following error occurred: %1.")
4214 .arg(clientSocket->errorString()));
4221 void VymModel::selectMapSelectionColor()
4223 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4224 setSelectionColor (col);
4227 void VymModel::setSelectionColorInt (QColor col)
4229 if ( !col.isValid() ) return;
4231 QString("setSelectionColor (%1)").arg(selection.getColor().name()),
4232 QString("setSelectionColor (%1)").arg(col.name()),
4233 QString("Set color of selection box to %1").arg(col.name())
4236 selection.setColor (col);
4239 void VymModel::updateSelection()
4244 void VymModel::setSelectionColor(QColor col)
4246 if ( !col.isValid() ) return;
4248 QString("setSelectionColor (%1)").arg(selection.getColor().name()),
4249 QString("setSelectionColor (%1)").arg(col.name()),
4250 QString("Set color of selection box to %1").arg(col.name())
4252 setSelectionColorInt (col);
4255 QColor VymModel::getSelectionColor()
4257 return selection.getColor();
4260 void VymModel::setHideTmpMode (HideTmpMode mode)
4263 for (int i=0;i<mapCenters.count(); i++)
4264 mapCenters.at(i)->setHideTmp (mode);
4266 // FIXME needed? scene()->update();
4270 QRectF VymModel::getTotalBBox()
4273 for (int i=0;i<mapCenters.count(); i++)
4274 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4278 //////////////////////////////////////////////
4279 // Selection related
4280 //////////////////////////////////////////////
4282 void VymModel::setSelectionBlocked (bool b)
4287 selection.unblock();
4290 bool VymModel::isSelectionBlocked()
4292 return selection.isBlocked();
4295 bool VymModel::select (const QString &s)
4297 if (selection.select(s))
4300 ensureSelectionVisible();
4308 bool VymModel::select (LinkableMapObj *lmo)
4310 if (selection.select(lmo))
4313 ensureSelectionVisible();
4320 void VymModel::unselect()
4322 selection.unselect();
4325 void VymModel::reselect()
4327 selection.reselect();
4330 void VymModel::ensureSelectionVisible()
4332 LinkableMapObj *lmo=selection.single();
4333 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4337 void VymModel::selectInt (LinkableMapObj *lmo)
4339 if (selection.select(lmo))
4347 void VymModel::selectNextBranchInt()
4349 // Increase number of branch
4350 LinkableMapObj *sel=selection.single();
4353 QString s=selection.getSelectString();
4359 part=s.section(",",-1);
4361 num=part.right(part.length() - 3);
4363 s=s.left (s.length() -num.length());
4366 num=QString ("%1").arg(num.toUInt()+1);
4370 // Try to select this one
4371 if (select (s)) return;
4373 // We have no direct successor,
4374 // try to increase the parental number in order to
4375 // find a successor with same depth
4377 int d=selection.single()->getDepth();
4382 while (!found && d>0)
4384 s=s.section (",",0,d-1);
4385 // replace substring of current depth in s with "1"
4386 part=s.section(",",-1);
4388 num=part.right(part.length() - 3);
4392 // increase number of parent
4393 num=QString ("%1").arg(num.toUInt()+1);
4394 s=s.section (",",0,d-2) + ","+ typ+num;
4397 // Special case, look at orientation
4398 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4399 num=QString ("%1").arg(num.toUInt()+1);
4401 num=QString ("%1").arg(num.toUInt()-1);
4406 // pad to oldDepth, select the first branch for each depth
4407 for (i=d;i<oldDepth;i++)
4412 if ( selection.getBranch()->countBranches()>0)
4420 // try to select the freshly built string
4428 void VymModel::selectPrevBranchInt()
4430 // Decrease number of branch
4431 BranchObj *bo=selection.getBranch();
4434 QString s=selection.getSelectString();
4440 part=s.section(",",-1);
4442 num=part.right(part.length() - 3);
4444 s=s.left (s.length() -num.length());
4446 int n=num.toInt()-1;
4449 num=QString ("%1").arg(n);
4452 // Try to select this one
4453 if (n>=0 && select (s)) return;
4455 // We have no direct precessor,
4456 // try to decrease the parental number in order to
4457 // find a precessor with same depth
4459 int d=selection.single()->getDepth();
4464 while (!found && d>0)
4466 s=s.section (",",0,d-1);
4467 // replace substring of current depth in s with "1"
4468 part=s.section(",",-1);
4470 num=part.right(part.length() - 3);
4474 // decrease number of parent
4475 num=QString ("%1").arg(num.toInt()-1);
4476 s=s.section (",",0,d-2) + ","+ typ+num;
4479 // Special case, look at orientation
4480 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4481 num=QString ("%1").arg(num.toInt()-1);
4483 num=QString ("%1").arg(num.toInt()+1);
4488 // pad to oldDepth, select the last branch for each depth
4489 for (i=d;i<oldDepth;i++)
4493 if ( selection.getBranch()->countBranches()>0)
4494 s+=",bo:"+ QString ("%1").arg( selection.getBranch()->countBranches()-1 );
4501 // try to select the freshly built string
4509 void VymModel::selectUpperBranch()
4511 if (selection.isBlocked() ) return;
4513 BranchObj *bo=selection.getBranch();
4514 if (bo && selection.type()==Selection::Branch)
4516 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4517 selectPrevBranchInt();
4519 if (bo->getDepth()==1)
4520 selectNextBranchInt();
4522 selectPrevBranchInt();
4526 void VymModel::selectLowerBranch()
4528 if (selection.isBlocked() ) return;
4530 BranchObj *bo=selection.getBranch();
4531 if (bo && selection.type()==Selection::Branch)
4533 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4534 selectNextBranchInt();
4536 if (bo->getDepth()==1)
4537 selectPrevBranchInt();
4539 selectNextBranchInt();
4544 void VymModel::selectLeftBranch()
4546 if (selection.isBlocked() ) return;
4550 LinkableMapObj *sel=selection.single();
4553 if (selection.type()== Selection::MapCenter)
4555 par=selection.getBranch();
4556 bo=par->getLastSelectedBranch();
4559 // Workaround for reselecting on left and right side
4560 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4561 bo=par->getLastBranch();
4564 bo=par->getLastBranch();
4565 selection.select(bo);
4567 ensureSelectionVisible();
4573 par=(BranchObj*)(sel->getParObj());
4574 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4576 if (selection.type() == Selection::Branch ||
4577 selection.type() == Selection::FloatImage)
4579 selection.select(par);
4581 ensureSelectionVisible();
4586 if (selection.type() == Selection::Branch )
4588 bo=selection.getBranch()->getLastSelectedBranch();
4591 selection.select(bo);
4593 ensureSelectionVisible();
4602 void VymModel::selectRightBranch()
4604 if (selection.isBlocked() ) return;
4608 LinkableMapObj *sel=selection.single();
4611 if (selection.type()==Selection::MapCenter)
4613 par=selection.getBranch();
4614 bo=par->getLastSelectedBranch();
4617 // Workaround for reselecting on left and right side
4618 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4619 bo=par->getFirstBranch();
4622 selection.select(bo);
4624 ensureSelectionVisible();
4630 par=(BranchObj*)(selection.single()->getParObj());
4631 if (selection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
4633 if (selection.type() == Selection::Branch ||
4634 selection.type() == Selection::FloatImage)
4636 selection.select(par);
4638 ensureSelectionVisible();
4643 if (selection.type() == Selection::Branch)
4645 bo=selection.getBranch()->getLastSelectedBranch();
4648 selection.select(bo);
4650 ensureSelectionVisible();
4659 void VymModel::selectFirstBranch()
4661 BranchObj *bo1=selection.getBranch();
4666 par=(BranchObj*)(bo1->getParObj());
4668 bo2=par->getFirstBranch();
4670 selection.select(bo2);
4672 ensureSelectionVisible();
4678 void VymModel::selectLastBranch()
4680 BranchObj *bo1=selection.getBranch();
4685 par=(BranchObj*)(bo1->getParObj());
4687 bo2=par->getLastBranch();
4690 selection.select(bo2);
4692 ensureSelectionVisible();
4698 Selection::Type VymModel::selectionType()
4700 return selection.type();
4703 LinkableMapObj* VymModel::getSelection()
4705 return selection.single();
4707 BranchObj* VymModel::getSelectedBranch()
4709 return selection.getBranch();
4712 FloatImageObj* VymModel::getSelectedFloatImage()
4714 return selection.getFloatImage();
4717 QString VymModel::getSelectString ()
4719 return selection.getSelectString();
4722 QString VymModel::getSelectString (LinkableMapObj *lmo)
4726 if (typeid(*lmo)==typeid(BranchObj) ||
4727 typeid(*lmo)==typeid(MapCenterObj) )
4729 LinkableMapObj *par=lmo->getParObj();
4732 if (lmo->getDepth() ==1)
4733 // Mainbranch, return
4734 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4736 // Branch, call myself recursively
4737 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4741 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
4742 if (i>=0) s=QString("mc:%1").arg(i);