insilmaril@0: #include "mapeditor.h" insilmaril@0: insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@374: #include insilmaril@374: #include insilmaril@0: insilmaril@0: #include insilmaril@95: #include insilmaril@0: #include insilmaril@0: insilmaril@0: #include "version.h" insilmaril@0: insilmaril@105: #include "api.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* saveImageFormatMenu; insilmaril@366: extern QMenu* canvasContextMenu; insilmaril@366: extern QMenu* lastMapsMenu; insilmaril@366: extern QMenu* importMenu; insilmaril@366: extern QMenu* exportMenu; insilmaril@366: insilmaril@0: insilmaril@0: extern Settings settings; insilmaril@366: extern ImageIO imageIO; insilmaril@0: insilmaril@269: extern QString iconPath; insilmaril@301: extern QDir vymBaseDir; insilmaril@366: extern QDir lastImageDir; insilmaril@269: insilmaril@164: int MapEditor::mapNum=0; // make instance insilmaril@0: insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: MapEditor::MapEditor( insilmaril@390: QWidget* parent, const char* name, Qt::WFlags f) : insilmaril@366: Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0) insilmaril@0: { insilmaril@0: //cout << "Constructor ME "<setAcceptDrops(true); insilmaril@119: insilmaril@366: mapCanvas = new Q3Canvas(width(),height()); insilmaril@0: mapCanvas->setAdvancePeriod(30); insilmaril@366: mapCanvas->setBackgroundColor (Qt::white); insilmaril@0: insilmaril@0: setCanvas (mapCanvas); insilmaril@0: insilmaril@160: // Always show scroll bars (automatic would flicker sometimes) insilmaril@366: setVScrollBarMode ( Q3ScrollView::AlwaysOn ); insilmaril@366: setHScrollBarMode ( Q3ScrollView::AlwaysOn ); insilmaril@0: insilmaril@0: mapCenter = new MapCenterObj(mapCanvas); insilmaril@0: mapCenter->setVisibility (true); insilmaril@0: mapCenter->setMapEditor (this); insilmaril@93: mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map")); insilmaril@175: mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2); 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@398: // FIXME should now work also on Mac... insilmaril@398: //#if defined(Q_OS_MACX) insilmaril@398: // HandOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png"),1,1 ); insilmaril@398: // PickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 ); insilmaril@398: //#else insilmaril@398: HandOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1); insilmaril@398: PickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); insilmaril@398: CopyCursor=QCursor ( QPixmap(iconPath+"cursorcopy.png"), 5,5 ); insilmaril@398: XLinkCursor=QCursor ( QPixmap(iconPath+"cursorxlink.png"), 5,27 ); insilmaril@398: //#endif 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: selection=NULL; insilmaril@0: selectionLast=NULL; insilmaril@0: movingObj=NULL; insilmaril@0: insilmaril@366: xelection.setMapCenter (mapCenter); 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@0: // Initially set movingCentre insilmaril@0: updateViewCenter(); insilmaril@0: insilmaril@0: mapCenter->reposition(); // for positioning heading insilmaril@381: insilmaril@381: // Initialize history window; insilmaril@381: historyWindow.setME(this); insilmaril@381: historyWindow.setStepsTotal(stepsTotal); insilmaril@381: historyWindow.update (undoSet); insilmaril@0: } insilmaril@0: insilmaril@0: MapEditor::~MapEditor() insilmaril@0: { insilmaril@119: if (imageBuffer) delete imageBuffer; insilmaril@119: if (urlOperator) { insilmaril@119: urlOperator->stop(); insilmaril@119: delete urlOperator; insilmaril@119: } insilmaril@119: 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@366: Q3Canvas* MapEditor::getCanvas() insilmaril@0: { insilmaril@0: return mapCanvas; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::adjustCanvasSize() insilmaril@0: { insilmaril@0: // To adjust the canvas to map, viewport size and position, we have to insilmaril@0: // do some coordinate magic... insilmaril@0: // insilmaril@0: // Get rectangle of (scroll-)view. insilmaril@0: // We want to be in canvas coords, so insilmaril@0: // we map. Important if view is zoomed... insilmaril@0: QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(), insilmaril@0: visibleWidth(), visibleHeight()) ); insilmaril@0: insilmaril@0: // Now we need the bounding box of view AND map to calc the correct canvas size. insilmaril@0: // Why? Because if the map itself is moved out of view, the view has to be enlarged insilmaril@0: // to avoid jumping aroung... insilmaril@0: QRect map=mapCenter->getTotalBBox(); insilmaril@0: insilmaril@0: // right edge - left edge insilmaril@0: int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x()); insilmaril@0: int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y()); insilmaril@0: insilmaril@0: insilmaril@0: if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) || insilmaril@0: !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight()) insilmaril@0: ) insilmaril@0: { insilmaril@0: // move the map on canvas (in order to not move it on screen) this is neccessary insilmaril@0: // a) if topleft corner of canvas is left or above topleft corner of view and also left of insilmaril@0: // above topleft corner of map. E.g. if map is completly inside view, but it would be possible insilmaril@0: // to scroll to an empty area of canvas to the left. insilmaril@0: // b) if topleft corner of map left of or above topleft of canvas insilmaril@0: int dx=0; insilmaril@0: int dy=0; insilmaril@0: insilmaril@0: if (cw > mapCanvas->width() ) insilmaril@0: { insilmaril@0: if (map.x()<0) dx=-map.x(); insilmaril@0: } insilmaril@0: if (cw < mapCanvas->width() ) insilmaril@0: dx=-min (view.x(),map.x()); insilmaril@0: if (ch > mapCanvas->height() ) insilmaril@0: { insilmaril@0: if (map.y()<0) dy=-map.y(); insilmaril@0: } insilmaril@0: if (ch < mapCanvas->height() ) insilmaril@0: { insilmaril@0: dy=-min (view.y(),map.y()); insilmaril@0: } insilmaril@0: // We really have to resize now. Let's go... insilmaril@0: mapCanvas->resize (cw,ch); insilmaril@0: if ( (dx!=0) || (dy!=0) ) insilmaril@0: { insilmaril@0: mapCenter->moveAllBy(dx,dy); insilmaril@0: mapCenter->reposition(); insilmaril@336: // mapCenter->positionBBox(); // To move float insilmaril@0: insilmaril@0: // scroll the view (in order to not move map on screen) insilmaril@0: scrollBy (dx,dy); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@139: bool MapEditor::isRepositionBlocked() insilmaril@0: { insilmaril@139: return blockReposition; insilmaril@0: } insilmaril@0: insilmaril@294: QString MapEditor::getName (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@366: QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &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@0: // offset offset of bbox of whole map in canvas. 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@185: QString mapAttr=attribut("version",__VYM_VERSION); 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@0: attribut("backgroundColor", mapCanvas->backgroundColor().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@166: FloatImageObj (mapCanvas).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@166: insilmaril@166: else if (selection && typeid(*selection)==typeid(BranchObj)) insilmaril@366: // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above? insilmaril@398: // FIXME is this possible at all? BO is already above... insilmaril@366: s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset); insilmaril@0: } insilmaril@0: insilmaril@0: // Save local settings insilmaril@0: s+=settings.getXMLData (destPath); insilmaril@0: insilmaril@0: // Save selection insilmaril@366: if (selection && !saveSel ) insilmaril@0: s+=valueElement("select",selection->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@366: backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),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@395: undoSet.setEntry (QString("/history/version"),__VYM_VERSION); insilmaril@366: undoSet.writeSettings(histPath); insilmaril@163: insilmaril@163: /* TODO remove after testing insilmaril@366: */ insilmaril@366: //cout << " into="<< histPath.toStdString()< pl; insilmaril@394: pl << 0 <<1; insilmaril@394: if (api.checkParamCount(pl)) insilmaril@394: { insilmaril@394: if (api.paramCount()==0) insilmaril@394: addNewBranchInt (-2); insilmaril@394: else insilmaril@394: { insilmaril@394: y=api.parInt (ok,0); insilmaril@394: if (ok ) addNewBranchInt (y); insilmaril@394: } insilmaril@394: } insilmaril@394: } insilmaril@394: } else if (com=="addBranchBefore") insilmaril@394: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else insilmaril@394: { insilmaril@394: if (api.paramCount()==0) insilmaril@394: { insilmaril@394: addNewBranchBefore (); insilmaril@394: } insilmaril@394: } insilmaril@393: } else if (com==QString("addMapReplace")) insilmaril@393: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@398: } else if (api.checkParamCount(1)) insilmaril@393: { insilmaril@398: //s=api.parString (ok,0); // selection insilmaril@398: t=api.parString (ok,0); // path to map insilmaril@393: if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); insilmaril@398: addMapReplaceInt(selection->getSelectString(),t); insilmaril@393: } insilmaril@393: } else if (com==QString("addMapInsert")) insilmaril@393: { insilmaril@394: if (!selection) insilmaril@393: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else insilmaril@394: { insilmaril@394: if (api.checkParamCount(2)) insilmaril@394: { insilmaril@394: t=api.parString (ok,0); // path to map insilmaril@394: y=api.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@395: } else if (com=="colorItem") insilmaril@395: { insilmaril@395: if (!selection) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Nothing selected"); insilmaril@395: } else if ( typeid(*selection) != typeid(BranchObj) && insilmaril@395: typeid(*selection) != typeid(MapCenterObj)) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@395: } else if (api.checkParamCount(1)) insilmaril@395: { insilmaril@395: QColor c=api.parColor (ok,0); insilmaril@395: if (ok) colorItem (c); insilmaril@395: } insilmaril@395: } else if (com=="colorBranch") insilmaril@395: { insilmaril@395: if (!selection) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Nothing selected"); insilmaril@395: } else if ( typeid(*selection) != typeid(BranchObj) && insilmaril@395: typeid(*selection) != typeid(MapCenterObj)) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@395: } else if (api.checkParamCount(1)) insilmaril@395: { insilmaril@395: QColor c=api.parColor (ok,0); insilmaril@395: if (ok) colorBranch (c); insilmaril@395: } insilmaril@395: } else if (com=="cut") insilmaril@395: { insilmaril@395: if (!selection) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Nothing selected"); insilmaril@395: } else if ( typeid(*selection) != typeid(BranchObj) && insilmaril@395: typeid(*selection) != typeid(MapCenterObj) && insilmaril@395: typeid(*selection) != typeid(FloatImageObj) ) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@395: } else if (api.checkParamCount(0)) insilmaril@395: { insilmaril@395: cut(); insilmaril@395: } insilmaril@393: } else if (com=="delete") insilmaril@393: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(0)) insilmaril@393: { insilmaril@393: deleteSelection(); insilmaril@393: } insilmaril@394: } else if (com=="deleteKeepChilds") insilmaril@394: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(0)) insilmaril@394: { insilmaril@395: deleteKeepChilds(); insilmaril@395: } insilmaril@395: } else if (com=="deleteChilds") insilmaril@395: { insilmaril@395: if (!selection) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Nothing selected"); insilmaril@395: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@395: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@395: } else if (api.checkParamCount(0)) insilmaril@395: { insilmaril@395: deleteChilds(); insilmaril@394: } insilmaril@393: } else if (com=="linkBranchToPos") insilmaril@129: { insilmaril@394: if (!selection) insilmaril@129: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(4)) insilmaril@394: { insilmaril@394: // 0 selectstring of parent insilmaril@394: // 1 num in parent (for branches) insilmaril@394: // 2,3 x,y of mainbranch or mapcenter insilmaril@394: s=api.parString(ok,0); insilmaril@394: LinkableMapObj *dst=mapCenter->findObjBySelect (s); insilmaril@394: if (dst) insilmaril@394: { insilmaril@394: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@394: { insilmaril@394: // Get number in parent insilmaril@394: x=api.parInt (ok,1); insilmaril@394: if (ok) insilmaril@394: ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x); insilmaril@394: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@394: { insilmaril@394: ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1); insilmaril@394: // Get coordinates of mainbranch insilmaril@394: x=api.parInt (ok,2); insilmaril@394: if (ok) insilmaril@139: { insilmaril@394: y=api.parInt (ok,3); insilmaril@394: if (ok) ((BranchObj*)selection)->move (x,y); insilmaril@394: } insilmaril@129: } insilmaril@394: } insilmaril@129: } insilmaril@393: } else if (com=="moveBranchUp") insilmaril@393: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(0)) insilmaril@394: { insilmaril@394: moveBranchUp(); insilmaril@394: } insilmaril@394: } else if (com=="moveBranchDown") insilmaril@394: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(0)) insilmaril@394: { insilmaril@394: moveBranchDown(); insilmaril@394: } insilmaril@394: } else if (com=="move") insilmaril@394: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj) && insilmaril@394: typeid(*selection) != typeid(FloatImageObj) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@394: } else if (api.checkParamCount(2)) insilmaril@393: { insilmaril@393: x=api.parInt (ok,0); insilmaril@393: if (ok) insilmaril@393: { insilmaril@393: y=api.parInt (ok,1); insilmaril@393: if (ok) move (x,y); insilmaril@393: } insilmaril@393: } insilmaril@395: } else if (com=="moveRel") insilmaril@393: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj) && insilmaril@394: typeid(*selection) != typeid(FloatImageObj) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@394: } else if (api.checkParamCount(2)) insilmaril@393: { insilmaril@393: x=api.parInt (ok,0); insilmaril@393: if (ok) insilmaril@393: { insilmaril@393: y=api.parInt (ok,1); insilmaril@393: if (ok) moveRel (x,y); insilmaril@393: } insilmaril@393: } insilmaril@395: } else if (com=="paste") insilmaril@395: { insilmaril@395: if (!selection) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Nothing selected"); insilmaril@395: } else if ( typeid(*selection) != typeid(BranchObj) && insilmaril@395: typeid(*selection) != typeid(MapCenterObj) ) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@395: } else if (api.checkParamCount(0)) insilmaril@395: { insilmaril@395: paste(); insilmaril@395: } insilmaril@398: } else if (com=="select") insilmaril@398: { insilmaril@398: if (api.checkParamCount(1)) insilmaril@398: { insilmaril@398: s=api.parString(ok,0); insilmaril@398: if (ok) select (s); insilmaril@398: } insilmaril@398: } else if (com=="setMapAuthor") insilmaril@398: { insilmaril@398: if (api.checkParamCount(1)) insilmaril@398: { insilmaril@398: s=api.parString(ok,0); insilmaril@398: if (ok) setMapAuthor (s); insilmaril@398: } insilmaril@398: } else if (com=="setMapComment") insilmaril@398: { insilmaril@398: if (api.checkParamCount(1)) insilmaril@398: { insilmaril@398: s=api.parString(ok,0); insilmaril@398: if (ok) setMapComment(s); insilmaril@398: } insilmaril@398: } else if (com=="setMapBackgroundColor") insilmaril@398: { insilmaril@398: if (!selection) insilmaril@398: { insilmaril@398: api.setError (Aborted,"Nothing selected"); insilmaril@398: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@398: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@398: { insilmaril@398: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@398: } else if (api.checkParamCount(1)) insilmaril@398: { insilmaril@398: QColor c=api.parColor (ok,0); insilmaril@398: if (ok) setMapBackgroundColor (c); insilmaril@398: } insilmaril@398: } else if (com=="setMapDefLinkColor") insilmaril@398: { insilmaril@398: if (!selection) insilmaril@398: { insilmaril@398: api.setError (Aborted,"Nothing selected"); insilmaril@398: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@398: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@398: { insilmaril@398: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@398: } else if (api.checkParamCount(1)) insilmaril@398: { insilmaril@398: QColor c=api.parColor (ok,0); insilmaril@398: if (ok) setMapDefLinkColor (c); insilmaril@398: } insilmaril@398: } else if (com=="setMapLinkStyle") insilmaril@398: { insilmaril@398: if (api.checkParamCount(1)) insilmaril@398: { insilmaril@398: s=api.parString (ok,0); insilmaril@398: if (ok) setMapLinkStyle(s); insilmaril@398: } insilmaril@129: } else if (com=="setHeading") insilmaril@129: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(1)) insilmaril@129: { insilmaril@129: s=api.parString (ok,0); insilmaril@366: if (ok) insilmaril@366: setHeading (s); insilmaril@129: } insilmaril@395: } else if (com=="setHideExport") insilmaril@395: { insilmaril@395: if (!selection) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Nothing selected"); insilmaril@395: } else if ( typeid(*selection) != typeid(BranchObj) && insilmaril@395: typeid(*selection) != typeid(FloatImageObj) ) insilmaril@395: { insilmaril@395: api.setError (Aborted,"Type of selection is not a branch or floatimage"); insilmaril@395: } else if (api.checkParamCount(1)) insilmaril@395: { insilmaril@395: b=api.parBool(ok,0); insilmaril@395: if (ok) setHideExport (b); insilmaril@395: } insilmaril@143: } else if (com=="setURL") insilmaril@143: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(1)) insilmaril@143: { insilmaril@143: s=api.parString (ok,0); insilmaril@366: if (ok) setURLInt(s); insilmaril@143: } insilmaril@143: } else if (com=="setVymLink") insilmaril@143: { insilmaril@394: if (!selection) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(1)) insilmaril@143: { insilmaril@143: s=api.parString (ok,0); insilmaril@366: if (ok) setVymLinkInt(s); insilmaril@143: } insilmaril@143: } insilmaril@366: else if (com=="setFlag") insilmaril@366: { insilmaril@394: if (!selection) insilmaril@366: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(1)) insilmaril@394: { insilmaril@394: s=api.parString(ok,0); insilmaril@394: if (ok) insilmaril@394: { insilmaril@394: BranchObj* bo=(BranchObj*)selection; insilmaril@394: bo->activateStandardFlag(s); insilmaril@394: bo->updateFlagsToolbar(); insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@366: else if (com=="unsetFlag") insilmaril@366: { insilmaril@394: if (!selection) insilmaril@366: { insilmaril@394: api.setError (Aborted,"Nothing selected"); insilmaril@394: } else if ( (typeid(*selection) != typeid(BranchObj) && insilmaril@394: typeid(*selection) != typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: api.setError (Aborted,"Type of selection is not a branch"); insilmaril@394: } else if (api.checkParamCount(1)) insilmaril@394: { insilmaril@394: s=api.parString(ok,0); insilmaril@394: if (ok) insilmaril@394: { insilmaril@394: BranchObj* bo=(BranchObj*)selection; insilmaril@394: bo->deactivateStandardFlag(s); insilmaril@394: bo->updateFlagsToolbar(); insilmaril@366: } insilmaril@366: } insilmaril@398: } else insilmaril@163: { insilmaril@394: api.setError (Aborted,"Unknown command"); insilmaril@163: } insilmaril@129: insilmaril@129: // Any errors? insilmaril@394: if (api.errorLevel()==NoError) insilmaril@394: setChanged(); insilmaril@394: else insilmaril@106: { insilmaril@366: // TODO Error handling insilmaril@366: qWarning("MapEditor::parseAtom: Error!"); insilmaril@394: qWarning(api.errorMessage()); insilmaril@394: } insilmaril@0: } insilmaril@0: insilmaril@294: void MapEditor::toggleHistoryWindow() insilmaril@294: { insilmaril@377: if (historyWindow.isVisible()) insilmaril@377: historyWindow.hide(); insilmaril@294: else insilmaril@377: historyWindow.show(); insilmaril@294: } insilmaril@294: 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@0: if (selection) selection->unselect(); insilmaril@0: selection=NULL; 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@294: insilmaril@294: // Adjust history window insilmaril@377: historyWindow.setCaption (__VYM " - " +tr("History for ")+fileName); 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@0: if (selection) selection->unselect(); insilmaril@0: selection=NULL; 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@395: if (!selection || (typeid(*selection) != typeid(BranchObj) && insilmaril@395: typeid(*selection) != typeid (MapCenterObj))) insilmaril@395: return aborted; insilmaril@395: BranchObj *bo=(BranchObj*)selection; insilmaril@395: if (lmode==ImportAdd) insilmaril@395: saveStateChangingPart( insilmaril@395: selection, insilmaril@395: selection, 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@395: selection, insilmaril@395: selection, 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@0: adjustCanvasSize(); 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@106: if (savemode==CompleteMap || selection==NULL) insilmaril@106: saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL); insilmaril@106: else insilmaril@106: saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection); 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@0: } insilmaril@0: insilmaril@0: QRect 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@0: // Don't print the visualisation of selection insilmaril@0: LinkableMapObj *oldselection=NULL; insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: oldselection=selection; insilmaril@0: selection->unselect(); insilmaril@0: } insilmaril@0: insilmaril@0: // Handle sizes of map and paper: insilmaril@0: // insilmaril@0: // setWindow defines which part of the canvas will be transformed insilmaril@0: // setViewport defines area on paper in device coordinates (dpi) insilmaril@0: // e.g. (0,50,700,700) is upper part on A4 insilmaril@0: // see also /usr/lib/qt3/doc/html/coordsys.html insilmaril@0: insilmaril@366: Q3PaintDeviceMetrics metrics (printer); insilmaril@0: insilmaril@0: double paperAspect = (double)metrics.width() / (double)metrics.height(); insilmaril@0: double mapAspect = (double)totalBBox.width() / (double)totalBBox.height(); insilmaril@0: insilmaril@102: QRect mapRect=totalBBox; insilmaril@366: Q3CanvasRectangle *frame=NULL; insilmaril@366: Q3CanvasText *footerFN=NULL; insilmaril@366: Q3CanvasText *footerDate=NULL; insilmaril@0: if (printFrame || printFooter) insilmaril@0: { insilmaril@0: insilmaril@0: if (printFrame) insilmaril@0: { insilmaril@0: // Print frame around map insilmaril@102: mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, insilmaril@102: totalBBox.width()+20, totalBBox.height()+20); insilmaril@366: frame=new Q3CanvasRectangle (mapRect,mapCanvas); insilmaril@366: frame->setBrush (QColor(Qt::white)); insilmaril@366: frame->setPen (QColor(Qt::black)); insilmaril@0: frame->setZ(0); insilmaril@0: frame->show(); insilmaril@0: } insilmaril@163: /* TODO remove after testing insilmaril@102: QCanvasLine *l=new QCanvasLine (mapCanvas); insilmaril@102: l->setPoints (0,0,mapRect.width(),mapRect.height()); insilmaril@102: l->setPen (QPen(QColor(black), 1)); insilmaril@102: l->setZ (200); insilmaril@102: l->show(); insilmaril@131: */ insilmaril@102: insilmaril@0: if (printFooter) insilmaril@0: { insilmaril@0: // Print footer below map insilmaril@0: QFont font; insilmaril@0: font.setPointSize(10); insilmaril@366: footerFN=new Q3CanvasText (mapCanvas); insilmaril@0: footerFN->setText ("VYM - " + fileName); insilmaril@0: footerFN->setFont(font); insilmaril@0: footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() ); insilmaril@0: footerFN->setZ(Z_TEXT); insilmaril@0: footerFN->show(); insilmaril@366: footerDate=new Q3CanvasText (mapCanvas); insilmaril@0: footerDate->setText (QDate::currentDate().toString(Qt::TextDate)); insilmaril@0: footerDate->setFont(font); insilmaril@0: footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() ); insilmaril@0: footerDate->setZ(Z_TEXT); insilmaril@0: footerDate->show(); insilmaril@0: } insilmaril@102: pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20); insilmaril@0: } else insilmaril@0: { insilmaril@0: pp.setWindow (mapRect); insilmaril@0: } insilmaril@0: insilmaril@0: if (mapAspect>=paperAspect) insilmaril@0: { insilmaril@0: // Fit horizontally to paper width insilmaril@0: pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) ); insilmaril@0: } else insilmaril@0: { insilmaril@0: // Fit vertically to paper height insilmaril@0: pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height()); insilmaril@0: } insilmaril@0: insilmaril@0: mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer insilmaril@0: insilmaril@0: // Delete Frame and footer insilmaril@0: if (footerFN) insilmaril@0: { insilmaril@0: delete (footerFN); insilmaril@0: delete (footerDate); insilmaril@0: } insilmaril@0: if (frame) delete (frame); insilmaril@0: insilmaril@0: // Restore selection insilmaril@0: if (oldselection) insilmaril@0: { insilmaril@0: selection=oldselection; insilmaril@0: selection->select(); insilmaril@0: } insilmaril@119: insilmaril@119: // Save settings in vymrc insilmaril@366: settings.writeEntry("/mainwindow/printerName",printer->printerName()); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: QPixmap MapEditor::getPixmap() insilmaril@0: { insilmaril@0: QRect mapRect=mapCenter->getTotalBBox(); insilmaril@0: QPixmap pix (mapRect.size()); insilmaril@0: QPainter pp (&pix); insilmaril@0: insilmaril@0: // Don't print the visualisation of selection insilmaril@0: LinkableMapObj *oldselection=NULL; insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: oldselection=selection; insilmaril@0: selection->unselect(); insilmaril@0: } insilmaril@0: insilmaril@0: pp.setWindow (mapRect); insilmaril@0: insilmaril@0: mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter insilmaril@0: insilmaril@0: insilmaril@0: // Restore selection insilmaril@0: if (oldselection) insilmaril@0: { insilmaril@0: selection=oldselection; insilmaril@0: selection->select(); insilmaril@0: } 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@260: adjustCanvasSize(); insilmaril@260: canvas()->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@0: if (selection) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=NULL; insilmaril@0: } insilmaril@0: insilmaril@0: mapCenter->clear(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::copy() insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@166: // write to directory insilmaril@166: QString clipfile="part"; insilmaril@166: QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection); 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@395: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(__VYM_VERSION)); 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@381: historyWindow.update (undoSet); insilmaril@366: updateActions(); insilmaril@366: insilmaril@366: /* TODO remove testing insilmaril@163: */ 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@395: tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(__VYM_VERSION)); 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@366: */ insilmaril@163: cout << "ME::undo() end\n"; insilmaril@163: cout << " undosAvail="<0) insilmaril@390: return true; insilmaril@390: else insilmaril@390: return false; insilmaril@390: } insilmaril@390: insilmaril@381: void MapEditor::gotoStep (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: cout << "ME::goto "<undosAvail) 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@393: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@393: typeid(*selection) == typeid(MapCenterObj))) 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@394: if (selection!=mapCenter) insilmaril@394: ((BranchObj*)selection)->getLastBranch()->moveBranchTo ((BranchObj*)(selection),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@0: void MapEditor::paste() insilmaril@0: { insilmaril@166: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@166: typeid(*selection) == typeid(MapCenterObj))) insilmaril@166: { insilmaril@166: pasteNoSave(); insilmaril@395: saveStateChangingPart( insilmaril@395: selection, insilmaril@395: selection, insilmaril@395: "paste ()", insilmaril@395: QString("Paste to %1").arg( getName(selection)) insilmaril@395: ); insilmaril@166: mapCenter->reposition(); insilmaril@166: adjustCanvasSize(); insilmaril@166: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cut() insilmaril@0: { insilmaril@395: saveStateChangingPart( insilmaril@395: selection->getParObj(), insilmaril@395: selection, insilmaril@395: "cut ()", insilmaril@395: QString("Cut %1").arg(getName(selection)) insilmaril@395: ); insilmaril@0: copy(); insilmaril@0: cutNoSave(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@130: void MapEditor::move(const int &x, const int &y) insilmaril@130: { insilmaril@366: if (selection) insilmaril@366: { insilmaril@366: QString ps=qpointToString (selection->getAbsPos()); insilmaril@366: QString s=selection->getSelectString(); insilmaril@366: saveState( insilmaril@366: s, "move "+ps, insilmaril@366: s, "move "+qpointToString (QPoint (x,y)), insilmaril@366: QString("Move %1 to %2").arg(getName(selection)).arg(ps)); insilmaril@366: selection->move(x,y); insilmaril@366: mapCenter->reposition(); insilmaril@366: adjustCanvasSize(); insilmaril@366: } insilmaril@366: insilmaril@366: } insilmaril@366: insilmaril@366: void MapEditor::moveRel (const int &x, const int &y) insilmaril@366: { insilmaril@388: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@388: typeid(*selection) == typeid(MapCenterObj) || insilmaril@388: typeid(*selection) == typeid (FloatImageObj))) insilmaril@366: { insilmaril@366: QString ps=qpointToString (selection->getRelPos()); insilmaril@366: QString s=selection->getSelectString(); insilmaril@366: saveState( insilmaril@366: s, "moveRel "+ps, insilmaril@366: s, "moveRel "+qpointToString (QPoint (x,y)), insilmaril@366: QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps)); insilmaril@388: ((OrnamentedObj*)selection)->move2RelPos (x,y); insilmaril@366: mapCenter->reposition(); insilmaril@366: adjustCanvasSize(); insilmaril@366: } insilmaril@130: } insilmaril@130: insilmaril@0: void MapEditor::moveBranchUp() insilmaril@0: { insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@163: bo=(BranchObj*)selection; insilmaril@314: if (!bo->canMoveBranchUp()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@0: selection->unselect(); insilmaril@366: bo=par->moveBranchUp (bo); // bo will be the one below selection insilmaril@0: selection->select(); insilmaril@366: saveState (selection,"moveBranchDown ()",bo,"moveBranchUp ()",QString("Move up %1").arg(getName(bo))); insilmaril@0: mapCenter->reposition(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::moveBranchDown() insilmaril@0: { insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@163: bo=(BranchObj*)selection; insilmaril@314: if (!bo->canMoveBranchDown()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@0: selection->unselect(); insilmaril@366: bo=par->moveBranchDown(bo); // bo will be the one above selection insilmaril@0: selection->select(); insilmaril@366: saveState(selection,"moveBranchUp ()",bo,"moveBranchDown ()",QString("Move down %1").arg(getName(bo))); insilmaril@0: mapCenter->reposition(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@366: QString MapEditor::getHeading(bool &ok, QPoint &p) insilmaril@0: { insilmaril@366: if (selection && insilmaril@366: (typeid(*selection) == typeid(BranchObj) || insilmaril@366: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@366: { insilmaril@366: ok=true; insilmaril@366: ensureSelectionVisible(); insilmaril@366: p = ((BranchObj*)selection)->getAbsPos(); insilmaril@366: p.setX (p.x() - contentsX()); insilmaril@366: p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2); insilmaril@366: return ((BranchObj*)selection)->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@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@0: { insilmaril@163: editingBO=(BranchObj*)selection; insilmaril@395: saveState( insilmaril@395: selection, insilmaril@366: "setHeading (\""+editingBO->getHeading()+"\")", insilmaril@395: selection, insilmaril@366: "setHeading (\""+s+"\")", insilmaril@366: QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) ); insilmaril@366: editingBO->setHeading(s ); insilmaril@366: editingBO=NULL; insilmaril@106: mapCenter->reposition(); insilmaril@106: adjustCanvasSize(); 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@143: if (selection && insilmaril@143: (typeid(*selection) == typeid(BranchObj) || insilmaril@143: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@143: { insilmaril@163: ((BranchObj*)selection)->setURL(s); insilmaril@143: mapCenter->reposition(); insilmaril@143: adjustCanvasSize(); insilmaril@143: ensureSelectionVisible(); insilmaril@143: } insilmaril@143: } insilmaril@143: insilmaril@366: void MapEditor::setHeadingInt(const QString &s) insilmaril@366: { insilmaril@366: if (selection && insilmaril@366: (typeid(*selection) == typeid(BranchObj) || insilmaril@366: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@366: { insilmaril@366: ((BranchObj*)selection)->setHeading(s); insilmaril@366: mapCenter->reposition(); insilmaril@366: adjustCanvasSize(); 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@143: if (selection && insilmaril@143: (typeid(*selection) == typeid(BranchObj) || insilmaril@143: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@143: { insilmaril@163: ((BranchObj*)selection)->setVymLink(s); insilmaril@143: mapCenter->reposition(); insilmaril@143: adjustCanvasSize(); 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@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@0: { insilmaril@366: BranchObj* bo = (BranchObj*) selection; 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@394: BranchObj *bo = (BranchObj*) selection; insilmaril@394: BranchObj *newbo=NULL; insilmaril@394: insilmaril@366: if (selection && insilmaril@366: (typeid(*selection) == typeid(BranchObj) || insilmaril@366: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@366: { insilmaril@366: newbo=addNewBranchInt (pos-2); insilmaril@366: insilmaril@366: if (newbo) insilmaril@366: { insilmaril@395: saveState( insilmaril@395: selection, // FIXME sholdnt newbo be deleted here??? insilmaril@393: "delete ()", insilmaril@395: selection, 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@366: adjustCanvasSize(); 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@366: if (selection && insilmaril@366: (typeid(*selection) == typeid(BranchObj) ) ) insilmaril@394: // We accept no MapCenterObj here, so we _have_ a parent insilmaril@366: { insilmaril@394: BranchObj* bo = (BranchObj*) selection; insilmaril@394: QPoint p=bo->getRelPos(); insilmaril@394: insilmaril@394: insilmaril@366: BranchObj *parbo=(BranchObj*)(selection->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@394: ((BranchObj*)selection)->moveBranchTo (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@394: adjustCanvasSize(); insilmaril@394: } insilmaril@0: } insilmaril@394: return newbo; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::deleteSelection() insilmaril@0: { insilmaril@0: if (selection && typeid(*selection) ==typeid(BranchObj) ) insilmaril@0: { insilmaril@366: BranchObj* bo=(BranchObj*)selection; insilmaril@294: BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@294: bo->unselect(); insilmaril@394: saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo))); insilmaril@0: selection=NULL; insilmaril@0: par->removeBranch(bo); insilmaril@0: selection=par; insilmaril@0: selection->select(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: if (selection && typeid(*selection) ==typeid(FloatImageObj) ) insilmaril@0: { insilmaril@366: FloatImageObj* fio=(FloatImageObj*)selection; 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@0: fio->unselect(); insilmaril@0: selection=NULL; insilmaril@0: par->removeFloatImage(fio); insilmaril@0: selection=par; insilmaril@0: selection->select(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: LinkableMapObj* MapEditor::getSelection() insilmaril@0: { insilmaril@0: return selection; insilmaril@0: } insilmaril@0: insilmaril@267: void MapEditor::unselect() insilmaril@267: { insilmaril@267: if (selection) insilmaril@267: { insilmaril@267: selectionLast=selection; insilmaril@267: selection->unselect(); insilmaril@267: selection=NULL; insilmaril@267: } insilmaril@267: } insilmaril@267: insilmaril@267: void MapEditor::reselect() insilmaril@267: { insilmaril@267: if (selectionLast) insilmaril@267: { insilmaril@267: selection=selectionLast; insilmaril@267: selection->select(); insilmaril@267: selectionLast=NULL; insilmaril@267: } 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@98: if (selection) unselect(); insilmaril@0: selection=lmo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); 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@366: if (selection) return selection->getSelectString(); insilmaril@366: return QString(); insilmaril@366: } insilmaril@366: insilmaril@366: void MapEditor::selectInt (LinkableMapObj *lmo) insilmaril@0: { insilmaril@267: if (lmo && selection != lmo) insilmaril@0: { insilmaril@267: // select the MapObj insilmaril@267: if (selection) selection->unselect(); insilmaril@267: selection=lmo; insilmaril@267: selection->select(); insilmaril@267: insilmaril@267: adjustCanvasSize(); insilmaril@0: } insilmaril@267: } insilmaril@0: insilmaril@366: void MapEditor::selectNextBranchInt() insilmaril@0: { insilmaril@0: // Increase number of branch insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: QString s=selection->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@0: int d=selection->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@0: if (selection->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@0: if (selection) insilmaril@0: { insilmaril@0: QString s=selection->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 precessor, insilmaril@0: // try to decrease the parental number in order to insilmaril@0: // find a precessor with same depth insilmaril@0: insilmaril@0: int d=selection->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@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@0: if (selection->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 last branch for each depth insilmaril@0: for (i=d;icountBranches()>0) insilmaril@163: s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->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@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj)) insilmaril@0: { insilmaril@0: if (selection->getOrientation()==OrientRightOfCenter) insilmaril@366: selectPrevBranchInt(); insilmaril@0: else insilmaril@0: if (selection->getDepth()==1) insilmaril@366: selectNextBranchInt(); insilmaril@0: else insilmaril@366: selectPrevBranchInt(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLowerBranch() insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj)) insilmaril@0: { insilmaril@0: if (selection->getOrientation()==OrientRightOfCenter) insilmaril@366: selectNextBranchInt(); insilmaril@0: else insilmaril@0: if (selection->getDepth()==1) insilmaril@366: selectPrevBranchInt(); insilmaril@0: else insilmaril@366: selectNextBranchInt(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::selectLeftBranch() insilmaril@0: { insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(MapCenterObj)) insilmaril@0: { insilmaril@163: par= (BranchObj*) selection; 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@0: { insilmaril@0: bo=par->getLastBranch(); insilmaril@0: } insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: par->unselect(); insilmaril@0: selection=bo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: par=(BranchObj*)(selection->getParObj()); insilmaril@0: if (selection->getOrientation()==OrientRightOfCenter) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(FloatImageObj)) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=par; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@163: bo=((BranchObj*)selection)->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=bo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); 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@0: insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(MapCenterObj)) insilmaril@0: { insilmaril@163: par= (BranchObj*) selection; 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@0: par->unselect(); insilmaril@0: selection=bo; insilmaril@0: selection->select(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: par=(BranchObj*)(selection->getParObj()); insilmaril@0: if (selection->getOrientation()==OrientLeftOfCenter) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(FloatImageObj)) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=par; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@163: bo=((BranchObj*)selection)->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=bo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); 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@0: BranchObj *bo1; insilmaril@0: BranchObj *bo2; insilmaril@0: BranchObj* par; insilmaril@0: if (selection) { insilmaril@0: if (typeid(*selection) == typeid(BranchObj)) insilmaril@0: { insilmaril@163: bo1= (BranchObj*) selection; insilmaril@0: par=(BranchObj*)(bo1->getParObj()); insilmaril@0: bo2=par->getFirstBranch(); insilmaril@0: if (bo2) { insilmaril@0: bo1->unselect(); insilmaril@0: selection=bo2; insilmaril@0: selection->select(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLastBranch() insilmaril@0: { insilmaril@0: BranchObj *bo1; insilmaril@0: BranchObj *bo2; insilmaril@0: BranchObj* par; insilmaril@0: if (selection) { insilmaril@0: if (typeid(*selection) == typeid(BranchObj)) insilmaril@0: { insilmaril@163: bo1= (BranchObj*) selection; insilmaril@0: par=(BranchObj*)(bo1->getParObj()); insilmaril@0: bo2=par->getLastBranch(); insilmaril@0: if (bo2) { insilmaril@0: bo1->unselect(); insilmaril@0: selection=bo2; insilmaril@0: selection->select(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@398: void MapEditor::selectMapBackgroundColor() insilmaril@0: { insilmaril@0: QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: setBackgroundColor( col ); insilmaril@0: } insilmaril@0: insilmaril@398: insilmaril@398: void MapEditor::setMapBackgroundColor(QColor col) insilmaril@0: { insilmaril@398: QColor oldcol=mapCanvas->backgroundColor(); insilmaril@398: saveState( insilmaril@398: selection, insilmaril@398: QString ("setMapBackgroundColor (%1)").arg(oldcol.name()), insilmaril@398: selection, insilmaril@398: QString ("setMapBackgroundColor (%1)").arg(col.name()), insilmaril@398: QString("Set background color of map to %1").arg(col.name())); insilmaril@398: mapCanvas->setBackgroundColor (col); insilmaril@398: } insilmaril@398: insilmaril@398: QColor MapEditor::getMapBackgroundColor() insilmaril@398: { insilmaril@398: return mapCanvas->backgroundColor(); insilmaril@0: } insilmaril@0: insilmaril@395: QColor MapEditor::getCurrentHeadingColor() insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) insilmaril@0: { insilmaril@163: BranchObj *bo=(BranchObj*)selection; insilmaril@395: return bo->getColor(); insilmaril@0: } insilmaril@0: } 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@395: void MapEditor::colorItem(QColor c) insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) insilmaril@0: { insilmaril@163: BranchObj *bo=(BranchObj*)selection; insilmaril@398: saveState( insilmaril@395: selection, insilmaril@398: QString ("colorItem (%1)").arg(bo->getColor().name()), insilmaril@395: selection, insilmaril@395: QString ("colorItem (%1)").arg(c.name()), insilmaril@395: QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name()) insilmaril@398: ); insilmaril@395: bo->setColor(c); // color branch insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@395: void MapEditor::colorBranch(QColor c) insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) insilmaril@0: { insilmaril@163: BranchObj *bo=(BranchObj*)selection; insilmaril@395: saveStateChangingPart( insilmaril@395: selection, insilmaril@395: selection, insilmaril@395: QString ("colorBranch (%1)").arg(c.name()), insilmaril@395: QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name()) insilmaril@395: ); insilmaril@395: bo->setColorChilds(c); // color links, color childs insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::toggleStandardFlag(QString f) insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@366: if (typeid(*selection) == typeid(BranchObj) || insilmaril@366: typeid(*selection) == typeid(MapCenterObj)) insilmaril@366: { insilmaril@366: BranchObj *bo=(BranchObj*)selection; insilmaril@366: QString u,r; insilmaril@366: if (bo->isSetStandardFlag(f)) insilmaril@366: { insilmaril@366: r="unsetFlag"; insilmaril@366: u="setFlag"; insilmaril@366: } insilmaril@366: else insilmaril@366: { insilmaril@366: u="unsetFlag"; insilmaril@366: r="setFlag"; insilmaril@366: } insilmaril@395: saveState( insilmaril@395: selection, insilmaril@395: QString("%1 (\"%2\")").arg(u).arg(f), insilmaril@395: selection, insilmaril@366: QString("%1 (\"%2\")").arg(r).arg(f), insilmaril@366: QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); insilmaril@390: bo->toggleStandardFlag (f,mainWindow->useFlagGroups()); insilmaril@366: adjustCanvasSize(); insilmaril@366: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setViewCenter() insilmaril@0: { insilmaril@0: // transform to CanvasView Coord: insilmaril@0: QPoint p=worldMatrix().map(movingCenter); insilmaril@0: center ( p.x(), p.y()); 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@0: if (selection!=itFind) insilmaril@0: { insilmaril@163: if (selection) ((BranchObj*)selection)->unselect(); insilmaril@0: selection=itFind; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); 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@163: if (selection) ((BranchObj*)selection)->unselect(); insilmaril@0: selection=itFind; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); 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@0: { insilmaril@0: adjustCanvasSize(); insilmaril@163: return (BranchObj*)selection; insilmaril@0: } 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@395: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@395: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@395: { insilmaril@395: BranchObj *bo=(BranchObj*)selection; insilmaril@395: QString oldurl=bo->getURL(); insilmaril@395: bo->setURL (url); insilmaril@395: saveState ( insilmaril@395: selection, insilmaril@395: QString ("setURL (\"%1\")").arg(oldurl), insilmaril@395: selection, 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@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@0: bool ok; insilmaril@163: BranchObj *bo=(BranchObj*)selection; 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@266: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@266: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@266: return ((BranchObj*)selection)->getURL(); insilmaril@266: else insilmaril@266: return ""; insilmaril@266: } insilmaril@266: insilmaril@366: QStringList MapEditor::getURLs() insilmaril@366: { insilmaril@366: QStringList urls; insilmaril@366: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@366: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@366: { insilmaril@366: BranchObj *bo=(BranchObj*)selection; 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@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@395: setURL (((BranchObj*)selection)->getHeading()); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::editBugzilla2URL() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@163: BranchObj *bo=(BranchObj*)selection; 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@175: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@175: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@175: { insilmaril@175: BranchObj *bo=(BranchObj*)selection; insilmaril@175: QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); insilmaril@395: saveState( insilmaril@395: selection, insilmaril@395: "setURL (\""+bo->getURL()+"\")", insilmaril@395: selection, 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@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@163: BranchObj *bo=(BranchObj*)selection; insilmaril@366: Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map")); insilmaril@0: fd->addFilter (QString (tr("vym map") + " (*.vym)")); insilmaril@185: fd->setCaption(__VYM " - " +tr("Link to another map")); insilmaril@143: if (! bo->getVymLink().isEmpty() ) insilmaril@143: fd->setSelection( bo->getVymLink() ); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@143: { insilmaril@395: saveState( insilmaril@395: selection, insilmaril@395: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@395: selection, 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@143: adjustCanvasSize(); insilmaril@143: canvas()->update(); insilmaril@143: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::deleteVymLink() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@163: BranchObj *bo=(BranchObj*)selection; insilmaril@395: saveState( insilmaril@395: selection, insilmaril@395: "setVymLink (\""+bo->getVymLink()+"\")", insilmaril@395: selection, 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@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@395: void MapEditor::setHideExport(bool b) insilmaril@243: { insilmaril@243: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@395: typeid(*selection)==typeid(FloatImageObj))) insilmaril@395: { insilmaril@250: OrnamentedObj *oo=(OrnamentedObj*)selection; insilmaril@395: oo->setHideInExport (b); insilmaril@395: QString u= b ? "false" : "true"; insilmaril@395: QString r=!b ? "false" : "true"; insilmaril@395: insilmaril@395: saveState( insilmaril@395: selection, insilmaril@395: QString ("setHideExport (%1)").arg(u), insilmaril@395: selection, insilmaril@395: QString ("setHideExport (%1)").arg(r), insilmaril@395: QString ("Set HideExport flag of %1 to %2").arg(getName(oo)).arg (r) insilmaril@395: ); insilmaril@243: updateActions(); insilmaril@243: mapCenter->reposition(); insilmaril@243: adjustCanvasSize(); insilmaril@243: canvas()->update(); insilmaril@243: } insilmaril@243: } insilmaril@243: insilmaril@395: void MapEditor::toggleHideExport() insilmaril@395: { insilmaril@395: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@395: typeid(*selection)==typeid(FloatImageObj))) insilmaril@395: setHideExport ( !((OrnamentedObj*)selection)->hideInExport() ); insilmaril@395: } insilmaril@395: insilmaril@0: QString MapEditor::getVymLink() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@163: return ((BranchObj*)selection)->getVymLink(); insilmaril@0: } insilmaril@0: return ""; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@366: QStringList MapEditor::getVymLinks() insilmaril@366: { insilmaril@366: QStringList links; insilmaril@366: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@366: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@366: { insilmaril@366: BranchObj *bo=(BranchObj*)selection; 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@98: if (selection && (typeid(*selection) == typeid(BranchObj) )) insilmaril@98: { insilmaril@163: BranchObj* bo=(BranchObj*)selection; insilmaril@98: BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@394: QPoint p=bo->getRelPos(); insilmaril@395: saveStateChangingPart( insilmaril@395: selection->getParObj(), insilmaril@395: selection, insilmaril@395: "deleteKeepChilds ()", insilmaril@395: QString("Remove %1 and keep its childs").arg(getName(bo)) insilmaril@395: ); insilmaril@394: insilmaril@139: QString sel=selection->getSelectString(); insilmaril@98: unselect(); insilmaril@98: par->removeBranchHere(bo); insilmaril@98: mapCenter->reposition(); insilmaril@98: select (sel); insilmaril@394: ((BranchObj*)selection)->move2RelPos (p); insilmaril@394: mapCenter->reposition(); insilmaril@394: adjustCanvasSize(); insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@395: void MapEditor::deleteChilds() insilmaril@98: { insilmaril@395: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@395: typeid(*selection)==typeid(MapCenterObj))) insilmaril@98: { insilmaril@395: saveStateChangingPart( insilmaril@395: selection->getParObj(), insilmaril@395: selection, insilmaril@395: "deleteChilds ()", insilmaril@395: QString( "Remove childs of branch %1").arg(getName(selection)) insilmaril@395: ); insilmaril@163: ((BranchObj*)selection)->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@0: int i=0; insilmaril@366: Q3CanvasItemList l=canvas()->allItems(); insilmaril@366: for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) insilmaril@0: i++; insilmaril@0: stats+=QString ("%1 items on canvas\n").arg (i,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@0: void MapEditor::updateActions() insilmaril@0: { insilmaril@390: mainWindow->updateActions(); insilmaril@390: // FIXME maybe don't update if blockReposition is set insilmaril@0: } insilmaril@0: insilmaril@160: void MapEditor::updateNoteFlag() insilmaril@160: { insilmaril@160: if (selection) insilmaril@160: if ( (typeid(*selection) == typeid(BranchObj)) || insilmaril@160: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@160: ((BranchObj*)selection)->updateNoteFlag(); insilmaril@160: } insilmaril@160: insilmaril@398: void MapEditor::setMapAuthor (const QString &s) insilmaril@0: { insilmaril@398: saveState ( insilmaril@398: selection, insilmaril@398: QString ("setMapAuthor (\"%1\")").arg(mapCenter->getAuthor()), insilmaril@398: selection, 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@398: selection, insilmaril@398: QString ("setMapComment (\"%1\")").arg(mapCenter->getComment()), insilmaril@398: selection, 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@398: selection, insilmaril@398: QString("setMapDefLinkColor (\"%1\")").arg(getMapDefLinkColor().name()), insilmaril@398: selection, 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@131: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::toggleScroll() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj)) ) insilmaril@0: { insilmaril@163: BranchObj *bo=((BranchObj*)selection); insilmaril@0: if (bo->countBranches()==0) return; insilmaril@0: if (bo->getDepth()==0) return; insilmaril@395: QString u,r; insilmaril@294: if (bo->isScrolled()) insilmaril@395: { insilmaril@395: r="unscroll"; insilmaril@395: u="scroll"; insilmaril@395: } insilmaril@294: else insilmaril@395: { insilmaril@395: u="scroll"; insilmaril@395: r="unscroll"; insilmaril@395: } insilmaril@395: saveState( insilmaril@395: selection, insilmaril@395: QString ("%1 ()").arg(u), insilmaril@395: selection, insilmaril@395: QString ("%1 ()").arg(r), insilmaril@395: QString ("%1 %2").arg(r).arg(getName(bo)) insilmaril@395: ); insilmaril@0: bo->toggleScroll(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::unScrollAll() insilmaril@0: { insilmaril@0: BranchObj *bo; insilmaril@0: bo=mapCenter->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: if (bo->isScrolled()) bo->toggleScroll(); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::loadFloatImage () insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj)) || insilmaril@0: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@163: BranchObj *bo=((BranchObj*)selection); 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@185: fd->setCaption(__VYM " - " +tr("Load image")); insilmaril@0: fd->setDir (lastImageDir); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@366: // FIXME in QT4 use: lastImageDir=fd->directory(); insilmaril@366: lastImageDir=QDir (fd->dirPath()); insilmaril@185: QStringList flist = fd->selectedFiles(); insilmaril@185: QStringList::Iterator it = flist.begin(); insilmaril@395: FloatImageObj *fio; insilmaril@185: while( it != flist.end() ) insilmaril@185: { insilmaril@185: fn = *it; insilmaril@185: bo->addFloatImage(); insilmaril@395: fio=bo->getLastFloatImage(); insilmaril@395: fio->load(*it); insilmaril@395: // FIXME check if load of fio was successful insilmaril@395: saveState( insilmaril@395: (LinkableMapObj*)fio, insilmaril@395: "delete ()", insilmaril@395: selection, insilmaril@395: QString ("loadFloatImage (%1)").arg(*it), insilmaril@395: QString("Add floatimage %1 to %2").arg(*it).arg(getName(selection)) insilmaril@395: ); insilmaril@185: bo->getLastFloatImage()->setOriginalFilename(fn); insilmaril@185: ++it; insilmaril@185: } insilmaril@185: insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@236: delete (p); insilmaril@236: delete (fd); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@366: void MapEditor::saveFloatImage () insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@0: { insilmaril@163: FloatImageObj *fio=((FloatImageObj*)selection); insilmaril@366: QFileDialog *fd=new QFileDialog( this); insilmaril@366: fd->setFilters (imageIO.getFilters()); insilmaril@366: fd->setCaption(__VYM " - " +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@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: if (QFile (fd->selectedFile()).exists() ) insilmaril@0: { insilmaril@185: QMessageBox mb( __VYM, insilmaril@159: tr("The file %1 exists already.\n" insilmaril@159: "Do you want to overwrite it?").arg(fd->selectedFile()), 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@366: fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) ); insilmaril@0: } insilmaril@377: delete (fd); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setFrame(const FrameType &t) insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj)) || insilmaril@0: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@0: selection->setFrameType (t); insilmaril@0: mapCenter->reposition(); insilmaril@0: selection->updateLink(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@175: void MapEditor::setIncludeImagesVer(bool b) insilmaril@175: { insilmaril@175: if (selection && insilmaril@175: (typeid(*selection) == typeid(BranchObj)) || insilmaril@175: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@175: ((BranchObj*)selection)->setIncludeImagesVer(b); insilmaril@175: mapCenter->reposition(); insilmaril@175: } insilmaril@175: insilmaril@175: void MapEditor::setIncludeImagesHor(bool b) insilmaril@175: { insilmaril@175: if (selection && insilmaril@175: (typeid(*selection) == typeid(BranchObj)) || insilmaril@175: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@175: ((BranchObj*)selection)->setIncludeImagesHor(b); insilmaril@175: mapCenter->reposition(); insilmaril@175: } insilmaril@175: insilmaril@160: void MapEditor::setHideLinkUnselected (bool b) insilmaril@160: { insilmaril@160: if (selection && insilmaril@160: (typeid(*selection) == typeid(BranchObj)) || insilmaril@160: (typeid(*selection) == typeid(MapCenterObj)) || insilmaril@160: (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@160: selection->setHideLinkUnselected(b); insilmaril@160: } insilmaril@160: insilmaril@366: void MapEditor::importDirInt(BranchObj *dst, QDir d) insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj)) || insilmaril@0: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@0: BranchObj *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@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj)) || insilmaril@0: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@366: Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import")); insilmaril@366: fd->setMode (Q3FileDialog::DirectoryOnly); insilmaril@0: fd->addFilter (QString (tr("vym map") + " (*.vym)")); insilmaril@185: fd->setCaption(__VYM " - " +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@163: BranchObj *bo=((BranchObj*)selection); insilmaril@366: importDirInt (bo,QDir(fd->selectedFile()) ); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@95: void MapEditor::followXLink(int i) insilmaril@89: { insilmaril@97: if (selection && insilmaril@97: (typeid(*selection) == typeid(BranchObj)) || insilmaril@97: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@89: { insilmaril@163: BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i); insilmaril@97: if (bo) insilmaril@97: { insilmaril@97: selection->unselect(); insilmaril@97: selection=bo; insilmaril@97: selection->select(); insilmaril@97: ensureSelectionVisible(); insilmaril@97: } insilmaril@89: } insilmaril@89: } insilmaril@89: insilmaril@95: void MapEditor::editXLink(int i) insilmaril@94: { insilmaril@97: if (selection && insilmaril@97: (typeid(*selection) == typeid(BranchObj)) || insilmaril@97: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@94: { insilmaril@163: XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i); insilmaril@97: if (xlo) insilmaril@94: { insilmaril@97: EditXLinkDialog dia; insilmaril@97: dia.setXLink (xlo); insilmaril@102: dia.setSelection(selection); 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@163: ((BranchObj*)selection)->deleteXLinkAt(i); insilmaril@398: //saveStateComplete("Edit xLink"); //FIXME undoCommand insilmaril@97: } insilmaril@97: } insilmaril@97: } insilmaril@94: } insilmaril@94: insilmaril@0: void MapEditor::testFunction() insilmaril@0: { insilmaril@0: cout << "MapEditor::testFunction() called\n"; insilmaril@314: insilmaril@394: if (selection && insilmaril@394: (typeid(*selection) == typeid(BranchObj)) || insilmaril@394: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@394: { insilmaril@394: BranchObj* bo=(BranchObj*)selection; insilmaril@394: cout << bo->getHeading().ascii() <<" is scrolled: "<isScrolled()<