diff -r 83a3be747ad9 -r 8b9cfc26638c mapeditor.cpp --- a/mapeditor.cpp Wed Apr 25 16:02:54 2007 +0000 +++ b/mapeditor.cpp Wed Apr 25 16:02:54 2007 +0000 @@ -27,6 +27,7 @@ extern QString tmpVymDir; extern QString clipboardDir; extern bool clipboardEmpty; +extern bool debug; extern FlagRowObj *standardFlagsDefault; extern QMenu* branchContextMenu; @@ -55,7 +56,7 @@ /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// MapEditor::MapEditor( QWidget* parent) : - QGraphicsView(parent) + QGraphicsView(parent) { //cout << "Constructor ME "<reposition(); // for positioning heading + // TODO animations + animObjList.clear(); + //timerId = startTimer(100); + + // autosave + autosaveTimer=new QTimer (this); + connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave())); } MapEditor::~MapEditor() { //cout <<"Destructor MapEditor\n"; + autosaveTimer->stop(); } MapCenterObj* MapEditor::getMapCenter() @@ -156,6 +165,11 @@ return blockReposition; } +void MapEditor::setSaveStateBlocked(bool b) +{ + blockSaveState=b; +} + QString MapEditor::getName (const LinkableMapObj *lmo) { QString s; @@ -197,13 +211,13 @@ QString ls; switch (linkstyle) { - case StyleLine: + case LinkableMapObj::Line: ls="StyleLine"; break; - case StyleParabel: + case LinkableMapObj::Parabel: ls="StyleParabel"; break; - case StylePolyLine: + case LinkableMapObj::PolyLine: ls="StylePolyLine"; break; default: @@ -213,7 +227,7 @@ QString s="\n"; QString colhint=""; - if (linkcolorhint==HeadingColor) + if (linkcolorhint==LinkableMapObj::HeadingColor) colhint=attribut("linkColorHint","HeadingColor"); QString mapAttr=attribut("version",vymVersion); @@ -349,7 +363,7 @@ /* TODO remove after testing */ - cout << "ME::saveState() "<updateHistory (undoSet); setChanged(); @@ -761,7 +777,7 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParamCount(0)) { - if (!scrollBranch ()) + if (!scrollBranch (selb)) parser.setError (Aborted,"Could not scroll branch"); } } else if (com=="select") @@ -803,6 +819,17 @@ selectInt (fio); } + } else if (com=="setFrameType") + { + if ( xelection.type()!=Branch && xelection.type()!= MapCenter && xelection.type()!=FloatImage) + { + parser.setError (Aborted,"Type of selection does not allow setting frame type"); + } + else if (parser.checkParamCount(1)) + { + s=parser.parString(ok,0); + if (ok) setFrameType (s); + } } else if (com=="setMapAuthor") { if (parser.checkParamCount(1)) @@ -869,17 +896,16 @@ if (xelection.isEmpty() ) { parser.setError (Aborted,"Nothing selected"); - } else if (! selb) + } else if (xelection.type()!=Branch && xelection.type() != MapCenter &&xelection.type()!=FloatImage) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); - //FIXME selb is never a floatimage!! } else if (parser.checkParamCount(1)) { b=parser.parBool(ok,0); if (ok) setHideExport (b); } } else if (com=="setIncludeImagesHorizontally") - { + { if (xelection.isEmpty() ) { parser.setError (Aborted,"Nothing selected"); @@ -996,9 +1022,21 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParamCount(0)) { - if (!unscrollBranch ()) + 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.checkParamCount(0)) + { + unscrollChilds (); + } } else if (com=="unsetFlag") { if (xelection.isEmpty() ) @@ -1058,10 +1096,13 @@ void MapEditor::setChanged() { + if (!mapChanged) + autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt()); mapChanged=true; mapDefault=false; mapUnsaved=true; findReset(); + } void MapEditor::closeMap() @@ -1168,7 +1209,9 @@ err=aborted; } else { + bool blockSaveStateOrg=blockSaveState; blockReposition=true; + blockSaveState=true; QXmlInputSource source( file); QXmlSimpleReader reader; reader.setContentHandler( &handler ); @@ -1177,10 +1220,9 @@ handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path handler.setInputFile (file.name()); handler.setLoadMode (lmode); - blockSaveState=true; bool ok = reader.parse( source ); blockReposition=false; - blockSaveState=false; + blockSaveState=blockSaveStateOrg; file.close(); if ( ok ) { @@ -1191,6 +1233,7 @@ mapDefault=false; mapChanged=false; mapUnsaved=false; + autosaveTimer->stop(); } } else { @@ -1224,7 +1267,8 @@ if (savemode==CompleteMap || xelection.isEmpty()) saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); else - saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); //FIXME check selected FIO + //save () FIXME check FIO + saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); if (!saveStringToDisk(fileDir+fname,saveFile)) return 1; @@ -1233,6 +1277,7 @@ { mapChanged=false; mapUnsaved=false; + autosaveTimer->stop(); updateActions(); } @@ -1373,7 +1418,7 @@ return pix; } -void MapEditor::setHideTmpMode (HideTmpMode mode) +void MapEditor::setHideTmpMode (BranchObj::HideTmpMode mode) { hidemode=mode; mapCenter->setHideTmp (hidemode); @@ -1381,7 +1426,7 @@ scene()->update(); } -HideTmpMode MapEditor::getHideTmpMode() +BranchObj::HideTmpMode MapEditor::getHideTmpMode() { return hidemode; } @@ -1399,9 +1444,9 @@ // should be called before and after exports // depending on the settings if (b && settings.value("/export/useHideExport","yes")=="yes") - setHideTmpMode (HideExport); + setHideTmpMode (BranchObj::HideExport); else - setHideTmpMode (HideNone); + setHideTmpMode (BranchObj::HideNone); } void MapEditor::exportImage(QString fn, QString format) @@ -1496,14 +1541,16 @@ void MapEditor::redo() { - blockSaveState=true; - // Restore variables int curStep=undoSet.readNumEntry (QString("/history/curStep")); int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); // Can we undo at all? if (redosAvail<1) return; + + bool blockSaveStateOrg=blockSaveState; + blockSaveState=true; + redosAvail--; if (undosAvailreposition(); - blockSaveState=false; + blockSaveState=blockSaveStateOrg; undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); @@ -1577,8 +1625,6 @@ void MapEditor::undo() { - blockSaveState=true; - // Restore variables int curStep=undoSet.readNumEntry (QString("/history/curStep")); int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); @@ -1587,6 +1633,9 @@ // Can we undo at all? if (undosAvail<1) return; + 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)); @@ -1605,19 +1654,20 @@ if (!undoSelection.isEmpty()) select (undoSelection); -/* TODO testing -*/ - cout << "ME::undo() begin\n"; - cout << " undosAvail="<reposition(); @@ -1627,7 +1677,7 @@ redosAvail++; - blockSaveState=false; + blockSaveState=blockSaveStateOrg; /* TODO remove testing cout << "ME::undo() end\n"; cout << " undosAvail="<move(x,y); // FIXME xelection not moved automagically... + sel->move(x,y); mapCenter->reposition(); xelection.update(); } @@ -1841,11 +1891,8 @@ { if (!bo->canMoveBranchUp()) return; par=(BranchObj*)(bo->getParObj()); - xelection.unselect(); // FIXME needed? - bo=par->moveBranchUp (bo); // bo will be the one below selection - xelection.reselect(); - //saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); - saveState (bo,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); + BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection + saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); mapCenter->reposition(); scene()->update(); xelection.update(); @@ -1861,11 +1908,8 @@ { if (!bo->canMoveBranchDown()) return; par=(BranchObj*)(bo->getParObj()); - xelection.unselect(); // FIXME needed? - bo=par->moveBranchDown(bo); // bo will be the one above selection - xelection.reselect(); - //saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); - saveState(bo,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); + BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection + saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); mapCenter->reposition(); scene()->update(); xelection.update(); @@ -2209,7 +2253,7 @@ } else { // Special case, look at orientation - if (xelection.single()->getOrientation()==OrientRightOfCenter) + if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) num=QString ("%1").arg(num.toUInt()+1); else num=QString ("%1").arg(num.toUInt()-1); @@ -2291,7 +2335,7 @@ } else { // Special case, look at orientation - if (xelection.single()->getOrientation()==OrientRightOfCenter) + if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) num=QString ("%1").arg(num.toInt()-1); else num=QString ("%1").arg(num.toInt()+1); @@ -2325,7 +2369,7 @@ BranchObj *bo=xelection.getBranch(); if (bo && xelection.type()==Branch) { - if (bo->getOrientation()==OrientRightOfCenter) + if (bo->getOrientation()==LinkableMapObj::RightOfCenter) selectPrevBranchInt(); else if (bo->getDepth()==1) @@ -2339,7 +2383,7 @@ { BranchObj *bo=xelection.getBranch(); if (bo && xelection.type()==Branch) - if (bo->getOrientation()==OrientRightOfCenter) + if (bo->getOrientation()==LinkableMapObj::RightOfCenter) selectNextBranchInt(); else if (bo->getDepth()==1) @@ -2363,7 +2407,7 @@ if (bo) { // Workaround for reselecting on left and right side - if (bo->getOrientation()==OrientRightOfCenter) + if (bo->getOrientation()==LinkableMapObj::RightOfCenter) bo=par->getLastBranch(); if (bo) { @@ -2376,7 +2420,7 @@ } else { par=(BranchObj*)(sel->getParObj()); - if (sel->getOrientation()==OrientRightOfCenter) + if (sel->getOrientation()==LinkableMapObj::RightOfCenter) { if (xelection.type() == Branch || xelection.type() == FloatImage) @@ -2416,7 +2460,7 @@ if (bo) { // Workaround for reselecting on left and right side - if (bo->getOrientation()==OrientLeftOfCenter) + if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) bo=par->getFirstBranch(); if (bo) { @@ -2428,7 +2472,7 @@ } else { par=(BranchObj*)(xelection.single()->getParObj()); - if (xelection.single()->getOrientation()==OrientLeftOfCenter) + if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter) { if (xelection.type() == Branch || xelection.type() == FloatImage) @@ -3025,13 +3069,13 @@ ); if (s=="StyleLine") - linkstyle=StyleLine; + linkstyle=LinkableMapObj::Line; else if (s=="StyleParabel") - linkstyle=StyleParabel; + linkstyle=LinkableMapObj::Parabel; else if (s=="StylePolyLine") - linkstyle=StylePolyLine; + linkstyle=LinkableMapObj::PolyLine; else - linkstyle=StylePolyParabel; + linkstyle=LinkableMapObj::PolyParabel; BranchObj *bo; bo=mapCenter->first(); @@ -3044,7 +3088,7 @@ mapCenter->reposition(); } -LinkStyle MapEditor::getMapLinkStyle () +LinkableMapObj::Style MapEditor::getMapLinkStyle () { return linkstyle; } @@ -3067,7 +3111,7 @@ } } -void MapEditor::setMapLinkColorHint(LinkColorHint lch) +void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch) { linkcolorhint=lch; setMapLinkColorHintInt(); @@ -3075,10 +3119,10 @@ void MapEditor::toggleMapLinkColorHint() { - if (linkcolorhint==HeadingColor) - linkcolorhint=DefaultColor; + if (linkcolorhint==LinkableMapObj::HeadingColor) + linkcolorhint=LinkableMapObj::DefaultColor; else - linkcolorhint=HeadingColor; + linkcolorhint=LinkableMapObj::HeadingColor; BranchObj *bo; bo=mapCenter->first(); while (bo) @@ -3088,7 +3132,7 @@ } } -LinkColorHint MapEditor::getMapLinkColorHint() +LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint() { return linkcolorhint; } @@ -3162,9 +3206,8 @@ return xelection.getColor(); } -bool MapEditor::scrollBranch() +bool MapEditor::scrollBranch(BranchObj *bo) { - BranchObj *bo=xelection.getBranch(); if (bo) { if (bo->isScrolled()) return false; @@ -3187,9 +3230,8 @@ return false; } -bool MapEditor::unscrollBranch() +bool MapEditor::unscrollBranch(BranchObj *bo) { - BranchObj *bo=xelection.getBranch(); if (bo) { if (!bo->isScrolled()) return false; @@ -3218,13 +3260,13 @@ if (xelection.type()==Branch ) { if (bo->isScrolled()) - unscrollBranch (); + unscrollBranch (bo); else - scrollBranch (); + scrollBranch (bo); } } -void MapEditor::unscrollChilds() // FIXME saveState missing +void MapEditor::unscrollChilds() { BranchObj *bo=xelection.getBranch(); if (bo) @@ -3232,7 +3274,7 @@ bo->first(); while (bo) { - if (bo->isScrolled()) bo->toggleScroll(); + if (bo->isScrolled()) unscrollBranch (bo); bo=bo->next(); } } @@ -3351,40 +3393,79 @@ } } -void MapEditor::setFrameType(const FrameType &t) // FIXME missing saveState +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)); mapCenter->reposition(); bo->updateLink(); } } -void MapEditor::setFrameType(const QString &s) // FIXME missing saveState +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); mapCenter->reposition(); bo->updateLink(); } } -void MapEditor::setFramePenColor(const QColor &c) // FIXME missing saveState +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) // FIXME missing saveState +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 &) +{ + 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::setFrameBorderWidth(const int &) +{ + 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::setIncludeImagesVer(bool b) @@ -3550,6 +3631,8 @@ { // This is the playground + BranchObj *bo=xelection.getBranch(); + if (bo) animObjList.append( bo ); /* WarningDialog dia; @@ -3636,13 +3719,13 @@ { switch (mainWindow->getModMode()) { - case ModModeColor: + case Main::ModModeColor: setCursor (PickColorCursor); break; - case ModModeCopy: + case Main::ModModeCopy: setCursor (CopyCursor); break; - case ModModeXLink: + case Main::ModModeXLink: setCursor (XLinkCursor); break; default : @@ -3706,13 +3789,13 @@ // No system flag clicked, take care of modmodes (CTRL-Click) if (e->state() & Qt::ControlModifier) { - if (mainWindow->getModMode()==ModModeColor) + if (mainWindow->getModMode()==Main::ModModeColor) { pickingColor=true; setCursor (PickColorCursor); return; } - if (mainWindow->getModMode()==ModModeXLink) + if (mainWindow->getModMode()==Main::ModModeXLink) { BranchObj *bo_begin=NULL; if (lmo) @@ -3754,7 +3837,7 @@ // If modMode==copy, then we want to "move" the _new_ object around // then we need the offset from p to the _old_ selection, because of tmp - if (mainWindow->getModMode()==ModModeCopy && + if (mainWindow->getModMode()==Main::ModModeCopy && e->state() & Qt::ControlModifier) { if (xelection.type()==Branch) @@ -3801,7 +3884,7 @@ if ( lmosel && movingObj) { // reset cursor if we are moving and don't copy - if (mainWindow->getModMode()!=ModModeCopy) + if (mainWindow->getModMode()!=Main::ModModeCopy) setCursor (Qt::ArrowCursor); // To avoid jumping of the sceneView, only @@ -3878,7 +3961,7 @@ } else { // Move ordinary branch - if (lmosel->getOrientation() == OrientLeftOfCenter) + 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(), p.y()-movingObj_start.y() +lmosel->getTopPad() ); @@ -3958,7 +4041,7 @@ } // Have we been drawing a link? - if (drawingLink) + if (drawingLink) //FIXME savestate missing { drawingLink=false; // Check if we are over another branch @@ -3968,7 +4051,7 @@ tmpXLink->setEnd ( ((BranchObj*)(dst)) ); tmpXLink->updateXLink(); tmpXLink->activate(); - //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand + //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); } else { delete(tmpXLink); @@ -4187,8 +4270,28 @@ event->acceptProposedAction(); } -/* -void MapEditor::contentsDropEvent(QDropEvent *event) +void MapEditor::timerEvent(QTimerEvent *event) //FIXME testing +{ + Q_UNUSED(event); + + cout << "ME::timerEvent\n"; + + for (int i=0; ianimate(); + ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() ); + } + mapCenter->reposition(); +} + +void MapEditor::autosave() +{ + if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/used",true).toBool() ) + mainWindow->fileSave (this); +} + + +/*FIXME not needed? void MapEditor::contentsDropEvent(QDropEvent *event) { } else if (event->provides("application/x-moz-file-promise-url") && @@ -4256,12 +4359,9 @@ BranchObj *bo=xelection.getBranch(); if (bo) { - //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo))); - //QString fn=fd->selectedFile(); - //lastImageDir=fn.left(fn.findRev ("/")); FloatImageObj *fio=bo->addFloatImage(); fio->load(img); - fio->setOriginalFilename("Image added by Drag and Drop"); + fio->setOriginalFilename("Image added by Drag and Drop"); // FIXME savestate mapCenter->reposition(); scene()->update(); }