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 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
1428 for (int i=0; i<mapCenters.count(); i++)
1429 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
1433 //////////////////////////////////////////////
1435 //////////////////////////////////////////////
1436 void VymModel::setVersion (const QString &s)
1441 void VymModel::setAuthor (const QString &s)
1444 QString ("setMapAuthor (\"%1\")").arg(author),
1445 QString ("setMapAuthor (\"%1\")").arg(s),
1446 QString ("Set author of map to \"%1\"").arg(s)
1452 QString VymModel::getAuthor()
1457 void VymModel::setComment (const QString &s)
1460 QString ("setMapComment (\"%1\")").arg(comment),
1461 QString ("setMapComment (\"%1\")").arg(s),
1462 QString ("Set comment of map")
1468 QString VymModel::getComment ()
1473 QString VymModel::getDate ()
1475 return QDate::currentDate().toString ("yyyy-MM-dd");
1478 void VymModel::setHeading(const QString &s)
1480 BranchObj *sel=selection.getBranch();
1485 "setHeading (\""+sel->getHeading()+"\")",
1487 "setHeading (\""+s+"\")",
1488 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1489 sel->setHeading(s );
1492 ensureSelectionVisible();
1496 QString VymModel::getHeading(bool &ok, QPoint &p)
1498 BranchObj *bo=selection.getBranch();
1502 //p=scene->mapFromScene(bo->getAbsPos()); // FIXME this is view-dependant!!!
1503 return bo->getHeading();
1510 void VymModel::setHeadingInt(const QString &s)
1512 BranchObj *bo=selection.getBranch();
1518 ensureSelectionVisible();
1522 BranchObj* VymModel::findText (QString s, bool cs)
1524 QTextDocument::FindFlags flags=0;
1525 if (cs) flags=QTextDocument::FindCaseSensitively;
1528 { // Nothing found or new find process
1530 // nothing found, start again
1534 bool searching=true;
1535 bool foundNote=false;
1536 while (searching && !EOFind)
1540 // Searching in Note
1541 if (itFind->getNote().contains(s,cs))
1543 if (selection.single()!=itFind)
1545 selection.select(itFind);
1546 ensureSelectionVisible();
1548 if (textEditor->findText(s,flags))
1554 // Searching in Heading
1555 if (searching && itFind->getHeading().contains (s,cs) )
1557 selection.select(itFind);
1558 ensureSelectionVisible();
1564 itFind=next(itFind);
1565 if (!itFind) EOFind=true;
1567 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1570 return selection.getBranch();
1575 void VymModel::findReset()
1576 { // Necessary if text to find changes during a find process
1583 void VymModel::setScene (QGraphicsScene *s)
1586 init(); // Here we have a mapScene set,
1587 // which is (still) needed to create MapCenters
1590 void VymModel::setURL(const QString &url)
1592 BranchObj *bo=selection.getBranch();
1595 QString oldurl=bo->getURL();
1599 QString ("setURL (\"%1\")").arg(oldurl),
1601 QString ("setURL (\"%1\")").arg(url),
1602 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1607 ensureSelectionVisible();
1611 QString VymModel::getURL()
1613 BranchObj *bo=selection.getBranch();
1615 return bo->getURL();
1620 QStringList VymModel::getURLs()
1623 BranchObj *bo=selection.getBranch();
1629 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1636 void VymModel::linkFloatImageTo(const QString &dstString)
1638 FloatImageObj *fio=selection.getFloatImage();
1641 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1642 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1643 typeid(*dst)==typeid (MapCenterObj)))
1645 LinkableMapObj *dstPar=dst->getParObj();
1646 QString parString=getSelectString(dstPar);
1647 QString fioPreSelectString=getSelectString(fio);
1648 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1649 ((BranchObj*)dst)->addFloatImage (fio);
1650 selection.unselect();
1651 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1652 fio=((BranchObj*)dst)->getLastFloatImage();
1655 selection.select(fio);
1657 getSelectString(fio),
1658 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1660 QString ("linkTo (\"%1\")").arg(dstString),
1661 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1667 void VymModel::setFrameType(const FrameObj::FrameType &t)
1669 BranchObj *bo=selection.getBranch();
1672 QString s=bo->getFrameTypeName();
1673 bo->setFrameType (t);
1674 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1675 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1681 void VymModel::setFrameType(const QString &s)
1683 BranchObj *bo=selection.getBranch();
1686 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1687 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1688 bo->setFrameType (s);
1694 void VymModel::setFramePenColor(const QColor &c)
1696 BranchObj *bo=selection.getBranch();
1699 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1700 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1701 bo->setFramePenColor (c);
1705 void VymModel::setFrameBrushColor(const QColor &c)
1707 BranchObj *bo=selection.getBranch();
1710 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1711 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1712 bo->setFrameBrushColor (c);
1716 void VymModel::setFramePadding (const int &i)
1718 BranchObj *bo=selection.getBranch();
1721 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1722 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1723 bo->setFramePadding (i);
1729 void VymModel::setFrameBorderWidth(const int &i)
1731 BranchObj *bo=selection.getBranch();
1734 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1735 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1736 bo->setFrameBorderWidth (i);
1742 void VymModel::setIncludeImagesVer(bool b)
1744 BranchObj *bo=selection.getBranch();
1747 QString u= b ? "false" : "true";
1748 QString r=!b ? "false" : "true";
1752 QString("setIncludeImagesVertically (%1)").arg(u),
1754 QString("setIncludeImagesVertically (%1)").arg(r),
1755 QString("Include images vertically in %1").arg(getObjectName(bo))
1757 bo->setIncludeImagesVer(b);
1762 void VymModel::setIncludeImagesHor(bool b)
1764 BranchObj *bo=selection.getBranch();
1767 QString u= b ? "false" : "true";
1768 QString r=!b ? "false" : "true";
1772 QString("setIncludeImagesHorizontally (%1)").arg(u),
1774 QString("setIncludeImagesHorizontally (%1)").arg(r),
1775 QString("Include images horizontally in %1").arg(getObjectName(bo))
1777 bo->setIncludeImagesHor(b);
1782 void VymModel::setHideLinkUnselected (bool b)
1784 LinkableMapObj *sel=selection.single();
1786 (selection.type() == Selection::Branch ||
1787 selection.type() == Selection::MapCenter ||
1788 selection.type() == Selection::FloatImage ))
1790 QString u= b ? "false" : "true";
1791 QString r=!b ? "false" : "true";
1795 QString("setHideLinkUnselected (%1)").arg(u),
1797 QString("setHideLinkUnselected (%1)").arg(r),
1798 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1800 sel->setHideLinkUnselected(b);
1804 void VymModel::setHideExport(bool b)
1806 BranchObj *bo=selection.getBranch();
1809 bo->setHideInExport (b);
1810 QString u= b ? "false" : "true";
1811 QString r=!b ? "false" : "true";
1815 QString ("setHideExport (%1)").arg(u),
1817 QString ("setHideExport (%1)").arg(r),
1818 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r)
1823 // FIXME needed? scene()->update();
1827 void VymModel::toggleHideExport()
1829 BranchObj *bo=selection.getBranch();
1831 setHideExport ( !bo->hideInExport() );
1835 void VymModel::copy()
1837 LinkableMapObj *sel=selection.single();
1840 if (redosAvail == 0)
1843 QString s=getSelectString(sel);
1844 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1845 curClipboard=curStep;
1848 // Copy also to global clipboard, because we are at last step in history
1849 QString bakMapName(QString("history-%1").arg(curStep));
1850 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1851 copyDir (bakMapDir,clipboardDir );
1853 clipboardEmpty=false;
1859 void VymModel::pasteNoSave(const int &n)
1861 bool old=blockSaveState;
1862 blockSaveState=true;
1863 bool zippedOrg=zipped;
1864 if (redosAvail > 0 || n!=0)
1866 // Use the "historical" buffer
1867 QString bakMapName(QString("history-%1").arg(n));
1868 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1869 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1871 // Use the global buffer
1872 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1877 void VymModel::paste()
1879 BranchObj *sel=selection.getBranch();
1882 saveStateChangingPart(
1885 QString ("paste (%1)").arg(curClipboard),
1886 QString("Paste to %1").arg( getObjectName(sel))
1893 void VymModel::cut()
1895 LinkableMapObj *sel=selection.single();
1896 if ( sel && (selection.type() == Selection::Branch ||
1897 selection.type()==Selection::MapCenter ||
1898 selection.type()==Selection::FloatImage))
1900 /* No savestate! savestate is called in cutNoSave
1901 saveStateChangingPart(
1905 QString("Cut %1").arg(getObjectName(sel ))
1914 void VymModel::moveBranchUp()
1916 BranchObj* bo=selection.getBranch();
1920 if (!bo->canMoveBranchUp()) return;
1921 par=(BranchObj*)(bo->getParObj());
1922 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1923 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1925 //FIXME needed? scene()->update();
1927 ensureSelectionVisible();
1931 void VymModel::moveBranchDown()
1933 BranchObj* bo=selection.getBranch();
1937 if (!bo->canMoveBranchDown()) return;
1938 par=(BranchObj*)(bo->getParObj());
1939 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1940 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1942 //FIXME needed? scene()->update();
1944 ensureSelectionVisible();
1948 void VymModel::sortChildren()
1950 BranchObj* bo=selection.getBranch();
1953 if(bo->countBranches()>1)
1955 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1958 ensureSelectionVisible();
1963 MapCenterObj* VymModel::addMapCenter ()
1965 MapCenterObj *mco=addMapCenter (QPointF(0,0));
1966 selection.select (mco);
1968 ensureSelectionVisible();
1973 // FIXME how to position LineEdit without contextMenuPos ?
1974 // QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()),
1975 // QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y())
1976 QString ("addMapCenter (%1,%2)").arg (0).arg(0),
1977 QString ("Adding MapCenter to (%1,%2").arg (0).arg(0)
1982 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
1984 MapCenterObj *mapCenter = new MapCenterObj(mapScene);
1985 mapCenter->move (absPos);
1986 mapCenter->setVisibility (true);
1987 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
1988 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
1989 mapCenters.append(mapCenter);
1993 MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco)
1995 int i=mapCenters.indexOf (mco);
1998 mapCenters.removeAt (i);
2000 if (i>0) return mapCenters.at(i-1); // Return previous MCO
2006 BranchObj* VymModel::addNewBranchInt(int num)
2008 // Depending on pos:
2009 // -3 insert in children of parent above selection
2010 // -2 add branch to selection
2011 // -1 insert in children of parent below selection
2012 // 0..n insert in children of parent at pos
2013 BranchObj *newbo=NULL;
2014 BranchObj *bo=selection.getBranch();
2019 // save scroll state. If scrolled, automatically select
2020 // new branch in order to tmp unscroll parent...
2021 newbo=bo->addBranch();
2026 bo=(BranchObj*)bo->getParObj();
2027 if (bo) newbo=bo->insertBranch(num);
2031 bo=(BranchObj*)bo->getParObj();
2032 if (bo) newbo=bo->insertBranch(num);
2034 if (!newbo) return NULL;
2039 BranchObj* VymModel::addNewBranch(int pos)
2041 // Different meaning than num in addNewBranchInt!
2045 BranchObj *bo = selection.getBranch();
2046 BranchObj *newbo=NULL;
2050 // FIXME do we still need this in model? setCursor (Qt::ArrowCursor);
2052 newbo=addNewBranchInt (pos-2);
2060 QString ("addBranch (%1)").arg(pos),
2061 QString ("Add new branch to %1").arg(getObjectName(bo)));
2065 latestSelectionString=getSelectString(newbo);
2066 // In Network mode, the client needs to know where the new branch is,
2067 // so we have to pass on this information via saveState.
2068 // TODO: Get rid of this positioning workaround
2069 QString ps=qpointfToString (newbo->getAbsPos());
2070 sendData ("selectLatestAdded ()");
2071 sendData (QString("move %1").arg(ps));
2079 BranchObj* VymModel::addNewBranchBefore()
2081 BranchObj *newbo=NULL;
2082 BranchObj *bo = selection.getBranch();
2083 if (bo && selection.type()==Selection::Branch)
2084 // We accept no MapCenterObj here, so we _have_ a parent
2086 QPointF p=bo->getRelPos();
2089 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2091 // add below selection
2092 newbo=parbo->insertBranch(bo->getNum()+1);
2095 newbo->move2RelPos (p);
2097 // Move selection to new branch
2098 bo->linkTo (newbo,-1);
2100 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2101 QString ("Add branch before %1").arg(getObjectName(bo)));
2107 latestSelectionString=selection.getSelectString();
2111 void VymModel::deleteSelection()
2113 BranchObj *bo = selection.getBranch();
2114 if (bo && selection.type()==Selection::MapCenter)
2116 // BranchObj* par=(BranchObj*)(bo->getParObj());
2117 selection.unselect();
2118 /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!)
2119 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2121 bo=removeMapCenter ((MapCenterObj*)bo);
2124 selection.select (bo);
2125 ensureSelectionVisible();
2131 if (bo && selection.type()==Selection::Branch)
2133 //FIXME need to check if any animObj is part of Branch, remove from animated obj list then
2138 BranchObj* par=(BranchObj*)bo->getParObj();
2139 selection.unselect();
2140 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2141 par->removeBranch(bo);
2142 selection.select (par);
2143 ensureSelectionVisible();
2148 FloatImageObj *fio=selection.getFloatImage();
2151 BranchObj* par=(BranchObj*)fio->getParObj();
2152 saveStateChangingPart(
2156 QString("Delete %1").arg(getObjectName(fio))
2158 selection.unselect();
2159 par->removeFloatImage(fio);
2160 selection.select (par);
2163 ensureSelectionVisible();
2168 void VymModel::deleteKeepChildren()
2170 BranchObj *bo=selection.getBranch();
2174 par=(BranchObj*)(bo->getParObj());
2175 QPointF p=bo->getRelPos();
2176 saveStateChangingPart(
2179 "deleteKeepChildren ()",
2180 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2183 QString sel=getSelectString(bo);
2185 par->removeBranchHere(bo);
2188 selection.getBranch()->move2RelPos (p);
2193 void VymModel::deleteChildren()
2195 BranchObj *bo=selection.getBranch();
2198 saveStateChangingPart(
2201 "deleteChildren ()",
2202 QString( "Remove children of branch %1").arg(getObjectName(bo))
2204 bo->removeChildren();
2210 bool VymModel::scrollBranch(BranchObj *bo)
2214 if (bo->isScrolled()) return false;
2215 if (bo->countBranches()==0) return false;
2216 if (bo->getDepth()==0) return false;
2222 QString ("%1 ()").arg(u),
2224 QString ("%1 ()").arg(r),
2225 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2229 // FIXME needed? scene()->update();
2235 bool VymModel::unscrollBranch(BranchObj *bo)
2239 if (!bo->isScrolled()) return false;
2240 if (bo->countBranches()==0) return false;
2241 if (bo->getDepth()==0) return false;
2247 QString ("%1 ()").arg(u),
2249 QString ("%1 ()").arg(r),
2250 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2254 // FIXME needed? scene()->update();
2260 void VymModel::toggleScroll()
2262 BranchObj *bo=selection.getBranch();
2263 if (selection.type()==Selection::Branch )
2265 if (bo->isScrolled())
2266 unscrollBranch (bo);
2272 void VymModel::unscrollChildren()
2274 BranchObj *bo=selection.getBranch();
2280 if (bo->isScrolled()) unscrollBranch (bo);
2285 void VymModel::addFloatImage (const QPixmap &img)
2287 BranchObj *bo=selection.getBranch();
2290 FloatImageObj *fio=bo->addFloatImage();
2292 fio->setOriginalFilename("No original filename (image added by dropevent)");
2293 QString s=getSelectString(bo);
2294 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2295 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2297 // FIXME needed? scene()->update();
2302 void VymModel::colorBranch (QColor c)
2304 BranchObj *bo=selection.getBranch();
2309 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2311 QString ("colorBranch (\"%1\")").arg(c.name()),
2312 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2314 bo->setColor(c); // color branch
2318 void VymModel::colorSubtree (QColor c)
2320 BranchObj *bo=selection.getBranch();
2323 saveStateChangingPart(
2326 QString ("colorSubtree (\"%1\")").arg(c.name()),
2327 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2329 bo->setColorSubtree (c); // color links, color children
2333 QColor VymModel::getCurrentHeadingColor()
2335 BranchObj *bo=selection.getBranch();
2336 if (bo) return bo->getColor();
2338 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2344 void VymModel::editURL()
2346 BranchObj *bo=selection.getBranch();
2350 QString text = QInputDialog::getText(
2351 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2352 bo->getURL(), &ok, NULL);
2354 // user entered something and pressed OK
2359 void VymModel::editLocalURL()
2361 BranchObj *bo=selection.getBranch();
2364 QStringList filters;
2365 filters <<"All files (*)";
2366 filters << tr("Text","Filedialog") + " (*.txt)";
2367 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2368 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2369 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2370 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2371 fd->setFilters (filters);
2372 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2373 fd->setDirectory (lastFileDir);
2374 if (! bo->getVymLink().isEmpty() )
2375 fd->selectFile( bo->getURL() );
2378 if ( fd->exec() == QDialog::Accepted )
2380 lastFileDir=QDir (fd->directory().path());
2381 setURL (fd->selectedFile() );
2387 void VymModel::editHeading2URL()
2389 BranchObj *bo=selection.getBranch();
2391 setURL (bo->getHeading());
2394 void VymModel::editBugzilla2URL()
2396 BranchObj *bo=selection.getBranch();
2399 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2404 void VymModel::editFATE2URL()
2406 BranchObj *bo=selection.getBranch();
2409 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2412 "setURL (\""+bo->getURL()+"\")",
2414 "setURL (\""+url+"\")",
2415 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2422 void VymModel::editVymLink()
2424 BranchObj *bo=selection.getBranch();
2427 QStringList filters;
2428 filters <<"VYM map (*.vym)";
2429 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2430 fd->setFilters (filters);
2431 fd->setCaption(vymName+" - " +tr("Link to another map"));
2432 fd->setDirectory (lastFileDir);
2433 if (! bo->getVymLink().isEmpty() )
2434 fd->selectFile( bo->getVymLink() );
2438 if ( fd->exec() == QDialog::Accepted )
2440 lastFileDir=QDir (fd->directory().path());
2443 "setVymLink (\""+bo->getVymLink()+"\")",
2445 "setVymLink (\""+fd->selectedFile()+"\")",
2446 QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile())
2448 setVymLink (fd->selectedFile() ); // FIXME ok?
2453 void VymModel::setVymLink (const QString &s)
2455 // Internal function, no saveState needed
2456 BranchObj *bo=selection.getBranch();
2463 ensureSelectionVisible();
2467 void VymModel::deleteVymLink()
2469 BranchObj *bo=selection.getBranch();
2474 "setVymLink (\""+bo->getVymLink()+"\")",
2476 "setVymLink (\"\")",
2477 QString("Unset vymlink of %1").arg(getObjectName(bo))
2479 bo->setVymLink ("" );
2482 // FIXME needed? scene()->update();
2486 QString VymModel::getVymLink()
2488 BranchObj *bo=selection.getBranch();
2490 return bo->getVymLink();
2496 QStringList VymModel::getVymLinks()
2499 BranchObj *bo=selection.getBranch();
2505 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2513 void VymModel::followXLink(int i)
2515 BranchObj *bo=selection.getBranch();
2518 bo=bo->XLinkTargetAt(i);
2521 selection.select(bo);
2522 ensureSelectionVisible();
2527 void VymModel::editXLink(int i) // FIXME missing saveState
2529 BranchObj *bo=selection.getBranch();
2532 XLinkObj *xlo=bo->XLinkAt(i);
2535 EditXLinkDialog dia;
2537 dia.setSelection(bo);
2538 if (dia.exec() == QDialog::Accepted)
2540 if (dia.useSettingsGlobal() )
2542 setMapDefXLinkColor (xlo->getColor() );
2543 setMapDefXLinkWidth (xlo->getWidth() );
2545 if (dia.deleteXLink())
2546 bo->deleteXLinkAt(i);
2556 //////////////////////////////////////////////
2558 //////////////////////////////////////////////
2560 void VymModel::parseAtom(const QString &atom)
2562 BranchObj *selb=selection.getBranch();
2568 // Split string s into command and parameters
2569 parser.parseAtom (atom);
2570 QString com=parser.getCommand();
2572 // External commands
2573 /////////////////////////////////////////////////////////////////////
2574 if (com=="addBranch")
2576 if (selection.isEmpty())
2578 parser.setError (Aborted,"Nothing selected");
2581 parser.setError (Aborted,"Type of selection is not a branch");
2586 if (parser.checkParCount(pl))
2588 if (parser.parCount()==0)
2592 n=parser.parInt (ok,0);
2593 if (ok ) addNewBranch (n);
2597 /////////////////////////////////////////////////////////////////////
2598 } else if (com=="addBranchBefore")
2600 if (selection.isEmpty())
2602 parser.setError (Aborted,"Nothing selected");
2605 parser.setError (Aborted,"Type of selection is not a branch");
2608 if (parser.parCount()==0)
2610 addNewBranchBefore ();
2613 /////////////////////////////////////////////////////////////////////
2614 } else if (com==QString("addMapCenter"))
2616 if (parser.checkParCount(2))
2618 x=parser.parDouble (ok,0);
2621 y=parser.parDouble (ok,1);
2622 if (ok) addMapCenter (QPointF(x,y));
2625 /////////////////////////////////////////////////////////////////////
2626 } else if (com==QString("addMapReplace"))
2628 if (selection.isEmpty())
2630 parser.setError (Aborted,"Nothing selected");
2633 parser.setError (Aborted,"Type of selection is not a branch");
2634 } else if (parser.checkParCount(1))
2636 //s=parser.parString (ok,0); // selection
2637 t=parser.parString (ok,0); // path to map
2638 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2639 addMapReplaceInt(getSelectString(selb),t);
2641 /////////////////////////////////////////////////////////////////////
2642 } else if (com==QString("addMapInsert"))
2644 if (selection.isEmpty())
2646 parser.setError (Aborted,"Nothing selected");
2649 parser.setError (Aborted,"Type of selection is not a branch");
2652 if (parser.checkParCount(2))
2654 t=parser.parString (ok,0); // path to map
2655 n=parser.parInt(ok,1); // position
2656 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2657 addMapInsertInt(t,n);
2660 /////////////////////////////////////////////////////////////////////
2661 } else if (com=="clearFlags")
2663 if (selection.isEmpty() )
2665 parser.setError (Aborted,"Nothing selected");
2668 parser.setError (Aborted,"Type of selection is not a branch");
2669 } else if (parser.checkParCount(0))
2671 selb->clearStandardFlags();
2672 selb->updateFlagsToolbar();
2674 /////////////////////////////////////////////////////////////////////
2675 } else if (com=="colorBranch")
2677 if (selection.isEmpty())
2679 parser.setError (Aborted,"Nothing selected");
2682 parser.setError (Aborted,"Type of selection is not a branch");
2683 } else if (parser.checkParCount(1))
2685 QColor c=parser.parColor (ok,0);
2686 if (ok) colorBranch (c);
2688 /////////////////////////////////////////////////////////////////////
2689 } else if (com=="colorSubtree")
2691 if (selection.isEmpty())
2693 parser.setError (Aborted,"Nothing selected");
2696 parser.setError (Aborted,"Type of selection is not a branch");
2697 } else if (parser.checkParCount(1))
2699 QColor c=parser.parColor (ok,0);
2700 if (ok) colorSubtree (c);
2702 /////////////////////////////////////////////////////////////////////
2703 } else if (com=="copy")
2705 if (selection.isEmpty())
2707 parser.setError (Aborted,"Nothing selected");
2710 parser.setError (Aborted,"Type of selection is not a branch");
2711 } else if (parser.checkParCount(0))
2713 //FIXME missing action for copy
2715 /////////////////////////////////////////////////////////////////////
2716 } else if (com=="cut")
2718 if (selection.isEmpty())
2720 parser.setError (Aborted,"Nothing selected");
2721 } else if ( selection.type()!=Selection::Branch &&
2722 selection.type()!=Selection::MapCenter &&
2723 selection.type()!=Selection::FloatImage )
2725 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2726 } else if (parser.checkParCount(0))
2730 /////////////////////////////////////////////////////////////////////
2731 } else if (com=="delete")
2733 if (selection.isEmpty())
2735 parser.setError (Aborted,"Nothing selected");
2737 /*else if (selection.type() != Selection::Branch && selection.type() != Selection::FloatImage )
2739 parser.setError (Aborted,"Type of selection is wrong.");
2742 else if (parser.checkParCount(0))
2746 /////////////////////////////////////////////////////////////////////
2747 } else if (com=="deleteKeepChildren")
2749 if (selection.isEmpty())
2751 parser.setError (Aborted,"Nothing selected");
2754 parser.setError (Aborted,"Type of selection is not a branch");
2755 } else if (parser.checkParCount(0))
2757 deleteKeepChildren();
2759 /////////////////////////////////////////////////////////////////////
2760 } else if (com=="deleteChildren")
2762 if (selection.isEmpty())
2764 parser.setError (Aborted,"Nothing selected");
2767 parser.setError (Aborted,"Type of selection is not a branch");
2768 } else if (parser.checkParCount(0))
2772 /////////////////////////////////////////////////////////////////////
2773 } else if (com=="exportASCII")
2777 if (parser.parCount()>=1)
2778 // Hey, we even have a filename
2779 fname=parser.parString(ok,0);
2782 parser.setError (Aborted,"Could not read filename");
2785 exportASCII (fname,false);
2787 /////////////////////////////////////////////////////////////////////
2788 } else if (com=="exportImage")
2792 if (parser.parCount()>=2)
2793 // Hey, we even have a filename
2794 fname=parser.parString(ok,0);
2797 parser.setError (Aborted,"Could not read filename");
2800 QString format="PNG";
2801 if (parser.parCount()>=2)
2803 format=parser.parString(ok,1);
2805 exportImage (fname,false,format);
2807 /////////////////////////////////////////////////////////////////////
2808 } else if (com=="exportXHTML")
2812 if (parser.parCount()>=2)
2813 // Hey, we even have a filename
2814 fname=parser.parString(ok,1);
2817 parser.setError (Aborted,"Could not read filename");
2820 exportXHTML (fname,false);
2822 /////////////////////////////////////////////////////////////////////
2823 } else if (com=="exportXML")
2827 if (parser.parCount()>=2)
2828 // Hey, we even have a filename
2829 fname=parser.parString(ok,1);
2832 parser.setError (Aborted,"Could not read filename");
2835 exportXML (fname,false);
2837 /////////////////////////////////////////////////////////////////////
2838 } else if (com=="importDir")
2840 if (selection.isEmpty())
2842 parser.setError (Aborted,"Nothing selected");
2845 parser.setError (Aborted,"Type of selection is not a branch");
2846 } else if (parser.checkParCount(1))
2848 s=parser.parString(ok,0);
2849 if (ok) importDirInt(s);
2851 /////////////////////////////////////////////////////////////////////
2852 } else if (com=="linkTo")
2854 if (selection.isEmpty())
2856 parser.setError (Aborted,"Nothing selected");
2859 if (parser.checkParCount(4))
2861 // 0 selectstring of parent
2862 // 1 num in parent (for branches)
2863 // 2,3 x,y of mainbranch or mapcenter
2864 s=parser.parString(ok,0);
2865 LinkableMapObj *dst=findObjBySelect (s);
2868 if (typeid(*dst) == typeid(BranchObj) )
2870 // Get number in parent
2871 n=parser.parInt (ok,1);
2874 selb->linkTo ((BranchObj*)(dst),n);
2877 } else if (typeid(*dst) == typeid(MapCenterObj) )
2879 selb->linkTo ((BranchObj*)(dst),-1);
2880 // Get coordinates of mainbranch
2881 x=parser.parDouble(ok,2);
2884 y=parser.parDouble(ok,3);
2894 } else if ( selection.type() == Selection::FloatImage)
2896 if (parser.checkParCount(1))
2898 // 0 selectstring of parent
2899 s=parser.parString(ok,0);
2900 LinkableMapObj *dst=findObjBySelect (s);
2903 if (typeid(*dst) == typeid(BranchObj) ||
2904 typeid(*dst) == typeid(MapCenterObj))
2905 linkFloatImageTo (getSelectString(dst));
2907 parser.setError (Aborted,"Destination is not a branch");
2910 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
2911 /////////////////////////////////////////////////////////////////////
2912 } else if (com=="loadImage")
2914 if (selection.isEmpty())
2916 parser.setError (Aborted,"Nothing selected");
2919 parser.setError (Aborted,"Type of selection is not a branch");
2920 } else if (parser.checkParCount(1))
2922 s=parser.parString(ok,0);
2923 if (ok) loadFloatImageInt (s);
2925 /////////////////////////////////////////////////////////////////////
2926 } else if (com=="moveBranchUp")
2928 if (selection.isEmpty() )
2930 parser.setError (Aborted,"Nothing selected");
2933 parser.setError (Aborted,"Type of selection is not a branch");
2934 } else if (parser.checkParCount(0))
2938 /////////////////////////////////////////////////////////////////////
2939 } else if (com=="moveBranchDown")
2941 if (selection.isEmpty() )
2943 parser.setError (Aborted,"Nothing selected");
2946 parser.setError (Aborted,"Type of selection is not a branch");
2947 } else if (parser.checkParCount(0))
2951 /////////////////////////////////////////////////////////////////////
2952 } else if (com=="move")
2954 if (selection.isEmpty() )
2956 parser.setError (Aborted,"Nothing selected");
2957 } else if ( selection.type()!=Selection::Branch &&
2958 selection.type()!=Selection::MapCenter &&
2959 selection.type()!=Selection::FloatImage )
2961 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2962 } else if (parser.checkParCount(2))
2964 x=parser.parDouble (ok,0);
2967 y=parser.parDouble (ok,1);
2971 /////////////////////////////////////////////////////////////////////
2972 } else if (com=="moveRel")
2974 if (selection.isEmpty() )
2976 parser.setError (Aborted,"Nothing selected");
2977 } else if ( selection.type()!=Selection::Branch &&
2978 selection.type()!=Selection::MapCenter &&
2979 selection.type()!=Selection::FloatImage )
2981 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2982 } else if (parser.checkParCount(2))
2984 x=parser.parDouble (ok,0);
2987 y=parser.parDouble (ok,1);
2988 if (ok) moveRel (x,y);
2991 /////////////////////////////////////////////////////////////////////
2992 } else if (com=="nop")
2994 /////////////////////////////////////////////////////////////////////
2995 } else if (com=="paste")
2997 if (selection.isEmpty() )
2999 parser.setError (Aborted,"Nothing selected");
3002 parser.setError (Aborted,"Type of selection is not a branch");
3003 } else if (parser.checkParCount(1))
3005 n=parser.parInt (ok,0);
3006 if (ok) pasteNoSave(n);
3008 /////////////////////////////////////////////////////////////////////
3009 } else if (com=="qa")
3011 if (selection.isEmpty() )
3013 parser.setError (Aborted,"Nothing selected");
3016 parser.setError (Aborted,"Type of selection is not a branch");
3017 } else if (parser.checkParCount(4))
3020 c=parser.parString (ok,0);
3023 parser.setError (Aborted,"No comment given");
3026 s=parser.parString (ok,1);
3029 parser.setError (Aborted,"First parameter is not a string");
3032 t=parser.parString (ok,2);
3035 parser.setError (Aborted,"Condition is not a string");
3038 u=parser.parString (ok,3);
3041 parser.setError (Aborted,"Third parameter is not a string");
3046 parser.setError (Aborted,"Unknown type: "+s);
3051 parser.setError (Aborted,"Unknown operator: "+t);
3056 parser.setError (Aborted,"Type of selection is not a branch");
3059 if (selb->getHeading() == u)
3061 cout << "PASSED: " << qPrintable (c) << endl;
3064 cout << "FAILED: " << qPrintable (c) << endl;
3074 /////////////////////////////////////////////////////////////////////
3075 } else if (com=="saveImage")
3077 FloatImageObj *fio=selection.getFloatImage();
3080 parser.setError (Aborted,"Type of selection is not an image");
3081 } else if (parser.checkParCount(2))
3083 s=parser.parString(ok,0);
3086 t=parser.parString(ok,1);
3087 if (ok) saveFloatImageInt (fio,t,s);
3090 /////////////////////////////////////////////////////////////////////
3091 } else if (com=="scroll")
3093 if (selection.isEmpty() )
3095 parser.setError (Aborted,"Nothing selected");
3098 parser.setError (Aborted,"Type of selection is not a branch");
3099 } else if (parser.checkParCount(0))
3101 if (!scrollBranch (selb))
3102 parser.setError (Aborted,"Could not scroll branch");
3104 /////////////////////////////////////////////////////////////////////
3105 } else if (com=="select")
3107 if (parser.checkParCount(1))
3109 s=parser.parString(ok,0);
3112 /////////////////////////////////////////////////////////////////////
3113 } else if (com=="selectLastBranch")
3115 if (selection.isEmpty() )
3117 parser.setError (Aborted,"Nothing selected");
3120 parser.setError (Aborted,"Type of selection is not a branch");
3121 } else if (parser.checkParCount(0))
3123 BranchObj *bo=selb->getLastBranch();
3125 parser.setError (Aborted,"Could not select last branch");
3129 /////////////////////////////////////////////////////////////////////
3130 } else if (com=="selectLastImage")
3132 if (selection.isEmpty() )
3134 parser.setError (Aborted,"Nothing selected");
3137 parser.setError (Aborted,"Type of selection is not a branch");
3138 } else if (parser.checkParCount(0))
3140 FloatImageObj *fio=selb->getLastFloatImage();
3142 parser.setError (Aborted,"Could not select last image");
3146 /////////////////////////////////////////////////////////////////////
3147 } else if (com=="selectLatestAdded")
3149 if (latestSelectionString.isEmpty() )
3151 parser.setError (Aborted,"No latest added object");
3154 if (!select (latestSelectionString))
3155 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3157 /////////////////////////////////////////////////////////////////////
3158 } else if (com=="setFrameType")
3160 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3162 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3164 else if (parser.checkParCount(1))
3166 s=parser.parString(ok,0);
3167 if (ok) setFrameType (s);
3169 /////////////////////////////////////////////////////////////////////
3170 } else if (com=="setFramePenColor")
3172 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3174 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3176 else if (parser.checkParCount(1))
3178 QColor c=parser.parColor(ok,0);
3179 if (ok) setFramePenColor (c);
3181 /////////////////////////////////////////////////////////////////////
3182 } else if (com=="setFrameBrushColor")
3184 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3186 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3188 else if (parser.checkParCount(1))
3190 QColor c=parser.parColor(ok,0);
3191 if (ok) setFrameBrushColor (c);
3193 /////////////////////////////////////////////////////////////////////
3194 } else if (com=="setFramePadding")
3196 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3198 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3200 else if (parser.checkParCount(1))
3202 n=parser.parInt(ok,0);
3203 if (ok) setFramePadding(n);
3205 /////////////////////////////////////////////////////////////////////
3206 } else if (com=="setFrameBorderWidth")
3208 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3210 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3212 else if (parser.checkParCount(1))
3214 n=parser.parInt(ok,0);
3215 if (ok) setFrameBorderWidth (n);
3217 /////////////////////////////////////////////////////////////////////
3218 } else if (com=="setMapAuthor")
3220 if (parser.checkParCount(1))
3222 s=parser.parString(ok,0);
3223 if (ok) setAuthor (s);
3225 /////////////////////////////////////////////////////////////////////
3226 } else if (com=="setMapComment")
3228 if (parser.checkParCount(1))
3230 s=parser.parString(ok,0);
3231 if (ok) setComment(s);
3233 /////////////////////////////////////////////////////////////////////
3234 } else if (com=="setMapBackgroundColor")
3236 if (selection.isEmpty() )
3238 parser.setError (Aborted,"Nothing selected");
3239 } else if (! selection.getBranch() )
3241 parser.setError (Aborted,"Type of selection is not a branch");
3242 } else if (parser.checkParCount(1))
3244 QColor c=parser.parColor (ok,0);
3245 if (ok) setMapBackgroundColor (c);
3247 /////////////////////////////////////////////////////////////////////
3248 } else if (com=="setMapDefLinkColor")
3250 if (selection.isEmpty() )
3252 parser.setError (Aborted,"Nothing selected");
3255 parser.setError (Aborted,"Type of selection is not a branch");
3256 } else if (parser.checkParCount(1))
3258 QColor c=parser.parColor (ok,0);
3259 if (ok) setMapDefLinkColor (c);
3261 /////////////////////////////////////////////////////////////////////
3262 } else if (com=="setMapLinkStyle")
3264 if (parser.checkParCount(1))
3266 s=parser.parString (ok,0);
3267 if (ok) setMapLinkStyle(s);
3269 /////////////////////////////////////////////////////////////////////
3270 } else if (com=="setHeading")
3272 if (selection.isEmpty() )
3274 parser.setError (Aborted,"Nothing selected");
3277 parser.setError (Aborted,"Type of selection is not a branch");
3278 } else if (parser.checkParCount(1))
3280 s=parser.parString (ok,0);
3284 /////////////////////////////////////////////////////////////////////
3285 } else if (com=="setHideExport")
3287 if (selection.isEmpty() )
3289 parser.setError (Aborted,"Nothing selected");
3290 } else if (selection.type()!=Selection::Branch && selection.type() != Selection::MapCenter &&selection.type()!=Selection::FloatImage)
3292 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3293 } else if (parser.checkParCount(1))
3295 b=parser.parBool(ok,0);
3296 if (ok) setHideExport (b);
3298 /////////////////////////////////////////////////////////////////////
3299 } else if (com=="setIncludeImagesHorizontally")
3301 if (selection.isEmpty() )
3303 parser.setError (Aborted,"Nothing selected");
3306 parser.setError (Aborted,"Type of selection is not a branch");
3307 } else if (parser.checkParCount(1))
3309 b=parser.parBool(ok,0);
3310 if (ok) setIncludeImagesHor(b);
3312 /////////////////////////////////////////////////////////////////////
3313 } else if (com=="setIncludeImagesVertically")
3315 if (selection.isEmpty() )
3317 parser.setError (Aborted,"Nothing selected");
3320 parser.setError (Aborted,"Type of selection is not a branch");
3321 } else if (parser.checkParCount(1))
3323 b=parser.parBool(ok,0);
3324 if (ok) setIncludeImagesVer(b);
3326 /////////////////////////////////////////////////////////////////////
3327 } else if (com=="setHideLinkUnselected")
3329 if (selection.isEmpty() )
3331 parser.setError (Aborted,"Nothing selected");
3332 } else if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3334 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3335 } else if (parser.checkParCount(1))
3337 b=parser.parBool(ok,0);
3338 if (ok) setHideLinkUnselected(b);
3340 /////////////////////////////////////////////////////////////////////
3341 } else if (com=="setSelectionColor")
3343 if (parser.checkParCount(1))
3345 QColor c=parser.parColor (ok,0);
3346 if (ok) setSelectionColorInt (c);
3348 /////////////////////////////////////////////////////////////////////
3349 } else if (com=="setURL")
3351 if (selection.isEmpty() )
3353 parser.setError (Aborted,"Nothing selected");
3356 parser.setError (Aborted,"Type of selection is not a branch");
3357 } else if (parser.checkParCount(1))
3359 s=parser.parString (ok,0);
3362 /////////////////////////////////////////////////////////////////////
3363 } else if (com=="setVymLink")
3365 if (selection.isEmpty() )
3367 parser.setError (Aborted,"Nothing selected");
3370 parser.setError (Aborted,"Type of selection is not a branch");
3371 } else if (parser.checkParCount(1))
3373 s=parser.parString (ok,0);
3374 if (ok) setVymLink(s);
3377 /////////////////////////////////////////////////////////////////////
3378 else if (com=="setFlag")
3380 if (selection.isEmpty() )
3382 parser.setError (Aborted,"Nothing selected");
3385 parser.setError (Aborted,"Type of selection is not a branch");
3386 } else if (parser.checkParCount(1))
3388 s=parser.parString(ok,0);
3391 selb->activateStandardFlag(s);
3392 selb->updateFlagsToolbar();
3395 /////////////////////////////////////////////////////////////////////
3396 } else if (com=="setFrameType")
3398 if (selection.isEmpty() )
3400 parser.setError (Aborted,"Nothing selected");
3403 parser.setError (Aborted,"Type of selection is not a branch");
3404 } else if (parser.checkParCount(1))
3406 s=parser.parString(ok,0);
3410 /////////////////////////////////////////////////////////////////////
3411 } else if (com=="sortChildren")
3413 if (selection.isEmpty() )
3415 parser.setError (Aborted,"Nothing selected");
3418 parser.setError (Aborted,"Type of selection is not a branch");
3419 } else if (parser.checkParCount(0))
3423 /////////////////////////////////////////////////////////////////////
3424 } else if (com=="toggleFlag")
3426 if (selection.isEmpty() )
3428 parser.setError (Aborted,"Nothing selected");
3431 parser.setError (Aborted,"Type of selection is not a branch");
3432 } else if (parser.checkParCount(1))
3434 s=parser.parString(ok,0);
3437 selb->toggleStandardFlag(s);
3438 selb->updateFlagsToolbar();
3441 /////////////////////////////////////////////////////////////////////
3442 } else if (com=="unscroll")
3444 if (selection.isEmpty() )
3446 parser.setError (Aborted,"Nothing selected");
3449 parser.setError (Aborted,"Type of selection is not a branch");
3450 } else if (parser.checkParCount(0))
3452 if (!unscrollBranch (selb))
3453 parser.setError (Aborted,"Could not unscroll branch");
3455 /////////////////////////////////////////////////////////////////////
3456 } else if (com=="unscrollChildren")
3458 if (selection.isEmpty() )
3460 parser.setError (Aborted,"Nothing selected");
3463 parser.setError (Aborted,"Type of selection is not a branch");
3464 } else if (parser.checkParCount(0))
3466 unscrollChildren ();
3468 /////////////////////////////////////////////////////////////////////
3469 } else if (com=="unsetFlag")
3471 if (selection.isEmpty() )
3473 parser.setError (Aborted,"Nothing selected");
3476 parser.setError (Aborted,"Type of selection is not a branch");
3477 } else if (parser.checkParCount(1))
3479 s=parser.parString(ok,0);
3482 selb->deactivateStandardFlag(s);
3483 selb->updateFlagsToolbar();
3487 parser.setError (Aborted,"Unknown command");
3490 if (parser.errorLevel()==NoError)
3492 // setChanged(); FIXME should not be called e.g. for export?!
3497 // TODO Error handling
3498 qWarning("VymModel::parseAtom: Error!");
3499 qWarning(parser.errorMessage());
3503 void VymModel::runScript (QString script)
3505 parser.setScript (script);
3507 while (parser.next() )
3508 parseAtom(parser.getAtom());
3511 void VymModel::setExportMode (bool b)
3513 // should be called before and after exports
3514 // depending on the settings
3515 if (b && settings.value("/export/useHideExport","true")=="true")
3516 setHideTmpMode (HideExport);
3518 setHideTmpMode (HideNone);
3521 void VymModel::exportImage(QString fname, bool askName, QString format)
3525 fname=getMapName()+".png";
3532 QFileDialog *fd=new QFileDialog (NULL);
3533 fd->setCaption (tr("Export map as image"));
3534 fd->setDirectory (lastImageDir);
3535 fd->setFileMode(QFileDialog::AnyFile);
3536 fd->setFilters (imageIO.getFilters() );
3539 fl=fd->selectedFiles();
3541 format=imageIO.getType(fd->selectedFilter());
3545 setExportMode (true);
3546 QPixmap pix (getPixmap());
3547 pix.save(fname, format);
3548 setExportMode (false);
3552 void VymModel::exportXML(QString dir, bool askForName)
3556 dir=browseDirectory(NULL,tr("Export XML to directory"));
3557 if (dir =="" && !reallyWriteDirectory(dir) )
3561 // Hide stuff during export, if settings want this
3562 setExportMode (true);
3564 // Create subdirectories
3567 // write to directory
3568 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3571 file.setName ( dir + "/"+mapName+".xml");
3572 if ( !file.open( QIODevice::WriteOnly ) )
3574 // This should neverever happen
3575 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3579 // Write it finally, and write in UTF8, no matter what
3580 QTextStream ts( &file );
3581 ts.setEncoding (QTextStream::UnicodeUTF8);
3585 // Now write image, too
3586 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3588 setExportMode (false);
3591 void VymModel::exportASCII(QString fname,bool askName)
3596 ex.setFile (mapName+".txt");
3602 //ex.addFilter ("TXT (*.txt)");
3603 ex.setDir(lastImageDir);
3604 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3609 setExportMode(true);
3611 setExportMode(false);
3615 void VymModel::exportXHTML (const QString &dir, bool askForName)
3617 ExportXHTMLDialog dia(NULL);
3618 dia.setFilePath (filePath );
3619 dia.setMapName (mapName );
3621 if (dir!="") dia.setDir (dir);
3627 if (dia.exec()!=QDialog::Accepted)
3631 QDir d (dia.getDir());
3632 // Check, if warnings should be used before overwriting
3633 // the output directory
3634 if (d.exists() && d.count()>0)
3637 warn.showCancelButton (true);
3638 warn.setText(QString(
3639 "The directory %1 is not empty.\n"
3640 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3641 warn.setCaption("Warning: Directory not empty");
3642 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3644 if (warn.exec()!=QDialog::Accepted) ok=false;
3651 exportXML (dia.getDir(),false );
3652 dia.doExport(mapName );
3653 //if (dia.hasChanged()) setChanged();
3657 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3662 if (ex.setConfigFile(cf))
3664 setExportMode (true);
3665 ex.exportPresentation();
3666 setExportMode (false);
3673 //////////////////////////////////////////////
3675 //////////////////////////////////////////////
3677 void VymModel::registerEditor(QWidget *)
3681 void VymModel::unregisterEditor(QWidget *)
3685 void VymModel::updateNoteFlag()
3688 BranchObj *bo=selection.getBranch();
3691 bo->updateNoteFlag();
3692 mainWindow->updateActions();
3696 void VymModel::updateRelPositions()
3698 for (int i=0; i<mapCenters.count(); i++)
3699 mapCenters.at(i)->updateRelPositions();
3702 void VymModel::reposition()
3704 for (int i=0;i<mapCenters.count(); i++)
3705 mapCenters.at(i)->reposition(); // for positioning heading
3708 QPolygonF VymModel::shape(BranchObj *bo)
3710 // Creating (arbitrary) shapes
3713 QRectF rb=bo->getBBox();
3714 if (bo->getDepth()==0)
3716 // Just take BBox of this mapCenter
3717 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3721 // Take union of BBox and TotalBBox
3723 QRectF ra=bo->getTotalBBox();
3724 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3727 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3730 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3732 p <<ra.bottomRight()
3734 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3737 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3742 void VymModel::moveAway(LinkableMapObj *lmo)
3746 // Move all branches and MapCenters away from lmo
3747 // to avoid collisions
3752 BranchObj *boA=(BranchObj*)lmo;
3754 for (int i=0; i<mapCenters.count(); i++)
3756 boB=mapCenters.at(i);
3759 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3762 <<" ("<<qPrintable(boA->getHeading() )<<")"
3763 <<" with ("<< qPrintable (boB->getHeading() )
3766 <<" minT="<<r.minTranslation<<endl<<endl;
3770 QPixmap VymModel::getPixmap()
3772 QRectF mapRect=getTotalBBox();
3773 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3776 pp.setRenderHints(mapEditor->renderHints());
3778 // Don't print the visualisation of selection
3779 selection.unselect();
3781 mapScene->render ( &pp,
3782 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3783 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3785 // Restore selection
3786 selection.reselect();
3792 void VymModel::setMapLinkStyle (const QString & s)
3795 if (linkstyle==LinkableMapObj::Line)
3797 else if (linkstyle==LinkableMapObj::Parabel)
3798 snow="StyleParabel";
3799 else if (linkstyle==LinkableMapObj::PolyLine)
3800 snow="StylePolyLine";
3801 else if (linkstyle==LinkableMapObj::PolyParabel)
3802 snow="StyleParabel";
3805 QString("setMapLinkStyle (\"%1\")").arg(s),
3806 QString("setMapLinkStyle (\"%1\")").arg(snow),
3807 QString("Set map link style (\"%1\")").arg(s)
3811 linkstyle=LinkableMapObj::Line;
3812 else if (s=="StyleParabel")
3813 linkstyle=LinkableMapObj::Parabel;
3814 else if (s=="StylePolyLine")
3815 linkstyle=LinkableMapObj::PolyLine;
3817 linkstyle=LinkableMapObj::PolyParabel;
3824 bo->setLinkStyle(bo->getDefLinkStyle());
3830 LinkableMapObj::Style VymModel::getMapLinkStyle ()
3835 void VymModel::setMapDefLinkColor(QColor col)
3837 if ( !col.isValid() ) return;
3839 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3840 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3841 QString("Set map link color to %1").arg(col.name())
3855 void VymModel::setMapLinkColorHintInt()
3857 // called from setMapLinkColorHint(lch) or at end of parse
3867 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3870 setMapLinkColorHintInt();
3873 void VymModel::toggleMapLinkColorHint()
3875 if (linkcolorhint==LinkableMapObj::HeadingColor)
3876 linkcolorhint=LinkableMapObj::DefaultColor;
3878 linkcolorhint=LinkableMapObj::HeadingColor;
3888 void VymModel::selectMapBackgroundImage ()
3890 Q3FileDialog *fd=new Q3FileDialog( NULL);
3891 fd->setMode (Q3FileDialog::ExistingFile);
3892 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3893 ImagePreview *p =new ImagePreview (fd);
3894 fd->setContentsPreviewEnabled( TRUE );
3895 fd->setContentsPreview( p, p );
3896 fd->setPreviewMode( Q3FileDialog::Contents );
3897 fd->setCaption(vymName+" - " +tr("Load background image"));
3898 fd->setDir (lastImageDir);
3901 if ( fd->exec() == QDialog::Accepted )
3903 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
3904 lastImageDir=QDir (fd->dirPath());
3905 setMapBackgroundImage (fd->selectedFile());
3909 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
3911 QColor oldcol=mapScene->backgroundBrush().color();
3915 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
3917 QString ("setMapBackgroundImage (%1)").arg(col.name()),
3918 QString("Set background color of map to %1").arg(col.name()));
3921 brush.setTextureImage (QPixmap (fn));
3922 mapScene->setBackgroundBrush(brush);
3925 void VymModel::selectMapBackgroundColor()
3927 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
3928 if ( !col.isValid() ) return;
3929 setMapBackgroundColor( col );
3933 void VymModel::setMapBackgroundColor(QColor col)
3935 QColor oldcol=mapScene->backgroundBrush().color();
3937 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
3938 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
3939 QString("Set background color of map to %1").arg(col.name()));
3940 mapScene->setBackgroundBrush(col);
3943 QColor VymModel::getMapBackgroundColor()
3945 return mapScene->backgroundBrush().color();
3949 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint()
3951 return linkcolorhint;
3954 QColor VymModel::getMapDefLinkColor()
3956 return defLinkColor;
3959 void VymModel::setMapDefXLinkColor(QColor col)
3964 QColor VymModel::getMapDefXLinkColor()
3966 return defXLinkColor;
3969 void VymModel::setMapDefXLinkWidth (int w)
3974 int VymModel::getMapDefXLinkWidth()
3976 return defXLinkWidth;
3979 void VymModel::move(const double &x, const double &y)
3981 LinkableMapObj *sel=selection.single();
3984 QPointF ap(sel->getAbsPos());
3988 QString ps=qpointfToString(ap);
3989 QString s=selection.getSelectString();
3992 s, "move "+qpointfToString(to),
3993 QString("Move %1 to %2").arg(getObjectName(sel)).arg(ps));
4001 void VymModel::moveRel (const double &x, const double &y)
4003 LinkableMapObj *sel=selection.single();
4006 QPointF rp(sel->getRelPos());
4010 QString ps=qpointfToString (sel->getRelPos());
4011 QString s=getSelectString(sel);
4014 s, "moveRel "+qpointfToString(to),
4015 QString("Move %1 to relative position %2").arg(getObjectName(sel)).arg(ps));
4016 ((OrnamentedObj*)sel)->move2RelPos (x,y);
4025 void VymModel::animate()
4027 animationTimer->stop();
4030 while (i<animObjList.size() )
4032 bo=(BranchObj*)animObjList.at(i);
4037 animObjList.removeAt(i);
4044 mapEditor->updateSelection();
4046 animationTimer->start();
4050 void VymModel::startAnimation(const QPointF &start, const QPointF &dest)
4052 BranchObj *bo=getSelectedBranch();
4053 if (bo && bo->getDepth()>0)
4056 ap.setStart (start);
4058 ap.setTicks (animationTicks);
4059 ap.setAnimated (true);
4060 bo->setAnimation (ap);
4061 animObjList.append( bo );
4062 animationTimer->setSingleShot (true);
4063 animationTimer->start(animationInterval);
4067 void VymModel::stopAnimation (MapObj *mo)
4069 int i=animObjList.indexOf(mo);
4071 animObjList.removeAt (i);
4074 void VymModel::sendSelection()
4076 if (netstate!=Server) return;
4077 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4080 void VymModel::newServer()
4084 tcpServer = new QTcpServer(this);
4085 if (!tcpServer->listen(QHostAddress::Any,port)) {
4086 QMessageBox::critical(NULL, "vym server",
4087 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4088 //FIXME needed? we are no widget any longer... close();
4091 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4093 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4096 void VymModel::connectToServer()
4099 server="salam.suse.de";
4101 clientSocket = new QTcpSocket (this);
4102 clientSocket->abort();
4103 clientSocket->connectToHost(server ,port);
4104 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4105 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4106 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4108 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4113 void VymModel::newClient()
4115 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4116 connect(newClient, SIGNAL(disconnected()),
4117 newClient, SLOT(deleteLater()));
4119 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4121 clientList.append (newClient);
4125 void VymModel::sendData(const QString &s)
4127 if (clientList.size()==0) return;
4129 // Create bytearray to send
4131 QDataStream out(&block, QIODevice::WriteOnly);
4132 out.setVersion(QDataStream::Qt_4_0);
4134 // Reserve some space for blocksize
4137 // Write sendCounter
4138 out << sendCounter++;
4143 // Go back and write blocksize so far
4144 out.device()->seek(0);
4145 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4149 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4151 for (int i=0; i<clientList.size(); ++i)
4153 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4154 clientList.at(i)->write (block);
4158 void VymModel::readData ()
4160 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4163 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4167 QDataStream in(clientSocket);
4168 in.setVersion(QDataStream::Qt_4_0);
4176 cout << " t="<<qPrintable (t)<<endl;
4182 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4184 switch (socketError) {
4185 case QAbstractSocket::RemoteHostClosedError:
4187 case QAbstractSocket::HostNotFoundError:
4188 QMessageBox::information(NULL, vymName +" Network client",
4189 "The host was not found. Please check the "
4190 "host name and port settings.");
4192 case QAbstractSocket::ConnectionRefusedError:
4193 QMessageBox::information(NULL, vymName + " Network client",
4194 "The connection was refused by the peer. "
4195 "Make sure the fortune server is running, "
4196 "and check that the host name and port "
4197 "settings are correct.");
4200 QMessageBox::information(NULL, vymName + " Network client",
4201 QString("The following error occurred: %1.")
4202 .arg(clientSocket->errorString()));
4209 void VymModel::selectMapSelectionColor()
4211 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4212 setSelectionColor (col);
4215 void VymModel::setSelectionColorInt (QColor col)
4217 if ( !col.isValid() ) return;
4219 QString("setSelectionColor (%1)").arg(selection.getColor().name()),
4220 QString("setSelectionColor (%1)").arg(col.name()),
4221 QString("Set color of selection box to %1").arg(col.name())
4224 selection.setColor (col);
4227 void VymModel::updateSelection()
4232 void VymModel::setSelectionColor(QColor col)
4234 if ( !col.isValid() ) return;
4236 QString("setSelectionColor (%1)").arg(selection.getColor().name()),
4237 QString("setSelectionColor (%1)").arg(col.name()),
4238 QString("Set color of selection box to %1").arg(col.name())
4240 setSelectionColorInt (col);
4243 QColor VymModel::getSelectionColor()
4245 return selection.getColor();
4248 void VymModel::setHideTmpMode (HideTmpMode mode)
4251 for (int i=0;i<mapCenters.count(); i++)
4252 mapCenters.at(i)->setHideTmp (mode);
4254 // FIXME needed? scene()->update();
4258 QRectF VymModel::getTotalBBox()
4261 for (int i=0;i<mapCenters.count(); i++)
4262 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4266 //////////////////////////////////////////////
4267 // Selection related
4268 //////////////////////////////////////////////
4270 void VymModel::setSelectionBlocked (bool b)
4275 selection.unblock();
4278 bool VymModel::isSelectionBlocked()
4280 return selection.isBlocked();
4283 bool VymModel::select (const QString &s)
4285 if (selection.select(s))
4288 ensureSelectionVisible();
4296 bool VymModel::select (LinkableMapObj *lmo)
4298 if (selection.select(lmo))
4301 ensureSelectionVisible();
4308 void VymModel::unselect()
4310 selection.unselect();
4313 void VymModel::reselect()
4315 selection.reselect();
4318 void VymModel::ensureSelectionVisible()
4320 LinkableMapObj *lmo=selection.single();
4321 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4325 void VymModel::selectInt (LinkableMapObj *lmo)
4327 if (selection.select(lmo))
4335 void VymModel::selectNextBranchInt()
4337 // Increase number of branch
4338 LinkableMapObj *sel=selection.single();
4341 QString s=selection.getSelectString();
4347 part=s.section(",",-1);
4349 num=part.right(part.length() - 3);
4351 s=s.left (s.length() -num.length());
4354 num=QString ("%1").arg(num.toUInt()+1);
4358 // Try to select this one
4359 if (select (s)) return;
4361 // We have no direct successor,
4362 // try to increase the parental number in order to
4363 // find a successor with same depth
4365 int d=selection.single()->getDepth();
4370 while (!found && d>0)
4372 s=s.section (",",0,d-1);
4373 // replace substring of current depth in s with "1"
4374 part=s.section(",",-1);
4376 num=part.right(part.length() - 3);
4380 // increase number of parent
4381 num=QString ("%1").arg(num.toUInt()+1);
4382 s=s.section (",",0,d-2) + ","+ typ+num;
4385 // Special case, look at orientation
4386 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4387 num=QString ("%1").arg(num.toUInt()+1);
4389 num=QString ("%1").arg(num.toUInt()-1);
4394 // pad to oldDepth, select the first branch for each depth
4395 for (i=d;i<oldDepth;i++)
4400 if ( selection.getBranch()->countBranches()>0)
4408 // try to select the freshly built string
4416 void VymModel::selectPrevBranchInt()
4418 // Decrease number of branch
4419 BranchObj *bo=selection.getBranch();
4422 QString s=selection.getSelectString();
4428 part=s.section(",",-1);
4430 num=part.right(part.length() - 3);
4432 s=s.left (s.length() -num.length());
4434 int n=num.toInt()-1;
4437 num=QString ("%1").arg(n);
4440 // Try to select this one
4441 if (n>=0 && select (s)) return;
4443 // We have no direct precessor,
4444 // try to decrease the parental number in order to
4445 // find a precessor with same depth
4447 int d=selection.single()->getDepth();
4452 while (!found && d>0)
4454 s=s.section (",",0,d-1);
4455 // replace substring of current depth in s with "1"
4456 part=s.section(",",-1);
4458 num=part.right(part.length() - 3);
4462 // decrease number of parent
4463 num=QString ("%1").arg(num.toInt()-1);
4464 s=s.section (",",0,d-2) + ","+ typ+num;
4467 // Special case, look at orientation
4468 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4469 num=QString ("%1").arg(num.toInt()-1);
4471 num=QString ("%1").arg(num.toInt()+1);
4476 // pad to oldDepth, select the last branch for each depth
4477 for (i=d;i<oldDepth;i++)
4481 if ( selection.getBranch()->countBranches()>0)
4482 s+=",bo:"+ QString ("%1").arg( selection.getBranch()->countBranches()-1 );
4489 // try to select the freshly built string
4497 void VymModel::selectUpperBranch()
4499 if (selection.isBlocked() ) return;
4501 BranchObj *bo=selection.getBranch();
4502 if (bo && selection.type()==Selection::Branch)
4504 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4505 selectPrevBranchInt();
4507 if (bo->getDepth()==1)
4508 selectNextBranchInt();
4510 selectPrevBranchInt();
4514 void VymModel::selectLowerBranch()
4516 if (selection.isBlocked() ) return;
4518 BranchObj *bo=selection.getBranch();
4519 if (bo && selection.type()==Selection::Branch)
4521 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4522 selectNextBranchInt();
4524 if (bo->getDepth()==1)
4525 selectPrevBranchInt();
4527 selectNextBranchInt();
4532 void VymModel::selectLeftBranch()
4534 if (selection.isBlocked() ) return;
4538 LinkableMapObj *sel=selection.single();
4541 if (selection.type()== Selection::MapCenter)
4543 par=selection.getBranch();
4544 bo=par->getLastSelectedBranch();
4547 // Workaround for reselecting on left and right side
4548 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4549 bo=par->getLastBranch();
4552 bo=par->getLastBranch();
4553 selection.select(bo);
4555 ensureSelectionVisible();
4561 par=(BranchObj*)(sel->getParObj());
4562 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4564 if (selection.type() == Selection::Branch ||
4565 selection.type() == Selection::FloatImage)
4567 selection.select(par);
4569 ensureSelectionVisible();
4574 if (selection.type() == Selection::Branch )
4576 bo=selection.getBranch()->getLastSelectedBranch();
4579 selection.select(bo);
4581 ensureSelectionVisible();
4590 void VymModel::selectRightBranch()
4592 if (selection.isBlocked() ) return;
4596 LinkableMapObj *sel=selection.single();
4599 if (selection.type()==Selection::MapCenter)
4601 par=selection.getBranch();
4602 bo=par->getLastSelectedBranch();
4605 // Workaround for reselecting on left and right side
4606 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4607 bo=par->getFirstBranch();
4610 selection.select(bo);
4612 ensureSelectionVisible();
4618 par=(BranchObj*)(selection.single()->getParObj());
4619 if (selection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
4621 if (selection.type() == Selection::Branch ||
4622 selection.type() == Selection::FloatImage)
4624 selection.select(par);
4626 ensureSelectionVisible();
4631 if (selection.type() == Selection::Branch)
4633 bo=selection.getBranch()->getLastSelectedBranch();
4636 selection.select(bo);
4638 ensureSelectionVisible();
4647 void VymModel::selectFirstBranch()
4649 BranchObj *bo1=selection.getBranch();
4654 par=(BranchObj*)(bo1->getParObj());
4656 bo2=par->getFirstBranch();
4658 selection.select(bo2);
4660 ensureSelectionVisible();
4666 void VymModel::selectLastBranch()
4668 BranchObj *bo1=selection.getBranch();
4673 par=(BranchObj*)(bo1->getParObj());
4675 bo2=par->getLastBranch();
4678 selection.select(bo2);
4680 ensureSelectionVisible();
4686 Selection::Type VymModel::selectionType()
4688 return selection.type();
4691 LinkableMapObj* VymModel::getSelection()
4693 return selection.single();
4695 BranchObj* VymModel::getSelectedBranch()
4697 return selection.getBranch();
4700 FloatImageObj* VymModel::getSelectedFloatImage()
4702 return selection.getFloatImage();
4705 QString VymModel::getSelectString ()
4707 return selection.getSelectString();
4710 QString VymModel::getSelectString (LinkableMapObj *lmo)
4714 if (typeid(*lmo)==typeid(BranchObj) ||
4715 typeid(*lmo)==typeid(MapCenterObj) )
4717 LinkableMapObj *par=lmo->getParObj();
4720 if (lmo->getDepth() ==1)
4721 // Mainbranch, return
4722 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4724 // Branch, call myself recursively
4725 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4729 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
4730 if (i>=0) s=QString("mc:%1").arg(i);