insilmaril@0: #include "mapeditor.h" insilmaril@0: insilmaril@374: #include insilmaril@0: insilmaril@0: #include insilmaril@95: #include insilmaril@0: #include insilmaril@0: insilmaril@0: #include "version.h" insilmaril@0: insilmaril@432: #include "parser.h" insilmaril@175: #include "editxlinkdialog.h" insilmaril@175: #include "exports.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@0: #include "xml.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@166: extern bool clipboardEmpty; 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@421: QGraphicsView(parent) insilmaril@0: { insilmaril@0: //cout << "Constructor ME "<setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern)); insilmaril@408: insilmaril@408: insilmaril@408: setScene (mapScene); insilmaril@0: insilmaril@408: mapCenter = new MapCenterObj(mapScene); insilmaril@0: mapCenter->setVisibility (true); insilmaril@0: mapCenter->setMapEditor (this); insilmaril@93: mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map")); insilmaril@408: //mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2); insilmaril@408: mapCenter->move(0,0); insilmaril@0: insilmaril@0: printer=NULL; insilmaril@0: insilmaril@97: defLinkColor=QColor (0,0,255); insilmaril@97: defXLinkColor=QColor (180,180,180); insilmaril@0: linkcolorhint=DefaultColor; insilmaril@0: linkstyle=StylePolyParabel; 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@442: xelection.setMapEditor (this); 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@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@260: hidemode=HideNone; insilmaril@260: insilmaril@377: // Create temporary files insilmaril@377: makeTmpDirs(); insilmaril@0: insilmaril@417: setAcceptDrops (true); insilmaril@0: insilmaril@0: mapCenter->reposition(); // for positioning heading insilmaril@381: insilmaril@0: } insilmaril@0: insilmaril@0: MapEditor::~MapEditor() insilmaril@0: { insilmaril@0: //cout <<"Destructor MapEditor\n"; insilmaril@0: } insilmaril@0: insilmaril@0: MapCenterObj* MapEditor::getMapCenter() insilmaril@0: { insilmaril@0: return mapCenter; insilmaril@0: } insilmaril@0: insilmaril@408: QGraphicsScene * MapEditor::getScene() insilmaril@0: { insilmaril@408: return mapScene; insilmaril@0: } insilmaril@0: insilmaril@139: bool MapEditor::isRepositionBlocked() insilmaril@0: { insilmaril@139: return blockReposition; insilmaril@0: } insilmaril@0: 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@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@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@366: tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum)); insilmaril@366: histPath=QDir::convertSeparators (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@0: case StyleLine: insilmaril@0: ls="StyleLine"; insilmaril@0: break; insilmaril@0: case StyleParabel: insilmaril@0: ls="StyleParabel"; insilmaril@0: break; insilmaril@0: case StylePolyLine: 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@0: if (linkcolorhint==HeadingColor) insilmaril@0: colhint=attribut("linkColorHint","HeadingColor"); insilmaril@0: insilmaril@404: QString mapAttr=attribut("version",vymVersion); insilmaril@398: if (!saveSel || saveSel==mapCenter) insilmaril@0: mapAttr+= attribut("author",mapCenter->getAuthor()) + insilmaril@0: attribut("comment",mapCenter->getComment()) + insilmaril@0: attribut("date",mapCenter->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@0: s+=mapCenter->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@0: s+=settings.getXMLData (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@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@366: insilmaril@366: void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) insilmaril@163: { insilmaril@163: // Main saveState insilmaril@163: insilmaril@139: if (blockSaveState) return; insilmaril@139: insilmaril@163: /* TODO remove after testing insilmaril@163: */ insilmaril@388: cout << "ME::saveState() "<stepsTotal) curStep=1; insilmaril@163: insilmaril@398: QString backupXML=""; insilmaril@388: QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep)); insilmaril@388: QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName); insilmaril@164: QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml"); insilmaril@164: insilmaril@164: // Create bakMapDir if not available insilmaril@164: QDir d(bakMapDir); insilmaril@164: if (!d.exists()) insilmaril@164: makeSubDirs (bakMapDir); insilmaril@163: insilmaril@366: // Save depending on how much needs to be saved insilmaril@398: if (saveSel) insilmaril@408: backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel); insilmaril@136: insilmaril@163: QString undoCommand=""; insilmaril@106: if (savemode==UndoCommand) insilmaril@0: { insilmaril@105: undoCommand=undoCom; insilmaril@106: } insilmaril@366: else if (savemode==PartOfMap ) insilmaril@0: { insilmaril@393: undoCommand=undoCom; insilmaril@393: undoCommand.replace ("PATH",bakMapPath); insilmaril@106: } insilmaril@398: insilmaril@163: if (!backupXML.isEmpty()) insilmaril@163: // Write XML Data to disk insilmaril@163: saveStringToDisk (QString(bakMapPath),backupXML); insilmaril@163: insilmaril@388: // We would have to save all actions in a tree, to keep track of insilmaril@393: // possible redos after a action. Possible, but we are too lazy: forget about redos. insilmaril@388: redosAvail=0; insilmaril@388: insilmaril@388: // Write the current state to disk insilmaril@366: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@388: undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); insilmaril@366: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@366: undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand); insilmaril@366: undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection); insilmaril@366: undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom); insilmaril@366: undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection); insilmaril@366: undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment); insilmaril@404: undoSet.setEntry (QString("/history/version"),vymVersion); insilmaril@366: undoSet.writeSettings(histPath); insilmaril@163: insilmaril@163: /* TODO remove after testing insilmaril@366: */ insilmaril@366: //cout << " into="<< histPath.toStdString()<updateHistory (undoSet); insilmaril@407: setChanged(); insilmaril@395: updateActions(); insilmaril@106: } insilmaril@106: insilmaril@129: void MapEditor::parseAtom(const QString &atom) insilmaril@106: { insilmaril@424: BranchObj *selb=xelection.getBranch(); insilmaril@163: QString s,t; insilmaril@129: int x,y; 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@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@432: if (parser.checkParamCount(pl)) insilmaril@394: { insilmaril@432: if (parser.paramCount()==0) insilmaril@394: addNewBranchInt (-2); insilmaril@394: else insilmaril@394: { insilmaril@432: y=parser.parInt (ok,0); insilmaril@394: if (ok ) addNewBranchInt (y); insilmaril@394: } insilmaril@394: } insilmaril@394: } 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@432: if (parser.paramCount()==0) insilmaril@394: { insilmaril@394: addNewBranchBefore (); insilmaril@394: } insilmaril@394: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@393: { insilmaril@432: //s=parser.parString (ok,0); // selection insilmaril@432: t=parser.parString (ok,0); // path to map insilmaril@393: if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); insilmaril@424: addMapReplaceInt(selb->getSelectString(),t); insilmaril@393: } 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@432: if (parser.checkParamCount(2)) insilmaril@394: { insilmaril@432: t=parser.parString (ok,0); // path to map insilmaril@432: y=parser.parInt(ok,1); // position insilmaril@394: if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); insilmaril@394: addMapInsertInt(t,y); insilmaril@394: } insilmaril@393: } 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@447: } else if (parser.checkParamCount(0)) insilmaril@447: { insilmaril@447: selb->clearStandardFlags(); insilmaril@447: selb->updateFlagsToolbar(); insilmaril@447: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@395: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@395: if (ok) colorBranch (c); insilmaril@395: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@417: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@417: if (ok) colorSubtree (c); insilmaril@417: } insilmaril@395: } else if (com=="cut") insilmaril@395: { insilmaril@424: if (xelection.isEmpty()) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if ( xelection.type()!=Branch && insilmaril@424: xelection.type()!=MapCenter && insilmaril@424: xelection.type()!=FloatImage ) insilmaril@395: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@432: } else if (parser.checkParamCount(0)) insilmaril@395: { insilmaril@395: cut(); insilmaril@395: } insilmaril@393: } else if (com=="delete") insilmaril@393: { insilmaril@424: if (xelection.isEmpty()) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@434: } else if (xelection.type() != Branch && xelection.type() != FloatImage ) insilmaril@424: { insilmaril@434: parser.setError (Aborted,"Type of selection is wrong."); insilmaril@432: } else if (parser.checkParamCount(0)) insilmaril@393: { insilmaril@393: deleteSelection(); insilmaril@393: } 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@432: } else if (parser.checkParamCount(0)) insilmaril@394: { insilmaril@395: deleteKeepChilds(); insilmaril@395: } 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@432: } else if (parser.checkParamCount(0)) insilmaril@395: { insilmaril@395: deleteChilds(); insilmaril@394: } 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@432: if (parser.checkParamCount(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@421: LinkableMapObj *dst=mapCenter->findObjBySelect (s); insilmaril@421: if (dst) insilmaril@421: { insilmaril@421: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@421: { insilmaril@421: // Get number in parent insilmaril@432: x=parser.parInt (ok,1); insilmaril@421: if (ok) insilmaril@424: selb->linkTo ((BranchObj*)(dst),x); insilmaril@421: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@421: { insilmaril@424: selb->linkTo ((BranchObj*)(dst),-1); insilmaril@421: // Get coordinates of mainbranch insilmaril@432: x=parser.parInt (ok,2); insilmaril@421: if (ok) insilmaril@421: { insilmaril@432: y=parser.parInt (ok,3); insilmaril@424: if (ok) selb->move (x,y); insilmaril@421: } insilmaril@421: } insilmaril@421: } insilmaril@421: } insilmaril@424: } else if ( xelection.type() == FloatImage) insilmaril@421: { insilmaril@432: if (parser.checkParamCount(1)) insilmaril@421: { insilmaril@421: // 0 selectstring of parent insilmaril@432: s=parser.parString(ok,0); insilmaril@421: LinkableMapObj *dst=mapCenter->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@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@432: } else if (parser.checkParamCount(1)) insilmaril@432: { insilmaril@432: s=parser.parString(ok,0); insilmaril@432: if (ok) loadFloatImageInt (s); insilmaril@432: } 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@432: } else if (parser.checkParamCount(0)) insilmaril@394: { insilmaril@394: moveBranchUp(); insilmaril@394: } 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@432: } else if (parser.checkParamCount(0)) insilmaril@394: { insilmaril@394: moveBranchDown(); insilmaril@394: } insilmaril@394: } else if (com=="move") insilmaril@394: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if ( xelection.type()!=Branch && insilmaril@424: xelection.type()!=MapCenter && insilmaril@424: xelection.type()!=FloatImage ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@432: } else if (parser.checkParamCount(2)) insilmaril@393: { insilmaril@432: x=parser.parInt (ok,0); insilmaril@393: if (ok) insilmaril@393: { insilmaril@432: y=parser.parInt (ok,1); insilmaril@393: if (ok) move (x,y); insilmaril@393: } insilmaril@393: } insilmaril@395: } else if (com=="moveRel") insilmaril@393: { insilmaril@424: if (xelection.isEmpty() ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Nothing selected"); insilmaril@424: } else if ( xelection.type()!=Branch && insilmaril@424: xelection.type()!=MapCenter && insilmaril@424: xelection.type()!=FloatImage ) insilmaril@394: { insilmaril@432: parser.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@432: } else if (parser.checkParamCount(2)) insilmaril@393: { insilmaril@432: x=parser.parInt (ok,0); insilmaril@393: if (ok) insilmaril@393: { insilmaril@432: y=parser.parInt (ok,1); insilmaril@393: if (ok) moveRel (x,y); insilmaril@393: } insilmaril@393: } 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@432: } else if (parser.checkParamCount(0)) insilmaril@395: { insilmaril@395: paste(); insilmaril@395: } 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@434: } else if (parser.checkParamCount(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@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@432: } else if (parser.checkParamCount(0)) insilmaril@427: { insilmaril@427: if (!scrollBranch ()) insilmaril@432: parser.setError (Aborted,"Could not scroll branch"); insilmaril@427: } insilmaril@398: } else if (com=="select") insilmaril@398: { insilmaril@432: if (parser.checkParamCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString(ok,0); insilmaril@398: if (ok) select (s); insilmaril@398: } 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@432: } else if (parser.checkParamCount(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@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@434: } else if (parser.checkParamCount(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@398: } else if (com=="setMapAuthor") insilmaril@398: { insilmaril@432: if (parser.checkParamCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString(ok,0); insilmaril@398: if (ok) setMapAuthor (s); insilmaril@398: } insilmaril@398: } else if (com=="setMapComment") insilmaril@398: { insilmaril@432: if (parser.checkParamCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString(ok,0); insilmaril@398: if (ok) setMapComment(s); insilmaril@398: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@398: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@398: if (ok) setMapBackgroundColor (c); insilmaril@398: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@398: { insilmaril@432: QColor c=parser.parColor (ok,0); insilmaril@398: if (ok) setMapDefLinkColor (c); insilmaril@398: } insilmaril@398: } else if (com=="setMapLinkStyle") insilmaril@398: { insilmaril@432: if (parser.checkParamCount(1)) insilmaril@398: { insilmaril@432: s=parser.parString (ok,0); insilmaril@398: if (ok) setMapLinkStyle(s); insilmaril@398: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@129: { insilmaril@432: s=parser.parString (ok,0); insilmaril@366: if (ok) insilmaril@366: setHeading (s); insilmaril@129: } insilmaril@395: } else if (com=="setHideExport") 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 or floatimage"); insilmaril@434: //FIXME selb is never a floatimage!! insilmaril@432: } else if (parser.checkParamCount(1)) insilmaril@395: { insilmaril@432: b=parser.parBool(ok,0); insilmaril@395: if (ok) setHideExport (b); insilmaril@395: } insilmaril@434: } else if (com=="setIncludeImagesHorizontally") 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@434: } else if (parser.checkParamCount(1)) insilmaril@434: { insilmaril@434: b=parser.parBool(ok,0); insilmaril@434: if (ok) setIncludeImagesHor(b); insilmaril@434: } 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@434: } else if (parser.checkParamCount(1)) insilmaril@434: { insilmaril@434: b=parser.parBool(ok,0); insilmaril@434: if (ok) setIncludeImagesVer(b); insilmaril@434: } insilmaril@442: } else if (com=="setSelectionColor") insilmaril@442: { insilmaril@442: if (parser.checkParamCount(1)) insilmaril@442: { insilmaril@442: QColor c=parser.parColor (ok,0); insilmaril@442: if (ok) setSelectionColorInt (c); insilmaril@442: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@143: { insilmaril@432: s=parser.parString (ok,0); insilmaril@366: if (ok) setURLInt(s); insilmaril@143: } 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@432: } else if (parser.checkParamCount(1)) insilmaril@143: { insilmaril@432: s=parser.parString (ok,0); insilmaril@366: if (ok) setVymLinkInt(s); insilmaril@143: } insilmaril@143: } 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@432: } else if (parser.checkParamCount(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@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@445: } else if (parser.checkParamCount(1)) insilmaril@445: { insilmaril@445: s=parser.parString(ok,0); insilmaril@445: if (ok) insilmaril@445: setFrameType (s); insilmaril@445: } 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@447: } else if (parser.checkParamCount(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@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@432: } else if (parser.checkParamCount(0)) insilmaril@427: { insilmaril@427: if (!unscrollBranch ()) insilmaril@432: parser.setError (Aborted,"Could not unscroll branch"); insilmaril@427: } 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@432: } else if (parser.checkParamCount(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@394: setChanged(); insilmaril@432: mapCenter->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::isUnsaved() insilmaril@0: { insilmaril@0: return mapUnsaved; 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@0: mapChanged=true; insilmaril@0: mapDefault=false; insilmaril@0: mapUnsaved=true; insilmaril@0: findReset(); 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@0: void MapEditor::setFilePath(QString fname) insilmaril@0: { insilmaril@0: setFilePath (fname,fname); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setFilePath(QString fname, QString destname) insilmaril@0: { insilmaril@205: if (fname.isEmpty() || fname=="") insilmaril@106: { insilmaril@106: filePath=""; insilmaril@106: fileName=""; insilmaril@106: destPath=""; insilmaril@106: } else insilmaril@106: { insilmaril@106: filePath=fname; // becomes absolute path insilmaril@106: fileName=fname; // gets stripped of path insilmaril@106: destPath=destname; // needed for vymlinks insilmaril@106: insilmaril@106: // If fname is not an absolute path, complete it insilmaril@106: filePath=QDir(fname).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@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@205: ErrorCode MapEditor::load (QString fname, LoadMode lmode) insilmaril@0: { insilmaril@205: ErrorCode err=success; insilmaril@0: insilmaril@0: if (lmode==NewMap) insilmaril@0: { insilmaril@424: if (xelection.isEmpty() ) xelection.unselect(); insilmaril@424: xelection.clear(); insilmaril@0: mapCenter->clear(); insilmaril@0: mapCenter->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: insilmaril@0: mapBuilderHandler handler; 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@139: blockReposition=true; insilmaril@0: QXmlInputSource source( file); insilmaril@0: QXmlSimpleReader reader; insilmaril@0: reader.setContentHandler( &handler ); insilmaril@0: reader.setErrorHandler( &handler ); insilmaril@0: handler.setMapEditor( this ); insilmaril@0: handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path insilmaril@243: handler.setInputFile (file.name()); insilmaril@0: handler.setLoadMode (lmode); insilmaril@163: blockSaveState=true; insilmaril@0: bool ok = reader.parse( source ); insilmaril@139: blockReposition=false; insilmaril@163: blockSaveState=false; insilmaril@0: file.close(); insilmaril@0: if ( ok ) insilmaril@0: { insilmaril@0: mapCenter->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@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Parse Error" ), insilmaril@0: 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: int returnCode=0; 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@408: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); insilmaril@106: else insilmaril@424: saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),xelection.getBranch()); //FIXME check selected FIO insilmaril@0: insilmaril@163: if (!saveStringToDisk(fileDir+fname,saveFile)) insilmaril@0: return 1; insilmaril@0: insilmaril@0: if (returnCode==0) insilmaril@0: { insilmaril@0: mapChanged=false; insilmaril@0: mapUnsaved=false; insilmaril@390: updateActions(); insilmaril@0: } insilmaril@0: insilmaril@0: return returnCode; 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@408: QRectF totalBBox=mapCenter->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@408: QRectF mapRect=mapCenter->getTotalBBox(); insilmaril@450: QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2); 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@260: void MapEditor::setHideTmpMode (HideTmpMode mode) insilmaril@260: { insilmaril@260: hidemode=mode; insilmaril@260: mapCenter->setHideTmp (hidemode); insilmaril@260: mapCenter->reposition(); insilmaril@408: scene()->update(); insilmaril@260: } insilmaril@260: insilmaril@260: HideTmpMode MapEditor::getHideTmpMode() insilmaril@260: { insilmaril@260: return hidemode; insilmaril@260: } insilmaril@260: insilmaril@0: void MapEditor::exportImage(QString fn) insilmaril@0: { insilmaril@260: setExportMode (true); insilmaril@0: QPixmap pix (getPixmap()); insilmaril@0: pix.save(fn, "PNG"); insilmaril@260: setExportMode (false); 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@366: if (b && settings.value("/export/useHideExport","yes")=="yes") insilmaril@260: setHideTmpMode (HideExport); insilmaril@260: else insilmaril@260: setHideTmpMode (HideNone); insilmaril@0: } insilmaril@0: insilmaril@366: void MapEditor::exportImage(QString fn, QString format) insilmaril@0: { insilmaril@260: setExportMode (true); insilmaril@0: QPixmap pix (getPixmap()); insilmaril@366: pix.save(fn, 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@185: ex.setMapCenter(mapCenter); 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@163: insilmaril@0: insilmaril@0: void MapEditor::exportXML(const QString &dir) insilmaril@0: { 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@106: QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->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@0: exportImage (dir+"/images/"+mapName+".png"); insilmaril@260: insilmaril@260: setExportMode (false); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::clear() insilmaril@0: { insilmaril@424: xelection.unselect(); insilmaril@0: mapCenter->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@166: // write to directory insilmaril@166: QString clipfile="part"; insilmaril@424: QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),sel ); // FIXME check FIO insilmaril@166: QFile file; insilmaril@166: insilmaril@166: file.setName ( clipboardDir + "/"+clipfile+".xml"); insilmaril@366: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@0: { insilmaril@166: // This should neverever happen insilmaril@166: QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name())); insilmaril@166: return; insilmaril@166: } insilmaril@166: insilmaril@166: // Write it finally, and write in UTF8, no matter what insilmaril@166: QTextStream ts( &file ); insilmaril@166: ts.setEncoding (QTextStream::UnicodeUTF8); insilmaril@166: ts << saveFile; insilmaril@166: file.close(); insilmaril@166: insilmaril@166: clipboardEmpty=false; insilmaril@166: updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@163: void MapEditor::redo() insilmaril@163: { insilmaril@163: blockSaveState=true; insilmaril@163: insilmaril@366: // Restore variables insilmaril@366: int curStep=undoSet.readNumEntry (QString("/history/curStep")); insilmaril@366: int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); insilmaril@366: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@381: // Can we undo at all? insilmaril@381: if (redosAvail<1) return; 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@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@395: insilmaril@366: insilmaril@163: // Find out current undo directory insilmaril@366: QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@366: insilmaril@366: /* TODO remove testing insilmaril@366: */ insilmaril@366: cout << "ME::redo() begin\n"; insilmaril@366: cout << " undosAvail="<reposition(); insilmaril@366: insilmaril@366: blockSaveState=false; 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@163: blockSaveState=true; insilmaril@163: insilmaril@366: // Restore variables insilmaril@366: int curStep=undoSet.readNumEntry (QString("/history/curStep")); insilmaril@366: int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); insilmaril@366: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@381: insilmaril@381: // Can we undo at all? insilmaril@381: if (undosAvail<1) return; insilmaril@381: 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@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@366: insilmaril@163: // Find out current undo directory insilmaril@366: QString bakMapDir=QDir::convertSeparators (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@164: /* TODO testing insilmaril@366: */ insilmaril@163: cout << "ME::undo() begin\n"; insilmaril@163: 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@163: blockSaveState=false; 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@381: 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@424: 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@393: mapBuilderHandler handler; insilmaril@393: QXmlInputSource source( file); insilmaril@393: QXmlSimpleReader reader; insilmaril@393: reader.setContentHandler( &handler ); insilmaril@393: reader.setErrorHandler( &handler ); insilmaril@393: handler.setMapEditor( this ); 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@424: if (sel!=mapCenter) 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@166: void MapEditor::pasteNoSave() insilmaril@0: { insilmaril@166: load (clipboardDir+"/part.xml",ImportAdd); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cutNoSave() insilmaril@0: { insilmaril@166: copy(); insilmaril@166: deleteSelection(); insilmaril@0: } insilmaril@0: insilmaril@424: void MapEditor::paste() // FIXME no pasting of FIO ??? insilmaril@0: { insilmaril@424: BranchObj *sel=xelection.getBranch(); insilmaril@424: if (sel) insilmaril@166: { insilmaril@166: pasteNoSave(); insilmaril@395: saveStateChangingPart( insilmaril@424: sel, insilmaril@424: sel, insilmaril@395: "paste ()", insilmaril@424: QString("Paste to %1").arg( getName(sel)) insilmaril@395: ); insilmaril@166: mapCenter->reposition(); insilmaril@166: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cut() insilmaril@0: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if ( sel && (xelection.type() == Branch || insilmaril@424: xelection.type()==MapCenter || insilmaril@424: xelection.type()==FloatImage)) insilmaril@424: { insilmaril@424: saveStateChangingPart( insilmaril@424: sel->getParObj(), insilmaril@424: sel, insilmaril@424: "cut ()", insilmaril@424: QString("Cut %1").arg(getName(sel )) insilmaril@424: ); insilmaril@424: copy(); insilmaril@424: cutNoSave(); insilmaril@424: mapCenter->reposition(); insilmaril@424: } insilmaril@0: } insilmaril@0: insilmaril@130: void MapEditor::move(const int &x, const int &y) insilmaril@130: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@366: { insilmaril@424: QString ps=qpointfToString (sel->getAbsPos()); insilmaril@424: QString s=xelection.single()->getSelectString(); insilmaril@366: saveState( insilmaril@366: s, "move "+ps, insilmaril@408: s, "move "+qpointfToString (QPointF (x,y)), insilmaril@424: QString("Move %1 to %2").arg(getName(sel)).arg(ps)); insilmaril@424: sel->move(x,y); // FIXME xelection not moved automagically... insilmaril@366: mapCenter->reposition(); insilmaril@442: xelection.update(); insilmaril@366: } insilmaril@366: insilmaril@366: } insilmaril@366: insilmaril@366: void MapEditor::moveRel (const int &x, const int &y) insilmaril@366: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@366: { insilmaril@424: QString ps=qpointfToString (sel->getRelPos()); insilmaril@424: QString s=sel->getSelectString(); insilmaril@366: saveState( insilmaril@366: s, "moveRel "+ps, insilmaril@408: s, "moveRel "+qpointfToString (QPointF (x,y)), insilmaril@424: QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps)); insilmaril@424: ((OrnamentedObj*)sel)->move2RelPos (x,y); insilmaril@366: mapCenter->reposition(); insilmaril@424: sel->updateLink(); insilmaril@442: xelection.update(); 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@424: xelection.unselect(); // FIXME needed? insilmaril@366: bo=par->moveBranchUp (bo); // bo will be the one below selection insilmaril@424: xelection.reselect(); insilmaril@424: //saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); insilmaril@424: saveState (bo,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); insilmaril@0: mapCenter->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@424: xelection.unselect(); // FIXME needed? insilmaril@366: bo=par->moveBranchDown(bo); // bo will be the one above selection insilmaril@424: xelection.reselect(); insilmaril@424: //saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); insilmaril@424: saveState(bo,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); insilmaril@0: mapCenter->reposition(); insilmaril@420: scene()->update(); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@424: void MapEditor::linkTo(const QString &dstString) // FIXME needed? only for FIO ?? insilmaril@420: { insilmaril@424: FloatImageObj *fio=xelection.getFloatImage(); insilmaril@424: if (fio) insilmaril@424: { insilmaril@424: BranchObj *dst=(BranchObj*)(mapCenter->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@106: mapCenter->reposition(); insilmaril@442: xelection.update(); insilmaril@106: ensureSelectionVisible(); insilmaril@106: } insilmaril@106: } insilmaril@106: insilmaril@366: void MapEditor::setURLInt (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->setURL(s); insilmaril@143: mapCenter->reposition(); insilmaril@442: xelection.update(); insilmaril@143: ensureSelectionVisible(); insilmaril@143: } insilmaril@143: } insilmaril@143: 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@366: mapCenter->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@143: mapCenter->reposition(); 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@366: return 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@366: }else if (num==-3) insilmaril@366: { insilmaril@366: num=bo->getNum(); insilmaril@366: bo=(BranchObj*)bo->getParObj(); insilmaril@366: } insilmaril@366: if (!bo) return bo; insilmaril@366: newbo=bo->insertBranch(num); 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@366: QString ("addBranch (%1)").arg(pos-2), insilmaril@395: QString ("Add new branch to %1").arg(getName(bo))); insilmaril@366: insilmaril@366: mapCenter->reposition(); insilmaril@442: xelection.update(); 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@424: if (bo && xelection.type()==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@394: mapCenter->reposition(); insilmaril@442: xelection.update(); insilmaril@394: } insilmaril@0: } insilmaril@394: return newbo; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::deleteSelection() insilmaril@0: { insilmaril@424: BranchObj *bo = xelection.getBranch(); insilmaril@424: if (bo && xelection.type()==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@0: mapCenter->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@442: mapCenter->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@106: LinkableMapObj *lmo=mapCenter->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@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@424: if (lmo && xelection.single()!= lmo) insilmaril@442: { insilmaril@424: xelection.select(lmo); insilmaril@442: xelection.update(); 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@424: if (xelection.single()->getOrientation()==OrientRightOfCenter) 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@424: if (xelection.single()->getOrientation()==OrientRightOfCenter) 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@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo && xelection.type()==Branch) insilmaril@0: { insilmaril@424: if (bo->getOrientation()==OrientRightOfCenter) 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@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo && xelection.type()==Branch) insilmaril@424: if (bo->getOrientation()==OrientRightOfCenter) 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@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@0: { insilmaril@424: if (xelection.type()== 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@0: if (bo->getOrientation()==OrientRightOfCenter) 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@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@424: par=(BranchObj*)(sel->getParObj()); insilmaril@424: if (sel->getOrientation()==OrientRightOfCenter) insilmaril@0: { insilmaril@424: if (xelection.type() == Branch || insilmaril@424: xelection.type() == FloatImage) insilmaril@0: { insilmaril@424: xelection.select(par); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@424: if (xelection.type() == 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@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectRightBranch() insilmaril@0: { insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel) insilmaril@0: { insilmaril@424: if (xelection.type()==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@0: if (bo->getOrientation()==OrientLeftOfCenter) insilmaril@0: bo=par->getFirstBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@424: xelection.select(bo); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@424: par=(BranchObj*)(xelection.single()->getParObj()); insilmaril@424: if (xelection.single()->getOrientation()==OrientLeftOfCenter) insilmaril@0: { insilmaril@424: if (xelection.type() == Branch || insilmaril@424: xelection.type() == FloatImage) insilmaril@0: { insilmaril@424: xelection.select(par); insilmaril@442: xelection.update(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@424: if (xelection.type() == 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@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@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@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@424: mapCenter, insilmaril@445: QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()), insilmaril@424: mapCenter, 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@0: itFind=mapCenter->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@0: itFind=itFind->next(); 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@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@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@143: bo->setVymLink (fd->selectedFile() ); insilmaril@143: updateActions(); insilmaril@143: mapCenter->reposition(); insilmaril@408: scene()->update(); 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@0: mapCenter->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@243: mapCenter->reposition(); 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@98: mapCenter->reposition(); insilmaril@98: select (sel); insilmaril@424: xelection.getBranch()->move2RelPos (p); insilmaril@394: mapCenter->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@424: bo->getParObj(), insilmaril@424: bo, insilmaril@395: "deleteChilds ()", insilmaril@424: QString( "Remove childs of branch %1").arg(getName(bo)) insilmaril@395: ); insilmaril@424: bo->removeChilds(); insilmaril@98: mapCenter->reposition(); insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@0: void MapEditor::editMapInfo() insilmaril@0: { insilmaril@0: ExtraInfoDialog dia; insilmaril@0: dia.setMapName (getFileName() ); insilmaril@0: dia.setAuthor (mapCenter->getAuthor() ); insilmaril@0: dia.setComment(mapCenter->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@0: bo=mapCenter->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@0: bo=bo->next(); 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@424: mapCenter, insilmaril@398: QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()), insilmaril@424: mapCenter, insilmaril@398: QString ("setMapAuthor (\"%1\")").arg(s), insilmaril@398: QString ("Set author of map to \"%1\"").arg(s) insilmaril@398: ); insilmaril@398: mapCenter->setAuthor (s); insilmaril@398: } insilmaril@398: insilmaril@398: void MapEditor::setMapComment (const QString &s) insilmaril@398: { insilmaril@398: saveState ( insilmaril@424: mapCenter, insilmaril@398: QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()), insilmaril@424: mapCenter, insilmaril@398: QString ("setMapComment (\"%1\")").arg(s), insilmaril@398: QString ("Set comment of map") insilmaril@398: ); insilmaril@398: mapCenter->setComment (s); insilmaril@398: } insilmaril@398: insilmaril@398: void MapEditor::setMapLinkStyle (const QString & s) insilmaril@398: { insilmaril@398: saveStateChangingPart ( insilmaril@398: mapCenter, insilmaril@398: mapCenter, insilmaril@398: QString("setMapLinkStyle (\"%1\")").arg(s), insilmaril@398: QString("Set map link style (\"%1\")").arg(s) insilmaril@398: ); insilmaril@398: insilmaril@398: if (s=="StyleLine") insilmaril@398: linkstyle=StyleLine; insilmaril@398: else if (s=="StyleParabel") insilmaril@398: linkstyle=StyleParabel; insilmaril@398: else if (s=="StylePolyLine") insilmaril@398: linkstyle=StylePolyLine; insilmaril@398: else insilmaril@398: linkstyle=StylePolyParabel; insilmaril@398: insilmaril@0: BranchObj *bo; insilmaril@0: bo=mapCenter->first(); insilmaril@0: bo=bo->next(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkStyle(bo->getDefLinkStyle()); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@102: mapCenter->reposition(); insilmaril@0: } insilmaril@0: insilmaril@398: LinkStyle 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@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@0: bo=mapCenter->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::setMapLinkColorHint(LinkColorHint lch) insilmaril@0: { insilmaril@0: linkcolorhint=lch; insilmaril@398: setMapLinkColorHintInt(); insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::toggleMapLinkColorHint() insilmaril@0: { insilmaril@0: if (linkcolorhint==HeadingColor) insilmaril@0: linkcolorhint=DefaultColor; insilmaril@0: else insilmaril@0: linkcolorhint=HeadingColor; insilmaril@0: BranchObj *bo; insilmaril@0: bo=mapCenter->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@398: LinkColorHint 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@424: mapCenter, insilmaril@398: QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()), insilmaril@424: mapCenter, insilmaril@398: QString("setMapDefLinkColor (\"%1\")").arg(col.name()), insilmaril@398: QString("Set 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: mapCenter, insilmaril@442: QString("setSelectionColor (%1)").arg(xelection.getColor().name()), insilmaril@442: mapCenter, 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@427: bool MapEditor::scrollBranch() insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); 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@408: scene()->update(); insilmaril@427: return true; insilmaril@427: } insilmaril@427: return false; insilmaril@427: } insilmaril@427: insilmaril@427: bool MapEditor::unscrollBranch() insilmaril@427: { insilmaril@427: BranchObj *bo=xelection.getBranch(); 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@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@427: if (xelection.type()==Branch ) insilmaril@427: { insilmaril@427: if (bo->isScrolled()) insilmaril@427: unscrollBranch (); insilmaril@427: else insilmaril@427: scrollBranch (); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@428: void MapEditor::unscrollChilds() // FIXME saveState missing 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@428: if (bo->isScrolled()) bo->toggleScroll(); 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@432: mapCenter->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@412: // FIXME 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@432: // FIXME 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@442: void MapEditor::setFrameType(const FrameType &t) // FIXME missing saveState insilmaril@0: { insilmaril@424: BranchObj *bo=xelection.getBranch(); insilmaril@424: if (bo) insilmaril@0: { insilmaril@424: bo->setFrameType (t); insilmaril@0: mapCenter->reposition(); insilmaril@424: bo->updateLink(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@445: void MapEditor::setFrameType(const QString &s) // FIXME missing saveState insilmaril@445: { insilmaril@445: BranchObj *bo=xelection.getBranch(); insilmaril@445: if (bo) insilmaril@445: { insilmaril@445: bo->setFrameType (s); insilmaril@445: mapCenter->reposition(); insilmaril@445: bo->updateLink(); insilmaril@445: } insilmaril@445: } insilmaril@445: insilmaril@442: void MapEditor::setFramePenColor(const QColor &c) // FIXME missing saveState insilmaril@442: { insilmaril@442: BranchObj *bo=xelection.getBranch(); insilmaril@442: if (bo) insilmaril@442: bo->setFramePenColor (c); insilmaril@442: } insilmaril@442: insilmaril@442: void MapEditor::setFrameBrushColor(const QColor &c) // FIXME missing saveState insilmaril@442: { insilmaril@442: BranchObj *bo=xelection.getBranch(); insilmaril@442: if (bo) insilmaril@442: bo->setFrameBrushColor (c); 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@175: mapCenter->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@175: mapCenter->reposition(); insilmaril@424: } insilmaril@175: } insilmaril@175: insilmaril@421: void MapEditor::setHideLinkUnselected (bool b) // FIXME missing saveState insilmaril@160: { insilmaril@424: LinkableMapObj *sel=xelection.single(); insilmaril@424: if (sel && insilmaril@424: (xelection.type() == Branch || insilmaril@424: xelection.type() == MapCenter || insilmaril@424: xelection.type() == FloatImage )) insilmaril@424: sel->setHideLinkUnselected(b); insilmaril@160: } insilmaril@160: insilmaril@421: void MapEditor::importDirInt(BranchObj *dst, QDir d) // FIXME missing saveState 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@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@366: importDirInt (bo,QDir(fd->selectedFile()) ); insilmaril@0: mapCenter->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@0: void MapEditor::testFunction() insilmaril@0: { insilmaril@421: // This is the playground insilmaril@421: insilmaril@432: insilmaril@432: /* insilmaril@314: WarningDialog dia; insilmaril@388: dia.showCancelButton (true); insilmaril@314: dia.setText("This is a longer \nWarning"); insilmaril@314: dia.setCaption("Warning: Flux problem"); insilmaril@432: dia.setShowAgainName("mapeditor/testDialog"); insilmaril@314: if (dia.exec()==QDialog::Accepted) insilmaril@314: cout << "accepted!\n"; insilmaril@314: else insilmaril@314: cout << "canceled!\n"; insilmaril@301: return; insilmaril@432: */ insilmaril@366: 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="<pos()); insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: insilmaril@0: if (lmo) insilmaril@0: { // MapObj was found insilmaril@424: if (xelection.single() != lmo) insilmaril@0: { insilmaril@0: // select the MapObj insilmaril@424: xelection.select(lmo); insilmaril@0: } insilmaril@0: // Context Menu insilmaril@424: if (xelection.getBranch() ) insilmaril@0: { insilmaril@424: // Context Menu on branch or mapcenter insilmaril@424: updateActions(); insilmaril@424: branchContextMenu->popup(e->globalPos() ); insilmaril@424: } else insilmaril@424: { insilmaril@424: if (xelection.getFloatImage() ) insilmaril@0: { insilmaril@0: // Context Menu on floatimage insilmaril@0: updateActions(); insilmaril@0: floatimageContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { // No MapObj found, we are on the Canvas itself insilmaril@408: // Context Menu on scene insilmaril@0: updateActions(); insilmaril@0: canvasContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@329: e->accept(); insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::keyPressEvent(QKeyEvent* e) insilmaril@398: { insilmaril@411: if (e->modifiers() & Qt::ControlModifier) insilmaril@398: { insilmaril@398: switch (mainWindow->getModMode()) insilmaril@398: { insilmaril@398: case ModModeColor: insilmaril@398: setCursor (PickColorCursor); insilmaril@398: break; insilmaril@398: case ModModeCopy: insilmaril@398: setCursor (CopyCursor); insilmaril@398: break; insilmaril@398: case ModModeXLink: insilmaril@398: setCursor (XLinkCursor); insilmaril@398: break; insilmaril@398: default : insilmaril@398: setCursor (Qt::ArrowCursor); insilmaril@398: break; insilmaril@398: } insilmaril@398: } insilmaril@398: } insilmaril@398: insilmaril@398: void MapEditor::keyReleaseEvent(QKeyEvent* e) insilmaril@398: { insilmaril@411: if (!(e->modifiers() & Qt::ControlModifier)) insilmaril@398: setCursor (Qt::ArrowCursor); insilmaril@398: } insilmaril@398: insilmaril@408: void MapEditor::mousePressEvent(QMouseEvent* e) insilmaril@0: { insilmaril@329: // Ignore right clicks, these will go to context menus insilmaril@366: if (e->button() == Qt::RightButton ) insilmaril@329: { insilmaril@329: e->ignore(); insilmaril@329: return; insilmaril@329: } insilmaril@329: insilmaril@408: QPointF p = mapToScene(e->pos()); insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: insilmaril@329: e->accept(); insilmaril@329: insilmaril@442: //Take care of system flags _or_ modifier modes insilmaril@267: // insilmaril@267: if (lmo && (typeid(*lmo)==typeid(BranchObj) || insilmaril@267: typeid(*lmo)==typeid(MapCenterObj) )) insilmaril@267: { insilmaril@267: QString foname=((BranchObj*)lmo)->getSystemFlagName(p); insilmaril@267: if (!foname.isEmpty()) insilmaril@267: { insilmaril@267: // systemFlag clicked insilmaril@366: selectInt (lmo); insilmaril@267: if (foname=="url") insilmaril@267: { insilmaril@366: if (e->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@390: if (mainWindow->getModMode()==ModModeColor) insilmaril@83: { insilmaril@83: pickingColor=true; insilmaril@398: setCursor (PickColorCursor); insilmaril@83: return; insilmaril@83: } insilmaril@390: if (mainWindow->getModMode()==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@390: if (mainWindow->getModMode()==ModModeCopy && insilmaril@366: e->state() & Qt::ControlModifier) insilmaril@93: { insilmaril@424: if (xelection.type()==Branch) insilmaril@93: { insilmaril@93: copyingObj=true; insilmaril@424: mapCenter->addBranch ((BranchObj*)xelection.single()); insilmaril@93: unselect(); insilmaril@424: xelection.select(mapCenter->getLastBranch()); insilmaril@104: mapCenter->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@421: if (mainWindow->getModMode()!=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@0: LinkableMapObj* lmo=mapCenter->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@424: QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow)); insilmaril@420: fio->getParObj()->requestReposition(); insilmaril@420: mapCenter->reposition(); insilmaril@420: insilmaril@420: linkTo (lmo->getSelectString()); insilmaril@442: //movingObj=lmosel; insilmaril@442: //movingObj_orgRelPos=lmosel->getRelPos(); insilmaril@420: insilmaril@420: mapCenter->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@0: mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: else insilmaril@0: mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@388: mapCenter->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@0: if (lmosel->getOrientation() == OrientLeftOfCenter) 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@408: dst=mapCenter->findMapObj(p, NULL); insilmaril@424: if (dst && lmosel) insilmaril@0: { insilmaril@366: if (e->state() & Qt::ShiftModifier) insilmaril@417: colorBranch (((BranchObj*)(dst))->getColor()); insilmaril@0: else insilmaril@417: colorSubtree (((BranchObj*)(dst))->getColor()); insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@83: insilmaril@83: // Have we been drawing a link? insilmaril@83: if (drawingLink) insilmaril@83: { insilmaril@83: drawingLink=false; insilmaril@83: // Check if we are over another branch insilmaril@408: dst=mapCenter->findMapObj(p, NULL); insilmaril@424: if (dst && lmosel) insilmaril@83: { insilmaril@95: tmpXLink->setEnd ( ((BranchObj*)(dst)) ); insilmaril@95: tmpXLink->updateXLink(); insilmaril@95: tmpXLink->activate(); insilmaril@398: //saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //FIXME undoCommand 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@424: QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow)); insilmaril@424: insilmaril@424: fo->getParObj()->requestReposition(); insilmaril@175: mapCenter->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@424: dst=mapCenter->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@424: if (xelection.type() == MapCenter ) insilmaril@412: { // FIXME The MapCenter was moved, no savestate yet insilmaril@388: } insilmaril@388: insilmaril@424: if (xelection.type() == 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@366: mapCenter->reposition(); insilmaril@366: insilmaril@424: QString ps=qpointfToString ( lmosel->getRelPos() ); insilmaril@366: saveState( insilmaril@424: lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), insilmaril@366: preSelStr, "moveRel "+ps, insilmaril@424: QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps)); insilmaril@163: insilmaril@366: } insilmaril@0: // Draw the original link, before selection was moved around insilmaril@0: mapCenter->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@366: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@408: QPointF p = mapToScene(e->pos()); insilmaril@0: LinkableMapObj *lmo=mapCenter->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@417: void MapEditor::dragMoveEvent(QDragMoveEvent *event) 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@417: QList 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@428: QString file = QDir::convertSeparators(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@420: mapCenter->reposition(); insilmaril@417: } insilmaril@417: } insilmaril@417: event->acceptProposedAction(); insilmaril@417: } insilmaril@417: insilmaril@417: /* insilmaril@417: 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; iselectedFile(); insilmaril@119: //lastImageDir=fn.left(fn.findRev ("/")); insilmaril@395: FloatImageObj *fio=bo->addFloatImage(); insilmaril@395: fio->load(img); insilmaril@395: fio->setOriginalFilename("Image added by Drag and Drop"); insilmaril@119: mapCenter->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: