insilmaril@0: #include "mapeditor.h" insilmaril@0: insilmaril@374: #include insilmaril@0: insilmaril@0: #include insilmaril@95: #include insilmaril@0: #include insilmaril@0: insilmaril@432: #include "parser.h" insilmaril@175: #include "editxlinkdialog.h" insilmaril@175: #include "exports.h" insilmaril@517: #include "exportxhtmldialog.h" insilmaril@175: #include "extrainfodialog.h" insilmaril@236: #include "file.h" insilmaril@175: #include "linkablemapobj.h" insilmaril@175: #include "mainwindow.h" insilmaril@175: #include "misc.h" insilmaril@175: #include "texteditor.h" insilmaril@314: #include "warningdialog.h" insilmaril@571: #include "xml-freemind.h" insilmaril@571: #include "xml-vym.h" insilmaril@0: insilmaril@0: insilmaril@0: extern TextEditor *textEditor; insilmaril@0: extern int statusbarTime; insilmaril@0: extern Main *mainWindow; insilmaril@164: extern QString tmpVymDir; insilmaril@166: extern QString clipboardDir; insilmaril@491: extern QString clipboardFile; insilmaril@166: extern bool clipboardEmpty; insilmaril@473: extern bool debug; insilmaril@0: extern FlagRowObj *standardFlagsDefault; insilmaril@0: insilmaril@366: extern QMenu* branchContextMenu; insilmaril@366: extern QMenu* branchAddContextMenu; insilmaril@366: extern QMenu* branchRemoveContextMenu; insilmaril@366: extern QMenu* branchLinksContextMenu; insilmaril@366: extern QMenu* branchXLinksContextMenuEdit; insilmaril@366: extern QMenu* branchXLinksContextMenuFollow; insilmaril@366: extern QMenu* floatimageContextMenu; insilmaril@366: extern QMenu* canvasContextMenu; insilmaril@366: insilmaril@0: insilmaril@0: extern Settings settings; insilmaril@366: extern ImageIO imageIO; insilmaril@0: insilmaril@404: extern QString vymName; insilmaril@404: extern QString vymVersion; insilmaril@404: insilmaril@269: extern QString iconPath; insilmaril@301: extern QDir vymBaseDir; insilmaril@366: extern QDir lastImageDir; insilmaril@421: extern QDir lastFileDir; insilmaril@269: insilmaril@164: int MapEditor::mapNum=0; // make instance insilmaril@0: insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@408: MapEditor::MapEditor( QWidget* parent) : insilmaril@473: QGraphicsView(parent) insilmaril@0: { insilmaril@0: //cout << "Constructor ME "<setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern)); insilmaril@408: insilmaril@645: model=new VymModel(); insilmaril@645: model->setScene (mapScene); insilmaril@645: model->setMapEditor (this); insilmaril@408: insilmaril@408: setScene (mapScene); insilmaril@0: insilmaril@0: printer=NULL; insilmaril@0: insilmaril@97: defLinkColor=QColor (0,0,255); insilmaril@97: defXLinkColor=QColor (180,180,180); insilmaril@473: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@473: linkstyle=LinkableMapObj::PolyParabel; insilmaril@0: insilmaril@366: // Create bitmap cursors, platform dependant insilmaril@404: HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1); insilmaril@404: PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); insilmaril@404: CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 1,1 ); insilmaril@404: XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 1,7 ); insilmaril@398: insilmaril@398: setFocusPolicy (Qt::StrongFocus); insilmaril@0: insilmaril@0: pickingColor=false; insilmaril@91: drawingLink=false; insilmaril@93: copyingObj=false; insilmaril@0: insilmaril@0: editingBO=NULL; insilmaril@0: movingObj=NULL; insilmaril@0: insilmaril@645: xelection.setModel (model); insilmaril@424: xelection.unselect(); insilmaril@366: insilmaril@102: defXLinkWidth=1; insilmaril@102: defXLinkColor=QColor (230,230,230); insilmaril@102: insilmaril@0: mapChanged=false; insilmaril@0: mapDefault=true; insilmaril@0: mapUnsaved=false; insilmaril@0: insilmaril@0: zipped=true; insilmaril@0: filePath=""; insilmaril@294: fileName=tr("unnamed"); insilmaril@0: mapName=""; insilmaril@0: insilmaril@398: stepsTotal=settings.readNumEntry("/mapeditor/stepsTotal",100); insilmaril@381: undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal)); insilmaril@491: mainWindow->updateHistory (undoSet); insilmaril@163: insilmaril@0: // Initialize find routine insilmaril@0: itFind=NULL; insilmaril@0: EOFind=false; insilmaril@0: insilmaril@0: printFrame=true; insilmaril@0: printFooter=true; insilmaril@0: insilmaril@139: blockReposition=false; insilmaril@139: blockSaveState=false; insilmaril@260: insilmaril@628: hidemode=HideNone; insilmaril@260: insilmaril@377: // Create temporary files insilmaril@377: makeTmpDirs(); insilmaril@0: insilmaril@502: curStep=0; insilmaril@502: redosAvail=0; insilmaril@502: undosAvail=0; insilmaril@502: insilmaril@417: setAcceptDrops (true); insilmaril@0: insilmaril@645: model->reposition(); insilmaril@381: insilmaril@473: // TODO animations insilmaril@473: animObjList.clear(); insilmaril@473: //timerId = startTimer(100); insilmaril@473: insilmaril@473: // autosave insilmaril@473: autosaveTimer=new QTimer (this); insilmaril@473: connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave())); insilmaril@531: insilmaril@531: // Network insilmaril@531: netstate=Offline; insilmaril@628: insilmaril@638: // Attributes //FIXME testing only... insilmaril@638: QString k; insilmaril@638: AttributeDef *ad; insilmaril@628: attrTable= new AttributeTable(); insilmaril@638: k="A - StringList"; insilmaril@638: ad=attrTable->addKey (k,StringList); insilmaril@638: if (ad) insilmaril@638: { insilmaril@638: QStringList sl; insilmaril@638: sl <<"val 1"<<"val 2"<< "val 3"; insilmaril@638: ad->setValue (QVariant (sl)); insilmaril@638: } insilmaril@638: //attrTable->addValue ("Key A","P 1"); insilmaril@638: //attrTable->addValue ("Key A","P 2"); insilmaril@638: //attrTable->addValue ("Key A","P 3"); insilmaril@638: //attrTable->addValue ("Key A","P 4"); insilmaril@638: k="B - FreeString"; insilmaril@638: ad=attrTable->addKey (k,FreeString); insilmaril@638: if (ad) insilmaril@638: { insilmaril@638: //attrTable->addValue ("Key B","w1"); insilmaril@638: //attrTable->addValue ("Key B","w2"); insilmaril@638: } insilmaril@638: k="C - UniqueString"; insilmaril@638: ad=attrTable->addKey (k,UniqueString); insilmaril@638: if (ad) insilmaril@638: { insilmaril@638: //attrTable->addKey ("Key Prio"); insilmaril@638: //attrTable->addValue ("Key Prio","Prio 1"); insilmaril@638: //attrTable->addValue ("Key Prio","Prio 2"); insilmaril@638: } insilmaril@0: } insilmaril@0: insilmaril@0: MapEditor::~MapEditor() insilmaril@0: { insilmaril@0: //cout <<"Destructor MapEditor\n"; insilmaril@473: autosaveTimer->stop(); insilmaril@625: insilmaril@625: // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes insilmaril@625: insilmaril@625: //removeDir(QDir(tmpMapDir)); insilmaril@645: delete (model); insilmaril@0: } insilmaril@0: insilmaril@645: VymModel* MapEditor::getModel() insilmaril@0: { insilmaril@645: return model; insilmaril@0: } insilmaril@0: insilmaril@408: QGraphicsScene * MapEditor::getScene() insilmaril@0: { insilmaril@408: return mapScene; insilmaril@0: } insilmaril@0: insilmaril@491: MapEditor::State MapEditor::getState() insilmaril@491: { insilmaril@491: return state; insilmaril@491: } insilmaril@491: insilmaril@491: void MapEditor::setStateEditHeading(bool s) insilmaril@491: { insilmaril@491: if (s) insilmaril@491: { insilmaril@491: if (state==Idle) state=EditHeading; insilmaril@491: } insilmaril@491: else insilmaril@491: state=Idle; insilmaril@491: } insilmaril@491: insilmaril@139: bool MapEditor::isRepositionBlocked() insilmaril@0: { insilmaril@139: return blockReposition; insilmaril@0: } insilmaril@0: insilmaril@473: void MapEditor::setSaveStateBlocked(bool b) insilmaril@473: { insilmaril@473: blockSaveState=b; insilmaril@473: } insilmaril@473: insilmaril@491: bool MapEditor::isSelectBlocked() insilmaril@491: { insilmaril@491: if (state==EditHeading) insilmaril@491: return true; insilmaril@491: else insilmaril@491: return false; insilmaril@491: } insilmaril@491: insilmaril@420: QString MapEditor::getName (const LinkableMapObj *lmo) insilmaril@294: { insilmaril@314: QString s; insilmaril@314: if (!lmo) return QString("Error: NULL has no name!"); insilmaril@294: insilmaril@294: if ((typeid(*lmo) == typeid(BranchObj) || insilmaril@294: typeid(*lmo) == typeid(MapCenterObj))) insilmaril@314: { insilmaril@314: insilmaril@314: s=(((BranchObj*)lmo)->getHeading()); insilmaril@314: if (s=="") s="unnamed"; insilmaril@377: return QString("branch (%1)").arg(s); insilmaril@314: } insilmaril@294: if ((typeid(*lmo) == typeid(FloatImageObj) )) insilmaril@377: return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); insilmaril@294: return QString("Unknown type has no name!"); insilmaril@294: } insilmaril@294: insilmaril@0: void MapEditor::makeTmpDirs() insilmaril@0: { insilmaril@0: // Create unique temporary directories insilmaril@625: tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum); insilmaril@625: histPath = tmpMapDir+"/history"; insilmaril@164: QDir d; insilmaril@377: d.mkdir (tmpMapDir); insilmaril@0: } insilmaril@0: insilmaril@408: QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel) insilmaril@0: { insilmaril@163: // tmpdir temporary directory to which data will be written insilmaril@0: // prefix mapname, which will be appended to images etc. insilmaril@0: // writeflags Only write flags for "real" save of map, not undo insilmaril@408: // offset offset of bbox of whole map in scene. insilmaril@0: // Needed for XML export insilmaril@0: insilmaril@0: // Save Header insilmaril@0: QString ls; insilmaril@0: switch (linkstyle) insilmaril@0: { insilmaril@473: case LinkableMapObj::Line: insilmaril@0: ls="StyleLine"; insilmaril@0: break; insilmaril@473: case LinkableMapObj::Parabel: insilmaril@0: ls="StyleParabel"; insilmaril@0: break; insilmaril@473: case LinkableMapObj::PolyLine: insilmaril@0: ls="StylePolyLine"; insilmaril@0: break; insilmaril@0: default: insilmaril@0: ls="StylePolyParabel"; insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: QString s="\n"; insilmaril@0: QString colhint=""; insilmaril@473: if (linkcolorhint==LinkableMapObj::HeadingColor) insilmaril@0: colhint=attribut("linkColorHint","HeadingColor"); insilmaril@0: insilmaril@404: QString mapAttr=attribut("version",vymVersion); insilmaril@645: if (!saveSel) insilmaril@645: mapAttr+= attribut("author",model->getAuthor()) + insilmaril@645: attribut("comment",model->getComment()) + insilmaril@645: attribut("date",model->getDate()) + insilmaril@408: attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + insilmaril@442: attribut("selectionColor", xelection.getColor().name() ) + insilmaril@0: attribut("linkStyle", ls ) + insilmaril@97: attribut("linkColor", defLinkColor.name() ) + insilmaril@102: attribut("defXLinkColor", defXLinkColor.name() ) + insilmaril@102: attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) + insilmaril@0: colhint; insilmaril@0: s+=beginElement("vymmap",mapAttr); insilmaril@0: incIndent(); insilmaril@0: insilmaril@0: // Find the used flags while traversing the tree insilmaril@0: standardFlagsDefault->resetUsedCounter(); insilmaril@0: insilmaril@166: // Reset the counters before saving insilmaril@406: // TODO constr. of FIO creates lots of objects, better do this in some other way... insilmaril@408: FloatImageObj (mapScene).resetSaveCounter(); insilmaril@166: insilmaril@0: // Build xml recursivly insilmaril@398: if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj)) insilmaril@366: // Save complete map, if saveSel not set insilmaril@645: s+=model->saveToDir(tmpdir,prefix,writeflags,offset); insilmaril@0: else insilmaril@0: { insilmaril@366: if ( typeid(*saveSel) == typeid(BranchObj) ) insilmaril@366: // Save Subtree insilmaril@366: s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); insilmaril@366: else if ( typeid(*saveSel) == typeid(FloatImageObj) ) insilmaril@366: // Save image insilmaril@377: s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix); insilmaril@0: } insilmaril@0: insilmaril@0: // Save local settings insilmaril@616: s+=settings.getDataXML (destPath); insilmaril@0: insilmaril@0: // Save selection insilmaril@424: if (!xelection.isEmpty() && !saveSel ) insilmaril@424: s+=valueElement("select",xelection.getSelectString()); insilmaril@0: insilmaril@0: decIndent(); insilmaril@0: s+=endElement("vymmap"); insilmaril@0: insilmaril@0: if (writeflags) insilmaril@0: standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags); insilmaril@0: return s; insilmaril@0: } insilmaril@0: insilmaril@505: QString MapEditor::getHistoryDir() insilmaril@505: { insilmaril@625: QString histName(QString("history-%1").arg(curStep)); insilmaril@625: return (tmpMapDir+"/"+histName); insilmaril@505: } insilmaril@505: insilmaril@486: void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) insilmaril@486: { insilmaril@528: sendData(redoCom); //FIXME testing insilmaril@528: insilmaril@486: // Main saveState insilmaril@486: insilmaril@528: insilmaril@486: if (blockSaveState) return; insilmaril@486: insilmaril@486: if (debug) cout << "ME::saveState() for "<stepsTotal) curStep=1; insilmaril@486: insilmaril@486: QString backupXML=""; insilmaril@505: QString histDir=getHistoryDir(); insilmaril@625: QString bakMapPath=histDir+"/map.xml"; insilmaril@505: insilmaril@505: // Create histDir if not available insilmaril@505: QDir d(histDir); insilmaril@486: if (!d.exists()) insilmaril@505: makeSubDirs (histDir); insilmaril@486: insilmaril@486: // Save depending on how much needs to be saved insilmaril@486: if (saveSel) insilmaril@505: backupXML=saveToDir (histDir,mapName+"-",false, QPointF (),saveSel); insilmaril@486: insilmaril@486: QString undoCommand=""; insilmaril@486: if (savemode==UndoCommand) insilmaril@486: { insilmaril@486: undoCommand=undoCom; insilmaril@486: } insilmaril@486: else if (savemode==PartOfMap ) insilmaril@486: { insilmaril@486: undoCommand=undoCom; insilmaril@486: undoCommand.replace ("PATH",bakMapPath); insilmaril@486: } insilmaril@486: insilmaril@486: if (!backupXML.isEmpty()) insilmaril@486: // Write XML Data to disk insilmaril@625: saveStringToDisk (bakMapPath,backupXML); insilmaril@486: insilmaril@486: // We would have to save all actions in a tree, to keep track of insilmaril@486: // possible redos after a action. Possible, but we are too lazy: forget about redos. insilmaril@486: redosAvail=0; insilmaril@486: insilmaril@486: // Write the current state to disk insilmaril@486: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@486: undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); insilmaril@486: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@486: undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand); insilmaril@486: undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection); insilmaril@486: undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom); insilmaril@486: undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection); insilmaril@486: undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment); insilmaril@486: undoSet.setEntry (QString("/history/version"),vymVersion); insilmaril@486: undoSet.writeSettings(histPath); insilmaril@486: insilmaril@486: if (debug) insilmaril@486: { insilmaril@486: // TODO remove after testing insilmaril@486: //cout << " into="<< histPath.toStdString()<updateHistory (undoSet); insilmaril@486: setChanged(); insilmaril@486: updateActions(); insilmaril@486: } insilmaril@486: insilmaril@486: insilmaril@395: void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment) insilmaril@0: { insilmaril@366: // save the selected part of the map, Undo will replace part of map insilmaril@366: QString undoSelection=""; insilmaril@395: if (undoSel) insilmaril@395: undoSelection=undoSel->getSelectString(); insilmaril@395: else insilmaril@395: qWarning ("MapEditor::saveStateChangingPart no undoSel given!"); insilmaril@395: QString redoSelection=""; insilmaril@395: if (redoSel) insilmaril@395: redoSelection=undoSel->getSelectString(); insilmaril@395: else insilmaril@395: qWarning ("MapEditor::saveStateChangingPart no redoSel given!"); insilmaril@395: insilmaril@366: insilmaril@366: saveState (PartOfMap, insilmaril@398: undoSelection, "addMapReplace (\"PATH\")", insilmaril@395: redoSelection, rc, insilmaril@366: comment, insilmaril@366: undoSel); insilmaril@105: } insilmaril@105: insilmaril@393: void MapEditor::saveStateRemovingPart(LinkableMapObj *redoSel, const QString &comment) insilmaril@393: { insilmaril@394: if (!redoSel) insilmaril@393: { insilmaril@394: qWarning ("MapEditor::saveStateRemovingPart no redoSel given!"); insilmaril@393: return; insilmaril@393: } insilmaril@393: QString undoSelection=redoSel->getParObj()->getSelectString(); insilmaril@393: QString redoSelection=redoSel->getSelectString(); insilmaril@398: if (typeid(*redoSel) == typeid(BranchObj) ) insilmaril@394: { insilmaril@394: // save the selected branch of the map, Undo will insert part of map insilmaril@394: saveState (PartOfMap, insilmaril@394: undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), insilmaril@394: redoSelection, "delete ()", insilmaril@394: comment, insilmaril@394: redoSel); insilmaril@394: } insilmaril@393: } insilmaril@393: insilmaril@106: insilmaril@366: void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) insilmaril@366: { insilmaril@366: // "Normal" savestate: save commands, selections and comment insilmaril@366: // so just save commands for undo and redo insilmaril@366: // and use current selection insilmaril@366: insilmaril@366: QString redoSelection=""; insilmaril@366: if (redoSel) redoSelection=redoSel->getSelectString(); insilmaril@366: QString undoSelection=""; insilmaril@366: if (undoSel) undoSelection=undoSel->getSelectString(); insilmaril@366: insilmaril@366: saveState (UndoCommand, insilmaril@366: undoSelection, uc, insilmaril@366: redoSelection, rc, insilmaril@366: comment, insilmaril@366: NULL); insilmaril@366: } insilmaril@366: insilmaril@366: void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) insilmaril@366: { insilmaril@366: // "Normal" savestate: save commands, selections and comment insilmaril@366: // so just save commands for undo and redo insilmaril@366: // and use current selection insilmaril@366: saveState (UndoCommand, insilmaril@366: undoSel, uc, insilmaril@366: redoSel, rc, insilmaril@366: comment, insilmaril@366: NULL); insilmaril@366: } insilmaril@366: insilmaril@645: void MapEditor::saveState(const QString &uc, const QString &rc, const QString &comment) insilmaril@645: { insilmaril@645: // "Normal" savestate applied to model (no selection needed): insilmaril@645: // save commands and comment insilmaril@645: saveState (UndoCommand, insilmaril@645: NULL, uc, insilmaril@645: NULL, rc, insilmaril@645: comment, insilmaril@645: NULL); insilmaril@645: } insilmaril@645: insilmaril@366: insilmaril@129: void MapEditor::parseAtom(const QString &atom) insilmaril@106: { insilmaril@424: BranchObj *selb=xelection.getBranch(); insilmaril@163: QString s,t; insilmaril@537: double x,y; insilmaril@537: int n; insilmaril@395: bool b,ok; insilmaril@129: insilmaril@129: // Split string s into command and parameters insilmaril@432: parser.parseAtom (atom); insilmaril@447: QString com=parser.getCommand(); insilmaril@129: insilmaril@106: // External commands insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@393: if (com=="addBranch") insilmaril@366: { insilmaril@424: if (xelection.isEmpty()) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else insilmaril@366: { insilmaril@394: QList pl; insilmaril@394: pl << 0 <<1; insilmaril@514: if (parser.checkParCount(pl)) insilmaril@394: { insilmaril@514: if (parser.parCount()==0) insilmaril@537: addNewBranch (0); insilmaril@394: else insilmaril@394: { insilmaril@537: n=parser.parInt (ok,0); insilmaril@537: if (ok ) addNewBranch (n); insilmaril@394: } insilmaril@394: } insilmaril@394: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@394: } else if (com=="addBranchBefore") insilmaril@394: { insilmaril@424: if (xelection.isEmpty()) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else insilmaril@394: { insilmaril@514: if (parser.parCount()==0) insilmaril@394: { insilmaril@394: addNewBranchBefore (); insilmaril@394: } insilmaril@394: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@393: } else if (com==QString("addMapReplace")) insilmaril@393: { insilmaril@424: if (xelection.isEmpty()) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@393: { insilmaril@432: //s=parser.parString (ok,0); // selection insilmaril@432: t=parser.parString (ok,0); // path to map insilmaril@625: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@424: addMapReplaceInt(selb->getSelectString(),t); insilmaril@393: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@434: } else if (com==QString("addMapInsert")) insilmaril@393: { insilmaril@424: if (xelection.isEmpty()) insilmaril@393: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else insilmaril@394: { insilmaril@514: if (parser.checkParCount(2)) insilmaril@394: { insilmaril@432: t=parser.parString (ok,0); // path to map insilmaril@537: n=parser.parInt(ok,1); // position insilmaril@625: if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t); insilmaril@537: addMapInsertInt(t,n); insilmaril@394: } insilmaril@393: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@447: } else if (com=="clearFlags") insilmaril@447: { insilmaril@447: if (xelection.isEmpty() ) insilmaril@447: { insilmaril@447: parser.setError (Aborted,"Nothing selected"); insilmaril@447: } else if (! selb ) insilmaril@447: { insilmaril@447: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@447: { insilmaril@447: selb->clearStandardFlags(); insilmaril@447: selb->updateFlagsToolbar(); insilmaril@447: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@395: } else if (com=="colorBranch") insilmaril@395: { insilmaril@424: if (xelection.isEmpty()) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@395: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@395: if (ok) colorBranch (c); insilmaril@395: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@417: } else if (com=="colorSubtree") insilmaril@417: { insilmaril@424: if (xelection.isEmpty()) insilmaril@417: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@417: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@417: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@417: if (ok) colorSubtree (c); insilmaril@417: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@502: } else if (com=="copy") insilmaril@502: { insilmaril@502: if (xelection.isEmpty()) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Nothing selected"); insilmaril@502: } else if (! selb ) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@502: { insilmaril@502: //FIXME missing action for copy insilmaril@502: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@395: } else if (com=="cut") insilmaril@395: { insilmaril@424: if (xelection.isEmpty()) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@491: } else if ( xelection.type()!=Selection::Branch && insilmaril@491: xelection.type()!=Selection::MapCenter && insilmaril@491: xelection.type()!=Selection::FloatImage ) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@395: { insilmaril@395: cut(); insilmaril@395: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@393: } else if (com=="delete") insilmaril@393: { insilmaril@424: if (xelection.isEmpty()) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@491: } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage ) insilmaril@424: { insilmaril@434: parser.setError (Aborted,"Type of selection is wrong."); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@393: { insilmaril@393: deleteSelection(); insilmaril@393: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@394: } else if (com=="deleteKeepChilds") insilmaril@394: { insilmaril@424: if (xelection.isEmpty()) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@424: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@394: { insilmaril@395: deleteKeepChilds(); insilmaril@395: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@395: } else if (com=="deleteChilds") insilmaril@395: { insilmaril@424: if (xelection.isEmpty()) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb) insilmaril@424: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@395: { insilmaril@395: deleteChilds(); insilmaril@394: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@517: } else if (com=="exportASCII") insilmaril@514: { insilmaril@517: QString fname=""; insilmaril@517: ok=true; insilmaril@613: if (parser.parCount()>=1) insilmaril@517: // Hey, we even have a filename insilmaril@613: fname=parser.parString(ok,0); insilmaril@517: if (!ok) insilmaril@514: { insilmaril@517: parser.setError (Aborted,"Could not read filename"); insilmaril@514: } else insilmaril@514: { insilmaril@517: exportASCII (fname,false); insilmaril@517: } insilmaril@517: ///////////////////////////////////////////////////////////////////// insilmaril@517: } else if (com=="exportImage") insilmaril@517: { insilmaril@517: QString fname=""; insilmaril@517: ok=true; insilmaril@517: if (parser.parCount()>=2) insilmaril@517: // Hey, we even have a filename insilmaril@613: fname=parser.parString(ok,0); insilmaril@517: if (!ok) insilmaril@517: { insilmaril@517: parser.setError (Aborted,"Could not read filename"); insilmaril@517: } else insilmaril@517: { insilmaril@517: QString format="PNG"; insilmaril@613: if (parser.parCount()>=2) insilmaril@514: { insilmaril@613: format=parser.parString(ok,1); insilmaril@514: } insilmaril@517: exportImage (fname,false,format); insilmaril@517: } insilmaril@517: ///////////////////////////////////////////////////////////////////// insilmaril@517: } else if (com=="exportXHTML") insilmaril@517: { insilmaril@517: QString fname=""; insilmaril@517: ok=true; insilmaril@517: if (parser.parCount()>=2) insilmaril@517: // Hey, we even have a filename insilmaril@517: fname=parser.parString(ok,1); insilmaril@517: if (!ok) insilmaril@517: { insilmaril@517: parser.setError (Aborted,"Could not read filename"); insilmaril@517: } else insilmaril@517: { insilmaril@520: exportXHTML (fname,false); insilmaril@517: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@526: } else if (com=="exportXML") insilmaril@526: { insilmaril@526: QString fname=""; insilmaril@526: ok=true; insilmaril@526: if (parser.parCount()>=2) insilmaril@526: // Hey, we even have a filename insilmaril@526: fname=parser.parString(ok,1); insilmaril@526: if (!ok) insilmaril@526: { insilmaril@526: parser.setError (Aborted,"Could not read filename"); insilmaril@526: } else insilmaril@526: { insilmaril@526: exportXML (fname,false); insilmaril@526: } insilmaril@526: ///////////////////////////////////////////////////////////////////// insilmaril@491: } else if (com=="importDir") insilmaril@491: { insilmaril@491: if (xelection.isEmpty()) insilmaril@491: { insilmaril@491: parser.setError (Aborted,"Nothing selected"); insilmaril@491: } else if (! selb ) insilmaril@491: { insilmaril@491: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@491: { insilmaril@491: s=parser.parString(ok,0); insilmaril@491: if (ok) importDirInt(s); insilmaril@491: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@420: } else if (com=="linkTo") insilmaril@420: { insilmaril@424: if (xelection.isEmpty()) insilmaril@420: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if ( selb) insilmaril@420: { insilmaril@514: if (parser.checkParCount(4)) insilmaril@421: { insilmaril@421: // 0 selectstring of parent insilmaril@421: // 1 num in parent (for branches) insilmaril@421: // 2,3 x,y of mainbranch or mapcenter insilmaril@432: s=parser.parString(ok,0); insilmaril@645: LinkableMapObj *dst=model->findObjBySelect (s); insilmaril@421: if (dst) insilmaril@421: { insilmaril@421: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@421: { insilmaril@421: // Get number in parent insilmaril@537: n=parser.parInt (ok,1); insilmaril@421: if (ok) insilmaril@534: { insilmaril@537: selb->linkTo ((BranchObj*)(dst),n); insilmaril@534: xelection.update(); insilmaril@534: } insilmaril@421: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@421: { insilmaril@424: selb->linkTo ((BranchObj*)(dst),-1); insilmaril@421: // Get coordinates of mainbranch insilmaril@537: x=parser.parDouble(ok,2); insilmaril@421: if (ok) insilmaril@421: { insilmaril@537: y=parser.parDouble(ok,3); insilmaril@534: if (ok) insilmaril@534: { insilmaril@534: selb->move (x,y); insilmaril@534: xelection.update(); insilmaril@534: } insilmaril@421: } insilmaril@421: } insilmaril@421: } insilmaril@421: } insilmaril@491: } else if ( xelection.type() == Selection::FloatImage) insilmaril@421: { insilmaril@514: if (parser.checkParCount(1)) insilmaril@421: { insilmaril@421: // 0 selectstring of parent insilmaril@432: s=parser.parString(ok,0); insilmaril@645: LinkableMapObj *dst=model->findObjBySelect (s); insilmaril@421: if (dst) insilmaril@421: { insilmaril@421: if (typeid(*dst) == typeid(BranchObj) || insilmaril@421: typeid(*dst) == typeid(MapCenterObj)) insilmaril@421: linkTo (dst->getSelectString()); insilmaril@421: } else insilmaril@432: parser.setError (Aborted,"Destination is not a branch"); insilmaril@421: } insilmaril@421: } else insilmaril@432: parser.setError (Aborted,"Type of selection is not a floatimage or branch"); insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@432: } else if (com=="loadImage") insilmaril@432: { insilmaril@432: if (xelection.isEmpty()) insilmaril@432: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@432: } else if (! selb ) insilmaril@432: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@432: { insilmaril@432: s=parser.parString(ok,0); insilmaril@432: if (ok) loadFloatImageInt (s); insilmaril@432: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@393: } else if (com=="moveBranchUp") insilmaril@393: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@394: { insilmaril@394: moveBranchUp(); insilmaril@394: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@394: } else if (com=="moveBranchDown") insilmaril@394: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@394: { insilmaril@394: moveBranchDown(); insilmaril@394: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@394: } else if (com=="move") insilmaril@394: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@491: } else if ( xelection.type()!=Selection::Branch && insilmaril@491: xelection.type()!=Selection::MapCenter && insilmaril@491: xelection.type()!=Selection::FloatImage ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@514: } else if (parser.checkParCount(2)) insilmaril@393: { insilmaril@537: x=parser.parDouble (ok,0); insilmaril@393: if (ok) insilmaril@393: { insilmaril@537: y=parser.parDouble (ok,1); insilmaril@393: if (ok) move (x,y); insilmaril@393: } insilmaril@393: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@395: } else if (com=="moveRel") insilmaril@393: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@491: } else if ( xelection.type()!=Selection::Selection::Branch && insilmaril@491: xelection.type()!=Selection::Selection::MapCenter && insilmaril@491: xelection.type()!=Selection::Selection::FloatImage ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@514: } else if (parser.checkParCount(2)) insilmaril@393: { insilmaril@537: x=parser.parDouble (ok,0); insilmaril@393: if (ok) insilmaril@393: { insilmaril@537: y=parser.parDouble (ok,1); insilmaril@393: if (ok) moveRel (x,y); insilmaril@393: } insilmaril@393: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@502: } else if (com=="nop") insilmaril@502: { insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@395: } else if (com=="paste") insilmaril@395: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@395: { insilmaril@537: n=parser.parInt (ok,0); insilmaril@537: if (ok) pasteNoSave(n); insilmaril@502: } insilmaril@502: ///////////////////////////////////////////////////////////////////// insilmaril@502: } else if (com=="qa") insilmaril@502: { insilmaril@502: if (xelection.isEmpty() ) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Nothing selected"); insilmaril@502: } else if (! selb ) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(4)) insilmaril@502: { insilmaril@502: QString c,u; insilmaril@502: c=parser.parString (ok,0); insilmaril@502: if (!ok) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"No comment given"); insilmaril@502: } else insilmaril@502: { insilmaril@502: s=parser.parString (ok,1); insilmaril@502: if (!ok) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"First parameter is not a string"); insilmaril@502: } else insilmaril@502: { insilmaril@502: t=parser.parString (ok,2); insilmaril@502: if (!ok) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Condition is not a string"); insilmaril@502: } else insilmaril@502: { insilmaril@502: u=parser.parString (ok,3); insilmaril@502: if (!ok) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Third parameter is not a string"); insilmaril@502: } else insilmaril@502: { insilmaril@502: if (s!="heading") insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Unknown type: "+s); insilmaril@502: } else insilmaril@502: { insilmaril@502: if (! (t=="eq") ) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Unknown operator: "+t); insilmaril@502: } else insilmaril@502: { insilmaril@502: if (! selb ) insilmaril@502: { insilmaril@502: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@502: } else insilmaril@502: { insilmaril@502: if (selb->getHeading() == u) insilmaril@502: { insilmaril@502: cout << "PASSED: " << c.ascii() << endl; insilmaril@502: } else insilmaril@502: { insilmaril@502: cout << "FAILED: " << c.ascii() << endl; insilmaril@502: } insilmaril@502: } insilmaril@502: } insilmaril@502: } insilmaril@502: } insilmaril@502: } insilmaril@502: } insilmaril@502: } insilmaril@395: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@434: } else if (com=="saveImage") insilmaril@434: { insilmaril@434: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@434: if (!fio) insilmaril@434: { insilmaril@434: parser.setError (Aborted,"Type of selection is not an image"); insilmaril@514: } else if (parser.checkParCount(2)) insilmaril@434: { insilmaril@434: s=parser.parString(ok,0); insilmaril@434: if (ok) insilmaril@434: { insilmaril@434: t=parser.parString(ok,1); insilmaril@434: if (ok) saveFloatImageInt (fio,t,s); insilmaril@434: } insilmaril@434: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@427: } else if (com=="scroll") insilmaril@427: { insilmaril@427: if (xelection.isEmpty() ) insilmaril@427: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@427: } else if (! selb ) insilmaril@427: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@427: { insilmaril@473: if (!scrollBranch (selb)) insilmaril@432: parser.setError (Aborted,"Could not scroll branch"); insilmaril@427: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@398: } else if (com=="select") insilmaril@398: { insilmaril@514: if (parser.checkParCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString(ok,0); insilmaril@398: if (ok) select (s); insilmaril@398: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@432: } else if (com=="selectLastBranch") insilmaril@432: { insilmaril@432: if (xelection.isEmpty() ) insilmaril@432: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@432: } else if (! selb ) insilmaril@432: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@432: { insilmaril@432: BranchObj *bo=selb->getLastBranch(); insilmaril@432: if (!bo) insilmaril@432: parser.setError (Aborted,"Could not select last branch"); insilmaril@432: selectInt (bo); insilmaril@432: insilmaril@432: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@434: } else if (com=="selectLastImage") insilmaril@434: { insilmaril@434: if (xelection.isEmpty() ) insilmaril@434: { insilmaril@434: parser.setError (Aborted,"Nothing selected"); insilmaril@434: } else if (! selb ) insilmaril@434: { insilmaril@434: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@434: { insilmaril@434: FloatImageObj *fio=selb->getLastFloatImage(); insilmaril@434: if (!fio) insilmaril@434: parser.setError (Aborted,"Could not select last image"); insilmaril@434: selectInt (fio); insilmaril@434: insilmaril@434: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@537: } else if (com=="selectLatestAdded") insilmaril@537: { insilmaril@537: if (latestSelection.isEmpty() ) insilmaril@537: { insilmaril@537: parser.setError (Aborted,"No latest added object"); insilmaril@537: } else insilmaril@537: { insilmaril@537: if (!select (latestSelection)) insilmaril@537: parser.setError (Aborted,"Could not select latest added object "+latestSelection); insilmaril@537: } insilmaril@537: ///////////////////////////////////////////////////////////////////// insilmaril@473: } else if (com=="setFrameType") insilmaril@473: { insilmaril@491: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@473: { insilmaril@473: parser.setError (Aborted,"Type of selection does not allow setting frame type"); insilmaril@473: } insilmaril@514: else if (parser.checkParCount(1)) insilmaril@473: { insilmaril@473: s=parser.parString(ok,0); insilmaril@473: if (ok) setFrameType (s); insilmaril@473: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@486: } else if (com=="setFramePenColor") insilmaril@486: { insilmaril@491: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@486: { insilmaril@486: parser.setError (Aborted,"Type of selection does not allow setting of pen color"); insilmaril@486: } insilmaril@514: else if (parser.checkParCount(1)) insilmaril@486: { insilmaril@486: QColor c=parser.parColor(ok,0); insilmaril@486: if (ok) setFramePenColor (c); insilmaril@486: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@486: } else if (com=="setFrameBrushColor") insilmaril@486: { insilmaril@491: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@486: { insilmaril@486: parser.setError (Aborted,"Type of selection does not allow setting brush color"); insilmaril@486: } insilmaril@514: else if (parser.checkParCount(1)) insilmaril@486: { insilmaril@486: QColor c=parser.parColor(ok,0); insilmaril@486: if (ok) setFrameBrushColor (c); insilmaril@486: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@486: } else if (com=="setFramePadding") insilmaril@486: { insilmaril@491: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@486: { insilmaril@486: parser.setError (Aborted,"Type of selection does not allow setting frame padding"); insilmaril@486: } insilmaril@514: else if (parser.checkParCount(1)) insilmaril@486: { insilmaril@537: n=parser.parInt(ok,0); insilmaril@537: if (ok) setFramePadding(n); insilmaril@486: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@486: } else if (com=="setFrameBorderWidth") insilmaril@486: { insilmaril@491: if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@486: { insilmaril@486: parser.setError (Aborted,"Type of selection does not allow setting frame border width"); insilmaril@486: } insilmaril@514: else if (parser.checkParCount(1)) insilmaril@486: { insilmaril@537: n=parser.parInt(ok,0); insilmaril@537: if (ok) setFrameBorderWidth (n); insilmaril@486: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@398: } else if (com=="setMapAuthor") insilmaril@398: { insilmaril@514: if (parser.checkParCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString(ok,0); insilmaril@398: if (ok) setMapAuthor (s); insilmaril@398: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@398: } else if (com=="setMapComment") insilmaril@398: { insilmaril@514: if (parser.checkParCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString(ok,0); insilmaril@398: if (ok) setMapComment(s); insilmaril@398: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@398: } else if (com=="setMapBackgroundColor") insilmaril@398: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@398: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! xelection.getBranch() ) insilmaril@398: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@398: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@398: if (ok) setMapBackgroundColor (c); insilmaril@398: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@398: } else if (com=="setMapDefLinkColor") insilmaril@398: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@398: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@398: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@398: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@398: if (ok) setMapDefLinkColor (c); insilmaril@398: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@398: } else if (com=="setMapLinkStyle") insilmaril@398: { insilmaril@514: if (parser.checkParCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString (ok,0); insilmaril@398: if (ok) setMapLinkStyle(s); insilmaril@398: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@129: } else if (com=="setHeading") insilmaril@129: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@129: { insilmaril@432: s=parser.parString (ok,0); insilmaril@366: if (ok) insilmaril@366: setHeading (s); insilmaril@129: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@395: } else if (com=="setHideExport") insilmaril@395: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@491: } else if (xelection.type()!=Selection::Branch && xelection.type() != Selection::MapCenter &&xelection.type()!=Selection::FloatImage) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@395: { insilmaril@432: b=parser.parBool(ok,0); insilmaril@395: if (ok) setHideExport (b); insilmaril@395: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@434: } else if (com=="setIncludeImagesHorizontally") insilmaril@473: { insilmaril@434: if (xelection.isEmpty() ) insilmaril@434: { insilmaril@434: parser.setError (Aborted,"Nothing selected"); insilmaril@434: } else if (! selb) insilmaril@434: { insilmaril@434: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@434: { insilmaril@434: b=parser.parBool(ok,0); insilmaril@434: if (ok) setIncludeImagesHor(b); insilmaril@434: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@434: } else if (com=="setIncludeImagesVertically") insilmaril@434: { insilmaril@434: if (xelection.isEmpty() ) insilmaril@434: { insilmaril@434: parser.setError (Aborted,"Nothing selected"); insilmaril@434: } else if (! selb) insilmaril@434: { insilmaril@434: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@434: { insilmaril@434: b=parser.parBool(ok,0); insilmaril@434: if (ok) setIncludeImagesVer(b); insilmaril@434: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@491: } else if (com=="setHideLinkUnselected") insilmaril@491: { insilmaril@491: if (xelection.isEmpty() ) insilmaril@491: { insilmaril@491: parser.setError (Aborted,"Nothing selected"); insilmaril@491: } else if ( xelection.type()!=Selection::Branch && xelection.type()!= Selection::MapCenter && xelection.type()!=Selection::FloatImage) insilmaril@491: { insilmaril@491: parser.setError (Aborted,"Type of selection does not allow hiding the link"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@491: { insilmaril@491: b=parser.parBool(ok,0); insilmaril@491: if (ok) setHideLinkUnselected(b); insilmaril@491: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@442: } else if (com=="setSelectionColor") insilmaril@442: { insilmaril@514: if (parser.checkParCount(1)) insilmaril@442: { insilmaril@442: QColor c=parser.parColor (ok,0); insilmaril@442: if (ok) setSelectionColorInt (c); insilmaril@442: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@143: } else if (com=="setURL") insilmaril@143: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@143: { insilmaril@432: s=parser.parString (ok,0); insilmaril@491: if (ok) setURL(s); insilmaril@143: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@143: } else if (com=="setVymLink") insilmaril@143: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@143: { insilmaril@432: s=parser.parString (ok,0); insilmaril@366: if (ok) setVymLinkInt(s); insilmaril@143: } insilmaril@143: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@366: else if (com=="setFlag") insilmaril@366: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@366: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@394: { insilmaril@432: s=parser.parString(ok,0); insilmaril@394: if (ok) insilmaril@394: { insilmaril@424: selb->activateStandardFlag(s); insilmaril@424: selb->updateFlagsToolbar(); insilmaril@366: } insilmaril@366: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@445: } else if (com=="setFrameType") insilmaril@445: { insilmaril@445: if (xelection.isEmpty() ) insilmaril@445: { insilmaril@445: parser.setError (Aborted,"Nothing selected"); insilmaril@445: } else if (! selb ) insilmaril@445: { insilmaril@445: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@445: { insilmaril@445: s=parser.parString(ok,0); insilmaril@445: if (ok) insilmaril@445: setFrameType (s); insilmaril@445: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@615: } else if (com=="sortChildren") insilmaril@615: { insilmaril@615: if (xelection.isEmpty() ) insilmaril@615: { insilmaril@615: parser.setError (Aborted,"Nothing selected"); insilmaril@615: } else if (! selb ) insilmaril@615: { insilmaril@615: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@615: } else if (parser.checkParCount(0)) insilmaril@615: { insilmaril@615: sortChildren(); insilmaril@615: } insilmaril@615: ///////////////////////////////////////////////////////////////////// insilmaril@447: } else if (com=="toggleFlag") insilmaril@447: { insilmaril@447: if (xelection.isEmpty() ) insilmaril@447: { insilmaril@447: parser.setError (Aborted,"Nothing selected"); insilmaril@447: } else if (! selb ) insilmaril@447: { insilmaril@447: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@447: { insilmaril@447: s=parser.parString(ok,0); insilmaril@447: if (ok) insilmaril@447: { insilmaril@447: selb->toggleStandardFlag(s); insilmaril@447: selb->updateFlagsToolbar(); insilmaril@447: } insilmaril@447: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@427: } else if (com=="unscroll") insilmaril@427: { insilmaril@427: if (xelection.isEmpty() ) insilmaril@427: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@427: } else if (! selb ) insilmaril@427: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@427: { insilmaril@473: if (!unscrollBranch (selb)) insilmaril@432: parser.setError (Aborted,"Could not unscroll branch"); insilmaril@427: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@473: } else if (com=="unscrollChilds") insilmaril@473: { insilmaril@473: if (xelection.isEmpty() ) insilmaril@473: { insilmaril@473: parser.setError (Aborted,"Nothing selected"); insilmaril@473: } else if (! selb ) insilmaril@473: { insilmaril@473: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(0)) insilmaril@473: { insilmaril@473: unscrollChilds (); insilmaril@473: } insilmaril@514: ///////////////////////////////////////////////////////////////////// insilmaril@427: } else if (com=="unsetFlag") insilmaril@366: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@366: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if (! selb ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch"); insilmaril@514: } else if (parser.checkParCount(1)) insilmaril@394: { insilmaril@432: s=parser.parString(ok,0); insilmaril@394: if (ok) insilmaril@394: { insilmaril@424: selb->deactivateStandardFlag(s); insilmaril@424: selb->updateFlagsToolbar(); insilmaril@366: } insilmaril@366: } insilmaril@398: } else insilmaril@432: parser.setError (Aborted,"Unknown command"); insilmaril@129: insilmaril@129: // Any errors? insilmaril@432: if (parser.errorLevel()==NoError) insilmaril@432: { insilmaril@613: // setChanged(); FIXME should not be called e.g. for export?! insilmaril@645: model->reposition(); insilmaril@432: } insilmaril@394: else insilmaril@106: { insilmaril@366: // TODO Error handling insilmaril@366: qWarning("MapEditor::parseAtom: Error!"); insilmaril@432: qWarning(parser.errorMessage()); insilmaril@394: } insilmaril@0: } insilmaril@0: insilmaril@432: void MapEditor::runScript (QString script) insilmaril@432: { insilmaril@445: parser.setScript (script); insilmaril@445: parser.runScript(); insilmaril@447: while (parser.next() ) insilmaril@447: parseAtom(parser.getAtom()); insilmaril@432: } insilmaril@0: insilmaril@0: bool MapEditor::isDefault() insilmaril@0: { insilmaril@0: return mapDefault; insilmaril@0: } insilmaril@0: insilmaril@0: bool MapEditor::hasChanged() insilmaril@0: { insilmaril@0: return mapChanged; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setChanged() insilmaril@0: { insilmaril@473: if (!mapChanged) insilmaril@473: autosaveTimer->start(settings.value("/mapeditor/autosave/ms/",300000).toInt()); insilmaril@0: mapChanged=true; insilmaril@0: mapDefault=false; insilmaril@0: mapUnsaved=true; insilmaril@0: findReset(); insilmaril@473: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::closeMap() insilmaril@0: { insilmaril@0: // Unselect before disabling the toolbar actions insilmaril@424: if (!xelection.isEmpty() ) xelection.unselect(); insilmaril@424: xelection.clear(); insilmaril@0: updateActions(); insilmaril@0: insilmaril@0: clear(); insilmaril@0: close(); insilmaril@0: } insilmaril@0: insilmaril@486: void MapEditor::setFilePath(QString fpath, QString destname) insilmaril@0: { insilmaril@486: if (fpath.isEmpty() || fpath=="") insilmaril@106: { insilmaril@106: filePath=""; insilmaril@106: fileName=""; insilmaril@106: destPath=""; insilmaril@106: } else insilmaril@106: { insilmaril@486: filePath=fpath; // becomes absolute path insilmaril@486: fileName=fpath; // gets stripped of path insilmaril@106: destPath=destname; // needed for vymlinks insilmaril@106: insilmaril@486: // If fpath is not an absolute path, complete it insilmaril@486: filePath=QDir(fpath).absPath(); insilmaril@106: fileDir=filePath.left (1+filePath.findRev ("/")); insilmaril@106: insilmaril@106: // Set short name, too. Search from behind: insilmaril@106: int i=fileName.findRev("/"); insilmaril@106: if (i>=0) fileName=fileName.remove (0,i+1); insilmaril@106: insilmaril@106: // Forget the .vym (or .xml) for name of map insilmaril@106: mapName=fileName.left(fileName.findRev(".",-1,true) ); insilmaril@106: } insilmaril@0: } insilmaril@0: insilmaril@486: void MapEditor::setFilePath(QString fpath) insilmaril@486: { insilmaril@486: setFilePath (fpath,fpath); insilmaril@486: } insilmaril@486: insilmaril@0: QString MapEditor::getFilePath() insilmaril@0: { insilmaril@0: return filePath; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getFileName() insilmaril@0: { insilmaril@0: return fileName; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getMapName() insilmaril@0: { insilmaril@0: return mapName; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getDestPath() insilmaril@0: { insilmaril@0: return destPath; insilmaril@0: } insilmaril@0: insilmaril@571: ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype) insilmaril@0: { insilmaril@205: ErrorCode err=success; insilmaril@0: insilmaril@571: parseBaseHandler *handler; insilmaril@571: switch (ftype) insilmaril@571: { insilmaril@571: case VymMap: handler=new parseVYMHandler; break; insilmaril@571: case FreemindMap : handler=new parseFreemindHandler; break; insilmaril@571: default: insilmaril@571: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@571: "Unknown FileType in MapEditor::load()"); insilmaril@571: return aborted; insilmaril@571: } insilmaril@0: if (lmode==NewMap) insilmaril@0: { insilmaril@424: if (xelection.isEmpty() ) xelection.unselect(); insilmaril@424: xelection.clear(); insilmaril@645: model->clear(); insilmaril@645: model->setMapEditor(this); insilmaril@0: // (map state is set later at end of load...) insilmaril@0: } else insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (!bo) return aborted; insilmaril@395: if (lmode==ImportAdd) insilmaril@395: saveStateChangingPart( insilmaril@424: bo, insilmaril@424: bo, insilmaril@395: QString("addMapInsert (%1)").arg(fname), insilmaril@395: QString("Add map %1 to %2").arg(fname).arg(getName(bo))); insilmaril@395: else insilmaril@395: saveStateChangingPart( insilmaril@424: bo, insilmaril@424: bo, insilmaril@395: QString("addMapReplace(%1)").arg(fname), insilmaril@395: QString("Add map %1 to %2").arg(fname).arg(getName(bo))); insilmaril@0: } insilmaril@0: insilmaril@0: QFile file( fname ); insilmaril@0: insilmaril@0: // I am paranoid: file should exist anyway insilmaril@0: // according to check in mainwindow. insilmaril@0: if (!file.exists() ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@0: tr("Couldn't open map " +fname)+"."); insilmaril@205: err=aborted; insilmaril@0: } else insilmaril@0: { insilmaril@473: bool blockSaveStateOrg=blockSaveState; insilmaril@139: blockReposition=true; insilmaril@473: blockSaveState=true; insilmaril@0: QXmlInputSource source( file); insilmaril@0: QXmlSimpleReader reader; insilmaril@571: reader.setContentHandler( handler ); insilmaril@571: reader.setErrorHandler( handler ); insilmaril@645: handler->setModel ( model); insilmaril@494: insilmaril@494: insilmaril@494: // We need to set the tmpDir in order to load files with rel. path insilmaril@494: QString tmpdir= fname.left(fname.findRev("/",-1)); insilmaril@571: handler->setTmpDir (tmpdir); insilmaril@571: handler->setInputFile (file.name()); insilmaril@571: handler->setLoadMode (lmode); insilmaril@0: bool ok = reader.parse( source ); insilmaril@139: blockReposition=false; insilmaril@473: blockSaveState=blockSaveStateOrg; insilmaril@0: file.close(); insilmaril@0: if ( ok ) insilmaril@0: { insilmaril@645: model->reposition(); insilmaril@442: xelection.update(); insilmaril@0: if (lmode==NewMap) insilmaril@0: { insilmaril@0: mapDefault=false; insilmaril@0: mapChanged=false; insilmaril@0: mapUnsaved=false; insilmaril@473: autosaveTimer->stop(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@571: tr( handler->errorProtocol() ) ); insilmaril@0: // returnCode=1; insilmaril@0: // Still return "success": the map maybe at least insilmaril@0: // partially read by the parser insilmaril@0: } insilmaril@0: } insilmaril@0: updateActions(); insilmaril@205: return err; insilmaril@0: } insilmaril@0: insilmaril@0: int MapEditor::save (const SaveMode &savemode) insilmaril@0: { insilmaril@0: // Create mapName and fileDir insilmaril@0: makeSubDirs (fileDir); insilmaril@0: QString fname; insilmaril@0: if (saveZipped()) insilmaril@0: // save as .xml insilmaril@0: fname=mapName+".xml"; insilmaril@0: else insilmaril@0: // use name given by user, even if he chooses .doc insilmaril@0: fname=fileName; insilmaril@0: insilmaril@0: insilmaril@0: QString saveFile; insilmaril@424: if (savemode==CompleteMap || xelection.isEmpty()) insilmaril@629: { insilmaril@629: // Save complete map insilmaril@408: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); insilmaril@629: mapChanged=false; insilmaril@629: mapUnsaved=false; insilmaril@629: autosaveTimer->stop(); insilmaril@629: } insilmaril@106: else insilmaril@491: { insilmaril@629: // Save part of map insilmaril@491: if (xelection.type()==Selection::FloatImage) insilmaril@491: saveFloatImage(); insilmaril@491: else insilmaril@491: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); insilmaril@629: // TODO take care of multiselections insilmaril@491: } insilmaril@0: insilmaril@163: if (!saveStringToDisk(fileDir+fname,saveFile)) insilmaril@0: return 1; insilmaril@0: insilmaril@531: updateActions(); insilmaril@531: return 0; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setZipped (bool z) insilmaril@0: { insilmaril@0: zipped=z; insilmaril@0: } insilmaril@0: insilmaril@0: bool MapEditor::saveZipped () insilmaril@0: { insilmaril@0: return zipped; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::print() insilmaril@0: { insilmaril@0: if ( !printer ) insilmaril@0: { insilmaril@0: printer = new QPrinter; insilmaril@0: printer->setColorMode (QPrinter::Color); insilmaril@366: printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString()); insilmaril@412: printer->setOutputFormat((QPrinter::OutputFormat)settings.value("/mainwindow/printerFormat",printer->outputFormat()).toInt()); insilmaril@412: printer->setOutputFileName(settings.value("/mainwindow/printerFileName",printer->outputFileName()).toString()); insilmaril@0: } insilmaril@0: insilmaril@645: QRectF totalBBox=model->getTotalBBox(); insilmaril@0: insilmaril@0: // Try to set orientation automagically insilmaril@0: // Note: Interpretation of generated postscript is amibiguous, if insilmaril@0: // there are problems with landscape mode, see insilmaril@0: // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html insilmaril@0: insilmaril@0: if (totalBBox.width()>totalBBox.height()) insilmaril@0: // recommend landscape insilmaril@0: printer->setOrientation (QPrinter::Landscape); insilmaril@0: else insilmaril@0: // recommend portrait insilmaril@0: printer->setOrientation (QPrinter::Portrait); insilmaril@0: insilmaril@0: if ( printer->setup(this) ) insilmaril@0: // returns false, if printing is canceled insilmaril@0: { insilmaril@0: QPainter pp(printer); insilmaril@0: insilmaril@412: pp.setRenderHint(QPainter::Antialiasing,true); insilmaril@412: insilmaril@0: // Don't print the visualisation of selection insilmaril@424: xelection.unselect(); insilmaril@0: insilmaril@408: QRectF mapRect=totalBBox; insilmaril@411: QGraphicsRectItem *frame=NULL; insilmaril@412: insilmaril@417: if (printFrame) insilmaril@0: { insilmaril@417: // Print frame around map insilmaril@417: mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, insilmaril@417: totalBBox.width()+20, totalBBox.height()+20); insilmaril@417: frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush)); insilmaril@417: frame->setZValue(0); insilmaril@417: frame->show(); insilmaril@417: } insilmaril@417: insilmaril@417: insilmaril@412: double paperAspect = (double)printer->width() / (double)printer->height(); insilmaril@412: double mapAspect = (double)mapRect.width() / (double)mapRect.height(); insilmaril@417: int viewBottom; insilmaril@0: if (mapAspect>=paperAspect) insilmaril@0: { insilmaril@0: // Fit horizontally to paper width insilmaril@417: //pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) ); insilmaril@417: viewBottom=(int)(printer->width()/mapAspect); insilmaril@0: } else insilmaril@0: { insilmaril@0: // Fit vertically to paper height insilmaril@417: //pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height()); insilmaril@417: viewBottom=printer->height(); insilmaril@0: } insilmaril@417: insilmaril@417: if (printFooter) insilmaril@417: { insilmaril@417: // Print footer below map insilmaril@417: QFont font; insilmaril@417: font.setPointSize(10); insilmaril@417: pp.setFont (font); insilmaril@417: QRectF footerBox(0,viewBottom,printer->width(),15); insilmaril@417: pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName); insilmaril@417: pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate)); insilmaril@417: } insilmaril@412: mapScene->render ( insilmaril@412: &pp, insilmaril@412: QRectF (0,0,printer->width(),printer->height()-15), insilmaril@412: QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height()) insilmaril@412: ); insilmaril@412: insilmaril@412: // Viewport has paper dimension insilmaril@412: if (frame) delete (frame); insilmaril@0: insilmaril@0: // Restore selection insilmaril@424: xelection.reselect(); insilmaril@119: insilmaril@119: // Save settings in vymrc insilmaril@366: settings.writeEntry("/mainwindow/printerName",printer->printerName()); insilmaril@412: settings.writeEntry("/mainwindow/printerFormat",printer->outputFormat()); insilmaril@412: settings.writeEntry("/mainwindow/printerFileName",printer->outputFileName()); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@408: void MapEditor::setAntiAlias (bool b) insilmaril@408: { insilmaril@408: setRenderHint(QPainter::Antialiasing,b); insilmaril@408: } insilmaril@408: insilmaril@408: void MapEditor::setSmoothPixmap(bool b) insilmaril@408: { insilmaril@408: setRenderHint(QPainter::SmoothPixmapTransform,b); insilmaril@408: } insilmaril@408: insilmaril@0: QPixmap MapEditor::getPixmap() insilmaril@0: { insilmaril@645: QRectF mapRect=model->getTotalBBox(); insilmaril@564: QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1); insilmaril@0: QPainter pp (&pix); insilmaril@420: insilmaril@420: pp.setRenderHints(renderHints()); insilmaril@0: insilmaril@0: // Don't print the visualisation of selection insilmaril@424: xelection.unselect(); insilmaril@0: insilmaril@420: mapScene->render ( &pp, insilmaril@450: QRectF(0,0,mapRect.width()+2,mapRect.height()+2), insilmaril@420: QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height() )); insilmaril@420: insilmaril@0: // Restore selection insilmaril@424: xelection.reselect(); insilmaril@0: insilmaril@0: return pix; insilmaril@0: } insilmaril@0: insilmaril@628: void MapEditor::setHideTmpMode (HideTmpMode mode) insilmaril@260: { insilmaril@260: hidemode=mode; insilmaril@645: model->setHideTmp (hidemode); insilmaril@645: model->reposition(); insilmaril@408: scene()->update(); insilmaril@260: } insilmaril@260: insilmaril@628: HideTmpMode MapEditor::getHideTmpMode() insilmaril@260: { insilmaril@260: return hidemode; insilmaril@260: } insilmaril@260: insilmaril@260: void MapEditor::setExportMode (bool b) insilmaril@260: { insilmaril@260: // should be called before and after exports insilmaril@260: // depending on the settings insilmaril@600: if (b && settings.value("/export/useHideExport","true")=="true") insilmaril@628: setHideTmpMode (HideExport); insilmaril@260: else insilmaril@628: setHideTmpMode (HideNone); insilmaril@0: } insilmaril@0: insilmaril@514: void MapEditor::exportASCII(QString fname,bool askName) insilmaril@0: { insilmaril@514: ExportASCII ex; insilmaril@645: ex.setModel (model); insilmaril@514: if (fname=="") insilmaril@514: ex.setFile (mapName+".txt"); insilmaril@514: else insilmaril@514: ex.setFile (fname); insilmaril@514: insilmaril@514: if (askName) insilmaril@514: { insilmaril@514: //ex.addFilter ("TXT (*.txt)"); insilmaril@514: ex.setDir(lastImageDir); insilmaril@514: //ex.setCaption(vymName+ " -" +tr("Export as ASCII")+" "+tr("(still experimental)")); insilmaril@514: ex.execDialog() ; insilmaril@514: } insilmaril@514: if (!ex.canceled()) insilmaril@514: { insilmaril@514: setExportMode(true); insilmaril@514: ex.doExport(); insilmaril@514: setExportMode(false); insilmaril@514: } insilmaril@514: } insilmaril@514: insilmaril@514: void MapEditor::exportImage(QString fname, bool askName, QString format) insilmaril@514: { insilmaril@514: if (fname=="") insilmaril@514: { insilmaril@514: fname=mapName+".png"; insilmaril@514: format="PNG"; insilmaril@514: } insilmaril@514: insilmaril@514: if (askName) insilmaril@514: { insilmaril@514: QStringList fl; insilmaril@514: QFileDialog *fd=new QFileDialog (this); insilmaril@514: fd->setCaption (tr("Export map as image")); insilmaril@514: fd->setDirectory (lastImageDir); insilmaril@514: fd->setFileMode(QFileDialog::AnyFile); insilmaril@514: fd->setFilters (imageIO.getFilters() ); insilmaril@514: if (fd->exec()) insilmaril@514: { insilmaril@514: fl=fd->selectedFiles(); insilmaril@514: fname=fl.first(); insilmaril@514: format=imageIO.getType(fd->selectedFilter()); insilmaril@514: } insilmaril@514: } insilmaril@514: insilmaril@260: setExportMode (true); insilmaril@0: QPixmap pix (getPixmap()); insilmaril@514: pix.save(fname, format); insilmaril@260: setExportMode (false); insilmaril@0: } insilmaril@0: insilmaril@185: void MapEditor::exportOOPresentation(const QString &fn, const QString &cf) insilmaril@163: { insilmaril@185: ExportOO ex; insilmaril@199: ex.setFile (fn); insilmaril@645: ex.setModel (model); insilmaril@260: if (ex.setConfigFile(cf)) insilmaril@260: { insilmaril@260: setExportMode (true); insilmaril@260: ex.exportPresentation(); insilmaril@260: setExportMode (false); insilmaril@260: } insilmaril@163: } insilmaril@163: insilmaril@520: void MapEditor::exportXHTML (const QString &dir, bool askForName) insilmaril@517: { insilmaril@517: ExportXHTMLDialog dia(this); insilmaril@517: dia.setFilePath (filePath ); insilmaril@517: dia.setMapName (mapName ); insilmaril@517: dia.readSettings(); insilmaril@526: if (dir!="") dia.setDir (dir); insilmaril@517: insilmaril@517: bool ok=true; insilmaril@517: insilmaril@520: if (askForName) insilmaril@517: { insilmaril@517: if (dia.exec()!=QDialog::Accepted) insilmaril@517: ok=false; insilmaril@517: else insilmaril@517: { insilmaril@517: QDir d (dia.getDir()); insilmaril@517: // Check, if warnings should be used before overwriting insilmaril@517: // the output directory insilmaril@517: if (d.exists() && d.count()>0) insilmaril@517: { insilmaril@517: WarningDialog warn; insilmaril@517: warn.showCancelButton (true); insilmaril@517: warn.setText(QString( insilmaril@517: "The directory %1 is not empty.\n" insilmaril@517: "Do you risk to overwrite some of its contents?").arg(d.path() )); insilmaril@517: warn.setCaption("Warning: Directory not empty"); insilmaril@517: warn.setShowAgainName("mainwindow/overwrite-dir-xhtml"); insilmaril@517: insilmaril@517: if (warn.exec()!=QDialog::Accepted) ok=false; insilmaril@517: } insilmaril@517: } insilmaril@517: } insilmaril@517: insilmaril@517: if (ok) insilmaril@517: { insilmaril@526: exportXML (dia.getDir(),false ); insilmaril@517: dia.doExport(mapName ); insilmaril@517: //if (dia.hasChanged()) setChanged(); insilmaril@517: } insilmaril@517: } insilmaril@0: insilmaril@526: void MapEditor::exportXML(QString dir, bool askForName) insilmaril@0: { insilmaril@526: if (askForName) insilmaril@526: { insilmaril@526: dir=browseDirectory(this,tr("Export XML to directory")); insilmaril@526: if (dir =="" && !reallyWriteDirectory(dir) ) insilmaril@526: return; insilmaril@526: } insilmaril@526: insilmaril@260: // Hide stuff during export, if settings want this insilmaril@260: setExportMode (true); insilmaril@260: insilmaril@0: // Create subdirectories insilmaril@0: makeSubDirs (dir); insilmaril@0: insilmaril@0: // write to directory insilmaril@645: QString saveFile=saveToDir (dir,mapName+"-",true,model->getTotalBBox().topLeft() ,NULL); insilmaril@0: QFile file; insilmaril@0: insilmaril@0: file.setName ( dir + "/"+mapName+".xml"); insilmaril@366: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@0: { insilmaril@0: // This should neverever happen insilmaril@159: QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name())); insilmaril@0: return; insilmaril@0: } insilmaril@0: insilmaril@0: // Write it finally, and write in UTF8, no matter what insilmaril@0: QTextStream ts( &file ); insilmaril@0: ts.setEncoding (QTextStream::UnicodeUTF8); insilmaril@0: ts << saveFile; insilmaril@0: file.close(); insilmaril@0: insilmaril@0: // Now write image, too insilmaril@517: exportImage (dir+"/images/"+mapName+".png",false,"PNG"); insilmaril@260: insilmaril@260: setExportMode (false); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::clear() insilmaril@0: { insilmaril@424: xelection.unselect(); insilmaril@645: model->clear(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::copy() insilmaril@0: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@0: { insilmaril@502: if (redosAvail == 0) insilmaril@0: { insilmaril@502: // Copy to history insilmaril@502: QString s=sel->getSelectString(); insilmaril@505: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel ); insilmaril@502: curClipboard=curStep; insilmaril@502: } insilmaril@502: insilmaril@502: // Copy also to global clipboard, because we are at last step in history insilmaril@625: QString bakMapName(QString("history-%1").arg(curStep)); insilmaril@625: QString bakMapDir(tmpMapDir +"/"+bakMapName); insilmaril@502: copyDir (bakMapDir,clipboardDir ); insilmaril@166: insilmaril@166: clipboardEmpty=false; insilmaril@166: updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@163: void MapEditor::redo() insilmaril@163: { insilmaril@381: // Can we undo at all? insilmaril@381: if (redosAvail<1) return; insilmaril@473: insilmaril@473: bool blockSaveStateOrg=blockSaveState; insilmaril@473: blockSaveState=true; insilmaril@473: insilmaril@381: redosAvail--; insilmaril@381: insilmaril@381: if (undosAvailstepsTotal) curStep=1; insilmaril@366: QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); insilmaril@366: QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); insilmaril@366: QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); insilmaril@366: QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); insilmaril@366: QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); insilmaril@395: QString version=undoSet.readEntry ("/history/version"); insilmaril@395: insilmaril@645: /* TODO Maybe check for version, if we save the history insilmaril@395: if (!checkVersion(version)) insilmaril@395: QMessageBox::warning(0,tr("Warning"), insilmaril@404: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); insilmaril@645: */ insilmaril@366: insilmaril@163: // Find out current undo directory insilmaril@625: QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@366: insilmaril@473: if (debug) insilmaril@473: { insilmaril@473: cout << "ME::redo() begin\n"; insilmaril@473: cout << " undosAvail="<reposition(); insilmaril@366: insilmaril@473: blockSaveState=blockSaveStateOrg; insilmaril@366: insilmaril@366: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@366: undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); insilmaril@366: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@366: undoSet.writeSettings(histPath); insilmaril@366: insilmaril@408: mainWindow->updateHistory (undoSet); insilmaril@407: updateActions(); insilmaril@366: insilmaril@366: /* TODO remove testing insilmaril@163: cout << "ME::redo() end\n"; insilmaril@163: cout << " undosAvail="<0) insilmaril@390: return true; insilmaril@390: else insilmaril@390: return false; insilmaril@390: } insilmaril@390: insilmaril@106: void MapEditor::undo() insilmaril@106: { insilmaril@381: // Can we undo at all? insilmaril@381: if (undosAvail<1) return; insilmaril@381: insilmaril@502: mainWindow->statusMessage (tr("Autosave disabled during undo.")); insilmaril@502: insilmaril@473: bool blockSaveStateOrg=blockSaveState; insilmaril@473: blockSaveState=true; insilmaril@473: insilmaril@366: QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); insilmaril@366: QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); insilmaril@366: QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); insilmaril@366: QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); insilmaril@366: QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); insilmaril@395: QString version=undoSet.readEntry ("/history/version"); insilmaril@395: insilmaril@645: /* TODO Maybe check for version, if we save the history insilmaril@395: if (!checkVersion(version)) insilmaril@395: QMessageBox::warning(0,tr("Warning"), insilmaril@404: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion)); insilmaril@645: */ insilmaril@366: insilmaril@163: // Find out current undo directory insilmaril@625: QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@163: insilmaril@136: // select object before undo insilmaril@136: if (!undoSelection.isEmpty()) insilmaril@136: select (undoSelection); insilmaril@136: insilmaril@473: if (debug) insilmaril@473: { insilmaril@473: cout << "ME::undo() begin\n"; insilmaril@473: cout << " undosAvail="<reposition(); insilmaril@106: insilmaril@163: undosAvail--; insilmaril@366: curStep--; insilmaril@381: if (curStep<1) curStep=stepsTotal; insilmaril@366: insilmaril@366: redosAvail++; insilmaril@163: insilmaril@473: blockSaveState=blockSaveStateOrg; insilmaril@163: /* TODO remove testing insilmaril@163: cout << "ME::undo() end\n"; insilmaril@163: cout << " undosAvail="<updateHistory (undoSet); insilmaril@366: updateActions(); insilmaril@442: xelection.update(); insilmaril@420: ensureSelectionVisible(); insilmaril@106: } insilmaril@106: insilmaril@390: bool MapEditor::isUndoAvailable() insilmaril@390: { insilmaril@390: if (undoSet.readNumEntry("/history/undosAvail",0)>0) insilmaril@390: return true; insilmaril@390: else insilmaril@390: return false; insilmaril@390: } insilmaril@390: insilmaril@404: void MapEditor::gotoHistoryStep (int i) insilmaril@381: { insilmaril@381: // Restore variables insilmaril@381: int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); insilmaril@388: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@388: insilmaril@388: if (i<0) i=undosAvail+redosAvail; insilmaril@388: insilmaril@388: // Clicking above current step makes us undo things insilmaril@381: if (iundosAvail) insilmaril@491: for (int j=undosAvail; jclear(); insilmaril@106: handler.setLoadMode (NewMap); insilmaril@106: } else insilmaril@106: { insilmaril@106: select (undoSel); insilmaril@106: handler.setLoadMode (ImportReplace); insilmaril@106: } insilmaril@139: blockReposition=true; insilmaril@106: bool ok = reader.parse( source ); insilmaril@139: blockReposition=false; insilmaril@106: if (! ok ) insilmaril@106: { insilmaril@106: // This should never ever happen insilmaril@393: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@393: handler.errorProtocol()); insilmaril@106: } insilmaril@106: } else insilmaril@393: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@393: } insilmaril@393: insilmaril@394: void MapEditor::addMapInsertInt (const QString &path, int pos) insilmaril@393: { insilmaril@424: BranchObj *sel=xelection.getBranch(); insilmaril@608: if (sel) insilmaril@106: { insilmaril@393: QString pathDir=path.left(path.findRev("/")); insilmaril@393: QDir d(pathDir); insilmaril@393: QFile file (path); insilmaril@393: insilmaril@393: if (d.exists() ) insilmaril@393: { insilmaril@393: // We need to parse saved XML data insilmaril@564: parseVYMHandler handler; insilmaril@393: QXmlInputSource source( file); insilmaril@393: QXmlSimpleReader reader; insilmaril@393: reader.setContentHandler( &handler ); insilmaril@393: reader.setErrorHandler( &handler ); insilmaril@645: handler.setModel (model); insilmaril@393: handler.setTmpDir ( pathDir ); // needed to load files with rel. path insilmaril@394: handler.setLoadMode (ImportAdd); insilmaril@393: blockReposition=true; insilmaril@393: bool ok = reader.parse( source ); insilmaril@393: blockReposition=false; insilmaril@393: if (! ok ) insilmaril@393: { insilmaril@393: // This should never ever happen insilmaril@393: QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path), insilmaril@393: handler.errorProtocol()); insilmaril@393: } insilmaril@645: if (sel->getDepth()>0) insilmaril@424: sel->getLastBranch()->linkTo (sel,pos); insilmaril@393: } else insilmaril@393: QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path)); insilmaril@393: } insilmaril@106: } insilmaril@106: insilmaril@502: void MapEditor::pasteNoSave(const int &n) insilmaril@0: { insilmaril@491: bool old=blockSaveState; insilmaril@491: blockSaveState=true; insilmaril@502: if (redosAvail > 0 || n!=0) insilmaril@502: { insilmaril@502: // Use the "historical" buffer insilmaril@625: QString bakMapName(QString("history-%1").arg(n)); insilmaril@625: QString bakMapDir(tmpMapDir +"/"+bakMapName); insilmaril@571: load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap); insilmaril@502: } else insilmaril@502: // Use the global buffer insilmaril@571: load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap); insilmaril@491: blockSaveState=old; insilmaril@0: } insilmaril@0: insilmaril@497: void MapEditor::paste() insilmaril@0: { insilmaril@424: BranchObj *sel=xelection.getBranch(); insilmaril@424: if (sel) insilmaril@166: { insilmaril@395: saveStateChangingPart( insilmaril@424: sel, insilmaril@424: sel, insilmaril@502: QString ("paste (%1)").arg(curClipboard), insilmaril@424: QString("Paste to %1").arg( getName(sel)) insilmaril@395: ); insilmaril@502: pasteNoSave(0); insilmaril@645: model->reposition(); insilmaril@166: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cut() insilmaril@0: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@491: if ( sel && (xelection.type() == Selection::Branch || insilmaril@491: xelection.type()==Selection::MapCenter || insilmaril@491: xelection.type()==Selection::FloatImage)) insilmaril@424: { insilmaril@491: /* No savestate! savestate is called in cutNoSave insilmaril@424: saveStateChangingPart( insilmaril@424: sel->getParObj(), insilmaril@424: sel, insilmaril@424: "cut ()", insilmaril@424: QString("Cut %1").arg(getName(sel )) insilmaril@424: ); insilmaril@491: */ insilmaril@424: copy(); insilmaril@491: deleteSelection(); insilmaril@645: model->reposition(); insilmaril@424: } insilmaril@0: } insilmaril@0: insilmaril@537: void MapEditor::move(const double &x, const double &y) insilmaril@130: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@366: { insilmaril@625: QPointF ap(sel->getAbsPos()); insilmaril@625: QPointF to(x, y); insilmaril@625: if (ap != to) insilmaril@625: { insilmaril@625: QString ps=qpointfToString(ap); insilmaril@625: QString s=xelection.single()->getSelectString(); insilmaril@625: saveState( insilmaril@625: s, "move "+ps, insilmaril@625: s, "move "+qpointfToString(to), insilmaril@625: QString("Move %1 to %2").arg(getName(sel)).arg(ps)); insilmaril@625: sel->move(x,y); insilmaril@645: model->reposition(); insilmaril@625: xelection.update(); insilmaril@625: } insilmaril@366: } insilmaril@366: } insilmaril@366: insilmaril@537: void MapEditor::moveRel (const double &x, const double &y) insilmaril@366: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@366: { insilmaril@625: QPointF rp(sel->getRelPos()); insilmaril@625: QPointF to(x, y); insilmaril@625: if (rp != to) insilmaril@625: { insilmaril@625: QString ps=qpointfToString (sel->getRelPos()); insilmaril@625: QString s=sel->getSelectString(); insilmaril@625: saveState( insilmaril@625: s, "moveRel "+ps, insilmaril@625: s, "moveRel "+qpointfToString(to), insilmaril@625: QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps)); insilmaril@625: ((OrnamentedObj*)sel)->move2RelPos (x,y); insilmaril@645: model->reposition(); insilmaril@625: sel->updateLink(); insilmaril@625: xelection.update(); insilmaril@625: } insilmaril@366: } insilmaril@130: } insilmaril@130: insilmaril@0: void MapEditor::moveBranchUp() insilmaril@0: { insilmaril@424: BranchObj* bo=xelection.getBranch(); insilmaril@0: BranchObj* par; insilmaril@424: if (bo) insilmaril@0: { insilmaril@314: if (!bo->canMoveBranchUp()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@473: BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection insilmaril@473: saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); insilmaril@645: model->reposition(); insilmaril@420: scene()->update(); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::moveBranchDown() insilmaril@0: { insilmaril@424: BranchObj* bo=xelection.getBranch(); insilmaril@0: BranchObj* par; insilmaril@424: if (bo) insilmaril@0: { insilmaril@314: if (!bo->canMoveBranchDown()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@473: BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection insilmaril@473: saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); insilmaril@645: model->reposition(); insilmaril@420: scene()->update(); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@608: void MapEditor::sortChildren() insilmaril@608: { insilmaril@608: BranchObj* bo=xelection.getBranch(); insilmaril@608: if (bo) insilmaril@608: { insilmaril@608: if(bo->countBranches()>1) insilmaril@608: { insilmaril@615: saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getName(bo))); insilmaril@608: bo->sortChildren(); insilmaril@645: model->reposition(); insilmaril@608: ensureSelectionVisible(); insilmaril@608: } insilmaril@608: } insilmaril@608: } insilmaril@608: insilmaril@491: void MapEditor::linkTo(const QString &dstString) insilmaril@420: { insilmaril@424: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@424: if (fio) insilmaril@424: { insilmaril@645: BranchObj *dst=(BranchObj*)(model->findObjBySelect(dstString)); insilmaril@424: if (dst && (typeid(*dst)==typeid (BranchObj) || insilmaril@424: typeid(*dst)==typeid (MapCenterObj))) insilmaril@424: { insilmaril@424: LinkableMapObj *dstPar=dst->getParObj(); insilmaril@424: QString parString=dstPar->getSelectString(); insilmaril@420: QString fioPreSelectString=fio->getSelectString(); insilmaril@420: QString fioPreParentSelectString=fio->getParObj()->getSelectString(); insilmaril@420: ((BranchObj*)(dst))->addFloatImage (fio); insilmaril@424: xelection.unselect(); insilmaril@420: ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); insilmaril@420: fio=((BranchObj*)(dst))->getLastFloatImage(); insilmaril@420: fio->setRelPos(); insilmaril@420: fio->reposition(); insilmaril@424: xelection.select(fio); insilmaril@420: saveState( insilmaril@420: fio->getSelectString(), insilmaril@420: QString("linkTo (\"%1\")").arg(fioPreParentSelectString), insilmaril@420: fioPreSelectString, insilmaril@420: QString ("linkTo (\"%1\")").arg(dstString), insilmaril@420: QString ("Link floatimage to %1").arg(getName(dst))); insilmaril@424: } insilmaril@420: } insilmaril@420: } insilmaril@420: insilmaril@366: QString MapEditor::getHeading(bool &ok, QPoint &p) insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@366: { insilmaril@366: ok=true; insilmaril@424: p=mapFromScene(bo->getAbsPos()); insilmaril@424: return bo->getHeading(); insilmaril@366: } insilmaril@366: ok=false; insilmaril@366: return QString(); insilmaril@366: } insilmaril@366: insilmaril@366: void MapEditor::setHeading(const QString &s) insilmaril@366: { insilmaril@424: BranchObj *sel=xelection.getBranch(); insilmaril@424: if (sel) insilmaril@0: { insilmaril@395: saveState( insilmaril@424: sel, insilmaril@424: "setHeading (\""+sel->getHeading()+"\")", insilmaril@424: sel, insilmaril@366: "setHeading (\""+s+"\")", insilmaril@424: QString("Set heading of %1 to \"%2\"").arg(getName(sel)).arg(s) ); insilmaril@424: sel->setHeading(s ); insilmaril@645: model->reposition(); insilmaril@442: xelection.update(); insilmaril@106: ensureSelectionVisible(); insilmaril@106: } insilmaril@106: } insilmaril@106: insilmaril@366: void MapEditor::setHeadingInt(const QString &s) insilmaril@366: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@366: { insilmaril@424: bo->setHeading(s); insilmaril@645: model->reposition(); insilmaril@442: xelection.update(); insilmaril@366: ensureSelectionVisible(); insilmaril@366: } insilmaril@366: } insilmaril@366: insilmaril@366: void MapEditor::setVymLinkInt (const QString &s) insilmaril@143: { insilmaril@143: // Internal function, no saveState needed insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@143: { insilmaril@424: bo->setVymLink(s); insilmaril@645: model->reposition(); insilmaril@491: updateActions(); insilmaril@442: xelection.update(); insilmaril@143: ensureSelectionVisible(); insilmaril@143: } insilmaril@143: } insilmaril@143: insilmaril@366: BranchObj* MapEditor::addNewBranchInt(int num) insilmaril@0: { insilmaril@366: // Depending on pos: insilmaril@366: // -3 insert in childs of parent above selection insilmaril@366: // -2 add branch to selection insilmaril@366: // -1 insert in childs of parent below selection insilmaril@366: // 0..n insert in childs of parent at pos insilmaril@366: BranchObj *newbo=NULL; insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@366: if (num==-2) insilmaril@0: { insilmaril@0: // save scroll state. If scrolled, automatically select insilmaril@0: // new branch in order to tmp unscroll parent... insilmaril@537: newbo=bo->addBranch(); insilmaril@366: insilmaril@366: }else if (num==-1) insilmaril@0: { insilmaril@366: num=bo->getNum()+1; insilmaril@366: bo=(BranchObj*)bo->getParObj(); insilmaril@537: if (bo) newbo=bo->insertBranch(num); insilmaril@366: }else if (num==-3) insilmaril@366: { insilmaril@366: num=bo->getNum(); insilmaril@366: bo=(BranchObj*)bo->getParObj(); insilmaril@537: if (bo) newbo=bo->insertBranch(num); insilmaril@366: } insilmaril@537: if (!newbo) return NULL; insilmaril@366: } insilmaril@366: return newbo; insilmaril@366: } insilmaril@366: insilmaril@394: BranchObj* MapEditor::addNewBranch(int pos) insilmaril@366: { insilmaril@366: // Different meaning than num in addNewBranchInt! insilmaril@366: // -1 add above insilmaril@366: // 0 add as child insilmaril@366: // +1 add below insilmaril@424: BranchObj *bo = xelection.getBranch(); insilmaril@394: BranchObj *newbo=NULL; insilmaril@394: insilmaril@424: if (bo) insilmaril@366: { insilmaril@421: setCursor (Qt::ArrowCursor); insilmaril@421: insilmaril@366: newbo=addNewBranchInt (pos-2); insilmaril@366: insilmaril@366: if (newbo) insilmaril@366: { insilmaril@395: saveState( insilmaril@417: newbo, insilmaril@393: "delete ()", insilmaril@424: bo, insilmaril@537: QString ("addBranch (%1)").arg(pos), insilmaril@395: QString ("Add new branch to %1").arg(getName(bo))); insilmaril@366: insilmaril@645: model->reposition(); insilmaril@537: xelection.update(); insilmaril@537: latestSelection=newbo->getSelectString(); insilmaril@531: // In Network mode, the client needs to know where the new branch is, insilmaril@531: // so we have to pass on this information via saveState. insilmaril@531: // TODO: Get rid of this positioning workaround insilmaril@531: QString ps=qpointfToString (newbo->getAbsPos()); insilmaril@537: sendData ("selectLatestAdded ()"); insilmaril@534: sendData (QString("move %1").arg(ps)); insilmaril@534: sendSelection(); insilmaril@366: } insilmaril@366: } insilmaril@394: return newbo; insilmaril@366: } insilmaril@366: insilmaril@366: insilmaril@394: BranchObj* MapEditor::addNewBranchBefore() insilmaril@366: { insilmaril@394: BranchObj *newbo=NULL; insilmaril@424: BranchObj *bo = xelection.getBranch(); insilmaril@491: if (bo && xelection.type()==Selection::Branch) insilmaril@394: // We accept no MapCenterObj here, so we _have_ a parent insilmaril@366: { insilmaril@408: QPointF p=bo->getRelPos(); insilmaril@394: insilmaril@394: insilmaril@424: BranchObj *parbo=(BranchObj*)(bo->getParObj()); insilmaril@394: insilmaril@394: // add below selection insilmaril@394: newbo=parbo->insertBranch(bo->getNum()+1); insilmaril@394: if (newbo) insilmaril@366: { insilmaril@394: newbo->move2RelPos (p); insilmaril@394: insilmaril@394: // Move selection to new branch insilmaril@424: bo->linkTo (newbo,-1); insilmaril@394: insilmaril@394: saveState (newbo, "deleteKeepChilds ()", newbo, "addBranchBefore ()", insilmaril@394: QString ("Add branch before %1").arg(getName(bo))); insilmaril@394: insilmaril@645: model->reposition(); insilmaril@442: xelection.update(); insilmaril@394: } insilmaril@0: } insilmaril@537: latestSelection=xelection.getSelectString(); insilmaril@394: return newbo; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::deleteSelection() insilmaril@0: { insilmaril@424: BranchObj *bo = xelection.getBranch(); insilmaril@645: if (bo && xelection.type()==Selection::MapCenter) insilmaril@645: { insilmaril@645: // BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@645: xelection.unselect(); insilmaril@645: /* FIXME Note: does saveStateRemovingPart work for MCO? (No parent!) insilmaril@645: saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); insilmaril@645: */ insilmaril@645: bo=model->removeMapCenter ((MapCenterObj*)bo); insilmaril@645: if (bo) insilmaril@645: { insilmaril@645: xelection.select (bo); insilmaril@645: ensureSelectionVisible(); insilmaril@645: xelection.update(); insilmaril@645: } insilmaril@645: model->reposition(); insilmaril@645: return; insilmaril@645: } insilmaril@491: if (bo && xelection.type()==Selection::Branch) insilmaril@0: { insilmaril@294: BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@424: xelection.unselect(); insilmaril@394: saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); insilmaril@0: par->removeBranch(bo); insilmaril@424: xelection.select (par); insilmaril@0: ensureSelectionVisible(); insilmaril@645: model->reposition(); insilmaril@442: xelection.update(); insilmaril@442: xelection.update(); insilmaril@424: return; insilmaril@0: } insilmaril@424: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@424: if (fio) insilmaril@0: { insilmaril@0: BranchObj* par=(BranchObj*)(fio->getParObj()); insilmaril@395: saveStateChangingPart( insilmaril@395: par, insilmaril@395: fio, insilmaril@395: "delete ()", insilmaril@395: QString("Delete %1").arg(getName(fio)) insilmaril@395: ); insilmaril@424: xelection.unselect(); insilmaril@0: par->removeFloatImage(fio); insilmaril@424: xelection.select (par); insilmaril@645: model->reposition(); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@424: return; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: LinkableMapObj* MapEditor::getSelection() insilmaril@0: { insilmaril@424: return xelection.single(); insilmaril@0: } insilmaril@0: insilmaril@442: BranchObj* MapEditor::getSelectedBranch() insilmaril@442: { insilmaril@442: return xelection.getBranch(); insilmaril@442: } insilmaril@442: insilmaril@442: FloatImageObj* MapEditor::getSelectedFloatImage() insilmaril@442: { insilmaril@442: return xelection.getFloatImage(); insilmaril@442: } insilmaril@442: insilmaril@267: void MapEditor::unselect() insilmaril@267: { insilmaril@424: xelection.unselect(); insilmaril@267: } insilmaril@267: insilmaril@267: void MapEditor::reselect() insilmaril@267: { insilmaril@424: xelection.reselect(); insilmaril@267: } insilmaril@267: insilmaril@83: bool MapEditor::select (const QString &s) insilmaril@83: { insilmaril@645: LinkableMapObj *lmo=model->findObjBySelect(s); insilmaril@0: insilmaril@0: // Finally select the found object insilmaril@0: if (lmo) insilmaril@0: { insilmaril@424: xelection.unselect(); insilmaril@424: xelection.select(lmo); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@528: sendSelection (); insilmaril@0: return true; insilmaril@139: } insilmaril@139: return false; insilmaril@0: } insilmaril@0: insilmaril@366: QString MapEditor::getSelectString() insilmaril@366: { insilmaril@424: return xelection.getSelectString(); insilmaril@366: } insilmaril@366: insilmaril@366: void MapEditor::selectInt (LinkableMapObj *lmo) insilmaril@0: { insilmaril@491: if (lmo && xelection.single()!= lmo && isSelectBlocked()==false ) insilmaril@442: { insilmaril@424: xelection.select(lmo); insilmaril@442: xelection.update(); insilmaril@528: sendSelection (); insilmaril@442: } insilmaril@267: } insilmaril@0: insilmaril@366: void MapEditor::selectNextBranchInt() insilmaril@0: { insilmaril@0: // Increase number of branch insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@0: { insilmaril@424: QString s=sel->getSelectString(); insilmaril@0: QString part; insilmaril@0: QString typ; insilmaril@0: QString num; insilmaril@0: insilmaril@0: // Where am I? insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: s=s.left (s.length() -num.length()); insilmaril@0: insilmaril@0: // Go to next lmo insilmaril@0: num=QString ("%1").arg(num.toUInt()+1); insilmaril@0: insilmaril@0: s=s+num; insilmaril@0: insilmaril@0: // Try to select this one insilmaril@0: if (select (s)) return; insilmaril@0: insilmaril@0: // We have no direct successor, insilmaril@0: // try to increase the parental number in order to insilmaril@0: // find a successor with same depth insilmaril@0: insilmaril@424: int d=xelection.single()->getDepth(); insilmaril@0: int oldDepth=d; insilmaril@0: int i; insilmaril@0: bool found=false; insilmaril@0: bool b; insilmaril@0: while (!found && d>0) insilmaril@0: { insilmaril@0: s=s.section (",",0,d-1); insilmaril@0: // replace substring of current depth in s with "1" insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: if (d>1) insilmaril@0: { insilmaril@0: // increase number of parent insilmaril@0: num=QString ("%1").arg(num.toUInt()+1); insilmaril@0: s=s.section (",",0,d-2) + ","+ typ+num; insilmaril@0: } else insilmaril@0: { insilmaril@0: // Special case, look at orientation insilmaril@473: if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@0: num=QString ("%1").arg(num.toUInt()+1); insilmaril@0: else insilmaril@0: num=QString ("%1").arg(num.toUInt()-1); insilmaril@0: s=typ+num; insilmaril@0: } insilmaril@0: insilmaril@0: if (select (s)) insilmaril@0: // pad to oldDepth, select the first branch for each depth insilmaril@0: for (i=d;icountBranches()>0) insilmaril@0: s+=",bo:0"; insilmaril@0: else insilmaril@0: break; insilmaril@0: } else insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: // try to select the freshly built string insilmaril@0: found=select(s); insilmaril@0: d--; insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@366: void MapEditor::selectPrevBranchInt() insilmaril@0: { insilmaril@0: // Decrease number of branch insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@424: QString s=bo->getSelectString(); insilmaril@0: QString part; insilmaril@0: QString typ; insilmaril@0: QString num; insilmaril@0: insilmaril@0: // Where am I? insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: s=s.left (s.length() -num.length()); insilmaril@0: insilmaril@411: int n=num.toInt()-1; insilmaril@411: insilmaril@0: // Go to next lmo insilmaril@411: num=QString ("%1").arg(n); insilmaril@0: s=s+num; insilmaril@0: insilmaril@0: // Try to select this one insilmaril@411: if (n>=0 && select (s)) return; insilmaril@0: insilmaril@0: // We have no direct precessor, insilmaril@0: // try to decrease the parental number in order to insilmaril@0: // find a precessor with same depth insilmaril@0: insilmaril@424: int d=xelection.single()->getDepth(); insilmaril@0: int oldDepth=d; insilmaril@0: int i; insilmaril@0: bool found=false; insilmaril@0: bool b; insilmaril@0: while (!found && d>0) insilmaril@0: { insilmaril@0: s=s.section (",",0,d-1); insilmaril@0: // replace substring of current depth in s with "1" insilmaril@0: part=s.section(",",-1); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: if (d>1) insilmaril@0: { insilmaril@0: // decrease number of parent insilmaril@411: num=QString ("%1").arg(num.toInt()-1); insilmaril@0: s=s.section (",",0,d-2) + ","+ typ+num; insilmaril@0: } else insilmaril@0: { insilmaril@0: // Special case, look at orientation insilmaril@473: if (xelection.single()->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@411: num=QString ("%1").arg(num.toInt()-1); insilmaril@0: else insilmaril@411: num=QString ("%1").arg(num.toInt()+1); insilmaril@0: s=typ+num; insilmaril@0: } insilmaril@0: insilmaril@0: if (select(s)) insilmaril@0: // pad to oldDepth, select the last branch for each depth insilmaril@0: for (i=d;icountBranches()>0) insilmaril@424: s+=",bo:"+ QString ("%1").arg( xelection.getBranch()->countBranches()-1 ); insilmaril@0: else insilmaril@0: break; insilmaril@0: else insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: // try to select the freshly built string insilmaril@0: found=select(s); insilmaril@0: d--; insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectUpperBranch() insilmaril@0: { insilmaril@491: if (isSelectBlocked() ) return; insilmaril@491: insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@491: if (bo && xelection.type()==Selection::Branch) insilmaril@0: { insilmaril@473: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@424: selectPrevBranchInt(); insilmaril@424: else insilmaril@424: if (bo->getDepth()==1) insilmaril@424: selectNextBranchInt(); insilmaril@424: else insilmaril@424: selectPrevBranchInt(); insilmaril@424: } insilmaril@424: } insilmaril@424: insilmaril@424: void MapEditor::selectLowerBranch() insilmaril@424: { insilmaril@491: if (isSelectBlocked() ) return; insilmaril@491: insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@491: if (bo && xelection.type()==Selection::Branch) insilmaril@473: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@424: selectNextBranchInt(); insilmaril@424: else insilmaril@424: if (bo->getDepth()==1) insilmaril@366: selectPrevBranchInt(); insilmaril@0: else insilmaril@366: selectNextBranchInt(); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::selectLeftBranch() insilmaril@0: { insilmaril@491: if (isSelectBlocked() ) return; insilmaril@491: insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@0: { insilmaril@491: if (xelection.type()== Selection::MapCenter) insilmaril@0: { insilmaril@424: par=xelection.getBranch(); insilmaril@0: bo=par->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: // Workaround for reselecting on left and right side insilmaril@473: if (bo->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@424: bo=par->getLastBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@0: bo=par->getLastBranch(); insilmaril@424: xelection.select(bo); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@424: par=(BranchObj*)(sel->getParObj()); insilmaril@473: if (sel->getOrientation()==LinkableMapObj::RightOfCenter) insilmaril@0: { insilmaril@491: if (xelection.type() == Selection::Branch || insilmaril@491: xelection.type() == Selection::FloatImage) insilmaril@0: { insilmaril@424: xelection.select(par); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@491: if (xelection.type() == Selection::Branch ) insilmaril@0: { insilmaril@424: bo=xelection.getBranch()->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@424: xelection.select(bo); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectRightBranch() insilmaril@0: { insilmaril@491: if (isSelectBlocked() ) return; insilmaril@491: insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@0: { insilmaril@491: if (xelection.type()==Selection::MapCenter) insilmaril@0: { insilmaril@424: par=xelection.getBranch(); insilmaril@0: bo=par->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@366: // Workaround for reselecting on left and right side insilmaril@473: if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@0: bo=par->getFirstBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@424: xelection.select(bo); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@424: par=(BranchObj*)(xelection.single()->getParObj()); insilmaril@473: if (xelection.single()->getOrientation()==LinkableMapObj::LeftOfCenter) insilmaril@0: { insilmaril@491: if (xelection.type() == Selection::Branch || insilmaril@491: xelection.type() == Selection::FloatImage) insilmaril@0: { insilmaril@424: xelection.select(par); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@491: if (xelection.type() == Selection::Branch) insilmaril@0: { insilmaril@424: bo=xelection.getBranch()->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@424: xelection.select(bo); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectFirstBranch() insilmaril@0: { insilmaril@424: BranchObj *bo1=xelection.getBranch(); insilmaril@0: BranchObj *bo2; insilmaril@0: BranchObj* par; insilmaril@424: if (bo1) insilmaril@424: { insilmaril@424: par=(BranchObj*)(bo1->getParObj()); insilmaril@424: bo2=par->getFirstBranch(); insilmaril@424: if (bo2) { insilmaril@424: xelection.select(bo2); insilmaril@442: xelection.update(); insilmaril@424: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@424: } insilmaril@424: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLastBranch() insilmaril@0: { insilmaril@424: BranchObj *bo1=xelection.getBranch(); insilmaril@0: BranchObj *bo2; insilmaril@0: BranchObj* par; insilmaril@424: if (bo1) insilmaril@424: { insilmaril@424: par=(BranchObj*)(bo1->getParObj()); insilmaril@424: bo2=par->getLastBranch(); insilmaril@424: if (bo2) insilmaril@0: { insilmaril@424: xelection.select(bo2); insilmaril@442: xelection.update(); insilmaril@424: ensureSelectionVisible(); insilmaril@528: sendSelection(); insilmaril@424: } insilmaril@424: } insilmaril@0: } insilmaril@0: insilmaril@408: void MapEditor::selectMapBackgroundImage () insilmaril@408: { insilmaril@408: Q3FileDialog *fd=new Q3FileDialog( this); insilmaril@408: fd->setMode (Q3FileDialog::ExistingFile); insilmaril@408: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@408: ImagePreview *p =new ImagePreview (fd); insilmaril@408: fd->setContentsPreviewEnabled( TRUE ); insilmaril@408: fd->setContentsPreview( p, p ); insilmaril@408: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@408: fd->setCaption(vymName+" - " +tr("Load background image")); insilmaril@408: fd->setDir (lastImageDir); insilmaril@408: fd->show(); insilmaril@408: insilmaril@408: if ( fd->exec() == QDialog::Accepted ) insilmaril@408: { insilmaril@412: // TODO selectMapBackgroundImg in QT4 use: lastImageDir=fd->directory(); insilmaril@408: lastImageDir=QDir (fd->dirPath()); insilmaril@408: setMapBackgroundImage (fd->selectedFile()); insilmaril@408: } insilmaril@408: } insilmaril@408: insilmaril@442: void MapEditor::setMapBackgroundImage (const QString &fn) //FIXME missing savestate insilmaril@408: { insilmaril@408: QColor oldcol=mapScene->backgroundBrush().color(); insilmaril@408: /* insilmaril@408: saveState( insilmaril@408: selection, insilmaril@408: QString ("setMapBackgroundImage (%1)").arg(oldcol.name()), insilmaril@408: selection, insilmaril@408: QString ("setMapBackgroundImage (%1)").arg(col.name()), insilmaril@408: QString("Set background color of map to %1").arg(col.name())); insilmaril@408: */ insilmaril@408: QBrush brush; insilmaril@408: brush.setTextureImage (QPixmap (fn)); insilmaril@408: mapScene->setBackgroundBrush(brush); insilmaril@408: } insilmaril@408: insilmaril@398: void MapEditor::selectMapBackgroundColor() insilmaril@0: { insilmaril@408: QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@408: setMapBackgroundColor( col ); insilmaril@0: } insilmaril@0: insilmaril@398: insilmaril@398: void MapEditor::setMapBackgroundColor(QColor col) insilmaril@0: { insilmaril@408: QColor oldcol=mapScene->backgroundBrush().color(); insilmaril@398: saveState( insilmaril@445: QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()), insilmaril@445: QString ("setMapBackgroundColor (\"%1\")").arg(col.name()), insilmaril@398: QString("Set background color of map to %1").arg(col.name())); insilmaril@408: mapScene->setBackgroundBrush(col); insilmaril@398: } insilmaril@398: insilmaril@398: QColor MapEditor::getMapBackgroundColor() insilmaril@398: { insilmaril@408: return mapScene->backgroundBrush().color(); insilmaril@0: } insilmaril@0: insilmaril@395: QColor MapEditor::getCurrentHeadingColor() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) return bo->getColor(); insilmaril@395: insilmaril@395: QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected")); insilmaril@395: return Qt::black; insilmaril@0: } insilmaril@0: insilmaril@417: void MapEditor::colorBranch (QColor c) insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@424: saveState( insilmaril@424: bo, insilmaril@445: QString ("colorBranch (\"%1\")").arg(bo->getColor().name()), insilmaril@424: bo, insilmaril@445: QString ("colorBranch (\"%1\")").arg(c.name()), insilmaril@424: QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name()) insilmaril@424: ); insilmaril@424: bo->setColor(c); // color branch insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@417: void MapEditor::colorSubtree (QColor c) insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@424: saveStateChangingPart( insilmaril@424: bo, insilmaril@424: bo, insilmaril@445: QString ("colorSubtree (\"%1\")").arg(c.name()), insilmaril@424: QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name()) insilmaril@424: ); insilmaril@424: bo->setColorSubtree (c); // color links, color childs insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::toggleStandardFlag(QString f) insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@424: QString u,r; insilmaril@424: if (bo->isSetStandardFlag(f)) insilmaril@366: { insilmaril@424: r="unsetFlag"; insilmaril@424: u="setFlag"; insilmaril@424: } insilmaril@424: else insilmaril@424: { insilmaril@424: u="unsetFlag"; insilmaril@424: r="setFlag"; insilmaril@424: } insilmaril@424: saveState( insilmaril@424: bo, insilmaril@424: QString("%1 (\"%2\")").arg(u).arg(f), insilmaril@424: bo, insilmaril@424: QString("%1 (\"%2\")").arg(r).arg(f), insilmaril@424: QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); insilmaril@424: bo->toggleStandardFlag (f,mainWindow->useFlagGroups()); insilmaril@442: xelection.update(); insilmaril@424: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: BranchObj* MapEditor::findText (QString s, bool cs) insilmaril@0: { insilmaril@366: QTextDocument::FindFlags flags=0; insilmaril@366: if (cs) flags=QTextDocument::FindCaseSensitively; insilmaril@366: insilmaril@0: if (!itFind) insilmaril@0: { // Nothing found or new find process insilmaril@0: if (EOFind) insilmaril@0: // nothing found, start again insilmaril@0: EOFind=false; insilmaril@645: itFind=model->first(); insilmaril@0: } insilmaril@0: bool searching=true; insilmaril@0: bool foundNote=false; insilmaril@0: while (searching && !EOFind) insilmaril@0: { insilmaril@0: if (itFind) insilmaril@0: { insilmaril@0: // Searching in Note insilmaril@0: if (itFind->getNote().contains(s,cs)) insilmaril@0: { insilmaril@424: if (xelection.single()!=itFind) insilmaril@0: { insilmaril@424: xelection.select(itFind); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@366: if (textEditor->findText(s,flags)) insilmaril@0: { insilmaril@0: searching=false; insilmaril@0: foundNote=true; insilmaril@0: } insilmaril@0: } insilmaril@0: // Searching in Heading insilmaril@0: if (searching && itFind->getHeading().contains (s,cs) ) insilmaril@0: { insilmaril@424: xelection.select(itFind); insilmaril@0: ensureSelectionVisible(); insilmaril@0: searching=false; insilmaril@0: } insilmaril@0: } insilmaril@0: if (!foundNote) insilmaril@0: { insilmaril@645: itFind=model->next(itFind); insilmaril@0: if (!itFind) EOFind=true; insilmaril@0: } insilmaril@0: } insilmaril@0: if (!searching) insilmaril@424: return xelection.getBranch(); insilmaril@424: else insilmaril@0: return NULL; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::findReset() insilmaril@0: { // Necessary if text to find changes during a find process insilmaril@0: itFind=NULL; insilmaril@0: EOFind=false; insilmaril@0: } insilmaril@395: void MapEditor::setURL(const QString &url) insilmaril@395: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@424: { insilmaril@395: QString oldurl=bo->getURL(); insilmaril@395: bo->setURL (url); insilmaril@395: saveState ( insilmaril@424: bo, insilmaril@395: QString ("setURL (\"%1\")").arg(oldurl), insilmaril@424: bo, insilmaril@395: QString ("setURL (\"%1\")").arg(url), insilmaril@395: QString ("set URL of %1 to %2").arg(getName(bo)).arg(url) insilmaril@395: ); insilmaril@395: updateActions(); insilmaril@645: model->reposition(); insilmaril@491: xelection.update(); insilmaril@491: ensureSelectionVisible(); insilmaril@395: } insilmaril@395: } insilmaril@0: insilmaril@0: void MapEditor::editURL() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@0: bool ok; insilmaril@0: QString text = QInputDialog::getText( insilmaril@0: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@143: bo->getURL(), &ok, this ); insilmaril@0: if ( ok) insilmaril@0: // user entered something and pressed OK insilmaril@395: setURL (text); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@528: void MapEditor::editLocalURL() insilmaril@528: { insilmaril@528: BranchObj *bo=xelection.getBranch(); insilmaril@528: if (bo) insilmaril@528: { insilmaril@528: QStringList filters; insilmaril@528: filters <<"All files (*)"; insilmaril@528: filters << tr("Text","Filedialog") + " (*.txt)"; insilmaril@528: filters << tr("Spreadsheet","Filedialog") + " (*.odp,*.sxc)"; insilmaril@528: filters << tr("Textdocument","Filedialog") +" (*.odw,*.sxw)"; insilmaril@528: filters << tr("Images","Filedialog") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"; insilmaril@528: QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Set URL to a local file")); insilmaril@528: fd->setFilters (filters); insilmaril@528: fd->setCaption(vymName+" - " +tr("Set URL to a local file")); insilmaril@528: fd->setDirectory (lastFileDir); insilmaril@528: if (! bo->getVymLink().isEmpty() ) insilmaril@528: fd->selectFile( bo->getURL() ); insilmaril@528: fd->show(); insilmaril@528: insilmaril@528: if ( fd->exec() == QDialog::Accepted ) insilmaril@528: { insilmaril@528: lastFileDir=QDir (fd->directory().path()); insilmaril@528: setURL (fd->selectedFile() ); insilmaril@528: } insilmaril@528: } insilmaril@528: } insilmaril@528: insilmaril@266: QString MapEditor::getURL() insilmaril@266: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@424: return bo->getURL(); insilmaril@266: else insilmaril@266: return ""; insilmaril@266: } insilmaril@266: insilmaril@366: QStringList MapEditor::getURLs() insilmaril@366: { insilmaril@366: QStringList urls; insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@366: { insilmaril@366: bo=bo->first(); insilmaril@366: while (bo) insilmaril@366: { insilmaril@366: if (!bo->getURL().isEmpty()) urls.append( bo->getURL()); insilmaril@366: bo=bo->next(); insilmaril@366: } insilmaril@366: } insilmaril@366: return urls; insilmaril@366: } insilmaril@366: insilmaril@366: insilmaril@0: void MapEditor::editHeading2URL() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@424: setURL (bo->getHeading()); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::editBugzilla2URL() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@143: QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); insilmaril@395: setURL (url); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@175: void MapEditor::editFATE2URL() insilmaril@175: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@175: { insilmaril@175: QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); insilmaril@395: saveState( insilmaril@424: bo, insilmaril@395: "setURL (\""+bo->getURL()+"\")", insilmaril@424: bo, insilmaril@395: "setURL (\""+url+"\")", insilmaril@395: QString("Use heading of %1 as link to FATE").arg(getName(bo)) insilmaril@395: ); insilmaril@175: bo->setURL (url); insilmaril@175: updateActions(); insilmaril@175: } insilmaril@175: } insilmaril@175: insilmaril@0: void MapEditor::editVymLink() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@404: QStringList filters; insilmaril@404: filters <<"VYM map (*.vym)"; insilmaril@404: QFileDialog *fd=new QFileDialog( this,vymName+" - " +tr("Link to another map")); insilmaril@404: fd->setFilters (filters); insilmaril@404: fd->setCaption(vymName+" - " +tr("Link to another map")); insilmaril@442: fd->setDirectory (lastFileDir); insilmaril@143: if (! bo->getVymLink().isEmpty() ) insilmaril@404: fd->selectFile( bo->getVymLink() ); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@143: { insilmaril@442: lastFileDir=QDir (fd->directory().path()); insilmaril@395: saveState( insilmaril@424: bo, insilmaril@395: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@424: bo, insilmaril@395: "setVymLink (\""+fd->selectedFile()+"\")", insilmaril@395: QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()) insilmaril@395: ); insilmaril@491: setVymLinkInt (fd->selectedFile() ); insilmaril@143: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::deleteVymLink() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@395: saveState( insilmaril@424: bo, insilmaril@395: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@424: bo, insilmaril@395: "setVymLink (\"\")", insilmaril@395: QString("Unset vymlink of %1").arg(getName(bo)) insilmaril@395: ); insilmaril@143: bo->setVymLink ("" ); insilmaril@0: updateActions(); insilmaril@645: model->reposition(); insilmaril@408: scene()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@395: void MapEditor::setHideExport(bool b) insilmaril@243: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@395: { insilmaril@424: bo->setHideInExport (b); insilmaril@395: QString u= b ? "false" : "true"; insilmaril@395: QString r=!b ? "false" : "true"; insilmaril@395: insilmaril@395: saveState( insilmaril@424: bo, insilmaril@395: QString ("setHideExport (%1)").arg(u), insilmaril@424: bo, insilmaril@395: QString ("setHideExport (%1)").arg(r), insilmaril@424: QString ("Set HideExport flag of %1 to %2").arg(getName(bo)).arg (r) insilmaril@395: ); insilmaril@243: updateActions(); insilmaril@645: model->reposition(); insilmaril@491: xelection.update(); insilmaril@408: scene()->update(); insilmaril@243: } insilmaril@243: } insilmaril@243: insilmaril@395: void MapEditor::toggleHideExport() insilmaril@395: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@424: setHideExport ( !bo->hideInExport() ); insilmaril@395: } insilmaril@395: insilmaril@0: QString MapEditor::getVymLink() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@424: return bo->getVymLink(); insilmaril@424: else insilmaril@424: return ""; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@366: QStringList MapEditor::getVymLinks() insilmaril@366: { insilmaril@366: QStringList links; insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@366: { insilmaril@366: bo=bo->first(); insilmaril@366: while (bo) insilmaril@366: { insilmaril@366: if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink()); insilmaril@366: bo=bo->next(); insilmaril@366: } insilmaril@366: } insilmaril@366: return links; insilmaril@366: } insilmaril@366: insilmaril@366: insilmaril@395: void MapEditor::deleteKeepChilds() insilmaril@98: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: BranchObj *par; insilmaril@424: if (bo) insilmaril@424: { insilmaril@424: par=(BranchObj*)(bo->getParObj()); insilmaril@408: QPointF p=bo->getRelPos(); insilmaril@395: saveStateChangingPart( insilmaril@424: bo->getParObj(), insilmaril@424: bo, insilmaril@395: "deleteKeepChilds ()", insilmaril@395: QString("Remove %1 and keep its childs").arg(getName(bo)) insilmaril@395: ); insilmaril@394: insilmaril@424: QString sel=bo->getSelectString(); insilmaril@98: unselect(); insilmaril@98: par->removeBranchHere(bo); insilmaril@645: model->reposition(); insilmaril@98: select (sel); insilmaril@424: xelection.getBranch()->move2RelPos (p); insilmaril@645: model->reposition(); insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@395: void MapEditor::deleteChilds() insilmaril@98: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@98: { insilmaril@395: saveStateChangingPart( insilmaril@491: bo, insilmaril@424: bo, insilmaril@395: "deleteChilds ()", insilmaril@424: QString( "Remove childs of branch %1").arg(getName(bo)) insilmaril@395: ); insilmaril@424: bo->removeChilds(); insilmaril@645: model->reposition(); insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@0: void MapEditor::editMapInfo() insilmaril@0: { insilmaril@0: ExtraInfoDialog dia; insilmaril@0: dia.setMapName (getFileName() ); insilmaril@645: dia.setAuthor (model->getAuthor() ); insilmaril@645: dia.setComment(model->getComment() ); insilmaril@0: insilmaril@0: // Calc some stats insilmaril@0: QString stats; insilmaril@408: stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6); insilmaril@0: insilmaril@0: uint b=0; insilmaril@0: uint f=0; insilmaril@0: uint n=0; insilmaril@103: uint xl=0; insilmaril@0: BranchObj *bo; insilmaril@645: bo=model->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: if (!bo->getNote().isEmpty() ) n++; insilmaril@0: f+= bo->countFloatImages(); insilmaril@0: b++; insilmaril@103: xl+=bo->countXLinks(); insilmaril@645: bo=model->next(bo); insilmaril@0: } insilmaril@0: stats+=QString ("%1 branches\n").arg (b-1,6); insilmaril@104: stats+=QString ("%1 xLinks \n").arg (xl,6); insilmaril@0: stats+=QString ("%1 notes\n").arg (n,6); insilmaril@0: stats+=QString ("%1 images\n").arg (f,6); insilmaril@0: dia.setStats (stats); insilmaril@0: insilmaril@0: // Finally show dialog insilmaril@0: if (dia.exec() == QDialog::Accepted) insilmaril@0: { insilmaril@398: setMapAuthor (dia.getAuthor() ); insilmaril@398: setMapComment (dia.getComment() ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@442: void MapEditor::ensureSelectionVisible() insilmaril@442: { insilmaril@442: LinkableMapObj *lmo=xelection.single(); insilmaril@442: if (lmo) ensureVisible (lmo->getBBox() ); insilmaril@442: insilmaril@442: } insilmaril@442: insilmaril@442: void MapEditor::updateSelection() insilmaril@442: { insilmaril@442: // Tell selection to update geometries insilmaril@442: xelection.update(); insilmaril@442: } insilmaril@442: insilmaril@0: void MapEditor::updateActions() insilmaril@0: { insilmaril@442: // Tell mainwindow to update states of actions insilmaril@390: mainWindow->updateActions(); insilmaril@412: // TODO maybe don't update if blockReposition is set insilmaril@0: } insilmaril@0: insilmaril@160: void MapEditor::updateNoteFlag() insilmaril@160: { insilmaril@427: setChanged(); insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@427: if (bo) insilmaril@427: { insilmaril@427: bo->updateNoteFlag(); insilmaril@427: mainWindow->updateActions(); insilmaril@427: } insilmaril@160: } insilmaril@160: insilmaril@398: void MapEditor::setMapAuthor (const QString &s) insilmaril@0: { insilmaril@398: saveState ( insilmaril@645: QString ("setMapAuthor (\"%1\")").arg(model->getAuthor()), insilmaril@398: QString ("setMapAuthor (\"%1\")").arg(s), insilmaril@398: QString ("Set author of map to \"%1\"").arg(s) insilmaril@398: ); insilmaril@645: model->setAuthor (s); insilmaril@398: } insilmaril@398: insilmaril@398: void MapEditor::setMapComment (const QString &s) insilmaril@398: { insilmaril@398: saveState ( insilmaril@645: QString ("setMapComment (\"%1\")").arg(model->getComment()), insilmaril@398: QString ("setMapComment (\"%1\")").arg(s), insilmaril@398: QString ("Set comment of map") insilmaril@398: ); insilmaril@645: model->setComment (s); insilmaril@398: } insilmaril@398: insilmaril@398: void MapEditor::setMapLinkStyle (const QString & s) insilmaril@398: { insilmaril@645: QString snow; insilmaril@645: if (linkstyle==LinkableMapObj::Line) insilmaril@645: snow="StyleLine"; insilmaril@645: else if (linkstyle==LinkableMapObj::Parabel) insilmaril@645: snow="StyleParabel"; insilmaril@645: else if (linkstyle==LinkableMapObj::PolyLine) insilmaril@645: snow="StylePolyLine"; insilmaril@645: else if (linkstyle==LinkableMapObj::PolyParabel) insilmaril@645: snow="StyleParabel"; insilmaril@645: insilmaril@645: saveState ( insilmaril@398: QString("setMapLinkStyle (\"%1\")").arg(s), insilmaril@645: QString("setMapLinkStyle (\"%1\")").arg(snow), insilmaril@398: QString("Set map link style (\"%1\")").arg(s) insilmaril@398: ); insilmaril@398: insilmaril@398: if (s=="StyleLine") insilmaril@473: linkstyle=LinkableMapObj::Line; insilmaril@398: else if (s=="StyleParabel") insilmaril@473: linkstyle=LinkableMapObj::Parabel; insilmaril@398: else if (s=="StylePolyLine") insilmaril@473: linkstyle=LinkableMapObj::PolyLine; insilmaril@398: else insilmaril@473: linkstyle=LinkableMapObj::PolyParabel; insilmaril@398: insilmaril@0: BranchObj *bo; insilmaril@645: bo=model->first(); insilmaril@645: bo=model->next(bo); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkStyle(bo->getDefLinkStyle()); insilmaril@645: bo=model->next(bo); insilmaril@0: } insilmaril@645: model->reposition(); insilmaril@0: } insilmaril@0: insilmaril@473: LinkableMapObj::Style MapEditor::getMapLinkStyle () insilmaril@0: { insilmaril@0: return linkstyle; insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::setMapDefLinkColor(QColor c) insilmaril@0: { insilmaril@97: defLinkColor=c; insilmaril@497: BranchObj *bo; insilmaril@645: bo=model->first(); insilmaril@497: while (bo) insilmaril@497: { insilmaril@497: bo->setLinkColor(); insilmaril@645: bo=model->next(bo); insilmaril@497: } insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::setMapLinkColorHintInt() insilmaril@0: { insilmaril@398: // called from setMapLinkColorHint(lch) or at end of parse insilmaril@0: BranchObj *bo; insilmaril@645: bo=model->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@645: bo=model->next(bo); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@473: void MapEditor::setMapLinkColorHint(LinkableMapObj::ColorHint lch) insilmaril@0: { insilmaril@0: linkcolorhint=lch; insilmaril@398: setMapLinkColorHintInt(); insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::toggleMapLinkColorHint() insilmaril@0: { insilmaril@473: if (linkcolorhint==LinkableMapObj::HeadingColor) insilmaril@473: linkcolorhint=LinkableMapObj::DefaultColor; insilmaril@0: else insilmaril@473: linkcolorhint=LinkableMapObj::HeadingColor; insilmaril@0: BranchObj *bo; insilmaril@645: bo=model->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@645: bo=model->next(bo); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@473: LinkableMapObj::ColorHint MapEditor::getMapLinkColorHint() insilmaril@0: { insilmaril@0: return linkcolorhint; insilmaril@0: } insilmaril@0: insilmaril@398: QColor MapEditor::getMapDefLinkColor() insilmaril@0: { insilmaril@97: return defLinkColor; insilmaril@97: } insilmaril@97: insilmaril@398: void MapEditor::setMapDefXLinkColor(QColor col) insilmaril@97: { insilmaril@97: defXLinkColor=col; insilmaril@97: } insilmaril@97: insilmaril@398: QColor MapEditor::getMapDefXLinkColor() insilmaril@97: { insilmaril@97: return defXLinkColor; insilmaril@97: } insilmaril@97: insilmaril@398: void MapEditor::setMapDefXLinkWidth (int w) insilmaril@97: { insilmaril@97: defXLinkWidth=w; insilmaril@97: } insilmaril@97: insilmaril@398: int MapEditor::getMapDefXLinkWidth() insilmaril@97: { insilmaril@97: return defXLinkWidth; insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::selectMapLinkColor() insilmaril@0: { insilmaril@97: QColor col = QColorDialog::getColor( defLinkColor, this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@398: saveState ( insilmaril@398: QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()), insilmaril@398: QString("setMapDefLinkColor (\"%1\")").arg(col.name()), insilmaril@497: QString("Set map link color to %1").arg(col.name()) insilmaril@398: ); insilmaril@398: setMapDefLinkColor( col ); insilmaril@442: } insilmaril@442: insilmaril@442: void MapEditor::selectMapSelectionColor() insilmaril@442: { insilmaril@442: QColor col = QColorDialog::getColor( defLinkColor, this ); insilmaril@442: setSelectionColor (col); insilmaril@442: } insilmaril@442: insilmaril@442: void MapEditor::setSelectionColorInt (QColor col) insilmaril@442: { insilmaril@442: if ( !col.isValid() ) return; insilmaril@442: xelection.setColor (col); insilmaril@442: } insilmaril@442: insilmaril@442: void MapEditor::setSelectionColor(QColor col) insilmaril@442: { insilmaril@442: if ( !col.isValid() ) return; insilmaril@442: saveState ( insilmaril@442: QString("setSelectionColor (%1)").arg(xelection.getColor().name()), insilmaril@442: QString("setSelectionColor (%1)").arg(col.name()), insilmaril@442: QString("Set color of selection box to %1").arg(col.name()) insilmaril@442: ); insilmaril@442: setSelectionColorInt (col); insilmaril@442: } insilmaril@442: insilmaril@442: QColor MapEditor::getSelectionColor() insilmaril@442: { insilmaril@442: return xelection.getColor(); insilmaril@0: } insilmaril@0: insilmaril@473: bool MapEditor::scrollBranch(BranchObj *bo) insilmaril@0: { insilmaril@427: if (bo) insilmaril@0: { insilmaril@427: if (bo->isScrolled()) return false; insilmaril@427: if (bo->countBranches()==0) return false; insilmaril@427: if (bo->getDepth()==0) return false; insilmaril@395: QString u,r; insilmaril@427: r="scroll"; insilmaril@427: u="unscroll"; insilmaril@395: saveState( insilmaril@424: bo, insilmaril@395: QString ("%1 ()").arg(u), insilmaril@424: bo, insilmaril@395: QString ("%1 ()").arg(r), insilmaril@395: QString ("%1 %2").arg(r).arg(getName(bo)) insilmaril@395: ); insilmaril@0: bo->toggleScroll(); insilmaril@491: xelection.update(); insilmaril@408: scene()->update(); insilmaril@427: return true; insilmaril@427: } insilmaril@427: return false; insilmaril@427: } insilmaril@427: insilmaril@473: bool MapEditor::unscrollBranch(BranchObj *bo) insilmaril@427: { insilmaril@427: if (bo) insilmaril@427: { insilmaril@427: if (!bo->isScrolled()) return false; insilmaril@427: if (bo->countBranches()==0) return false; insilmaril@427: if (bo->getDepth()==0) return false; insilmaril@427: QString u,r; insilmaril@427: u="scroll"; insilmaril@427: r="unscroll"; insilmaril@427: saveState( insilmaril@427: bo, insilmaril@427: QString ("%1 ()").arg(u), insilmaril@427: bo, insilmaril@427: QString ("%1 ()").arg(r), insilmaril@427: QString ("%1 %2").arg(r).arg(getName(bo)) insilmaril@427: ); insilmaril@427: bo->toggleScroll(); insilmaril@491: xelection.update(); insilmaril@427: scene()->update(); insilmaril@427: return true; insilmaril@427: } insilmaril@427: return false; insilmaril@427: } insilmaril@427: insilmaril@427: void MapEditor::toggleScroll() insilmaril@427: { insilmaril@427: BranchObj *bo=xelection.getBranch(); insilmaril@491: if (xelection.type()==Selection::Branch ) insilmaril@427: { insilmaril@427: if (bo->isScrolled()) insilmaril@473: unscrollBranch (bo); insilmaril@427: else insilmaril@473: scrollBranch (bo); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@473: void MapEditor::unscrollChilds() insilmaril@0: { insilmaril@428: BranchObj *bo=xelection.getBranch(); insilmaril@428: if (bo) insilmaril@0: { insilmaril@428: bo->first(); insilmaril@428: while (bo) insilmaril@428: { insilmaril@473: if (bo->isScrolled()) unscrollBranch (bo); insilmaril@428: bo=bo->next(); insilmaril@428: } insilmaril@428: } insilmaril@0: } insilmaril@0: insilmaril@432: FloatImageObj* MapEditor::loadFloatImageInt (QString fn) insilmaril@432: { insilmaril@432: BranchObj *bo=xelection.getBranch(); insilmaril@432: if (bo) insilmaril@432: { insilmaril@432: FloatImageObj *fio; insilmaril@432: bo->addFloatImage(); insilmaril@432: fio=bo->getLastFloatImage(); insilmaril@432: fio->load(fn); insilmaril@645: model->reposition(); insilmaril@432: scene()->update(); insilmaril@432: return fio; insilmaril@432: } insilmaril@432: return NULL; insilmaril@432: } insilmaril@428: insilmaril@0: void MapEditor::loadFloatImage () insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@0: insilmaril@366: Q3FileDialog *fd=new Q3FileDialog( this); insilmaril@366: fd->setMode (Q3FileDialog::ExistingFiles); insilmaril@0: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@0: ImagePreview *p =new ImagePreview (fd); insilmaril@0: fd->setContentsPreviewEnabled( TRUE ); insilmaril@0: fd->setContentsPreview( p, p ); insilmaril@366: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@404: fd->setCaption(vymName+" - " +tr("Load image")); insilmaril@0: fd->setDir (lastImageDir); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@491: // TODO loadFIO in QT4 use: lastImageDir=fd->directory(); insilmaril@366: lastImageDir=QDir (fd->dirPath()); insilmaril@432: QString s; insilmaril@395: FloatImageObj *fio; insilmaril@432: for (int j=0; jselectedFiles().count(); j++) insilmaril@185: { insilmaril@432: s=fd->selectedFiles().at(j); insilmaril@432: fio=loadFloatImageInt (s); insilmaril@432: if (fio) insilmaril@432: saveState( insilmaril@432: (LinkableMapObj*)fio, insilmaril@432: "delete ()", insilmaril@432: bo, insilmaril@432: QString ("loadImage (%1)").arg(s ), insilmaril@432: QString("Add image %1 to %2").arg(s).arg(getName(bo)) insilmaril@432: ); insilmaril@432: else insilmaril@491: // TODO loadFIO error handling insilmaril@432: qWarning ("Failed to load "+s); insilmaril@185: } insilmaril@0: } insilmaril@236: delete (p); insilmaril@236: delete (fd); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@434: void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) insilmaril@434: { insilmaril@434: fio->save (fn,type); insilmaril@434: } insilmaril@434: insilmaril@366: void MapEditor::saveFloatImage () insilmaril@0: { insilmaril@424: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@424: if (fio) insilmaril@0: { insilmaril@366: QFileDialog *fd=new QFileDialog( this); insilmaril@366: fd->setFilters (imageIO.getFilters()); insilmaril@404: fd->setCaption(vymName+" - " +tr("Save image")); insilmaril@366: fd->setFileMode( QFileDialog::AnyFile ); insilmaril@366: fd->setDirectory (lastImageDir); insilmaril@366: // fd->setSelection (fio->getOriginalFilename()); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@434: if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1) insilmaril@0: { insilmaril@434: fn=fd->selectedFiles().at(0); insilmaril@434: if (QFile (fn).exists() ) insilmaril@0: { insilmaril@404: QMessageBox mb( vymName, insilmaril@159: tr("The file %1 exists already.\n" insilmaril@434: "Do you want to overwrite it?").arg(fn), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@0: QMessageBox::QMessageBox::NoButton ); insilmaril@0: insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save insilmaril@0: break;; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@377: delete (fd); insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@434: saveFloatImageInt (fio,fd->selectedFilter(),fn ); insilmaril@0: } insilmaril@377: delete (fd); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@473: void MapEditor::setFrameType(const FrameObj::FrameType &t) insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@473: QString s=bo->getFrameTypeName(); insilmaril@424: bo->setFrameType (t); insilmaril@473: saveState (bo, QString("setFrameType (\"%1\")").arg(s), insilmaril@473: bo, QString ("setFrameType (\"%1\")").arg(bo->getFrameTypeName()),QString ("set type of frame to %1").arg(s)); insilmaril@645: model->reposition(); insilmaril@424: bo->updateLink(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@473: void MapEditor::setFrameType(const QString &s) insilmaril@445: { insilmaril@445: BranchObj *bo=xelection.getBranch(); insilmaril@445: if (bo) insilmaril@445: { insilmaril@473: saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), insilmaril@473: bo, QString ("setFrameType (\"%1\")").arg(s),QString ("set type of frame to %1").arg(s)); insilmaril@445: bo->setFrameType (s); insilmaril@645: model->reposition(); insilmaril@445: bo->updateLink(); insilmaril@445: } insilmaril@445: } insilmaril@445: insilmaril@473: void MapEditor::setFramePenColor(const QColor &c) insilmaril@442: { insilmaril@442: BranchObj *bo=xelection.getBranch(); insilmaril@442: if (bo) insilmaril@473: { insilmaril@473: saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), insilmaril@473: bo, QString ("setFramePenColor (\"%1\")").arg(c.name() ),QString ("set pen color of frame to %1").arg(c.name() )); insilmaril@442: bo->setFramePenColor (c); insilmaril@473: } insilmaril@442: } insilmaril@442: insilmaril@473: void MapEditor::setFrameBrushColor(const QColor &c) insilmaril@442: { insilmaril@442: BranchObj *bo=xelection.getBranch(); insilmaril@442: if (bo) insilmaril@473: { insilmaril@473: saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), insilmaril@473: bo, QString ("setFrameBrushColor (\"%1\")").arg(c.name() ),QString ("set brush color of frame to %1").arg(c.name() )); insilmaril@442: bo->setFrameBrushColor (c); insilmaril@473: } insilmaril@473: } insilmaril@473: insilmaril@486: void MapEditor::setFramePadding (const int &i) insilmaril@473: { insilmaril@473: BranchObj *bo=xelection.getBranch(); insilmaril@473: if (bo) insilmaril@473: { insilmaril@486: saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), insilmaril@486: bo, QString ("setFramePadding (\"%1\")").arg(i),QString ("set brush color of frame to %1").arg(i)); insilmaril@486: bo->setFramePadding (i); insilmaril@645: model->reposition(); insilmaril@486: bo->updateLink(); insilmaril@473: } insilmaril@473: } insilmaril@473: insilmaril@486: void MapEditor::setFrameBorderWidth(const int &i) insilmaril@473: { insilmaril@473: BranchObj *bo=xelection.getBranch(); insilmaril@473: if (bo) insilmaril@473: { insilmaril@486: saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), insilmaril@486: bo, QString ("setFrameBorderWidth (\"%1\")").arg(i),QString ("set border width of frame to %1").arg(i)); insilmaril@486: bo->setFrameBorderWidth (i); insilmaril@645: model->reposition(); insilmaril@486: bo->updateLink(); insilmaril@473: } insilmaril@442: } insilmaril@442: insilmaril@437: void MapEditor::setIncludeImagesVer(bool b) insilmaril@175: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@424: { insilmaril@434: QString u= b ? "false" : "true"; insilmaril@434: QString r=!b ? "false" : "true"; insilmaril@434: insilmaril@434: saveState( insilmaril@434: bo, insilmaril@434: QString("setIncludeImagesVertically (%1)").arg(u), insilmaril@434: bo, insilmaril@434: QString("setIncludeImagesVertically (%1)").arg(r), insilmaril@434: QString("Include images vertically in %1").arg(getName(bo)) insilmaril@434: ); insilmaril@424: bo->setIncludeImagesVer(b); insilmaril@645: model->reposition(); insilmaril@424: } insilmaril@175: } insilmaril@175: insilmaril@437: void MapEditor::setIncludeImagesHor(bool b) insilmaril@175: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@424: { insilmaril@434: QString u= b ? "false" : "true"; insilmaril@434: QString r=!b ? "false" : "true"; insilmaril@434: insilmaril@434: saveState( insilmaril@434: bo, insilmaril@434: QString("setIncludeImagesHorizontally (%1)").arg(u), insilmaril@434: bo, insilmaril@434: QString("setIncludeImagesHorizontally (%1)").arg(r), insilmaril@434: QString("Include images horizontally in %1").arg(getName(bo)) insilmaril@434: ); insilmaril@424: bo->setIncludeImagesHor(b); insilmaril@645: model->reposition(); insilmaril@424: } insilmaril@175: } insilmaril@175: insilmaril@491: void MapEditor::setHideLinkUnselected (bool b) insilmaril@160: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel && insilmaril@491: (xelection.type() == Selection::Branch || insilmaril@491: xelection.type() == Selection::MapCenter || insilmaril@491: xelection.type() == Selection::FloatImage )) insilmaril@491: { insilmaril@491: QString u= b ? "false" : "true"; insilmaril@491: QString r=!b ? "false" : "true"; insilmaril@491: insilmaril@491: saveState( insilmaril@491: sel, insilmaril@491: QString("setHideLinkUnselected (%1)").arg(u), insilmaril@491: sel, insilmaril@491: QString("setHideLinkUnselected (%1)").arg(r), insilmaril@491: QString("Hide link of %1 if unselected").arg(getName(sel)) insilmaril@491: ); insilmaril@424: sel->setHideLinkUnselected(b); insilmaril@491: } insilmaril@160: } insilmaril@160: insilmaril@491: void MapEditor::importDirInt(BranchObj *dst, QDir d) insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@0: // Traverse directories insilmaril@0: d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks ); insilmaril@366: QFileInfoList list = d.entryInfoList(); insilmaril@366: QFileInfo fi; insilmaril@366: insilmaril@366: for (int i = 0; i < list.size(); ++i) insilmaril@0: { insilmaril@366: fi=list.at(i); insilmaril@366: if (fi.fileName() != "." && fi.fileName() != ".." ) insilmaril@0: { insilmaril@0: dst->addBranch(); insilmaril@0: bo=dst->getLastBranch(); insilmaril@366: bo->setHeading (fi.fileName() ); insilmaril@243: bo->setColor (QColor("blue")); insilmaril@0: bo->toggleScroll(); insilmaril@366: if ( !d.cd(fi.fileName()) ) insilmaril@366: QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); insilmaril@0: else insilmaril@0: { insilmaril@103: // Recursively add subdirs insilmaril@366: importDirInt (bo,d); insilmaril@0: d.cdUp(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: // Traverse files insilmaril@0: d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks ); insilmaril@366: list = d.entryInfoList(); insilmaril@366: insilmaril@366: for (int i = 0; i < list.size(); ++i) insilmaril@0: { insilmaril@366: fi=list.at(i); insilmaril@0: dst->addBranch(); insilmaril@0: bo=dst->getLastBranch(); insilmaril@366: bo->setHeading (fi.fileName() ); insilmaril@243: bo->setColor (QColor("black")); insilmaril@366: if (fi.fileName().right(4) == ".vym" ) insilmaril@366: bo->setVymLink (fi.filePath()); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@491: void MapEditor::importDirInt (const QString &s) insilmaril@491: { insilmaril@491: BranchObj *bo=xelection.getBranch(); insilmaril@491: if (bo) insilmaril@491: { insilmaril@491: saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); insilmaril@491: insilmaril@491: QDir d(s); insilmaril@491: importDirInt (bo,d); insilmaril@491: } insilmaril@491: } insilmaril@491: insilmaril@0: void MapEditor::importDir() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@404: QStringList filters; insilmaril@404: filters <<"VYM map (*.vym)"; insilmaril@404: QFileDialog *fd=new QFileDialog( this,vymName+ " - " +tr("Choose directory structure to import")); insilmaril@404: fd->setMode (QFileDialog::DirectoryOnly); insilmaril@404: fd->setFilters (filters); insilmaril@404: fd->setCaption(vymName+" - " +tr("Choose directory structure to import")); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@491: importDirInt (fd->selectedFile() ); insilmaril@645: model->reposition(); insilmaril@408: scene()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@95: void MapEditor::followXLink(int i) insilmaril@89: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@89: { insilmaril@424: bo=bo->XLinkTargetAt(i); insilmaril@97: if (bo) insilmaril@97: { insilmaril@424: xelection.select(bo); insilmaril@97: ensureSelectionVisible(); insilmaril@97: } insilmaril@89: } insilmaril@89: } insilmaril@89: insilmaril@421: void MapEditor::editXLink(int i) // FIXME missing saveState insilmaril@94: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@94: { insilmaril@424: XLinkObj *xlo=bo->XLinkAt(i); insilmaril@97: if (xlo) insilmaril@94: { insilmaril@97: EditXLinkDialog dia; insilmaril@97: dia.setXLink (xlo); insilmaril@424: dia.setSelection(bo); insilmaril@97: if (dia.exec() == QDialog::Accepted) insilmaril@97: { insilmaril@97: if (dia.useSettingsGlobal() ) insilmaril@97: { insilmaril@398: setMapDefXLinkColor (xlo->getColor() ); insilmaril@398: setMapDefXLinkWidth (xlo->getWidth() ); insilmaril@97: } insilmaril@97: if (dia.deleteXLink()) insilmaril@424: bo->deleteXLinkAt(i); insilmaril@97: } insilmaril@97: } insilmaril@97: } insilmaril@94: } insilmaril@94: insilmaril@628: AttributeTable* MapEditor::attributeTable() insilmaril@628: { insilmaril@628: return attrTable; insilmaril@628: } insilmaril@628: insilmaril@527: void MapEditor::testFunction1() insilmaril@0: { insilmaril@527: /* insilmaril@473: BranchObj *bo=xelection.getBranch(); insilmaril@473: if (bo) animObjList.append( bo ); insilmaril@527: */ insilmaril@432: insilmaril@420: /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere insilmaril@260: if (hidemode==HideNone) insilmaril@185: { insilmaril@260: setHideTmpMode (HideExport); insilmaril@260: mapCenter->calcBBoxSizeWithChilds(); insilmaril@408: QRectF totalBBox=mapCenter->getTotalBBox(); insilmaril@408: QRectF mapRect=totalBBox; insilmaril@260: QCanvasRectangle *frame=NULL; insilmaril@260: insilmaril@260: cout << " map has =("<setBrush (QColor(white)); insilmaril@260: frame->setPen (QColor(black)); insilmaril@408: frame->setZValue(0); insilmaril@260: frame->show(); insilmaril@260: } insilmaril@260: else insilmaril@260: { insilmaril@260: setHideTmpMode (HideNone); insilmaril@260: } insilmaril@260: cout <<" hidemode="<addMapCenter(); insilmaril@638: insilmaril@638: /* insilmaril@628: // Toggle hidemode insilmaril@628: if (hidemode==HideExport) insilmaril@628: setHideTmpMode (HideNone); insilmaril@628: else insilmaril@628: setHideTmpMode (HideExport); insilmaril@638: */ insilmaril@628: /* insilmaril@595: LinkableMapObj *lmo=xelection.getBranch(); insilmaril@595: if (lmo) insilmaril@595: { insilmaril@595: cout << "LMO::id="<getID().ascii()<state() & Qt::ControlModifier) insilmaril@267: mainWindow->editOpenURLTab(); insilmaril@267: else insilmaril@267: mainWindow->editOpenURL(); insilmaril@267: } insilmaril@267: else if (foname=="vymLink") insilmaril@267: { insilmaril@267: mainWindow->editOpenVymLink(); insilmaril@267: // tabWidget may change, better return now insilmaril@267: // before segfaulting... insilmaril@267: } else if (foname=="note") insilmaril@267: mainWindow->windowToggleNoteEditor(); insilmaril@267: else if (foname=="hideInExport") insilmaril@267: toggleHideExport(); insilmaril@442: xelection.update(); insilmaril@267: return; insilmaril@267: } insilmaril@267: } insilmaril@442: insilmaril@442: // No system flag clicked, take care of modmodes (CTRL-Click) insilmaril@366: if (e->state() & Qt::ControlModifier) insilmaril@0: { insilmaril@473: if (mainWindow->getModMode()==Main::ModModeColor) insilmaril@83: { insilmaril@83: pickingColor=true; insilmaril@398: setCursor (PickColorCursor); insilmaril@83: return; insilmaril@83: } insilmaril@473: if (mainWindow->getModMode()==Main::ModModeXLink) insilmaril@83: { insilmaril@90: BranchObj *bo_begin=NULL; insilmaril@90: if (lmo) insilmaril@90: bo_begin=(BranchObj*)(lmo); insilmaril@90: else insilmaril@424: if (xelection.getBranch() ) insilmaril@424: bo_begin=xelection.getBranch(); insilmaril@90: if (bo_begin) insilmaril@83: { insilmaril@83: drawingLink=true; insilmaril@90: linkingObj_src=bo_begin; insilmaril@408: tmpXLink=new XLinkObj (mapScene); insilmaril@95: tmpXLink->setBegin (bo_begin); insilmaril@95: tmpXLink->setEnd (p); insilmaril@97: tmpXLink->setColor(defXLinkColor); insilmaril@97: tmpXLink->setWidth(defXLinkWidth); insilmaril@95: tmpXLink->updateXLink(); insilmaril@95: tmpXLink->setVisibility (true); insilmaril@83: return; insilmaril@89: } insilmaril@267: } insilmaril@442: } // End of modmodes insilmaril@442: insilmaril@0: if (lmo) insilmaril@267: { insilmaril@442: // Select the clicked object insilmaril@366: selectInt (lmo); insilmaril@442: insilmaril@0: // Left Button Move Branches insilmaril@366: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@424: //movingObj_start.setX( p.x() - selection->x() );// TODO replaced selection->lmo here insilmaril@424: //movingObj_start.setY( p.y() - selection->y() ); insilmaril@424: movingObj_start.setX( p.x() - lmo->x() ); insilmaril@424: movingObj_start.setY( p.y() - lmo->y() ); insilmaril@129: movingObj_orgPos.setX (lmo->x() ); insilmaril@129: movingObj_orgPos.setY (lmo->y() ); insilmaril@366: movingObj_orgRelPos=lmo->getRelPos(); insilmaril@129: insilmaril@93: // If modMode==copy, then we want to "move" the _new_ object around insilmaril@93: // then we need the offset from p to the _old_ selection, because of tmp insilmaril@473: if (mainWindow->getModMode()==Main::ModModeCopy && insilmaril@366: e->state() & Qt::ControlModifier) insilmaril@93: { insilmaril@645: BranchObj *bo=xelection.getBranch(); insilmaril@645: if (bo) insilmaril@93: { insilmaril@93: copyingObj=true; insilmaril@645: bo->addBranch ((BranchObj*)xelection.single()); insilmaril@93: unselect(); insilmaril@645: xelection.select(bo->getLastBranch()); insilmaril@645: model->reposition(); insilmaril@93: } insilmaril@421: } insilmaril@421: insilmaril@424: movingObj=xelection.single(); insilmaril@0: } else insilmaril@0: // Middle Button Toggle Scroll insilmaril@0: // (On Mac OS X this won't work, but we still have insilmaril@0: // a button in the toolbar) insilmaril@366: if (e->button() == Qt::MidButton ) insilmaril@0: toggleScroll(); insilmaril@0: updateActions(); insilmaril@442: xelection.update(); insilmaril@0: } else insilmaril@408: { // No MapObj found, we are on the scene itself insilmaril@408: // Left Button move Pos of sceneView insilmaril@366: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@0: movingObj=NULL; // move Content not Obj insilmaril@0: movingObj_start=e->globalPos(); insilmaril@408: movingCont_start=QPointF ( insilmaril@408: horizontalScrollBar()->value(), insilmaril@408: verticalScrollBar()->value()); insilmaril@408: movingVec=QPointF(0,0); insilmaril@398: setCursor(HandOpenCursor); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@408: void MapEditor::mouseMoveEvent(QMouseEvent* e) insilmaril@0: { insilmaril@408: QPointF p = mapToScene(e->pos()); insilmaril@424: LinkableMapObj *lmosel=xelection.single(); insilmaril@83: insilmaril@0: // Move the selected MapObj insilmaril@424: if ( lmosel && movingObj) insilmaril@0: { insilmaril@421: // reset cursor if we are moving and don't copy insilmaril@473: if (mainWindow->getModMode()!=Main::ModModeCopy) insilmaril@421: setCursor (Qt::ArrowCursor); insilmaril@421: insilmaril@408: // To avoid jumping of the sceneView, only insilmaril@164: // ensureSelectionVisible, if not tmp linked insilmaril@424: if (!lmosel->hasParObjTmp()) insilmaril@164: ensureSelectionVisible (); insilmaril@0: insilmaril@83: // Now move the selection, but add relative position insilmaril@83: // (movingObj_start) where selection was chosen with insilmaril@83: // mousepointer. (This avoids flickering resp. jumping insilmaril@0: // of selection back to absPos) insilmaril@0: insilmaril@0: // Check if we could link insilmaril@645: LinkableMapObj* lmo=model->findMapObj(p, lmosel); insilmaril@0: insilmaril@0: insilmaril@424: FloatObj *fio=xelection.getFloatImage(); insilmaril@424: if (fio) insilmaril@0: { insilmaril@424: fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@424: fio->setRelPos(); insilmaril@424: fio->updateLink(); //no need for reposition, if we update link here insilmaril@442: xelection.update(); insilmaril@0: insilmaril@0: // Relink float to new mapcenter or branch, if shift is pressed insilmaril@0: // Only relink, if selection really has a new parent insilmaril@388: if ( (e->modifiers()==Qt::ShiftModifier) && lmo && insilmaril@0: ( (typeid(*lmo)==typeid(BranchObj)) || insilmaril@0: (typeid(*lmo)==typeid(MapCenterObj)) ) && insilmaril@424: ( lmo != fio->getParObj()) insilmaril@0: ) insilmaril@0: { insilmaril@424: if (typeid(*fio) == typeid(FloatImageObj) && insilmaril@420: ( (typeid(*lmo)==typeid(BranchObj) || insilmaril@420: typeid(*lmo)==typeid(MapCenterObj)) )) insilmaril@0: { insilmaril@420: insilmaril@420: // Also save the move which was done so far insilmaril@420: QString pold=qpointfToString(movingObj_orgRelPos); insilmaril@420: QString pnow=qpointfToString(fio->getRelPos()); insilmaril@420: saveState( insilmaril@424: fio, insilmaril@420: "moveRel "+pold, insilmaril@424: fio, insilmaril@420: "moveRel "+pnow, insilmaril@625: QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow)); insilmaril@420: fio->getParObj()->requestReposition(); insilmaril@645: model->reposition(); insilmaril@420: insilmaril@420: linkTo (lmo->getSelectString()); insilmaril@442: //movingObj=lmosel; insilmaril@442: //movingObj_orgRelPos=lmosel->getRelPos(); insilmaril@420: insilmaril@645: model->reposition(); insilmaril@0: } insilmaril@0: } insilmaril@388: } else insilmaril@388: { // selection != a FloatObj insilmaril@0: if (lmosel->getDepth()==0) insilmaril@0: { insilmaril@388: // Move MapCenter insilmaril@388: if (e->buttons()== Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) insilmaril@645: ((MapCenterObj*)lmosel)->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: else insilmaril@645: lmosel->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@645: model->updateRelPositions(); insilmaril@0: } else insilmaril@0: { insilmaril@0: if (lmosel->getDepth()==1) insilmaril@0: { insilmaril@388: // Move mainbranch insilmaril@0: lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@388: lmosel->setRelPos(); insilmaril@0: } else insilmaril@0: { insilmaril@388: // Move ordinary branch insilmaril@473: if (lmosel->getOrientation() == LinkableMapObj::LeftOfCenter) insilmaril@0: // Add width of bbox here, otherwise alignRelTo will cause jumping around insilmaril@0: lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), insilmaril@175: p.y()-movingObj_start.y() +lmosel->getTopPad() ); insilmaril@0: else insilmaril@175: lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad()); insilmaril@0: } insilmaril@0: insilmaril@431: // Maybe we can relink temporary? insilmaril@431: if (lmo && (lmo!=lmosel) && xelection.getBranch() && insilmaril@431: (typeid(*lmo)==typeid(BranchObj) || insilmaril@431: typeid(*lmo)==typeid(MapCenterObj)) ) insilmaril@431: insilmaril@0: { insilmaril@388: if (e->modifiers()==Qt::ControlModifier) insilmaril@0: { insilmaril@0: // Special case: CTRL to link below lmo insilmaril@0: lmosel->setParObjTmp (lmo,p,+1); insilmaril@0: } insilmaril@388: else if (e->modifiers()==Qt::ShiftModifier) insilmaril@0: lmosel->setParObjTmp (lmo,p,-1); insilmaril@0: else insilmaril@0: lmosel->setParObjTmp (lmo,p,0); insilmaril@0: } else insilmaril@0: { insilmaril@93: lmosel->unsetParObjTmp(); insilmaril@0: } insilmaril@428: // reposition subbranch insilmaril@428: lmosel->reposition(); insilmaril@0: } // depth>0 insilmaril@0: insilmaril@442: xelection.update(); insilmaril@0: } // no FloatImageObj insilmaril@0: insilmaril@408: scene()->update(); insilmaril@0: return; insilmaril@0: } // selection && moving_obj insilmaril@0: insilmaril@83: // Draw a link from one branch to another insilmaril@83: if (drawingLink) insilmaril@83: { insilmaril@95: tmpXLink->setEnd (p); insilmaril@95: tmpXLink->updateXLink(); insilmaril@83: } insilmaril@83: insilmaril@408: // Move sceneView insilmaril@411: if (!movingObj && !pickingColor &&!drawingLink && e->buttons() == Qt::LeftButton ) insilmaril@0: { insilmaril@408: QPointF p=e->globalPos(); insilmaril@0: movingVec.setX(-p.x() + movingObj_start.x() ); insilmaril@0: movingVec.setY(-p.y() + movingObj_start.y() ); insilmaril@408: horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() )); insilmaril@408: verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@408: void MapEditor::mouseReleaseEvent(QMouseEvent* e) insilmaril@0: { insilmaril@408: QPointF p = mapToScene(e->pos()); insilmaril@0: LinkableMapObj *dst; insilmaril@424: LinkableMapObj *lmosel=xelection.single(); insilmaril@0: // Have we been picking color? insilmaril@0: if (pickingColor) insilmaril@0: { insilmaril@0: pickingColor=false; insilmaril@366: setCursor (Qt::ArrowCursor); insilmaril@0: // Check if we are over another branch insilmaril@645: dst=model->findMapObj(p, NULL); insilmaril@424: if (dst && lmosel) insilmaril@0: { insilmaril@366: if (e->state() & Qt::ShiftModifier) insilmaril@638: colorBranch (((BranchObj*)dst)->getColor()); insilmaril@0: else insilmaril@638: colorSubtree (((BranchObj*)dst)->getColor()); insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@83: insilmaril@83: // Have we been drawing a link? insilmaril@491: if (drawingLink) insilmaril@83: { insilmaril@83: drawingLink=false; insilmaril@83: // Check if we are over another branch insilmaril@645: dst=model->findMapObj(p, NULL); insilmaril@424: if (dst && lmosel) insilmaril@83: { insilmaril@95: tmpXLink->setEnd ( ((BranchObj*)(dst)) ); insilmaril@95: tmpXLink->updateXLink(); insilmaril@491: tmpXLink->activate(); //FIXME savestate missing insilmaril@473: //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); insilmaril@83: } else insilmaril@83: { insilmaril@95: delete(tmpXLink); insilmaril@95: tmpXLink=NULL; insilmaril@83: } insilmaril@83: return; insilmaril@83: } insilmaril@83: insilmaril@0: // Have we been moving something? insilmaril@424: if ( lmosel && movingObj ) insilmaril@0: { insilmaril@424: FloatImageObj *fo=xelection.getFloatImage(); insilmaril@424: if(fo) insilmaril@175: { insilmaril@388: // Moved FloatObj. Maybe we need to reposition insilmaril@408: QString pold=qpointfToString(movingObj_orgRelPos); insilmaril@408: QString pnow=qpointfToString(fo->getRelPos()); insilmaril@395: saveState( insilmaril@424: fo, insilmaril@366: "moveRel "+pold, insilmaril@424: fo, insilmaril@366: "moveRel "+pnow, insilmaril@625: QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow)); insilmaril@424: insilmaril@424: fo->getParObj()->requestReposition(); insilmaril@645: model->reposition(); insilmaril@175: } insilmaril@175: insilmaril@0: // Check if we are over another branch, but ignore insilmaril@0: // any found LMOs, which are FloatObjs insilmaril@645: dst=model->findMapObj(mapToScene(e->pos() ), lmosel); insilmaril@0: insilmaril@336: if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) insilmaril@0: dst=NULL; insilmaril@0: insilmaril@645: BranchObj *bo=xelection.getBranch(); insilmaril@645: if (bo && bo->getDepth()==0) insilmaril@497: { insilmaril@645: if (movingObj_orgPos != bo->getAbsPos()) insilmaril@625: { insilmaril@625: QString pold=qpointfToString(movingObj_orgPos); insilmaril@645: QString pnow=qpointfToString(bo->getAbsPos()); insilmaril@625: saveState( insilmaril@625: fo, insilmaril@625: "move "+pold, insilmaril@625: fo, insilmaril@625: "move "+pnow, insilmaril@645: QString("Move mapcenter %1 to position %2").arg(getName(bo)).arg(pnow)); insilmaril@625: } insilmaril@388: } insilmaril@645: insilmaril@491: if (xelection.type() == Selection::Branch ) insilmaril@388: { // A branch was moved insilmaril@388: insilmaril@0: // save the position in case we link to mapcenter insilmaril@424: QPointF savePos=QPointF (lmosel->getAbsPos() ); insilmaril@0: insilmaril@0: // Reset the temporary drawn link to the original one insilmaril@424: lmosel->unsetParObjTmp(); insilmaril@0: insilmaril@366: // For Redo we may need to save original selection insilmaril@424: QString preSelStr=lmosel->getSelectString(); insilmaril@93: insilmaril@94: copyingObj=false; insilmaril@129: if (dst ) insilmaril@93: { insilmaril@424: BranchObj* bsel=xelection.getBranch(); insilmaril@366: BranchObj* bdst=(BranchObj*)dst; insilmaril@366: insilmaril@366: QString preParStr=(bsel->getParObj())->getSelectString(); insilmaril@366: QString preNum=QString::number (bsel->getNum(),10); insilmaril@366: QString preDstParStr; insilmaril@366: insilmaril@366: if (e->state() & Qt::ShiftModifier && dst->getParObj()) insilmaril@366: { // Link above dst insilmaril@366: preDstParStr=dst->getParObj()->getSelectString(); insilmaril@421: bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()); insilmaril@366: } else insilmaril@366: if (e->state() & Qt::ControlModifier && dst->getParObj()) insilmaril@366: { insilmaril@366: // Link below dst insilmaril@366: preDstParStr=dst->getParObj()->getSelectString(); insilmaril@421: bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1); insilmaril@366: } else insilmaril@366: { // Append to dst insilmaril@366: preDstParStr=dst->getSelectString(); insilmaril@421: bsel->linkTo (bdst,-1); insilmaril@366: if (dst->getDepth()==0) bsel->move (savePos); insilmaril@366: } insilmaril@424: QString postSelStr=lmosel->getSelectString(); insilmaril@366: QString postNum=QString::number (bsel->getNum(),10); insilmaril@366: insilmaril@421: QString undoCom="linkTo (\""+ insilmaril@366: preParStr+ "\"," + preNum +"," + insilmaril@366: QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; insilmaril@366: insilmaril@421: QString redoCom="linkTo (\""+ insilmaril@366: preDstParStr + "\"," + postNum + "," + insilmaril@366: QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; insilmaril@366: insilmaril@366: saveState ( insilmaril@366: postSelStr,undoCom, insilmaril@366: preSelStr, redoCom, insilmaril@366: QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) ); insilmaril@163: } else insilmaril@424: if (lmosel->getDepth()==1) insilmaril@366: { insilmaril@366: // The select string might be different _after_ moving around. insilmaril@366: // Therefor reposition and then use string of old selection, too insilmaril@645: model->reposition(); insilmaril@366: insilmaril@625: QPointF rp(lmosel->getRelPos()); insilmaril@625: if (rp != movingObj_orgRelPos) insilmaril@625: { insilmaril@625: QString ps=qpointfToString(rp); insilmaril@625: saveState( insilmaril@625: lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), insilmaril@625: preSelStr, "moveRel "+ps, insilmaril@625: QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps)); insilmaril@625: } insilmaril@366: } insilmaril@0: // Draw the original link, before selection was moved around insilmaril@645: model->reposition(); insilmaril@0: } insilmaril@442: xelection.update(); insilmaril@408: // Finally resize scene, if needed insilmaril@408: scene()->update(); insilmaril@0: movingObj=NULL; insilmaril@366: insilmaril@366: // Just make sure, that actions are still ok,e.g. the move branch up/down buttons... insilmaril@366: updateActions(); insilmaril@0: } else insilmaril@83: // maybe we moved View: set old cursor insilmaril@366: setCursor (Qt::ArrowCursor); insilmaril@83: insilmaril@0: } insilmaril@0: insilmaril@408: void MapEditor::mouseDoubleClickEvent(QMouseEvent* e) insilmaril@0: { insilmaril@491: if (isSelectBlocked() ) insilmaril@491: { insilmaril@491: e->ignore(); insilmaril@491: return; insilmaril@491: } insilmaril@491: insilmaril@366: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@408: QPointF p = mapToScene(e->pos()); insilmaril@645: LinkableMapObj *lmo=model->findMapObj(p, NULL); insilmaril@0: if (lmo) { // MapObj was found insilmaril@0: // First select the MapObj than edit heading insilmaril@424: xelection.select(lmo); insilmaril@366: mainWindow->editHeading(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::resizeEvent (QResizeEvent* e) insilmaril@0: { insilmaril@408: QGraphicsView::resizeEvent( e ); insilmaril@0: } insilmaril@0: insilmaril@412: void MapEditor::dragEnterEvent(QDragEnterEvent *event) insilmaril@119: { insilmaril@417: //for (unsigned int i=0;event->format(i);i++) // Debug mime type insilmaril@417: // cerr << event->format(i) << endl; insilmaril@417: insilmaril@417: if (event->mimeData()->hasImage()) insilmaril@417: event->acceptProposedAction(); insilmaril@417: else insilmaril@417: if (event->mimeData()->hasUrls()) insilmaril@417: event->acceptProposedAction(); insilmaril@417: } insilmaril@417: insilmaril@531: void MapEditor::dragMoveEvent(QDragMoveEvent *) insilmaril@417: { insilmaril@417: } insilmaril@417: insilmaril@417: void MapEditor::dragLeaveEvent(QDragLeaveEvent *event) insilmaril@417: { insilmaril@417: event->accept(); insilmaril@119: } insilmaril@129: insilmaril@412: void MapEditor::dropEvent(QDropEvent *event) insilmaril@129: { insilmaril@424: BranchObj *sel=xelection.getBranch(); insilmaril@424: if (sel) insilmaril@128: { insilmaril@505: if (debug) insilmaril@505: foreach (QString format,event->mimeData()->formats()) insilmaril@505: cout << "MapEditor: Dropped format: "< uris; insilmaril@417: if (event->mimeData()->hasImage()) insilmaril@128: { insilmaril@417: QVariant imageData = event->mimeData()->imageData(); insilmaril@417: addFloatImageInt (qvariant_cast(imageData)); insilmaril@417: } else insilmaril@417: if (event->mimeData()->hasUrls()) insilmaril@417: uris=event->mimeData()->urls(); insilmaril@417: insilmaril@417: if (uris.count()>0) insilmaril@128: { insilmaril@417: QStringList files; insilmaril@417: QString s; insilmaril@417: QString heading; insilmaril@417: BranchObj *bo; insilmaril@428: for (int i=0; iaddBranch(); insilmaril@428: if (bo) insilmaril@417: { insilmaril@428: s=uris.at(i).toLocalFile(); insilmaril@428: if (!s.isEmpty()) insilmaril@428: { insilmaril@625: QString file = QDir::fromNativeSeparators(s); insilmaril@428: heading = QFileInfo(file).baseName(); insilmaril@428: files.append(file); insilmaril@428: if (file.endsWith(".vym", false)) insilmaril@428: bo->setVymLink(file); insilmaril@428: else insilmaril@428: bo->setURL(uris.at(i).toString()); insilmaril@428: } else insilmaril@428: { insilmaril@428: bo->setURL(uris.at(i).toString()); insilmaril@428: } insilmaril@428: insilmaril@428: if (!heading.isEmpty()) insilmaril@428: bo->setHeading(heading); insilmaril@428: else insilmaril@428: bo->setHeading(uris.at(i).toString()); insilmaril@428: } insilmaril@417: } insilmaril@417: } insilmaril@645: model->reposition(); insilmaril@417: } insilmaril@417: } insilmaril@417: event->acceptProposedAction(); insilmaril@417: } insilmaril@417: insilmaril@491: void MapEditor::timerEvent(QTimerEvent *event) //TODO animation insilmaril@473: { insilmaril@473: Q_UNUSED(event); insilmaril@473: insilmaril@473: cout << "ME::timerEvent\n"; insilmaril@473: insilmaril@473: for (int i=0; ianimate(); insilmaril@473: ((BranchObj*)animObjList.at(i))->move2RelPos (((BranchObj*)animObjList.at(i))->getRelPos() ); insilmaril@473: } insilmaril@645: model->reposition(); insilmaril@473: } insilmaril@473: insilmaril@528: insilmaril@528: void MapEditor::sendSelection() insilmaril@473: { insilmaril@531: if (netstate!=Server) return; insilmaril@531: sendData (QString("select (\"%1\")").arg(xelection.getSelectString()) ); insilmaril@528: } insilmaril@528: insilmaril@528: void MapEditor::newServer() insilmaril@528: { insilmaril@531: port=54321; insilmaril@531: sendCounter=0; insilmaril@528: tcpServer = new QTcpServer(this); insilmaril@531: if (!tcpServer->listen(QHostAddress::Any,port)) { insilmaril@528: QMessageBox::critical(this, "vym server", insilmaril@528: QString("Unable to start the server: %1.").arg(tcpServer->errorString())); insilmaril@528: close(); insilmaril@528: return; insilmaril@528: } insilmaril@528: connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newClient())); insilmaril@531: netstate=Server; insilmaril@534: cout<<"Server is running on port "<serverPort()<abort(); insilmaril@531: clientSocket->connectToHost(server ,port); insilmaril@531: connect(clientSocket, SIGNAL(readyRead()), this, SLOT(readData())); insilmaril@531: connect(clientSocket, SIGNAL(error(QAbstractSocket::SocketError)), insilmaril@531: this, SLOT(displayNetworkError(QAbstractSocket::SocketError))); insilmaril@531: netstate=Client; insilmaril@531: cout<<"connected to "<nextPendingConnection(); insilmaril@527: connect(newClient, SIGNAL(disconnected()), insilmaril@527: newClient, SLOT(deleteLater())); insilmaril@527: insilmaril@527: cout <<"ME::newClient at "<peerAddress().toString().ascii()<seek(0); insilmaril@531: quint16 bs=(quint16)(block.size() - 2*sizeof(quint16)); insilmaril@531: out << bs; insilmaril@531: insilmaril@537: if (debug) insilmaril@537: cout << "ME::sendData bs="<peerAddress().toString().ascii()<write (block); insilmaril@528: } insilmaril@528: } insilmaril@531: insilmaril@531: void MapEditor::readData () insilmaril@531: { insilmaril@531: while (clientSocket->bytesAvailable() >=(int)sizeof(quint16) ) insilmaril@531: { insilmaril@537: if (debug) insilmaril@537: cout <<"readData bytesAvail="<bytesAvailable(); insilmaril@534: quint16 recCounter; insilmaril@534: quint16 blockSize; insilmaril@534: insilmaril@534: QDataStream in(clientSocket); insilmaril@534: in.setVersion(QDataStream::Qt_4_0); insilmaril@534: insilmaril@534: in >> blockSize; insilmaril@534: in >> recCounter; insilmaril@534: insilmaril@534: QString t; insilmaril@534: in >>t; insilmaril@537: if (debug) insilmaril@537: cout << " t="<errorString())); insilmaril@531: } insilmaril@531: } insilmaril@531: insilmaril@528: void MapEditor::autosave() insilmaril@528: { insilmaril@528: // Disable autosave, while we have gone back in history insilmaril@528: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@528: if (redosAvail>0) return; insilmaril@528: insilmaril@528: insilmaril@528: if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() ) insilmaril@528: mainWindow->fileSave (this); insilmaril@528: } insilmaril@528: insilmaril@528: insilmaril@491: /*TODO not needed? void MapEditor::contentsDropEvent(QDropEvent *event) insilmaril@417: { insilmaril@408: insilmaril@408: } else if (event->provides("application/x-moz-file-promise-url") && insilmaril@408: event->provides("application/x-moz-nativeimage")) insilmaril@408: { insilmaril@129: // Contains url to the img src in unicode16 insilmaril@128: QByteArray d = event->encodedData("application/x-moz-file-promise-url"); insilmaril@128: QString url = QString((const QChar*)d.data(),d.size()/2); insilmaril@408: fetchImage(url); insilmaril@408: event->accept(); insilmaril@128: update=true; insilmaril@408: } else if (event->provides ("text/uri-list")) insilmaril@408: { // Uris provided e.g. by konqueror insilmaril@408: Q3UriDrag::decode (event,uris); insilmaril@408: } else if (event->provides ("_NETSCAPE_URL")) insilmaril@128: { // Uris provided by Mozilla insilmaril@129: QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); insilmaril@129: uris.append(l[0]); insilmaril@129: heading = l[1]; insilmaril@129: } else if (event->provides("text/html")) { insilmaril@129: insilmaril@129: // Handels text mime types insilmaril@129: // Look like firefox allways handle text as unicode16 (2 bytes per char.) insilmaril@129: QByteArray d = event->encodedData("text/html"); insilmaril@129: QString text; insilmaril@129: if (isUnicode16(d)) insilmaril@129: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@129: else insilmaril@129: text = QString(d); insilmaril@129: insilmaril@129: textEditor->setText(text); insilmaril@129: insilmaril@129: event->accept(); insilmaril@129: update=true; insilmaril@129: } else if (event->provides("text/plain")) { insilmaril@129: QByteArray d = event->encodedData("text/plain"); insilmaril@129: QString text; insilmaril@129: if (isUnicode16(d)) insilmaril@129: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@129: else insilmaril@129: text = QString(d); insilmaril@129: insilmaril@129: textEditor->setText(text); insilmaril@129: insilmaril@129: event->accept(); insilmaril@129: update= true; insilmaril@128: } insilmaril@417: insilmaril@406: */ insilmaril@406: insilmaril@417: insilmaril@412: insilmaril@412: bool isUnicode16(const QByteArray &d) insilmaril@412: { insilmaril@412: // TODO: make more precise check for unicode 16. insilmaril@412: // Guess unicode16 if any of second bytes are zero insilmaril@412: unsigned int length = max(0,d.size()-2)/2; insilmaril@412: for (unsigned int i = 0; iaddFloatImage(); insilmaril@395: fio->load(img); insilmaril@505: fio->setOriginalFilename("No original filename (image added by dropevent)"); insilmaril@505: QString s=bo->getSelectString(); insilmaril@505: saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio ); insilmaril@505: saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image"); insilmaril@645: model->reposition(); insilmaril@408: scene()->update(); insilmaril@119: } insilmaril@119: } insilmaril@119: insilmaril@412: /* insilmaril@412: insilmaril@412: void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation * / *nop* /) insilmaril@119: { insilmaril@119: if (!imageBuffer) imageBuffer = new QBuffer(); insilmaril@119: if (!imageBuffer->isOpen()) { insilmaril@366: imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append); insilmaril@119: } insilmaril@119: imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a)); insilmaril@119: } insilmaril@119: insilmaril@119: insilmaril@366: void MapEditor::imageDataFinished(Q3NetworkOperation *nop) insilmaril@119: { insilmaril@366: if (nop->state()==Q3NetworkProtocol::StDone) { insilmaril@129: QPixmap img(imageBuffer->buffer()); insilmaril@395: addFloatImageInt (img); insilmaril@129: } insilmaril@129: insilmaril@129: if (imageBuffer) { insilmaril@129: imageBuffer->close(); insilmaril@129: if (imageBuffer) { insilmaril@129: imageBuffer->close(); insilmaril@129: delete imageBuffer; insilmaril@129: imageBuffer = 0; insilmaril@129: } insilmaril@129: } insilmaril@119: } insilmaril@119: insilmaril@129: void MapEditor::fetchImage(const QString &url) insilmaril@119: { insilmaril@119: if (urlOperator) { insilmaril@119: urlOperator->stop(); insilmaril@119: disconnect(urlOperator); insilmaril@119: delete urlOperator; insilmaril@119: } insilmaril@119: insilmaril@366: urlOperator = new Q3UrlOperator(url); insilmaril@366: connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), insilmaril@366: this, SLOT(imageDataFinished(Q3NetworkOperation*))); insilmaril@366: insilmaril@366: connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)), insilmaril@366: this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *))); insilmaril@119: urlOperator->get(); insilmaril@119: } insilmaril@412: */ insilmaril@412: