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 void VymModel::setMapEditor(MapEditor *me)
162 for (int i=0; i<mapCenters.count(); i++)
163 mapCenters.at(i)->setMapEditor(mapEditor);
166 MapEditor* VymModel::getMapEditor()
171 bool VymModel::isRepositionBlocked()
173 return blockReposition;
176 void VymModel::updateActions() // FIXME maybe don't update if blockReposition is set
178 // Tell mainwindow to update states of actions
179 mainWindow->updateActions();
184 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
186 // tmpdir temporary directory to which data will be written
187 // prefix mapname, which will be appended to images etc.
188 // writeflags Only write flags for "real" save of map, not undo
189 // offset offset of bbox of whole map in scene.
190 // Needed for XML export
196 case LinkableMapObj::Line:
199 case LinkableMapObj::Parabel:
202 case LinkableMapObj::PolyLine:
206 ls="StylePolyParabel";
210 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
212 if (linkcolorhint==LinkableMapObj::HeadingColor)
213 colhint=attribut("linkColorHint","HeadingColor");
215 QString mapAttr=attribut("version",vymVersion);
217 mapAttr+= attribut("author",author) +
218 attribut("comment",comment) +
219 attribut("date",getDate()) +
220 attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
221 attribut("selectionColor", selection.getColor().name() ) +
222 attribut("linkStyle", ls ) +
223 attribut("linkColor", defLinkColor.name() ) +
224 attribut("defXLinkColor", defXLinkColor.name() ) +
225 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
227 s+=beginElement("vymmap",mapAttr);
230 // Find the used flags while traversing the tree
231 standardFlagsDefault->resetUsedCounter();
233 // Reset the counters before saving
234 // TODO constr. of FIO creates lots of objects, better do this in some other way...
235 FloatImageObj (mapScene).resetSaveCounter();
237 // Build xml recursivly
238 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
239 // Save complete map, if saveSel not set
240 s+=saveToDir(tmpdir,prefix,writeflags,offset);
243 if ( typeid(*saveSel) == typeid(BranchObj) )
245 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
246 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
248 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
251 // Save local settings
252 s+=settings.getDataXML (destPath);
255 if (!selection.isEmpty() && !saveSel )
256 s+=valueElement("select",selection.getSelectString());
259 s+=endElement("vymmap");
262 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
266 void VymModel::setFilePath(QString fpath, QString destname)
268 if (fpath.isEmpty() || fpath=="")
275 filePath=fpath; // becomes absolute path
276 fileName=fpath; // gets stripped of path
277 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
279 // If fpath is not an absolute path, complete it
280 filePath=QDir(fpath).absPath();
281 fileDir=filePath.left (1+filePath.findRev ("/"));
283 // Set short name, too. Search from behind:
284 int i=fileName.findRev("/");
285 if (i>=0) fileName=fileName.remove (0,i+1);
287 // Forget the .vym (or .xml) for name of map
288 mapName=fileName.left(fileName.findRev(".",-1,true) );
292 void VymModel::setFilePath(QString fpath)
294 setFilePath (fpath,fpath);
297 QString VymModel::getFilePath()
302 QString VymModel::getFileName()
307 QString VymModel::getMapName()
312 QString VymModel::getDestPath()
317 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
319 ErrorCode err=success;
321 parseBaseHandler *handler;
325 case VymMap: handler=new parseVYMHandler; break;
326 case FreemindMap : handler=new parseFreemindHandler; break;
328 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
329 "Unknown FileType in VymModel::load()");
335 // FIXME not needed??? model->setMapEditor(this);
336 // (map state is set later at end of load...)
339 BranchObj *bo=selection.getBranch();
340 if (!bo) return aborted;
341 if (lmode==ImportAdd)
342 saveStateChangingPart(
345 QString("addMapInsert (%1)").arg(fname),
346 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
348 saveStateChangingPart(
351 QString("addMapReplace(%1)").arg(fname),
352 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
356 // Create temporary directory for packing
358 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
361 QMessageBox::critical( 0, tr( "Critical Load Error" ),
362 tr("Couldn't create temporary directory before load\n"));
367 err=unzipDir (tmpZipDir,fname);
377 // Look for mapname.xml
378 xmlfile= fname.left(fname.findRev(".",-1,true));
379 xmlfile=xmlfile.section( '/', -1 );
380 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
381 if (!mfile.exists() )
383 // mapname.xml does not exist, well,
384 // maybe someone renamed the mapname.vym file...
385 // Try to find any .xml in the toplevel
386 // directory of the .vym file
387 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
388 if (flist.count()==1)
390 // Only one entry, take this one
391 xmlfile=tmpZipDir + "/"+flist.first();
394 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
395 *it=tmpZipDir + "/" + *it;
396 // TODO Multiple entries, load all (but only the first one into this ME)
397 //mainWindow->fileLoadFromTmp (flist);
398 //returnCode=1; // Silently forget this attempt to load
399 qWarning ("MainWindow::load (fn) multimap found...");
402 if (flist.isEmpty() )
404 QMessageBox::critical( 0, tr( "Critical Load Error" ),
405 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
408 } //file doesn't exist
410 xmlfile=mfile.name();
413 QFile file( xmlfile);
415 // I am paranoid: file should exist anyway
416 // according to check in mainwindow.
419 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
420 tr(QString("Couldn't open map %1").arg(file.name())));
424 bool blockSaveStateOrg=blockSaveState;
425 blockReposition=true;
427 QXmlInputSource source( file);
428 QXmlSimpleReader reader;
429 reader.setContentHandler( handler );
430 reader.setErrorHandler( handler );
431 handler->setModel ( this);
434 // We need to set the tmpDir in order to load files with rel. path
439 tmpdir=fname.left(fname.findRev("/",-1));
440 handler->setTmpDir (tmpdir);
441 handler->setInputFile (file.name());
442 handler->setLoadMode (lmode);
443 bool ok = reader.parse( source );
444 blockReposition=false;
445 blockSaveState=blockSaveStateOrg;
449 reposition(); // FIXME reposition the view instead...
456 autosaveTimer->stop();
459 // Reset timestamp to check for later updates of file
460 fileChangedTime=QFileInfo (destPath).lastModified();
463 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
464 tr( handler->errorProtocol() ) );
466 // Still return "success": the map maybe at least
467 // partially read by the parser
472 removeDir (QDir(tmpZipDir));
479 ErrorCode VymModel::save (const SaveMode &savemode)
483 QString safeFilePath;
485 ErrorCode err=success;
489 mapFileName=mapName+".xml";
491 // use name given by user, even if he chooses .doc
492 mapFileName=fileName;
494 // Look, if we should zip the data:
497 QMessageBox mb( vymName,
498 tr("The map %1\ndid not use the compressed "
499 "vym file format.\nWriting it uncompressed will also write images \n"
500 "and flags and thus may overwrite files in the "
501 "given directory\n\nDo you want to write the map").arg(filePath),
502 QMessageBox::Warning,
503 QMessageBox::Yes | QMessageBox::Default,
505 QMessageBox::Cancel | QMessageBox::Escape);
506 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
507 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
508 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
511 case QMessageBox::Yes:
512 // save compressed (default file format)
515 case QMessageBox::No:
519 case QMessageBox::Cancel:
526 // First backup existing file, we
527 // don't want to add to old zip archives
531 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
533 QString backupFileName(destPath + "~");
534 QFile backupFile(backupFileName);
535 if (backupFile.exists() && !backupFile.remove())
537 QMessageBox::warning(0, tr("Save Error"),
538 tr("%1\ncould not be removed before saving").arg(backupFileName));
540 else if (!f.rename(backupFileName))
542 QMessageBox::warning(0, tr("Save Error"),
543 tr("%1\ncould not be renamed before saving").arg(destPath));
550 // Create temporary directory for packing
552 tmpZipDir=makeTmpDir (ok,"vym-zip");
555 QMessageBox::critical( 0, tr( "Critical Load Error" ),
556 tr("Couldn't create temporary directory before save\n"));
560 safeFilePath=filePath;
561 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
564 // Create mapName and fileDir
565 makeSubDirs (fileDir);
568 if (savemode==CompleteMap || selection.isEmpty())
571 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
574 autosaveTimer->stop();
579 if (selection.type()==Selection::FloatImage)
582 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),selection.getBranch());
583 // TODO take care of multiselections
586 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
589 qWarning ("ME::saveStringToDisk failed!");
595 if (err==success) err=zipDir (tmpZipDir,destPath);
598 removeDir (QDir(tmpZipDir));
600 // Restore original filepath outside of tmp zip dir
601 setFilePath (safeFilePath);
605 fileChangedTime=QFileInfo (destPath).lastModified();
609 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
611 QString pathDir=path.left(path.findRev("/"));
617 // We need to parse saved XML data
618 parseVYMHandler handler;
619 QXmlInputSource source( file);
620 QXmlSimpleReader reader;
621 reader.setContentHandler( &handler );
622 reader.setErrorHandler( &handler );
623 handler.setModel ( this);
624 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
625 if (undoSel.isEmpty())
629 handler.setLoadMode (NewMap);
633 handler.setLoadMode (ImportReplace);
635 blockReposition=true;
636 bool ok = reader.parse( source );
637 blockReposition=false;
640 // This should never ever happen
641 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
642 handler.errorProtocol());
645 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
648 void VymModel::addMapInsertInt (const QString &path, int pos)
650 BranchObj *sel=selection.getBranch();
653 QString pathDir=path.left(path.findRev("/"));
659 // We need to parse saved XML data
660 parseVYMHandler handler;
661 QXmlInputSource source( file);
662 QXmlSimpleReader reader;
663 reader.setContentHandler( &handler );
664 reader.setErrorHandler( &handler );
665 handler.setModel (this);
666 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
667 handler.setLoadMode (ImportAdd);
668 blockReposition=true;
669 bool ok = reader.parse( source );
670 blockReposition=false;
673 // This should never ever happen
674 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
675 handler.errorProtocol());
677 if (sel->getDepth()>0)
678 sel->getLastBranch()->linkTo (sel,pos);
680 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
684 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
686 BranchObj *bo=selection.getBranch();
691 fio=bo->getLastFloatImage();
694 // FIXME needed? scene()->update();
700 void VymModel::loadFloatImage ()
702 BranchObj *bo=selection.getBranch();
706 Q3FileDialog *fd=new Q3FileDialog( NULL);
707 fd->setMode (Q3FileDialog::ExistingFiles);
708 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
709 ImagePreview *p =new ImagePreview (fd);
710 fd->setContentsPreviewEnabled( TRUE );
711 fd->setContentsPreview( p, p );
712 fd->setPreviewMode( Q3FileDialog::Contents );
713 fd->setCaption(vymName+" - " +tr("Load image"));
714 fd->setDir (lastImageDir);
717 if ( fd->exec() == QDialog::Accepted )
719 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
720 lastImageDir=QDir (fd->dirPath());
723 for (int j=0; j<fd->selectedFiles().count(); j++)
725 s=fd->selectedFiles().at(j);
726 fio=loadFloatImageInt (s);
729 (LinkableMapObj*)fio,
732 QString ("loadImage (%1)").arg(s ),
733 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
736 // TODO loadFIO error handling
737 qWarning ("Failed to load "+s);
745 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
750 void VymModel::saveFloatImage ()
752 FloatImageObj *fio=selection.getFloatImage();
755 QFileDialog *fd=new QFileDialog( NULL);
756 fd->setFilters (imageIO.getFilters());
757 fd->setCaption(vymName+" - " +tr("Save image"));
758 fd->setFileMode( QFileDialog::AnyFile );
759 fd->setDirectory (lastImageDir);
760 // fd->setSelection (fio->getOriginalFilename());
764 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
766 fn=fd->selectedFiles().at(0);
767 if (QFile (fn).exists() )
769 QMessageBox mb( vymName,
770 tr("The file %1 exists already.\n"
771 "Do you want to overwrite it?").arg(fn),
772 QMessageBox::Warning,
773 QMessageBox::Yes | QMessageBox::Default,
774 QMessageBox::Cancel | QMessageBox::Escape,
775 QMessageBox::NoButton );
777 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
778 mb.setButtonText( QMessageBox::No, tr("Cancel"));
781 case QMessageBox::Yes:
784 case QMessageBox::Cancel:
791 saveFloatImageInt (fio,fd->selectedFilter(),fn );
798 void VymModel::importDirInt(BranchObj *dst, QDir d)
800 BranchObj *bo=selection.getBranch();
803 // Traverse directories
804 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
805 QFileInfoList list = d.entryInfoList();
808 for (int i = 0; i < list.size(); ++i)
811 if (fi.fileName() != "." && fi.fileName() != ".." )
814 bo=dst->getLastBranch();
815 bo->setHeading (fi.fileName() );
816 bo->setColor (QColor("blue"));
818 if ( !d.cd(fi.fileName()) )
819 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
822 // Recursively add subdirs
829 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
830 list = d.entryInfoList();
832 for (int i = 0; i < list.size(); ++i)
836 bo=dst->getLastBranch();
837 bo->setHeading (fi.fileName() );
838 bo->setColor (QColor("black"));
839 if (fi.fileName().right(4) == ".vym" )
840 bo->setVymLink (fi.filePath());
845 void VymModel::importDirInt (const QString &s)
847 BranchObj *bo=selection.getBranch();
850 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
857 void VymModel::importDir()
859 BranchObj *bo=selection.getBranch();
863 filters <<"VYM map (*.vym)";
864 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
865 fd->setMode (QFileDialog::DirectoryOnly);
866 fd->setFilters (filters);
867 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
871 if ( fd->exec() == QDialog::Accepted )
873 importDirInt (fd->selectedFile() );
875 //FIXME needed? scene()->update();
881 void VymModel::autosave()
883 QDateTime now=QDateTime().currentDateTime();
885 // Disable autosave, while we have gone back in history
886 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
887 if (redosAvail>0) return;
889 // Also disable autosave for new map without filename
890 if (filePath.isEmpty()) return;
893 if (mapUnsaved &&mapChanged && settings.value ("/autosave/use",true).toBool() )
895 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
896 mainWindow->fileSave (this);
899 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
904 void VymModel::fileChanged()
906 // Check if file on disk has changed meanwhile
907 if (!filePath.isEmpty())
909 QDateTime tmod=QFileInfo (filePath).lastModified();
910 if (tmod>fileChangedTime)
912 // FIXME switch to current mapeditor and finish lineedits...
913 QMessageBox mb( vymName,
914 tr("The file of the map on disk has changed:\n\n"
915 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
916 QMessageBox::Question,
918 QMessageBox::Cancel | QMessageBox::Default,
919 QMessageBox::NoButton );
921 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
922 mb.setButtonText( QMessageBox::No, tr("Ignore"));
925 case QMessageBox::Yes:
927 load (filePath,NewMap,fileType);
928 case QMessageBox::Cancel:
929 fileChangedTime=tmod; // allow autosave to overwrite newer file!
935 bool VymModel::isDefault()
940 void VymModel::makeDefault()
946 bool VymModel::hasChanged()
951 void VymModel::setChanged()
954 autosaveTimer->start(settings.value("/autosave/ms/",300000).toInt());
962 QString VymModel::getObjectName (const LinkableMapObj *lmo)
965 if (!lmo) return QString("Error: NULL has no name!");
967 if ((typeid(*lmo) == typeid(BranchObj) ||
968 typeid(*lmo) == typeid(MapCenterObj)))
971 s=(((BranchObj*)lmo)->getHeading());
972 if (s=="") s="unnamed";
973 return QString("branch (%1)").arg(s);
975 if ((typeid(*lmo) == typeid(FloatImageObj) ))
976 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
977 return QString("Unknown type has no name!");
980 void VymModel::redo()
982 // Can we undo at all?
983 if (redosAvail<1) return;
985 bool blockSaveStateOrg=blockSaveState;
990 if (undosAvail<stepsTotal) undosAvail++;
992 if (curStep>stepsTotal) curStep=1;
993 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
994 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
995 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
996 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
997 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
998 QString version=undoSet.readEntry ("/history/version");
1000 /* TODO Maybe check for version, if we save the history
1001 if (!checkVersion(version))
1002 QMessageBox::warning(0,tr("Warning"),
1003 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1006 // Find out current undo directory
1007 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1011 cout << "VymModel::redo() begin\n";
1012 cout << " undosAvail="<<undosAvail<<endl;
1013 cout << " redosAvail="<<redosAvail<<endl;
1014 cout << " curStep="<<curStep<<endl;
1015 cout << " ---------------------------"<<endl;
1016 cout << " comment="<<comment.toStdString()<<endl;
1017 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1018 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1019 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1020 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1021 cout << " ---------------------------"<<endl<<endl;
1024 // select object before redo
1025 if (!redoSelection.isEmpty())
1026 select (redoSelection);
1029 parseAtom (redoCommand);
1032 blockSaveState=blockSaveStateOrg;
1034 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1035 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1036 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1037 undoSet.writeSettings(histPath);
1039 mainWindow->updateHistory (undoSet);
1042 /* TODO remove testing
1043 cout << "ME::redo() end\n";
1044 cout << " undosAvail="<<undosAvail<<endl;
1045 cout << " redosAvail="<<redosAvail<<endl;
1046 cout << " curStep="<<curStep<<endl;
1047 cout << " ---------------------------"<<endl<<endl;
1053 bool VymModel::isRedoAvailable()
1055 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1061 void VymModel::undo()
1063 // Can we undo at all?
1064 if (undosAvail<1) return;
1066 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1068 bool blockSaveStateOrg=blockSaveState;
1069 blockSaveState=true;
1071 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1072 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1073 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1074 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1075 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1076 QString version=undoSet.readEntry ("/history/version");
1078 /* TODO Maybe check for version, if we save the history
1079 if (!checkVersion(version))
1080 QMessageBox::warning(0,tr("Warning"),
1081 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1084 // Find out current undo directory
1085 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1087 // select object before undo
1088 if (!undoSelection.isEmpty())
1089 select (undoSelection);
1093 cout << "VymModel::undo() begin\n";
1094 cout << " undosAvail="<<undosAvail<<endl;
1095 cout << " redosAvail="<<redosAvail<<endl;
1096 cout << " curStep="<<curStep<<endl;
1097 cout << " ---------------------------"<<endl;
1098 cout << " comment="<<comment.toStdString()<<endl;
1099 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1100 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1101 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1102 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1103 cout << " ---------------------------"<<endl<<endl;
1105 parseAtom (undoCommand);
1110 if (curStep<1) curStep=stepsTotal;
1114 blockSaveState=blockSaveStateOrg;
1115 /* TODO remove testing
1116 cout << "VymModel::undo() end\n";
1117 cout << " undosAvail="<<undosAvail<<endl;
1118 cout << " redosAvail="<<redosAvail<<endl;
1119 cout << " curStep="<<curStep<<endl;
1120 cout << " ---------------------------"<<endl<<endl;
1123 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1124 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1125 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1126 undoSet.writeSettings(histPath);
1128 mainWindow->updateHistory (undoSet);
1131 ensureSelectionVisible();
1134 bool VymModel::isUndoAvailable()
1136 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1142 void VymModel::gotoHistoryStep (int i)
1144 // Restore variables
1145 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1146 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1148 if (i<0) i=undosAvail+redosAvail;
1150 // Clicking above current step makes us undo things
1153 for (int j=0; j<undosAvail-i; j++) undo();
1156 // Clicking below current step makes us redo things
1158 for (int j=undosAvail; j<i; j++)
1160 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1164 // And ignore clicking the current row ;-)
1168 QString VymModel::getHistoryPath()
1170 QString histName(QString("history-%1").arg(curStep));
1171 return (tmpMapDir+"/"+histName);
1174 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
1176 sendData(redoCom); //FIXME testing
1181 if (blockSaveState) return;
1183 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1185 // Find out current undo directory
1186 if (undosAvail<stepsTotal) undosAvail++;
1188 if (curStep>stepsTotal) curStep=1;
1190 QString backupXML="";
1191 QString histDir=getHistoryPath();
1192 QString bakMapPath=histDir+"/map.xml";
1194 // Create histDir if not available
1197 makeSubDirs (histDir);
1199 // Save depending on how much needs to be saved
1201 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1203 QString undoCommand="";
1204 if (savemode==UndoCommand)
1206 undoCommand=undoCom;
1208 else if (savemode==PartOfMap )
1210 undoCommand=undoCom;
1211 undoCommand.replace ("PATH",bakMapPath);
1214 if (!backupXML.isEmpty())
1215 // Write XML Data to disk
1216 saveStringToDisk (bakMapPath,backupXML);
1218 // We would have to save all actions in a tree, to keep track of
1219 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1222 // Write the current state to disk
1223 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1224 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1225 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1226 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1227 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1228 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1229 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1230 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1231 undoSet.setEntry (QString("/history/version"),vymVersion);
1232 undoSet.writeSettings(histPath);
1236 // TODO remove after testing
1237 //cout << " into="<< histPath.toStdString()<<endl;
1238 cout << " stepsTotal="<<stepsTotal<<
1239 ", undosAvail="<<undosAvail<<
1240 ", redosAvail="<<redosAvail<<
1241 ", curStep="<<curStep<<endl;
1242 cout << " ---------------------------"<<endl;
1243 cout << " comment="<<comment.toStdString()<<endl;
1244 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1245 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1246 cout << " redoCom="<<redoCom.toStdString()<<endl;
1247 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1248 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1249 cout << " ---------------------------"<<endl;
1252 mainWindow->updateHistory (undoSet);
1258 void VymModel::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
1260 // save the selected part of the map, Undo will replace part of map
1261 QString undoSelection="";
1263 undoSelection=getSelectString(undoSel);
1265 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1266 QString redoSelection="";
1268 redoSelection=getSelectString(undoSel);
1270 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1273 saveState (PartOfMap,
1274 undoSelection, "addMapReplace (\"PATH\")",
1280 void VymModel::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
1284 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1287 QString undoSelection=getSelectString (redoSel->getParObj());
1288 QString redoSelection=getSelectString(redoSel);
1289 if (typeid(*redoSel) == typeid(BranchObj) )
1291 // save the selected branch of the map, Undo will insert part of map
1292 saveState (PartOfMap,
1293 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
1294 redoSelection, "delete ()",
1301 void VymModel::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
1303 // "Normal" savestate: save commands, selections and comment
1304 // so just save commands for undo and redo
1305 // and use current selection
1307 QString redoSelection="";
1308 if (redoSel) redoSelection=getSelectString(redoSel);
1309 QString undoSelection="";
1310 if (undoSel) undoSelection=getSelectString(undoSel);
1312 saveState (UndoCommand,
1319 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1321 // "Normal" savestate: save commands, selections and comment
1322 // so just save commands for undo and redo
1323 // and use current selection
1324 saveState (UndoCommand,
1331 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1333 // "Normal" savestate applied to model (no selection needed):
1334 // save commands and comment
1335 saveState (UndoCommand,
1343 QGraphicsScene* VymModel::getScene ()
1348 BranchObj* VymModel::first()
1350 if (mapCenters.count()>0)
1351 return mapCenters.first();
1356 BranchObj* VymModel::next(BranchObj *bo_start)
1359 BranchObj *bo=bo_start;
1362 // Try to find next branch in current MapCenter
1364 if (rbo) return rbo;
1366 // Try to find MapCenter of bo
1367 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
1369 // Try to find next MapCenter
1370 int i=mapCenters.indexOf ((MapCenterObj*)bo);
1371 if (i+2 > mapCenters.count() || i<0) return NULL;
1372 if (mapCenters.at(i+1)!=bo_start)
1373 return mapCenters.at(i+1);
1378 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
1380 LinkableMapObj *lmo;
1382 for (int i=0;i<mapCenters.count(); i++)
1384 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
1385 if (lmo) return lmo;
1390 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
1392 LinkableMapObj *lmo;
1398 part=s.section(",",0,0);
1400 num=part.right(part.length() - 3);
1401 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
1402 return mapCenters.at(num.toInt() );
1405 for (int i=0; i<mapCenters.count(); i++)
1407 lmo=mapCenters.at(i)->findObjBySelect(s);
1408 if (lmo) return lmo;
1413 LinkableMapObj* VymModel::findID (const QString &s)
1415 LinkableMapObj *lmo;
1416 for (int i=0; i<mapCenters.count(); i++)
1418 lmo=mapCenters.at(i)->findID (s);
1419 if (lmo) return lmo;
1424 void VymModel::removeSelection()
1428 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
1432 for (int i=0; i<mapCenters.count(); i++)
1433 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
1437 //////////////////////////////////////////////
1439 //////////////////////////////////////////////
1440 void VymModel::setVersion (const QString &s)
1445 void VymModel::setAuthor (const QString &s)
1448 QString ("setMapAuthor (\"%1\")").arg(author),
1449 QString ("setMapAuthor (\"%1\")").arg(s),
1450 QString ("Set author of map to \"%1\"").arg(s)
1456 QString VymModel::getAuthor()
1461 void VymModel::setComment (const QString &s)
1464 QString ("setMapComment (\"%1\")").arg(comment),
1465 QString ("setMapComment (\"%1\")").arg(s),
1466 QString ("Set comment of map")
1472 QString VymModel::getComment ()
1477 QString VymModel::getDate ()
1479 return QDate::currentDate().toString ("yyyy-MM-dd");
1482 void VymModel::setHeading(const QString &s)
1484 BranchObj *sel=selection.getBranch();
1489 "setHeading (\""+sel->getHeading()+"\")",
1491 "setHeading (\""+s+"\")",
1492 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1493 sel->setHeading(s );
1496 ensureSelectionVisible();
1500 QString VymModel::getHeading(bool &ok, QPoint &p)
1502 BranchObj *bo=selection.getBranch();
1506 //p=scene->mapFromScene(bo->getAbsPos()); // FIXME this is view-dependant!!!
1507 return bo->getHeading();
1514 void VymModel::setHeadingInt(const QString &s)
1516 BranchObj *bo=selection.getBranch();
1522 ensureSelectionVisible();
1526 BranchObj* VymModel::findText (QString s, bool cs)
1528 QTextDocument::FindFlags flags=0;
1529 if (cs) flags=QTextDocument::FindCaseSensitively;
1532 { // Nothing found or new find process
1534 // nothing found, start again
1538 bool searching=true;
1539 bool foundNote=false;
1540 while (searching && !EOFind)
1544 // Searching in Note
1545 if (itFind->getNote().contains(s,cs))
1547 if (selection.single()!=itFind)
1549 selection.select(itFind);
1550 ensureSelectionVisible();
1552 if (textEditor->findText(s,flags))
1558 // Searching in Heading
1559 if (searching && itFind->getHeading().contains (s,cs) )
1561 selection.select(itFind);
1562 ensureSelectionVisible();
1568 itFind=next(itFind);
1569 if (!itFind) EOFind=true;
1571 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1574 return selection.getBranch();
1579 void VymModel::findReset()
1580 { // Necessary if text to find changes during a find process
1587 void VymModel::setScene (QGraphicsScene *s)
1590 init(); // Here we have a mapScene set,
1591 // which is (still) needed to create MapCenters
1594 void VymModel::setURL(const QString &url)
1596 BranchObj *bo=selection.getBranch();
1599 QString oldurl=bo->getURL();
1603 QString ("setURL (\"%1\")").arg(oldurl),
1605 QString ("setURL (\"%1\")").arg(url),
1606 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1611 ensureSelectionVisible();
1615 QString VymModel::getURL()
1617 BranchObj *bo=selection.getBranch();
1619 return bo->getURL();
1624 QStringList VymModel::getURLs()
1627 BranchObj *bo=selection.getBranch();
1633 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1640 void VymModel::linkFloatImageTo(const QString &dstString)
1642 FloatImageObj *fio=selection.getFloatImage();
1645 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1646 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1647 typeid(*dst)==typeid (MapCenterObj)))
1649 LinkableMapObj *dstPar=dst->getParObj();
1650 QString parString=getSelectString(dstPar);
1651 QString fioPreSelectString=getSelectString(fio);
1652 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1653 ((BranchObj*)dst)->addFloatImage (fio);
1654 selection.unselect();
1655 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1656 fio=((BranchObj*)dst)->getLastFloatImage();
1659 selection.select(fio);
1661 getSelectString(fio),
1662 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1664 QString ("linkTo (\"%1\")").arg(dstString),
1665 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1671 void VymModel::setFrameType(const FrameObj::FrameType &t)
1673 BranchObj *bo=selection.getBranch();
1676 QString s=bo->getFrameTypeName();
1677 bo->setFrameType (t);
1678 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1679 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1685 void VymModel::setFrameType(const QString &s)
1687 BranchObj *bo=selection.getBranch();
1690 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1691 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1692 bo->setFrameType (s);
1698 void VymModel::setFramePenColor(const QColor &c)
1700 BranchObj *bo=selection.getBranch();
1703 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1704 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1705 bo->setFramePenColor (c);
1709 void VymModel::setFrameBrushColor(const QColor &c)
1711 BranchObj *bo=selection.getBranch();
1714 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1715 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1716 bo->setFrameBrushColor (c);
1720 void VymModel::setFramePadding (const int &i)
1722 BranchObj *bo=selection.getBranch();
1725 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1726 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1727 bo->setFramePadding (i);
1733 void VymModel::setFrameBorderWidth(const int &i)
1735 BranchObj *bo=selection.getBranch();
1738 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1739 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1740 bo->setFrameBorderWidth (i);
1746 void VymModel::setIncludeImagesVer(bool b)
1748 BranchObj *bo=selection.getBranch();
1751 QString u= b ? "false" : "true";
1752 QString r=!b ? "false" : "true";
1756 QString("setIncludeImagesVertically (%1)").arg(u),
1758 QString("setIncludeImagesVertically (%1)").arg(r),
1759 QString("Include images vertically in %1").arg(getObjectName(bo))
1761 bo->setIncludeImagesVer(b);
1766 void VymModel::setIncludeImagesHor(bool b)
1768 BranchObj *bo=selection.getBranch();
1771 QString u= b ? "false" : "true";
1772 QString r=!b ? "false" : "true";
1776 QString("setIncludeImagesHorizontally (%1)").arg(u),
1778 QString("setIncludeImagesHorizontally (%1)").arg(r),
1779 QString("Include images horizontally in %1").arg(getObjectName(bo))
1781 bo->setIncludeImagesHor(b);
1786 void VymModel::setHideLinkUnselected (bool b)
1788 LinkableMapObj *sel=selection.single();
1790 (selection.type() == Selection::Branch ||
1791 selection.type() == Selection::MapCenter ||
1792 selection.type() == Selection::FloatImage ))
1794 QString u= b ? "false" : "true";
1795 QString r=!b ? "false" : "true";
1799 QString("setHideLinkUnselected (%1)").arg(u),
1801 QString("setHideLinkUnselected (%1)").arg(r),
1802 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1804 sel->setHideLinkUnselected(b);
1808 void VymModel::setHideExport(bool b)
1810 BranchObj *bo=selection.getBranch();
1813 bo->setHideInExport (b);
1814 QString u= b ? "false" : "true";
1815 QString r=!b ? "false" : "true";
1819 QString ("setHideExport (%1)").arg(u),
1821 QString ("setHideExport (%1)").arg(r),
1822 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r)
1827 // FIXME needed? scene()->update();
1831 void VymModel::toggleHideExport()
1833 BranchObj *bo=selection.getBranch();
1835 setHideExport ( !bo->hideInExport() );
1839 void VymModel::copy()
1841 LinkableMapObj *sel=selection.single();
1844 if (redosAvail == 0)
1847 QString s=getSelectString(sel);
1848 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1849 curClipboard=curStep;
1852 // Copy also to global clipboard, because we are at last step in history
1853 QString bakMapName(QString("history-%1").arg(curStep));
1854 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1855 copyDir (bakMapDir,clipboardDir );
1857 clipboardEmpty=false;
1863 void VymModel::pasteNoSave(const int &n)
1865 bool old=blockSaveState;
1866 blockSaveState=true;
1867 bool zippedOrg=zipped;
1868 if (redosAvail > 0 || n!=0)
1870 // Use the "historical" buffer
1871 QString bakMapName(QString("history-%1").arg(n));
1872 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1873 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1875 // Use the global buffer
1876 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1881 void VymModel::paste()
1883 BranchObj *sel=selection.getBranch();
1886 saveStateChangingPart(
1889 QString ("paste (%1)").arg(curClipboard),
1890 QString("Paste to %1").arg( getObjectName(sel))
1897 void VymModel::cut()
1899 LinkableMapObj *sel=selection.single();
1900 if ( sel && (selection.type() == Selection::Branch ||
1901 selection.type()==Selection::MapCenter ||
1902 selection.type()==Selection::FloatImage))
1904 /* No savestate! savestate is called in cutNoSave
1905 saveStateChangingPart(
1909 QString("Cut %1").arg(getObjectName(sel ))
1918 void VymModel::moveBranchUp()
1920 BranchObj* bo=selection.getBranch();
1924 if (!bo->canMoveBranchUp()) return;
1925 par=(BranchObj*)(bo->getParObj());
1926 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1927 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1929 //FIXME needed? scene()->update();
1931 ensureSelectionVisible();
1935 void VymModel::moveBranchDown()
1937 BranchObj* bo=selection.getBranch();
1941 if (!bo->canMoveBranchDown()) return;
1942 par=(BranchObj*)(bo->getParObj());
1943 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1944 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1946 //FIXME needed? scene()->update();
1948 ensureSelectionVisible();
1952 void VymModel::sortChildren()
1954 BranchObj* bo=selection.getBranch();
1957 if(bo->countBranches()>1)
1959 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1962 ensureSelectionVisible();
1967 MapCenterObj* VymModel::addMapCenter ()
1969 MapCenterObj *mco=addMapCenter (QPointF(0,0));
1970 selection.select (mco);
1972 ensureSelectionVisible();
1977 // FIXME how to position LineEdit without contextMenuPos ?
1978 // QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()),
1979 // QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y())
1980 QString ("addMapCenter (%1,%2)").arg (0).arg(0),
1981 QString ("Adding MapCenter to (%1,%2").arg (0).arg(0)
1986 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
1988 MapCenterObj *mapCenter = new MapCenterObj(mapScene);
1989 mapCenter->move (absPos);
1990 mapCenter->setVisibility (true);
1991 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
1992 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
1993 mapCenters.append(mapCenter);
1997 MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco)
1999 int i=mapCenters.indexOf (mco);
2002 mapCenters.removeAt (i);
2004 if (i>0) return mapCenters.at(i-1); // Return previous MCO
2010 BranchObj* VymModel::addNewBranchInt(int num)
2012 // Depending on pos:
2013 // -3 insert in children of parent above selection
2014 // -2 add branch to selection
2015 // -1 insert in children of parent below selection
2016 // 0..n insert in children of parent at pos
2017 BranchObj *newbo=NULL;
2018 BranchObj *bo=selection.getBranch();
2023 // save scroll state. If scrolled, automatically select
2024 // new branch in order to tmp unscroll parent...
2025 newbo=bo->addBranch();
2030 bo=(BranchObj*)bo->getParObj();
2031 if (bo) newbo=bo->insertBranch(num);
2035 bo=(BranchObj*)bo->getParObj();
2036 if (bo) newbo=bo->insertBranch(num);
2038 if (!newbo) return NULL;
2043 BranchObj* VymModel::addNewBranch(int pos)
2045 // Different meaning than num in addNewBranchInt!
2049 BranchObj *bo = selection.getBranch();
2050 BranchObj *newbo=NULL;
2054 // FIXME do we still need this in model? setCursor (Qt::ArrowCursor);
2056 newbo=addNewBranchInt (pos-2);
2064 QString ("addBranch (%1)").arg(pos),
2065 QString ("Add new branch to %1").arg(getObjectName(bo)));
2069 latestSelectionString=getSelectString(newbo);
2070 // In Network mode, the client needs to know where the new branch is,
2071 // so we have to pass on this information via saveState.
2072 // TODO: Get rid of this positioning workaround
2073 QString ps=qpointfToString (newbo->getAbsPos());
2074 sendData ("selectLatestAdded ()");
2075 sendData (QString("move %1").arg(ps));
2083 BranchObj* VymModel::addNewBranchBefore()
2085 BranchObj *newbo=NULL;
2086 BranchObj *bo = selection.getBranch();
2087 if (bo && selection.type()==Selection::Branch)
2088 // We accept no MapCenterObj here, so we _have_ a parent
2090 QPointF p=bo->getRelPos();
2093 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2095 // add below selection
2096 newbo=parbo->insertBranch(bo->getNum()+1);
2099 newbo->move2RelPos (p);
2101 // Move selection to new branch
2102 bo->linkTo (newbo,-1);
2104 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2105 QString ("Add branch before %1").arg(getObjectName(bo)));
2111 latestSelectionString=selection.getSelectString();
2115 void VymModel::deleteSelection()
2117 BranchObj *bo = selection.getBranch();
2118 if (bo && selection.type()==Selection::MapCenter)
2120 // BranchObj* par=(BranchObj*)(bo->getParObj());
2121 selection.unselect();
2122 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2123 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2125 bo=removeMapCenter ((MapCenterObj*)bo);
2128 selection.select (bo);
2129 ensureSelectionVisible();
2135 if (bo && selection.type()==Selection::Branch)
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 *)
3680 void VymModel::unregisterEditor(QWidget *)
3684 void VymModel::updateNoteFlag()
3687 BranchObj *bo=selection.getBranch();
3690 bo->updateNoteFlag();
3691 mainWindow->updateActions();
3695 void VymModel::updateRelPositions()
3697 for (int i=0; i<mapCenters.count(); i++)
3698 mapCenters.at(i)->updateRelPositions();
3701 void VymModel::reposition()
3703 for (int i=0;i<mapCenters.count(); i++)
3704 mapCenters.at(i)->reposition(); // for positioning heading
3707 QPolygonF VymModel::shape(BranchObj *bo)
3709 // Creating (arbitrary) shapes
3712 QRectF rb=bo->getBBox();
3713 if (bo->getDepth()==0)
3715 // Just take BBox of this mapCenter
3716 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3720 // Take union of BBox and TotalBBox
3722 QRectF ra=bo->getTotalBBox();
3723 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3726 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3729 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3731 p <<ra.bottomRight()
3733 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3736 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3741 void VymModel::moveAway(LinkableMapObj *lmo)
3745 // Move all branches and MapCenters away from lmo
3746 // to avoid collisions
3751 BranchObj *boA=(BranchObj*)lmo;
3753 for (int i=0; i<mapCenters.count(); i++)
3755 boB=mapCenters.at(i);
3758 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3761 <<" ("<<qPrintable(boA->getHeading() )<<")"
3762 <<" with ("<< qPrintable (boB->getHeading() )
3765 <<" minT="<<r.minTranslation<<endl<<endl;
3769 QPixmap VymModel::getPixmap()
3771 QRectF mapRect=getTotalBBox();
3772 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3775 pp.setRenderHints(mapEditor->renderHints());
3777 // Don't print the visualisation of selection
3778 selection.unselect();
3780 mapScene->render ( &pp,
3781 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3782 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3784 // Restore selection
3785 selection.reselect();
3791 void VymModel::setMapLinkStyle (const QString & s)
3794 if (linkstyle==LinkableMapObj::Line)
3796 else if (linkstyle==LinkableMapObj::Parabel)
3797 snow="StyleParabel";
3798 else if (linkstyle==LinkableMapObj::PolyLine)
3799 snow="StylePolyLine";
3800 else if (linkstyle==LinkableMapObj::PolyParabel)
3801 snow="StyleParabel";
3804 QString("setMapLinkStyle (\"%1\")").arg(s),
3805 QString("setMapLinkStyle (\"%1\")").arg(snow),
3806 QString("Set map link style (\"%1\")").arg(s)
3810 linkstyle=LinkableMapObj::Line;
3811 else if (s=="StyleParabel")
3812 linkstyle=LinkableMapObj::Parabel;
3813 else if (s=="StylePolyLine")
3814 linkstyle=LinkableMapObj::PolyLine;
3816 linkstyle=LinkableMapObj::PolyParabel;
3823 bo->setLinkStyle(bo->getDefLinkStyle());
3829 LinkableMapObj::Style VymModel::getMapLinkStyle ()
3834 void VymModel::setMapDefLinkColor(QColor col)
3836 if ( !col.isValid() ) return;
3838 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3839 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3840 QString("Set map link color to %1").arg(col.name())
3854 void VymModel::setMapLinkColorHintInt()
3856 // called from setMapLinkColorHint(lch) or at end of parse
3866 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3869 setMapLinkColorHintInt();
3872 void VymModel::toggleMapLinkColorHint()
3874 if (linkcolorhint==LinkableMapObj::HeadingColor)
3875 linkcolorhint=LinkableMapObj::DefaultColor;
3877 linkcolorhint=LinkableMapObj::HeadingColor;
3887 void VymModel::selectMapBackgroundImage ()
3889 Q3FileDialog *fd=new Q3FileDialog( NULL);
3890 fd->setMode (Q3FileDialog::ExistingFile);
3891 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3892 ImagePreview *p =new ImagePreview (fd);
3893 fd->setContentsPreviewEnabled( TRUE );
3894 fd->setContentsPreview( p, p );
3895 fd->setPreviewMode( Q3FileDialog::Contents );
3896 fd->setCaption(vymName+" - " +tr("Load background image"));
3897 fd->setDir (lastImageDir);
3900 if ( fd->exec() == QDialog::Accepted )
3902 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3903 lastImageDir=QDir (fd->dirPath());
3904 setMapBackgroundImage (fd->selectedFile());
3908 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3910 QColor oldcol=mapScene->backgroundBrush().color();
3914 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3916 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3917 QString("Set background color of map to %1").arg(col.name()));
3920 brush.setTextureImage (QPixmap (fn));
3921 mapScene->setBackgroundBrush(brush);
3924 void VymModel::selectMapBackgroundColor()
3926 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
3927 if ( !col.isValid() ) return;
3928 setMapBackgroundColor( col );
3932 void VymModel::setMapBackgroundColor(QColor col)
3934 QColor oldcol=mapScene->backgroundBrush().color();
3936 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3937 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3938 QString("Set background color of map to %1").arg(col.name()));
3939 mapScene->setBackgroundBrush(col);
3942 QColor VymModel::getMapBackgroundColor()
3944 return mapScene->backgroundBrush().color();
3948 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint()
3950 return linkcolorhint;
3953 QColor VymModel::getMapDefLinkColor()
3955 return defLinkColor;
3958 void VymModel::setMapDefXLinkColor(QColor col)
3963 QColor VymModel::getMapDefXLinkColor()
3965 return defXLinkColor;
3968 void VymModel::setMapDefXLinkWidth (int w)
3973 int VymModel::getMapDefXLinkWidth()
3975 return defXLinkWidth;
3978 void VymModel::move(const double &x, const double &y)
3980 LinkableMapObj *sel=selection.single();
3983 QPointF ap(sel->getAbsPos());
3987 QString ps=qpointfToString(ap);
3988 QString s=selection.getSelectString();
3991 s, "move "+qpointfToString(to),
3992 QString("Move %1 to %2").arg(getObjectName(sel)).arg(ps));
4000 void VymModel::moveRel (const double &x, const double &y)
4002 LinkableMapObj *sel=selection.single();
4005 QPointF rp(sel->getRelPos());
4009 QString ps=qpointfToString (sel->getRelPos());
4010 QString s=getSelectString(sel);
4013 s, "moveRel "+qpointfToString(to),
4014 QString("Move %1 to relative position %2").arg(getObjectName(sel)).arg(ps));
4015 ((OrnamentedObj*)sel)->move2RelPos (x,y);
4024 void VymModel::animate()
4026 animationTimer->stop();
4029 while (i<animObjList.size() )
4031 bo=(BranchObj*)animObjList.at(i);
4036 animObjList.removeAt(i);
4043 mapEditor->updateSelection();
4045 animationTimer->start();
4049 void VymModel::startAnimation(const QPointF &start, const QPointF &dest)
4051 BranchObj *bo=getSelectedBranch();
4052 if (bo && bo->getDepth()>0)
4055 ap.setStart (start);
4057 ap.setTicks (animationTicks);
4058 ap.setAnimated (true);
4059 bo->setAnimation (ap);
4060 animObjList.append( bo );
4061 animationTimer->setSingleShot (true);
4062 animationTimer->start(animationInterval);
4066 void VymModel::sendSelection()
4068 if (netstate!=Server) return;
4069 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4072 void VymModel::newServer()
4076 tcpServer = new QTcpServer(this);
4077 if (!tcpServer->listen(QHostAddress::Any,port)) {
4078 QMessageBox::critical(NULL, "vym server",
4079 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4080 //FIXME needed? we are no widget any longer... close();
4083 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4085 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4088 void VymModel::connectToServer()
4091 server="salam.suse.de";
4093 clientSocket = new QTcpSocket (this);
4094 clientSocket->abort();
4095 clientSocket->connectToHost(server ,port);
4096 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4097 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4098 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4100 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4105 void VymModel::newClient()
4107 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4108 connect(newClient, SIGNAL(disconnected()),
4109 newClient, SLOT(deleteLater()));
4111 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4113 clientList.append (newClient);
4117 void VymModel::sendData(const QString &s)
4119 if (clientList.size()==0) return;
4121 // Create bytearray to send
4123 QDataStream out(&block, QIODevice::WriteOnly);
4124 out.setVersion(QDataStream::Qt_4_0);
4126 // Reserve some space for blocksize
4129 // Write sendCounter
4130 out << sendCounter++;
4135 // Go back and write blocksize so far
4136 out.device()->seek(0);
4137 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4141 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4143 for (int i=0; i<clientList.size(); ++i)
4145 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4146 clientList.at(i)->write (block);
4150 void VymModel::readData ()
4152 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4155 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4159 QDataStream in(clientSocket);
4160 in.setVersion(QDataStream::Qt_4_0);
4168 cout << " t="<<qPrintable (t)<<endl;
4174 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4176 switch (socketError) {
4177 case QAbstractSocket::RemoteHostClosedError:
4179 case QAbstractSocket::HostNotFoundError:
4180 QMessageBox::information(NULL, vymName +" Network client",
4181 "The host was not found. Please check the "
4182 "host name and port settings.");
4184 case QAbstractSocket::ConnectionRefusedError:
4185 QMessageBox::information(NULL, vymName + " Network client",
4186 "The connection was refused by the peer. "
4187 "Make sure the fortune server is running, "
4188 "and check that the host name and port "
4189 "settings are correct.");
4192 QMessageBox::information(NULL, vymName + " Network client",
4193 QString("The following error occurred: %1.")
4194 .arg(clientSocket->errorString()));
4201 void VymModel::selectMapSelectionColor()
4203 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4204 setSelectionColor (col);
4207 void VymModel::setSelectionColorInt (QColor col)
4209 if ( !col.isValid() ) return;
4211 QString("setSelectionColor (%1)").arg(selection.getColor().name()),
4212 QString("setSelectionColor (%1)").arg(col.name()),
4213 QString("Set color of selection box to %1").arg(col.name())
4216 selection.setColor (col);
4219 void VymModel::updateSelection()
4224 void VymModel::setSelectionColor(QColor col)
4226 if ( !col.isValid() ) return;
4228 QString("setSelectionColor (%1)").arg(selection.getColor().name()),
4229 QString("setSelectionColor (%1)").arg(col.name()),
4230 QString("Set color of selection box to %1").arg(col.name())
4232 setSelectionColorInt (col);
4235 QColor VymModel::getSelectionColor()
4237 return selection.getColor();
4240 void VymModel::setHideTmpMode (HideTmpMode mode)
4243 for (int i=0;i<mapCenters.count(); i++)
4244 mapCenters.at(i)->setHideTmp (mode);
4246 // FIXME needed? scene()->update();
4250 QRectF VymModel::getTotalBBox()
4253 for (int i=0;i<mapCenters.count(); i++)
4254 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4258 //////////////////////////////////////////////
4259 // Selection related
4260 //////////////////////////////////////////////
4262 void VymModel::setSelectionBlocked (bool b)
4267 selection.unblock();
4270 bool VymModel::isSelectionBlocked()
4272 return selection.isBlocked();
4275 bool VymModel::select (const QString &s)
4277 if (selection.select(s))
4280 ensureSelectionVisible();
4288 bool VymModel::select (LinkableMapObj *lmo)
4290 if (selection.select(lmo))
4293 ensureSelectionVisible();
4300 void VymModel::unselect()
4302 selection.unselect();
4305 void VymModel::reselect()
4307 selection.reselect();
4310 void VymModel::ensureSelectionVisible()
4312 LinkableMapObj *lmo=selection.single();
4313 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4317 void VymModel::selectInt (LinkableMapObj *lmo)
4319 if (selection.select(lmo))
4327 void VymModel::selectNextBranchInt()
4329 // Increase number of branch
4330 LinkableMapObj *sel=selection.single();
4333 QString s=selection.getSelectString();
4339 part=s.section(",",-1);
4341 num=part.right(part.length() - 3);
4343 s=s.left (s.length() -num.length());
4346 num=QString ("%1").arg(num.toUInt()+1);
4350 // Try to select this one
4351 if (select (s)) return;
4353 // We have no direct successor,
4354 // try to increase the parental number in order to
4355 // find a successor with same depth
4357 int d=selection.single()->getDepth();
4362 while (!found && d>0)
4364 s=s.section (",",0,d-1);
4365 // replace substring of current depth in s with "1"
4366 part=s.section(",",-1);
4368 num=part.right(part.length() - 3);
4372 // increase number of parent
4373 num=QString ("%1").arg(num.toUInt()+1);
4374 s=s.section (",",0,d-2) + ","+ typ+num;
4377 // Special case, look at orientation
4378 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4379 num=QString ("%1").arg(num.toUInt()+1);
4381 num=QString ("%1").arg(num.toUInt()-1);
4386 // pad to oldDepth, select the first branch for each depth
4387 for (i=d;i<oldDepth;i++)
4392 if ( selection.getBranch()->countBranches()>0)
4400 // try to select the freshly built string
4408 void VymModel::selectPrevBranchInt()
4410 // Decrease number of branch
4411 BranchObj *bo=selection.getBranch();
4414 QString s=selection.getSelectString();
4420 part=s.section(",",-1);
4422 num=part.right(part.length() - 3);
4424 s=s.left (s.length() -num.length());
4426 int n=num.toInt()-1;
4429 num=QString ("%1").arg(n);
4432 // Try to select this one
4433 if (n>=0 && select (s)) return;
4435 // We have no direct precessor,
4436 // try to decrease the parental number in order to
4437 // find a precessor with same depth
4439 int d=selection.single()->getDepth();
4444 while (!found && d>0)
4446 s=s.section (",",0,d-1);
4447 // replace substring of current depth in s with "1"
4448 part=s.section(",",-1);
4450 num=part.right(part.length() - 3);
4454 // decrease number of parent
4455 num=QString ("%1").arg(num.toInt()-1);
4456 s=s.section (",",0,d-2) + ","+ typ+num;
4459 // Special case, look at orientation
4460 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4461 num=QString ("%1").arg(num.toInt()-1);
4463 num=QString ("%1").arg(num.toInt()+1);
4468 // pad to oldDepth, select the last branch for each depth
4469 for (i=d;i<oldDepth;i++)
4473 if ( selection.getBranch()->countBranches()>0)
4474 s+=",bo:"+ QString ("%1").arg( selection.getBranch()->countBranches()-1 );
4481 // try to select the freshly built string
4489 void VymModel::selectUpperBranch()
4491 if (selection.isBlocked() ) return;
4493 BranchObj *bo=selection.getBranch();
4494 if (bo && selection.type()==Selection::Branch)
4496 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4497 selectPrevBranchInt();
4499 if (bo->getDepth()==1)
4500 selectNextBranchInt();
4502 selectPrevBranchInt();
4506 void VymModel::selectLowerBranch()
4508 if (selection.isBlocked() ) return;
4510 BranchObj *bo=selection.getBranch();
4511 if (bo && selection.type()==Selection::Branch)
4513 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4514 selectNextBranchInt();
4516 if (bo->getDepth()==1)
4517 selectPrevBranchInt();
4519 selectNextBranchInt();
4524 void VymModel::selectLeftBranch()
4526 if (selection.isBlocked() ) return;
4530 LinkableMapObj *sel=selection.single();
4533 if (selection.type()== Selection::MapCenter)
4535 par=selection.getBranch();
4536 bo=par->getLastSelectedBranch();
4539 // Workaround for reselecting on left and right side
4540 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4541 bo=par->getLastBranch();
4544 bo=par->getLastBranch();
4545 selection.select(bo);
4547 ensureSelectionVisible();
4553 par=(BranchObj*)(sel->getParObj());
4554 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4556 if (selection.type() == Selection::Branch ||
4557 selection.type() == Selection::FloatImage)
4559 selection.select(par);
4561 ensureSelectionVisible();
4566 if (selection.type() == Selection::Branch )
4568 bo=selection.getBranch()->getLastSelectedBranch();
4571 selection.select(bo);
4573 ensureSelectionVisible();
4582 void VymModel::selectRightBranch()
4584 if (selection.isBlocked() ) return;
4588 LinkableMapObj *sel=selection.single();
4591 if (selection.type()==Selection::MapCenter)
4593 par=selection.getBranch();
4594 bo=par->getLastSelectedBranch();
4597 // Workaround for reselecting on left and right side
4598 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4599 bo=par->getFirstBranch();
4602 selection.select(bo);
4604 ensureSelectionVisible();
4610 par=(BranchObj*)(selection.single()->getParObj());
4611 if (selection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
4613 if (selection.type() == Selection::Branch ||
4614 selection.type() == Selection::FloatImage)
4616 selection.select(par);
4618 ensureSelectionVisible();
4623 if (selection.type() == Selection::Branch)
4625 bo=selection.getBranch()->getLastSelectedBranch();
4628 selection.select(bo);
4630 ensureSelectionVisible();
4639 void VymModel::selectFirstBranch()
4641 BranchObj *bo1=selection.getBranch();
4646 par=(BranchObj*)(bo1->getParObj());
4648 bo2=par->getFirstBranch();
4650 selection.select(bo2);
4652 ensureSelectionVisible();
4658 void VymModel::selectLastBranch()
4660 BranchObj *bo1=selection.getBranch();
4665 par=(BranchObj*)(bo1->getParObj());
4667 bo2=par->getLastBranch();
4670 selection.select(bo2);
4672 ensureSelectionVisible();
4678 Selection::Type VymModel::selectionType()
4680 return selection.type();
4683 LinkableMapObj* VymModel::getSelection()
4685 return selection.single();
4687 BranchObj* VymModel::getSelectedBranch()
4689 return selection.getBranch();
4692 FloatImageObj* VymModel::getSelectedFloatImage()
4694 return selection.getFloatImage();
4697 QString VymModel::getSelectString ()
4699 return selection.getSelectString();
4702 QString VymModel::getSelectString (LinkableMapObj *lmo)
4706 if (typeid(*lmo)==typeid(BranchObj) ||
4707 typeid(*lmo)==typeid(MapCenterObj) )
4709 LinkableMapObj *par=lmo->getParObj();
4712 if (lmo->getDepth() ==1)
4713 // Mainbranch, return
4714 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4716 // Branch, call myself recursively
4717 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4721 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
4722 if (i>=0) s=QString("mc:%1").arg(i);