deleting works - partially.
1 #include <QApplication>
6 #include "editxlinkdialog.h"
8 #include "exportxhtmldialog.h"
10 #include "geometry.h" // for addBBox
11 #include "mainwindow.h"
12 #include "mapcenterobj.h"
15 #include "selection.h"
18 #include "warningdialog.h"
19 #include "xml-freemind.h"
25 extern Main *mainWindow;
26 extern Settings settings;
27 extern QString tmpVymDir;
29 extern TextEditor *textEditor;
31 extern QString clipboardDir;
32 extern QString clipboardFile;
33 extern bool clipboardEmpty;
35 extern ImageIO imageIO;
37 extern QString vymName;
38 extern QString vymVersion;
39 extern QDir vymBaseDir;
41 extern QDir lastImageDir;
42 extern QDir lastFileDir;
44 extern FlagRowObj *standardFlagsDefault;
46 extern Settings settings;
50 int VymModel::mapNum=0; // make instance
54 // cout << "Const VymModel\n";
61 // cout << "Destr VymModel\n";
62 autosaveTimer->stop();
63 fileChangedTimer->stop();
67 void VymModel::clear()
69 cout << "VymModel::clear rows="<<rowCount(index(rootItem))<<endl;
73 while (!mapCenters.isEmpty()) // FIXME VM needs to be in treemodel only...
74 delete mapCenters.takeFirst();
76 QModelIndex ri=index(rootItem);
77 removeRows (0, rowCount(ri),ri);
80 void VymModel::init ()
82 // We should have at least one map center to start with
83 // addMapCenter(); FIXME VM create this in MapEditor as long as model is part of that
88 // Also no scene yet (should not be needed anyway) FIXME VM
101 stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
102 undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
103 mainWindow->updateHistory (undoSet);
106 makeTmpDirectories();
111 fileName=tr("unnamed");
113 blockReposition=false;
114 blockSaveState=false;
116 autosaveTimer=new QTimer (this);
117 connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave()));
119 fileChangedTimer=new QTimer (this);
120 fileChangedTimer->start(3000);
121 connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged()));
126 selection.setModel (this);
127 selection.unselect();
134 animationUse=settings.readBoolEntry("/animation/use",false);
135 animationTicks=settings.readNumEntry("/animation/ticks",10);
136 animationInterval=settings.readNumEntry("/animation/interval",50);
138 animationTimer=new QTimer (this);
139 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
142 defLinkColor=QColor (0,0,255);
143 defXLinkColor=QColor (180,180,180);
144 linkcolorhint=LinkableMapObj::DefaultColor;
145 linkstyle=LinkableMapObj::PolyParabel;
147 defXLinkColor=QColor (230,230,230);
157 // addMapCenter(); FIXME VM create this in MapEditor until BO and MCO are independent of scene
161 void VymModel::makeTmpDirectories()
163 // Create unique temporary directories
164 tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
165 histPath = tmpMapDir+"/history";
171 MapEditor* VymModel::getMapEditor() // FIXME VM better return favourite editor here
176 bool VymModel::isRepositionBlocked()
178 return blockReposition;
181 void VymModel::updateActions() // FIXME maybe don't update if blockReposition is set
183 // Tell mainwindow to update states of actions
184 mainWindow->updateActions();
189 QString VymModel::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
191 // tmpdir temporary directory to which data will be written
192 // prefix mapname, which will be appended to images etc.
193 // writeflags Only write flags for "real" save of map, not undo
194 // offset offset of bbox of whole map in scene.
195 // Needed for XML export
204 case LinkableMapObj::Line:
207 case LinkableMapObj::Parabel:
210 case LinkableMapObj::PolyLine:
214 ls="StylePolyParabel";
218 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
220 if (linkcolorhint==LinkableMapObj::HeadingColor)
221 colhint=xml.attribut("linkColorHint","HeadingColor");
223 QString mapAttr=xml.attribut("version",vymVersion);
225 mapAttr+= xml.attribut("author",author) +
226 xml.attribut("comment",comment) +
227 xml.attribut("date",getDate()) +
228 xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
229 xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) +
230 xml.attribut("linkStyle", ls ) +
231 xml.attribut("linkColor", defLinkColor.name() ) +
232 xml.attribut("defXLinkColor", defXLinkColor.name() ) +
233 xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
235 s+=xml.beginElement("vymmap",mapAttr);
238 // Find the used flags while traversing the tree
239 standardFlagsDefault->resetUsedCounter();
241 // Reset the counters before saving
242 // TODO constr. of FIO creates lots of objects, better do this in some other way...
243 FloatImageObj (mapScene).resetSaveCounter();
245 // Build xml recursivly
246 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
247 // Save complete map, if saveSel not set
248 s+=saveToDir(tmpdir,prefix,writeflags,offset);
251 if ( typeid(*saveSel) == typeid(BranchObj) )
253 s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset);
254 else if ( typeid(*saveSel) == typeid(FloatImageObj) )
256 s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
259 // Save local settings
260 s+=settings.getDataXML (destPath);
263 if (!selection.isEmpty() && !saveSel )
264 s+=xml.valueElement("select",selection.getSelectString());
267 s+=xml.endElement("vymmap");
270 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
274 void VymModel::setFilePath(QString fpath, QString destname)
276 if (fpath.isEmpty() || fpath=="")
283 filePath=fpath; // becomes absolute path
284 fileName=fpath; // gets stripped of path
285 destPath=destname; // needed for vymlinks and during load to reset fileChangedTime
287 // If fpath is not an absolute path, complete it
288 filePath=QDir(fpath).absPath();
289 fileDir=filePath.left (1+filePath.findRev ("/"));
291 // Set short name, too. Search from behind:
292 int i=fileName.findRev("/");
293 if (i>=0) fileName=fileName.remove (0,i+1);
295 // Forget the .vym (or .xml) for name of map
296 mapName=fileName.left(fileName.findRev(".",-1,true) );
300 void VymModel::setFilePath(QString fpath)
302 setFilePath (fpath,fpath);
305 QString VymModel::getFilePath()
310 QString VymModel::getFileName()
315 QString VymModel::getMapName()
320 QString VymModel::getDestPath()
325 ErrorCode VymModel::load (QString fname, const LoadMode &lmode, const FileType &ftype)
327 ErrorCode err=success;
329 parseBaseHandler *handler;
333 case VymMap: handler=new parseVYMHandler; break;
334 case FreemindMap : handler=new parseFreemindHandler; break;
336 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
337 "Unknown FileType in VymModel::load()");
341 bool zipped_org=zipped;
346 // FIXME VM not needed??? model->setMapEditor(this);
347 // (map state is set later at end of load...)
350 BranchObj *bo=selection.getBranch();
351 if (!bo) return aborted;
352 if (lmode==ImportAdd)
353 saveStateChangingPart(
356 QString("addMapInsert (%1)").arg(fname),
357 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
359 saveStateChangingPart(
362 QString("addMapReplace(%1)").arg(fname),
363 QString("Add map %1 to %2").arg(fname).arg(getObjectName(bo)));
367 // Create temporary directory for packing
369 QString tmpZipDir=makeTmpDir (ok,"vym-pack");
372 QMessageBox::critical( 0, tr( "Critical Load Error" ),
373 tr("Couldn't create temporary directory before load\n"));
378 err=unzipDir (tmpZipDir,fname);
388 // Look for mapname.xml
389 xmlfile= fname.left(fname.findRev(".",-1,true));
390 xmlfile=xmlfile.section( '/', -1 );
391 QFile mfile( tmpZipDir + "/" + xmlfile + ".xml");
392 if (!mfile.exists() )
394 // mapname.xml does not exist, well,
395 // maybe someone renamed the mapname.vym file...
396 // Try to find any .xml in the toplevel
397 // directory of the .vym file
398 QStringList flist=QDir (tmpZipDir).entryList("*.xml");
399 if (flist.count()==1)
401 // Only one entry, take this one
402 xmlfile=tmpZipDir + "/"+flist.first();
405 for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
406 *it=tmpZipDir + "/" + *it;
407 // TODO Multiple entries, load all (but only the first one into this ME)
408 //mainWindow->fileLoadFromTmp (flist);
409 //returnCode=1; // Silently forget this attempt to load
410 qWarning ("MainWindow::load (fn) multimap found...");
413 if (flist.isEmpty() )
415 QMessageBox::critical( 0, tr( "Critical Load Error" ),
416 tr("Couldn't find a map (*.xml) in .vym archive.\n"));
419 } //file doesn't exist
421 xmlfile=mfile.name();
424 QFile file( xmlfile);
426 // I am paranoid: file should exist anyway
427 // according to check in mainwindow.
430 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
431 tr(QString("Couldn't open map %1").arg(file.name())));
435 bool blockSaveStateOrg=blockSaveState;
436 blockReposition=true;
438 QXmlInputSource source( file);
439 QXmlSimpleReader reader;
440 reader.setContentHandler( handler );
441 reader.setErrorHandler( handler );
442 handler->setModel ( this);
445 // We need to set the tmpDir in order to load files with rel. path
450 tmpdir=fname.left(fname.findRev("/",-1));
451 handler->setTmpDir (tmpdir);
452 handler->setInputFile (file.name());
453 handler->setLoadMode (lmode);
454 bool ok = reader.parse( source );
455 blockReposition=false;
456 blockSaveState=blockSaveStateOrg;
460 reposition(); // FIXME VM reposition the view instead...
467 autosaveTimer->stop();
470 // Reset timestamp to check for later updates of file
471 fileChangedTime=QFileInfo (destPath).lastModified();
474 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
475 tr( handler->errorProtocol() ) );
477 // Still return "success": the map maybe at least
478 // partially read by the parser
483 removeDir (QDir(tmpZipDir));
485 // Restore original zip state
492 ErrorCode VymModel::save (const SaveMode &savemode)
496 QString safeFilePath;
498 ErrorCode err=success;
502 mapFileName=mapName+".xml";
504 // use name given by user, even if he chooses .doc
505 mapFileName=fileName;
507 // Look, if we should zip the data:
510 QMessageBox mb( vymName,
511 tr("The map %1\ndid not use the compressed "
512 "vym file format.\nWriting it uncompressed will also write images \n"
513 "and flags and thus may overwrite files in the "
514 "given directory\n\nDo you want to write the map").arg(filePath),
515 QMessageBox::Warning,
516 QMessageBox::Yes | QMessageBox::Default,
518 QMessageBox::Cancel | QMessageBox::Escape);
519 mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") );
520 mb.setButtonText( QMessageBox::No, tr("uncompressed") );
521 mb.setButtonText( QMessageBox::Cancel, tr("Cancel"));
524 case QMessageBox::Yes:
525 // save compressed (default file format)
528 case QMessageBox::No:
532 case QMessageBox::Cancel:
539 // First backup existing file, we
540 // don't want to add to old zip archives
544 if ( settings.value ("/mapeditor/writeBackupFile").toBool())
546 QString backupFileName(destPath + "~");
547 QFile backupFile(backupFileName);
548 if (backupFile.exists() && !backupFile.remove())
550 QMessageBox::warning(0, tr("Save Error"),
551 tr("%1\ncould not be removed before saving").arg(backupFileName));
553 else if (!f.rename(backupFileName))
555 QMessageBox::warning(0, tr("Save Error"),
556 tr("%1\ncould not be renamed before saving").arg(destPath));
563 // Create temporary directory for packing
565 tmpZipDir=makeTmpDir (ok,"vym-zip");
568 QMessageBox::critical( 0, tr( "Critical Load Error" ),
569 tr("Couldn't create temporary directory before save\n"));
573 safeFilePath=filePath;
574 setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath);
577 // Create mapName and fileDir
578 makeSubDirs (fileDir);
581 if (savemode==CompleteMap || selection.isEmpty())
584 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
587 autosaveTimer->stop();
592 if (selection.type()==Selection::FloatImage)
595 saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),selection.getBranch());
596 // TODO take care of multiselections
599 if (!saveStringToDisk(fileDir+mapFileName,saveFile))
602 qWarning ("ME::saveStringToDisk failed!");
608 if (err==success) err=zipDir (tmpZipDir,destPath);
611 removeDir (QDir(tmpZipDir));
613 // Restore original filepath outside of tmp zip dir
614 setFilePath (safeFilePath);
618 fileChangedTime=QFileInfo (destPath).lastModified();
622 void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)
624 QString pathDir=path.left(path.findRev("/"));
630 // We need to parse saved XML data
631 parseVYMHandler handler;
632 QXmlInputSource source( file);
633 QXmlSimpleReader reader;
634 reader.setContentHandler( &handler );
635 reader.setErrorHandler( &handler );
636 handler.setModel ( this);
637 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
638 if (undoSel.isEmpty())
642 handler.setLoadMode (NewMap);
646 handler.setLoadMode (ImportReplace);
648 blockReposition=true;
649 bool ok = reader.parse( source );
650 blockReposition=false;
653 // This should never ever happen
654 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
655 handler.errorProtocol());
658 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
661 void VymModel::addMapInsertInt (const QString &path, int pos)
663 BranchObj *sel=selection.getBranch();
666 QString pathDir=path.left(path.findRev("/"));
672 // We need to parse saved XML data
673 parseVYMHandler handler;
674 QXmlInputSource source( file);
675 QXmlSimpleReader reader;
676 reader.setContentHandler( &handler );
677 reader.setErrorHandler( &handler );
678 handler.setModel (this);
679 handler.setTmpDir ( pathDir ); // needed to load files with rel. path
680 handler.setLoadMode (ImportAdd);
681 blockReposition=true;
682 bool ok = reader.parse( source );
683 blockReposition=false;
686 // This should never ever happen
687 QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
688 handler.errorProtocol());
690 if (sel->getDepth()>0)
691 sel->getLastBranch()->linkTo (sel,pos);
693 QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
697 FloatImageObj* VymModel::loadFloatImageInt (QString fn)
699 BranchObj *bo=selection.getBranch();
704 fio=bo->getLastFloatImage();
707 // FIXME VM needed? scene()->update();
713 void VymModel::loadFloatImage ()
715 BranchObj *bo=selection.getBranch();
719 Q3FileDialog *fd=new Q3FileDialog( NULL);
720 fd->setMode (Q3FileDialog::ExistingFiles);
721 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
722 ImagePreview *p =new ImagePreview (fd);
723 fd->setContentsPreviewEnabled( TRUE );
724 fd->setContentsPreview( p, p );
725 fd->setPreviewMode( Q3FileDialog::Contents );
726 fd->setCaption(vymName+" - " +tr("Load image"));
727 fd->setDir (lastImageDir);
730 if ( fd->exec() == QDialog::Accepted )
732 // TODO loadFIO in QT4 use: lastImageDir=fd->directory();
733 lastImageDir=QDir (fd->dirPath());
736 for (int j=0; j<fd->selectedFiles().count(); j++)
738 s=fd->selectedFiles().at(j);
739 fio=loadFloatImageInt (s);
742 (LinkableMapObj*)fio,
745 QString ("loadImage (%1)").arg(s ),
746 QString("Add image %1 to %2").arg(s).arg(getObjectName(bo))
749 // TODO loadFIO error handling
750 qWarning ("Failed to load "+s);
758 void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn)
763 void VymModel::saveFloatImage ()
765 FloatImageObj *fio=selection.getFloatImage();
768 QFileDialog *fd=new QFileDialog( NULL);
769 fd->setFilters (imageIO.getFilters());
770 fd->setCaption(vymName+" - " +tr("Save image"));
771 fd->setFileMode( QFileDialog::AnyFile );
772 fd->setDirectory (lastImageDir);
773 // fd->setSelection (fio->getOriginalFilename());
777 if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
779 fn=fd->selectedFiles().at(0);
780 if (QFile (fn).exists() )
782 QMessageBox mb( vymName,
783 tr("The file %1 exists already.\n"
784 "Do you want to overwrite it?").arg(fn),
785 QMessageBox::Warning,
786 QMessageBox::Yes | QMessageBox::Default,
787 QMessageBox::Cancel | QMessageBox::Escape,
788 QMessageBox::NoButton );
790 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
791 mb.setButtonText( QMessageBox::No, tr("Cancel"));
794 case QMessageBox::Yes:
797 case QMessageBox::Cancel:
804 saveFloatImageInt (fio,fd->selectedFilter(),fn );
811 void VymModel::importDirInt(BranchObj *dst, QDir d)
813 BranchObj *bo=selection.getBranch();
816 // Traverse directories
817 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
818 QFileInfoList list = d.entryInfoList();
821 for (int i = 0; i < list.size(); ++i)
824 if (fi.fileName() != "." && fi.fileName() != ".." )
827 bo=dst->getLastBranch();
828 bo->setHeading (fi.fileName() );
829 bo->setColor (QColor("blue"));
831 if ( !d.cd(fi.fileName()) )
832 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
835 // Recursively add subdirs
842 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
843 list = d.entryInfoList();
845 for (int i = 0; i < list.size(); ++i)
849 bo=dst->getLastBranch();
850 bo->setHeading (fi.fileName() );
851 bo->setColor (QColor("black"));
852 if (fi.fileName().right(4) == ".vym" )
853 bo->setVymLink (fi.filePath());
858 void VymModel::importDirInt (const QString &s)
860 BranchObj *bo=selection.getBranch();
863 saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
870 void VymModel::importDir()
872 BranchObj *bo=selection.getBranch();
876 filters <<"VYM map (*.vym)";
877 QFileDialog *fd=new QFileDialog( NULL,vymName+ " - " +tr("Choose directory structure to import"));
878 fd->setMode (QFileDialog::DirectoryOnly);
879 fd->setFilters (filters);
880 fd->setCaption(vymName+" - " +tr("Choose directory structure to import"));
884 if ( fd->exec() == QDialog::Accepted )
886 importDirInt (fd->selectedFile() );
888 //FIXME VM needed? scene()->update();
894 void VymModel::autosave()
896 QDateTime now=QDateTime().currentDateTime();
898 // Disable autosave, while we have gone back in history
899 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
900 if (redosAvail>0) return;
902 // Also disable autosave for new map without filename
903 if (filePath.isEmpty()) return;
906 if (mapUnsaved &&mapChanged && settings.value ("/autosave/use",true).toBool() )
908 if (QFileInfo(filePath).lastModified()<=fileChangedTime)
909 mainWindow->fileSave (this);
912 cout <<" ME::autosave rejected, file on disk is newer than last save.\n";
917 void VymModel::fileChanged()
919 // Check if file on disk has changed meanwhile
920 if (!filePath.isEmpty())
922 QDateTime tmod=QFileInfo (filePath).lastModified();
923 if (tmod>fileChangedTime)
925 // FIXME VM switch to current mapeditor and finish lineedits...
926 QMessageBox mb( vymName,
927 tr("The file of the map on disk has changed:\n\n"
928 " %1\n\nDo you want to reload that map with the new file?").arg(filePath),
929 QMessageBox::Question,
931 QMessageBox::Cancel | QMessageBox::Default,
932 QMessageBox::NoButton );
934 mb.setButtonText( QMessageBox::Yes, tr("Reload"));
935 mb.setButtonText( QMessageBox::No, tr("Ignore"));
938 case QMessageBox::Yes:
940 load (filePath,NewMap,fileType);
941 case QMessageBox::Cancel:
942 fileChangedTime=tmod; // allow autosave to overwrite newer file!
948 bool VymModel::isDefault()
953 void VymModel::makeDefault()
959 bool VymModel::hasChanged()
964 void VymModel::setChanged()
967 autosaveTimer->start(settings.value("/autosave/ms/",300000).toInt());
975 QString VymModel::getObjectName (const LinkableMapObj *lmo)
978 if (!lmo) return QString("Error: NULL has no name!");
980 if ((typeid(*lmo) == typeid(BranchObj) ||
981 typeid(*lmo) == typeid(MapCenterObj)))
984 s=(((BranchObj*)lmo)->getHeading());
985 if (s=="") s="unnamed";
986 return QString("branch (%1)").arg(s);
988 if ((typeid(*lmo) == typeid(FloatImageObj) ))
989 return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
990 return QString("Unknown type has no name!");
993 void VymModel::redo()
995 // Can we undo at all?
996 if (redosAvail<1) return;
998 bool blockSaveStateOrg=blockSaveState;
1003 if (undosAvail<stepsTotal) undosAvail++;
1005 if (curStep>stepsTotal) curStep=1;
1006 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1007 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1008 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1009 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1010 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1011 QString version=undoSet.readEntry ("/history/version");
1013 /* TODO Maybe check for version, if we save the history
1014 if (!checkVersion(version))
1015 QMessageBox::warning(0,tr("Warning"),
1016 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1019 // Find out current undo directory
1020 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1024 cout << "VymModel::redo() begin\n";
1025 cout << " undosAvail="<<undosAvail<<endl;
1026 cout << " redosAvail="<<redosAvail<<endl;
1027 cout << " curStep="<<curStep<<endl;
1028 cout << " ---------------------------"<<endl;
1029 cout << " comment="<<comment.toStdString()<<endl;
1030 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1031 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1032 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1033 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1034 cout << " ---------------------------"<<endl<<endl;
1037 // select object before redo
1038 if (!redoSelection.isEmpty())
1039 select (redoSelection);
1042 parseAtom (redoCommand);
1045 blockSaveState=blockSaveStateOrg;
1047 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1048 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1049 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1050 undoSet.writeSettings(histPath);
1052 mainWindow->updateHistory (undoSet);
1055 /* TODO remove testing
1056 cout << "ME::redo() end\n";
1057 cout << " undosAvail="<<undosAvail<<endl;
1058 cout << " redosAvail="<<redosAvail<<endl;
1059 cout << " curStep="<<curStep<<endl;
1060 cout << " ---------------------------"<<endl<<endl;
1066 bool VymModel::isRedoAvailable()
1068 if (undoSet.readNumEntry("/history/redosAvail",0)>0)
1074 void VymModel::undo()
1076 // Can we undo at all?
1077 if (undosAvail<1) return;
1079 mainWindow->statusMessage (tr("Autosave disabled during undo."));
1081 bool blockSaveStateOrg=blockSaveState;
1082 blockSaveState=true;
1084 QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep));
1085 QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep));
1086 QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep));
1087 QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep));
1088 QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep));
1089 QString version=undoSet.readEntry ("/history/version");
1091 /* TODO Maybe check for version, if we save the history
1092 if (!checkVersion(version))
1093 QMessageBox::warning(0,tr("Warning"),
1094 tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
1097 // Find out current undo directory
1098 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1100 // select object before undo
1101 if (!undoSelection.isEmpty())
1102 select (undoSelection);
1106 cout << "VymModel::undo() begin\n";
1107 cout << " undosAvail="<<undosAvail<<endl;
1108 cout << " redosAvail="<<redosAvail<<endl;
1109 cout << " curStep="<<curStep<<endl;
1110 cout << " ---------------------------"<<endl;
1111 cout << " comment="<<comment.toStdString()<<endl;
1112 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1113 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1114 cout << " redoCom="<<redoCommand.toStdString()<<endl;
1115 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1116 cout << " ---------------------------"<<endl<<endl;
1118 parseAtom (undoCommand);
1123 if (curStep<1) curStep=stepsTotal;
1127 blockSaveState=blockSaveStateOrg;
1128 /* TODO remove testing
1129 cout << "VymModel::undo() end\n";
1130 cout << " undosAvail="<<undosAvail<<endl;
1131 cout << " redosAvail="<<redosAvail<<endl;
1132 cout << " curStep="<<curStep<<endl;
1133 cout << " ---------------------------"<<endl<<endl;
1136 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1137 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1138 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1139 undoSet.writeSettings(histPath);
1141 mainWindow->updateHistory (undoSet);
1144 ensureSelectionVisible();
1147 bool VymModel::isUndoAvailable()
1149 if (undoSet.readNumEntry("/history/undosAvail",0)>0)
1155 void VymModel::gotoHistoryStep (int i)
1157 // Restore variables
1158 int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
1159 int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
1161 if (i<0) i=undosAvail+redosAvail;
1163 // Clicking above current step makes us undo things
1166 for (int j=0; j<undosAvail-i; j++) undo();
1169 // Clicking below current step makes us redo things
1171 for (int j=undosAvail; j<i; j++)
1173 if (debug) cout << "VymModel::gotoHistoryStep redo "<<j<<"/"<<undosAvail<<" i="<<i<<endl;
1177 // And ignore clicking the current row ;-)
1181 QString VymModel::getHistoryPath()
1183 QString histName(QString("history-%1").arg(curStep));
1184 return (tmpMapDir+"/"+histName);
1187 void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
1189 sendData(redoCom); //FIXME testing
1194 if (blockSaveState) return;
1196 if (debug) cout << "ME::saveState() for "<<qPrintable (mapName)<<endl;
1198 // Find out current undo directory
1199 if (undosAvail<stepsTotal) undosAvail++;
1201 if (curStep>stepsTotal) curStep=1;
1203 QString backupXML="";
1204 QString histDir=getHistoryPath();
1205 QString bakMapPath=histDir+"/map.xml";
1207 // Create histDir if not available
1210 makeSubDirs (histDir);
1212 // Save depending on how much needs to be saved
1214 backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel);
1216 QString undoCommand="";
1217 if (savemode==UndoCommand)
1219 undoCommand=undoCom;
1221 else if (savemode==PartOfMap )
1223 undoCommand=undoCom;
1224 undoCommand.replace ("PATH",bakMapPath);
1227 if (!backupXML.isEmpty())
1228 // Write XML Data to disk
1229 saveStringToDisk (bakMapPath,backupXML);
1231 // We would have to save all actions in a tree, to keep track of
1232 // possible redos after a action. Possible, but we are too lazy: forget about redos.
1235 // Write the current state to disk
1236 undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail));
1237 undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail));
1238 undoSet.setEntry ("/history/curStep",QString::number(curStep));
1239 undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand);
1240 undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection);
1241 undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom);
1242 undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection);
1243 undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment);
1244 undoSet.setEntry (QString("/history/version"),vymVersion);
1245 undoSet.writeSettings(histPath);
1249 // TODO remove after testing
1250 //cout << " into="<< histPath.toStdString()<<endl;
1251 cout << " stepsTotal="<<stepsTotal<<
1252 ", undosAvail="<<undosAvail<<
1253 ", redosAvail="<<redosAvail<<
1254 ", curStep="<<curStep<<endl;
1255 cout << " ---------------------------"<<endl;
1256 cout << " comment="<<comment.toStdString()<<endl;
1257 cout << " undoCom="<<undoCommand.toStdString()<<endl;
1258 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1259 cout << " redoCom="<<redoCom.toStdString()<<endl;
1260 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1261 if (saveSel) cout << " saveSel="<<qPrintable (getSelectString(saveSel))<<endl;
1262 cout << " ---------------------------"<<endl;
1265 mainWindow->updateHistory (undoSet);
1271 void VymModel::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment)
1273 // save the selected part of the map, Undo will replace part of map
1274 QString undoSelection="";
1276 undoSelection=getSelectString(undoSel);
1278 qWarning ("VymModel::saveStateChangingPart no undoSel given!");
1279 QString redoSelection="";
1281 redoSelection=getSelectString(undoSel);
1283 qWarning ("VymModel::saveStateChangingPart no redoSel given!");
1286 saveState (PartOfMap,
1287 undoSelection, "addMapReplace (\"PATH\")",
1293 void VymModel::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment)
1297 qWarning ("VymModel::saveStateRemovingPart no redoSel given!");
1300 QString undoSelection=getSelectString (redoSel->getParObj());
1301 QString redoSelection=getSelectString(redoSel);
1302 if (typeid(*redoSel) == typeid(BranchObj) )
1304 // save the selected branch of the map, Undo will insert part of map
1305 saveState (PartOfMap,
1306 undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
1307 redoSelection, "delete ()",
1314 void VymModel::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment)
1316 // "Normal" savestate: save commands, selections and comment
1317 // so just save commands for undo and redo
1318 // and use current selection
1320 QString redoSelection="";
1321 if (redoSel) redoSelection=getSelectString(redoSel);
1322 QString undoSelection="";
1323 if (undoSel) undoSelection=getSelectString(undoSel);
1325 saveState (UndoCommand,
1332 void VymModel::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment)
1334 // "Normal" savestate: save commands, selections and comment
1335 // so just save commands for undo and redo
1336 // and use current selection
1337 saveState (UndoCommand,
1344 void VymModel::saveState(const QString &uc, const QString &rc, const QString &comment)
1346 // "Normal" savestate applied to model (no selection needed):
1347 // save commands and comment
1348 saveState (UndoCommand,
1356 QGraphicsScene* VymModel::getScene ()
1361 BranchObj* VymModel::first()
1363 if (mapCenters.count()>0)
1364 return mapCenters.first();
1369 BranchObj* VymModel::next(BranchObj *bo_start)
1372 BranchObj *bo=bo_start;
1375 // Try to find next branch in current MapCenter
1377 if (rbo) return rbo;
1379 // Try to find MapCenter of bo
1380 while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
1382 // Try to find next MapCenter
1383 int i=mapCenters.indexOf ((MapCenterObj*)bo);
1384 if (i+2 > mapCenters.count() || i<0) return NULL;
1385 if (mapCenters.at(i+1)!=bo_start)
1386 return mapCenters.at(i+1);
1391 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
1393 LinkableMapObj *lmo;
1395 for (int i=0;i<mapCenters.count(); i++)
1397 lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
1398 if (lmo) return lmo;
1403 LinkableMapObj* VymModel::findObjBySelect(const QString &s)
1405 LinkableMapObj *lmo;
1411 part=s.section(",",0,0);
1413 num=part.right(part.length() - 3);
1414 if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
1415 return mapCenters.at(num.toInt() );
1418 for (int i=0; i<mapCenters.count(); i++)
1420 lmo=mapCenters.at(i)->findObjBySelect(s);
1421 if (lmo) return lmo;
1426 LinkableMapObj* VymModel::findID (const QString &s)
1428 LinkableMapObj *lmo;
1429 for (int i=0; i<mapCenters.count(); i++)
1431 lmo=mapCenters.at(i)->findID (s);
1432 if (lmo) return lmo;
1437 QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
1441 for (int i=0; i<mapCenters.count(); i++)
1442 s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
1446 //////////////////////////////////////////////
1448 //////////////////////////////////////////////
1449 void VymModel::setVersion (const QString &s)
1454 void VymModel::setAuthor (const QString &s)
1457 QString ("setMapAuthor (\"%1\")").arg(author),
1458 QString ("setMapAuthor (\"%1\")").arg(s),
1459 QString ("Set author of map to \"%1\"").arg(s)
1465 QString VymModel::getAuthor()
1470 void VymModel::setComment (const QString &s)
1473 QString ("setMapComment (\"%1\")").arg(comment),
1474 QString ("setMapComment (\"%1\")").arg(s),
1475 QString ("Set comment of map")
1481 QString VymModel::getComment ()
1486 QString VymModel::getDate ()
1488 return QDate::currentDate().toString ("yyyy-MM-dd");
1491 void VymModel::setHeading(const QString &s)
1493 BranchObj *sel=selection.getBranch();
1498 "setHeading (\""+sel->getHeading()+"\")",
1500 "setHeading (\""+s+"\")",
1501 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1502 sel->setHeading(s );
1503 TreeItem *ti=selection.getBranchItem();
1507 //FIXME VM ix is wrong ModelIndex below, ix2 is (hopefully) correct:
1508 QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) );
1509 //FIXME VM testing only cout <<"VM::setHeading s="<<s.toStdString()<<" ti="<<ti<<" r,c=("<<ti->row()<<","<<ti->column()<<")"<<endl;
1510 QModelIndex ix2=index (ti);
1511 emit (dataChanged ( ix2,ix2));
1515 cout << "Warning: VM::setHeading ti==NULL\n";
1518 //cout <<" (r,c)=("<<ix2.row()<<","<<ix2.column()<<")"<<endl;
1522 ensureSelectionVisible();
1526 void VymModel::setHeadingInt(const QString &s)
1528 BranchObj *bo=selection.getBranch();
1534 ensureSelectionVisible();
1538 BranchObj* VymModel::findText (QString s, bool cs)
1540 QTextDocument::FindFlags flags=0;
1541 if (cs) flags=QTextDocument::FindCaseSensitively;
1544 { // Nothing found or new find process
1546 // nothing found, start again
1550 bool searching=true;
1551 bool foundNote=false;
1552 while (searching && !EOFind)
1556 // Searching in Note
1557 if (itFind->getNote().contains(s,cs))
1559 if (selection.single()!=itFind)
1561 selection.select(itFind);
1562 ensureSelectionVisible();
1564 if (textEditor->findText(s,flags))
1570 // Searching in Heading
1571 if (searching && itFind->getHeading().contains (s,cs) )
1573 selection.select(itFind);
1574 ensureSelectionVisible();
1580 itFind=next(itFind);
1581 if (!itFind) EOFind=true;
1583 //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1586 return selection.getBranch();
1591 void VymModel::findReset()
1592 { // Necessary if text to find changes during a find process
1599 void VymModel::setScene (QGraphicsScene *s)
1601 cout << "VM::setscene scene="<<s<<endl;
1602 mapScene=s; // FIXME VM should not be necessary anymore, move all occurences to MapEditor
1603 //init(); // Here we have a mapScene set,
1604 // which is (still) needed to create MapCenters
1607 void VymModel::setURL(const QString &url)
1609 BranchObj *bo=selection.getBranch();
1612 QString oldurl=bo->getURL();
1616 QString ("setURL (\"%1\")").arg(oldurl),
1618 QString ("setURL (\"%1\")").arg(url),
1619 QString ("set URL of %1 to %2").arg(getObjectName(bo)).arg(url)
1624 ensureSelectionVisible();
1628 QString VymModel::getURL()
1630 BranchObj *bo=selection.getBranch();
1632 return bo->getURL();
1637 QStringList VymModel::getURLs()
1640 BranchObj *bo=selection.getBranch();
1646 if (!bo->getURL().isEmpty()) urls.append( bo->getURL());
1653 void VymModel::linkFloatImageTo(const QString &dstString)
1655 FloatImageObj *fio=selection.getFloatImage();
1658 BranchObj *dst=(BranchObj*)findObjBySelect(dstString);
1659 if (dst && (typeid(*dst)==typeid (BranchObj) ||
1660 typeid(*dst)==typeid (MapCenterObj)))
1662 LinkableMapObj *dstPar=dst->getParObj();
1663 QString parString=getSelectString(dstPar);
1664 QString fioPreSelectString=getSelectString(fio);
1665 QString fioPreParentSelectString=getSelectString (fio->getParObj());
1666 ((BranchObj*)dst)->addFloatImage (fio);
1667 selection.unselect();
1668 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1669 fio=((BranchObj*)dst)->getLastFloatImage();
1672 selection.select(fio);
1674 getSelectString(fio),
1675 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1677 QString ("linkTo (\"%1\")").arg(dstString),
1678 QString ("Link floatimage to %1").arg(getObjectName(dst)));
1684 void VymModel::setFrameType(const FrameObj::FrameType &t)
1686 BranchObj *bo=selection.getBranch();
1689 QString s=bo->getFrameTypeName();
1690 bo->setFrameType (t);
1691 saveState (bo, QString("setFrameType (\"%1\")").arg(s),
1692 bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s));
1698 void VymModel::setFrameType(const QString &s)
1700 BranchObj *bo=selection.getBranch();
1703 saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),
1704 bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s));
1705 bo->setFrameType (s);
1711 void VymModel::setFramePenColor(const QColor &c)
1713 BranchObj *bo=selection.getBranch();
1716 saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ),
1717 bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() ));
1718 bo->setFramePenColor (c);
1722 void VymModel::setFrameBrushColor(const QColor &c)
1724 BranchObj *bo=selection.getBranch();
1727 saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ),
1728 bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() ));
1729 bo->setFrameBrushColor (c);
1733 void VymModel::setFramePadding (const int &i)
1735 BranchObj *bo=selection.getBranch();
1738 saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ),
1739 bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i));
1740 bo->setFramePadding (i);
1746 void VymModel::setFrameBorderWidth(const int &i)
1748 BranchObj *bo=selection.getBranch();
1751 saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ),
1752 bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i));
1753 bo->setFrameBorderWidth (i);
1759 void VymModel::setIncludeImagesVer(bool b)
1761 BranchObj *bo=selection.getBranch();
1764 QString u= b ? "false" : "true";
1765 QString r=!b ? "false" : "true";
1769 QString("setIncludeImagesVertically (%1)").arg(u),
1771 QString("setIncludeImagesVertically (%1)").arg(r),
1772 QString("Include images vertically in %1").arg(getObjectName(bo))
1774 bo->setIncludeImagesVer(b);
1779 void VymModel::setIncludeImagesHor(bool b)
1781 BranchObj *bo=selection.getBranch();
1784 QString u= b ? "false" : "true";
1785 QString r=!b ? "false" : "true";
1789 QString("setIncludeImagesHorizontally (%1)").arg(u),
1791 QString("setIncludeImagesHorizontally (%1)").arg(r),
1792 QString("Include images horizontally in %1").arg(getObjectName(bo))
1794 bo->setIncludeImagesHor(b);
1799 void VymModel::setHideLinkUnselected (bool b)
1801 LinkableMapObj *sel=selection.single();
1803 (selection.type() == Selection::Branch ||
1804 selection.type() == Selection::MapCenter ||
1805 selection.type() == Selection::FloatImage ))
1807 QString u= b ? "false" : "true";
1808 QString r=!b ? "false" : "true";
1812 QString("setHideLinkUnselected (%1)").arg(u),
1814 QString("setHideLinkUnselected (%1)").arg(r),
1815 QString("Hide link of %1 if unselected").arg(getObjectName(sel))
1817 sel->setHideLinkUnselected(b);
1821 void VymModel::setHideExport(bool b)
1823 BranchObj *bo=selection.getBranch();
1826 bo->setHideInExport (b);
1827 QString u= b ? "false" : "true";
1828 QString r=!b ? "false" : "true";
1832 QString ("setHideExport (%1)").arg(u),
1834 QString ("setHideExport (%1)").arg(r),
1835 QString ("Set HideExport flag of %1 to %2").arg(getObjectName(bo)).arg (r)
1840 // FIXME VM needed? scene()->update();
1844 void VymModel::toggleHideExport()
1846 BranchObj *bo=selection.getBranch();
1848 setHideExport ( !bo->hideInExport() );
1852 void VymModel::copy()
1854 LinkableMapObj *sel=selection.single();
1857 if (redosAvail == 0)
1860 QString s=getSelectString(sel);
1861 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1862 curClipboard=curStep;
1865 // Copy also to global clipboard, because we are at last step in history
1866 QString bakMapName(QString("history-%1").arg(curStep));
1867 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1868 copyDir (bakMapDir,clipboardDir );
1870 clipboardEmpty=false;
1876 void VymModel::pasteNoSave(const int &n)
1878 bool old=blockSaveState;
1879 blockSaveState=true;
1880 bool zippedOrg=zipped;
1881 if (redosAvail > 0 || n!=0)
1883 // Use the "historical" buffer
1884 QString bakMapName(QString("history-%1").arg(n));
1885 QString bakMapDir(tmpMapDir +"/"+bakMapName);
1886 load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
1888 // Use the global buffer
1889 load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap);
1894 void VymModel::paste()
1896 BranchObj *sel=selection.getBranch();
1899 saveStateChangingPart(
1902 QString ("paste (%1)").arg(curClipboard),
1903 QString("Paste to %1").arg( getObjectName(sel))
1910 void VymModel::cut()
1912 LinkableMapObj *sel=selection.single();
1913 if ( sel && (selection.type() == Selection::Branch ||
1914 selection.type()==Selection::MapCenter ||
1915 selection.type()==Selection::FloatImage))
1917 /* No savestate! savestate is called in cutNoSave
1918 saveStateChangingPart(
1922 QString("Cut %1").arg(getObjectName(sel ))
1931 void VymModel::moveBranchUp()
1933 BranchObj* bo=selection.getBranch();
1937 if (!bo->canMoveBranchUp()) return;
1938 par=(BranchObj*)(bo->getParObj());
1939 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1940 saveState (getSelectString(bo),"moveBranchDown ()",getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getObjectName(bo)));
1942 //FIXME VM needed? scene()->update();
1944 ensureSelectionVisible();
1948 void VymModel::moveBranchDown()
1950 BranchObj* bo=selection.getBranch();
1954 if (!bo->canMoveBranchDown()) return;
1955 par=(BranchObj*)(bo->getParObj());
1956 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1957 saveState(getSelectString(bo),"moveBranchUp ()",getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getObjectName(bo)));
1959 //FIXME VM needed? scene()->update();
1961 ensureSelectionVisible();
1965 void VymModel::sortChildren()
1967 BranchObj* bo=selection.getBranch();
1970 if(bo->countBranches()>1)
1972 saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
1975 ensureSelectionVisible();
1980 void VymModel::createMapCenter()
1982 MapCenterObj *mco=addMapCenter (QPointF (0,0) );
1983 selection.select (mco);
1986 void VymModel::createBranch()
1988 BranchObj *bo=selection.getBranch();
1991 BranchObj *newbo=addNewBranchInt (-2); // FIXME VM Old model, merge with below
1994 QList<QVariant> cData;
1995 cData << "VM:createBranch" << "undef"<<"undef";
1996 TreeItem *parti=bo->getTreeItem();
1997 TreeItem *ti=new TreeItem (cData,parti);
1999 ti->setType (TreeItem::Branch);
2000 parti->appendChild (ti);
2004 newbo->setTreeItem (ti);
2005 selection.select (newbo); // FIXME VM really needed here?
2010 MapCenterObj* VymModel::addMapCenter ()
2012 MapCenterObj *mco=addMapCenter (contextPos);
2013 cout <<"VM::addMCO () mapScene="<<mapScene<<endl;
2014 selection.select (mco);
2016 ensureSelectionVisible();
2021 QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()),
2022 QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y())
2027 MapCenterObj* VymModel::addMapCenter(QPointF absPos)
2029 MapCenterObj *mapCenter = new MapCenterObj(mapScene,this);
2030 mapCenter->setMapEditor(mapEditor); //FIXME VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
2031 mapCenter->move (absPos);
2032 mapCenter->setVisibility (true);
2033 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
2034 mapCenters.append(mapCenter);
2037 QList<QVariant> cData;
2038 cData << "VM:addMapCenter" << "undef"<<"undef";
2039 TreeItem *ti=new TreeItem (cData,rootItem);
2040 ti->setLMO (mapCenter);
2041 ti->setType (TreeItem::MapCenter);
2042 mapCenter->setTreeItem (ti);
2043 rootItem->appendChild (ti);
2048 MapCenterObj* VymModel::removeMapCenter(MapCenterObj* mco)
2050 int i=mapCenters.indexOf (mco);
2053 mapCenters.removeAt (i);
2055 if (i>0) return mapCenters.at(i-1); // Return previous MCO
2060 MapCenterObj* VymModel::getLastMapCenter()
2062 if (mapCenters.size()>0)
2063 return mapCenters.last();
2070 BranchObj* VymModel::addNewBranchInt(int num)
2072 // Depending on pos:
2073 // -3 insert in children of parent above selection
2074 // -2 add branch to selection
2075 // -1 insert in children of parent below selection
2076 // 0..n insert in children of parent at pos
2077 BranchObj *newbo=NULL;
2078 BranchObj *bo=selection.getBranch();
2083 // save scroll state. If scrolled, automatically select
2084 // new branch in order to tmp unscroll parent...
2085 newbo=bo->addBranch();
2090 bo=(BranchObj*)bo->getParObj();
2091 if (bo) newbo=bo->insertBranch(num);
2095 bo=(BranchObj*)bo->getParObj();
2096 if (bo) newbo=bo->insertBranch(num);
2098 if (!newbo) return NULL;
2103 BranchObj* VymModel::addNewBranch(int pos)
2105 // Different meaning than num in addNewBranchInt!
2109 BranchObj *bo = selection.getBranch();
2110 BranchObj *newbo=NULL;
2114 // FIXME VM do we still need this in model? setCursor (Qt::ArrowCursor);
2116 newbo=addNewBranchInt (pos-2);
2124 QString ("addBranch (%1)").arg(pos),
2125 QString ("Add new branch to %1").arg(getObjectName(bo)));
2129 latestSelectionString=getSelectString(newbo);
2130 // In Network mode, the client needs to know where the new branch is,
2131 // so we have to pass on this information via saveState.
2132 // TODO: Get rid of this positioning workaround
2133 QString ps=qpointfToString (newbo->getAbsPos());
2134 sendData ("selectLatestAdded ()");
2135 sendData (QString("move %1").arg(ps));
2143 BranchObj* VymModel::addNewBranchBefore()
2145 BranchObj *newbo=NULL;
2146 BranchObj *bo = selection.getBranch();
2147 if (bo && selection.type()==Selection::Branch)
2148 // We accept no MapCenterObj here, so we _have_ a parent
2150 QPointF p=bo->getRelPos();
2153 BranchObj *parbo=(BranchObj*)(bo->getParObj());
2155 // add below selection
2156 newbo=parbo->insertBranch(bo->getNum()+1);
2159 newbo->move2RelPos (p);
2161 // Move selection to new branch
2162 bo->linkTo (newbo,-1);
2164 saveState (newbo, "deleteKeepChildren ()", newbo, "addBranchBefore ()",
2165 QString ("Add branch before %1").arg(getObjectName(bo)));
2171 latestSelectionString=selection.getSelectString();
2175 void VymModel::deleteSelection()
2177 BranchObj *bo = selection.getBranch();
2179 if (bo && selection.type()==Selection::MapCenter)
2181 // BranchObj* par=(BranchObj*)(bo->getParObj());
2182 selection.unselect();
2183 /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!)
2184 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2186 bo=removeMapCenter ((MapCenterObj*)bo);
2189 selection.select (bo);
2190 ensureSelectionVisible();
2196 if (bo && selection.type()==Selection::Branch)
2198 QModelIndex ix=selection.getBranchIndex();
2200 BranchObj* par=(BranchObj*)bo->getParObj();
2201 selection.unselect();
2202 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
2203 par->removeBranch(bo);
2204 selection.select (par);
2205 ensureSelectionVisible();
2210 FloatImageObj *fio=selection.getFloatImage();
2213 BranchObj* par=(BranchObj*)fio->getParObj();
2214 saveStateChangingPart(
2218 QString("Delete %1").arg(getObjectName(fio))
2220 selection.unselect();
2221 par->removeFloatImage(fio);
2222 selection.select (par);
2225 ensureSelectionVisible();
2230 void VymModel::deleteKeepChildren()
2232 BranchObj *bo=selection.getBranch();
2236 par=(BranchObj*)(bo->getParObj());
2238 // Don't use this on mapcenter
2241 // Check if we have childs at all to keep
2242 if (bo->countBranches()==0)
2248 QPointF p=bo->getRelPos();
2249 saveStateChangingPart(
2252 "deleteKeepChildren ()",
2253 QString("Remove %1 and keep its children").arg(getObjectName(bo))
2256 QString sel=getSelectString(bo);
2258 par->removeBranchHere(bo);
2261 selection.getBranch()->move2RelPos (p);
2266 void VymModel::deleteChildren()
2268 BranchObj *bo=selection.getBranch();
2271 saveStateChangingPart(
2274 "deleteChildren ()",
2275 QString( "Remove children of branch %1").arg(getObjectName(bo))
2277 bo->removeChildren();
2283 bool VymModel::scrollBranch(BranchObj *bo)
2287 if (bo->isScrolled()) return false;
2288 if (bo->countBranches()==0) return false;
2289 if (bo->getDepth()==0) return false;
2295 QString ("%1 ()").arg(u),
2297 QString ("%1 ()").arg(r),
2298 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2302 // FIXME VM needed? scene()->update();
2308 bool VymModel::unscrollBranch(BranchObj *bo)
2312 if (!bo->isScrolled()) return false;
2313 if (bo->countBranches()==0) return false;
2314 if (bo->getDepth()==0) return false;
2320 QString ("%1 ()").arg(u),
2322 QString ("%1 ()").arg(r),
2323 QString ("%1 %2").arg(r).arg(getObjectName(bo))
2327 // FIXME VM needed? scene()->update();
2333 void VymModel::toggleScroll()
2335 BranchObj *bo=selection.getBranch();
2336 if (selection.type()==Selection::Branch )
2338 if (bo->isScrolled())
2339 unscrollBranch (bo);
2345 void VymModel::unscrollChildren()
2347 BranchObj *bo=selection.getBranch();
2353 if (bo->isScrolled()) unscrollBranch (bo);
2358 void VymModel::addFloatImage (const QPixmap &img)
2360 BranchObj *bo=selection.getBranch();
2363 FloatImageObj *fio=bo->addFloatImage();
2365 fio->setOriginalFilename("No original filename (image added by dropevent)");
2366 QString s=getSelectString(bo);
2367 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
2368 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
2370 // FIXME VM needed? scene()->update();
2375 void VymModel::colorBranch (QColor c)
2377 BranchObj *bo=selection.getBranch();
2382 QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
2384 QString ("colorBranch (\"%1\")").arg(c.name()),
2385 QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name())
2387 bo->setColor(c); // color branch
2391 void VymModel::colorSubtree (QColor c)
2393 BranchObj *bo=selection.getBranch();
2396 saveStateChangingPart(
2399 QString ("colorSubtree (\"%1\")").arg(c.name()),
2400 QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name())
2402 bo->setColorSubtree (c); // color links, color children
2406 QColor VymModel::getCurrentHeadingColor()
2408 BranchObj *bo=selection.getBranch();
2409 if (bo) return bo->getColor();
2411 QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected");
2417 void VymModel::editURL()
2419 BranchObj *bo=selection.getBranch();
2423 QString text = QInputDialog::getText(
2424 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2425 bo->getURL(), &ok, NULL);
2427 // user entered something and pressed OK
2432 void VymModel::editLocalURL()
2434 BranchObj *bo=selection.getBranch();
2437 QStringList filters;
2438 filters <<"All files (*)";
2439 filters << tr("Text","Filedialog") + " (*.txt)";
2440 filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)";
2441 filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)";
2442 filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)";
2443 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Set URL to a local file"));
2444 fd->setFilters (filters);
2445 fd->setCaption(vymName+" - " +tr("Set URL to a local file"));
2446 fd->setDirectory (lastFileDir);
2447 if (! bo->getVymLink().isEmpty() )
2448 fd->selectFile( bo->getURL() );
2451 if ( fd->exec() == QDialog::Accepted )
2453 lastFileDir=QDir (fd->directory().path());
2454 setURL (fd->selectedFile() );
2460 void VymModel::editHeading2URL()
2462 BranchObj *bo=selection.getBranch();
2464 setURL (bo->getHeading());
2467 void VymModel::editBugzilla2URL()
2469 BranchObj *bo=selection.getBranch();
2472 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2477 void VymModel::editFATE2URL()
2479 BranchObj *bo=selection.getBranch();
2482 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2485 "setURL (\""+bo->getURL()+"\")",
2487 "setURL (\""+url+"\")",
2488 QString("Use heading of %1 as link to FATE").arg(getObjectName(bo))
2495 void VymModel::editVymLink()
2497 BranchObj *bo=selection.getBranch();
2500 QStringList filters;
2501 filters <<"VYM map (*.vym)";
2502 QFileDialog *fd=new QFileDialog( NULL,vymName+" - " +tr("Link to another map"));
2503 fd->setFilters (filters);
2504 fd->setCaption(vymName+" - " +tr("Link to another map"));
2505 fd->setDirectory (lastFileDir);
2506 if (! bo->getVymLink().isEmpty() )
2507 fd->selectFile( bo->getVymLink() );
2511 if ( fd->exec() == QDialog::Accepted )
2513 lastFileDir=QDir (fd->directory().path());
2516 "setVymLink (\""+bo->getVymLink()+"\")",
2518 "setVymLink (\""+fd->selectedFile()+"\")",
2519 QString("Set vymlink of %1 to %2").arg(getObjectName(bo)).arg(fd->selectedFile())
2521 setVymLink (fd->selectedFile() ); // FIXME ok?
2526 void VymModel::setVymLink (const QString &s)
2528 // Internal function, no saveState needed
2529 BranchObj *bo=selection.getBranch();
2536 ensureSelectionVisible();
2540 void VymModel::deleteVymLink()
2542 BranchObj *bo=selection.getBranch();
2547 "setVymLink (\""+bo->getVymLink()+"\")",
2549 "setVymLink (\"\")",
2550 QString("Unset vymlink of %1").arg(getObjectName(bo))
2552 bo->setVymLink ("" );
2555 // FIXME VM needed? scene()->update();
2559 QString VymModel::getVymLink()
2561 BranchObj *bo=selection.getBranch();
2563 return bo->getVymLink();
2569 QStringList VymModel::getVymLinks()
2572 BranchObj *bo=selection.getBranch();
2578 if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink());
2586 void VymModel::followXLink(int i)
2588 BranchObj *bo=selection.getBranch();
2591 bo=bo->XLinkTargetAt(i);
2594 selection.select(bo);
2595 ensureSelectionVisible();
2600 void VymModel::editXLink(int i) // FIXME VM missing saveState
2602 BranchObj *bo=selection.getBranch();
2605 XLinkObj *xlo=bo->XLinkAt(i);
2608 EditXLinkDialog dia;
2610 dia.setSelection(bo);
2611 if (dia.exec() == QDialog::Accepted)
2613 if (dia.useSettingsGlobal() )
2615 setMapDefXLinkColor (xlo->getColor() );
2616 setMapDefXLinkWidth (xlo->getWidth() );
2618 if (dia.deleteXLink())
2619 bo->deleteXLinkAt(i);
2629 //////////////////////////////////////////////
2631 //////////////////////////////////////////////
2633 void VymModel::parseAtom(const QString &atom)
2635 BranchObj *selb=selection.getBranch();
2641 // Split string s into command and parameters
2642 parser.parseAtom (atom);
2643 QString com=parser.getCommand();
2645 // External commands
2646 /////////////////////////////////////////////////////////////////////
2647 if (com=="addBranch")
2649 if (selection.isEmpty())
2651 parser.setError (Aborted,"Nothing selected");
2654 parser.setError (Aborted,"Type of selection is not a branch");
2659 if (parser.checkParCount(pl))
2661 if (parser.parCount()==0)
2665 n=parser.parInt (ok,0);
2666 if (ok ) addNewBranch (n);
2670 /////////////////////////////////////////////////////////////////////
2671 } else if (com=="addBranchBefore")
2673 if (selection.isEmpty())
2675 parser.setError (Aborted,"Nothing selected");
2678 parser.setError (Aborted,"Type of selection is not a branch");
2681 if (parser.parCount()==0)
2683 addNewBranchBefore ();
2686 /////////////////////////////////////////////////////////////////////
2687 } else if (com==QString("addMapCenter"))
2689 if (parser.checkParCount(2))
2691 x=parser.parDouble (ok,0);
2694 y=parser.parDouble (ok,1);
2695 if (ok) addMapCenter (QPointF(x,y));
2698 /////////////////////////////////////////////////////////////////////
2699 } else if (com==QString("addMapReplace"))
2701 if (selection.isEmpty())
2703 parser.setError (Aborted,"Nothing selected");
2706 parser.setError (Aborted,"Type of selection is not a branch");
2707 } else if (parser.checkParCount(1))
2709 //s=parser.parString (ok,0); // selection
2710 t=parser.parString (ok,0); // path to map
2711 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2712 addMapReplaceInt(getSelectString(selb),t);
2714 /////////////////////////////////////////////////////////////////////
2715 } else if (com==QString("addMapInsert"))
2717 if (selection.isEmpty())
2719 parser.setError (Aborted,"Nothing selected");
2722 parser.setError (Aborted,"Type of selection is not a branch");
2725 if (parser.checkParCount(2))
2727 t=parser.parString (ok,0); // path to map
2728 n=parser.parInt(ok,1); // position
2729 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
2730 addMapInsertInt(t,n);
2733 /////////////////////////////////////////////////////////////////////
2734 } else if (com=="clearFlags")
2736 if (selection.isEmpty() )
2738 parser.setError (Aborted,"Nothing selected");
2741 parser.setError (Aborted,"Type of selection is not a branch");
2742 } else if (parser.checkParCount(0))
2744 selb->clearStandardFlags();
2745 selb->updateFlagsToolbar();
2747 /////////////////////////////////////////////////////////////////////
2748 } else if (com=="colorBranch")
2750 if (selection.isEmpty())
2752 parser.setError (Aborted,"Nothing selected");
2755 parser.setError (Aborted,"Type of selection is not a branch");
2756 } else if (parser.checkParCount(1))
2758 QColor c=parser.parColor (ok,0);
2759 if (ok) colorBranch (c);
2761 /////////////////////////////////////////////////////////////////////
2762 } else if (com=="colorSubtree")
2764 if (selection.isEmpty())
2766 parser.setError (Aborted,"Nothing selected");
2769 parser.setError (Aborted,"Type of selection is not a branch");
2770 } else if (parser.checkParCount(1))
2772 QColor c=parser.parColor (ok,0);
2773 if (ok) colorSubtree (c);
2775 /////////////////////////////////////////////////////////////////////
2776 } else if (com=="copy")
2778 if (selection.isEmpty())
2780 parser.setError (Aborted,"Nothing selected");
2783 parser.setError (Aborted,"Type of selection is not a branch");
2784 } else if (parser.checkParCount(0))
2786 //FIXME missing action for copy
2788 /////////////////////////////////////////////////////////////////////
2789 } else if (com=="cut")
2791 if (selection.isEmpty())
2793 parser.setError (Aborted,"Nothing selected");
2794 } else if ( selection.type()!=Selection::Branch &&
2795 selection.type()!=Selection::MapCenter &&
2796 selection.type()!=Selection::FloatImage )
2798 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
2799 } else if (parser.checkParCount(0))
2803 /////////////////////////////////////////////////////////////////////
2804 } else if (com=="delete")
2806 if (selection.isEmpty())
2808 parser.setError (Aborted,"Nothing selected");
2810 /*else if (selection.type() != Selection::Branch && selection.type() != Selection::FloatImage )
2812 parser.setError (Aborted,"Type of selection is wrong.");
2815 else if (parser.checkParCount(0))
2819 /////////////////////////////////////////////////////////////////////
2820 } else if (com=="deleteKeepChildren")
2822 if (selection.isEmpty())
2824 parser.setError (Aborted,"Nothing selected");
2827 parser.setError (Aborted,"Type of selection is not a branch");
2828 } else if (parser.checkParCount(0))
2830 deleteKeepChildren();
2832 /////////////////////////////////////////////////////////////////////
2833 } else if (com=="deleteChildren")
2835 if (selection.isEmpty())
2837 parser.setError (Aborted,"Nothing selected");
2840 parser.setError (Aborted,"Type of selection is not a branch");
2841 } else if (parser.checkParCount(0))
2845 /////////////////////////////////////////////////////////////////////
2846 } else if (com=="exportASCII")
2850 if (parser.parCount()>=1)
2851 // Hey, we even have a filename
2852 fname=parser.parString(ok,0);
2855 parser.setError (Aborted,"Could not read filename");
2858 exportASCII (fname,false);
2860 /////////////////////////////////////////////////////////////////////
2861 } else if (com=="exportImage")
2865 if (parser.parCount()>=2)
2866 // Hey, we even have a filename
2867 fname=parser.parString(ok,0);
2870 parser.setError (Aborted,"Could not read filename");
2873 QString format="PNG";
2874 if (parser.parCount()>=2)
2876 format=parser.parString(ok,1);
2878 exportImage (fname,false,format);
2880 /////////////////////////////////////////////////////////////////////
2881 } else if (com=="exportXHTML")
2885 if (parser.parCount()>=2)
2886 // Hey, we even have a filename
2887 fname=parser.parString(ok,1);
2890 parser.setError (Aborted,"Could not read filename");
2893 exportXHTML (fname,false);
2895 /////////////////////////////////////////////////////////////////////
2896 } else if (com=="exportXML")
2900 if (parser.parCount()>=2)
2901 // Hey, we even have a filename
2902 fname=parser.parString(ok,1);
2905 parser.setError (Aborted,"Could not read filename");
2908 exportXML (fname,false);
2910 /////////////////////////////////////////////////////////////////////
2911 } else if (com=="importDir")
2913 if (selection.isEmpty())
2915 parser.setError (Aborted,"Nothing selected");
2918 parser.setError (Aborted,"Type of selection is not a branch");
2919 } else if (parser.checkParCount(1))
2921 s=parser.parString(ok,0);
2922 if (ok) importDirInt(s);
2924 /////////////////////////////////////////////////////////////////////
2925 } else if (com=="linkTo")
2927 if (selection.isEmpty())
2929 parser.setError (Aborted,"Nothing selected");
2932 if (parser.checkParCount(4))
2934 // 0 selectstring of parent
2935 // 1 num in parent (for branches)
2936 // 2,3 x,y of mainbranch or mapcenter
2937 s=parser.parString(ok,0);
2938 LinkableMapObj *dst=findObjBySelect (s);
2941 if (typeid(*dst) == typeid(BranchObj) )
2943 // Get number in parent
2944 n=parser.parInt (ok,1);
2947 selb->linkTo ((BranchObj*)(dst),n);
2950 } else if (typeid(*dst) == typeid(MapCenterObj) )
2952 selb->linkTo ((BranchObj*)(dst),-1);
2953 // Get coordinates of mainbranch
2954 x=parser.parDouble(ok,2);
2957 y=parser.parDouble(ok,3);
2967 } else if ( selection.type() == Selection::FloatImage)
2969 if (parser.checkParCount(1))
2971 // 0 selectstring of parent
2972 s=parser.parString(ok,0);
2973 LinkableMapObj *dst=findObjBySelect (s);
2976 if (typeid(*dst) == typeid(BranchObj) ||
2977 typeid(*dst) == typeid(MapCenterObj))
2978 linkFloatImageTo (getSelectString(dst));
2980 parser.setError (Aborted,"Destination is not a branch");
2983 parser.setError (Aborted,"Type of selection is not a floatimage or branch");
2984 /////////////////////////////////////////////////////////////////////
2985 } else if (com=="loadImage")
2987 if (selection.isEmpty())
2989 parser.setError (Aborted,"Nothing selected");
2992 parser.setError (Aborted,"Type of selection is not a branch");
2993 } else if (parser.checkParCount(1))
2995 s=parser.parString(ok,0);
2996 if (ok) loadFloatImageInt (s);
2998 /////////////////////////////////////////////////////////////////////
2999 } else if (com=="moveBranchUp")
3001 if (selection.isEmpty() )
3003 parser.setError (Aborted,"Nothing selected");
3006 parser.setError (Aborted,"Type of selection is not a branch");
3007 } else if (parser.checkParCount(0))
3011 /////////////////////////////////////////////////////////////////////
3012 } else if (com=="moveBranchDown")
3014 if (selection.isEmpty() )
3016 parser.setError (Aborted,"Nothing selected");
3019 parser.setError (Aborted,"Type of selection is not a branch");
3020 } else if (parser.checkParCount(0))
3024 /////////////////////////////////////////////////////////////////////
3025 } else if (com=="move")
3027 if (selection.isEmpty() )
3029 parser.setError (Aborted,"Nothing selected");
3030 } else if ( selection.type()!=Selection::Branch &&
3031 selection.type()!=Selection::MapCenter &&
3032 selection.type()!=Selection::FloatImage )
3034 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3035 } else if (parser.checkParCount(2))
3037 x=parser.parDouble (ok,0);
3040 y=parser.parDouble (ok,1);
3044 /////////////////////////////////////////////////////////////////////
3045 } else if (com=="moveRel")
3047 if (selection.isEmpty() )
3049 parser.setError (Aborted,"Nothing selected");
3050 } else if ( selection.type()!=Selection::Branch &&
3051 selection.type()!=Selection::MapCenter &&
3052 selection.type()!=Selection::FloatImage )
3054 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3055 } else if (parser.checkParCount(2))
3057 x=parser.parDouble (ok,0);
3060 y=parser.parDouble (ok,1);
3061 if (ok) moveRel (x,y);
3064 /////////////////////////////////////////////////////////////////////
3065 } else if (com=="nop")
3067 /////////////////////////////////////////////////////////////////////
3068 } else if (com=="paste")
3070 if (selection.isEmpty() )
3072 parser.setError (Aborted,"Nothing selected");
3075 parser.setError (Aborted,"Type of selection is not a branch");
3076 } else if (parser.checkParCount(1))
3078 n=parser.parInt (ok,0);
3079 if (ok) pasteNoSave(n);
3081 /////////////////////////////////////////////////////////////////////
3082 } else if (com=="qa")
3084 if (selection.isEmpty() )
3086 parser.setError (Aborted,"Nothing selected");
3089 parser.setError (Aborted,"Type of selection is not a branch");
3090 } else if (parser.checkParCount(4))
3093 c=parser.parString (ok,0);
3096 parser.setError (Aborted,"No comment given");
3099 s=parser.parString (ok,1);
3102 parser.setError (Aborted,"First parameter is not a string");
3105 t=parser.parString (ok,2);
3108 parser.setError (Aborted,"Condition is not a string");
3111 u=parser.parString (ok,3);
3114 parser.setError (Aborted,"Third parameter is not a string");
3119 parser.setError (Aborted,"Unknown type: "+s);
3124 parser.setError (Aborted,"Unknown operator: "+t);
3129 parser.setError (Aborted,"Type of selection is not a branch");
3132 if (selb->getHeading() == u)
3134 cout << "PASSED: " << qPrintable (c) << endl;
3137 cout << "FAILED: " << qPrintable (c) << endl;
3147 /////////////////////////////////////////////////////////////////////
3148 } else if (com=="saveImage")
3150 FloatImageObj *fio=selection.getFloatImage();
3153 parser.setError (Aborted,"Type of selection is not an image");
3154 } else if (parser.checkParCount(2))
3156 s=parser.parString(ok,0);
3159 t=parser.parString(ok,1);
3160 if (ok) saveFloatImageInt (fio,t,s);
3163 /////////////////////////////////////////////////////////////////////
3164 } else if (com=="scroll")
3166 if (selection.isEmpty() )
3168 parser.setError (Aborted,"Nothing selected");
3171 parser.setError (Aborted,"Type of selection is not a branch");
3172 } else if (parser.checkParCount(0))
3174 if (!scrollBranch (selb))
3175 parser.setError (Aborted,"Could not scroll branch");
3177 /////////////////////////////////////////////////////////////////////
3178 } else if (com=="select")
3180 if (parser.checkParCount(1))
3182 s=parser.parString(ok,0);
3185 /////////////////////////////////////////////////////////////////////
3186 } else if (com=="selectLastBranch")
3188 if (selection.isEmpty() )
3190 parser.setError (Aborted,"Nothing selected");
3193 parser.setError (Aborted,"Type of selection is not a branch");
3194 } else if (parser.checkParCount(0))
3196 BranchObj *bo=selb->getLastBranch();
3198 parser.setError (Aborted,"Could not select last branch");
3202 /////////////////////////////////////////////////////////////////////
3203 } else if (com=="selectLastImage")
3205 if (selection.isEmpty() )
3207 parser.setError (Aborted,"Nothing selected");
3210 parser.setError (Aborted,"Type of selection is not a branch");
3211 } else if (parser.checkParCount(0))
3213 FloatImageObj *fio=selb->getLastFloatImage();
3215 parser.setError (Aborted,"Could not select last image");
3219 /////////////////////////////////////////////////////////////////////
3220 } else if (com=="selectLatestAdded")
3222 if (latestSelectionString.isEmpty() )
3224 parser.setError (Aborted,"No latest added object");
3227 if (!select (latestSelectionString))
3228 parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
3230 /////////////////////////////////////////////////////////////////////
3231 } else if (com=="setFrameType")
3233 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3235 parser.setError (Aborted,"Type of selection does not allow setting frame type");
3237 else if (parser.checkParCount(1))
3239 s=parser.parString(ok,0);
3240 if (ok) setFrameType (s);
3242 /////////////////////////////////////////////////////////////////////
3243 } else if (com=="setFramePenColor")
3245 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3247 parser.setError (Aborted,"Type of selection does not allow setting of pen color");
3249 else if (parser.checkParCount(1))
3251 QColor c=parser.parColor(ok,0);
3252 if (ok) setFramePenColor (c);
3254 /////////////////////////////////////////////////////////////////////
3255 } else if (com=="setFrameBrushColor")
3257 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3259 parser.setError (Aborted,"Type of selection does not allow setting brush color");
3261 else if (parser.checkParCount(1))
3263 QColor c=parser.parColor(ok,0);
3264 if (ok) setFrameBrushColor (c);
3266 /////////////////////////////////////////////////////////////////////
3267 } else if (com=="setFramePadding")
3269 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3271 parser.setError (Aborted,"Type of selection does not allow setting frame padding");
3273 else if (parser.checkParCount(1))
3275 n=parser.parInt(ok,0);
3276 if (ok) setFramePadding(n);
3278 /////////////////////////////////////////////////////////////////////
3279 } else if (com=="setFrameBorderWidth")
3281 if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3283 parser.setError (Aborted,"Type of selection does not allow setting frame border width");
3285 else if (parser.checkParCount(1))
3287 n=parser.parInt(ok,0);
3288 if (ok) setFrameBorderWidth (n);
3290 /////////////////////////////////////////////////////////////////////
3291 } else if (com=="setMapAuthor")
3293 if (parser.checkParCount(1))
3295 s=parser.parString(ok,0);
3296 if (ok) setAuthor (s);
3298 /////////////////////////////////////////////////////////////////////
3299 } else if (com=="setMapComment")
3301 if (parser.checkParCount(1))
3303 s=parser.parString(ok,0);
3304 if (ok) setComment(s);
3306 /////////////////////////////////////////////////////////////////////
3307 } else if (com=="setMapBackgroundColor")
3309 if (selection.isEmpty() )
3311 parser.setError (Aborted,"Nothing selected");
3312 } else if (! selection.getBranch() )
3314 parser.setError (Aborted,"Type of selection is not a branch");
3315 } else if (parser.checkParCount(1))
3317 QColor c=parser.parColor (ok,0);
3318 if (ok) setMapBackgroundColor (c);
3320 /////////////////////////////////////////////////////////////////////
3321 } else if (com=="setMapDefLinkColor")
3323 if (selection.isEmpty() )
3325 parser.setError (Aborted,"Nothing selected");
3328 parser.setError (Aborted,"Type of selection is not a branch");
3329 } else if (parser.checkParCount(1))
3331 QColor c=parser.parColor (ok,0);
3332 if (ok) setMapDefLinkColor (c);
3334 /////////////////////////////////////////////////////////////////////
3335 } else if (com=="setMapLinkStyle")
3337 if (parser.checkParCount(1))
3339 s=parser.parString (ok,0);
3340 if (ok) setMapLinkStyle(s);
3342 /////////////////////////////////////////////////////////////////////
3343 } else if (com=="setHeading")
3345 if (selection.isEmpty() )
3347 parser.setError (Aborted,"Nothing selected");
3350 parser.setError (Aborted,"Type of selection is not a branch");
3351 } else if (parser.checkParCount(1))
3353 s=parser.parString (ok,0);
3357 /////////////////////////////////////////////////////////////////////
3358 } else if (com=="setHideExport")
3360 if (selection.isEmpty() )
3362 parser.setError (Aborted,"Nothing selected");
3363 } else if (selection.type()!=Selection::Branch && selection.type() != Selection::MapCenter &&selection.type()!=Selection::FloatImage)
3365 parser.setError (Aborted,"Type of selection is not a branch or floatimage");
3366 } else if (parser.checkParCount(1))
3368 b=parser.parBool(ok,0);
3369 if (ok) setHideExport (b);
3371 /////////////////////////////////////////////////////////////////////
3372 } else if (com=="setIncludeImagesHorizontally")
3374 if (selection.isEmpty() )
3376 parser.setError (Aborted,"Nothing selected");
3379 parser.setError (Aborted,"Type of selection is not a branch");
3380 } else if (parser.checkParCount(1))
3382 b=parser.parBool(ok,0);
3383 if (ok) setIncludeImagesHor(b);
3385 /////////////////////////////////////////////////////////////////////
3386 } else if (com=="setIncludeImagesVertically")
3388 if (selection.isEmpty() )
3390 parser.setError (Aborted,"Nothing selected");
3393 parser.setError (Aborted,"Type of selection is not a branch");
3394 } else if (parser.checkParCount(1))
3396 b=parser.parBool(ok,0);
3397 if (ok) setIncludeImagesVer(b);
3399 /////////////////////////////////////////////////////////////////////
3400 } else if (com=="setHideLinkUnselected")
3402 if (selection.isEmpty() )
3404 parser.setError (Aborted,"Nothing selected");
3405 } else if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage)
3407 parser.setError (Aborted,"Type of selection does not allow hiding the link");
3408 } else if (parser.checkParCount(1))
3410 b=parser.parBool(ok,0);
3411 if (ok) setHideLinkUnselected(b);
3413 /////////////////////////////////////////////////////////////////////
3414 } else if (com=="setSelectionColor")
3416 if (parser.checkParCount(1))
3418 QColor c=parser.parColor (ok,0);
3419 if (ok) setSelectionColorInt (c);
3421 /////////////////////////////////////////////////////////////////////
3422 } else if (com=="setURL")
3424 if (selection.isEmpty() )
3426 parser.setError (Aborted,"Nothing selected");
3429 parser.setError (Aborted,"Type of selection is not a branch");
3430 } else if (parser.checkParCount(1))
3432 s=parser.parString (ok,0);
3435 /////////////////////////////////////////////////////////////////////
3436 } else if (com=="setVymLink")
3438 if (selection.isEmpty() )
3440 parser.setError (Aborted,"Nothing selected");
3443 parser.setError (Aborted,"Type of selection is not a branch");
3444 } else if (parser.checkParCount(1))
3446 s=parser.parString (ok,0);
3447 if (ok) setVymLink(s);
3450 /////////////////////////////////////////////////////////////////////
3451 else if (com=="setFlag")
3453 if (selection.isEmpty() )
3455 parser.setError (Aborted,"Nothing selected");
3458 parser.setError (Aborted,"Type of selection is not a branch");
3459 } else if (parser.checkParCount(1))
3461 s=parser.parString(ok,0);
3464 selb->activateStandardFlag(s);
3465 selb->updateFlagsToolbar();
3468 /////////////////////////////////////////////////////////////////////
3469 } else if (com=="setFrameType")
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);
3483 /////////////////////////////////////////////////////////////////////
3484 } else if (com=="sortChildren")
3486 if (selection.isEmpty() )
3488 parser.setError (Aborted,"Nothing selected");
3491 parser.setError (Aborted,"Type of selection is not a branch");
3492 } else if (parser.checkParCount(0))
3496 /////////////////////////////////////////////////////////////////////
3497 } else if (com=="toggleFlag")
3499 if (selection.isEmpty() )
3501 parser.setError (Aborted,"Nothing selected");
3504 parser.setError (Aborted,"Type of selection is not a branch");
3505 } else if (parser.checkParCount(1))
3507 s=parser.parString(ok,0);
3510 selb->toggleStandardFlag(s);
3511 selb->updateFlagsToolbar();
3514 /////////////////////////////////////////////////////////////////////
3515 } else if (com=="unscroll")
3517 if (selection.isEmpty() )
3519 parser.setError (Aborted,"Nothing selected");
3522 parser.setError (Aborted,"Type of selection is not a branch");
3523 } else if (parser.checkParCount(0))
3525 if (!unscrollBranch (selb))
3526 parser.setError (Aborted,"Could not unscroll branch");
3528 /////////////////////////////////////////////////////////////////////
3529 } else if (com=="unscrollChildren")
3531 if (selection.isEmpty() )
3533 parser.setError (Aborted,"Nothing selected");
3536 parser.setError (Aborted,"Type of selection is not a branch");
3537 } else if (parser.checkParCount(0))
3539 unscrollChildren ();
3541 /////////////////////////////////////////////////////////////////////
3542 } else if (com=="unsetFlag")
3544 if (selection.isEmpty() )
3546 parser.setError (Aborted,"Nothing selected");
3549 parser.setError (Aborted,"Type of selection is not a branch");
3550 } else if (parser.checkParCount(1))
3552 s=parser.parString(ok,0);
3555 selb->deactivateStandardFlag(s);
3556 selb->updateFlagsToolbar();
3560 parser.setError (Aborted,"Unknown command");
3563 if (parser.errorLevel()==NoError)
3565 // setChanged(); FIXME should not be called e.g. for export?!
3570 // TODO Error handling
3571 qWarning("VymModel::parseAtom: Error!");
3572 qWarning(parser.errorMessage());
3576 void VymModel::runScript (QString script)
3578 parser.setScript (script);
3580 while (parser.next() )
3581 parseAtom(parser.getAtom());
3584 void VymModel::setExportMode (bool b)
3586 // should be called before and after exports
3587 // depending on the settings
3588 if (b && settings.value("/export/useHideExport","true")=="true")
3589 setHideTmpMode (HideExport);
3591 setHideTmpMode (HideNone);
3594 void VymModel::exportImage(QString fname, bool askName, QString format)
3598 fname=getMapName()+".png";
3605 QFileDialog *fd=new QFileDialog (NULL);
3606 fd->setCaption (tr("Export map as image"));
3607 fd->setDirectory (lastImageDir);
3608 fd->setFileMode(QFileDialog::AnyFile);
3609 fd->setFilters (imageIO.getFilters() );
3612 fl=fd->selectedFiles();
3614 format=imageIO.getType(fd->selectedFilter());
3618 setExportMode (true);
3619 QPixmap pix (getPixmap());
3620 pix.save(fname, format);
3621 setExportMode (false);
3625 void VymModel::exportXML(QString dir, bool askForName)
3629 dir=browseDirectory(NULL,tr("Export XML to directory"));
3630 if (dir =="" && !reallyWriteDirectory(dir) )
3634 // Hide stuff during export, if settings want this
3635 setExportMode (true);
3637 // Create subdirectories
3640 // write to directory
3641 QString saveFile=saveToDir (dir,mapName+"-",true,getTotalBBox().topLeft() ,NULL);
3644 file.setName ( dir + "/"+mapName+".xml");
3645 if ( !file.open( QIODevice::WriteOnly ) )
3647 // This should neverever happen
3648 QMessageBox::critical (0,tr("Critical Export Error"),tr("VymModel::exportXML couldn't open %1").arg(file.name()));
3652 // Write it finally, and write in UTF8, no matter what
3653 QTextStream ts( &file );
3654 ts.setEncoding (QTextStream::UnicodeUTF8);
3658 // Now write image, too
3659 exportImage (dir+"/images/"+mapName+".png",false,"PNG");
3661 setExportMode (false);
3664 void VymModel::exportASCII(QString fname,bool askName)
3669 ex.setFile (mapName+".txt");
3675 //ex.addFilter ("TXT (*.txt)");
3676 ex.setDir(lastImageDir);
3677 //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)"));
3682 setExportMode(true);
3684 setExportMode(false);
3688 void VymModel::exportXHTML (const QString &dir, bool askForName)
3690 ExportXHTMLDialog dia(NULL);
3691 dia.setFilePath (filePath );
3692 dia.setMapName (mapName );
3694 if (dir!="") dia.setDir (dir);
3700 if (dia.exec()!=QDialog::Accepted)
3704 QDir d (dia.getDir());
3705 // Check, if warnings should be used before overwriting
3706 // the output directory
3707 if (d.exists() && d.count()>0)
3710 warn.showCancelButton (true);
3711 warn.setText(QString(
3712 "The directory %1 is not empty.\n"
3713 "Do you risk to overwrite some of its contents?").arg(d.path() ));
3714 warn.setCaption("Warning: Directory not empty");
3715 warn.setShowAgainName("mainwindow/overwrite-dir-xhtml");
3717 if (warn.exec()!=QDialog::Accepted) ok=false;
3724 exportXML (dia.getDir(),false );
3725 dia.doExport(mapName );
3726 //if (dia.hasChanged()) setChanged();
3730 void VymModel::exportOOPresentation(const QString &fn, const QString &cf)
3735 if (ex.setConfigFile(cf))
3737 setExportMode (true);
3738 ex.exportPresentation();
3739 setExportMode (false);
3746 //////////////////////////////////////////////
3748 //////////////////////////////////////////////
3750 void VymModel::registerEditor(QWidget *me)
3752 mapEditor=(MapEditor*)me;
3753 for (int i=0; i<mapCenters.count(); i++)
3754 mapCenters.at(i)->setMapEditor(mapEditor);
3757 void VymModel::unregisterEditor(QWidget *)
3762 void VymModel::setContextPos(QPointF p)
3767 void VymModel::unsetContextPos()
3769 contextPos=QPointF();
3772 void VymModel::updateNoteFlag()
3775 BranchObj *bo=selection.getBranch();
3778 bo->updateNoteFlag();
3779 mainWindow->updateActions();
3783 void VymModel::updateRelPositions()
3785 for (int i=0; i<mapCenters.count(); i++)
3786 mapCenters.at(i)->updateRelPositions();
3789 void VymModel::reposition()
3791 for (int i=0;i<mapCenters.count(); i++)
3792 mapCenters.at(i)->reposition(); // for positioning heading
3795 QPolygonF VymModel::shape(BranchObj *bo)
3797 // Creating (arbitrary) shapes
3800 QRectF rb=bo->getBBox();
3801 if (bo->getDepth()==0)
3803 // Just take BBox of this mapCenter
3804 p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
3808 // Take union of BBox and TotalBBox
3810 QRectF ra=bo->getTotalBBox();
3811 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
3814 <<QPointF (rb.topLeft().x(), ra.topLeft().y() )
3817 <<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
3819 p <<ra.bottomRight()
3821 <<QPointF (rb.topRight().x(), ra.topRight().y() )
3824 <<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
3829 void VymModel::moveAway(LinkableMapObj *lmo)
3833 // Move all branches and MapCenters away from lmo
3834 // to avoid collisions
3839 BranchObj *boA=(BranchObj*)lmo;
3841 for (int i=0; i<mapCenters.count(); i++)
3843 boB=mapCenters.at(i);
3846 PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
3849 <<" ("<<qPrintable(boA->getHeading() )<<")"
3850 <<" with ("<< qPrintable (boB->getHeading() )
3853 <<" minT="<<r.minTranslation<<endl<<endl;
3857 QPixmap VymModel::getPixmap()
3859 QRectF mapRect=getTotalBBox();
3860 QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
3863 pp.setRenderHints(mapEditor->renderHints());
3865 // Don't print the visualisation of selection
3866 selection.unselect();
3868 mapScene->render ( &pp,
3869 QRectF(0,0,mapRect.width()+2,mapRect.height()+2),
3870 QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() ));
3872 // Restore selection
3873 selection.reselect();
3879 void VymModel::setMapLinkStyle (const QString & s)
3884 case LinkableMapObj::Line :
3887 case LinkableMapObj::Parabel:
3888 snow="StyleParabel";
3890 case LinkableMapObj::PolyLine:
3891 snow="StylePolyLine";
3893 case LinkableMapObj::PolyParabel:
3894 snow="StylePolyParabel";
3897 snow="UndefinedStyle";
3902 QString("setMapLinkStyle (\"%1\")").arg(s),
3903 QString("setMapLinkStyle (\"%1\")").arg(snow),
3904 QString("Set map link style (\"%1\")").arg(s)
3908 linkstyle=LinkableMapObj::Line;
3909 else if (s=="StyleParabel")
3910 linkstyle=LinkableMapObj::Parabel;
3911 else if (s=="StylePolyLine")
3912 linkstyle=LinkableMapObj::PolyLine;
3913 else if (s=="StylePolyParabel")
3914 linkstyle=LinkableMapObj::PolyParabel;
3916 linkstyle=LinkableMapObj::UndefinedStyle;
3923 bo->setLinkStyle(bo->getDefLinkStyle());
3929 LinkableMapObj::Style VymModel::getMapLinkStyle ()
3934 void VymModel::setMapDefLinkColor(QColor col)
3936 if ( !col.isValid() ) return;
3938 QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()),
3939 QString("setMapDefLinkColor (\"%1\")").arg(col.name()),
3940 QString("Set map link color to %1").arg(col.name())
3954 void VymModel::setMapLinkColorHintInt()
3956 // called from setMapLinkColorHint(lch) or at end of parse
3966 void VymModel::setMapLinkColorHint(LinkableMapObj::ColorHint lch)
3969 setMapLinkColorHintInt();
3972 void VymModel::toggleMapLinkColorHint()
3974 if (linkcolorhint==LinkableMapObj::HeadingColor)
3975 linkcolorhint=LinkableMapObj::DefaultColor;
3977 linkcolorhint=LinkableMapObj::HeadingColor;
3987 void VymModel::selectMapBackgroundImage ()
3989 Q3FileDialog *fd=new Q3FileDialog( NULL);
3990 fd->setMode (Q3FileDialog::ExistingFile);
3991 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
3992 ImagePreview *p =new ImagePreview (fd);
3993 fd->setContentsPreviewEnabled( TRUE );
3994 fd->setContentsPreview( p, p );
3995 fd->setPreviewMode( Q3FileDialog::Contents );
3996 fd->setCaption(vymName+" - " +tr("Load background image"));
3997 fd->setDir (lastImageDir);
4000 if ( fd->exec() == QDialog::Accepted )
4002 // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory();
4003 lastImageDir=QDir (fd->dirPath());
4004 setMapBackgroundImage (fd->selectedFile());
4008 void VymModel::setMapBackgroundImage (const QString &fn) //FIXME missing savestate
4010 QColor oldcol=mapScene->backgroundBrush().color();
4014 QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
4016 QString ("setMapBackgroundImage (%1)").arg(col.name()),
4017 QString("Set background color of map to %1").arg(col.name()));
4020 brush.setTextureImage (QPixmap (fn));
4021 mapScene->setBackgroundBrush(brush);
4024 void VymModel::selectMapBackgroundColor()
4026 QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), NULL);
4027 if ( !col.isValid() ) return;
4028 setMapBackgroundColor( col );
4032 void VymModel::setMapBackgroundColor(QColor col)
4034 QColor oldcol=mapScene->backgroundBrush().color();
4036 QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
4037 QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
4038 QString("Set background color of map to %1").arg(col.name()));
4039 mapScene->setBackgroundBrush(col);
4042 QColor VymModel::getMapBackgroundColor()
4044 return mapScene->backgroundBrush().color();
4048 LinkableMapObj::ColorHint VymModel::getMapLinkColorHint()
4050 return linkcolorhint;
4053 QColor VymModel::getMapDefLinkColor()
4055 return defLinkColor;
4058 void VymModel::setMapDefXLinkColor(QColor col)
4063 QColor VymModel::getMapDefXLinkColor()
4065 return defXLinkColor;
4068 void VymModel::setMapDefXLinkWidth (int w)
4073 int VymModel::getMapDefXLinkWidth()
4075 return defXLinkWidth;
4078 void VymModel::move(const double &x, const double &y)
4080 LinkableMapObj *sel=selection.single();
4083 QPointF ap(sel->getAbsPos());
4087 QString ps=qpointfToString(ap);
4088 QString s=selection.getSelectString();
4091 s, "move "+qpointfToString(to),
4092 QString("Move %1 to %2").arg(getObjectName(sel)).arg(ps));
4100 void VymModel::moveRel (const double &x, const double &y)
4102 LinkableMapObj *sel=selection.single();
4105 QPointF rp(sel->getRelPos());
4109 QString ps=qpointfToString (sel->getRelPos());
4110 QString s=getSelectString(sel);
4113 s, "moveRel "+qpointfToString(to),
4114 QString("Move %1 to relative position %2").arg(getObjectName(sel)).arg(ps));
4115 ((OrnamentedObj*)sel)->move2RelPos (x,y);
4124 void VymModel::animate()
4126 animationTimer->stop();
4129 while (i<animObjList.size() )
4131 bo=(BranchObj*)animObjList.at(i);
4136 animObjList.removeAt(i);
4143 emit (selectionChanged(selModel->selection(), selModel->selection()) );
4145 if (!animObjList.isEmpty()) animationTimer->start();
4149 void VymModel::startAnimation(BranchObj *bo, const QPointF &start, const QPointF &dest)
4151 if (bo && bo->getDepth()>0)
4154 ap.setStart (start);
4156 ap.setTicks (animationTicks);
4157 ap.setAnimated (true);
4158 bo->setAnimation (ap);
4159 animObjList.append( bo );
4160 animationTimer->setSingleShot (true);
4161 animationTimer->start(animationInterval);
4165 void VymModel::stopAnimation (MapObj *mo)
4167 int i=animObjList.indexOf(mo);
4169 animObjList.removeAt (i);
4172 void VymModel::sendSelection()
4174 if (netstate!=Server) return;
4175 sendData (QString("select (\"%1\")").arg(selection.getSelectString()) );
4178 void VymModel::newServer()
4182 tcpServer = new QTcpServer(this);
4183 if (!tcpServer->listen(QHostAddress::Any,port)) {
4184 QMessageBox::critical(NULL, "vym server",
4185 QString("Unable to start the server: %1.").arg(tcpServer->errorString()));
4186 //FIXME needed? we are no widget any longer... close();
4189 connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient()));
4191 cout<<"Server is running on port "<<tcpServer->serverPort()<<endl;
4194 void VymModel::connectToServer()
4197 server="salam.suse.de";
4199 clientSocket = new QTcpSocket (this);
4200 clientSocket->abort();
4201 clientSocket->connectToHost(server ,port);
4202 connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData()));
4203 connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
4204 this, SLOT(displayNetworkError(QAbstractSocket::SocketError)));
4206 cout<<"connected to "<<qPrintable (server)<<" port "<<port<<endl;
4211 void VymModel::newClient()
4213 QTcpSocket *newClient = tcpServer->nextPendingConnection();
4214 connect(newClient, SIGNAL(disconnected()),
4215 newClient, SLOT(deleteLater()));
4217 cout <<"ME::newClient at "<<qPrintable( newClient->peerAddress().toString() )<<endl;
4219 clientList.append (newClient);
4223 void VymModel::sendData(const QString &s)
4225 if (clientList.size()==0) return;
4227 // Create bytearray to send
4229 QDataStream out(&block, QIODevice::WriteOnly);
4230 out.setVersion(QDataStream::Qt_4_0);
4232 // Reserve some space for blocksize
4235 // Write sendCounter
4236 out << sendCounter++;
4241 // Go back and write blocksize so far
4242 out.device()->seek(0);
4243 quint16 bs=(quint16)(block.size() - 2*sizeof(quint16));
4247 cout << "ME::sendData bs="<<bs<<" counter="<<sendCounter<<" s="<<qPrintable(s)<<endl;
4249 for (int i=0; i<clientList.size(); ++i)
4251 //cout << "Sending \""<<qPrintable (s)<<"\" to "<<qPrintable (clientList.at(i)->peerAddress().toString())<<endl;
4252 clientList.at(i)->write (block);
4256 void VymModel::readData ()
4258 while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) )
4261 cout <<"readData bytesAvail="<<clientSocket->bytesAvailable();
4265 QDataStream in(clientSocket);
4266 in.setVersion(QDataStream::Qt_4_0);
4274 cout << " t="<<qPrintable (t)<<endl;
4280 void VymModel::displayNetworkError(QAbstractSocket::SocketError socketError)
4282 switch (socketError) {
4283 case QAbstractSocket::RemoteHostClosedError:
4285 case QAbstractSocket::HostNotFoundError:
4286 QMessageBox::information(NULL, vymName +" Network client",
4287 "The host was not found. Please check the "
4288 "host name and port settings.");
4290 case QAbstractSocket::ConnectionRefusedError:
4291 QMessageBox::information(NULL, vymName + " Network client",
4292 "The connection was refused by the peer. "
4293 "Make sure the fortune server is running, "
4294 "and check that the host name and port "
4295 "settings are correct.");
4298 QMessageBox::information(NULL, vymName + " Network client",
4299 QString("The following error occurred: %1.")
4300 .arg(clientSocket->errorString()));
4307 void VymModel::selectMapSelectionColor()
4309 QColor col = QColorDialog::getColor( defLinkColor, NULL);
4310 setSelectionColor (col);
4313 void VymModel::setSelectionColorInt (QColor col)
4315 if ( !col.isValid() ) return;
4317 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4318 QString("setSelectionColor (%1)").arg(col.name()),
4319 QString("Set color of selection box to %1").arg(col.name())
4322 mapEditor->setSelectionColor (col);
4325 void VymModel::updateSelection()
4330 void VymModel::setSelectionColor(QColor col)
4332 if ( !col.isValid() ) return;
4334 QString("setSelectionColor (%1)").arg(mapEditor->getSelectionColor().name()),
4335 QString("setSelectionColor (%1)").arg(col.name()),
4336 QString("Set color of selection box to %1").arg(col.name())
4338 setSelectionColorInt (col);
4341 QColor VymModel::getSelectionColor()
4343 return mapEditor->getSelectionColor();
4346 void VymModel::setHideTmpMode (HideTmpMode mode)
4349 for (int i=0;i<mapCenters.count(); i++)
4350 mapCenters.at(i)->setHideTmp (mode);
4352 // FIXME needed? scene()->update();
4356 QRectF VymModel::getTotalBBox()
4359 for (int i=0;i<mapCenters.count(); i++)
4360 r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
4364 //////////////////////////////////////////////
4365 // Selection related
4366 //////////////////////////////////////////////
4368 void VymModel::setSelectionModel (QItemSelectionModel *sm)
4371 cout << "VM::setSelModel selModel="<<selModel<<endl;
4374 QItemSelectionModel* VymModel::getSelectionModel()
4379 void VymModel::setSelectionBlocked (bool b)
4384 selection.unblock();
4387 bool VymModel::isSelectionBlocked()
4389 return selection.isBlocked();
4392 bool VymModel::select ()
4394 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
4396 TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
4397 return select (item->getLMO() );
4400 bool VymModel::select (const QString &s)
4402 if (selection.select(s))
4405 ensureSelectionVisible();
4413 bool VymModel::select (LinkableMapObj *lmo)
4415 if (selection.select(lmo))
4418 ensureSelectionVisible();
4425 void VymModel::unselect()
4427 selection.unselect();
4430 void VymModel::reselect()
4432 selection.reselect();
4435 void VymModel::ensureSelectionVisible()
4437 LinkableMapObj *lmo=selection.single();
4438 if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() );
4442 void VymModel::selectInt (LinkableMapObj *lmo)
4444 if (selection.select(lmo))
4446 //selection.update();
4447 sendSelection (); // FIXME VM use signal
4452 void VymModel::selectNextBranchInt()
4454 // Increase number of branch
4455 LinkableMapObj *sel=selection.single();
4458 QString s=selection.getSelectString();
4464 part=s.section(",",-1);
4466 num=part.right(part.length() - 3);
4468 s=s.left (s.length() -num.length());
4471 num=QString ("%1").arg(num.toUInt()+1);
4475 // Try to select this one
4476 if (select (s)) return;
4478 // We have no direct successor,
4479 // try to increase the parental number in order to
4480 // find a successor with same depth
4482 int d=selection.single()->getDepth();
4487 while (!found && d>0)
4489 s=s.section (",",0,d-1);
4490 // replace substring of current depth in s with "1"
4491 part=s.section(",",-1);
4493 num=part.right(part.length() - 3);
4497 // increase number of parent
4498 num=QString ("%1").arg(num.toUInt()+1);
4499 s=s.section (",",0,d-2) + ","+ typ+num;
4502 // Special case, look at orientation
4503 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4504 num=QString ("%1").arg(num.toUInt()+1);
4506 num=QString ("%1").arg(num.toUInt()-1);
4511 // pad to oldDepth, select the first branch for each depth
4512 for (i=d;i<oldDepth;i++)
4517 if ( selection.getBranch()->countBranches()>0)
4525 // try to select the freshly built string
4533 void VymModel::selectPrevBranchInt()
4535 // Decrease number of branch
4536 BranchObj *bo=selection.getBranch();
4539 QString s=selection.getSelectString();
4545 part=s.section(",",-1);
4547 num=part.right(part.length() - 3);
4549 s=s.left (s.length() -num.length());
4551 int n=num.toInt()-1;
4554 num=QString ("%1").arg(n);
4557 // Try to select this one
4558 if (n>=0 && select (s)) return;
4560 // We have no direct precessor,
4561 // try to decrease the parental number in order to
4562 // find a precessor with same depth
4564 int d=selection.single()->getDepth();
4569 while (!found && d>0)
4571 s=s.section (",",0,d-1);
4572 // replace substring of current depth in s with "1"
4573 part=s.section(",",-1);
4575 num=part.right(part.length() - 3);
4579 // decrease number of parent
4580 num=QString ("%1").arg(num.toInt()-1);
4581 s=s.section (",",0,d-2) + ","+ typ+num;
4584 // Special case, look at orientation
4585 if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter)
4586 num=QString ("%1").arg(num.toInt()-1);
4588 num=QString ("%1").arg(num.toInt()+1);
4593 // pad to oldDepth, select the last branch for each depth
4594 for (i=d;i<oldDepth;i++)
4598 if ( selection.getBranch()->countBranches()>0)
4599 s+=",bo:"+ QString ("%1").arg( selection.getBranch()->countBranches()-1 );
4606 // try to select the freshly built string
4614 void VymModel::selectUpperBranch()
4616 if (selection.isBlocked() ) return;
4618 BranchObj *bo=selection.getBranch();
4619 if (bo && selection.type()==Selection::Branch)
4621 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4622 selectPrevBranchInt();
4624 if (bo->getDepth()==1)
4625 selectNextBranchInt();
4627 selectPrevBranchInt();
4631 void VymModel::selectLowerBranch()
4633 if (selection.isBlocked() ) return;
4635 BranchObj *bo=selection.getBranch();
4636 if (bo && selection.type()==Selection::Branch)
4638 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4639 selectNextBranchInt();
4641 if (bo->getDepth()==1)
4642 selectPrevBranchInt();
4644 selectNextBranchInt();
4649 void VymModel::selectLeftBranch()
4651 if (selection.isBlocked() ) return;
4655 LinkableMapObj *sel=selection.single();
4658 if (selection.type()== Selection::MapCenter)
4660 par=selection.getBranch();
4661 bo=par->getLastSelectedBranch();
4664 // Workaround for reselecting on left and right side
4665 if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
4666 bo=par->getLastBranch();
4669 bo=par->getLastBranch();
4670 selection.select(bo);
4672 ensureSelectionVisible();
4678 par=(BranchObj*)(sel->getParObj());
4679 if (sel->getOrientation()==LinkableMapObj::RightOfCenter)
4681 if (selection.type() == Selection::Branch ||
4682 selection.type() == Selection::FloatImage)
4684 selection.select(par);
4686 ensureSelectionVisible();
4691 if (selection.type() == Selection::Branch )
4693 bo=selection.getBranch()->getLastSelectedBranch();
4696 selection.select(bo);
4698 ensureSelectionVisible();
4707 void VymModel::selectRightBranch()
4709 if (selection.isBlocked() ) return;
4713 LinkableMapObj *sel=selection.single();
4716 if (selection.type()==Selection::MapCenter)
4718 par=selection.getBranch();
4719 bo=par->getLastSelectedBranch();
4722 // Workaround for reselecting on left and right side
4723 if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
4724 bo=par->getFirstBranch();
4727 selection.select(bo);
4729 ensureSelectionVisible();
4735 par=(BranchObj*)(selection.single()->getParObj());
4736 if (selection.single()->getOrientation()==LinkableMapObj::LeftOfCenter)
4738 if (selection.type() == Selection::Branch ||
4739 selection.type() == Selection::FloatImage)
4741 selection.select(par);
4743 ensureSelectionVisible();
4748 if (selection.type() == Selection::Branch)
4750 bo=selection.getBranch()->getLastSelectedBranch();
4753 selection.select(bo);
4755 ensureSelectionVisible();
4764 void VymModel::selectFirstBranch()
4766 BranchObj *bo1=selection.getBranch();
4771 par=(BranchObj*)(bo1->getParObj());
4773 bo2=par->getFirstBranch();
4775 selection.select(bo2);
4777 ensureSelectionVisible();
4783 void VymModel::selectLastBranch()
4785 BranchObj *bo1=selection.getBranch();
4790 par=(BranchObj*)(bo1->getParObj());
4792 bo2=par->getLastBranch();
4795 selection.select(bo2);
4797 ensureSelectionVisible();
4803 void VymModel::selectParent()
4805 LinkableMapObj *lmo=selection.first();
4809 par=(BranchObj*)(lmo->getParObj());
4811 selection.select(par);
4813 ensureSelectionVisible();
4818 Selection::Type VymModel::selectionType()
4820 return selection.type();
4823 LinkableMapObj* VymModel::getSelection()
4825 return selection.single();
4827 BranchObj* VymModel::getSelectedBranch()
4829 return selection.getBranch();
4832 FloatImageObj* VymModel::getSelectedFloatImage()
4834 return selection.getFloatImage();
4837 QString VymModel::getSelectString ()
4839 return selection.getSelectString();
4842 QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME VM needs to use TreeModel
4846 if (typeid(*lmo)==typeid(BranchObj) ||
4847 typeid(*lmo)==typeid(MapCenterObj) )
4849 LinkableMapObj *par=lmo->getParObj();
4852 if (lmo->getDepth() ==1)
4853 // Mainbranch, return
4854 s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4857 //cout << "VM::getSelectString lmo="<<lmo<<" d="<<lmo->getDepth()<<" s="<<s.toStdString()<<" h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
4858 // Branch, call myself recursively
4859 s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
4864 int i=mapCenters.indexOf ((MapCenterObj*)lmo);
4865 if (i>=0) s=QString("mc:%1").arg(i);