# HG changeset patch # User insilmaril # Date 1216205084 0 # Node ID 192e1392ba6ada56dd1fac2b0eabb93e9ab42f17 # Parent 3f90aab4794dcb06db3b3bfd5c25171c9d01538a Started to restructure for later use of Model/View diff -r 3f90aab4794d -r 192e1392ba6a mapeditor.cpp --- a/mapeditor.cpp Mon Jul 14 11:25:09 2008 +0000 +++ b/mapeditor.cpp Wed Jul 16 10:44:44 2008 +0000 @@ -1,27 +1,16 @@ #include "mapeditor.h" -#include - #include #include #include -#include "parser.h" -#include "editxlinkdialog.h" -#include "exports.h" -#include "exportxhtmldialog.h" -#include "extrainfodialog.h" -#include "file.h" -#include "linkablemapobj.h" +#include + #include "mainwindow.h" #include "misc.h" -#include "texteditor.h" #include "warningdialog.h" -#include "xml-freemind.h" -#include "xml-vym.h" -extern TextEditor *textEditor; extern int statusbarTime; extern Main *mainWindow; extern QString tmpVymDir; @@ -40,48 +29,28 @@ extern QMenu* floatimageContextMenu; extern QMenu* canvasContextMenu; - extern Settings settings; -extern ImageIO imageIO; - -extern QString vymName; -extern QString vymVersion; - extern QString iconPath; -extern QDir vymBaseDir; -extern QDir lastImageDir; -extern QDir lastFileDir; - -int MapEditor::mapNum=0; // make instance /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// -MapEditor::MapEditor( QWidget* parent) : - QGraphicsView(parent) +MapEditor::MapEditor( VymModel *vm) { - setObjectName ("MapEditor"); - //cout << "Constructor ME "<setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern)); - model=new VymModel(); + model=vm; model->setScene (mapScene); model->setMapEditor (this); + model->registerEditor(this); + model->addMapCenter(); // FIXME create this in MapEditor until BO and MCO are independent of scene + model->makeDefault(); setScene (mapScene); printer=NULL; - defLinkColor=QColor (0,0,255); - defXLinkColor=QColor (180,180,180); - linkcolorhint=LinkableMapObj::DefaultColor; - linkstyle=LinkableMapObj::PolyParabel; - // Create bitmap cursors, platform dependant HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1); PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); @@ -97,58 +66,31 @@ editingBO=NULL; movingObj=NULL; - xelection.setModel (model); - xelection.unselect(); - - defXLinkWidth=1; - defXLinkColor=QColor (230,230,230); - - mapChanged=false; - mapDefault=true; - mapUnsaved=false; - - zipped=true; - filePath=""; - fileName=tr("unnamed"); - mapName=""; - - stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100); - undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal)); - mainWindow->updateHistory (undoSet); - - // Initialize find routine - itFind=NULL; - EOFind=false; - printFrame=true; printFooter=true; - blockReposition=false; - blockSaveState=false; - - hidemode=HideNone; - - // Create temporary files - makeTmpDirs(); - - curStep=0; - redosAvail=0; - undosAvail=0; - setAcceptDrops (true); - model->reposition(); + model->reposition(); //FIXME really still needed? - // autosave - autosaveTimer=new QTimer (this); - connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave())); - fileChangedTimer=new QTimer (this); - fileChangedTimer->start(3000); - connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged())); + // Action to embed LineEdit for heading in Scene + editingHeading=false; + lineEdit=new QLineEdit; + lineEdit->hide(); + QGraphicsProxyWidget *pw=scene()->addWidget (lineEdit); + pw->setZValue (100); - // Network - netstate=Offline; + QAction *a = new QAction( tr( "Edit heading","MapEditor" ), this); + a->setShortcut ( Qt::Key_Return ); //Edit heading + //a->setShortcutContext (Qt::WindowShortcut); + addAction (a); + connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) ); + a = new QAction( tr( "Edit heading","MapEditor" ), this); + a->setShortcut ( Qt::Key_Enter); //Edit heading + //a->setShortcutContext (Qt::WindowShortcut); + addAction (a); + connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) ); // Attributes //FIXME testing only... QString k; @@ -186,13 +128,10 @@ MapEditor::~MapEditor() { //cout <<"Destructor MapEditor\n"; - autosaveTimer->stop(); - fileChangedTimer->stop(); - // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes - //removeDir(QDir(tmpMapDir)); - delete (model); + //removeDir(QDir(tmpMapDir)); // FIXME check?!? + model->unregisterEditor(this); } VymModel* MapEditor::getModel() @@ -205,1650 +144,6 @@ return mapScene; } -MapEditor::State MapEditor::getState() -{ - return state; -} - -void MapEditor::setStateEditHeading(bool s) -{ - if (s) - { - if (state==Idle) state=EditHeading; - } - else - state=Idle; -} - -bool MapEditor::isRepositionBlocked() -{ - return blockReposition; -} - -void MapEditor::setSaveStateBlocked(bool b) -{ - blockSaveState=b; -} - -bool MapEditor::isSelectBlocked() -{ - if (state==EditHeading) - return true; - else - return false; -} - -QString MapEditor::getName (const LinkableMapObj *lmo) -{ - QString s; - if (!lmo) return QString("Error: NULL has no name!"); - - if ((typeid(*lmo) == typeid(BranchObj) || - typeid(*lmo) == typeid(MapCenterObj))) - { - - s=(((BranchObj*)lmo)->getHeading()); - if (s=="") s="unnamed"; - return QString("branch (%1)").arg(s); - } - if ((typeid(*lmo) == typeid(FloatImageObj) )) - return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); - return QString("Unknown type has no name!"); -} - -void MapEditor::makeTmpDirs() -{ - // Create unique temporary directories - tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum); - histPath = tmpMapDir+"/history"; - QDir d; - d.mkdir (tmpMapDir); -} - -QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel) -{ - // tmpdir temporary directory to which data will be written - // prefix mapname, which will be appended to images etc. - // writeflags Only write flags for "real" save of map, not undo - // offset offset of bbox of whole map in scene. - // Needed for XML export - - // Save Header - QString ls; - switch (linkstyle) - { - case LinkableMapObj::Line: - ls="StyleLine"; - break; - case LinkableMapObj::Parabel: - ls="StyleParabel"; - break; - case LinkableMapObj::PolyLine: - ls="StylePolyLine"; - break; - default: - ls="StylePolyParabel"; - break; - } - - QString s="\n"; - QString colhint=""; - if (linkcolorhint==LinkableMapObj::HeadingColor) - colhint=attribut("linkColorHint","HeadingColor"); - - QString mapAttr=attribut("version",vymVersion); - if (!saveSel) - mapAttr+= attribut("author",model->getAuthor()) + - attribut("comment",model->getComment()) + - attribut("date",model->getDate()) + - attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + - attribut("selectionColor", xelection.getColor().name() ) + - attribut("linkStyle", ls ) + - attribut("linkColor", defLinkColor.name() ) + - attribut("defXLinkColor", defXLinkColor.name() ) + - attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) + - colhint; - s+=beginElement("vymmap",mapAttr); - incIndent(); - - // Find the used flags while traversing the tree - standardFlagsDefault->resetUsedCounter(); - - // Reset the counters before saving - // TODO constr. of FIO creates lots of objects, better do this in some other way... - FloatImageObj (mapScene).resetSaveCounter(); - - // Build xml recursivly - if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj)) - // Save complete map, if saveSel not set - s+=model->saveToDir(tmpdir,prefix,writeflags,offset); - else - { - if ( typeid(*saveSel) == typeid(BranchObj) ) - // Save Subtree - s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); - else if ( typeid(*saveSel) == typeid(FloatImageObj) ) - // Save image - s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix); - } - - // Save local settings - s+=settings.getDataXML (destPath); - - // Save selection - if (!xelection.isEmpty() && !saveSel ) - s+=valueElement("select",xelection.getSelectString()); - - decIndent(); - s+=endElement("vymmap"); - - if (writeflags) - standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags); - return s; -} - -QString MapEditor::getHistoryDir() -{ - QString histName(QString("history-%1").arg(curStep)); - return (tmpMapDir+"/"+histName); -} - -void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) -{ - sendData(redoCom); //FIXME testing - - // Main saveState - - - if (blockSaveState) return; - - if (debug) cout << "ME::saveState() for "<stepsTotal) curStep=1; - - QString backupXML=""; - QString histDir=getHistoryDir(); - QString bakMapPath=histDir+"/map.xml"; - - // Create histDir if not available - QDir d(histDir); - if (!d.exists()) - makeSubDirs (histDir); - - // Save depending on how much needs to be saved - if (saveSel) - backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel); - - QString undoCommand=""; - if (savemode==UndoCommand) - { - undoCommand=undoCom; - } - else if (savemode==PartOfMap ) - { - undoCommand=undoCom; - undoCommand.replace ("PATH",bakMapPath); - } - - if (!backupXML.isEmpty()) - // Write XML Data to disk - saveStringToDisk (bakMapPath,backupXML); - - // We would have to save all actions in a tree, to keep track of - // possible redos after a action. Possible, but we are too lazy: forget about redos. - redosAvail=0; - - // Write the current state to disk - undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); - undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); - undoSet.setEntry ("/history/curStep",QString::number(curStep)); - undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand); - undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection); - undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom); - undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection); - undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment); - undoSet.setEntry (QString("/history/version"),vymVersion); - undoSet.writeSettings(histPath); - - if (debug) - { - // TODO remove after testing - //cout << " into="<< histPath.toStdString()<updateHistory (undoSet); - setChanged(); - updateActions(); -} - - -void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment) -{ - // save the selected part of the map, Undo will replace part of map - QString undoSelection=""; - if (undoSel) - undoSelection=model->getSelectString(undoSel); - else - qWarning ("MapEditor::saveStateChangingPart no undoSel given!"); - QString redoSelection=""; - if (redoSel) - redoSelection=model->getSelectString(undoSel); - else - qWarning ("MapEditor::saveStateChangingPart no redoSel given!"); - - - saveState (PartOfMap, - undoSelection, "addMapReplace (\"PATH\")", - redoSelection, rc, - comment, - undoSel); -} - -void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment) -{ - if (!redoSel) - { - qWarning ("MapEditor::saveStateRemovingPart no redoSel given!"); - return; - } - QString undoSelection=model->getSelectString (redoSel->getParObj()); - QString redoSelection=model->getSelectString(redoSel); - if (typeid(*redoSel) == typeid(BranchObj) ) - { - // save the selected branch of the map, Undo will insert part of map - saveState (PartOfMap, - undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), - redoSelection, "delete ()", - comment, - redoSel); - } -} - - -void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) -{ - // "Normal" savestate: save commands, selections and comment - // so just save commands for undo and redo - // and use current selection - - QString redoSelection=""; - if (redoSel) redoSelection=model->getSelectString(redoSel); - QString undoSelection=""; - if (undoSel) undoSelection=model->getSelectString(undoSel); - - saveState (UndoCommand, - undoSelection, uc, - redoSelection, rc, - comment, - NULL); -} - -void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) -{ - // "Normal" savestate: save commands, selections and comment - // so just save commands for undo and redo - // and use current selection - saveState (UndoCommand, - undoSel, uc, - redoSel, rc, - comment, - NULL); -} - -void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment) -{ - // "Normal" savestate applied to model (no selection needed): - // save commands and comment - saveState (UndoCommand, - NULL, uc, - NULL, rc, - comment, - NULL); -} - - -void MapEditor::parseAtom(const QString &atom) -{ - BranchObj *selb=xelection.getBranch(); - QString s,t; - double x,y; - int n; - bool b,ok; - - // Split string s into command and parameters - parser.parseAtom (atom); - QString com=parser.getCommand(); - - // External commands - ///////////////////////////////////////////////////////////////////// - if (com=="addBranch") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else - { - QList pl; - pl << 0 <<1; - if (parser.checkParCount(pl)) - { - if (parser.parCount()==0) - addNewBranch (0); - else - { - n=parser.parInt (ok,0); - if (ok ) addNewBranch (n); - } - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="addBranchBefore") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else - { - if (parser.parCount()==0) - { - addNewBranchBefore (); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com==QString("addMapCenter")) - { - if (parser.checkParCount(2)) - { - x=parser.parDouble (ok,0); - if (ok) - { - y=parser.parDouble (ok,1); - if (ok) model->addMapCenter (QPointF(x,y)); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com==QString("addMapReplace")) - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - //s=parser.parString (ok,0); // selection - t=parser.parString (ok,0); // path to map - if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); - addMapReplaceInt(model->getSelectString(selb),t); - } - ///////////////////////////////////////////////////////////////////// - } else if (com==QString("addMapInsert")) - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else - { - if (parser.checkParCount(2)) - { - t=parser.parString (ok,0); // path to map - n=parser.parInt(ok,1); // position - if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); - addMapInsertInt(t,n); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="clearFlags") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - selb->clearStandardFlags(); - selb->updateFlagsToolbar(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="colorBranch") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - QColor c=parser.parColor (ok,0); - if (ok) colorBranch (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="colorSubtree") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - QColor c=parser.parColor (ok,0); - if (ok) colorSubtree (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="copy") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - //FIXME missing action for copy - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="cut") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if ( xelection.type()!=Selection::Branch && - xelection.type()!=Selection::MapCenter && - xelection.type()!=Selection::FloatImage ) - { - parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParCount(0)) - { - cut(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="delete") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } - /*else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage ) - { - parser.setError (Aborted,"Type of selection is wrong."); - } - */ - else if (parser.checkParCount(0)) - { - deleteSelection(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="deleteKeepChilds") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - deleteKeepChilds(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="deleteChilds") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - deleteChilds(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="exportASCII") - { - QString fname=""; - ok=true; - if (parser.parCount()>=1) - // Hey, we even have a filename - fname=parser.parString(ok,0); - if (!ok) - { - parser.setError (Aborted,"Could not read filename"); - } else - { - exportASCII (fname,false); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="exportImage") - { - QString fname=""; - ok=true; - if (parser.parCount()>=2) - // Hey, we even have a filename - fname=parser.parString(ok,0); - if (!ok) - { - parser.setError (Aborted,"Could not read filename"); - } else - { - QString format="PNG"; - if (parser.parCount()>=2) - { - format=parser.parString(ok,1); - } - exportImage (fname,false,format); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="exportXHTML") - { - QString fname=""; - ok=true; - if (parser.parCount()>=2) - // Hey, we even have a filename - fname=parser.parString(ok,1); - if (!ok) - { - parser.setError (Aborted,"Could not read filename"); - } else - { - exportXHTML (fname,false); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="exportXML") - { - QString fname=""; - ok=true; - if (parser.parCount()>=2) - // Hey, we even have a filename - fname=parser.parString(ok,1); - if (!ok) - { - parser.setError (Aborted,"Could not read filename"); - } else - { - exportXML (fname,false); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="importDir") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) importDirInt(s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="linkTo") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if ( selb) - { - if (parser.checkParCount(4)) - { - // 0 selectstring of parent - // 1 num in parent (for branches) - // 2,3 x,y of mainbranch or mapcenter - s=parser.parString(ok,0); - LinkableMapObj *dst=model->findObjBySelect (s); - if (dst) - { - if (typeid(*dst) == typeid(BranchObj) ) - { - // Get number in parent - n=parser.parInt (ok,1); - if (ok) - { - selb->linkTo ((BranchObj*)(dst),n); - xelection.update(); - } - } else if (typeid(*dst) == typeid(MapCenterObj) ) - { - selb->linkTo ((BranchObj*)(dst),-1); - // Get coordinates of mainbranch - x=parser.parDouble(ok,2); - if (ok) - { - y=parser.parDouble(ok,3); - if (ok) - { - selb->move (x,y); - xelection.update(); - } - } - } - } - } - } else if ( xelection.type() == Selection::FloatImage) - { - if (parser.checkParCount(1)) - { - // 0 selectstring of parent - s=parser.parString(ok,0); - LinkableMapObj *dst=model->findObjBySelect (s); - if (dst) - { - if (typeid(*dst) == typeid(BranchObj) || - typeid(*dst) == typeid(MapCenterObj)) - linkTo (model->getSelectString(dst)); - } else - parser.setError (Aborted,"Destination is not a branch"); - } - } else - parser.setError (Aborted,"Type of selection is not a floatimage or branch"); - ///////////////////////////////////////////////////////////////////// - } else if (com=="loadImage") - { - if (xelection.isEmpty()) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) loadFloatImageInt (s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="moveBranchUp") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - moveBranchUp(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="moveBranchDown") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - moveBranchDown(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="move") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if ( xelection.type()!=Selection::Branch && - xelection.type()!=Selection::MapCenter && - xelection.type()!=Selection::FloatImage ) - { - parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParCount(2)) - { - x=parser.parDouble (ok,0); - if (ok) - { - y=parser.parDouble (ok,1); - if (ok) move (x,y); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="moveRel") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if ( xelection.type()!=Selection::Branch && - xelection.type()!=Selection::MapCenter && - xelection.type()!=Selection::FloatImage ) - { - parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParCount(2)) - { - x=parser.parDouble (ok,0); - if (ok) - { - y=parser.parDouble (ok,1); - if (ok) moveRel (x,y); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="nop") - { - ///////////////////////////////////////////////////////////////////// - } else if (com=="paste") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - n=parser.parInt (ok,0); - if (ok) pasteNoSave(n); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="qa") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(4)) - { - QString c,u; - c=parser.parString (ok,0); - if (!ok) - { - parser.setError (Aborted,"No comment given"); - } else - { - s=parser.parString (ok,1); - if (!ok) - { - parser.setError (Aborted,"First parameter is not a string"); - } else - { - t=parser.parString (ok,2); - if (!ok) - { - parser.setError (Aborted,"Condition is not a string"); - } else - { - u=parser.parString (ok,3); - if (!ok) - { - parser.setError (Aborted,"Third parameter is not a string"); - } else - { - if (s!="heading") - { - parser.setError (Aborted,"Unknown type: "+s); - } else - { - if (! (t=="eq") ) - { - parser.setError (Aborted,"Unknown operator: "+t); - } else - { - if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else - { - if (selb->getHeading() == u) - { - cout << "PASSED: " << qPrintable (c) << endl; - } else - { - cout << "FAILED: " << qPrintable (c) << endl; - } - } - } - } - } - } - } - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="saveImage") - { - FloatImageObj *fio=xelection.getFloatImage(); - if (!fio) - { - parser.setError (Aborted,"Type of selection is not an image"); - } else if (parser.checkParCount(2)) - { - s=parser.parString(ok,0); - if (ok) - { - t=parser.parString(ok,1); - if (ok) saveFloatImageInt (fio,t,s); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="scroll") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - if (!scrollBranch (selb)) - parser.setError (Aborted,"Could not scroll branch"); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="select") - { - if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) select (s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="selectLastBranch") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - BranchObj *bo=selb->getLastBranch(); - if (!bo) - parser.setError (Aborted,"Could not select last branch"); - selectInt (bo); - - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="selectLastImage") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - FloatImageObj *fio=selb->getLastFloatImage(); - if (!fio) - parser.setError (Aborted,"Could not select last image"); - selectInt (fio); - - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="selectLatestAdded") - { - if (latestSelection.isEmpty() ) - { - parser.setError (Aborted,"No latest added object"); - } else - { - if (!select (latestSelection)) - parser.setError (Aborted,"Could not select latest added object "+latestSelection); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setFrameType") - { - if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) - { - parser.setError (Aborted,"Type of selection does not allow setting frame type"); - } - else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) setFrameType (s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setFramePenColor") - { - if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) - { - parser.setError (Aborted,"Type of selection does not allow setting of pen color"); - } - else if (parser.checkParCount(1)) - { - QColor c=parser.parColor(ok,0); - if (ok) setFramePenColor (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setFrameBrushColor") - { - if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) - { - parser.setError (Aborted,"Type of selection does not allow setting brush color"); - } - else if (parser.checkParCount(1)) - { - QColor c=parser.parColor(ok,0); - if (ok) setFrameBrushColor (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setFramePadding") - { - if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) - { - parser.setError (Aborted,"Type of selection does not allow setting frame padding"); - } - else if (parser.checkParCount(1)) - { - n=parser.parInt(ok,0); - if (ok) setFramePadding(n); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setFrameBorderWidth") - { - if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) - { - parser.setError (Aborted,"Type of selection does not allow setting frame border width"); - } - else if (parser.checkParCount(1)) - { - n=parser.parInt(ok,0); - if (ok) setFrameBorderWidth (n); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapAuthor") - { - if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) setMapAuthor (s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapComment") - { - if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) setMapComment(s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapBackgroundColor") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! xelection.getBranch() ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - QColor c=parser.parColor (ok,0); - if (ok) setMapBackgroundColor (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapDefLinkColor") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - QColor c=parser.parColor (ok,0); - if (ok) setMapDefLinkColor (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setMapLinkStyle") - { - if (parser.checkParCount(1)) - { - s=parser.parString (ok,0); - if (ok) setMapLinkStyle(s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setHeading") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString (ok,0); - if (ok) - setHeading (s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setHideExport") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage) - { - parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (parser.checkParCount(1)) - { - b=parser.parBool(ok,0); - if (ok) setHideExport (b); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setIncludeImagesHorizontally") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - b=parser.parBool(ok,0); - if (ok) setIncludeImagesHor(b); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setIncludeImagesVertically") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - b=parser.parBool(ok,0); - if (ok) setIncludeImagesVer(b); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setHideLinkUnselected") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) - { - parser.setError (Aborted,"Type of selection does not allow hiding the link"); - } else if (parser.checkParCount(1)) - { - b=parser.parBool(ok,0); - if (ok) setHideLinkUnselected(b); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setSelectionColor") - { - if (parser.checkParCount(1)) - { - QColor c=parser.parColor (ok,0); - if (ok) setSelectionColorInt (c); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setURL") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString (ok,0); - if (ok) setURL(s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setVymLink") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString (ok,0); - if (ok) setVymLinkInt(s); - } - } - ///////////////////////////////////////////////////////////////////// - else if (com=="setFlag") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) - { - selb->activateStandardFlag(s); - selb->updateFlagsToolbar(); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="setFrameType") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) - setFrameType (s); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="sortChildren") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - sortChildren(); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="toggleFlag") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) - { - selb->toggleStandardFlag(s); - selb->updateFlagsToolbar(); - } - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="unscroll") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - if (!unscrollBranch (selb)) - parser.setError (Aborted,"Could not unscroll branch"); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="unscrollChilds") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(0)) - { - unscrollChilds (); - } - ///////////////////////////////////////////////////////////////////// - } else if (com=="unsetFlag") - { - if (xelection.isEmpty() ) - { - parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) - { - parser.setError (Aborted,"Type of selection is not a branch"); - } else if (parser.checkParCount(1)) - { - s=parser.parString(ok,0); - if (ok) - { - selb->deactivateStandardFlag(s); - selb->updateFlagsToolbar(); - } - } - } else - parser.setError (Aborted,"Unknown command"); - - // Any errors? - if (parser.errorLevel()==NoError) - { - // setChanged(); FIXME should not be called e.g. for export?! - model->reposition(); - } - else - { - // TODO Error handling - qWarning("MapEditor::parseAtom: Error!"); - qWarning(parser.errorMessage()); - } -} - -void MapEditor::runScript (QString script) -{ - parser.setScript (script); - parser.runScript(); - while (parser.next() ) - parseAtom(parser.getAtom()); -} - -bool MapEditor::isDefault() -{ - return mapDefault; -} - -bool MapEditor::hasChanged() -{ - return mapChanged; -} - -void MapEditor::setChanged() -{ - if (!mapChanged) - autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt()); - mapChanged=true; - mapDefault=false; - mapUnsaved=true; - findReset(); - -} - -void MapEditor::closeMap() -{ - // Unselect before disabling the toolbar actions - if (!xelection.isEmpty() ) xelection.unselect(); - xelection.clear(); - updateActions(); - - clear(); - // close(); FIXME needed? -} - -void MapEditor::setFilePath(QString fpath, QString destname) -{ - if (fpath.isEmpty() || fpath=="") - { - filePath=""; - fileName=""; - destPath=""; - } else - { - filePath=fpath; // becomes absolute path - fileName=fpath; // gets stripped of path - destPath=destname; // needed for vymlinks and during load to reset fileChangedTime - - // If fpath is not an absolute path, complete it - filePath=QDir(fpath).absPath(); - fileDir=filePath.left (1+filePath.findRev ("/")); - - // Set short name, too. Search from behind: - int i=fileName.findRev("/"); - if (i>=0) fileName=fileName.remove (0,i+1); - - // Forget the .vym (or .xml) for name of map - mapName=fileName.left(fileName.findRev(".",-1,true) ); - } -} - -void MapEditor::setFilePath(QString fpath) -{ - setFilePath (fpath,fpath); -} - -QString MapEditor::getFilePath() -{ - return filePath; -} - -QString MapEditor::getFileName() -{ - return fileName; -} - -QString MapEditor::getMapName() -{ - return mapName; -} - -QString MapEditor::getDestPath() -{ - return destPath; -} - -ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype) -{ - ErrorCode err=success; - - parseBaseHandler *handler; - fileType=ftype; - switch (fileType) - { - case VymMap: handler=new parseVYMHandler; break; - case FreemindMap : handler=new parseFreemindHandler; break; - default: - QMessageBox::critical( 0, tr( "Critical Parse Error" ), - "Unknown FileType in MapEditor::load()"); - return aborted; - } - if (lmode==NewMap) - { - xelection.clear(); - model->setMapEditor(this); - // (map state is set later at end of load...) - } else - { - BranchObj *bo=xelection.getBranch(); - if (!bo) return aborted; - if (lmode==ImportAdd) - saveStateChangingPart( - bo, - bo, - QString("addMapInsert (%1)").arg(fname), - QString("Add map %1 to %2").arg(fname).arg(getName(bo))); - else - saveStateChangingPart( - bo, - bo, - QString("addMapReplace(%1)").arg(fname), - QString("Add map %1 to %2").arg(fname).arg(getName(bo))); - } - - - // Create temporary directory for packing - bool ok; - QString tmpZipDir=makeTmpDir (ok,"vym-pack"); - if (!ok) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't create temporary directory before load\n")); - return aborted; - } - - // Try to unzip file - err=unzipDir (tmpZipDir,fname); - QString xmlfile; - if (err==nozip) - { - xmlfile=fname; - zipped=false; - } else - { - zipped=true; - - // Look for mapname.xml - xmlfile= fname.left(fname.findRev(".",-1,true)); - xmlfile=xmlfile.section( '/', -1 ); - QFile mfile( tmpZipDir + "/" + xmlfile + ".xml"); - if (!mfile.exists() ) - { - // mapname.xml does not exist, well, - // maybe someone renamed the mapname.vym file... - // Try to find any .xml in the toplevel - // directory of the .vym file - QStringList flist=QDir (tmpZipDir).entryList("*.xml"); - if (flist.count()==1) - { - // Only one entry, take this one - xmlfile=tmpZipDir + "/"+flist.first(); - } else - { - for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) - *it=tmpZipDir + "/" + *it; - // TODO Multiple entries, load all (but only the first one into this ME) - //mainWindow->fileLoadFromTmp (flist); - //returnCode=1; // Silently forget this attempt to load - qWarning ("MainWindow::load (fn) multimap found..."); - } - - if (flist.isEmpty() ) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't find a map (*.xml) in .vym archive.\n")); - err=aborted; - } - } //file doesn't exist - else - xmlfile=mfile.name(); - } - - QFile file( xmlfile); - - // I am paranoid: file should exist anyway - // according to check in mainwindow. - if (!file.exists() ) - { - QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr(QString("Couldn't open map %1").arg(file.name()))); - err=aborted; - } else - { - bool blockSaveStateOrg=blockSaveState; - blockReposition=true; - blockSaveState=true; - QXmlInputSource source( file); - QXmlSimpleReader reader; - reader.setContentHandler( handler ); - reader.setErrorHandler( handler ); - handler->setModel ( model); - - - // We need to set the tmpDir in order to load files with rel. path - QString tmpdir; - if (zipped) - tmpdir=tmpZipDir; - else - tmpdir=fname.left(fname.findRev("/",-1)); - handler->setTmpDir (tmpdir); - handler->setInputFile (file.name()); - handler->setLoadMode (lmode); - bool ok = reader.parse( source ); - blockReposition=false; - blockSaveState=blockSaveStateOrg; - file.close(); - if ( ok ) - { - model->reposition(); // FIXME reposition the view instead... - xelection.update(); - if (lmode==NewMap) - { - mapDefault=false; - mapChanged=false; - mapUnsaved=false; - autosaveTimer->stop(); - } - - // Reset timestamp to check for later updates of file - fileChangedTime=QFileInfo (destPath).lastModified(); - } else - { - QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr( handler->errorProtocol() ) ); - // returnCode=1; - // Still return "success": the map maybe at least - // partially read by the parser - } - } - - // Delete tmpZipDir - removeDir (QDir(tmpZipDir)); - - updateActions(); - - return err; -} - -ErrorCode MapEditor::save (const SaveMode &savemode) -{ - QString tmpZipDir; - QString mapFileName; - QString safeFilePath; - - ErrorCode err=success; - - if (zipped) - // save as .xml - mapFileName=mapName+".xml"; - else - // use name given by user, even if he chooses .doc - mapFileName=fileName; - - // Look, if we should zip the data: - if (!zipped) - { - QMessageBox mb( vymName, - tr("The map %1\ndid not use the compressed " - "vym file format.\nWriting it uncompressed will also write images \n" - "and flags and thus may overwrite files in the " - "given directory\n\nDo you want to write the map").arg(filePath), - QMessageBox::Warning, - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No , - QMessageBox::Cancel | QMessageBox::Escape); - mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); - mb.setButtonText( QMessageBox::No, tr("uncompressed") ); - mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); - switch( mb.exec() ) - { - case QMessageBox::Yes: - // save compressed (default file format) - zipped=true; - break; - case QMessageBox::No: - // save uncompressed - zipped=false; - break; - case QMessageBox::Cancel: - // do nothing - return aborted; - break; - } - } - - // First backup existing file, we - // don't want to add to old zip archives - QFile f(destPath); - if (f.exists()) - { - if ( settings.value ("/mapeditor/writeBackupFile").toBool()) - { - QString backupFileName(destPath + "~"); - QFile backupFile(backupFileName); - if (backupFile.exists() && !backupFile.remove()) - { - QMessageBox::warning(0, tr("Save Error"), - tr("%1\ncould not be removed before saving").arg(backupFileName)); - } - else if (!f.rename(backupFileName)) - { - QMessageBox::warning(0, tr("Save Error"), - tr("%1\ncould not be renamed before saving").arg(destPath)); - } - } - } - - if (zipped) - { - // Create temporary directory for packing - bool ok; - tmpZipDir=makeTmpDir (ok,"vym-zip"); - if (!ok) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't create temporary directory before save\n")); - return aborted; - } - - safeFilePath=filePath; - setFilePath (tmpZipDir+"/"+ mapName+ ".xml", safeFilePath); - } // zipped - - // Create mapName and fileDir - makeSubDirs (fileDir); - - QString saveFile; - if (savemode==CompleteMap || xelection.isEmpty()) - { - // Save complete map - saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); - mapChanged=false; - mapUnsaved=false; - autosaveTimer->stop(); - } - else - { - // Save part of map - if (xelection.type()==Selection::FloatImage) - saveFloatImage(); - else - saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); - // TODO take care of multiselections - } - - if (!saveStringToDisk(fileDir+mapFileName,saveFile)) - { - err=aborted; - qWarning ("ME::saveStringToDisk failed!"); - } - - if (zipped) - { - // zip - if (err==success) err=zipDir (tmpZipDir,destPath); - - // Delete tmpDir - removeDir (QDir(tmpZipDir)); - - // Restore original filepath outside of tmp zip dir - setFilePath (safeFilePath); - } - - updateActions(); - fileChangedTime=QFileInfo (destPath).lastModified(); - return err; -} - - void MapEditor::print() { if ( !printer ) @@ -1882,7 +177,7 @@ pp.setRenderHint(QPainter::Antialiasing,true); // Don't print the visualisation of selection - xelection.unselect(); + model->unselect(); QRectF mapRect=totalBBox; QGraphicsRectItem *frame=NULL; @@ -1920,7 +215,7 @@ font.setPointSize(10); pp.setFont (font); QRectF footerBox(0,viewBottom,printer->width(),15); - pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName); + // FIXME fileName not any longer available here: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName); pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate)); } mapScene->render ( @@ -1933,7 +228,7 @@ if (frame) delete (frame); // Restore selection - xelection.reselect(); + model->reselect(); // Save settings in vymrc settings.writeEntry("/mainwindow/printerName",printer->printerName()); @@ -1952,1418 +247,9 @@ setRenderHint(QPainter::SmoothPixmapTransform,b); } -QPixmap MapEditor::getPixmap() -{ - QRectF mapRect=model->getTotalBBox(); - QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1); - QPainter pp (&pix); - - pp.setRenderHints(renderHints()); - - // Don't print the visualisation of selection - xelection.unselect(); - - mapScene->render ( &pp, - QRectF(0,0,mapRect.width()+2,mapRect.height()+2), - QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() )); - - // Restore selection - xelection.reselect(); - - return pix; -} - -void MapEditor::setHideTmpMode (HideTmpMode mode) -{ - hidemode=mode; - model->setHideTmp (hidemode); - model->reposition(); - scene()->update(); -} - -HideTmpMode MapEditor::getHideTmpMode() -{ - return hidemode; -} - -void MapEditor::setExportMode (bool b) -{ - // should be called before and after exports - // depending on the settings - if (b && settings.value("/export/useHideExport","true")=="true") - setHideTmpMode (HideExport); - else - setHideTmpMode (HideNone); -} - -void MapEditor::exportASCII(QString fname,bool askName) -{ - ExportASCII ex; - ex.setModel (model); - if (fname=="") - ex.setFile (mapName+".txt"); - else - ex.setFile (fname); - - if (askName) - { - //ex.addFilter ("TXT (*.txt)"); - ex.setDir(lastImageDir); - //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)")); - ex.execDialog() ; - } - if (!ex.canceled()) - { - setExportMode(true); - ex.doExport(); - setExportMode(false); - } -} - -void MapEditor::exportImage(QString fname, bool askName, QString format) -{ - if (fname=="") - { - fname=mapName+".png"; - format="PNG"; - } - - if (askName) - { - QStringList fl; - QFileDialog *fd=new QFileDialog (this); - fd->setCaption (tr("Export map as image")); - fd->setDirectory (lastImageDir); - fd->setFileMode(QFileDialog::AnyFile); - fd->setFilters (imageIO.getFilters() ); - if (fd->exec()) - { - fl=fd->selectedFiles(); - fname=fl.first(); - format=imageIO.getType(fd->selectedFilter()); - } - } - - setExportMode (true); - QPixmap pix (getPixmap()); - pix.save(fname, format); - setExportMode (false); -} - -void MapEditor::exportOOPresentation(const QString &fn, const QString &cf) -{ - ExportOO ex; - ex.setFile (fn); - ex.setModel (model); - if (ex.setConfigFile(cf)) - { - setExportMode (true); - ex.exportPresentation(); - setExportMode (false); - } -} - -void MapEditor::exportXHTML (const QString &dir, bool askForName) -{ - ExportXHTMLDialog dia(this); - dia.setFilePath (filePath ); - dia.setMapName (mapName ); - dia.readSettings(); - if (dir!="") dia.setDir (dir); - - bool ok=true; - - if (askForName) - { - if (dia.exec()!=QDialog::Accepted) - ok=false; - else - { - QDir d (dia.getDir()); - // Check, if warnings should be used before overwriting - // the output directory - if (d.exists() && d.count()>0) - { - WarningDialog warn; - warn.showCancelButton (true); - warn.setText(QString( - "The directory %1 is not empty.\n" - "Do you risk to overwrite some of its contents?").arg(d.path() )); - warn.setCaption("Warning: Directory not empty"); - warn.setShowAgainName("mainwindow/overwrite-dir-xhtml"); - - if (warn.exec()!=QDialog::Accepted) ok=false; - } - } - } - - if (ok) - { - exportXML (dia.getDir(),false ); - dia.doExport(mapName ); - //if (dia.hasChanged()) setChanged(); - } -} - -void MapEditor::exportXML(QString dir, bool askForName) -{ - if (askForName) - { - dir=browseDirectory(this,tr("Export XML to directory")); - if (dir =="" && !reallyWriteDirectory(dir) ) - return; - } - - // Hide stuff during export, if settings want this - setExportMode (true); - - // Create subdirectories - makeSubDirs (dir); - - // write to directory - QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL); - QFile file; - - file.setName ( dir + "/"+mapName+".xml"); - if ( !file.open( QIODevice::WriteOnly ) ) - { - // This should neverever happen - QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name())); - return; - } - - // Write it finally, and write in UTF8, no matter what - QTextStream ts( &file ); - ts.setEncoding (QTextStream::UnicodeUTF8); - ts << saveFile; - file.close(); - - // Now write image, too - exportImage (dir+"/images/"+mapName+".png",false,"PNG"); - - setExportMode (false); -} - -void MapEditor::clear() -{ - xelection.unselect(); - model->clear(); -} - -void MapEditor::copy() -{ - LinkableMapObj *sel=xelection.single(); - if (sel) - { - if (redosAvail == 0) - { - // Copy to history - QString s=model->getSelectString(sel); - saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel ); - curClipboard=curStep; - } - - // Copy also to global clipboard, because we are at last step in history - QString bakMapName(QString("history-%1").arg(curStep)); - QString bakMapDir(tmpMapDir +"/"+bakMapName); - copyDir (bakMapDir,clipboardDir ); - - clipboardEmpty=false; - updateActions(); - } -} - -void MapEditor::redo() -{ - // Can we undo at all? - if (redosAvail<1) return; - - bool blockSaveStateOrg=blockSaveState; - blockSaveState=true; - - redosAvail--; - - if (undosAvailstepsTotal) curStep=1; - QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); - QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); - QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); - QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); - QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); - QString version=undoSet.readEntry ("/history/version"); - - /* TODO Maybe check for version, if we save the history - if (!checkVersion(version)) - QMessageBox::warning(0,tr("Warning"), - tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); - */ - - // Find out current undo directory - QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); - - if (debug) - { - cout << "ME::redo() begin\n"; - cout << " undosAvail="<reposition(); - - blockSaveState=blockSaveStateOrg; - - undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); - undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); - undoSet.setEntry ("/history/curStep",QString::number(curStep)); - undoSet.writeSettings(histPath); - - mainWindow->updateHistory (undoSet); - updateActions(); - - /* TODO remove testing - cout << "ME::redo() end\n"; - cout << " undosAvail="<0) - return true; - else - return false; -} - -void MapEditor::undo() -{ - // Can we undo at all? - if (undosAvail<1) return; - - mainWindow->statusMessage (tr("Autosave disabled during undo.")); - - bool blockSaveStateOrg=blockSaveState; - blockSaveState=true; - - QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); - QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); - QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); - QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); - QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); - QString version=undoSet.readEntry ("/history/version"); - - /* TODO Maybe check for version, if we save the history - if (!checkVersion(version)) - QMessageBox::warning(0,tr("Warning"), - tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); - */ - - // Find out current undo directory - QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); - - // select object before undo - if (!undoSelection.isEmpty()) - select (undoSelection); - - if (debug) - { - cout << "ME::undo() begin\n"; - cout << " undosAvail="<reposition(); - - undosAvail--; - curStep--; - if (curStep<1) curStep=stepsTotal; - - redosAvail++; - - blockSaveState=blockSaveStateOrg; -/* TODO remove testing - cout << "ME::undo() end\n"; - cout << " undosAvail="<updateHistory (undoSet); - updateActions(); - xelection.update(); - ensureSelectionVisible(); -} - -bool MapEditor::isUndoAvailable() -{ - if (undoSet.readNumEntry("/history/undosAvail",0)>0) - return true; - else - return false; -} - -void MapEditor::gotoHistoryStep (int i) -{ - // Restore variables - int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); - int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); - - if (i<0) i=undosAvail+redosAvail; - - // Clicking above current step makes us undo things - if (iundosAvail) - for (int j=undosAvail; jclear(); - handler.setLoadMode (NewMap); - } else - { - select (undoSel); - handler.setLoadMode (ImportReplace); - } - blockReposition=true; - bool ok = reader.parse( source ); - blockReposition=false; - if (! ok ) - { - // This should never ever happen - QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), - handler.errorProtocol()); - } - } else - QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); -} - -void MapEditor::addMapInsertInt (const QString &path, int pos) -{ - BranchObj *sel=xelection.getBranch(); - if (sel) - { - QString pathDir=path.left(path.findRev("/")); - QDir d(pathDir); - QFile file (path); - - if (d.exists() ) - { - // We need to parse saved XML data - parseVYMHandler handler; - QXmlInputSource source( file); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setModel (model); - handler.setTmpDir ( pathDir ); // needed to load files with rel. path - handler.setLoadMode (ImportAdd); - blockReposition=true; - bool ok = reader.parse( source ); - blockReposition=false; - if (! ok ) - { - // This should never ever happen - QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), - handler.errorProtocol()); - } - if (sel->getDepth()>0) - sel->getLastBranch()->linkTo (sel,pos); - } else - QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); - } -} - -void MapEditor::pasteNoSave(const int &n) -{ - bool old=blockSaveState; - blockSaveState=true; - bool zippedOrg=zipped; - if (redosAvail > 0 || n!=0) - { - // Use the "historical" buffer - QString bakMapName(QString("history-%1").arg(n)); - QString bakMapDir(tmpMapDir +"/"+bakMapName); - load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap); - } else - // Use the global buffer - load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap); - zipped=zippedOrg; - blockSaveState=old; -} - -void MapEditor::paste() -{ - BranchObj *sel=xelection.getBranch(); - if (sel) - { - saveStateChangingPart( - sel, - sel, - QString ("paste (%1)").arg(curClipboard), - QString("Paste to %1").arg( getName(sel)) - ); - pasteNoSave(0); - model->reposition(); - } -} - -void MapEditor::cut() -{ - LinkableMapObj *sel=xelection.single(); - if ( sel && (xelection.type() == Selection::Branch || - xelection.type()==Selection::MapCenter || - xelection.type()==Selection::FloatImage)) - { - /* No savestate! savestate is called in cutNoSave - saveStateChangingPart( - sel->getParObj(), - sel, - "cut ()", - QString("Cut %1").arg(getName(sel )) - ); - */ - copy(); - deleteSelection(); - model->reposition(); - } -} - -void MapEditor::move(const double &x, const double &y) -{ - LinkableMapObj *sel=xelection.single(); - if (sel) - { - QPointF ap(sel->getAbsPos()); - QPointF to(x, y); - if (ap != to) - { - QString ps=qpointfToString(ap); - QString s=xelection.getSelectString(); - saveState( - s, "move "+ps, - s, "move "+qpointfToString(to), - QString("Move %1 to %2").arg(getName(sel)).arg(ps)); - sel->move(x,y); - model->reposition(); - xelection.update(); - } - } -} - -void MapEditor::moveRel (const double &x, const double &y) -{ - LinkableMapObj *sel=xelection.single(); - if (sel) - { - QPointF rp(sel->getRelPos()); - QPointF to(x, y); - if (rp != to) - { - QString ps=qpointfToString (sel->getRelPos()); - QString s=model->getSelectString(sel); - saveState( - s, "moveRel "+ps, - s, "moveRel "+qpointfToString(to), - QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps)); - ((OrnamentedObj*)sel)->move2RelPos (x,y); - model->reposition(); - sel->updateLink(); - xelection.update(); - } - } -} - -void MapEditor::moveBranchUp() -{ - BranchObj* bo=xelection.getBranch(); - BranchObj* par; - if (bo) - { - if (!bo->canMoveBranchUp()) return; - par=(BranchObj*)(bo->getParObj()); - BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection - saveState (model->getSelectString(bo),"moveBranchDown ()",model->getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); - model->reposition(); - scene()->update(); - xelection.update(); - ensureSelectionVisible(); - } -} - -void MapEditor::moveBranchDown() -{ - BranchObj* bo=xelection.getBranch(); - BranchObj* par; - if (bo) - { - if (!bo->canMoveBranchDown()) return; - par=(BranchObj*)(bo->getParObj()); - BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection - saveState(model->getSelectString(bo),"moveBranchUp ()",model->getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); - model->reposition(); - scene()->update(); - xelection.update(); - ensureSelectionVisible(); - } -} - -void MapEditor::sortChildren() -{ - BranchObj* bo=xelection.getBranch(); - if (bo) - { - if(bo->countBranches()>1) - { - saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo))); - bo->sortChildren(); - model->reposition(); - ensureSelectionVisible(); - } - } -} - -void MapEditor::linkTo(const QString &dstString) -{ - FloatImageObj *fio=xelection.getFloatImage(); - if (fio) - { - BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString)); - if (dst && (typeid(*dst)==typeid (BranchObj) || - typeid(*dst)==typeid (MapCenterObj))) - { - LinkableMapObj *dstPar=dst->getParObj(); - QString parString=model->getSelectString(dstPar); - QString fioPreSelectString=model->getSelectString(fio); - QString fioPreParentSelectString=model->getSelectString (fio->getParObj()); - ((BranchObj*)(dst))->addFloatImage (fio); - xelection.unselect(); - ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); - fio=((BranchObj*)(dst))->getLastFloatImage(); - fio->setRelPos(); - fio->reposition(); - xelection.select(fio); - saveState( - model->getSelectString(fio), - QString("linkTo (\"%1\")").arg(fioPreParentSelectString), - fioPreSelectString, - QString ("linkTo (\"%1\")").arg(dstString), - QString ("Link floatimage to %1").arg(getName(dst))); - } - } -} - -QString MapEditor::getHeading(bool &ok, QPoint &p) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - ok=true; - p=mapFromScene(bo->getAbsPos()); - return bo->getHeading(); - } - ok=false; - return QString(); -} - -void MapEditor::setHeading(const QString &s) -{ - BranchObj *sel=xelection.getBranch(); - if (sel) - { - saveState( - sel, - "setHeading (\""+sel->getHeading()+"\")", - sel, - "setHeading (\""+s+"\")", - QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) ); - sel->setHeading(s ); - model->reposition(); - xelection.update(); - ensureSelectionVisible(); - } -} - -void MapEditor::setHeadingInt(const QString &s) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo->setHeading(s); - model->reposition(); - xelection.update(); - ensureSelectionVisible(); - } -} - -void MapEditor::setVymLinkInt (const QString &s) -{ - // Internal function, no saveState needed - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo->setVymLink(s); - model->reposition(); - updateActions(); - xelection.update(); - ensureSelectionVisible(); - } -} - -BranchObj* MapEditor::addMapCenter () -{ - MapCenterObj *mco= model->addMapCenter(contextMenuPos); - xelection.select (mco); - updateActions(); - ensureSelectionVisible(); - saveState ( - mco, - "delete()", - NULL, - QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()), - QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y()) - ); - return mco; -} - -BranchObj* MapEditor::addNewBranchInt(int num) -{ - // Depending on pos: - // -3 insert in childs of parent above selection - // -2 add branch to selection - // -1 insert in childs of parent below selection - // 0..n insert in childs of parent at pos - BranchObj *newbo=NULL; - BranchObj *bo=xelection.getBranch(); - if (bo) - { - if (num==-2) - { - // save scroll state. If scrolled, automatically select - // new branch in order to tmp unscroll parent... - newbo=bo->addBranch(); - - }else if (num==-1) - { - num=bo->getNum()+1; - bo=(BranchObj*)bo->getParObj(); - if (bo) newbo=bo->insertBranch(num); - }else if (num==-3) - { - num=bo->getNum(); - bo=(BranchObj*)bo->getParObj(); - if (bo) newbo=bo->insertBranch(num); - } - if (!newbo) return NULL; - } - return newbo; -} - -BranchObj* MapEditor::addNewBranch(int pos) -{ - // Different meaning than num in addNewBranchInt! - // -1 add above - // 0 add as child - // +1 add below - BranchObj *bo = xelection.getBranch(); - BranchObj *newbo=NULL; - - if (bo) - { - setCursor (Qt::ArrowCursor); - - newbo=addNewBranchInt (pos-2); - - if (newbo) - { - saveState( - newbo, - "delete ()", - bo, - QString ("addBranch (%1)").arg(pos), - QString ("Add new branch to %1").arg(getName(bo))); - - model->reposition(); - xelection.update(); - latestSelection=model->getSelectString(newbo); - // In Network mode, the client needs to know where the new branch is, - // so we have to pass on this information via saveState. - // TODO: Get rid of this positioning workaround - QString ps=qpointfToString (newbo->getAbsPos()); - sendData ("selectLatestAdded ()"); - sendData (QString("move %1").arg(ps)); - sendSelection(); - } - } - return newbo; -} - - -BranchObj* MapEditor::addNewBranchBefore() -{ - BranchObj *newbo=NULL; - BranchObj *bo = xelection.getBranch(); - if (bo && xelection.type()==Selection::Branch) - // We accept no MapCenterObj here, so we _have_ a parent - { - QPointF p=bo->getRelPos(); - - - BranchObj *parbo=(BranchObj*)(bo->getParObj()); - - // add below selection - newbo=parbo->insertBranch(bo->getNum()+1); - if (newbo) - { - newbo->move2RelPos (p); - - // Move selection to new branch - bo->linkTo (newbo,-1); - - saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", - QString ("Add branch before %1").arg(getName(bo))); - - model->reposition(); - xelection.update(); - } - } - latestSelection=xelection.getSelectString(); - return newbo; -} - -void MapEditor::deleteSelection() -{ - BranchObj *bo = xelection.getBranch(); - if (bo && xelection.type()==Selection::MapCenter) - { - // BranchObj* par=(BranchObj*)(bo->getParObj()); - xelection.unselect(); - /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!) - saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); - */ - bo=model->removeMapCenter ((MapCenterObj*)bo); - if (bo) - { - xelection.select (bo); - ensureSelectionVisible(); - xelection.update(); - } - model->reposition(); - return; - } - if (bo && xelection.type()==Selection::Branch) - { - BranchObj* par=(BranchObj*)bo->getParObj(); - xelection.unselect(); - saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); - par->removeBranch(bo); - xelection.select (par); - ensureSelectionVisible(); - model->reposition(); -// xelection.update(); - xelection.update(); - return; - } - FloatImageObj *fio=xelection.getFloatImage(); - if (fio) - { - BranchObj* par=(BranchObj*)fio->getParObj(); - saveStateChangingPart( - par, - fio, - "delete ()", - QString("Delete %1").arg(getName(fio)) - ); - xelection.unselect(); - par->removeFloatImage(fio); - xelection.select (par); - model->reposition(); - xelection.update(); - ensureSelectionVisible(); - return; - } -} - -LinkableMapObj* MapEditor::getSelection() -{ - return xelection.single(); -} - -BranchObj* MapEditor::getSelectedBranch() -{ - return xelection.getBranch(); -} - -FloatImageObj* MapEditor::getSelectedFloatImage() -{ - return xelection.getFloatImage(); -} - -void MapEditor::unselect() -{ - xelection.unselect(); -} - -void MapEditor::reselect() -{ - xelection.reselect(); -} - -bool MapEditor::select (const QString &s) -{ - if (xelection.select(s)) - { - xelection.update(); - ensureSelectionVisible(); - sendSelection (); - return true; - } - return false; -} - -bool MapEditor::select (LinkableMapObj *lmo) -{ - if (xelection.select(lmo)) - { - xelection.update(); - ensureSelectionVisible(); - sendSelection (); - return true; - } - return false; -} - -QString MapEditor::getSelectString() -{ - return xelection.getSelectString(); -} - -void MapEditor::selectInt (LinkableMapObj *lmo) -{ - if (lmo && xelection.single()!= lmo && isSelectBlocked()==false ) - { - xelection.select(lmo); - xelection.update(); - sendSelection (); - } -} - -void MapEditor::selectNextBranchInt() -{ - // Increase number of branch - LinkableMapObj *sel=xelection.single(); - if (sel) - { - QString s=xelection.getSelectString(); - QString part; - QString typ; - QString num; - - // Where am I? - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - s=s.left (s.length() -num.length()); - - // Go to next lmo - num=QString ("%1").arg(num.toUInt()+1); - - s=s+num; - - // Try to select this one - if (select (s)) return; - - // We have no direct successor, - // try to increase the parental number in order to - // find a successor with same depth - - int d=xelection.single()->getDepth(); - int oldDepth=d; - int i; - bool found=false; - bool b; - while (!found && d>0) - { - s=s.section (",",0,d-1); - // replace substring of current depth in s with "1" - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - if (d>1) - { - // increase number of parent - num=QString ("%1").arg(num.toUInt()+1); - s=s.section (",",0,d-2) + ","+ typ+num; - } else - { - // Special case, look at orientation - if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) - num=QString ("%1").arg(num.toUInt()+1); - else - num=QString ("%1").arg(num.toUInt()-1); - s=typ+num; - } - - if (select (s)) - // pad to oldDepth, select the first branch for each depth - for (i=d;icountBranches()>0) - s+=",bo:0"; - else - break; - } else - break; - } - - // try to select the freshly built string - found=select(s); - d--; - } - return; - } -} - -void MapEditor::selectPrevBranchInt() -{ - // Decrease number of branch - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QString s=xelection.getSelectString(); - QString part; - QString typ; - QString num; - - // Where am I? - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - s=s.left (s.length() -num.length()); - - int n=num.toInt()-1; - - // Go to next lmo - num=QString ("%1").arg(n); - s=s+num; - - // Try to select this one - if (n>=0 && select (s)) return; - - // We have no direct precessor, - // try to decrease the parental number in order to - // find a precessor with same depth - - int d=xelection.single()->getDepth(); - int oldDepth=d; - int i; - bool found=false; - bool b; - while (!found && d>0) - { - s=s.section (",",0,d-1); - // replace substring of current depth in s with "1" - part=s.section(",",-1); - typ=part.left (3); - num=part.right(part.length() - 3); - - if (d>1) - { - // decrease number of parent - num=QString ("%1").arg(num.toInt()-1); - s=s.section (",",0,d-2) + ","+ typ+num; - } else - { - // Special case, look at orientation - if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) - num=QString ("%1").arg(num.toInt()-1); - else - num=QString ("%1").arg(num.toInt()+1); - s=typ+num; - } - - if (select(s)) - // pad to oldDepth, select the last branch for each depth - for (i=d;icountBranches()>0) - s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 ); - else - break; - else - break; - } - - // try to select the freshly built string - found=select(s); - d--; - } - return; - } -} - -void MapEditor::selectUpperBranch() -{ - if (isSelectBlocked() ) return; - - BranchObj *bo=xelection.getBranch(); - if (bo && xelection.type()==Selection::Branch) - { - if (bo->getOrientation()==LinkableMapObj::RightOfCenter) - selectPrevBranchInt(); - else - if (bo->getDepth()==1) - selectNextBranchInt(); - else - selectPrevBranchInt(); - } -} - -void MapEditor::selectLowerBranch() -{ - if (isSelectBlocked() ) return; - - BranchObj *bo=xelection.getBranch(); - if (bo && xelection.type()==Selection::Branch) - { - if (bo->getOrientation()==LinkableMapObj::RightOfCenter) - selectNextBranchInt(); - else - if (bo->getDepth()==1) - selectPrevBranchInt(); - else - selectNextBranchInt(); - } -} - - -void MapEditor::selectLeftBranch() -{ - if (isSelectBlocked() ) return; - - BranchObj* bo; - BranchObj* par; - LinkableMapObj *sel=xelection.single(); - if (sel) - { - if (xelection.type()== Selection::MapCenter) - { - par=xelection.getBranch(); - bo=par->getLastSelectedBranch(); - if (bo) - { - // Workaround for reselecting on left and right side - if (bo->getOrientation()==LinkableMapObj::RightOfCenter) - bo=par->getLastBranch(); - if (bo) - { - bo=par->getLastBranch(); - xelection.select(bo); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } - } else - { - par=(BranchObj*)(sel->getParObj()); - if (sel->getOrientation()==LinkableMapObj::RightOfCenter) - { - if (xelection.type() == Selection::Branch || - xelection.type() == Selection::FloatImage) - { - xelection.select(par); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } else - { - if (xelection.type() == Selection::Branch ) - { - bo=xelection.getBranch()->getLastSelectedBranch(); - if (bo) - { - xelection.select(bo); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } - } - } - } -} - -void MapEditor::selectRightBranch() -{ - if (isSelectBlocked() ) return; - - BranchObj* bo; - BranchObj* par; - LinkableMapObj *sel=xelection.single(); - if (sel) - { - if (xelection.type()==Selection::MapCenter) - { - par=xelection.getBranch(); - bo=par->getLastSelectedBranch(); - if (bo) - { - // Workaround for reselecting on left and right side - if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) - bo=par->getFirstBranch(); - if (bo) - { - xelection.select(bo); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } - } else - { - par=(BranchObj*)(xelection.single()->getParObj()); - if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter) - { - if (xelection.type() == Selection::Branch || - xelection.type() == Selection::FloatImage) - { - xelection.select(par); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } else - { - if (xelection.type() == Selection::Branch) - { - bo=xelection.getBranch()->getLastSelectedBranch(); - if (bo) - { - xelection.select(bo); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } - } - } - } -} - -void MapEditor::selectFirstBranch() -{ - BranchObj *bo1=xelection.getBranch(); - BranchObj *bo2; - BranchObj* par; - if (bo1) - { - par=(BranchObj*)(bo1->getParObj()); - if (!par) return; - bo2=par->getFirstBranch(); - if (bo2) { - xelection.select(bo2); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } -} - -void MapEditor::selectLastBranch() -{ - BranchObj *bo1=xelection.getBranch(); - BranchObj *bo2; - BranchObj* par; - if (bo1) - { - par=(BranchObj*)(bo1->getParObj()); - if (!par) return; - bo2=par->getLastBranch(); - if (bo2) - { - xelection.select(bo2); - xelection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } -} - -void MapEditor::selectMapBackgroundImage () -{ - Q3FileDialog *fd=new Q3FileDialog( this); - fd->setMode (Q3FileDialog::ExistingFile); - fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); - ImagePreview *p =new ImagePreview (fd); - fd->setContentsPreviewEnabled( TRUE ); - fd->setContentsPreview( p, p ); - fd->setPreviewMode( Q3FileDialog::Contents ); - fd->setCaption(vymName+" - " +tr("Load background image")); - fd->setDir (lastImageDir); - fd->show(); - - if ( fd->exec() == QDialog::Accepted ) - { - // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory(); - lastImageDir=QDir (fd->dirPath()); - setMapBackgroundImage (fd->selectedFile()); - } -} - -void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate -{ - QColor oldcol=mapScene->backgroundBrush().color(); - /* - saveState( - selection, - QString ("setMapBackgroundImage (%1)").arg(oldcol.name()), - selection, - QString ("setMapBackgroundImage (%1)").arg(col.name()), - QString("Set background color of map to %1").arg(col.name())); - */ - QBrush brush; - brush.setTextureImage (QPixmap (fn)); - mapScene->setBackgroundBrush(brush); -} - -void MapEditor::selectMapBackgroundColor() -{ - QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this ); - if ( !col.isValid() ) return; - setMapBackgroundColor( col ); -} - - -void MapEditor::setMapBackgroundColor(QColor col) -{ - QColor oldcol=mapScene->backgroundBrush().color(); - saveState( - QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()), - QString ("setMapBackgroundColor (\"%1\")").arg(col.name()), - QString("Set background color of map to %1").arg(col.name())); - mapScene->setBackgroundBrush(col); -} - -QColor MapEditor::getMapBackgroundColor() -{ - return mapScene->backgroundBrush().color(); -} - -QColor MapEditor::getCurrentHeadingColor() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) return bo->getColor(); - - QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected")); - return Qt::black; -} - -void MapEditor::colorBranch (QColor c) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveState( - bo, - QString ("colorBranch (\"%1\")").arg(bo->getColor().name()), - bo, - QString ("colorBranch (\"%1\")").arg(c.name()), - QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name()) - ); - bo->setColor(c); // color branch - } -} - -void MapEditor::colorSubtree (QColor c) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveStateChangingPart( - bo, - bo, - QString ("colorSubtree (\"%1\")").arg(c.name()), - QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name()) - ); - bo->setColorSubtree (c); // color links, color childs - } -} - - void MapEditor::toggleStandardFlag(QString f) { - BranchObj *bo=xelection.getBranch(); + BranchObj *bo=model->getSelectedBranch(); if (bo) { QString u,r; @@ -3377,1042 +263,21 @@ u="unsetFlag"; r="setFlag"; } - saveState( + model->saveState( bo, QString("%1 (\"%2\")").arg(u).arg(f), bo, QString("%1 (\"%2\")").arg(r).arg(f), QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); bo->toggleStandardFlag (f,mainWindow->useFlagGroups()); - xelection.update(); + model->updateSelection(); } } - -BranchObj* MapEditor::findText (QString s, bool cs) -{ - QTextDocument::FindFlags flags=0; - if (cs) flags=QTextDocument::FindCaseSensitively; - - if (!itFind) - { // Nothing found or new find process - if (EOFind) - // nothing found, start again - EOFind=false; - itFind=model->first(); - } - bool searching=true; - bool foundNote=false; - while (searching && !EOFind) - { - if (itFind) - { - // Searching in Note - if (itFind->getNote().contains(s,cs)) - { - if (xelection.single()!=itFind) - { - xelection.select(itFind); - ensureSelectionVisible(); - } - if (textEditor->findText(s,flags)) - { - searching=false; - foundNote=true; - } - } - // Searching in Heading - if (searching && itFind->getHeading().contains (s,cs) ) - { - xelection.select(itFind); - ensureSelectionVisible(); - searching=false; - } - } - if (!foundNote) - { - itFind=model->next(itFind); - if (!itFind) EOFind=true; - } - //cout <<"still searching... "<getHeading())<getURL(); - bo->setURL (url); - saveState ( - bo, - QString ("setURL (\"%1\")").arg(oldurl), - bo, - QString ("setURL (\"%1\")").arg(url), - QString ("set URL of %1 to %2").arg(getName(bo)).arg(url) - ); - updateActions(); - model->reposition(); - xelection.update(); - ensureSelectionVisible(); - } -} - -void MapEditor::editURL() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bool ok; - QString text = QInputDialog::getText( - "VYM", tr("Enter URL:"), QLineEdit::Normal, - bo->getURL(), &ok, this ); - if ( ok) - // user entered something and pressed OK - setURL (text); - } -} - -void MapEditor::editLocalURL() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QStringList filters; - filters <<"All files (*)"; - filters << tr("Text","Filedialog") + " (*.txt)"; - filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)"; - filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)"; - filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"; - QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file")); - fd->setFilters (filters); - fd->setCaption(vymName+" - " +tr("Set URL to a local file")); - fd->setDirectory (lastFileDir); - if (! bo->getVymLink().isEmpty() ) - fd->selectFile( bo->getURL() ); - fd->show(); - - if ( fd->exec() == QDialog::Accepted ) - { - lastFileDir=QDir (fd->directory().path()); - setURL (fd->selectedFile() ); - } - } -} - -QString MapEditor::getURL() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - return bo->getURL(); - else - return ""; -} - -QStringList MapEditor::getURLs() -{ - QStringList urls; - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo=bo->first(); - while (bo) - { - if (!bo->getURL().isEmpty()) urls.append( bo->getURL()); - bo=bo->next(); - } - } - return urls; -} - - -void MapEditor::editHeading2URL() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - setURL (bo->getHeading()); -} - -void MapEditor::editBugzilla2URL() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); - setURL (url); - } -} - -void MapEditor::editFATE2URL() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); - saveState( - bo, - "setURL (\""+bo->getURL()+"\")", - bo, - "setURL (\""+url+"\")", - QString("Use heading of %1 as link to FATE").arg(getName(bo)) - ); - bo->setURL (url); - updateActions(); - } -} - -void MapEditor::editVymLink() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QStringList filters; - filters <<"VYM map (*.vym)"; - QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map")); - fd->setFilters (filters); - fd->setCaption(vymName+" - " +tr("Link to another map")); - fd->setDirectory (lastFileDir); - if (! bo->getVymLink().isEmpty() ) - fd->selectFile( bo->getVymLink() ); - fd->show(); - - QString fn; - if ( fd->exec() == QDialog::Accepted ) - { - lastFileDir=QDir (fd->directory().path()); - saveState( - bo, - "setVymLink (\""+bo->getVymLink()+"\")", - bo, - "setVymLink (\""+fd->selectedFile()+"\")", - QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()) - ); - setVymLinkInt (fd->selectedFile() ); - } - } -} - -void MapEditor::deleteVymLink() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveState( - bo, - "setVymLink (\""+bo->getVymLink()+"\")", - bo, - "setVymLink (\"\")", - QString("Unset vymlink of %1").arg(getName(bo)) - ); - bo->setVymLink ("" ); - updateActions(); - model->reposition(); - scene()->update(); - } -} - -void MapEditor::setHideExport(bool b) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo->setHideInExport (b); - QString u= b ? "false" : "true"; - QString r=!b ? "false" : "true"; - - saveState( - bo, - QString ("setHideExport (%1)").arg(u), - bo, - QString ("setHideExport (%1)").arg(r), - QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r) - ); - updateActions(); - model->reposition(); - xelection.update(); - scene()->update(); - } -} - -void MapEditor::toggleHideExport() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - setHideExport ( !bo->hideInExport() ); -} - -QString MapEditor::getVymLink() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - return bo->getVymLink(); - else - return ""; - -} - -QStringList MapEditor::getVymLinks() -{ - QStringList links; - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo=bo->first(); - while (bo) - { - if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink()); - bo=bo->next(); - } - } - return links; -} - - -void MapEditor::deleteKeepChilds() -{ - BranchObj *bo=xelection.getBranch(); - BranchObj *par; - if (bo) - { - par=(BranchObj*)(bo->getParObj()); - QPointF p=bo->getRelPos(); - saveStateChangingPart( - bo->getParObj(), - bo, - "deleteKeepChilds ()", - QString("Remove %1 and keep its childs").arg(getName(bo)) - ); - - QString sel=model->getSelectString(bo); - unselect(); - par->removeBranchHere(bo); - model->reposition(); - select (sel); - xelection.getBranch()->move2RelPos (p); - model->reposition(); - } -} - -void MapEditor::deleteChilds() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveStateChangingPart( - bo, - bo, - "deleteChilds ()", - QString( "Remove childs of branch %1").arg(getName(bo)) - ); - bo->removeChilds(); - model->reposition(); - } -} - -void MapEditor::editMapInfo() -{ - ExtraInfoDialog dia; - dia.setMapName (getFileName() ); - dia.setAuthor (model->getAuthor() ); - dia.setComment(model->getComment() ); - - // Calc some stats - QString stats; - stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6); - - uint b=0; - uint f=0; - uint n=0; - uint xl=0; - BranchObj *bo; - bo=model->first(); - while (bo) - { - if (!bo->getNote().isEmpty() ) n++; - f+= bo->countFloatImages(); - b++; - xl+=bo->countXLinks(); - bo=model->next(bo); - } - stats+=QString ("%1 branches\n").arg (b-1,6); - stats+=QString ("%1 xLinks \n").arg (xl,6); - stats+=QString ("%1 notes\n").arg (n,6); - stats+=QString ("%1 images\n").arg (f,6); - dia.setStats (stats); - - // Finally show dialog - if (dia.exec() == QDialog::Accepted) - { - setMapAuthor (dia.getAuthor() ); - setMapComment (dia.getComment() ); - } -} - -void MapEditor::ensureSelectionVisible() -{ - LinkableMapObj *lmo=xelection.single(); - if (lmo) ensureVisible (lmo->getBBox() ); - -} - void MapEditor::updateSelection() { // Tell selection to update geometries - xelection.update(); -} - -void MapEditor::updateActions() -{ - // Tell mainwindow to update states of actions - mainWindow->updateActions(); - // TODO maybe don't update if blockReposition is set -} - -void MapEditor::updateNoteFlag() -{ - setChanged(); - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo->updateNoteFlag(); - mainWindow->updateActions(); - } -} - -void MapEditor::setMapAuthor (const QString &s) -{ - saveState ( - QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()), - QString ("setMapAuthor (\"%1\")").arg(s), - QString ("Set author of map to \"%1\"").arg(s) - ); - model->setAuthor (s); -} - -void MapEditor::setMapComment (const QString &s) -{ - saveState ( - QString ("setMapComment (\"%1\")").arg(model->getComment()), - QString ("setMapComment (\"%1\")").arg(s), - QString ("Set comment of map") - ); - model->setComment (s); -} - -void MapEditor::setMapLinkStyle (const QString & s) -{ - QString snow; - if (linkstyle==LinkableMapObj::Line) - snow="StyleLine"; - else if (linkstyle==LinkableMapObj::Parabel) - snow="StyleParabel"; - else if (linkstyle==LinkableMapObj::PolyLine) - snow="StylePolyLine"; - else if (linkstyle==LinkableMapObj::PolyParabel) - snow="StyleParabel"; - - saveState ( - QString("setMapLinkStyle (\"%1\")").arg(s), - QString("setMapLinkStyle (\"%1\")").arg(snow), - QString("Set map link style (\"%1\")").arg(s) - ); - - if (s=="StyleLine") - linkstyle=LinkableMapObj::Line; - else if (s=="StyleParabel") - linkstyle=LinkableMapObj::Parabel; - else if (s=="StylePolyLine") - linkstyle=LinkableMapObj::PolyLine; - else - linkstyle=LinkableMapObj::PolyParabel; - - BranchObj *bo; - bo=model->first(); - bo=model->next(bo); - while (bo) - { - bo->setLinkStyle(bo->getDefLinkStyle()); - bo=model->next(bo); - } - model->reposition(); -} - -LinkableMapObj::Style MapEditor::getMapLinkStyle () -{ - return linkstyle; -} - -void MapEditor::setMapDefLinkColor(QColor c) -{ - defLinkColor=c; - BranchObj *bo; - bo=model->first(); - while (bo) - { - bo->setLinkColor(); - bo=model->next(bo); - } - updateActions(); -} - -void MapEditor::setMapLinkColorHintInt() -{ - // called from setMapLinkColorHint(lch) or at end of parse - BranchObj *bo; - bo=model->first(); - while (bo) - { - bo->setLinkColor(); - bo=model->next(bo); - } -} - -void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch) -{ - linkcolorhint=lch; - setMapLinkColorHintInt(); -} - -void MapEditor::toggleMapLinkColorHint() -{ - if (linkcolorhint==LinkableMapObj::HeadingColor) - linkcolorhint=LinkableMapObj::DefaultColor; - else - linkcolorhint=LinkableMapObj::HeadingColor; - BranchObj *bo; - bo=model->first(); - while (bo) - { - bo->setLinkColor(); - bo=model->next(bo); - } -} - -LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint() -{ - return linkcolorhint; -} - -QColor MapEditor::getMapDefLinkColor() -{ - return defLinkColor; -} - -void MapEditor::setMapDefXLinkColor(QColor col) -{ - defXLinkColor=col; -} - -QColor MapEditor::getMapDefXLinkColor() -{ - return defXLinkColor; -} - -void MapEditor::setMapDefXLinkWidth (int w) -{ - defXLinkWidth=w; -} - -int MapEditor::getMapDefXLinkWidth() -{ - return defXLinkWidth; -} - -void MapEditor::selectMapLinkColor() -{ - QColor col = QColorDialog::getColor( defLinkColor, this ); - if ( !col.isValid() ) return; - saveState ( - QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()), - QString("setMapDefLinkColor (\"%1\")").arg(col.name()), - QString("Set map link color to %1").arg(col.name()) - ); - setMapDefLinkColor( col ); -} - -void MapEditor::selectMapSelectionColor() -{ - QColor col = QColorDialog::getColor( defLinkColor, this ); - setSelectionColor (col); -} - -void MapEditor::setSelectionColorInt (QColor col) -{ - if ( !col.isValid() ) return; - xelection.setColor (col); -} - -void MapEditor::setSelectionColor(QColor col) -{ - if ( !col.isValid() ) return; - saveState ( - QString("setSelectionColor (%1)").arg(xelection.getColor().name()), - QString("setSelectionColor (%1)").arg(col.name()), - QString("Set color of selection box to %1").arg(col.name()) - ); - setSelectionColorInt (col); -} - -QColor MapEditor::getSelectionColor() -{ - return xelection.getColor(); -} - -bool MapEditor::scrollBranch(BranchObj *bo) -{ - if (bo) - { - if (bo->isScrolled()) return false; - if (bo->countBranches()==0) return false; - if (bo->getDepth()==0) return false; - QString u,r; - r="scroll"; - u="unscroll"; - saveState( - bo, - QString ("%1 ()").arg(u), - bo, - QString ("%1 ()").arg(r), - QString ("%1 %2").arg(r).arg(getName(bo)) - ); - bo->toggleScroll(); - xelection.update(); - scene()->update(); - return true; - } - return false; -} - -bool MapEditor::unscrollBranch(BranchObj *bo) -{ - if (bo) - { - if (!bo->isScrolled()) return false; - if (bo->countBranches()==0) return false; - if (bo->getDepth()==0) return false; - QString u,r; - u="scroll"; - r="unscroll"; - saveState( - bo, - QString ("%1 ()").arg(u), - bo, - QString ("%1 ()").arg(r), - QString ("%1 %2").arg(r).arg(getName(bo)) - ); - bo->toggleScroll(); - xelection.update(); - scene()->update(); - return true; - } - return false; -} - -void MapEditor::toggleScroll() -{ - BranchObj *bo=xelection.getBranch(); - if (xelection.type()==Selection::Branch ) - { - if (bo->isScrolled()) - unscrollBranch (bo); - else - scrollBranch (bo); - } -} - -void MapEditor::unscrollChilds() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo->first(); - while (bo) - { - if (bo->isScrolled()) unscrollBranch (bo); - bo=bo->next(); - } - } -} - -FloatImageObj* MapEditor::loadFloatImageInt (QString fn) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - FloatImageObj *fio; - bo->addFloatImage(); - fio=bo->getLastFloatImage(); - fio->load(fn); - model->reposition(); - scene()->update(); - return fio; - } - return NULL; -} - -void MapEditor::loadFloatImage () -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - - Q3FileDialog *fd=new Q3FileDialog( this); - fd->setMode (Q3FileDialog::ExistingFiles); - fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); - ImagePreview *p =new ImagePreview (fd); - fd->setContentsPreviewEnabled( TRUE ); - fd->setContentsPreview( p, p ); - fd->setPreviewMode( Q3FileDialog::Contents ); - fd->setCaption(vymName+" - " +tr("Load image")); - fd->setDir (lastImageDir); - fd->show(); - - if ( fd->exec() == QDialog::Accepted ) - { - // TODO loadFIO in QT4 use: lastImageDir=fd->directory(); - lastImageDir=QDir (fd->dirPath()); - QString s; - FloatImageObj *fio; - for (int j=0; jselectedFiles().count(); j++) - { - s=fd->selectedFiles().at(j); - fio=loadFloatImageInt (s); - if (fio) - saveState( - (LinkableMapObj*)fio, - "delete ()", - bo, - QString ("loadImage (%1)").arg(s ), - QString("Add image %1 to %2").arg(s).arg(getName(bo)) - ); - else - // TODO loadFIO error handling - qWarning ("Failed to load "+s); - } - } - delete (p); - delete (fd); - } -} - -void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) -{ - fio->save (fn,type); -} - -void MapEditor::saveFloatImage () -{ - FloatImageObj *fio=xelection.getFloatImage(); - if (fio) - { - QFileDialog *fd=new QFileDialog( this); - fd->setFilters (imageIO.getFilters()); - fd->setCaption(vymName+" - " +tr("Save image")); - fd->setFileMode( QFileDialog::AnyFile ); - fd->setDirectory (lastImageDir); -// fd->setSelection (fio->getOriginalFilename()); - fd->show(); - - QString fn; - if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1) - { - fn=fd->selectedFiles().at(0); - if (QFile (fn).exists() ) - { - QMessageBox mb( vymName, - tr("The file %1 exists already.\n" - "Do you want to overwrite it?").arg(fn), - QMessageBox::Warning, - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::Cancel | QMessageBox::Escape, - QMessageBox::NoButton ); - - mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); - mb.setButtonText( QMessageBox::No, tr("Cancel")); - switch( mb.exec() ) - { - case QMessageBox::Yes: - // save - break; - case QMessageBox::Cancel: - // do nothing - delete (fd); - return; - break; - } - } - saveFloatImageInt (fio,fd->selectedFilter(),fn ); - } - delete (fd); - } -} - -void MapEditor::setFrameType(const FrameObj::FrameType &t) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QString s=bo->getFrameTypeName(); - bo->setFrameType (t); - saveState (bo, QString("setFrameType (\"%1\")").arg(s), - bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); - model->reposition(); - bo->updateLink(); - } -} - -void MapEditor::setFrameType(const QString &s) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), - bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); - bo->setFrameType (s); - model->reposition(); - bo->updateLink(); - } -} - -void MapEditor::setFramePenColor(const QColor &c) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), - bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); - bo->setFramePenColor (c); - } -} - -void MapEditor::setFrameBrushColor(const QColor &c) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), - bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); - bo->setFrameBrushColor (c); - } -} - -void MapEditor::setFramePadding (const int &i) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), - bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); - bo->setFramePadding (i); - model->reposition(); - bo->updateLink(); - } -} - -void MapEditor::setFrameBorderWidth(const int &i) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), - bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); - bo->setFrameBorderWidth (i); - model->reposition(); - bo->updateLink(); - } -} - -void MapEditor::setIncludeImagesVer(bool b) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QString u= b ? "false" : "true"; - QString r=!b ? "false" : "true"; - - saveState( - bo, - QString("setIncludeImagesVertically (%1)").arg(u), - bo, - QString("setIncludeImagesVertically (%1)").arg(r), - QString("Include images vertically in %1").arg(getName(bo)) - ); - bo->setIncludeImagesVer(b); - model->reposition(); - } -} - -void MapEditor::setIncludeImagesHor(bool b) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QString u= b ? "false" : "true"; - QString r=!b ? "false" : "true"; - - saveState( - bo, - QString("setIncludeImagesHorizontally (%1)").arg(u), - bo, - QString("setIncludeImagesHorizontally (%1)").arg(r), - QString("Include images horizontally in %1").arg(getName(bo)) - ); - bo->setIncludeImagesHor(b); - model->reposition(); - } -} - -void MapEditor::setHideLinkUnselected (bool b) -{ - LinkableMapObj *sel=xelection.single(); - if (sel && - (xelection.type() == Selection::Branch || - xelection.type() == Selection::MapCenter || - xelection.type() == Selection::FloatImage )) - { - QString u= b ? "false" : "true"; - QString r=!b ? "false" : "true"; - - saveState( - sel, - QString("setHideLinkUnselected (%1)").arg(u), - sel, - QString("setHideLinkUnselected (%1)").arg(r), - QString("Hide link of %1 if unselected").arg(getName(sel)) - ); - sel->setHideLinkUnselected(b); - } -} - -void MapEditor::importDirInt(BranchObj *dst, QDir d) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - // Traverse directories - d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks ); - QFileInfoList list = d.entryInfoList(); - QFileInfo fi; - - for (int i = 0; i < list.size(); ++i) - { - fi=list.at(i); - if (fi.fileName() != "." && fi.fileName() != ".." ) - { - dst->addBranch(); - bo=dst->getLastBranch(); - bo->setHeading (fi.fileName() ); - bo->setColor (QColor("blue")); - bo->toggleScroll(); - if ( !d.cd(fi.fileName()) ) - QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); - else - { - // Recursively add subdirs - importDirInt (bo,d); - d.cdUp(); - } - } - } - // Traverse files - d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks ); - list = d.entryInfoList(); - - for (int i = 0; i < list.size(); ++i) - { - fi=list.at(i); - dst->addBranch(); - bo=dst->getLastBranch(); - bo->setHeading (fi.fileName() ); - bo->setColor (QColor("black")); - if (fi.fileName().right(4) == ".vym" ) - bo->setVymLink (fi.filePath()); - } - } -} - -void MapEditor::importDirInt (const QString &s) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); - - QDir d(s); - importDirInt (bo,d); - } -} - -void MapEditor::importDir() -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - QStringList filters; - filters <<"VYM map (*.vym)"; - QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import")); - fd->setMode (QFileDialog::DirectoryOnly); - fd->setFilters (filters); - fd->setCaption(vymName+" - " +tr("Choose directory structure to import")); - fd->show(); - - QString fn; - if ( fd->exec() == QDialog::Accepted ) - { - importDirInt (fd->selectedFile() ); - model->reposition(); - scene()->update(); - } - } -} - -void MapEditor::followXLink(int i) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - bo=bo->XLinkTargetAt(i); - if (bo) - { - xelection.select(bo); - ensureSelectionVisible(); - } - } -} - -void MapEditor::editXLink(int i) // FIXME missing saveState -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - XLinkObj *xlo=bo->XLinkAt(i); - if (xlo) - { - EditXLinkDialog dia; - dia.setXLink (xlo); - dia.setSelection(bo); - if (dia.exec() == QDialog::Accepted) - { - if (dia.useSettingsGlobal() ) - { - setMapDefXLinkColor (xlo->getColor() ); - setMapDefXLinkWidth (xlo->getWidth() ); - } - if (dia.deleteXLink()) - bo->deleteXLinkAt(i); - } - } - } + model->updateSelection(); } AttributeTable* MapEditor::attributeTable() @@ -4422,8 +287,9 @@ void MapEditor::testFunction1() { - BranchObj *bo=xelection.getBranch(); - if (bo) model->moveAway (bo); + BranchObj *bo=model->getSelectedBranch(); + //if (bo) model->moveAway (bo); + if (bo) bo->setLinkStyle (LinkableMapObj::Line); /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone) @@ -4464,6 +330,42 @@ */ } +void MapEditor::editHeading() +{ + if (editingHeading) + { + editHeadingFinished(); + return; + } + BranchObj *bo=model->getSelectedBranch(); + if (bo) + { + model->setSelectionBlocked(true); + + lineEdit->setText (bo->getHeading()); + QPoint p = mapTo (this,bo->getAbsPos().toPoint() ); + lineEdit->setGeometry(p.x(),p.y(),230,25); + lineEdit->selectAll(); + lineEdit->show(); + lineEdit->setFocus(); + lineEdit->grabKeyboard(); + editingHeading=true; + } + +} +void MapEditor::editHeadingFinished() +{ + editingHeading=false; + lineEdit->releaseKeyboard(); + model->setHeading (lineEdit->text() ); + model->setSelectionBlocked(false); + lineEdit->hide(); + + // Maybe reselect previous branch + mainWindow->editHeadingFinished (model); +} + + void MapEditor::contextMenuEvent ( QContextMenuEvent * e ) { // Lineedits are already closed by preceding @@ -4474,30 +376,30 @@ if (lmo) { // MapObj was found - if (xelection.single() != lmo) + if (model->getSelection() != lmo) { // select the MapObj - xelection.select(lmo); + model->select(lmo); } // Context Menu - if (xelection.getBranch() ) + if (model->getSelectedBranch() ) { // Context Menu on branch or mapcenter - updateActions(); + model->updateActions(); branchContextMenu->popup(e->globalPos() ); } else { - if (xelection.getFloatImage() ) + if (model->getSelectedFloatImage() ) { // Context Menu on floatimage - updateActions(); + model->updateActions(); floatimageContextMenu->popup(e->globalPos() ); } } } else { // No MapObj found, we are on the Canvas itself // Context Menu on scene - updateActions(); + model->updateActions(); contextMenuPos=p; canvasContextMenu->popup(e->globalPos() ); } @@ -4542,7 +444,7 @@ } //Ignore clicks while editing heading - if (isSelectBlocked() ) + if (model->isSelectionBlocked() ) { e->ignore(); return; @@ -4562,7 +464,7 @@ if (!foname.isEmpty()) { // systemFlag clicked - selectInt (lmo); + model->selectInt (lmo); if (foname=="url") { if (e->state() & Qt::ControlModifier) @@ -4578,12 +480,11 @@ } else if (foname=="note") mainWindow->windowToggleNoteEditor(); else if (foname=="hideInExport") - toggleHideExport(); - xelection.update(); + model->toggleHideExport(); + // FIXME needed? xelection.update(); return; } - } - + } // No system flag clicked, take care of modmodes (CTRL-Click) if (e->state() & Qt::ControlModifier) { @@ -4599,8 +500,7 @@ if (lmo) bo_begin=(BranchObj*)(lmo); else - if (xelection.getBranch() ) - bo_begin=xelection.getBranch(); + bo_begin=model->getSelectedBranch(); if (bo_begin) { drawingLink=true; @@ -4608,8 +508,8 @@ tmpXLink=new XLinkObj (mapScene); tmpXLink->setBegin (bo_begin); tmpXLink->setEnd (p); - tmpXLink->setColor(defXLinkColor); - tmpXLink->setWidth(defXLinkWidth); + tmpXLink->setColor(model->getMapDefXLinkColor()); + tmpXLink->setWidth(model->getMapDefXLinkWidth()); tmpXLink->updateXLink(); tmpXLink->setVisibility (true); return; @@ -4620,7 +520,7 @@ if (lmo) { // Select the clicked object - selectInt (lmo); + model->selectInt (lmo); // Left Button Move Branches if (e->button() == Qt::LeftButton ) @@ -4631,6 +531,7 @@ movingObj_start.setY( p.y() - lmo->y() ); movingObj_orgPos.setX (lmo->x() ); movingObj_orgPos.setY (lmo->y() ); + lmo->setRelPos(); movingObj_orgRelPos=lmo->getRelPos(); // If modMode==copy, then we want to "move" the _new_ object around @@ -4638,26 +539,26 @@ if (mainWindow->getModMode()==Main::ModModeCopy && e->state() & Qt::ControlModifier) { - BranchObj *bo=xelection.getBranch(); + BranchObj *bo=model->getSelectedBranch(); if (bo) { copyingObj=true; - bo->addBranch ((BranchObj*)xelection.single()); - unselect(); - xelection.select(bo->getLastBranch()); + bo->addBranch ((BranchObj*)model->getSelection()); + model->unselect(); + model->select(bo->getLastBranch()); model->reposition(); } } - movingObj=xelection.single(); + movingObj=model->getSelection(); } else // Middle Button Toggle Scroll // (On Mac OS X this won't work, but we still have // a button in the toolbar) if (e->button() == Qt::MidButton ) - toggleScroll(); - updateActions(); - xelection.update(); + model->toggleScroll(); + model->updateActions(); + // FIXME needed? xelection.update(); } else { // No MapObj found, we are on the scene itself // Left Button move Pos of sceneView @@ -4677,7 +578,7 @@ void MapEditor::mouseMoveEvent(QMouseEvent* e) { QPointF p = mapToScene(e->pos()); - LinkableMapObj *lmosel=xelection.single(); + LinkableMapObj *lmosel=model->getSelection(); // Move the selected MapObj if ( lmosel && movingObj) @@ -4689,7 +590,7 @@ // To avoid jumping of the sceneView, only // ensureSelectionVisible, if not tmp linked if (!lmosel->hasParObjTmp()) - ensureSelectionVisible (); + model->ensureSelectionVisible (); // Now move the selection, but add relative position // (movingObj_start) where selection was chosen with @@ -4700,13 +601,13 @@ LinkableMapObj* lmo=model->findMapObj(p, lmosel); - FloatObj *fio=xelection.getFloatImage(); + FloatObj *fio=model->getSelectedFloatImage(); if (fio) { fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); fio->setRelPos(); fio->updateLink(); //no need for reposition, if we update link here - xelection.update(); + model->updateSelection(); // Relink float to new mapcenter or branch, if shift is pressed // Only relink, if selection really has a new parent @@ -4724,7 +625,7 @@ // Also save the move which was done so far QString pold=qpointfToString(movingObj_orgRelPos); QString pnow=qpointfToString(fio->getRelPos()); - saveState( + model->saveState( fio, "moveRel "+pold, fio, @@ -4733,7 +634,7 @@ fio->getParObj()->requestReposition(); model->reposition(); - linkTo (model->getSelectString(lmo)); + model->linkFloatImageTo (model->getSelectString(lmo)); //movingObj=lmosel; //movingObj_orgRelPos=lmosel->getRelPos(); @@ -4762,14 +663,15 @@ // Move ordinary branch if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter) // Add width of bbox here, otherwise alignRelTo will cause jumping around - lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), + lmosel->move(p.x() -movingObj_start.x() , //lmosel->getBBox().width(), p.y()-movingObj_start.y() +lmosel->getTopPad() ); else lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad()); + lmosel->setRelPos(); } // Maybe we can relink temporary? - if (lmo && (lmo!=lmosel) && xelection.getBranch() && + if (lmo && (lmo!=lmosel) && model->getSelectedBranch() && (typeid(*lmo)==typeid(BranchObj) || typeid(*lmo)==typeid(MapCenterObj)) ) @@ -4791,7 +693,7 @@ lmosel->reposition(); } // depth>0 - xelection.update(); + model->updateSelection();// FIXME needed? } // no FloatImageObj scene()->update(); @@ -4821,7 +723,7 @@ { QPointF p = mapToScene(e->pos()); LinkableMapObj *dst; - LinkableMapObj *lmosel=xelection.single(); + LinkableMapObj *lmosel=model->getSelection(); // Have we been picking color? if (pickingColor) { @@ -4832,9 +734,9 @@ if (dst && lmosel) { if (e->state() & Qt::ShiftModifier) - colorBranch (((BranchObj*)dst)->getColor()); + model->colorBranch (((BranchObj*)dst)->getColor()); else - colorSubtree (((BranchObj*)dst)->getColor()); + model->colorSubtree (((BranchObj*)dst)->getColor()); } return; } @@ -4850,7 +752,7 @@ tmpXLink->setEnd ( ((BranchObj*)(dst)) ); tmpXLink->updateXLink(); tmpXLink->activate(); //FIXME savestate missing - //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); + //model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); } else { delete(tmpXLink); @@ -4862,13 +764,13 @@ // Have we been moving something? if ( lmosel && movingObj ) { - FloatImageObj *fo=xelection.getFloatImage(); + FloatImageObj *fo=model->getSelectedFloatImage(); if(fo) { // Moved FloatObj. Maybe we need to reposition QString pold=qpointfToString(movingObj_orgRelPos); QString pnow=qpointfToString(fo->getRelPos()); - saveState( + model->saveState( fo, "moveRel "+pold, fo, @@ -4886,14 +788,14 @@ if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) dst=NULL; - BranchObj *bo=xelection.getBranch(); + BranchObj *bo=model->getSelectedBranch(); if (bo && bo->getDepth()==0) { if (movingObj_orgPos != bo->getAbsPos()) { QString pold=qpointfToString(movingObj_orgPos); QString pnow=qpointfToString(bo->getAbsPos()); - saveState( + model->saveState( fo, "move "+pold, fo, @@ -4902,7 +804,7 @@ } } - if (xelection.type() == Selection::Branch ) + if (model->selectionType() == Selection::Branch ) { // A branch was moved // save the position in case we link to mapcenter @@ -4919,7 +821,7 @@ { // We have a destination, relink to that - BranchObj* bsel=xelection.getBranch(); + BranchObj* bsel=model->getSelectedBranch(); BranchObj* bdst=(BranchObj*)dst; QString preParStr=model->getSelectString (bsel->getParObj()); @@ -4953,7 +855,7 @@ preDstParStr + "\"," + postNum + "," + QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; - saveState ( + model->saveState ( postSelStr,undoCom, preSelStr, redoCom, QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) ); @@ -4973,7 +875,7 @@ if (rp != movingObj_orgRelPos) { QString ps=qpointfToString(rp); - saveState( + model->saveState( model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos), preSelStr, "moveRel "+ps, QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps)); @@ -4983,23 +885,26 @@ // Draw the original link, before selection was moved around if (settings.value("/animation/use",false).toBool() && lmosel->getDepth()>1) { - QPointF p=bo->getParObj()->getChildPos(); - lmosel->setRelPos(); // calc relPos first + lmosel->setRelPos(); // calc relPos first for starting point + QPointF dst=bo->getParObj()->getChildPos(); + // if (lmosel->getOrientation()==LinkableMapObj::LeftOfCenter) dst.setX (dst.x()+lmosel->width() ); + model->startAnimation( lmosel->getRelPos(), - QPointF (movingObj_orgPos.x() - p.x(), movingObj_orgPos.y() - p.y() ) + movingObj_orgRelPos +// QPointF (movingObj_orgPos.x() - dst.x(), movingObj_orgPos.y() - dst.y() ) ); } else model->reposition(); } } - xelection.update(); + model->updateSelection(); // Finally resize scene, if needed scene()->update(); movingObj=NULL; // Just make sure, that actions are still ok,e.g. the move branch up/down buttons... - updateActions(); + model->updateActions(); } else // maybe we moved View: set old cursor setCursor (Qt::ArrowCursor); @@ -5008,7 +913,7 @@ void MapEditor::mouseDoubleClickEvent(QMouseEvent* e) { - if (isSelectBlocked() ) + if (model->isSelectionBlocked() ) { e->ignore(); return; @@ -5020,8 +925,8 @@ LinkableMapObj *lmo=model->findMapObj(p, NULL); if (lmo) { // MapObj was found // First select the MapObj than edit heading - xelection.select(lmo); - mainWindow->editHeading(); + model->select (lmo); + editHeading(); } } } @@ -5054,7 +959,7 @@ void MapEditor::dropEvent(QDropEvent *event) { - BranchObj *sel=xelection.getBranch(); + BranchObj *sel=model->getSelectedBranch(); if (sel) { if (debug) @@ -5066,7 +971,7 @@ if (event->mimeData()->hasImage()) { QVariant imageData = event->mimeData()->imageData(); - addFloatImageInt (qvariant_cast(imageData)); + model->addFloatImage (qvariant_cast(imageData)); } else if (event->mimeData()->hasUrls()) uris=event->mimeData()->urls(); @@ -5114,258 +1019,6 @@ } -void MapEditor::sendSelection() -{ - if (netstate!=Server) return; - sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) ); -} - -void MapEditor::newServer() -{ - port=54321; - sendCounter=0; - tcpServer = new QTcpServer(this); - if (!tcpServer->listen(QHostAddress::Any,port)) { - QMessageBox::critical(this, "vym server", - QString("Unable to start the server: %1.").arg(tcpServer->errorString())); - close(); - return; - } - connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient())); - netstate=Server; - cout<<"Server is running on port "<serverPort()<abort(); - clientSocket->connectToHost(server ,port); - connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData())); - connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)), - this, SLOT(displayNetworkError(QAbstractSocket::SocketError))); - netstate=Client; - cout<<"connected to "<nextPendingConnection(); - connect(newClient, SIGNAL(disconnected()), - newClient, SLOT(deleteLater())); - - cout <<"ME::newClient at "<peerAddress().toString() )<seek(0); - quint16 bs=(quint16)(block.size() - 2*sizeof(quint16)); - out << bs; - - if (debug) - cout << "ME::sendData bs="<peerAddress().toString())<write (block); - } -} - -void MapEditor::readData () -{ - while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) ) - { - if (debug) - cout <<"readData bytesAvail="<bytesAvailable(); - quint16 recCounter; - quint16 blockSize; - - QDataStream in(clientSocket); - in.setVersion(QDataStream::Qt_4_0); - - in >> blockSize; - in >> recCounter; - - QString t; - in >>t; - if (debug) - cout << " t="<errorString())); - } -} - -void MapEditor::autosave() -{ - QDateTime now=QDateTime().currentDateTime(); - /* FIXME debug - cout << "ME::autosave checking "<0) return; - - // Also disable autosave for new map without filename - if (filePath.isEmpty()) return; - - - if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() ) - { - if (QFileInfo(filePath).lastModified()<=fileChangedTime) - mainWindow->fileSave (this); - else - if (debug) - cout <<" ME::autosave rejected, file on disk is newer than last save.\n"; - - } -} - -void MapEditor::fileChanged() -{ - // Check if file on disk has changed meanwhile - if (!filePath.isEmpty()) - { - QDateTime tmod=QFileInfo (filePath).lastModified(); - if (tmod>fileChangedTime) - { - - /* FIXME debug message, sometimes there's a glitch in the metrics... - cout << "ME::fileChanged()\n" - << " last saved: "<provides("application/x-moz-file-promise-url") && - event->provides("application/x-moz-nativeimage")) - { - // Contains url to the img src in unicode16 - QByteArray d = event->encodedData("application/x-moz-file-promise-url"); - QString url = QString((const QChar*)d.data(),d.size()/2); - fetchImage(url); - event->accept(); - update=true; - } else if (event->provides ("text/uri-list")) - { // Uris provided e.g. by konqueror - Q3UriDrag::decode (event,uris); - } else if (event->provides ("_NETSCAPE_URL")) - { // Uris provided by Mozilla - QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); - uris.append(l[0]); - heading = l[1]; - } else if (event->provides("text/html")) { - - // Handels text mime types - // Look like firefox allways handle text as unicode16 (2 bytes per char.) - QByteArray d = event->encodedData("text/html"); - QString text; - if (isUnicode16(d)) - text = QString((const QChar*)d.data(),d.size()/2); - else - text = QString(d); - - textEditor->setText(text); - - event->accept(); - update=true; - } else if (event->provides("text/plain")) { - QByteArray d = event->encodedData("text/plain"); - QString text; - if (isUnicode16(d)) - text = QString((const QChar*)d.data(),d.size()/2); - else - text = QString(d); - - textEditor->setText(text); - - event->accept(); - update= true; - } - - */ - - bool isUnicode16(const QByteArray &d) { @@ -5377,66 +1030,7 @@ return false; } -void MapEditor::addFloatImageInt (const QPixmap &img) -{ - BranchObj *bo=xelection.getBranch(); - if (bo) - { - FloatImageObj *fio=bo->addFloatImage(); - fio->load(img); - fio->setOriginalFilename("No original filename (image added by dropevent)"); - QString s=model->getSelectString(bo); - saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio ); - saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image"); - model->reposition(); - scene()->update(); - } -} -/* +// FIXME the following are not needed... +QString MapEditor::getName(const LinkableMapObj*) {return QString();} -void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) -{ - if (!imageBuffer) imageBuffer = new QBuffer(); - if (!imageBuffer->isOpen()) { - imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append); - } - imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a)); -} - - -void MapEditor::imageDataFinished(Q3NetworkOperation *nop) -{ - if (nop->state()==Q3NetworkProtocol::StDone) { - QPixmap img(imageBuffer->buffer()); - addFloatImageInt (img); - } - - if (imageBuffer) { - imageBuffer->close(); - if (imageBuffer) { - imageBuffer->close(); - delete imageBuffer; - imageBuffer = 0; - } - } -} - -void MapEditor::fetchImage(const QString &url) -{ - if (urlOperator) { - urlOperator->stop(); - disconnect(urlOperator); - delete urlOperator; - } - - urlOperator = new Q3UrlOperator(url); - connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), - this, SLOT(imageDataFinished(Q3NetworkOperation*))); - - connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)), - this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *))); - urlOperator->get(); -} -*/ - diff -r 3f90aab4794d -r 192e1392ba6a mapeditor.h --- a/mapeditor.h Mon Jul 14 11:25:09 2008 +0000 +++ b/mapeditor.h Wed Jul 16 10:44:44 2008 +0000 @@ -2,370 +2,46 @@ #define MAPEDITOR_H #include -#include #include "attribute.h" -#include "file.h" -#include "misc.h" -#include "parser.h" #include "ornamentedobj.h" -#include "selection.h" +#include "selection.h" // FIXME should not be needed #include "settings.h" #include "vymmodel.h" -class VymModel; -class Selection; /*! \brief Main widget in vym to display and edit a map */ -class MapEditor : public QGraphicsView, public XMLObj { +class MapEditor : public QGraphicsView { Q_OBJECT public: - /*! \brief State of the mapeditor - - While a heading is edited, the state has to change, so - that e.g. no other object might get selected. This is done - in Main by calling setStateEditHeading - */ - enum State { - Idle, //!< Idle, waiting for user event - EditHeading //!< Editing heading (dont't select another branch now) - }; - /*! \brief Networking states - - In Network modus we want to switch of saveState, autosave, ... - */ - enum NetState { - Offline, //!< Offline - Client, //!< I am the client and connected to server - Server //!< I am the server - }; - MapEditor(QWidget* parent=0); + MapEditor(VymModel *vm); ~MapEditor(); VymModel* getModel(); QGraphicsScene * getScene(); - State getState(); //!< Return State of MapEditor - void setStateEditHeading (bool); //!< If set to true, State will change to EditHeading - bool isRepositionBlocked(); //!< While load or undo there is no need to update graphicsview - bool isSaveStateBlocked(); //!< block while undo/redo or while running scripts - void setSaveStateBlocked(bool); //!< block saving the undo/redo state - bool isSelectBlocked(); //!< true, if no change of selection is possible, e.g. while editing the heading of abranch - -protected: - /*! \brief Get name of object - - Returns heading of a branch or name of an object for use in comment - of undo/redo history - */ - QString getName(const LinkableMapObj*); // Get e.g. heading or filename - void makeTmpDirs(); // create temporary directories - - /*! This function saves all information of the map to disc. - saveToDir also calls the functions for all BranchObj and other objects in the map. - The structure of the map itself is returned as QString and passed back to Main, - where saveToDir is called initially - */ - QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel); - - /*! \brief Get directory, where current step in history is save - - saveState creates a directory for each step in history. This function returns the - path of the current directory - */ - QString getHistoryDir(); - - /*! \brief Save the current changes in map - - Two commands and selections are saved: - - - undocommand and undoselection to undo the change - - redocommand and redoselection to redo the action after an undo - - Additionally a comment is logged. - - */ - void saveState( - const SaveMode& savemode, - const QString &undoSelection, - const QString &undoCommand, - const QString &redoSelection, - const QString &redoCommand, - const QString &comment, - LinkableMapObj *saveSelection); - /*! Overloaded for convenience */ - void saveStateChangingPart( - LinkableMapObj *undoSelection, - LinkableMapObj* redoSelection, - const QString &redoCommand, - const QString &comment); - /*! Overloaded for convenience */ - void saveStateRemovingPart( - LinkableMapObj *redoSelection, - const QString &comment); - /*! Overloaded for convenience */ - void saveState( - LinkableMapObj *undoSelection, - const QString &undoCommand, - LinkableMapObj *redoSelection, - const QString &redoCommand, - const QString &comment); - /*! Overloaded for convenience */ - void saveState( - const QString &undoSelection, - const QString &undoCommand, - const QString &redoSelection, - const QString &redoCommand, - const QString &comment) ; - void saveState( - const QString &undoCommand, - const QString &redoCommand, - const QString &comment) ; - -public: - - /* \brief Process one command and its parameters */ - void parseAtom (const QString &atom); - - /* \brief Runs the script */ - void runScript (QString script); -private: - void addFloatImageInt(const QPixmap &img); public: - bool isDefault(); //!< true, if map is still the empty default map - bool hasChanged(); //!< true, if something has changed and is not saved yet - void setChanged(); //!< called from TextEditor via LinkableMapObj - void closeMap(); //!< Closes the map - - /*! \brief Sets filepath, filename and mapname - - If the filepath is "/home/tux/map.xml", then the filename will be set - to map.xml. The destname is needed for vymLinks, pointing to another map. - The destname holds the real name of the file, after it has been compressed, e.g. "map.vym" - */ - - /*! \brief Set File path - - The destname is needed to construct the references between maps - */ - void setFilePath (QString filepath,QString destname); - void setFilePath (QString); //!< Overloaded for convenience - QString getFilePath (); //!< Full path e.g. "/home/tux/map.xml" - QString getFileName (); //!< e.g. "map.xml" - QString getMapName (); //!< e.g. "map" - QString getDestPath (); //!< e.g. "/home/tux/map.vym" - - /*! \brief Load map - - The data is read from file. Depending on LoadMode the current - selection gets replaced by data or the data is appended. - */ - ErrorCode load (QString, const LoadMode &, const FileType& ); // newmap, import/replace selection -public: - /*! \brief Save the map to file */ - ErrorCode save(const SaveMode &); - /* FIXME no needed any longer - void setZipped(bool); //!< Set or unset compression of map with zip save map zipped - bool saveZipped(); //!< True, if file will be saved zipped - */ void print(); //!< Print the map void setAntiAlias (bool); //!< Set or unset antialiasing void setSmoothPixmap(bool); //!< Set or unset smoothing of pixmaps -private: - QPixmap getPixmap(); - void setHideTmpMode (HideTmpMode); // temporary hide stuff - HideTmpMode getHideTmpMode(); // temporary hide stuff public: - /*! Set or unset temporary hiding of objects during export */ - void setExportMode (bool); + void toggleStandardFlag(QString); - /*! Export as ASCII text to file */ - void exportASCII (QString fname="",bool askForName=true); + void updateSelection(); // update geometry of selection - /*! Save as image */ - void exportImage (QString fname="",bool askForName=true,QString format="PNG"); - - /*! Export as OpenOfficeOrg presentation */ - void exportOOPresentation(const QString &,const QString &); - - /*! Export as XHTML to directory */ - void exportXHTML(const QString& dir="", bool askForName=true); - - /*! Export as XTML to directory */ - void exportXML(QString dir="", bool askForName=true); - - void clear(); //!< Clear map - void copy(); //!< Copy to clipboard - void redo(); //!< Redo last action - bool isRedoAvailable(); //!< True, if redo is available - void undo(); //!< Undo last action - bool isUndoAvailable(); //!< True, if undo is available - void gotoHistoryStep (int); //!< Goto a specifig step in history -private: - void addMapReplaceInt(const QString & undoSel, const QString & path); - void addMapInsertInt (const QString & path, int pos); - void pasteNoSave(const int &n); //!< paste clipboard to branch -public: - void paste(); //!< Paste clipboard to branch and backup - void cut(); //!< Cut to clipboard (and copy) - /*! \brief Move absolutly - - Move absolutly to (x,y). - */ - void move (const double &x, const double &y); - /*! \brief Move relativly - - Move relativly to (x,y). - */ - void moveRel (const double &x, const double &y); - void moveBranchUp(); //!< Move branch up - void moveBranchDown(); //!< Move branch down - void sortChildren(); //!< Sort children lexically -private: - void linkTo(const QString &); -public: - QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch - void setHeading(const QString &); //!< Set heading of branch -private: - void setHeadingInt(const QString &); - void setVymLinkInt(const QString &); // Set vymLink for selection - /*! \brief Add new mapcenter - - Disclaimer: Still experimental, not fully supported. - */ -public: - BranchObj* addMapCenter(); - - /*! \brief Add new branch - - Depending on num the new branch is created - - -3 above selection as child of selections parent - -2 as child of selection - -1 below selection as child of selections parent - 0..n insert at a specific position in selections parent - (needed for free relinking) - */ -private: - BranchObj* addNewBranchInt(int); // pos allows to add above/below selection -public: - /*! \Add new branch - - Depending on num the new branch is created - -1 above selection - 0 as child of selection - 1 below selection - */ - BranchObj* addNewBranch(int pos); - BranchObj* addNewBranchBefore(); //!< Insert branch between selection and its parent - void deleteSelection(); //!< Delete selection - LinkableMapObj* getSelection(); //!< Returns selection - BranchObj* getSelectedBranch(); // returns selected branch or NULL - FloatImageObj* getSelectedFloatImage(); // returns selected branch or NULL - void unselect(); // before changing current noteedit - void reselect(); // after changing current noteedit - bool select(const QString &); // Select by string - bool select(LinkableMapObj *lmo); // Select by pointer - QString getSelectString(); -private: - void selectInt(LinkableMapObj*); - void selectNextBranchInt(); // Increment number of branch - void selectPrevBranchInt(); // Decrement number of branch -public: - void selectUpperBranch(); - void selectLowerBranch(); - void selectLeftBranch(); - void selectRightBranch(); - void selectFirstBranch(); - void selectLastBranch(); - void selectMapBackgroundImage(); - void setMapBackgroundImage(const QString &); - void selectMapBackgroundColor(); - void setMapBackgroundColor(QColor); - QColor getMapBackgroundColor(); - QColor getCurrentHeadingColor(); - void colorBranch(QColor); - void colorSubtree(QColor); - void toggleStandardFlag(QString); - BranchObj* findText(QString,bool); // Find object - void findReset(); // Reset Find - void setURL(const QString &); // set URL - void editURL(); // edit URL - void editLocalURL(); // edit URL to local file - QString getURL(); // returns URL of selection or "" - QStringList getURLs(); // returns URLs of subtree - void editHeading2URL(); // copy heading to URL - void editBugzilla2URL(); // create URL to Bugzilla - void editFATE2URL(); // create URL to FATE - void editVymLink(); // edit link to another map - void deleteVymLink(); // delete link to another map - QString getVymLink(); // return path to map - QStringList getVymLinks(); // return paths in subtree - void setHideExport(bool); // toggle the export flag - void toggleHideExport(); // toggle the export flag - void deleteKeepChilds(); // remove but keep childs - void deleteChilds(); // remove childs - void editMapInfo(); // dialog to enter author, ... - void ensureSelectionVisible(); - void updateSelection(); // update geometry of selection - void updateActions(); // update e.g. format buttons - void updateNoteFlag(); // when TextEditor changes - void setMapAuthor (const QString &); - void setMapComment(const QString &); - void setMapLinkStyle (const QString &); // Set style of link - LinkableMapObj::Style getMapLinkStyle (); // requested in LMO - void setMapDefLinkColor(QColor); // default color of links - void setMapLinkColorHintInt(); // color of links - void setMapLinkColorHint(LinkableMapObj::ColorHint);// color of links - LinkableMapObj::ColorHint getMapLinkColorHint(); - QColor getMapDefLinkColor(); - void setMapDefXLinkColor(QColor); - QColor getMapDefXLinkColor(); - void setMapDefXLinkWidth (int); - int getMapDefXLinkWidth(); - void toggleMapLinkColorHint(); // after changing linkStyles - void selectMapLinkColor(); - void selectMapSelectionColor(); -private: - void setSelectionColorInt(QColor); -public: - void setSelectionColor(QColor); - QColor getSelectionColor(); - bool scrollBranch(BranchObj*); - bool unscrollBranch(BranchObj*); - void toggleScroll(); - void unscrollChilds(); -private: - FloatImageObj* loadFloatImageInt (QString); -public: - void loadFloatImage (); -private: - void saveFloatImageInt (FloatImageObj*, const QString &, const QString &); -public: - void saveFloatImage (); - void setFrameType(const FrameObj::FrameType &); - void setFrameType(const QString &); - void setFramePenColor (const QColor &); - void setFrameBrushColor (const QColor &); - void setFramePadding (const int &); - void setFrameBorderWidth (const int &); - void setIncludeImagesVer(bool); - void setIncludeImagesHor(bool); - void setHideLinkUnselected (bool); - bool getHideLinkUnselected (); -private: - void importDirInt(BranchObj *,QDir); - void importDirInt(const QString&); -public: - void importDir(); - void followXLink (int); - void editXLink (int); AttributeTable* attributeTable(); void testFunction1(); // just testing new stuff void testFunction2(); // just testing new stuff // set /mainwindo/showTestMenu=true... +public slots: + void editHeading(); + void editHeadingFinished(); +private: + bool editingHeading; + QLineEdit *lineEdit; + protected: virtual void contextMenuEvent ( QContextMenuEvent *e ); virtual void keyPressEvent(QKeyEvent*); @@ -382,39 +58,13 @@ void dropEvent (QDropEvent *); -protected: - void sendSelection(); - -public: - void newServer(); - void connectToServer(); - -private slots: - void newClient(); - void sendData(const QString &s); - void readData(); - void displayNetworkError (QAbstractSocket::SocketError); - - void autosave (); - void fileChanged(); - private: - State state; // State of MapEditor QGraphicsScene *mapScene; VymModel *model; // Vym Map, includding several mapCenters - QTimer *autosaveTimer; - QTimer *fileChangedTimer; - QDateTime fileChangedTime; bool adjustCanvasRequested; // collect requests until end of user event BranchObj *editingBO; // entering Text into BO - QColor defLinkColor; // default color for links - QColor defXLinkColor; // default color for xlinks - int defXLinkWidth; // default width for xlinks - LinkableMapObj::ColorHint linkcolorhint;// use heading color or own color - LinkableMapObj::Style linkstyle; // default style for links - QCursor HandOpenCursor; // cursor while moving canvas view QCursor PickColorCursor; // cursor while picking color QCursor CopyCursor; // cursor while picking color @@ -424,11 +74,7 @@ bool copyingObj; // true while creating a link XLinkObj* tmpXLink; - Selection xelection; - - QString latestSelection; // select string of latest added object - - MapObj* movingObj; // moving a MapObj + MapObj* movingObj; // moving a MapObj MapObj* linkingObj_src; // part of a link QPointF movingObj_orgPos; // org. pos of mouse before move QPointF movingObj_orgRelPos; // org. relative pos of mouse before move @@ -436,58 +82,19 @@ QPointF movingCont_start; // inital pos of moving Content or QPointF movingVec; // how far has Content moved - QPointF contextMenuPos; // position where context event was triggered + QPointF contextMenuPos; // position where context event was triggered QPrinter* printer; // Printing - bool mapDefault; // Flag if map is untouched - bool mapChanged; // Flag if undo is possible - bool mapUnsaved; // Flag if map should be saved - - Parser parser; // Parser stuff for scripting - AttributeTable *attrTable; bool printFrame; // Print frame around map bool printFooter; // Print footer below map - bool zipped; // should map be zipped - static int mapNum; // unique number for Editor - FileType fileType; // type of file, e.g. vym, freemind... - QString fileName; // short name of file (for tab) - QString filePath; // path to file which will be saved - QString fileDir; // dir where file is saved - QString destPath; // path to .vym file (needed for vymlinks) - QString mapName; // fileName without ".vym" + QPoint exportOffset; // set before export, used in save - QString tmpMapDir; // tmp directory with undo history - QString histPath; // Path to history file - SimpleSettings undoSet; // undo/redo commands, saved in histPath - int stepsTotal; // total number of steps (undos+redos) - int curStep; // Current step in history (ring buffer) - int curClipboard; // number of history step, which is the current clipboard - int redosAvail; // Available number of redo steps - int undosAvail; // Available number of undo steps - bool blockReposition; // block while load or undo - bool blockSaveState; // block while load or undo - - BranchObj* itFind; // next object in find process - bool EOFind; // true, if search failed - - QPoint exportOffset; // set before export, used in save - HideTmpMode hidemode; // true while exporting to hide some stuff - - // Network connections **Experimental** - NetState netstate; // offline, client, server - QTcpServer *tcpServer; // Act as server in conference mode (experimental) - QList clientList; // List of connected clients - quint16 sendCounter; // Increased with every sent command - - QTcpSocket *clientSocket; // socket of this client - QString server; // server address of this client - int port; // server port of this client - void displayClientError(QAbstractSocket::SocketError socketError); - + Selection xelection; // FIXME only here to get rid of some gcc errors... + QString getName(const LinkableMapObj*); // FIXME see above, renamed to getObjectName in VymModel... }; #endif