insilmaril@0: #include "mapeditor.h" insilmaril@0: insilmaril@0: #include insilmaril@366: #include insilmaril@0: #include insilmaril@0: #include insilmaril@366: #include insilmaril@0: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@0: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: //Added by qt3to4: insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #include insilmaril@366: #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 *systemFlagsDefault; insilmaril@0: extern FlagRowObj *standardFlagsDefault; insilmaril@0: insilmaril@366: extern Q3PtrList actionListBranches; insilmaril@98: insilmaril@0: extern QAction *actionFileSave; insilmaril@0: extern QAction *actionEditUndo; insilmaril@366: extern QAction *actionEditRedo; insilmaril@0: extern QAction *actionEditCopy; insilmaril@0: extern QAction *actionEditCut; insilmaril@0: extern QAction *actionEditPaste; insilmaril@0: extern QAction *actionEditMoveUp; insilmaril@0: extern QAction *actionEditMoveDown; insilmaril@0: extern QAction *actionEditToggleScroll; insilmaril@0: extern QAction *actionEditOpenURL; insilmaril@266: extern QAction *actionEditOpenURLTab; insilmaril@0: extern QAction *actionEditURL; insilmaril@0: extern QAction *actionEditHeading2URL; insilmaril@0: extern QAction *actionEditBugzilla2URL; insilmaril@175: extern QAction *actionEditFATE2URL; insilmaril@0: extern QAction *actionEditOpenVymLink; insilmaril@0: extern QAction *actionEditVymLink; insilmaril@0: extern QAction *actionEditDeleteVymLink; insilmaril@243: extern QAction *actionEditToggleHideExport; insilmaril@0: extern QAction *actionEditHeading; insilmaril@0: extern QAction *actionEditDelete; insilmaril@0: extern QAction *actionEditAddBranch; insilmaril@0: extern QAction *actionEditAddBranchAbove; insilmaril@0: extern QAction *actionEditAddBranchBelow; insilmaril@98: extern QAction *actionEditRemoveBranchHere; insilmaril@98: extern QAction *actionEditRemoveChilds; insilmaril@0: extern QAction *actionEditImportAdd; insilmaril@0: extern QAction *actionEditImportReplace; insilmaril@0: extern QAction *actionEditSaveBranch; insilmaril@0: extern QAction *actionEditSelectFirst; insilmaril@0: extern QAction *actionEditSelectLast; insilmaril@0: extern QAction *actionEditLoadImage; insilmaril@0: insilmaril@0: extern QAction* actionFormatPickColor; insilmaril@0: extern QAction* actionFormatColorBranch; insilmaril@0: extern QAction* actionFormatColorSubtree; insilmaril@0: extern QAction *actionFormatLinkColorHint; insilmaril@0: extern QAction *actionFormatBackColor; insilmaril@0: extern QAction *actionFormatLinkColor; insilmaril@0: insilmaril@89: extern QActionGroup* actionGroupModModes; insilmaril@89: extern QAction* actionModModeColor; insilmaril@89: extern QAction* actionModModeLink; insilmaril@93: extern QAction* actionModModeCopy; insilmaril@89: insilmaril@0: extern QActionGroup *actionGroupFormatFrameTypes; insilmaril@0: extern QAction *actionFormatFrameNone; insilmaril@0: extern QAction *actionFormatFrameRectangle; insilmaril@0: insilmaril@0: extern QActionGroup *actionGroupFormatLinkStyles; insilmaril@175: extern QAction *actionFormatIncludeImagesVer; insilmaril@175: extern QAction *actionFormatIncludeImagesHor; insilmaril@160: extern QAction *actionFormatHideLinkUnselected; insilmaril@0: extern QAction *actionFormatLinkStyleLine; insilmaril@0: extern QAction *actionFormatLinkStyleParabel; insilmaril@0: extern QAction *actionFormatLinkStylePolyLine; insilmaril@0: extern QAction *actionFormatLinkStylePolyParabel; insilmaril@0: insilmaril@0: extern QAction *actionViewToggleNoteEditor; insilmaril@0: insilmaril@0: extern QAction *actionSettingsAutoedit; insilmaril@0: extern QAction *actionSettingsAutoselectHeading; insilmaril@0: extern QAction *actionSettingsAutoselectText; insilmaril@103: extern QAction *actionSettingsUseFlagGroups; 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@366: QWidget* parent, bool interactive, 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@366: actColor=Qt::black; setColor (actColor); 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@0: #if defined(Q_OS_MACX) insilmaril@366: handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png"),1,1 ); insilmaril@269: pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 ); insilmaril@0: #else insilmaril@366: handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1); insilmaril@269: pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); insilmaril@0: #endif 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@366: undosTotal=settings.readNumEntry("/mapeditor/undoLevels",50); 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@0: isInteractive=interactive; insilmaril@0: if (isInteractive) insilmaril@0: // Create temporary files insilmaril@0: makeTmpDirs(); insilmaril@0: insilmaril@0: // Initially set movingCentre insilmaril@0: updateViewCenter(); insilmaril@0: insilmaril@294: // For testing purposes create history window insilmaril@294: historyWindow = new ShowTextDialog (this); insilmaril@294: historyWindow->setCaption (fileName); insilmaril@294: insilmaril@0: mapCenter->reposition(); // for positioning heading insilmaril@366: insilmaril@366: 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: // Save Settings insilmaril@366: //settings.writeEntry( "/mapeditor/editmode/autoselect", ); insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: QColor MapEditor::color() insilmaril@0: { insilmaril@0: return actColor; insilmaril@0: } insilmaril@0: insilmaril@0: QColor MapEditor::backgroundColor() insilmaril@0: { insilmaril@0: return mapCanvas->backgroundColor(); 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@314: return QString("branch (%1)").arg(s); insilmaril@314: } insilmaril@294: if ((typeid(*lmo) == typeid(FloatImageObj) )) insilmaril@314: 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@164: d.mkdir (tmpMapDir,true); 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@366: if (!saveSel) 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@366: if (!saveSel) 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@366: s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); 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@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@366: void MapEditor::saveStateComplete(const QString &comment) insilmaril@0: { insilmaril@366: // Save complete map, Undo will replace whole map insilmaril@366: saveState (CompleteMap, insilmaril@366: "", "", insilmaril@366: "", "", insilmaril@366: comment, insilmaril@366: mapCenter); insilmaril@0: } insilmaril@0: insilmaril@366: void MapEditor::saveStatePart(LinkableMapObj *undoSel, 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@366: if (undoSel) undoSelection=undoSel->getSelectString(); insilmaril@366: insilmaril@366: saveState (PartOfMap, insilmaril@366: undoSelection, "", insilmaril@366: "", "", insilmaril@366: comment, insilmaril@366: undoSel); insilmaril@105: } insilmaril@105: insilmaril@366: void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment) insilmaril@105: { insilmaril@163: // selection does not change during action, insilmaril@163: // so just save commands for undo and redo insilmaril@366: // and use current selection insilmaril@366: insilmaril@366: QString sel; insilmaril@366: if (selection) sel=selection->getSelectString(); insilmaril@366: insilmaril@366: saveState (UndoCommand, insilmaril@366: sel, uc, insilmaril@366: sel, rc, insilmaril@366: comment, insilmaril@366: NULL); insilmaril@106: } insilmaril@106: insilmaril@366: void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) insilmaril@106: { 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, "FIXME-redoCom", //FIXME insilmaril@366: comment, insilmaril@366: saveSel); insilmaril@163: } insilmaril@163: 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@366: cout << "ME::saveState() begin"<append (comment); insilmaril@294: insilmaril@131: setChanged(); insilmaril@136: insilmaril@366: int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0); insilmaril@366: int curStep=undoSet.readNumEntry ("/history/curStep",0); insilmaril@163: // Find out current undo directory insilmaril@163: if (undosAvailundosTotal) curStep=1; insilmaril@163: insilmaril@163: QString backupXML; insilmaril@366: QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); 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@366: if (!saveSel) insilmaril@366: backupXML=""; insilmaril@366: else 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@163: undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")"; insilmaril@106: } else insilmaril@106: { insilmaril@163: undoCommand="undoMap (\""+bakMapPath+"\")"; insilmaril@106: } insilmaril@163: if (!backupXML.isEmpty()) insilmaril@163: // Write XML Data to disk insilmaril@163: saveStringToDisk (QString(bakMapPath),backupXML); insilmaril@163: insilmaril@366: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); 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@366: undoSet.writeSettings(histPath); insilmaril@163: insilmaril@163: /* TODO remove after testing insilmaril@366: */ insilmaril@366: //cout << " into="<< histPath.toStdString()<findObjBySelect (s); insilmaril@129: if (dst) insilmaril@129: { insilmaril@129: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@139: { insilmaril@139: // Get number in parent insilmaril@139: x=api.parInt (ok,1); insilmaril@139: if (ok) insilmaril@163: ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x); insilmaril@139: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@129: { insilmaril@163: ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1); insilmaril@139: // Get coordinates of mainbranch insilmaril@129: x=api.parInt (ok,2); insilmaril@129: if (ok) insilmaril@129: { insilmaril@129: y=api.parInt (ok,3); insilmaril@163: if (ok) ((BranchObj*)selection)->move (x,y); insilmaril@129: } insilmaril@129: } insilmaril@129: } insilmaril@129: } insilmaril@129: } insilmaril@129: } else if (com=="setHeading") insilmaril@129: { insilmaril@129: if (api.checkParamCount(1)) insilmaril@129: { insilmaril@129: s=api.parString (ok,0); insilmaril@366: if (ok) insilmaril@366: setHeading (s); insilmaril@129: } insilmaril@143: } else if (com=="setURL") insilmaril@143: { insilmaril@143: 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@143: 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@366: if (selection && typeid(*selection) == typeid(BranchObj) ) insilmaril@366: { insilmaril@366: if (api.checkParamCount(1) ) insilmaril@366: { insilmaril@366: s=api.parString(ok,0); insilmaril@366: if (ok) insilmaril@366: { insilmaril@366: BranchObj* bo=(BranchObj*)selection; insilmaril@366: bo->activateStandardFlag(s); insilmaril@366: bo->updateFlagsToolbar(); insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@366: else if (com=="unsetFlag") insilmaril@366: { insilmaril@366: if (selection && typeid(*selection) == typeid(BranchObj) ) insilmaril@366: { insilmaril@366: if (api.checkParamCount(1) ) insilmaril@366: { insilmaril@366: s=api.parString(ok,0); insilmaril@366: if (ok) insilmaril@366: { insilmaril@366: BranchObj* bo=(BranchObj*)selection; insilmaril@366: bo->deactivateStandardFlag(s); insilmaril@366: bo->updateFlagsToolbar(); insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@106: // Internal commands, used for undo etc. insilmaril@129: else if (com==QString("undoMap")) insilmaril@139: { insilmaril@163: if (api.checkParamCount(1)) insilmaril@163: undoXML("",api.parString (ok,0)); insilmaril@139: } else if (com==QString("undoPart")) insilmaril@129: { insilmaril@163: if (api.checkParamCount(2)) insilmaril@129: { insilmaril@366: s=api.parString (ok,0); // undo selection insilmaril@366: t=api.parString (ok,1); // backup dir insilmaril@163: undoXML(s,t); insilmaril@129: } insilmaril@129: } else if (com=="select") insilmaril@366: { insilmaril@129: if (api.checkParamCount(1)) insilmaril@129: { insilmaril@129: s=api.parString(ok,0); insilmaril@129: if (ok) select (s); insilmaril@129: } insilmaril@366: } insilmaril@106: else insilmaril@163: { insilmaril@129: api.setError ("Unknown command in: "+atom); insilmaril@163: } insilmaril@129: insilmaril@129: // Any errors? insilmaril@129: if (api.error()) insilmaril@106: { insilmaril@366: // TODO Error handling insilmaril@366: qWarning("MapEditor::parseAtom: Error!"); insilmaril@366: qWarning(api.errorDesc()); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@294: void MapEditor::toggleHistoryWindow() insilmaril@294: { insilmaril@294: if (historyWindow->isVisible()) insilmaril@294: historyWindow->hide(); insilmaril@294: else insilmaril@294: 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: actionEditUndo->setEnabled (true); insilmaril@0: actionFileSave->setEnabled (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@294: historyWindow->setCaption (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@366: saveStatePart(selection,"Load map"); 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@106: // The SaveMode UndoCommand is not supported here insilmaril@106: if (savemode==UndoCommand) return 1; insilmaril@106: 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@0: actionFileSave->setEnabled(false); 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@366: if (redosAvail>0) redosAvail--; insilmaril@366: if (undosAvailundosTotal) 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@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@366: updateActions(); insilmaril@366: insilmaril@366: /* TODO remove testing insilmaril@163: */ insilmaril@163: cout << "ME::redo() end\n"; insilmaril@163: cout << " undosAvail="<reposition(); insilmaril@106: insilmaril@163: undosAvail--; insilmaril@366: curStep--; insilmaril@366: if (curStep<1) curStep=undosTotal; 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="<clear(); 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@106: QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), insilmaril@163: tr( handler.errorProtocol() )+" in "+bakMapDir ); insilmaril@106: } insilmaril@106: } else insilmaril@106: { insilmaril@106: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@159: tr("Temporary directory %1 used for undo is gone. \n" insilmaril@106: "I will create a new one, but at the moment no undo is available.\n" insilmaril@106: "Maybe you want to reload your original data.\n\n" insilmaril@159: "Sorry for any inconveniences.").arg(bakMapDir) ); insilmaril@106: makeTmpDirs(); insilmaril@106: } 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@366: saveStatePart(selection,QString("Paste to %1").arg( getName(selection))); insilmaril@166: pasteNoSave(); insilmaril@166: mapCenter->reposition(); insilmaril@166: adjustCanvasSize(); insilmaril@166: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cut() insilmaril@0: { insilmaril@366: saveStatePart(selection->getParObj(),QString("Cut %1").arg(getName(selection))); 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@366: if (selection) 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@366: selection->setRelPos (QPoint(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@366: saveStateConstSelection( insilmaril@366: "setHeading (\""+editingBO->getHeading()+"\")", 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@366: void 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@366: if (selection && insilmaril@366: (typeid(*selection) == typeid(BranchObj) || insilmaril@366: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@366: { insilmaril@366: BranchObj *bo = (BranchObj*) selection; insilmaril@366: BranchObj *newbo; insilmaril@366: newbo=addNewBranchInt (pos-2); insilmaril@366: insilmaril@366: if (newbo) insilmaril@366: { insilmaril@366: saveStateConstSelection ( insilmaril@366: QString ("delete (\"%1\")").arg(newbo->getSelectString()), insilmaril@366: QString ("addBranch (%1)").arg(pos-2), insilmaril@366: QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand insilmaril@366: insilmaril@366: LinkableMapObj *oldselection=selection; insilmaril@366: insilmaril@366: mapCenter->reposition(); insilmaril@366: adjustCanvasSize(); insilmaril@366: insilmaril@366: insilmaril@366: if (actionSettingsAutoedit->isOn() || insilmaril@366: actionSettingsAutoselectHeading->isOn() ) insilmaril@0: { insilmaril@366: selection->unselect(); insilmaril@366: selection=newbo; insilmaril@366: selection->select(); insilmaril@366: if (actionSettingsAutoedit->isOn() ) insilmaril@366: mainWindow->editHeading(); insilmaril@366: if (!actionSettingsAutoselectHeading->isOn() insilmaril@366: )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt insilmaril@366: { insilmaril@366: selection->unselect(); insilmaril@366: selection=oldselection; insilmaril@366: selection->select(); insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@366: } insilmaril@366: insilmaril@366: insilmaril@366: void MapEditor::addNewBranchHere() insilmaril@366: { insilmaril@366: if (selection && insilmaril@366: (typeid(*selection) == typeid(BranchObj) ) ) insilmaril@366: { insilmaril@366: BranchObj* bo1 = (BranchObj*) selection; insilmaril@366: saveStatePart(selection, QString("Add new branch here").arg(getName(bo1))); insilmaril@366: insilmaril@366: bool wasScrolled=false; insilmaril@366: BranchObj *newbo=NULL; insilmaril@366: BranchObj *parbo=(BranchObj*)(selection->getParObj()); insilmaril@366: if (parbo) insilmaril@366: { insilmaril@366: // add below selection insilmaril@366: newbo=parbo->insertBranch(bo1->getNum()+1); insilmaril@366: } insilmaril@0: insilmaril@0: LinkableMapObj *oldselection=selection; insilmaril@366: ((BranchObj*)selection)->moveBranchTo (newbo,-1); insilmaril@0: insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: if (actionSettingsAutoedit->isOn() || insilmaril@0: actionSettingsAutoselectHeading->isOn() ) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=newbo; insilmaril@0: selection->select(); insilmaril@0: if (actionSettingsAutoedit->isOn() ) insilmaril@366: mainWindow->editHeading(); insilmaril@0: if (!actionSettingsAutoselectHeading->isOn() insilmaril@0: && !wasScrolled) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=oldselection; insilmaril@0: selection->select(); insilmaril@0: } insilmaril@0: } insilmaril@0: } 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@139: if (selection->getDepth()>1) insilmaril@139: // Normal branch, save parent with childs insilmaril@366: saveStatePart(par,QString("Delete %1").arg(getName(bo))); insilmaril@366: // naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo)))); insilmaril@139: else insilmaril@139: // Mainbranch, save whole map insilmaril@164: // TODO Better would be to insert mainbranch again at pos insilmaril@139: // But undoCommand is missing right now insilmaril@366: saveStateComplete(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@366: saveStatePart(par, QString("Delete %1").arg(getName(fio))); 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@0: void MapEditor::setColor(QColor c) insilmaril@0: { insilmaril@0: actColor=c; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectBackgroundColor() insilmaril@0: { insilmaril@0: QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: setBackgroundColor( col ); insilmaril@366: //TODO undocomm insilmaril@366: saveStateComplete(QString("Set background color of map to %1").arg(col.name())); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setBackgroundColor(QColor c) insilmaril@0: { insilmaril@0: mapCanvas->setBackgroundColor (c); insilmaril@0: } insilmaril@0: insilmaril@0: QColor MapEditor::pickColor() 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@0: actColor=bo->getColor(); insilmaril@0: } insilmaril@0: } insilmaril@0: return actColor; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::colorItem() 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@366: saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand insilmaril@243: bo->setColor(actColor); // color branch insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::colorBranch() 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@366: saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand insilmaril@243: bo->setColorChilds(actColor); // 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@366: saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f), insilmaril@366: QString("%1 (\"%2\")").arg(r).arg(f), insilmaril@366: QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); insilmaril@366: bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn()); 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@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: { insilmaril@0: // user entered something and pressed OK insilmaril@366: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text)); insilmaril@143: bo->setURL (text); insilmaril@0: updateActions(); insilmaril@0: } 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@0: { insilmaril@163: BranchObj *bo=(BranchObj*)selection; insilmaril@366: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo))); insilmaril@143: bo->setURL (bo->getHeading()); insilmaril@0: updateActions(); insilmaril@0: } 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@366: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo))); insilmaril@143: bo->setURL (url); insilmaril@0: updateActions(); 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@366: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo))); 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@366: saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())); 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@366: saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo))); 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@243: void MapEditor::toggleHideExport() insilmaril@243: { insilmaril@243: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@250: typeid(*selection) == typeid(MapCenterObj)) || insilmaril@250: (typeid(*selection)==typeid(FloatImageObj)) insilmaril@243: ) insilmaril@243: { insilmaril@250: OrnamentedObj *oo=(OrnamentedObj*)selection; insilmaril@294: QString s; insilmaril@250: if (oo->hideInExport()) insilmaril@294: { insilmaril@250: oo->setHideInExport(false); insilmaril@294: s="Unset"; insilmaril@294: } insilmaril@250: else insilmaril@294: { insilmaril@250: oo->setHideInExport(true); insilmaril@294: s="Set"; insilmaril@294: } insilmaril@366: saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand insilmaril@250: actionEditToggleHideExport->setOn (oo->hideInExport()); insilmaril@243: updateActions(); insilmaril@243: mapCenter->reposition(); insilmaril@243: adjustCanvasSize(); insilmaril@243: canvas()->update(); insilmaril@243: } insilmaril@243: } insilmaril@243: 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@294: void MapEditor::removeBranchKeepChilds() 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@294: QString s=QString("Remove %1 and keep its childs").arg(getName(bo)); insilmaril@139: if (bo->getDepth()==1) insilmaril@366: saveStateComplete(s); insilmaril@139: else insilmaril@366: saveStatePart(selection->getParObj(),s); // TODO undoCommand insilmaril@139: QString sel=selection->getSelectString(); insilmaril@98: unselect(); insilmaril@98: par->removeBranchHere(bo); insilmaril@98: mapCenter->reposition(); insilmaril@98: select (sel); insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@98: void MapEditor::removeChilds() insilmaril@98: { insilmaril@98: if (selection && (typeid(*selection) == typeid(BranchObj) )) insilmaril@98: { insilmaril@366: saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection))); 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@366: saveStateComplete("Edit info about map"); //TODO undoCommand insilmaril@0: mapCenter->setAuthor (dia.getAuthor() ); insilmaril@0: mapCenter->setComment (dia.getComment() ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::updateActions() insilmaril@0: { insilmaril@98: QAction *a; insilmaril@0: if (getLinkColorHint()==HeadingColor) insilmaril@0: actionFormatLinkColorHint->setOn(true); insilmaril@0: else insilmaril@0: actionFormatLinkColorHint->setOn(false); insilmaril@0: insilmaril@0: switch (linkstyle) insilmaril@0: { insilmaril@0: case StyleLine: insilmaril@0: actionFormatLinkStyleLine->setOn(true); insilmaril@0: break; insilmaril@0: case StyleParabel: insilmaril@0: actionFormatLinkStyleParabel->setOn(true); insilmaril@0: break; insilmaril@0: case StylePolyLine: insilmaril@0: actionFormatLinkStylePolyLine->setOn(true); insilmaril@0: break; insilmaril@0: case StylePolyParabel: insilmaril@0: actionFormatLinkStylePolyParabel->setOn(true); insilmaril@0: break; insilmaril@0: default: insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: QPixmap pix( 16, 16 ); insilmaril@0: pix.fill( mapCanvas->backgroundColor() ); insilmaril@0: actionFormatBackColor->setIconSet( pix ); insilmaril@97: pix.fill( defLinkColor ); insilmaril@0: actionFormatLinkColor->setIconSet( pix ); insilmaril@0: insilmaril@0: actionFileSave->setEnabled( mapUnsaved ); insilmaril@366: if (undoSet.readNumEntry("/history/undosAvail",0)>0) insilmaril@366: actionEditUndo->setEnabled( true); insilmaril@366: else insilmaril@366: actionEditUndo->setEnabled( false); insilmaril@366: insilmaril@366: if (undoSet.readNumEntry("/history/redosAvail",0)>0) insilmaril@366: actionEditRedo->setEnabled( true); insilmaril@366: else insilmaril@366: actionEditRedo->setEnabled( false); 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@89: // Take care of links insilmaril@95: if (bo->countXLinks()==0) insilmaril@89: { insilmaril@366: branchXLinksContextMenuEdit->clear(); insilmaril@366: branchXLinksContextMenuFollow->clear(); insilmaril@89: } else insilmaril@89: { insilmaril@89: BranchObj *bot; insilmaril@89: QString s; insilmaril@366: branchXLinksContextMenuEdit->clear(); insilmaril@366: branchXLinksContextMenuFollow->clear(); insilmaril@95: for (int i=0; i<=bo->countXLinks();i++) insilmaril@89: { insilmaril@95: bot=bo->XLinkTargetAt(i); insilmaril@89: if (bot) insilmaril@89: { insilmaril@89: s=bot->getHeading(); insilmaril@89: if (s.length()>25) insilmaril@89: s=s.left(25)+"..."; insilmaril@366: branchXLinksContextMenuFollow->addAction (s); insilmaril@366: branchXLinksContextMenuEdit->addAction (s); insilmaril@89: } insilmaril@89: } insilmaril@89: } insilmaril@89: insilmaril@0: standardFlagsDefault->setEnabled (true); insilmaril@0: insilmaril@250: actionEditToggleScroll->setEnabled (true); insilmaril@250: if ( bo->isScrolled() ) insilmaril@250: actionEditToggleScroll->setOn(true); insilmaril@250: else insilmaril@250: actionEditToggleScroll->setOn(false); insilmaril@250: insilmaril@89: if ( bo->getURL().isEmpty() ) insilmaril@266: { insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@266: actionEditOpenURLTab->setEnabled (false); insilmaril@266: } insilmaril@0: else insilmaril@266: { insilmaril@0: actionEditOpenURL->setEnabled (true); insilmaril@266: actionEditOpenURLTab->setEnabled (true); insilmaril@266: } insilmaril@89: if ( bo->getVymLink().isEmpty() ) insilmaril@0: { insilmaril@0: actionEditOpenVymLink->setEnabled (false); insilmaril@0: actionEditDeleteVymLink->setEnabled (false); insilmaril@0: } else insilmaril@0: { insilmaril@0: actionEditOpenVymLink->setEnabled (true); insilmaril@0: actionEditDeleteVymLink->setEnabled (true); insilmaril@0: } insilmaril@314: insilmaril@314: if (bo->canMoveBranchUp()) insilmaril@314: actionEditMoveUp->setEnabled (true); insilmaril@314: else insilmaril@314: actionEditMoveUp->setEnabled (false); insilmaril@314: if (bo->canMoveBranchDown()) insilmaril@314: actionEditMoveDown->setEnabled (true); insilmaril@314: else insilmaril@314: actionEditMoveDown->setEnabled (false); insilmaril@314: insilmaril@314: insilmaril@243: actionEditToggleHideExport->setEnabled (true); insilmaril@243: actionEditToggleHideExport->setOn (bo->hideInExport() ); insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (true); insilmaril@0: actionEditCut->setEnabled (true); insilmaril@166: if (!clipboardEmpty) insilmaril@119: actionEditPaste->setEnabled (true); insilmaril@119: else insilmaril@119: actionEditPaste->setEnabled (false); insilmaril@119: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@119: a->setEnabled(true); insilmaril@0: actionEditDelete->setEnabled (true); insilmaril@0: switch (selection->getFrameType()) insilmaril@0: { insilmaril@0: case NoFrame: insilmaril@0: actionFormatFrameNone->setOn(true); insilmaril@0: break; insilmaril@0: case Rectangle: insilmaril@0: actionFormatFrameRectangle->setOn(true); insilmaril@0: break; insilmaril@0: default: insilmaril@0: break; insilmaril@0: } insilmaril@175: actionFormatIncludeImagesVer->setOn insilmaril@175: ( ((BranchObj*)selection)->getIncludeImagesVer()); insilmaril@175: actionFormatIncludeImagesHor->setOn insilmaril@175: ( ((BranchObj*)selection)->getIncludeImagesHor()); insilmaril@160: actionFormatHideLinkUnselected->setOn insilmaril@175: (selection->getHideLinkUnselected()); insilmaril@0: } insilmaril@0: if ( (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@0: { insilmaril@250: FloatObj *fo=(FloatImageObj*)selection; insilmaril@366: //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false); insilmaril@0: insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@0: actionEditOpenVymLink->setEnabled (false); insilmaril@0: actionEditDeleteVymLink->setEnabled (false); insilmaril@250: actionEditToggleHideExport->setEnabled (true); insilmaril@250: actionEditToggleHideExport->setOn (fo->hideInExport() ); insilmaril@250: insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (true); insilmaril@0: actionEditCut->setEnabled (true); insilmaril@243: actionEditPaste->setEnabled (false); insilmaril@98: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@98: a->setEnabled(false); insilmaril@0: actionEditDelete->setEnabled (true); insilmaril@160: actionFormatHideLinkUnselected->setOn insilmaril@160: ( selection->getHideLinkUnselected()); insilmaril@314: actionEditMoveUp->setEnabled (false); insilmaril@314: actionEditMoveDown->setEnabled (false); insilmaril@0: } insilmaril@0: insilmaril@0: } else insilmaril@0: { insilmaril@366: //FIXME do this in mainwindow standardFlagsDefault->setEnabled (false); insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (false); insilmaril@0: actionEditCut->setEnabled (false); insilmaril@0: actionEditPaste->setEnabled (false); insilmaril@98: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@98: a->setEnabled(false); insilmaril@98: insilmaril@314: actionEditToggleScroll->setEnabled (false); insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@0: actionEditOpenVymLink->setEnabled (false); insilmaril@0: actionEditDeleteVymLink->setEnabled (false); insilmaril@0: actionEditHeading2URL->setEnabled (false); insilmaril@0: actionEditDelete->setEnabled (false); insilmaril@314: actionEditMoveUp->setEnabled (false); insilmaril@314: actionEditMoveDown->setEnabled (false); insilmaril@314: actionEditToggleHideExport->setEnabled (false); insilmaril@0: } 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@0: void MapEditor::setLinkStyle (LinkStyle ls) insilmaril@0: { insilmaril@0: linkstyle=ls; insilmaril@0: insilmaril@366: saveStateComplete("Set link style"); // TODO undoCommand 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@0: LinkStyle MapEditor::getLinkStyle () insilmaril@0: { insilmaril@0: return linkstyle; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setLinkColor(QColor c) insilmaril@0: { insilmaril@97: defLinkColor=c; insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setLinkColorHint() insilmaril@0: { insilmaril@0: // called from setLinkColorHint(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@0: void MapEditor::setLinkColorHint(LinkColorHint lch) insilmaril@0: { insilmaril@0: linkcolorhint=lch; insilmaril@0: setLinkColorHint(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::toggleLinkColorHint() 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@0: LinkColorHint MapEditor::getLinkColorHint() insilmaril@0: { insilmaril@0: return linkcolorhint; insilmaril@0: } insilmaril@0: insilmaril@0: QColor MapEditor::getDefLinkColor() insilmaril@0: { insilmaril@97: return defLinkColor; insilmaril@97: } insilmaril@97: insilmaril@97: void MapEditor::setDefXLinkColor(QColor col) insilmaril@97: { insilmaril@97: defXLinkColor=col; insilmaril@97: } insilmaril@97: insilmaril@97: QColor MapEditor::getDefXLinkColor() insilmaril@97: { insilmaril@97: return defXLinkColor; insilmaril@97: } insilmaril@97: insilmaril@97: void MapEditor::setDefXLinkWidth (int w) insilmaril@97: { insilmaril@97: defXLinkWidth=w; insilmaril@97: } insilmaril@97: insilmaril@97: int MapEditor::getDefXLinkWidth() insilmaril@97: { insilmaril@97: return defXLinkWidth; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLinkColor() insilmaril@0: { insilmaril@97: QColor col = QColorDialog::getColor( defLinkColor, this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: setLinkColor( col ); insilmaril@366: saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand 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@294: QString s; insilmaril@294: if (bo->isScrolled()) insilmaril@294: s="Unscroll"; insilmaril@294: else insilmaril@294: s="Scroll"; insilmaril@366: saveStatePart(selection, QString ("%1 %2").arg(s).arg(getName(bo))); 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: saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection))); 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@185: while( it != flist.end() ) insilmaril@185: { insilmaril@185: fn = *it; insilmaril@185: bo->addFloatImage(); insilmaril@185: // TODO check if load was successful insilmaril@185: bo->getLastFloatImage()->load(*it); 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@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@366: fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) ); insilmaril@0: } 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@366: qDebug ("ko."); //FIXME Huh? 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@97: setDefXLinkColor (xlo->getColor() ); insilmaril@97: setDefXLinkWidth (xlo->getWidth() ); insilmaril@97: } insilmaril@97: if (dia.deleteXLink()) insilmaril@163: ((BranchObj*)selection)->deleteXLinkAt(i); insilmaril@366: saveStateComplete("Edit xLink"); //TODO 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@366: /* insilmaril@366: bool ok; insilmaril@366: QString text = QInputDialog::getText( insilmaril@366: this, insilmaril@366: tr("QInputDialog::getText()"), insilmaril@366: tr("User name:"), QLineEdit::Normal, insilmaril@366: QDir::home().dirName(), &ok, Qt::FramelessWindowHint); insilmaril@366: */ insilmaril@366: insilmaril@366: QDialog *d =new QDialog(NULL); insilmaril@366: QLineEdit *le=new QLineEdit (d); insilmaril@366: // d->setModal (true); insilmaril@366: d->setWindowFlags (Qt::FramelessWindowHint); insilmaril@366: le->setFocus(); insilmaril@366: le->setText ("Foo"); insilmaril@366: le->selectAll(); insilmaril@366: connect (le, SIGNAL (returnPressed()), d, SLOT (accept())); insilmaril@366: d->exec(); insilmaril@366: qWarning( le->text()); insilmaril@336: return; insilmaril@366: insilmaril@366: insilmaril@366: insilmaril@366: /* insilmaril@314: WarningDialog dia; insilmaril@314: dia.setCancelButton (true); insilmaril@314: dia.setText("This is a longer \nWarning"); insilmaril@314: dia.setCaption("Warning: Flux problem"); insilmaril@366: dia.setShowAgainName("/warnings/mapeditor"); insilmaril@366: dia.setWindowFlags (Qt::FramelessWindowHint); insilmaril@314: if (dia.exec()==QDialog::Accepted) insilmaril@314: cout << "accepted!\n"; insilmaril@314: else insilmaril@314: cout << "canceled!\n"; insilmaril@301: return; insilmaril@366: */ insilmaril@366: insilmaril@366: /* Hide hidden stuff temporary, maybe add this as regular function somewhere insilmaril@260: if (hidemode==HideNone) insilmaril@185: { insilmaril@260: setHideTmpMode (HideExport); insilmaril@260: mapCenter->calcBBoxSizeWithChilds(); insilmaril@260: QRect totalBBox=mapCenter->getTotalBBox(); insilmaril@260: QRect mapRect=totalBBox; insilmaril@260: QCanvasRectangle *frame=NULL; insilmaril@260: insilmaril@260: cout << " map has =("<setBrush (QColor(white)); insilmaril@260: frame->setPen (QColor(black)); insilmaril@260: frame->setZ(0); insilmaril@260: frame->show(); insilmaril@260: } insilmaril@260: else insilmaril@260: { insilmaril@260: setHideTmpMode (HideNone); insilmaril@260: } insilmaril@260: cout <<" hidemode="< (selection); insilmaril@98: QPoint p; insilmaril@98: if (selection->getOrientation() == OrientLeftOfCenter) insilmaril@98: p= worldMatrix().map(QPoint (lmo->x(),lmo->y())); insilmaril@98: else insilmaril@98: p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height())); insilmaril@98: ensureVisible (p.x(), p.y() ); insilmaril@98: } insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::updateViewCenter() insilmaril@0: { insilmaril@0: // Update movingCenter, so that we can zoom comfortably later insilmaril@0: QRect rc = QRect( contentsX(), contentsY(), insilmaril@0: visibleWidth(), visibleHeight() ); insilmaril@0: QRect canvasRect = inverseWorldMatrix().mapRect(rc); insilmaril@0: movingCenter.setX((canvasRect.right() + canvasRect.left())/2); insilmaril@0: movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e ) insilmaril@0: { insilmaril@0: // Lineedits are already closed by preceding insilmaril@0: // mouseEvent, we don't need to close here. insilmaril@0: insilmaril@0: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: insilmaril@0: if (lmo) insilmaril@0: { // MapObj was found insilmaril@0: if (selection != lmo) insilmaril@0: { insilmaril@0: // select the MapObj insilmaril@0: if (selection) selection->unselect(); insilmaril@0: selection=lmo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: // Context Menu insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection)==typeid(BranchObj) || insilmaril@0: typeid(*selection)==typeid(MapCenterObj) ) insilmaril@0: { insilmaril@0: // Context Menu on branch or mapcenter insilmaril@0: updateActions(); insilmaril@0: branchContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@0: if (typeid(*selection)==typeid(FloatImageObj)) insilmaril@0: { insilmaril@0: // Context Menu on floatimage insilmaril@0: updateActions(); insilmaril@0: floatimageContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { // No MapObj found, we are on the Canvas itself insilmaril@0: // Context Menu on Canvas insilmaril@0: updateActions(); insilmaril@0: canvasContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@329: e->accept(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMousePressEvent(QMouseEvent* e) insilmaril@0: { insilmaril@329: // Ignore right clicks, these will go to context menus insilmaril@366: if (e->button() == Qt::RightButton ) insilmaril@329: { insilmaril@329: e->ignore(); insilmaril@329: return; insilmaril@329: } insilmaril@329: insilmaril@0: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: insilmaril@329: e->accept(); insilmaril@329: insilmaril@267: //Take care of clickdesystem flags _or_ modifier modes insilmaril@267: // insilmaril@267: if (lmo && (typeid(*lmo)==typeid(BranchObj) || insilmaril@267: typeid(*lmo)==typeid(MapCenterObj) )) insilmaril@267: { insilmaril@267: QString foname=((BranchObj*)lmo)->getSystemFlagName(p); insilmaril@267: if (!foname.isEmpty()) insilmaril@267: { insilmaril@267: // systemFlag clicked insilmaril@366: selectInt (lmo); insilmaril@267: if (foname=="url") insilmaril@267: { insilmaril@366: if (e->state() & Qt::ControlModifier) insilmaril@267: mainWindow->editOpenURLTab(); insilmaril@267: else insilmaril@267: mainWindow->editOpenURL(); insilmaril@267: } insilmaril@267: else if (foname=="vymLink") insilmaril@267: { insilmaril@267: mainWindow->editOpenVymLink(); insilmaril@267: // tabWidget may change, better return now insilmaril@267: // before segfaulting... insilmaril@267: } else if (foname=="note") insilmaril@267: mainWindow->windowToggleNoteEditor(); insilmaril@267: else if (foname=="hideInExport") insilmaril@267: toggleHideExport(); insilmaril@267: return; insilmaril@267: } insilmaril@267: } insilmaril@267: // No system flag clicked, take care of modmodes insilmaril@267: insilmaril@83: // Special case: CTRL is pressed insilmaril@366: if (e->state() & Qt::ControlModifier) insilmaril@0: { insilmaril@89: if (actionModModeColor->isOn()) insilmaril@83: { insilmaril@83: pickingColor=true; insilmaril@83: setCursor (pickColorCursor); insilmaril@83: return; insilmaril@83: } insilmaril@89: if (actionModModeLink->isOn()) insilmaril@83: { insilmaril@90: BranchObj *bo_begin=NULL; insilmaril@90: if (lmo) insilmaril@90: bo_begin=(BranchObj*)(lmo); insilmaril@90: else insilmaril@90: if (selection && insilmaril@90: ((typeid(*selection) == typeid(BranchObj)) || insilmaril@90: (typeid(*selection) == typeid(MapCenterObj))) ) insilmaril@163: bo_begin=(BranchObj*)selection; insilmaril@90: if (bo_begin) insilmaril@83: { insilmaril@83: drawingLink=true; insilmaril@90: linkingObj_src=bo_begin; insilmaril@95: tmpXLink=new XLinkObj (mapCanvas); insilmaril@95: tmpXLink->setBegin (bo_begin); insilmaril@95: tmpXLink->setEnd (p); insilmaril@97: tmpXLink->setColor(defXLinkColor); insilmaril@97: tmpXLink->setWidth(defXLinkWidth); insilmaril@95: tmpXLink->updateXLink(); insilmaril@95: tmpXLink->setVisibility (true); insilmaril@83: return; insilmaril@89: } insilmaril@267: } insilmaril@0: } insilmaril@0: if (lmo) insilmaril@267: { insilmaril@366: selectInt (lmo); insilmaril@0: // Left Button Move Branches insilmaril@366: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@129: movingObj_start.setX( p.x() - selection->x() ); insilmaril@129: movingObj_start.setY( p.y() - selection->y() ); insilmaril@129: movingObj_orgPos.setX (lmo->x() ); insilmaril@129: movingObj_orgPos.setY (lmo->y() ); insilmaril@366: movingObj_orgRelPos=lmo->getRelPos(); insilmaril@129: insilmaril@93: // If modMode==copy, then we want to "move" the _new_ object around insilmaril@93: // then we need the offset from p to the _old_ selection, because of tmp insilmaril@93: if (actionModModeCopy->isOn() && insilmaril@366: e->state() & Qt::ControlModifier) insilmaril@93: { insilmaril@93: if (typeid(*selection)==typeid(BranchObj) ) insilmaril@93: { insilmaril@93: copyingObj=true; insilmaril@163: mapCenter->addBranch ((BranchObj*)selection); insilmaril@93: unselect(); insilmaril@93: selection=mapCenter->getLastBranch(); insilmaril@93: selection->select(); insilmaril@104: mapCenter->reposition(); insilmaril@93: } insilmaril@129: } insilmaril@0: movingObj=selection; insilmaril@0: } else insilmaril@0: // Middle Button Toggle Scroll insilmaril@0: // (On Mac OS X this won't work, but we still have insilmaril@0: // a button in the toolbar) insilmaril@366: if (e->button() == Qt::MidButton ) insilmaril@0: toggleScroll(); insilmaril@0: updateActions(); insilmaril@0: } else insilmaril@0: { // No MapObj found, we are on the Canvas itself insilmaril@0: // Left Button move Pos of CanvasView insilmaril@366: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@0: movingObj=NULL; // move Content not Obj insilmaril@0: movingObj_start=e->globalPos(); insilmaril@0: movingCont_start=QPoint (contentsX(), contentsY() ); insilmaril@0: movingVec=QPoint(0,0); insilmaril@0: setCursor(handOpenCursor); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMouseMoveEvent(QMouseEvent* e) insilmaril@0: { insilmaril@83: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@83: insilmaril@0: // Move the selected MapObj insilmaril@0: if ( selection && movingObj) insilmaril@0: { insilmaril@164: // To avoid jumping of the CanvasView, only insilmaril@164: // ensureSelectionVisible, if not tmp linked insilmaril@164: if (!selection->hasParObjTmp()) insilmaril@164: ensureSelectionVisible (); insilmaril@0: insilmaril@83: // Now move the selection, but add relative position insilmaril@83: // (movingObj_start) where selection was chosen with insilmaril@83: // mousepointer. (This avoids flickering resp. jumping insilmaril@0: // of selection back to absPos) insilmaril@0: insilmaril@0: LinkableMapObj *lmosel; insilmaril@0: lmosel = dynamic_cast (selection); insilmaril@0: insilmaril@0: // Check if we could link insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel); insilmaril@0: insilmaril@0: insilmaril@0: if (typeid(*selection) == typeid(FloatImageObj)) insilmaril@0: { insilmaril@163: FloatObj *fo=(FloatObj*)selection; insilmaril@0: fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: fo->setRelPos(); insilmaril@0: fo->reposition(); insilmaril@0: insilmaril@0: // Relink float to new mapcenter or branch, if shift is pressed insilmaril@0: // Only relink, if selection really has a new parent insilmaril@366: if ( (e->state() & Qt::ShiftModifier) && lmo && insilmaril@0: ( (typeid(*lmo)==typeid(BranchObj)) || insilmaril@0: (typeid(*lmo)==typeid(MapCenterObj)) ) && insilmaril@0: ( lmo != fo->getParObj()) insilmaril@0: ) insilmaril@0: { insilmaril@0: if (typeid(*fo) == typeid(FloatImageObj)) insilmaril@0: { insilmaril@366: //TODO undocom insilmaril@366: saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) ); insilmaril@0: FloatImageObj *fio=(FloatImageObj*)(fo); insilmaril@0: ((BranchObj*)(lmo))->addFloatImage (fio); insilmaril@0: fio->unselect(); insilmaril@0: ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); insilmaril@0: fio=((BranchObj*)(lmo))->getLastFloatImage(); insilmaril@0: fio->setRelPos(); insilmaril@0: fio->reposition(); insilmaril@0: selection=(LinkableMapObj*)(fio); insilmaril@0: selection->select(); insilmaril@0: movingObj=(MapObj*)(fio); insilmaril@0: } insilmaril@0: } insilmaril@0: } else // selection != a FloatObj insilmaril@0: { insilmaril@0: if (lmosel->getDepth()==0) insilmaril@0: { insilmaril@366: if (e->state() == Qt::LeftButton && e->modifiers()==Qt::ShiftModifier) insilmaril@0: // If mapCenter is moved, move all the rest by default, too. insilmaril@0: mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: else insilmaril@0: mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: } else insilmaril@0: { insilmaril@0: if (lmosel->getDepth()==1) insilmaril@0: { insilmaril@0: // depth==1, mainbranch insilmaril@0: lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: } else insilmaril@0: { insilmaril@0: // depth>1 insilmaril@0: if (lmosel->getOrientation() == OrientLeftOfCenter) insilmaril@0: // Add width of bbox here, otherwise alignRelTo will cause jumping around insilmaril@0: lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(), insilmaril@175: p.y()-movingObj_start.y() +lmosel->getTopPad() ); insilmaril@0: else insilmaril@175: lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad()); insilmaril@0: } insilmaril@0: // reposition subbranch insilmaril@0: lmosel->reposition(); insilmaril@89: //ensureSelectionVisible(); insilmaril@0: insilmaril@0: if (lmo && (lmo!=selection) && insilmaril@0: (typeid(*lmo) == typeid(BranchObj) || insilmaril@0: (typeid(*lmo) == typeid(MapCenterObj) ) insilmaril@0: ) ) insilmaril@0: { insilmaril@366: if (e->state() & Qt::ControlModifier) insilmaril@0: { insilmaril@0: // Special case: CTRL to link below lmo insilmaril@0: lmosel->setParObjTmp (lmo,p,+1); insilmaril@0: } insilmaril@366: else if (e->state() & Qt::ShiftModifier) insilmaril@0: lmosel->setParObjTmp (lmo,p,-1); insilmaril@0: else insilmaril@0: lmosel->setParObjTmp (lmo,p,0); insilmaril@0: } else insilmaril@0: { insilmaril@93: lmosel->unsetParObjTmp(); insilmaril@0: } insilmaril@0: } // depth>0 insilmaril@0: insilmaril@0: } // no FloatImageObj insilmaril@0: insilmaril@0: canvas()->update(); insilmaril@0: return; insilmaril@0: } // selection && moving_obj insilmaril@0: insilmaril@83: // Draw a link from one branch to another insilmaril@83: if (drawingLink) insilmaril@83: { insilmaril@95: tmpXLink->setEnd (p); insilmaril@95: tmpXLink->updateXLink(); insilmaril@83: } insilmaril@83: insilmaril@0: // Move CanvasView insilmaril@83: if (!movingObj && !pickingColor &&!drawingLink) insilmaril@0: { insilmaril@0: QPoint p=e->globalPos(); insilmaril@0: movingVec.setX(-p.x() + movingObj_start.x() ); insilmaril@0: movingVec.setY(-p.y() + movingObj_start.y() ); insilmaril@0: setContentsPos( movingCont_start.x() + movingVec.x(), insilmaril@0: movingCont_start.y() + movingVec.y()); insilmaril@0: insilmaril@0: updateViewCenter(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e) insilmaril@0: { insilmaril@0: LinkableMapObj *dst; insilmaril@0: // Have we been picking color? insilmaril@0: if (pickingColor) insilmaril@0: { insilmaril@0: pickingColor=false; insilmaril@366: setCursor (Qt::ArrowCursor); insilmaril@0: // Check if we are over another branch insilmaril@0: dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL); insilmaril@0: if (dst && selection) insilmaril@0: { insilmaril@366: if (e->state() & Qt::ShiftModifier) insilmaril@0: { insilmaril@243: ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor()); insilmaril@163: ((BranchObj*)selection)->setLinkColor (); insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@243: ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor()); insilmaril@163: ((BranchObj*)selection)->setLinkColor (); insilmaril@0: } insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@83: insilmaril@83: // Have we been drawing a link? insilmaril@83: if (drawingLink) insilmaril@83: { insilmaril@83: drawingLink=false; insilmaril@83: // Check if we are over another branch insilmaril@83: dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL); insilmaril@83: if (dst && selection) insilmaril@83: { insilmaril@95: tmpXLink->setEnd ( ((BranchObj*)(dst)) ); insilmaril@95: tmpXLink->updateXLink(); insilmaril@95: tmpXLink->activate(); insilmaril@366: saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand insilmaril@83: } else insilmaril@83: { insilmaril@95: delete(tmpXLink); insilmaril@95: tmpXLink=NULL; insilmaril@83: } insilmaril@83: return; insilmaril@83: } insilmaril@83: insilmaril@0: // Have we been moving something? insilmaril@0: if ( selection && movingObj ) insilmaril@0: { insilmaril@175: // Moved FloatObj? Maybe we need to reposition insilmaril@175: if(typeid(*selection)==typeid (FloatImageObj)) insilmaril@175: { insilmaril@366: FloatImageObj *fo=(FloatImageObj*)selection; insilmaril@366: QString pold=qpointToString(movingObj_orgRelPos); insilmaril@366: QString pnow=qpointToString(fo->getRelPos()); insilmaril@366: saveStateConstSelection( insilmaril@366: "moveRel "+pold, insilmaril@366: "moveRel "+pnow, insilmaril@366: QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow)); insilmaril@366: insilmaril@175: selection->getParObj()->requestReposition(); insilmaril@175: mapCenter->reposition(); insilmaril@175: } insilmaril@175: insilmaril@0: // Check if we are over another branch, but ignore insilmaril@0: // any found LMOs, which are FloatObjs insilmaril@0: dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), insilmaril@163: ((LinkableMapObj*)selection) ); insilmaril@0: insilmaril@336: if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) insilmaril@0: dst=NULL; insilmaril@0: insilmaril@0: // Now check, if we have been moving a branch insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@0: // save the position in case we link to mapcenter insilmaril@0: QPoint savePos=QPoint (selection->x(),selection->y() ); insilmaril@0: insilmaril@0: // Reset the temporary drawn link to the original one insilmaril@163: ((LinkableMapObj*)selection)->unsetParObjTmp(); insilmaril@0: insilmaril@366: // For Redo we may need to save original selection insilmaril@366: QString preSelStr=selection->getSelectString(); insilmaril@93: insilmaril@94: copyingObj=false; insilmaril@129: if (dst ) insilmaril@93: { insilmaril@366: BranchObj* bsel=(BranchObj*)selection; insilmaril@366: BranchObj* bdst=(BranchObj*)dst; insilmaril@366: insilmaril@366: QString preParStr=(bsel->getParObj())->getSelectString(); insilmaril@366: QString preNum=QString::number (bsel->getNum(),10); insilmaril@366: QString preDstParStr; insilmaril@366: insilmaril@366: if (e->state() & Qt::ShiftModifier && dst->getParObj()) insilmaril@366: { // Link above dst insilmaril@366: preDstParStr=dst->getParObj()->getSelectString(); insilmaril@366: bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()); insilmaril@366: } else insilmaril@366: if (e->state() & Qt::ControlModifier && dst->getParObj()) insilmaril@366: { insilmaril@366: // Link below dst insilmaril@366: preDstParStr=dst->getParObj()->getSelectString(); insilmaril@366: bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1); insilmaril@366: } else insilmaril@366: { // Append to dst insilmaril@366: preDstParStr=dst->getSelectString(); insilmaril@366: bsel->moveBranchTo (bdst,-1); insilmaril@366: if (dst->getDepth()==0) bsel->move (savePos); insilmaril@366: } insilmaril@366: QString postSelStr=selection->getSelectString(); insilmaril@366: QString postNum=QString::number (bsel->getNum(),10); insilmaril@366: insilmaril@139: QString undoCom="linkBranchToPos (\""+ insilmaril@366: preParStr+ "\"," + preNum +"," + insilmaril@366: QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; insilmaril@366: insilmaril@366: QString redoCom="linkBranchToPos (\""+ insilmaril@366: preDstParStr + "\"," + postNum + "," + insilmaril@366: QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; insilmaril@366: insilmaril@366: saveState ( insilmaril@366: postSelStr,undoCom, insilmaril@366: preSelStr, redoCom, insilmaril@366: QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) ); insilmaril@163: } else insilmaril@163: if (selection->getDepth()==1) insilmaril@366: { insilmaril@366: // The select string might be different _after_ moving around. insilmaril@366: // Therefor reposition and then use string of old selection, too insilmaril@366: mapCenter->reposition(); insilmaril@366: insilmaril@366: QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() ); insilmaril@366: saveState( insilmaril@366: selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos), insilmaril@366: preSelStr, "moveRel "+ps, insilmaril@366: QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps)); insilmaril@163: insilmaril@366: } insilmaril@0: // Draw the original link, before selection was moved around insilmaril@0: mapCenter->reposition(); insilmaril@0: } insilmaril@0: // Finally resize canvas, if needed insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: movingObj=NULL; insilmaril@366: insilmaril@366: // Just make sure, that actions are still ok,e.g. the move branch up/down buttons... insilmaril@366: updateActions(); insilmaril@0: } else insilmaril@83: // maybe we moved View: set old cursor insilmaril@366: setCursor (Qt::ArrowCursor); insilmaril@83: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e) insilmaril@0: { insilmaril@366: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@0: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@0: LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: if (lmo) { // MapObj was found insilmaril@0: // First select the MapObj than edit heading insilmaril@0: if (selection) selection->unselect(); insilmaril@0: selection=lmo; insilmaril@0: selection->select(); insilmaril@366: mainWindow->editHeading(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::resizeEvent (QResizeEvent* e) insilmaril@0: { insilmaril@366: Q3CanvasView::resizeEvent( e ); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@128: void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) insilmaril@119: { insilmaril@129: insilmaril@129: // for (unsigned int i=0;event->format(i);i++) // Debug mime type insilmaril@129: // cerr << event->format(i) << endl; insilmaril@129: insilmaril@119: if (selection && insilmaril@119: (typeid(*selection) == typeid(BranchObj)) || insilmaril@119: (typeid(*selection) == typeid(MapCenterObj))) { insilmaril@119: insilmaril@119: // If QImageDrag can decode mime type insilmaril@366: if (Q3ImageDrag::canDecode(event)) { insilmaril@119: event->accept(); insilmaril@119: return; insilmaril@119: } insilmaril@119: insilmaril@128: // If image are dragged from firefox insilmaril@119: if (event->provides("application/x-moz-file-promise-url") && insilmaril@119: event->provides("application/x-moz-nativeimage")) { insilmaril@119: event->accept(true); insilmaril@119: return; insilmaril@119: } insilmaril@125: insilmaril@128: // If QUriDrag can decode mime type insilmaril@366: if (Q3UriDrag::canDecode(event)) { insilmaril@128: event->accept(); insilmaril@128: return; insilmaril@128: } insilmaril@128: insilmaril@128: // If Uri are dragged from firefox insilmaril@129: if (event->provides("_NETSCAPE_URL")){ insilmaril@128: event->accept(); insilmaril@128: return; insilmaril@128: } insilmaril@129: insilmaril@129: // If QTextDrag can decode mime type insilmaril@366: if (Q3TextDrag::canDecode(event)) { insilmaril@129: event->accept(); insilmaril@129: return; insilmaril@129: } insilmaril@129: insilmaril@119: } insilmaril@119: event->ignore(); insilmaril@119: } insilmaril@129: insilmaril@129: bool isUnicode16(const QByteArray &d) insilmaril@129: { insilmaril@164: // TODO: make more precise check for unicode 16. insilmaril@129: // Guess unicode16 if any of second bytes are zero insilmaril@129: unsigned int length = max(0,d.size()-2)/2; insilmaril@129: for (unsigned int i = 0; iprovides("image/png")) insilmaril@128: { insilmaril@128: QPixmap pix; insilmaril@366: if (Q3ImageDrag::decode(event, pix)) insilmaril@128: { insilmaril@128: addFloatImage(pix); insilmaril@128: event->accept(); insilmaril@128: update=true; insilmaril@128: } else insilmaril@128: event->ignore(); insilmaril@128: insilmaril@128: } else if (event->provides("application/x-moz-file-promise-url") && insilmaril@128: event->provides("application/x-moz-nativeimage")) insilmaril@128: { insilmaril@129: // Contains url to the img src in unicode16 insilmaril@128: QByteArray d = event->encodedData("application/x-moz-file-promise-url"); insilmaril@128: QString url = QString((const QChar*)d.data(),d.size()/2); insilmaril@128: fetchImage(url); insilmaril@128: event->accept(); insilmaril@128: update=true; insilmaril@128: } else if (event->provides ("text/uri-list")) insilmaril@128: { // Uris provided e.g. by konqueror insilmaril@366: Q3UriDrag::decode (event,uris); insilmaril@129: } else if (event->provides ("_NETSCAPE_URL")) insilmaril@128: { // Uris provided by Mozilla insilmaril@129: QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); insilmaril@129: uris.append(l[0]); insilmaril@129: heading = l[1]; insilmaril@129: } else if (event->provides("text/html")) { insilmaril@129: insilmaril@129: // Handels text mime types insilmaril@129: // Look like firefox allways handle text as unicode16 (2 bytes per char.) insilmaril@129: QByteArray d = event->encodedData("text/html"); insilmaril@129: QString text; insilmaril@129: if (isUnicode16(d)) insilmaril@129: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@129: else insilmaril@129: text = QString(d); insilmaril@129: insilmaril@129: textEditor->setText(text); insilmaril@129: insilmaril@129: event->accept(); insilmaril@129: update=true; insilmaril@129: } else if (event->provides("text/plain")) { insilmaril@129: QByteArray d = event->encodedData("text/plain"); insilmaril@129: QString text; insilmaril@129: if (isUnicode16(d)) insilmaril@129: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@129: else insilmaril@129: text = QString(d); insilmaril@129: insilmaril@129: textEditor->setText(text); insilmaril@129: insilmaril@129: event->accept(); insilmaril@129: update= true; insilmaril@128: } insilmaril@128: insilmaril@128: if (uris.count()>0) insilmaril@128: { insilmaril@128: QStringList files; insilmaril@128: QStringList urls; insilmaril@128: QString s; insilmaril@128: BranchObj *bo; insilmaril@128: for (const char* u=uris.first(); u; u=uris.next()) insilmaril@128: { insilmaril@163: bo=((BranchObj*)selection)->addBranch(); insilmaril@128: if (bo) insilmaril@128: { insilmaril@366: s=Q3UriDrag::uriToLocalFile(u); insilmaril@366: if (!s.isEmpty()) insilmaril@366: { insilmaril@129: QString file = QDir::convertSeparators(s); insilmaril@129: heading = QFileInfo(file).baseName(); insilmaril@129: files.append(file); insilmaril@129: if (file.endsWith(".vym", false)) insilmaril@129: bo->setVymLink(file); insilmaril@129: else insilmaril@129: bo->setURL(u); insilmaril@366: } else insilmaril@366: { insilmaril@129: urls.append (u); insilmaril@129: bo->setURL(u); insilmaril@129: } insilmaril@129: insilmaril@366: if (!heading.isEmpty()) insilmaril@129: bo->setHeading(heading); insilmaril@129: else insilmaril@129: bo->setHeading(u); insilmaril@128: } insilmaril@128: } insilmaril@128: update=true; insilmaril@128: } insilmaril@128: insilmaril@128: if (update) insilmaril@128: { insilmaril@294: //FIXME saveState has to be called earlier for each of the drops... insilmaril@366: saveStateComplete("Drop Event"); //TODO undo Command insilmaril@128: mapCenter->reposition(); insilmaril@128: adjustCanvasSize(); insilmaril@128: canvas()->update(); insilmaril@128: } insilmaril@128: } insilmaril@119: } insilmaril@119: insilmaril@125: void MapEditor::addFloatImage(const QPixmap &img) insilmaril@119: { insilmaril@119: if (selection && insilmaril@119: (typeid(*selection) == typeid(BranchObj)) || insilmaril@119: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@119: { insilmaril@163: BranchObj *bo=((BranchObj*)selection); insilmaril@366: saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo))); insilmaril@119: //QString fn=fd->selectedFile(); insilmaril@119: //lastImageDir=fn.left(fn.findRev ("/")); insilmaril@119: bo->addFloatImage(); insilmaril@119: // FIXME check if load was successful insilmaril@119: bo->getLastFloatImage()->load(img); insilmaril@119: //bo->getLastFloatImage()->setOriginalFilename(fn); insilmaril@119: mapCenter->reposition(); insilmaril@119: adjustCanvasSize(); insilmaril@119: canvas()->update(); insilmaril@119: } insilmaril@119: } insilmaril@119: insilmaril@119: insilmaril@366: void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/) insilmaril@119: { insilmaril@119: if (!imageBuffer) imageBuffer = new QBuffer(); insilmaril@119: if (!imageBuffer->isOpen()) { insilmaril@366: imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append); insilmaril@119: } insilmaril@119: imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a)); insilmaril@119: } insilmaril@119: insilmaril@119: insilmaril@366: void MapEditor::imageDataFinished(Q3NetworkOperation *nop) insilmaril@119: { insilmaril@366: if (nop->state()==Q3NetworkProtocol::StDone) { insilmaril@129: QPixmap img(imageBuffer->buffer()); insilmaril@129: addFloatImage(img); insilmaril@129: } insilmaril@129: insilmaril@129: if (imageBuffer) { insilmaril@129: imageBuffer->close(); insilmaril@129: if (imageBuffer) { insilmaril@129: imageBuffer->close(); insilmaril@129: delete imageBuffer; insilmaril@129: imageBuffer = 0; insilmaril@129: } insilmaril@129: } insilmaril@119: } insilmaril@119: insilmaril@129: void MapEditor::fetchImage(const QString &url) insilmaril@119: { insilmaril@119: if (urlOperator) { insilmaril@119: urlOperator->stop(); insilmaril@119: disconnect(urlOperator); insilmaril@119: delete urlOperator; insilmaril@119: } insilmaril@119: insilmaril@366: urlOperator = new Q3UrlOperator(url); insilmaril@366: connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), insilmaril@366: this, SLOT(imageDataFinished(Q3NetworkOperation*))); insilmaril@366: insilmaril@366: connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)), insilmaril@366: this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *))); insilmaril@119: urlOperator->get(); insilmaril@119: }