diff -r 699f28529079 -r 41c3d7f9f532 mapeditor.cpp --- a/mapeditor.cpp Tue Aug 15 12:01:14 2006 +0000 +++ b/mapeditor.cpp Tue Aug 29 08:31:42 2006 +0000 @@ -44,7 +44,6 @@ #include "linkablemapobj.h" #include "mainwindow.h" #include "misc.h" -#include "settings.h" #include "texteditor.h" #include "warningdialog.h" #include "xml.h" @@ -63,6 +62,7 @@ extern QAction *actionFileSave; extern QAction *actionEditUndo; +extern QAction *actionEditRedo; extern QAction *actionEditCopy; extern QAction *actionEditCut; extern QAction *actionEditPaste; @@ -177,10 +177,6 @@ printer=NULL; - lineedit = new QLineEdit(this, "lineedit" ); - connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEdit() ) ); - lineedit->hide(); - actColor=Qt::black; setColor (actColor); defLinkColor=QColor (0,0,255); defXLinkColor=QColor (180,180,180); @@ -207,6 +203,8 @@ selectionLast=NULL; movingObj=NULL; + xelection.setMapCenter (mapCenter); + defXLinkWidth=1; defXLinkColor=QColor (230,230,230); @@ -220,8 +218,6 @@ mapName=""; undosTotal=settings.readNumEntry("/mapeditor/undoLevels",50); - undosAvail=0; - undoNum=0; // Initialize find routine itFind=NULL; @@ -248,6 +244,8 @@ historyWindow->setCaption (fileName); mapCenter->reposition(); // for positioning heading + + } MapEditor::~MapEditor() @@ -372,7 +370,8 @@ void MapEditor::makeTmpDirs() { // Create unique temporary directories - tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum); + tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum)); + histPath=QDir::convertSeparators (tmpMapDir+"/history"); QDir d; d.mkdir (tmpMapDir,true); } @@ -458,32 +457,29 @@ return s; } -void MapEditor::saveState(const QString &comment) +void MapEditor::saveStateComplete(const QString &comment) { // Save complete map saveState (CompleteMap,"",NULL,"",NULL, comment); } -void MapEditor::saveState(LinkableMapObj *undoSel, const QString &comment) +void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment) { - // save the given part of the map + // save the selected part of the map saveState (PartOfMap,"",undoSel,"",NULL, comment); } -void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment) +void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment) { // selection does not change during action, // so just save commands for undo and redo - LinkableMapObj *unsel; - if (selection) - unsel=selection; - else - unsel=NULL; - saveState (UndoCommand,uc,unsel,rc,unsel, comment); + // and use current selection + saveState (UndoCommand,uc,selection,rc,selection, comment); } -void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel, const QString &comment) +void MapEditor::saveStateX(LinkableMapObj *unsel, const QString &uncom, const QString &comment) { + // saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL, comment); } @@ -494,24 +490,24 @@ if (blockSaveState) return; /* TODO remove after testing + */ cout << "ME::saveState() begin\n"<append (comment); setChanged(); + int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0); + int curStep=undoSet.readNumEntry ("/history/curStep",0); // Find out current undo directory if (undosAvailundosTotal) undoNum=1; + curStep++; + if (curStep>undosTotal) curStep=1; QString backupXML; - QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum)); + QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml"); // Create bakMapDir if not available @@ -550,28 +546,27 @@ // Write XML Data to disk saveStringToDisk (QString(bakMapPath),backupXML); - SimpleSettings set; - set.setEntry (QString("undoCommand"),undoCommand); - set.setEntry (QString("undoSelection"),undoSelection); - set.setEntry (QString("redoCommand"),redoCom); - set.setEntry (QString("redoSelection"),redoSelection); - set.setEntry (QString("comment"),comment); - set.writeSettings(QString(bakMapDir+"/commands")); + undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); + 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.writeSettings(histPath); /* TODO remove after testing - cout << " into="<< bakMapDir<activateStandardFlag(s); + } + } + } + else if (com=="unsetFlag") + { + if (selection && typeid(*selection) == typeid(BranchObj) ) + { + if (api.checkParamCount(1) ) + { + s=api.parString(ok,0); + if (ok) ((BranchObj*)selection)->deactivateStandardFlag(s); + } + } + } // Internal commands, used for undo etc. else if (com==QString("undoMap")) { @@ -687,31 +716,6 @@ } } - -void MapEditor::finishedLineEdit() -{ - // This is called by finishedLineEdit or any MapEditor method, - // which wants to assure, that lineedits finish, before e.g. a branch is - // deleted - - // After calling LineEdit and using the clipboard, the - // focus is not any longer on the main widget, we - // have to restore it using parentWidget()->setFocus() - - if (editingBO!=NULL) - { - saveState("setHeading (\""+editingBO->getHeading()+"\")",editingBO, QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(lineedit->text()) ); - editingBO->setHeading(lineedit->text() ); - editingBO=NULL; - lineedit->releaseKeyboard(); - lineedit->hide(); - parentWidget()->setFocus(); - mapCenter->reposition(); - adjustCanvasSize(); - ensureSelectionVisible(); - } -} - void MapEditor::toggleHistoryWindow() { if (historyWindow->isVisible()) @@ -748,9 +752,6 @@ void MapEditor::closeMap() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - // Unselect before disabling the toolbar actions if (selection) selection->unselect(); selection=NULL; @@ -816,9 +817,6 @@ ErrorCode MapEditor::load (QString fname, LoadMode lmode) { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - ErrorCode err=success; if (lmode==NewMap) @@ -830,7 +828,7 @@ // (map state is set later at end of load...) } else { - saveState(selection,"Load map"); + saveStatePart(selection,"Load map"); } @@ -885,9 +883,6 @@ int MapEditor::save (const SaveMode &savemode) { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - int returnCode=0; // The SaveMode UndoCommand is not supported here @@ -935,9 +930,6 @@ void MapEditor::print() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - if ( !printer ) { printer = new QPrinter; @@ -1111,9 +1103,6 @@ void MapEditor::exportImage(QString fn) { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - setExportMode (true); QPixmap pix (getPixmap()); pix.save(fn, "PNG"); @@ -1132,9 +1121,6 @@ void MapEditor::exportImage(QString fn, QString format) { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - setExportMode (true); QPixmap pix (getPixmap()); pix.save(fn, format); @@ -1201,9 +1187,6 @@ void MapEditor::copy() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - if (selection) { // write to directory @@ -1232,124 +1215,134 @@ void MapEditor::redo() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - 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")); + if (redosAvail>0) redosAvail--; + if (undosAvailundosTotal) 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)); + // Find out current undo directory - QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum)); - - // Restore variables - QString undoCommand; - QString undoSelection; - QString redoCommand; - QString redoSelection; - SimpleSettings set; - set.readSettings(QString(bakMapDir+"/commands")); - undoCommand=set.readEntry ("undoCommand"); - undoSelection=set.readEntry ("undoSelection"); - redoCommand=set.readEntry ("redoCommand"); - redoSelection=set.readEntry ("redoSelection"); + QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); + +/* TODO remove testing +*/ + cout << "ME::redo() begin\n"; + cout << " undosAvail="<reposition(); + + //if (!redoSelection.isEmpty()) + // select (redoSelection); + + blockSaveState=false; /* TODO remove testing - cout << "ME::redo() begin\n"; - cout << " undosTotal="<reposition(); //if (!redoSelection.isEmpty()) // select (redoSelection); + undosAvail--; if (undosAvail<1) // Undo not longer available now actionEditUndo->setEnabled (false); else - undoNum--; if (undoNum<1) undoNum=undosTotal; + curStep--; if (curStep<1) curStep=undosTotal; + + redosAvail++; blockSaveState=false; /* TODO remove testing - cout << "ME::redo() end\n"; - cout << " undosAvail="<reposition(); - - //if (!redoSelection.isEmpty()) - // select (redoSelection); - - undosAvail--; - if (undosAvail<1) - // Undo not longer available now - actionEditUndo->setEnabled (false); - else - undoNum--; if (undoNum<1) undoNum=undosTotal; - - blockSaveState=false; -/* TODO remove testing +*/ cout << "ME::undo() end\n"; cout << " undosAvail="<reposition(); adjustCanvasSize(); @@ -1426,7 +1416,7 @@ void MapEditor::cut() { - saveState(selection->getParObj(),QString("Cut %1").arg(getName(selection))); + saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection))); copy(); cutNoSave(); mapCenter->reposition(); @@ -1443,9 +1433,6 @@ void MapEditor::moveBranchUp() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - BranchObj* bo; BranchObj* par; if (typeid(*selection) == typeid(BranchObj) ) @@ -1456,7 +1443,7 @@ selection->unselect(); selection=par->moveBranchUp (bo); selection->select(); - saveState("moveBranchDown ()",bo,QString("Move up %1").arg(getName(bo))); + saveStateX(bo,"moveBranchDown ()",QString("Move up %1").arg(getName(bo))); mapCenter->reposition(); ensureSelectionVisible(); } @@ -1464,9 +1451,6 @@ void MapEditor::moveBranchDown() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - BranchObj* bo; BranchObj* par; if (typeid(*selection) == typeid(BranchObj) ) @@ -1477,7 +1461,7 @@ selection->unselect(); selection=par->moveBranchDown(bo); selection->select(); - saveState("moveBranchUp ()",bo,QString("Move down %1").arg(getName(bo))); + saveStateX(bo,"moveBranchUp ()",QString("Move down %1").arg(getName(bo))); mapCenter->reposition(); ensureSelectionVisible(); } @@ -1485,32 +1469,56 @@ void MapEditor::editHeading() { - // Finish open lineEdits - if (lineedit->isVisible()) - { - finishedLineEdit(); - return; - } - +/* FIXME not needed any longer if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj) ) ) { editingBO=(BranchObj*)selection; - ensureSelectionVisible(); QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y())); - lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25); - QString s=editingBO->getHeading(); - lineedit->setText(s); - lineedit->setCursorPosition(1); - if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() ) - lineedit->selectAll(); - lineedit->show(); - lineedit->setFocus(); - lineedit->grabKeyboard(); - cout << "le="<getHeading()+"\")", + "setHeading (\""+le->text()+"\")", + QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(le->text()) ); + editingBO->setHeading(le->text() ); + editingBO=NULL; + mapCenter->reposition(); + adjustCanvasSize(); + ensureSelectionVisible(); + activateWindow(); + } +*/ +} + +QString MapEditor::getHeading(bool &ok, QPoint &p) +{ + if (selection && + (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj) ) ) + { + ok=true; + ensureSelectionVisible(); + p = ((BranchObj*)selection)->getAbsPos(); + p.setY(p.y()+((BranchObj*)selection)->height()/2); +// p = mapTo(mainWindow,worldMatrix().map( p)); + return ((BranchObj*)selection)->getHeading(); + } + ok=false; + return QString(); } void MapEditor::setHeading(const QString &s) @@ -1520,14 +1528,20 @@ (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj) ) ) { - ((BranchObj*)selection)->setHeading(s); + editingBO=(BranchObj*)selection; + saveStateConstSelection( + "setHeading (\""+editingBO->getHeading()+"\")", + "setHeading (\""+s+"\")", + QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) ); + editingBO->setHeading(s ); + editingBO=NULL; mapCenter->reposition(); adjustCanvasSize(); ensureSelectionVisible(); } } -void MapEditor::setURL (const QString &s) +void MapEditor::setURLInt (const QString &s) { // Internal function, no saveState needed if (selection && @@ -1541,7 +1555,20 @@ } } -void MapEditor::setVymLink (const QString &s) +void MapEditor::setHeadingInt(const QString &s) +{ + if (selection && + (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj) ) ) + { + ((BranchObj*)selection)->setHeading(s); + mapCenter->reposition(); + adjustCanvasSize(); + ensureSelectionVisible(); + } +} + +void MapEditor::setVymLinkInt (const QString &s) { // Internal function, no saveState needed if (selection && @@ -1557,15 +1584,11 @@ void MapEditor::addNewBranch(int pos) { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj) ) ) { BranchObj* bo1 = (BranchObj*) selection; - saveState(selection, QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand bool wasScrolled=false; BranchObj *newbo=NULL; @@ -1588,14 +1611,65 @@ newbo=parbo->insertBranch(bo1->getNum()+1); } else // This should not happen... + // ...but it happens if CTRL-A is pressed on MCO, + // ignore it then return; - } + saveStateX(selection,QString ("delete (\"%1\")").arg(newbo->getSelectString()),QString("Add new branch to %1").arg(getName(bo1))); //TODO undoCommand LinkableMapObj *oldselection=selection; mapCenter->reposition(); adjustCanvasSize(); + + + if (actionSettingsAutoedit->isOn() || + actionSettingsAutoselectHeading->isOn() ) + { + selection->unselect(); + selection=newbo; + selection->select(); + if (actionSettingsPasteNewHeading->isOn() ) + { + BranchObj *bo2= (BranchObj*)selection; + bo2->setHeading(""); + } + if (actionSettingsAutoedit->isOn() ) + mainWindow->editHeading(); + if (!actionSettingsAutoselectHeading->isOn() + && !wasScrolled) + { + selection->unselect(); + selection=oldselection; + selection->select(); + } + } + } +} + + +void MapEditor::addNewBranchHere() +{ + if (selection && + (typeid(*selection) == typeid(BranchObj) ) ) + { + BranchObj* bo1 = (BranchObj*) selection; + saveStatePart(selection, QString("Add new branch here").arg(getName(bo1))); + + bool wasScrolled=false; + BranchObj *newbo=NULL; + BranchObj *parbo=(BranchObj*)(selection->getParObj()); + if (parbo) + { + // add below selection + newbo=parbo->insertBranch(bo1->getNum()+1); + } + + LinkableMapObj *oldselection=selection; + ((BranchObj*)selection)->moveBranchTo (newbo,-1); + + mapCenter->reposition(); + adjustCanvasSize(); if (actionSettingsAutoedit->isOn() || actionSettingsAutoselectHeading->isOn() ) { @@ -1620,61 +1694,8 @@ } } - -void MapEditor::addNewBranchHere() -{ - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - - if (selection && - (typeid(*selection) == typeid(BranchObj) ) ) - { - BranchObj* bo1 = (BranchObj*) selection; - saveState(selection, QString("Add new branch here").arg(getName(bo1))); - - bool wasScrolled=false; - BranchObj *newbo=NULL; - BranchObj *parbo=(BranchObj*)(selection->getParObj()); - if (parbo) - { - // add below selection - newbo=parbo->insertBranch(bo1->getNum()+1); - } - - LinkableMapObj *oldselection=selection; - ((BranchObj*)selection)->moveBranchTo (newbo,-1); - - mapCenter->reposition(); - adjustCanvasSize(); - if (actionSettingsAutoedit->isOn() || - actionSettingsAutoselectHeading->isOn() ) - { - selection->unselect(); - selection=newbo; - selection->select(); - if (actionSettingsPasteNewHeading->isOn() ) - { - BranchObj *bo2= (BranchObj*)selection; - bo2->setHeading(""); - } - if (actionSettingsAutoedit->isOn() ) - editHeading(); - if (!actionSettingsAutoselectHeading->isOn() - && !wasScrolled) - { - selection->unselect(); - selection=oldselection; - selection->select(); - } - } - } -} - void MapEditor::deleteSelection() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - if (selection && typeid(*selection) ==typeid(BranchObj) ) { BranchObj* bo=dynamic_cast (selection); @@ -1682,12 +1703,12 @@ bo->unselect(); if (selection->getDepth()>1) // Normal branch, save parent with childs - saveState(par,QString("Delete %1").arg(getName(bo))); + saveStatePart(par,QString("Delete %1").arg(getName(bo))); else // Mainbranch, save whole map // TODO Better would be to insert mainbranch again at pos // But undoCommand is missing right now - saveState(QString("Delete %1").arg(getName(bo))); + saveStateComplete(QString("Delete %1").arg(getName(bo))); selection=NULL; par->removeBranch(bo); selection=par; @@ -1700,7 +1721,7 @@ { FloatImageObj* fio=dynamic_cast (selection); BranchObj* par=(BranchObj*)(fio->getParObj()); - saveState(par, QString("Delete %1").arg(getName(fio))); + saveStatePart(par, QString("Delete %1").arg(getName(fio))); fio->unselect(); selection=NULL; par->removeFloatImage(fio); @@ -1754,7 +1775,7 @@ return false; } -void MapEditor::select (LinkableMapObj *lmo) +void MapEditor::selectInt (LinkableMapObj *lmo) { if (lmo && selection != lmo) { @@ -1768,7 +1789,7 @@ } -void MapEditor::selectNextBranch() +void MapEditor::selectNextBranchInt() { // Increase number of branch if (selection) @@ -1848,7 +1869,7 @@ } } -void MapEditor::selectPrevBranch() +void MapEditor::selectPrevBranchInt() { // Decrease number of branch if (selection) @@ -1929,40 +1950,34 @@ void MapEditor::selectUpperBranch() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - if (selection) { if (typeid(*selection) == typeid(BranchObj)) { if (selection->getOrientation()==OrientRightOfCenter) - selectPrevBranch(); + selectPrevBranchInt(); else if (selection->getDepth()==1) - selectNextBranch(); + selectNextBranchInt(); else - selectPrevBranch(); + selectPrevBranchInt(); } } } void MapEditor::selectLowerBranch() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - if (selection) { if (typeid(*selection) == typeid(BranchObj)) { if (selection->getOrientation()==OrientRightOfCenter) - selectNextBranch(); + selectNextBranchInt(); else if (selection->getDepth()==1) - selectPrevBranch(); + selectPrevBranchInt(); else - selectNextBranch(); + selectNextBranchInt(); } } } @@ -1970,9 +1985,6 @@ void MapEditor::selectLeftBranch() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - BranchObj* bo; BranchObj* par; if (selection) @@ -2032,9 +2044,6 @@ void MapEditor::selectRightBranch() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - BranchObj* bo; BranchObj* par; @@ -2046,7 +2055,7 @@ bo=par->getLastSelectedBranch(); if (bo) { - // Workaround for relecting on left and right side + // Workaround for reselecting on left and right side if (bo->getOrientation()==OrientLeftOfCenter) bo=par->getFirstBranch(); if (bo) @@ -2092,9 +2101,6 @@ void MapEditor::selectFirstBranch() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - BranchObj *bo1; BranchObj *bo2; BranchObj* par; @@ -2117,9 +2123,6 @@ void MapEditor::selectLastBranch() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - BranchObj *bo1; BranchObj *bo2; BranchObj* par; @@ -2147,13 +2150,11 @@ void MapEditor::selectBackgroundColor() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this ); if ( !col.isValid() ) return; setBackgroundColor( col ); - saveState(QString("Set background color of map to %1").arg(col.name())); + //TODO undocomm + saveStateComplete(QString("Set background color of map to %1").arg(col.name())); } void MapEditor::setBackgroundColor(QColor c) @@ -2183,7 +2184,7 @@ typeid(*selection) == typeid(MapCenterObj)) { BranchObj *bo=(BranchObj*)selection; - saveState(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand + saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand bo->setColor(actColor); // color branch } } @@ -2197,7 +2198,7 @@ typeid(*selection) == typeid(MapCenterObj)) { BranchObj *bo=(BranchObj*)selection; - saveState(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand + saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand bo->setColorChilds(actColor); // color links, color childs } } @@ -2212,12 +2213,20 @@ typeid(*selection) == typeid(MapCenterObj)) { BranchObj *bo=(BranchObj*)selection; - QString s; + QString u,r; if (bo->isSetStandardFlag(f)) - s="Unset"; + { + r="unsetFlag"; + u="setFlag"; + } else - s="Set"; - saveState(selection, QString("%1 standard flag \"%2\" of %3").arg(s).arg(f).arg(getName(bo)));// TODO undoCommand + { + u="unsetFlag"; + r="setFlag"; + } + saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f), + QString("%1 (\"%2\")").arg(r).arg(f), + QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn()); adjustCanvasSize(); } @@ -2311,7 +2320,7 @@ if ( ok) { // user entered something and pressed OK - saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text)); + saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text)); bo->setURL (text); updateActions(); } @@ -2333,7 +2342,7 @@ typeid(*selection) == typeid(MapCenterObj)) ) { BranchObj *bo=(BranchObj*)selection; - saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo))); + saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo))); bo->setURL (bo->getHeading()); updateActions(); } @@ -2346,7 +2355,7 @@ { BranchObj *bo=(BranchObj*)selection; QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); - saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo))); + saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo))); bo->setURL (url); updateActions(); } @@ -2359,7 +2368,7 @@ { BranchObj *bo=(BranchObj*)selection; QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); - saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo))); + saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo))); bo->setURL (url); updateActions(); } @@ -2381,7 +2390,7 @@ QString fn; if ( fd->exec() == QDialog::Accepted ) { - saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())); + saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())); bo->setVymLink (fd->selectedFile() ); updateActions(); mapCenter->reposition(); @@ -2397,7 +2406,7 @@ typeid(*selection) == typeid(MapCenterObj)) ) { BranchObj *bo=(BranchObj*)selection; - saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo))); + saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo))); bo->setVymLink ("" ); updateActions(); mapCenter->reposition(); @@ -2425,7 +2434,7 @@ oo->setHideInExport(true); s="Set"; } - saveState(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand + saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand actionEditToggleHideExport->setOn (oo->hideInExport()); updateActions(); mapCenter->reposition(); @@ -2453,9 +2462,9 @@ BranchObj* par=(BranchObj*)(bo->getParObj()); QString s=QString("Remove %1 and keep its childs").arg(getName(bo)); if (bo->getDepth()==1) - saveState(s); + saveStateComplete(s); else - saveState(selection->getParObj(),s); // TODO undoCommand + saveStatePart(selection->getParObj(),s); // TODO undoCommand QString sel=selection->getSelectString(); unselect(); par->removeBranchHere(bo); @@ -2468,7 +2477,7 @@ { if (selection && (typeid(*selection) == typeid(BranchObj) )) { - saveState(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection))); + saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection))); ((BranchObj*)selection)->removeChilds(); mapCenter->reposition(); } @@ -2512,7 +2521,7 @@ // Finally show dialog if (dia.exec() == QDialog::Accepted) { - saveState("Edit info about map"); //TODO undoCommand + saveStateComplete("Edit info about map"); //TODO undoCommand mapCenter->setAuthor (dia.getAuthor() ); mapCenter->setComment (dia.getComment() ); } @@ -2550,8 +2559,16 @@ pix.fill( defLinkColor ); actionFormatLinkColor->setIconSet( pix ); - actionEditUndo->setEnabled( mapChanged ); actionFileSave->setEnabled( mapUnsaved ); + if (undoSet.readNumEntry("/history/undosAvail",0)>0) + actionEditUndo->setEnabled( true); + else + actionEditUndo->setEnabled( false); + + if (undoSet.readNumEntry("/history/redosAvail",0)>0) + actionEditRedo->setEnabled( true); + else + actionEditRedo->setEnabled( false); if (selection) { @@ -2710,7 +2727,7 @@ { linkstyle=ls; - saveState("Set link style"); // TODO undoCommand + saveStateComplete("Set link style"); // TODO undoCommand BranchObj *bo; bo=mapCenter->first(); bo=bo->next(); @@ -2798,13 +2815,10 @@ void MapEditor::selectLinkColor() { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - QColor col = QColorDialog::getColor( defLinkColor, this ); if ( !col.isValid() ) return; setLinkColor( col ); - saveState(QString("Set link color to %1").arg(col.name())); //TODO undoCommand + saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand } @@ -2820,7 +2834,7 @@ s="Unscroll"; else s="Scroll"; - saveState(selection, QString ("%1 %2").arg(s).arg(getName(bo))); + saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo))); bo->toggleScroll(); adjustCanvasSize(); canvas()->update(); @@ -2860,7 +2874,7 @@ QString fn; if ( fd->exec() == QDialog::Accepted ) { - saveState(selection, QString("Add floatimage to %1").arg(getName(selection))); + saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection))); // FIXME in QT4 use: lastImageDir=fd->directory(); lastImageDir=QDir (fd->dirPath()); QStringList flist = fd->selectedFiles(); @@ -2968,7 +2982,7 @@ selection->setHideLinkUnselected(b); } -void MapEditor::importDir(BranchObj *dst, QDir d) +void MapEditor::importDirInt(BranchObj *dst, QDir d) { if (selection && (typeid(*selection) == typeid(BranchObj)) || @@ -2996,7 +3010,7 @@ else { // Recursively add subdirs - importDir (bo,d); + importDirInt (bo,d); d.cdUp(); } } @@ -3034,7 +3048,7 @@ if ( fd->exec() == QDialog::Accepted ) { BranchObj *bo=((BranchObj*)selection); - importDir (bo,QDir(fd->selectedFile()) ); + importDirInt (bo,QDir(fd->selectedFile()) ); mapCenter->reposition(); adjustCanvasSize(); canvas()->update(); @@ -3061,7 +3075,7 @@ void MapEditor::editXLink(int i) { - qDebug ("ko."); + qDebug ("ko."); //FIXME Huh? if (selection && (typeid(*selection) == typeid(BranchObj)) || (typeid(*selection) == typeid(MapCenterObj)) ) @@ -3081,7 +3095,7 @@ } if (dia.deleteXLink()) ((BranchObj*)selection)->deleteXLinkAt(i); - saveState("Edit xLink"); //TODO undoCommand + saveStateComplete("Edit xLink"); //TODO undoCommand } } } @@ -3091,32 +3105,43 @@ { cout << "MapEditor::testFunction() called\n"; - mapCenter->positionBBox(); +/* + bool ok; + QString text = QInputDialog::getText( + this, + tr("QInputDialog::getText()"), + tr("User name:"), QLineEdit::Normal, + QDir::home().dirName(), &ok, Qt::FramelessWindowHint); +*/ + + QDialog *d =new QDialog(NULL); + QLineEdit *le=new QLineEdit (d); +// d->setModal (true); + d->setWindowFlags (Qt::FramelessWindowHint); + le->setFocus(); + le->setText ("Foo"); + le->selectAll(); + connect (le, SIGNAL (returnPressed()), d, SLOT (accept())); + d->exec(); + qWarning( le->text()); return; - + + + +/* WarningDialog dia; dia.setCancelButton (true); dia.setText("This is a longer \nWarning"); dia.setCaption("Warning: Flux problem"); dia.setShowAgainName("/warnings/mapeditor"); + dia.setWindowFlags (Qt::FramelessWindowHint); if (dia.exec()==QDialog::Accepted) cout << "accepted!\n"; else cout << "canceled!\n"; return; - - QString ub=vymBaseDir.path()+"/scripts/update-bookmarks"; - - QProcess *proc= new QProcess (this); - proc->start( ub); - if (!proc->waitForStarted()); - { - QMessageBox::warning(0, - tr("Warning"), - tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub)); - } - - +*/ + /* Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone) { @@ -3222,9 +3247,6 @@ return; } - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - QPoint p = inverseWorldMatrix().map(e->pos()); LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); @@ -3239,7 +3261,7 @@ if (!foname.isEmpty()) { // systemFlag clicked - select (lmo); + selectInt (lmo); if (foname=="url") { if (e->state() & Qt::ControlModifier) @@ -3297,7 +3319,7 @@ } if (lmo) { - select (lmo); + selectInt (lmo); // Left Button Move Branches if (e->button() == Qt::LeftButton ) { @@ -3370,7 +3392,7 @@ if (typeid(*selection) == typeid(FloatImageObj)) { FloatObj *fo=(FloatObj*)selection; - saveState( + saveStateConstSelection( "move "+qpointToString(movingObj_orgPos),fo->getSelectString() , QString("Move %1").arg(getName(selection))); fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); @@ -3387,7 +3409,8 @@ { if (typeid(*fo) == typeid(FloatImageObj)) { - saveState(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) ); + //TODO undocom + saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) ); FloatImageObj *fio=(FloatImageObj*)(fo); ((BranchObj*)(lmo))->addFloatImage (fio); fio->unselect(); @@ -3513,7 +3536,7 @@ tmpXLink->setEnd ( ((BranchObj*)(dst)) ); tmpXLink->updateXLink(); tmpXLink->activate(); - saveState(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand + saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand } else { delete(tmpXLink); @@ -3578,11 +3601,11 @@ if (dst->getDepth()==0) bs->move (savePos); } - saveState (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) ); + saveStateConstSelection (undoCom,bs->getSelectString(),QString("Relink %1 to %2").arg(getName(bs)).arg(getName(dst)) ); } else if (selection->getDepth()==1) // If we have moved mainbranch only save endposition - saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos))); + saveStateConstSelection("move "+qpointToString(movingObj_orgPos), selection->getSelectString(), QString("Move %1 to %2").arg(getName(selection)).arg(qpointToString(movingObj_orgPos))); // Draw the original link, before selection was moved around mapCenter->reposition(); @@ -3599,9 +3622,6 @@ void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e) { - // Finish open lineEdits - if (lineedit) finishedLineEdit(); - if (e->button() == Qt::LeftButton ) { QPoint p = inverseWorldMatrix().map(e->pos()); @@ -3782,7 +3802,7 @@ if (update) { //FIXME saveState has to be called earlier for each of the drops... - saveState("Drop Event"); //TODO undo Command + saveStateComplete("Drop Event"); //TODO undo Command mapCenter->reposition(); adjustCanvasSize(); canvas()->update(); @@ -3797,7 +3817,7 @@ (typeid(*selection) == typeid(MapCenterObj)) ) { BranchObj *bo=((BranchObj*)selection); - saveState(selection,QString("Add floatimage to %1").arg(getName(bo))); + saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo))); //QString fn=fd->selectedFile(); //lastImageDir=fn.left(fn.findRev ("/")); bo->addFloatImage();