insilmaril@0: #include "mapeditor.h" insilmaril@0: insilmaril@0: #include insilmaril@9: #include insilmaril@0: #include insilmaril@0: #include insilmaril@2: #include insilmaril@0: #include insilmaril@2: #include insilmaril@9: #include insilmaril@2: #include insilmaril@9: #include insilmaril@9: #include insilmaril@9: #include insilmaril@9: #include insilmaril@0: #include insilmaril@2: #include insilmaril@2: #include insilmaril@2: #include insilmaril@9: #include insilmaril@2: //Added by qt3to4: insilmaril@2: #include insilmaril@2: #include insilmaril@2: #include insilmaril@2: #include insilmaril@2: #include insilmaril@2: #include insilmaril@2: #include insilmaril@2: #include insilmaril@3: #include insilmaril@2: #include insilmaril@0: insilmaril@0: #include insilmaril@2: #include insilmaril@0: #include insilmaril@0: insilmaril@0: #include "version.h" insilmaril@0: insilmaril@2: #include "api.h" insilmaril@2: #include "editxlinkdialog.h" insilmaril@2: #include "exports.h" insilmaril@2: #include "extrainfodialog.h" insilmaril@2: #include "file.h" insilmaril@2: #include "linkablemapobj.h" insilmaril@2: #include "mainwindow.h" insilmaril@2: #include "misc.h" insilmaril@2: #include "texteditor.h" insilmaril@2: #include "warningdialog.h" insilmaril@0: #include "xml.h" insilmaril@2: insilmaril@0: insilmaril@0: extern TextEditor *textEditor; insilmaril@0: extern int statusbarTime; insilmaril@0: extern Main *mainWindow; insilmaril@2: extern QString tmpVymDir; insilmaril@2: extern QString clipboardDir; insilmaril@2: extern bool clipboardEmpty; insilmaril@0: extern FlagRowObj *systemFlagsDefault; insilmaril@0: extern FlagRowObj *standardFlagsDefault; insilmaril@2: insilmaril@2: extern Q3PtrList actionListBranches; insilmaril@0: insilmaril@0: extern QAction *actionFileSave; insilmaril@0: extern QAction *actionEditUndo; insilmaril@16: 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@2: extern QAction *actionEditOpenURLTab; insilmaril@0: extern QAction *actionEditURL; insilmaril@0: extern QAction *actionEditHeading2URL; insilmaril@0: extern QAction *actionEditBugzilla2URL; insilmaril@2: extern QAction *actionEditFATE2URL; insilmaril@0: extern QAction *actionEditOpenVymLink; insilmaril@0: extern QAction *actionEditVymLink; insilmaril@0: extern QAction *actionEditDeleteVymLink; insilmaril@2: 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@2: extern QAction *actionEditRemoveBranchHere; insilmaril@2: 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@3: extern QActionGroup* actionGroupModModes; insilmaril@2: extern QAction* actionModModeColor; insilmaril@2: extern QAction* actionModModeLink; insilmaril@2: extern QAction* actionModModeCopy; insilmaril@2: insilmaril@3: extern QActionGroup *actionGroupFormatFrameTypes; insilmaril@0: extern QAction *actionFormatFrameNone; insilmaril@0: extern QAction *actionFormatFrameRectangle; insilmaril@0: insilmaril@3: extern QActionGroup *actionGroupFormatLinkStyles; insilmaril@2: extern QAction *actionFormatIncludeImagesVer; insilmaril@2: extern QAction *actionFormatIncludeImagesHor; insilmaril@2: 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@2: extern QAction *actionSettingsUseFlagGroups; insilmaril@2: insilmaril@4: extern QMenu* branchContextMenu; insilmaril@4: extern QMenu* branchAddContextMenu; insilmaril@4: extern QMenu* branchRemoveContextMenu; insilmaril@17: extern QMenu* branchLinksContextMenu; insilmaril@17: extern QMenu* branchXLinksContextMenuEdit; insilmaril@17: extern QMenu* branchXLinksContextMenuFollow; insilmaril@4: extern QMenu* floatimageContextMenu; insilmaril@4: extern QMenu* saveImageFormatMenu; insilmaril@4: extern QMenu* canvasContextMenu; insilmaril@4: extern QMenu* lastMapsMenu; insilmaril@4: extern QMenu* importMenu; insilmaril@4: extern QMenu* exportMenu; insilmaril@4: insilmaril@0: insilmaril@0: extern Settings settings; insilmaril@4: extern ImageIO imageIO; insilmaril@0: insilmaril@2: extern QString iconPath; insilmaril@2: extern QDir vymBaseDir; insilmaril@4: extern QDir lastImageDir; insilmaril@2: insilmaril@2: int MapEditor::mapNum=0; // make instance insilmaril@0: insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: MapEditor::MapEditor( insilmaril@2: QWidget* parent, bool interactive, const char* name, Qt::WFlags f) : insilmaril@2: Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0) insilmaril@0: { insilmaril@0: //cout << "Constructor ME "<setAcceptDrops(true); insilmaril@2: insilmaril@13: mapCanvas = new Q3Canvas(width(),height()); insilmaril@0: mapCanvas->setAdvancePeriod(30); insilmaril@2: mapCanvas->setBackgroundColor (Qt::white); insilmaril@0: insilmaril@0: setCanvas (mapCanvas); insilmaril@0: insilmaril@2: // Always show scroll bars (automatic would flicker sometimes) insilmaril@2: setVScrollBarMode ( Q3ScrollView::AlwaysOn ); insilmaril@2: setHScrollBarMode ( Q3ScrollView::AlwaysOn ); insilmaril@2: insilmaril@0: mapCenter = new MapCenterObj(mapCanvas); insilmaril@0: mapCenter->setVisibility (true); insilmaril@0: mapCenter->setMapEditor (this); insilmaril@2: mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map")); insilmaril@2: mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2); insilmaril@0: insilmaril@0: printer=NULL; insilmaril@0: insilmaril@2: actColor=Qt::black; setColor (actColor); insilmaril@2: defLinkColor=QColor (0,0,255); insilmaril@2: defXLinkColor=QColor (180,180,180); insilmaril@0: linkcolorhint=DefaultColor; insilmaril@0: linkstyle=StylePolyParabel; insilmaril@0: insilmaril@18: // Create bitmap cursors, platform dependant insilmaril@0: #if defined(Q_OS_MACX) insilmaril@18: handOpenCursor=QCursor ( QPixmap(iconPath+"cursorhandopen16.png"),1,1 ); insilmaril@2: pickColorCursor=QCursor ( QPixmap (iconPath+"cursorcolorpicker16.png"), 1,15 ); insilmaril@0: #else insilmaril@18: handOpenCursor=QCursor (QPixmap(iconPath+"cursorhandopen.png"),1,1); insilmaril@2: pickColorCursor=QCursor ( QPixmap(iconPath+"cursorcolorpicker.png"), 5,27 ); insilmaril@0: #endif insilmaril@0: insilmaril@0: pickingColor=false; insilmaril@2: drawingLink=false; insilmaril@2: copyingObj=false; insilmaril@0: insilmaril@0: editingBO=NULL; insilmaril@0: selection=NULL; insilmaril@0: selectionLast=NULL; insilmaril@0: movingObj=NULL; insilmaril@0: insilmaril@16: xelection.setMapCenter (mapCenter); insilmaril@16: insilmaril@2: defXLinkWidth=1; insilmaril@2: defXLinkColor=QColor (230,230,230); insilmaril@2: insilmaril@0: mapChanged=false; insilmaril@0: mapDefault=true; insilmaril@0: mapUnsaved=false; insilmaril@0: insilmaril@0: zipped=true; insilmaril@0: filePath=""; insilmaril@2: fileName=tr("unnamed"); insilmaril@0: mapName=""; insilmaril@0: insilmaril@13: undosTotal=settings.readNumEntry("/mapeditor/undoLevels",50); insilmaril@2: 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@2: blockReposition=false; insilmaril@2: blockSaveState=false; insilmaril@2: insilmaril@2: hidemode=HideNone; insilmaril@2: 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@2: // For testing purposes create history window insilmaril@2: historyWindow = new ShowTextDialog (this); insilmaril@2: historyWindow->setCaption (fileName); insilmaril@2: insilmaril@0: mapCenter->reposition(); // for positioning heading insilmaril@16: insilmaril@16: insilmaril@0: } insilmaril@0: insilmaril@0: MapEditor::~MapEditor() insilmaril@0: { insilmaril@2: if (imageBuffer) delete imageBuffer; insilmaril@2: if (urlOperator) { insilmaril@2: urlOperator->stop(); insilmaril@2: delete urlOperator; insilmaril@2: } insilmaril@2: insilmaril@0: //cout <<"Destructor MapEditor\n"; insilmaril@0: insilmaril@0: // Save Settings insilmaril@13: //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@2: 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@2: // 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@2: bool MapEditor::isRepositionBlocked() insilmaril@0: { insilmaril@2: return blockReposition; insilmaril@2: } insilmaril@2: insilmaril@2: QString MapEditor::getName (LinkableMapObj *lmo) insilmaril@2: { insilmaril@2: QString s; insilmaril@2: if (!lmo) return QString("Error: NULL has no name!"); insilmaril@2: insilmaril@2: if ((typeid(*lmo) == typeid(BranchObj) || insilmaril@2: typeid(*lmo) == typeid(MapCenterObj))) insilmaril@2: { insilmaril@2: insilmaril@2: s=(((BranchObj*)lmo)->getHeading()); insilmaril@2: if (s=="") s="unnamed"; insilmaril@2: return QString("branch (%1)").arg(s); insilmaril@2: } insilmaril@2: if ((typeid(*lmo) == typeid(FloatImageObj) )) insilmaril@2: return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); insilmaril@2: return QString("Unknown type has no name!"); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::makeTmpDirs() insilmaril@0: { insilmaril@0: // Create unique temporary directories insilmaril@16: tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum)); insilmaril@16: histPath=QDir::convertSeparators (tmpMapDir+"/history"); insilmaril@2: QDir d; insilmaril@2: d.mkdir (tmpMapDir,true); insilmaril@0: } insilmaril@0: insilmaril@17: QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel) insilmaril@0: { insilmaril@2: // 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@2: QString mapAttr=attribut("version",__VYM_VERSION); insilmaril@17: 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@2: attribut("linkColor", defLinkColor.name() ) + insilmaril@2: attribut("defXLinkColor", defXLinkColor.name() ) + insilmaril@2: 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@2: // Reset the counters before saving insilmaril@2: FloatImageObj (mapCanvas).resetSaveCounter(); insilmaril@2: insilmaril@0: // Build xml recursivly insilmaril@17: if (!saveSel) insilmaril@17: // Save complete map, if saveSel not set insilmaril@0: s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset); insilmaril@0: else insilmaril@0: { insilmaril@17: if ( typeid(*saveSel) == typeid(BranchObj) ) insilmaril@17: // Save Subtree insilmaril@17: s+=((BranchObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); insilmaril@17: else if ( typeid(*saveSel) == typeid(FloatImageObj) ) insilmaril@17: // Save image insilmaril@17: s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix,offset); insilmaril@2: insilmaril@2: else if (selection && typeid(*selection)==typeid(BranchObj)) insilmaril@17: // Save selected branch is saved from mainwindow //FIXME maybe use "subtree" above? insilmaril@17: 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@17: 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@16: void MapEditor::saveStateComplete(const QString &comment) insilmaril@0: { insilmaril@17: // Save complete map, Undo will replace whole map insilmaril@17: saveState (CompleteMap, insilmaril@18: "", "", insilmaril@18: "", "", insilmaril@17: comment, insilmaril@17: mapCenter); insilmaril@0: } insilmaril@0: insilmaril@16: void MapEditor::saveStatePart(LinkableMapObj *undoSel, const QString &comment) insilmaril@0: { insilmaril@17: // save the selected part of the map, Undo will replace part of map insilmaril@18: QString undoSelection=""; insilmaril@18: if (undoSel) undoSelection=undoSel->getSelectString(); insilmaril@18: insilmaril@17: saveState (PartOfMap, insilmaril@18: undoSelection, "", insilmaril@18: "", "", insilmaril@17: comment, insilmaril@17: undoSel); insilmaril@2: } insilmaril@2: insilmaril@16: void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment) insilmaril@2: { insilmaril@2: // selection does not change during action, insilmaril@2: // so just save commands for undo and redo insilmaril@16: // and use current selection insilmaril@18: insilmaril@18: QString sel; insilmaril@18: if (selection) sel=selection->getSelectString(); insilmaril@18: insilmaril@17: saveState (UndoCommand, insilmaril@18: sel, uc, insilmaril@18: sel, rc, insilmaril@17: comment, insilmaril@17: NULL); insilmaril@2: } insilmaril@2: insilmaril@18: void MapEditor::saveStateComData(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment, LinkableMapObj *saveSel) insilmaril@2: { insilmaril@18: QString redoSelection=""; insilmaril@18: if (redoSel) redoSelection=redoSel->getSelectString(); insilmaril@18: QString undoSelection=""; insilmaril@18: if (undoSel) undoSelection=undoSel->getSelectString(); insilmaril@18: insilmaril@17: saveState (UndoCommand, insilmaril@18: undoSelection, uc, insilmaril@18: redoSelection, "FIXME-redoCom", //FIXME insilmaril@18: comment, insilmaril@18: saveSel); insilmaril@18: } insilmaril@18: insilmaril@18: void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) insilmaril@18: { insilmaril@18: // "Normal" savestate: save commands, selections and comment insilmaril@18: // so just save commands for undo and redo insilmaril@18: // and use current selection insilmaril@18: insilmaril@18: QString redoSelection=""; insilmaril@18: if (redoSel) redoSelection=redoSel->getSelectString(); insilmaril@18: QString undoSelection=""; insilmaril@18: if (undoSel) undoSelection=undoSel->getSelectString(); insilmaril@18: insilmaril@18: saveState (UndoCommand, insilmaril@18: undoSelection, uc, insilmaril@18: redoSelection, rc, insilmaril@17: comment, insilmaril@17: NULL); insilmaril@2: } insilmaril@2: insilmaril@18: void MapEditor::saveState(const QString &undoSel, const QString &uc, const QString &redoSel, const QString &rc, const QString &comment) insilmaril@17: { insilmaril@18: // "Normal" savestate: save commands, selections and comment insilmaril@18: // so just save commands for undo and redo insilmaril@18: // and use current selection insilmaril@17: saveState (UndoCommand, insilmaril@18: undoSel, uc, insilmaril@18: redoSel, rc, insilmaril@17: comment, insilmaril@18: NULL); insilmaril@17: } insilmaril@17: insilmaril@18: insilmaril@18: void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel) insilmaril@2: { insilmaril@2: // Main saveState insilmaril@2: insilmaril@2: if (blockSaveState) return; insilmaril@2: insilmaril@2: /* TODO remove after testing insilmaril@16: */ insilmaril@17: cout << "ME::saveState() begin"<append (comment); insilmaril@2: insilmaril@2: setChanged(); insilmaril@2: insilmaril@16: int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0); insilmaril@16: int curStep=undoSet.readNumEntry ("/history/curStep",0); insilmaril@2: // Find out current undo directory insilmaril@2: if (undosAvailundosTotal) curStep=1; insilmaril@2: insilmaril@2: QString backupXML; insilmaril@16: QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@2: QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml"); insilmaril@2: insilmaril@2: // Create bakMapDir if not available insilmaril@2: QDir d(bakMapDir); insilmaril@2: if (!d.exists()) insilmaril@2: makeSubDirs (bakMapDir); insilmaril@2: insilmaril@2: // Save depending on how much needs to be saved insilmaril@17: if (!saveSel) insilmaril@17: backupXML=""; insilmaril@17: else insilmaril@17: backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel); insilmaril@17: insilmaril@2: QString undoCommand=""; insilmaril@2: if (savemode==UndoCommand) insilmaril@0: { insilmaril@2: undoCommand=undoCom; insilmaril@2: } insilmaril@18: else if (savemode==PartOfMap ) insilmaril@0: { insilmaril@2: undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")"; insilmaril@2: } else insilmaril@2: { insilmaril@2: undoCommand="undoMap (\""+bakMapPath+"\")"; insilmaril@2: } insilmaril@2: if (!backupXML.isEmpty()) insilmaril@2: // Write XML Data to disk insilmaril@2: saveStringToDisk (QString(bakMapPath),backupXML); insilmaril@2: insilmaril@16: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@16: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@16: undoSet.setEntry (QString("/history/step-%1/undoCommand").arg(curStep),undoCommand); insilmaril@16: undoSet.setEntry (QString("/history/step-%1/undoSelection").arg(curStep),undoSelection); insilmaril@16: undoSet.setEntry (QString("/history/step-%1/redoCommand").arg(curStep),redoCom); insilmaril@16: undoSet.setEntry (QString("/history/step-%1/redoSelection").arg(curStep),redoSelection); insilmaril@16: undoSet.setEntry (QString("/history/step-%1/comment").arg(curStep),comment); insilmaril@16: undoSet.writeSettings(histPath); insilmaril@2: insilmaril@2: /* TODO remove after testing insilmaril@16: */ insilmaril@17: //cout << " into="<< histPath.toStdString()<findObjBySelect (s); insilmaril@2: if (dst) insilmaril@2: { insilmaril@2: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@2: { insilmaril@2: // Get number in parent insilmaril@2: x=api.parInt (ok,1); insilmaril@2: if (ok) insilmaril@2: ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x); insilmaril@2: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@2: { insilmaril@2: ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1); insilmaril@2: // Get coordinates of mainbranch insilmaril@2: x=api.parInt (ok,2); insilmaril@2: if (ok) insilmaril@2: { insilmaril@2: y=api.parInt (ok,3); insilmaril@2: if (ok) ((BranchObj*)selection)->move (x,y); insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: } else if (com=="setHeading") insilmaril@2: { insilmaril@2: if (api.checkParamCount(1)) insilmaril@2: { insilmaril@2: s=api.parString (ok,0); insilmaril@16: if (ok) insilmaril@16: setHeading (s); insilmaril@2: } insilmaril@2: } else if (com=="setURL") insilmaril@2: { insilmaril@2: if (api.checkParamCount(1)) insilmaril@2: { insilmaril@2: s=api.parString (ok,0); insilmaril@16: if (ok) setURLInt(s); insilmaril@2: } insilmaril@2: } else if (com=="setVymLink") insilmaril@2: { insilmaril@2: if (api.checkParamCount(1)) insilmaril@2: { insilmaril@2: s=api.parString (ok,0); insilmaril@16: if (ok) setVymLinkInt(s); insilmaril@2: } insilmaril@2: } insilmaril@16: else if (com=="setFlag") insilmaril@16: { insilmaril@16: if (selection && typeid(*selection) == typeid(BranchObj) ) insilmaril@16: { insilmaril@16: if (api.checkParamCount(1) ) insilmaril@16: { insilmaril@16: s=api.parString(ok,0); insilmaril@18: if (ok) insilmaril@18: { insilmaril@18: BranchObj* bo=(BranchObj*)selection; insilmaril@18: bo->activateStandardFlag(s); insilmaril@18: bo->updateFlagsToolbar(); insilmaril@18: } insilmaril@16: } insilmaril@16: } insilmaril@16: } insilmaril@16: else if (com=="unsetFlag") insilmaril@16: { insilmaril@16: if (selection && typeid(*selection) == typeid(BranchObj) ) insilmaril@16: { insilmaril@16: if (api.checkParamCount(1) ) insilmaril@16: { insilmaril@16: s=api.parString(ok,0); insilmaril@18: if (ok) insilmaril@18: { insilmaril@18: BranchObj* bo=(BranchObj*)selection; insilmaril@18: bo->deactivateStandardFlag(s); insilmaril@18: bo->updateFlagsToolbar(); insilmaril@18: } insilmaril@16: } insilmaril@16: } insilmaril@16: } insilmaril@2: // Internal commands, used for undo etc. insilmaril@2: else if (com==QString("undoMap")) insilmaril@2: { insilmaril@2: if (api.checkParamCount(1)) insilmaril@2: undoXML("",api.parString (ok,0)); insilmaril@2: } else if (com==QString("undoPart")) insilmaril@2: { insilmaril@2: if (api.checkParamCount(2)) insilmaril@2: { insilmaril@17: s=api.parString (ok,0); // undo selection insilmaril@17: t=api.parString (ok,1); // backup dir insilmaril@2: undoXML(s,t); insilmaril@2: } insilmaril@2: } else if (com=="select") insilmaril@20: { insilmaril@2: if (api.checkParamCount(1)) insilmaril@2: { insilmaril@2: s=api.parString(ok,0); insilmaril@2: if (ok) select (s); insilmaril@2: } insilmaril@20: } insilmaril@2: else insilmaril@2: { insilmaril@2: api.setError ("Unknown command in: "+atom); insilmaril@2: } insilmaril@2: insilmaril@2: // Any errors? insilmaril@2: if (api.error()) insilmaril@2: { insilmaril@17: // TODO Error handling insilmaril@2: qWarning("MapEditor::parseAtom: Error!"); insilmaril@2: qWarning(api.errorDesc()); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@2: void MapEditor::toggleHistoryWindow() insilmaril@2: { insilmaril@2: if (historyWindow->isVisible()) insilmaril@2: historyWindow->hide(); insilmaril@2: else insilmaril@2: historyWindow->show(); insilmaril@2: } insilmaril@2: 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@2: if (fname.isEmpty() || fname=="") insilmaril@2: { insilmaril@2: filePath=""; insilmaril@2: fileName=""; insilmaril@2: destPath=""; insilmaril@2: } else insilmaril@2: { insilmaril@2: filePath=fname; // becomes absolute path insilmaril@2: fileName=fname; // gets stripped of path insilmaril@2: destPath=destname; // needed for vymlinks insilmaril@2: insilmaril@2: // If fname is not an absolute path, complete it insilmaril@2: filePath=QDir(fname).absPath(); insilmaril@2: fileDir=filePath.left (1+filePath.findRev ("/")); insilmaril@2: insilmaril@2: // Set short name, too. Search from behind: insilmaril@2: int i=fileName.findRev("/"); insilmaril@2: if (i>=0) fileName=fileName.remove (0,i+1); insilmaril@2: insilmaril@2: // Forget the .vym (or .xml) for name of map insilmaril@2: mapName=fileName.left(fileName.findRev(".",-1,true) ); insilmaril@2: insilmaril@2: // Adjust history window insilmaril@2: historyWindow->setCaption (fileName); insilmaril@2: } 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@2: ErrorCode MapEditor::load (QString fname, LoadMode lmode) insilmaril@0: { insilmaril@2: 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@16: 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@2: err=aborted; insilmaril@0: } else insilmaril@0: { insilmaril@2: 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@2: handler.setInputFile (file.name()); insilmaril@0: handler.setLoadMode (lmode); insilmaril@2: blockSaveState=true; insilmaril@0: bool ok = reader.parse( source ); insilmaril@2: blockReposition=false; insilmaril@2: 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@2: return err; insilmaril@0: } insilmaril@0: insilmaril@0: int MapEditor::save (const SaveMode &savemode) insilmaril@0: { insilmaril@0: int returnCode=0; insilmaril@0: insilmaril@2: // The SaveMode UndoCommand is not supported here insilmaril@2: if (savemode==UndoCommand) return 1; insilmaril@2: 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@2: QString saveFile; insilmaril@2: if (savemode==CompleteMap || selection==NULL) insilmaril@2: saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL); insilmaril@2: else insilmaril@2: saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection); insilmaril@2: insilmaril@2: 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@13: 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@2: 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@2: QRect mapRect=totalBBox; insilmaril@2: Q3CanvasRectangle *frame=NULL; insilmaril@2: Q3CanvasText *footerFN=NULL; insilmaril@2: 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@2: mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, insilmaril@2: totalBBox.width()+20, totalBBox.height()+20); insilmaril@2: frame=new Q3CanvasRectangle (mapRect,mapCanvas); insilmaril@2: frame->setBrush (QColor(Qt::white)); insilmaril@2: frame->setPen (QColor(Qt::black)); insilmaril@0: frame->setZ(0); insilmaril@0: frame->show(); insilmaril@0: } insilmaril@2: /* TODO remove after testing insilmaril@2: QCanvasLine *l=new QCanvasLine (mapCanvas); insilmaril@2: l->setPoints (0,0,mapRect.width(),mapRect.height()); insilmaril@2: l->setPen (QPen(QColor(black), 1)); insilmaril@2: l->setZ (200); insilmaril@2: l->show(); insilmaril@2: */ insilmaril@2: insilmaril@0: if (printFooter) insilmaril@0: { insilmaril@0: // Print footer below map insilmaril@0: QFont font; insilmaril@0: font.setPointSize(10); insilmaril@2: 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@2: 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@2: 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@2: insilmaril@2: // Save settings in vymrc insilmaril@13: 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@2: void MapEditor::setHideTmpMode (HideTmpMode mode) insilmaril@2: { insilmaril@2: hidemode=mode; insilmaril@2: mapCenter->setHideTmp (hidemode); insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: canvas()->update(); insilmaril@2: } insilmaril@2: insilmaril@2: HideTmpMode MapEditor::getHideTmpMode() insilmaril@2: { insilmaril@2: return hidemode; insilmaril@2: } insilmaril@2: insilmaril@0: void MapEditor::exportImage(QString fn) insilmaril@0: { insilmaril@2: setExportMode (true); insilmaril@0: QPixmap pix (getPixmap()); insilmaril@0: pix.save(fn, "PNG"); insilmaril@2: setExportMode (false); insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::setExportMode (bool b) insilmaril@2: { insilmaril@2: // should be called before and after exports insilmaril@2: // depending on the settings insilmaril@13: if (b && settings.value("/export/useHideExport","yes")=="yes") insilmaril@2: setHideTmpMode (HideExport); insilmaril@2: else insilmaril@2: setHideTmpMode (HideNone); insilmaril@0: } insilmaril@0: insilmaril@4: void MapEditor::exportImage(QString fn, QString format) insilmaril@0: { insilmaril@2: setExportMode (true); insilmaril@0: QPixmap pix (getPixmap()); insilmaril@4: pix.save(fn, format); insilmaril@2: setExportMode (false); insilmaril@0: } insilmaril@0: insilmaril@2: void MapEditor::exportOOPresentation(const QString &fn, const QString &cf) insilmaril@0: { insilmaril@2: ExportOO ex; insilmaril@2: ex.setFile (fn); insilmaril@2: ex.setMapCenter(mapCenter); insilmaril@2: if (ex.setConfigFile(cf)) insilmaril@0: { insilmaril@2: setExportMode (true); insilmaril@2: ex.exportPresentation(); insilmaril@2: setExportMode (false); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@2: insilmaril@0: void MapEditor::exportXML(const QString &dir) insilmaril@0: { insilmaril@2: // Hide stuff during export, if settings want this insilmaril@2: setExportMode (true); insilmaril@2: insilmaril@0: // Create subdirectories insilmaril@0: makeSubDirs (dir); insilmaril@0: insilmaril@0: // write to directory insilmaril@2: QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL); insilmaril@0: QFile file; insilmaril@0: insilmaril@0: file.setName ( dir + "/"+mapName+".xml"); insilmaril@2: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@0: { insilmaril@0: // This should neverever happen insilmaril@2: 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@2: insilmaril@2: 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@2: void MapEditor::copy() insilmaril@2: { insilmaril@2: if (selection) insilmaril@2: { insilmaril@2: // write to directory insilmaril@2: QString clipfile="part"; insilmaril@2: QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection); insilmaril@2: QFile file; insilmaril@2: insilmaril@2: file.setName ( clipboardDir + "/"+clipfile+".xml"); insilmaril@2: if ( !file.open( QIODevice::WriteOnly ) ) insilmaril@2: { insilmaril@2: // This should neverever happen insilmaril@2: QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name())); insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@2: // Write it finally, and write in UTF8, no matter what insilmaril@2: QTextStream ts( &file ); insilmaril@2: ts.setEncoding (QTextStream::UnicodeUTF8); insilmaril@2: ts << saveFile; insilmaril@2: file.close(); insilmaril@2: insilmaril@2: clipboardEmpty=false; insilmaril@2: updateActions(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::redo() insilmaril@2: { insilmaril@2: blockSaveState=true; insilmaril@2: insilmaril@16: // Restore variables insilmaril@16: int curStep=undoSet.readNumEntry (QString("/history/curStep")); insilmaril@16: int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail")); insilmaril@16: int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail")); insilmaril@16: if (redosAvail>0) redosAvail--; insilmaril@16: if (undosAvailundosTotal) curStep=1; insilmaril@16: QString undoCommand= undoSet.readEntry (QString("/history/step-%1/undoCommand").arg(curStep)); insilmaril@16: QString undoSelection=undoSet.readEntry (QString("/history/step-%1/undoSelection").arg(curStep)); insilmaril@16: QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); insilmaril@16: QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); insilmaril@16: QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); insilmaril@16: insilmaril@2: // Find out current undo directory insilmaril@16: QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); insilmaril@16: insilmaril@16: /* TODO remove testing insilmaril@16: */ insilmaril@16: cout << "ME::redo() begin\n"; insilmaril@16: cout << " undosAvail="<reposition(); insilmaril@16: insilmaril@16: blockSaveState=false; insilmaril@18: insilmaril@18: undoSet.setEntry ("/history/undosAvail",QString::number(undosAvail)); insilmaril@18: undoSet.setEntry ("/history/redosAvail",QString::number(redosAvail)); insilmaril@18: undoSet.setEntry ("/history/curStep",QString::number(curStep)); insilmaril@18: undoSet.writeSettings(histPath); insilmaril@18: insilmaril@18: updateActions(); insilmaril@18: insilmaril@18: /* TODO remove testing insilmaril@18: */ insilmaril@16: cout << "ME::redo() end\n"; insilmaril@2: cout << " undosAvail="<reposition(); insilmaril@2: insilmaril@2: undosAvail--; insilmaril@18: curStep--; insilmaril@18: if (curStep<1) curStep=undosTotal; insilmaril@16: insilmaril@16: redosAvail++; insilmaril@2: insilmaril@2: blockSaveState=false; insilmaril@2: /* TODO remove testing insilmaril@16: */ insilmaril@2: cout << "ME::undo() end\n"; insilmaril@2: cout << " undosAvail="<clear(); insilmaril@2: handler.setLoadMode (NewMap); insilmaril@0: } else insilmaril@0: { insilmaril@2: select (undoSel); insilmaril@2: handler.setLoadMode (ImportReplace); insilmaril@0: } insilmaril@2: blockReposition=true; insilmaril@0: bool ok = reader.parse( source ); insilmaril@2: blockReposition=false; insilmaril@2: if (! ok ) insilmaril@0: { insilmaril@0: // This should never ever happen insilmaril@0: QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), insilmaril@2: tr( handler.errorProtocol() )+" in "+bakMapDir ); insilmaril@0: } insilmaril@0: } else insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@2: tr("Temporary directory %1 used for undo is gone. \n" insilmaril@0: "I will create a new one, but at the moment no undo is available.\n" insilmaril@0: "Maybe you want to reload your original data.\n\n" insilmaril@2: "Sorry for any inconveniences.").arg(bakMapDir) ); insilmaril@0: makeTmpDirs(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@2: void MapEditor::pasteNoSave() insilmaril@0: { insilmaril@2: load (clipboardDir+"/part.xml",ImportAdd); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cutNoSave() insilmaril@0: { insilmaril@2: copy(); insilmaril@2: deleteSelection(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::paste() insilmaril@0: { insilmaril@2: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@2: typeid(*selection) == typeid(MapCenterObj))) insilmaril@2: { insilmaril@16: saveStatePart(selection,QString("Paste to %1").arg( getName(selection))); insilmaril@2: pasteNoSave(); insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cut() insilmaril@0: { insilmaril@16: 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@2: void MapEditor::move(const int &x, const int &y) insilmaril@2: { insilmaril@20: if (selection) insilmaril@20: { insilmaril@20: QString ps=qpointToString (selection->getAbsPos()); insilmaril@20: QString s=selection->getSelectString(); insilmaril@20: saveState( insilmaril@20: s, "move "+ps, insilmaril@20: s, "move "+qpointToString (QPoint (x,y)), insilmaril@20: QString("Move %1 to %2").arg(getName(selection)).arg(ps)); insilmaril@20: selection->move(x,y); insilmaril@20: mapCenter->reposition(); insilmaril@20: adjustCanvasSize(); insilmaril@20: } insilmaril@20: insilmaril@20: } insilmaril@20: insilmaril@20: void MapEditor::moveRel (const int &x, const int &y) insilmaril@20: { insilmaril@20: if (selection) insilmaril@20: { insilmaril@20: QString ps=qpointToString (selection->getRelPos()); insilmaril@20: QString s=selection->getSelectString(); insilmaril@20: saveState( insilmaril@20: s, "moveRel "+ps, insilmaril@20: s, "moveRel "+qpointToString (QPoint (x,y)), insilmaril@20: QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps)); insilmaril@20: selection->setRelPos (QPoint(x,y)); insilmaril@20: mapCenter->reposition(); insilmaril@20: adjustCanvasSize(); insilmaril@20: } insilmaril@2: } insilmaril@2: 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@2: bo=(BranchObj*)selection; insilmaril@2: if (!bo->canMoveBranchUp()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@0: selection->unselect(); insilmaril@18: bo=par->moveBranchUp (bo); // bo will be the one below selection insilmaril@0: selection->select(); insilmaril@18: 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@2: bo=(BranchObj*)selection; insilmaril@2: if (!bo->canMoveBranchDown()) return; insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@0: selection->unselect(); insilmaril@18: bo=par->moveBranchDown(bo); // bo will be the one above selection insilmaril@0: selection->select(); insilmaril@18: 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@16: QString MapEditor::getHeading(bool &ok, QPoint &p) insilmaril@16: { insilmaril@16: if (selection && insilmaril@16: (typeid(*selection) == typeid(BranchObj) || insilmaril@16: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@16: { insilmaril@16: ok=true; insilmaril@16: ensureSelectionVisible(); insilmaril@16: p = ((BranchObj*)selection)->getAbsPos(); insilmaril@17: p.setX (p.x() - contentsX()); insilmaril@17: p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2); insilmaril@16: return ((BranchObj*)selection)->getHeading(); insilmaril@16: } insilmaril@16: ok=false; insilmaril@16: return QString(); insilmaril@0: } insilmaril@0: insilmaril@2: void MapEditor::setHeading(const QString &s) insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@0: { insilmaril@16: editingBO=(BranchObj*)selection; insilmaril@16: saveStateConstSelection( insilmaril@16: "setHeading (\""+editingBO->getHeading()+"\")", insilmaril@16: "setHeading (\""+s+"\")", insilmaril@16: QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) ); insilmaril@16: editingBO->setHeading(s ); insilmaril@16: editingBO=NULL; insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: ensureSelectionVisible(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@16: void MapEditor::setURLInt (const QString &s) insilmaril@2: { insilmaril@2: // Internal function, no saveState needed insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj) || insilmaril@2: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@2: { insilmaril@2: ((BranchObj*)selection)->setURL(s); insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: ensureSelectionVisible(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@16: void MapEditor::setHeadingInt(const QString &s) insilmaril@16: { insilmaril@16: if (selection && insilmaril@16: (typeid(*selection) == typeid(BranchObj) || insilmaril@16: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@16: { insilmaril@16: ((BranchObj*)selection)->setHeading(s); insilmaril@16: mapCenter->reposition(); insilmaril@16: adjustCanvasSize(); insilmaril@16: ensureSelectionVisible(); insilmaril@16: } insilmaril@16: } insilmaril@16: insilmaril@16: void MapEditor::setVymLinkInt (const QString &s) insilmaril@2: { insilmaril@2: // Internal function, no saveState needed insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj) || insilmaril@2: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@2: { insilmaril@2: ((BranchObj*)selection)->setVymLink(s); insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: ensureSelectionVisible(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@18: BranchObj* MapEditor::addNewBranchInt(int num) insilmaril@2: { insilmaril@18: // Depending on pos: insilmaril@18: // -3 insert in childs of parent above selection insilmaril@18: // -2 add branch to selection insilmaril@18: // -1 insert in childs of parent below selection insilmaril@18: // 0..n insert in childs of parent at pos insilmaril@18: BranchObj *newbo=NULL; insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj) || insilmaril@2: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@2: { insilmaril@18: BranchObj* bo = (BranchObj*) selection; insilmaril@18: 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@18: return bo->addBranch(); insilmaril@18: insilmaril@18: }else if (num==-1) insilmaril@0: { insilmaril@18: num=bo->getNum()+1; insilmaril@18: bo=(BranchObj*)bo->getParObj(); insilmaril@18: }else if (num==-3) insilmaril@16: { insilmaril@18: num=bo->getNum(); insilmaril@18: bo=(BranchObj*)bo->getParObj(); insilmaril@18: } insilmaril@18: if (!bo) return bo; insilmaril@18: newbo=bo->insertBranch(num); insilmaril@18: } insilmaril@18: return newbo; insilmaril@18: } insilmaril@18: insilmaril@18: void MapEditor::addNewBranch(int pos) insilmaril@18: { insilmaril@18: // Different meaning than num in addNewBranchInt! insilmaril@18: // -1 add above insilmaril@18: // 0 add as child insilmaril@18: // +1 add below insilmaril@18: if (selection && insilmaril@18: (typeid(*selection) == typeid(BranchObj) || insilmaril@18: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@18: { insilmaril@18: BranchObj *bo = (BranchObj*) selection; insilmaril@18: BranchObj *newbo; insilmaril@18: newbo=addNewBranchInt (pos-2); insilmaril@18: insilmaril@18: if (newbo) insilmaril@18: { insilmaril@18: saveStateConstSelection ( insilmaril@18: QString ("delete (\"%1\")").arg(newbo->getSelectString()), insilmaril@18: QString ("addBranch (%1)").arg(pos-2), insilmaril@18: QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand insilmaril@18: insilmaril@18: LinkableMapObj *oldselection=selection; insilmaril@18: insilmaril@18: mapCenter->reposition(); insilmaril@18: adjustCanvasSize(); insilmaril@18: insilmaril@18: insilmaril@18: if (actionSettingsAutoedit->isOn() || insilmaril@18: actionSettingsAutoselectHeading->isOn() ) insilmaril@16: { insilmaril@16: selection->unselect(); insilmaril@18: selection=newbo; insilmaril@16: selection->select(); insilmaril@18: if (actionSettingsAutoedit->isOn() ) insilmaril@18: mainWindow->editHeading(); insilmaril@18: if (!actionSettingsAutoselectHeading->isOn() insilmaril@18: )//&& !wasScrolled) //FIXME wasScrolled was moved to addNewBranchInt insilmaril@18: { insilmaril@18: selection->unselect(); insilmaril@18: selection=oldselection; insilmaril@18: selection->select(); insilmaril@18: } insilmaril@18: } insilmaril@18: } insilmaril@16: } insilmaril@16: } insilmaril@16: insilmaril@16: insilmaril@16: void MapEditor::addNewBranchHere() insilmaril@16: { insilmaril@16: if (selection && insilmaril@16: (typeid(*selection) == typeid(BranchObj) ) ) insilmaril@16: { insilmaril@16: BranchObj* bo1 = (BranchObj*) selection; insilmaril@16: saveStatePart(selection, QString("Add new branch here").arg(getName(bo1))); insilmaril@16: insilmaril@16: bool wasScrolled=false; insilmaril@16: BranchObj *newbo=NULL; insilmaril@16: BranchObj *parbo=(BranchObj*)(selection->getParObj()); insilmaril@16: if (parbo) insilmaril@16: { insilmaril@16: // add below selection insilmaril@16: newbo=parbo->insertBranch(bo1->getNum()+1); insilmaril@16: } insilmaril@16: insilmaril@16: LinkableMapObj *oldselection=selection; insilmaril@16: ((BranchObj*)selection)->moveBranchTo (newbo,-1); insilmaril@16: insilmaril@16: mapCenter->reposition(); insilmaril@16: 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@17: 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@17: BranchObj* bo=(BranchObj*)selection; insilmaril@0: BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@0: bo->unselect(); insilmaril@2: if (selection->getDepth()>1) insilmaril@2: // Normal branch, save parent with childs insilmaril@16: saveStatePart(par,QString("Delete %1").arg(getName(bo))); insilmaril@17: // naveState (UndoCom, par, QString("insertBranchAt (%1)", bo, "", QString ("Delete %1").arg(getName(bo)))); insilmaril@2: else insilmaril@2: // Mainbranch, save whole map insilmaril@2: // TODO Better would be to insert mainbranch again at pos insilmaril@2: // But undoCommand is missing right now insilmaril@16: 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@17: FloatImageObj* fio=(FloatImageObj*)selection; insilmaril@0: BranchObj* par=(BranchObj*)(fio->getParObj()); insilmaril@16: 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@0: void MapEditor::unselect() insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: selectionLast=selection; insilmaril@0: selection->unselect(); insilmaril@0: selection=NULL; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::reselect() insilmaril@0: { insilmaril@0: if (selectionLast) insilmaril@0: { insilmaril@0: selection=selectionLast; insilmaril@0: selection->select(); insilmaril@0: selectionLast=NULL; insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@2: bool MapEditor::select (const QString &s) insilmaril@2: { insilmaril@2: LinkableMapObj *lmo=mapCenter->findObjBySelect(s); insilmaril@2: insilmaril@2: // Finally select the found object insilmaril@2: if (lmo) insilmaril@2: { insilmaril@2: if (selection) unselect(); insilmaril@2: selection=lmo; insilmaril@2: selection->select(); insilmaril@2: adjustCanvasSize(); insilmaril@2: ensureSelectionVisible(); insilmaril@2: return true; insilmaril@2: } insilmaril@2: return false; insilmaril@2: } insilmaril@2: insilmaril@17: QString MapEditor::getSelectString() insilmaril@17: { insilmaril@17: if (selection) return selection->getSelectString(); insilmaril@17: return QString(); insilmaril@17: } insilmaril@17: insilmaril@16: void MapEditor::selectInt (LinkableMapObj *lmo) insilmaril@2: { insilmaril@2: if (lmo && selection != lmo) insilmaril@2: { insilmaril@2: // select the MapObj insilmaril@2: if (selection) selection->unselect(); insilmaril@2: selection=lmo; insilmaril@2: selection->select(); insilmaril@2: insilmaril@2: adjustCanvasSize(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@16: 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@16: 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@2: 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@16: selectPrevBranchInt(); insilmaril@0: else insilmaril@0: if (selection->getDepth()==1) insilmaril@16: selectNextBranchInt(); insilmaril@0: else insilmaril@16: 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@16: selectNextBranchInt(); insilmaril@0: else insilmaril@0: if (selection->getDepth()==1) insilmaril@16: selectPrevBranchInt(); insilmaril@0: else insilmaril@16: 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@2: 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@2: 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@2: par= (BranchObj*) selection; insilmaril@0: bo=par->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@16: // 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@2: 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@2: 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@2: 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@16: //TODO undocomm insilmaril@16: 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@2: 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@2: BranchObj *bo=(BranchObj*)selection; insilmaril@16: saveStatePart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand insilmaril@2: 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@2: BranchObj *bo=(BranchObj*)selection; insilmaril@16: saveStatePart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand insilmaril@2: 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@3: if (typeid(*selection) == typeid(BranchObj) || insilmaril@3: typeid(*selection) == typeid(MapCenterObj)) insilmaril@3: { insilmaril@3: BranchObj *bo=(BranchObj*)selection; insilmaril@16: QString u,r; insilmaril@3: if (bo->isSetStandardFlag(f)) insilmaril@16: { insilmaril@16: r="unsetFlag"; insilmaril@16: u="setFlag"; insilmaril@16: } insilmaril@3: else insilmaril@16: { insilmaril@16: u="unsetFlag"; insilmaril@16: r="setFlag"; insilmaril@16: } insilmaril@16: saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f), insilmaril@16: QString("%1 (\"%2\")").arg(r).arg(f), insilmaril@16: QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); insilmaril@3: bo->toggleStandardFlag (f,actionSettingsUseFlagGroups->isOn()); insilmaril@3: adjustCanvasSize(); insilmaril@3: } 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@9: QTextDocument::FindFlags flags=0; insilmaril@17: if (cs) flags=QTextDocument::FindCaseSensitively; insilmaril@9: 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@2: if (selection) ((BranchObj*)selection)->unselect(); insilmaril@0: selection=itFind; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@9: 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@2: 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@2: 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@2: BranchObj *bo=(BranchObj*)selection; insilmaril@0: QString text = QInputDialog::getText( insilmaril@0: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@2: bo->getURL(), &ok, this ); insilmaril@0: if ( ok) insilmaril@0: { insilmaril@0: // user entered something and pressed OK insilmaril@16: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text)); insilmaril@2: bo->setURL (text); insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@2: QString MapEditor::getURL() insilmaril@2: { insilmaril@2: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@2: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: return ((BranchObj*)selection)->getURL(); insilmaril@2: else insilmaril@2: return ""; insilmaril@2: } insilmaril@2: insilmaril@17: QStringList MapEditor::getURLs() insilmaril@17: { insilmaril@17: QStringList urls; insilmaril@17: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@17: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@17: { insilmaril@17: BranchObj *bo=(BranchObj*)selection; insilmaril@17: bo=bo->first(); insilmaril@17: while (bo) insilmaril@17: { insilmaril@17: if (!bo->getURL().isEmpty()) urls.append( bo->getURL()); insilmaril@17: bo=bo->next(); insilmaril@17: } insilmaril@17: } insilmaril@17: return urls; insilmaril@17: } insilmaril@17: insilmaril@17: insilmaril@0: void MapEditor::editHeading2URL() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@2: BranchObj *bo=(BranchObj*)selection; insilmaril@16: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo))); insilmaril@2: 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@2: BranchObj *bo=(BranchObj*)selection; insilmaril@2: QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); insilmaril@16: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo))); insilmaril@2: bo->setURL (url); insilmaril@0: updateActions(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::editFATE2URL() insilmaril@2: { insilmaril@2: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@2: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: { insilmaril@2: BranchObj *bo=(BranchObj*)selection; insilmaril@2: QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); insilmaril@16: saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo))); insilmaril@2: bo->setURL (url); insilmaril@2: updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::editVymLink() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@2: BranchObj *bo=(BranchObj*)selection; insilmaril@2: Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Link to another map")); insilmaril@0: fd->addFilter (QString (tr("vym map") + " (*.vym)")); insilmaril@2: fd->setCaption(__VYM " - " +tr("Link to another map")); insilmaril@2: if (! bo->getVymLink().isEmpty() ) insilmaril@2: fd->setSelection( bo->getVymLink() ); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@2: { insilmaril@16: saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())); insilmaril@2: bo->setVymLink (fd->selectedFile() ); insilmaril@2: updateActions(); insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: canvas()->update(); insilmaril@2: } 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@2: BranchObj *bo=(BranchObj*)selection; insilmaril@16: saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo))); insilmaril@2: bo->setVymLink ("" ); insilmaril@0: updateActions(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::toggleHideExport() insilmaril@2: { insilmaril@2: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@2: typeid(*selection) == typeid(MapCenterObj)) || insilmaril@2: (typeid(*selection)==typeid(FloatImageObj)) insilmaril@2: ) insilmaril@2: { insilmaril@2: OrnamentedObj *oo=(OrnamentedObj*)selection; insilmaril@2: QString s; insilmaril@2: if (oo->hideInExport()) insilmaril@2: { insilmaril@2: oo->setHideInExport(false); insilmaril@2: s="Unset"; insilmaril@2: } insilmaril@2: else insilmaril@2: { insilmaril@2: oo->setHideInExport(true); insilmaril@2: s="Set"; insilmaril@2: } insilmaril@16: saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand insilmaril@2: actionEditToggleHideExport->setOn (oo->hideInExport()); insilmaril@2: updateActions(); insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: canvas()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getVymLink() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@2: return ((BranchObj*)selection)->getVymLink(); insilmaril@0: } insilmaril@0: return ""; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@17: QStringList MapEditor::getVymLinks() insilmaril@17: { insilmaril@17: QStringList links; insilmaril@17: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@17: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@17: { insilmaril@17: BranchObj *bo=(BranchObj*)selection; insilmaril@17: bo=bo->first(); insilmaril@17: while (bo) insilmaril@17: { insilmaril@17: if (!bo->getVymLink().isEmpty()) links.append( bo->getVymLink()); insilmaril@17: bo=bo->next(); insilmaril@17: } insilmaril@17: } insilmaril@17: return links; insilmaril@17: } insilmaril@17: insilmaril@17: insilmaril@2: void MapEditor::removeBranchKeepChilds() insilmaril@2: { insilmaril@2: if (selection && (typeid(*selection) == typeid(BranchObj) )) insilmaril@2: { insilmaril@2: BranchObj* bo=(BranchObj*)selection; insilmaril@2: BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@2: QString s=QString("Remove %1 and keep its childs").arg(getName(bo)); insilmaril@2: if (bo->getDepth()==1) insilmaril@16: saveStateComplete(s); insilmaril@2: else insilmaril@16: saveStatePart(selection->getParObj(),s); // TODO undoCommand insilmaril@2: QString sel=selection->getSelectString(); insilmaril@2: unselect(); insilmaril@2: par->removeBranchHere(bo); insilmaril@2: mapCenter->reposition(); insilmaril@2: select (sel); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::removeChilds() insilmaril@2: { insilmaril@2: if (selection && (typeid(*selection) == typeid(BranchObj) )) insilmaril@2: { insilmaril@16: saveStatePart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection))); insilmaril@2: ((BranchObj*)selection)->removeChilds(); insilmaril@2: mapCenter->reposition(); insilmaril@2: } insilmaril@2: } insilmaril@2: 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@2: Q3CanvasItemList l=canvas()->allItems(); insilmaril@2: 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@2: 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@2: xl+=bo->countXLinks(); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@0: stats+=QString ("%1 branches\n").arg (b-1,6); insilmaril@2: 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@16: 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@2: 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@2: pix.fill( defLinkColor ); insilmaril@0: actionFormatLinkColor->setIconSet( pix ); insilmaril@0: insilmaril@0: actionFileSave->setEnabled( mapUnsaved ); insilmaril@16: if (undoSet.readNumEntry("/history/undosAvail",0)>0) insilmaril@16: actionEditUndo->setEnabled( true); insilmaril@16: else insilmaril@16: actionEditUndo->setEnabled( false); insilmaril@16: insilmaril@16: if (undoSet.readNumEntry("/history/redosAvail",0)>0) insilmaril@16: actionEditRedo->setEnabled( true); insilmaril@16: else insilmaril@16: 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@2: BranchObj *bo=(BranchObj*)selection; insilmaril@2: // Take care of links insilmaril@2: if (bo->countXLinks()==0) insilmaril@2: { insilmaril@17: branchXLinksContextMenuEdit->clear(); insilmaril@17: branchXLinksContextMenuFollow->clear(); insilmaril@2: } else insilmaril@2: { insilmaril@2: BranchObj *bot; insilmaril@2: QString s; insilmaril@17: branchXLinksContextMenuEdit->clear(); insilmaril@17: branchXLinksContextMenuFollow->clear(); insilmaril@2: for (int i=0; i<=bo->countXLinks();i++) insilmaril@2: { insilmaril@2: bot=bo->XLinkTargetAt(i); insilmaril@2: if (bot) insilmaril@2: { insilmaril@2: s=bot->getHeading(); insilmaril@2: if (s.length()>25) insilmaril@2: s=s.left(25)+"..."; insilmaril@17: branchXLinksContextMenuFollow->addAction (s); insilmaril@17: branchXLinksContextMenuEdit->addAction (s); insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@0: standardFlagsDefault->setEnabled (true); insilmaril@0: insilmaril@2: actionEditToggleScroll->setEnabled (true); insilmaril@2: if ( bo->isScrolled() ) insilmaril@2: actionEditToggleScroll->setOn(true); insilmaril@2: else insilmaril@2: actionEditToggleScroll->setOn(false); insilmaril@2: insilmaril@2: if ( bo->getURL().isEmpty() ) insilmaril@2: { insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@2: actionEditOpenURLTab->setEnabled (false); insilmaril@2: } insilmaril@0: else insilmaril@2: { insilmaril@0: actionEditOpenURL->setEnabled (true); insilmaril@2: actionEditOpenURLTab->setEnabled (true); insilmaril@2: } insilmaril@2: 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@2: insilmaril@2: if (bo->canMoveBranchUp()) insilmaril@2: actionEditMoveUp->setEnabled (true); insilmaril@2: else insilmaril@2: actionEditMoveUp->setEnabled (false); insilmaril@2: if (bo->canMoveBranchDown()) insilmaril@2: actionEditMoveDown->setEnabled (true); insilmaril@2: else insilmaril@2: actionEditMoveDown->setEnabled (false); insilmaril@2: insilmaril@2: insilmaril@2: actionEditToggleHideExport->setEnabled (true); insilmaril@2: actionEditToggleHideExport->setOn (bo->hideInExport() ); insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (true); insilmaril@0: actionEditCut->setEnabled (true); insilmaril@2: if (!clipboardEmpty) insilmaril@2: actionEditPaste->setEnabled (true); insilmaril@2: else insilmaril@2: actionEditPaste->setEnabled (false); insilmaril@2: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@2: 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@2: actionFormatIncludeImagesVer->setOn insilmaril@2: ( ((BranchObj*)selection)->getIncludeImagesVer()); insilmaril@2: actionFormatIncludeImagesHor->setOn insilmaril@2: ( ((BranchObj*)selection)->getIncludeImagesHor()); insilmaril@2: actionFormatHideLinkUnselected->setOn insilmaril@2: (selection->getHideLinkUnselected()); insilmaril@0: } insilmaril@0: if ( (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@0: { insilmaril@2: FloatObj *fo=(FloatImageObj*)selection; insilmaril@3: //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@2: actionEditToggleHideExport->setEnabled (true); insilmaril@2: actionEditToggleHideExport->setOn (fo->hideInExport() ); insilmaril@2: insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (true); insilmaril@0: actionEditCut->setEnabled (true); insilmaril@2: actionEditPaste->setEnabled (false); insilmaril@2: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@2: a->setEnabled(false); insilmaril@0: actionEditDelete->setEnabled (true); insilmaril@2: actionFormatHideLinkUnselected->setOn insilmaril@2: ( selection->getHideLinkUnselected()); insilmaril@2: actionEditMoveUp->setEnabled (false); insilmaril@2: actionEditMoveDown->setEnabled (false); insilmaril@0: } insilmaril@0: insilmaril@0: } else insilmaril@0: { insilmaril@3: //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@2: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@2: a->setEnabled(false); insilmaril@2: insilmaril@2: 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@2: actionEditMoveUp->setEnabled (false); insilmaril@2: actionEditMoveDown->setEnabled (false); insilmaril@2: actionEditToggleHideExport->setEnabled (false); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@2: void MapEditor::updateNoteFlag() insilmaril@2: { insilmaril@2: if (selection) insilmaril@2: if ( (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: ((BranchObj*)selection)->updateNoteFlag(); insilmaril@2: } insilmaril@2: insilmaril@0: void MapEditor::setLinkStyle (LinkStyle ls) insilmaril@0: { insilmaril@0: linkstyle=ls; insilmaril@0: insilmaril@16: 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@2: 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@2: 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@2: return defLinkColor; insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::setDefXLinkColor(QColor col) insilmaril@2: { insilmaril@2: defXLinkColor=col; insilmaril@2: } insilmaril@2: insilmaril@2: QColor MapEditor::getDefXLinkColor() insilmaril@2: { insilmaril@2: return defXLinkColor; insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::setDefXLinkWidth (int w) insilmaril@2: { insilmaril@2: defXLinkWidth=w; insilmaril@2: } insilmaril@2: insilmaril@2: int MapEditor::getDefXLinkWidth() insilmaril@2: { insilmaril@2: return defXLinkWidth; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLinkColor() insilmaril@0: { insilmaril@2: QColor col = QColorDialog::getColor( defLinkColor, this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: setLinkColor( col ); insilmaril@16: saveStateComplete(QString("Set link color to %1").arg(col.name())); //TODO undoCommand insilmaril@2: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::toggleScroll() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj)) ) insilmaril@0: { insilmaril@2: BranchObj *bo=((BranchObj*)selection); insilmaril@0: if (bo->countBranches()==0) return; insilmaril@0: if (bo->getDepth()==0) return; insilmaril@2: QString s; insilmaril@2: if (bo->isScrolled()) insilmaril@2: s="Unscroll"; insilmaril@2: else insilmaril@2: s="Scroll"; insilmaril@16: 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@2: BranchObj *bo=((BranchObj*)selection); insilmaril@2: insilmaril@2: Q3FileDialog *fd=new Q3FileDialog( this); insilmaril@2: 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@2: fd->setPreviewMode( Q3FileDialog::Contents ); insilmaril@2: 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@16: saveStatePart(selection, QString("Add floatimage to %1").arg(getName(selection))); insilmaril@4: // FIXME in QT4 use: lastImageDir=fd->directory(); insilmaril@4: lastImageDir=QDir (fd->dirPath()); insilmaril@2: QStringList flist = fd->selectedFiles(); insilmaril@2: QStringList::Iterator it = flist.begin(); insilmaril@2: while( it != flist.end() ) insilmaril@2: { insilmaril@2: fn = *it; insilmaril@2: bo->addFloatImage(); insilmaril@2: // TODO check if load was successful insilmaril@2: bo->getLastFloatImage()->load(*it); insilmaril@2: bo->getLastFloatImage()->setOriginalFilename(fn); insilmaril@2: ++it; insilmaril@2: } insilmaril@2: insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@2: delete (p); insilmaril@2: delete (fd); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@11: void MapEditor::saveFloatImage () insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@0: { insilmaril@2: FloatImageObj *fio=((FloatImageObj*)selection); insilmaril@11: QFileDialog *fd=new QFileDialog( this); insilmaril@11: fd->setFilters (imageIO.getFilters()); insilmaril@11: fd->setCaption(__VYM " - " +tr("Save image")); insilmaril@11: fd->setFileMode( QFileDialog::AnyFile ); insilmaril@11: fd->setDirectory (lastImageDir); insilmaril@11: // 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@2: QMessageBox mb( __VYM, insilmaril@2: tr("The file %1 exists already.\n" insilmaril@2: "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@11: 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@2: void MapEditor::setIncludeImagesVer(bool b) insilmaril@2: { insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: ((BranchObj*)selection)->setIncludeImagesVer(b); insilmaril@2: mapCenter->reposition(); insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::setIncludeImagesHor(bool b) insilmaril@2: { insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: ((BranchObj*)selection)->setIncludeImagesHor(b); insilmaril@2: mapCenter->reposition(); insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::setHideLinkUnselected (bool b) insilmaril@2: { insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj)) || insilmaril@2: (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@2: selection->setHideLinkUnselected(b); insilmaril@2: } insilmaril@2: insilmaril@16: 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@2: QFileInfoList list = d.entryInfoList(); insilmaril@2: QFileInfo fi; insilmaril@2: insilmaril@2: for (int i = 0; i < list.size(); ++i) insilmaril@0: { insilmaril@2: fi=list.at(i); insilmaril@2: if (fi.fileName() != "." && fi.fileName() != ".." ) insilmaril@0: { insilmaril@0: dst->addBranch(); insilmaril@0: bo=dst->getLastBranch(); insilmaril@2: bo->setHeading (fi.fileName() ); insilmaril@2: bo->setColor (QColor("blue")); insilmaril@0: bo->toggleScroll(); insilmaril@2: if ( !d.cd(fi.fileName()) ) insilmaril@2: QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); insilmaril@0: else insilmaril@0: { insilmaril@2: // Recursively add subdirs insilmaril@16: 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@2: list = d.entryInfoList(); insilmaril@2: insilmaril@2: for (int i = 0; i < list.size(); ++i) insilmaril@0: { insilmaril@2: fi=list.at(i); insilmaril@0: dst->addBranch(); insilmaril@0: bo=dst->getLastBranch(); insilmaril@2: bo->setHeading (fi.fileName() ); insilmaril@2: bo->setColor (QColor("black")); insilmaril@2: if (fi.fileName().right(4) == ".vym" ) insilmaril@2: 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@2: Q3FileDialog *fd=new Q3FileDialog( this,__VYM " - " +tr("Choose directory structure to import")); insilmaril@2: fd->setMode (Q3FileDialog::DirectoryOnly); insilmaril@0: fd->addFilter (QString (tr("vym map") + " (*.vym)")); insilmaril@2: 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@2: BranchObj *bo=((BranchObj*)selection); insilmaril@16: 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@2: void MapEditor::followXLink(int i) insilmaril@2: { insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: { insilmaril@2: BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i); insilmaril@2: if (bo) insilmaril@2: { insilmaril@2: selection->unselect(); insilmaril@2: selection=bo; insilmaril@2: selection->select(); insilmaril@2: ensureSelectionVisible(); insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::editXLink(int i) insilmaril@2: { insilmaril@16: qDebug ("ko."); //FIXME Huh? insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: { insilmaril@2: XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i); insilmaril@2: if (xlo) insilmaril@2: { insilmaril@2: EditXLinkDialog dia; insilmaril@2: dia.setXLink (xlo); insilmaril@2: dia.setSelection(selection); insilmaril@2: if (dia.exec() == QDialog::Accepted) insilmaril@2: { insilmaril@2: if (dia.useSettingsGlobal() ) insilmaril@2: { insilmaril@2: setDefXLinkColor (xlo->getColor() ); insilmaril@2: setDefXLinkWidth (xlo->getWidth() ); insilmaril@2: } insilmaril@2: if (dia.deleteXLink()) insilmaril@2: ((BranchObj*)selection)->deleteXLinkAt(i); insilmaril@16: saveStateComplete("Edit xLink"); //TODO undoCommand insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@0: void MapEditor::testFunction() insilmaril@0: { insilmaril@0: cout << "MapEditor::testFunction() called\n"; insilmaril@2: insilmaril@16: /* insilmaril@16: bool ok; insilmaril@16: QString text = QInputDialog::getText( insilmaril@16: this, insilmaril@16: tr("QInputDialog::getText()"), insilmaril@16: tr("User name:"), QLineEdit::Normal, insilmaril@16: QDir::home().dirName(), &ok, Qt::FramelessWindowHint); insilmaril@16: */ insilmaril@16: insilmaril@16: QDialog *d =new QDialog(NULL); insilmaril@16: QLineEdit *le=new QLineEdit (d); insilmaril@16: // d->setModal (true); insilmaril@16: d->setWindowFlags (Qt::FramelessWindowHint); insilmaril@16: le->setFocus(); insilmaril@16: le->setText ("Foo"); insilmaril@16: le->selectAll(); insilmaril@16: connect (le, SIGNAL (returnPressed()), d, SLOT (accept())); insilmaril@16: d->exec(); insilmaril@16: qWarning( le->text()); insilmaril@2: return; insilmaril@16: insilmaril@16: insilmaril@16: insilmaril@16: /* insilmaril@2: WarningDialog dia; insilmaril@2: dia.setCancelButton (true); insilmaril@2: dia.setText("This is a longer \nWarning"); insilmaril@2: dia.setCaption("Warning: Flux problem"); insilmaril@13: dia.setShowAgainName("/warnings/mapeditor"); insilmaril@16: dia.setWindowFlags (Qt::FramelessWindowHint); insilmaril@2: if (dia.exec()==QDialog::Accepted) insilmaril@2: cout << "accepted!\n"; insilmaril@2: else insilmaril@2: cout << "canceled!\n"; insilmaril@2: return; insilmaril@16: */ insilmaril@16: insilmaril@9: /* Hide hidden stuff temporary, maybe add this as regular function somewhere insilmaril@2: if (hidemode==HideNone) insilmaril@2: { insilmaril@2: setHideTmpMode (HideExport); insilmaril@2: mapCenter->calcBBoxSizeWithChilds(); insilmaril@2: QRect totalBBox=mapCenter->getTotalBBox(); insilmaril@2: QRect mapRect=totalBBox; insilmaril@2: QCanvasRectangle *frame=NULL; insilmaril@2: insilmaril@2: cout << " map has =("<setBrush (QColor(white)); insilmaril@2: frame->setPen (QColor(black)); insilmaril@2: frame->setZ(0); insilmaril@2: frame->show(); insilmaril@2: } insilmaril@2: else insilmaril@2: { insilmaril@2: setHideTmpMode (HideNone); insilmaril@2: } insilmaril@2: cout <<" hidemode="< (selection); insilmaril@2: QPoint p; insilmaril@2: if (selection->getOrientation() == OrientLeftOfCenter) insilmaril@2: p= worldMatrix().map(QPoint (lmo->x(),lmo->y())); insilmaril@2: else insilmaril@2: p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height())); insilmaril@2: ensureVisible (p.x(), p.y() ); insilmaril@2: } 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@2: e->accept(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMousePressEvent(QMouseEvent* e) insilmaril@0: { insilmaril@2: // Ignore right clicks, these will go to context menus insilmaril@2: if (e->button() == Qt::RightButton ) insilmaril@2: { insilmaril@2: e->ignore(); insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@0: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: insilmaril@2: e->accept(); insilmaril@2: insilmaril@2: //Take care of clickdesystem flags _or_ modifier modes insilmaril@2: // insilmaril@2: if (lmo && (typeid(*lmo)==typeid(BranchObj) || insilmaril@2: typeid(*lmo)==typeid(MapCenterObj) )) insilmaril@0: { insilmaril@2: QString foname=((BranchObj*)lmo)->getSystemFlagName(p); insilmaril@2: if (!foname.isEmpty()) insilmaril@2: { insilmaril@2: // systemFlag clicked insilmaril@16: selectInt (lmo); insilmaril@2: if (foname=="url") insilmaril@2: { insilmaril@2: if (e->state() & Qt::ControlModifier) insilmaril@2: mainWindow->editOpenURLTab(); insilmaril@2: else insilmaril@2: mainWindow->editOpenURL(); insilmaril@2: } insilmaril@2: else if (foname=="vymLink") insilmaril@2: { insilmaril@2: mainWindow->editOpenVymLink(); insilmaril@2: // tabWidget may change, better return now insilmaril@2: // before segfaulting... insilmaril@2: } else if (foname=="note") insilmaril@2: mainWindow->windowToggleNoteEditor(); insilmaril@2: else if (foname=="hideInExport") insilmaril@2: toggleHideExport(); insilmaril@2: return; insilmaril@2: } insilmaril@2: } insilmaril@2: // No system flag clicked, take care of modmodes insilmaril@2: insilmaril@2: // Special case: CTRL is pressed insilmaril@2: if (e->state() & Qt::ControlModifier) insilmaril@2: { insilmaril@2: if (actionModModeColor->isOn()) insilmaril@2: { insilmaril@2: pickingColor=true; insilmaril@2: setCursor (pickColorCursor); insilmaril@2: return; insilmaril@2: } insilmaril@2: if (actionModModeLink->isOn()) insilmaril@2: { insilmaril@2: BranchObj *bo_begin=NULL; insilmaril@2: if (lmo) insilmaril@2: bo_begin=(BranchObj*)(lmo); insilmaril@2: else insilmaril@2: if (selection && insilmaril@2: ((typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj))) ) insilmaril@2: bo_begin=(BranchObj*)selection; insilmaril@2: if (bo_begin) insilmaril@2: { insilmaril@2: drawingLink=true; insilmaril@2: linkingObj_src=bo_begin; insilmaril@2: tmpXLink=new XLinkObj (mapCanvas); insilmaril@2: tmpXLink->setBegin (bo_begin); insilmaril@2: tmpXLink->setEnd (p); insilmaril@2: tmpXLink->setColor(defXLinkColor); insilmaril@2: tmpXLink->setWidth(defXLinkWidth); insilmaril@2: tmpXLink->updateXLink(); insilmaril@2: tmpXLink->setVisibility (true); insilmaril@2: return; insilmaril@2: } insilmaril@2: } insilmaril@0: } insilmaril@0: if (lmo) insilmaril@2: { insilmaril@16: selectInt (lmo); insilmaril@2: // Left Button Move Branches insilmaril@2: if (e->button() == Qt::LeftButton ) insilmaril@0: { insilmaril@0: movingObj_start.setX( p.x() - selection->x() ); insilmaril@0: movingObj_start.setY( p.y() - selection->y() ); insilmaril@2: movingObj_orgPos.setX (lmo->x() ); insilmaril@2: movingObj_orgPos.setY (lmo->y() ); insilmaril@20: movingObj_orgRelPos=lmo->getRelPos(); insilmaril@2: insilmaril@2: // If modMode==copy, then we want to "move" the _new_ object around insilmaril@2: // then we need the offset from p to the _old_ selection, because of tmp insilmaril@2: if (actionModModeCopy->isOn() && insilmaril@2: e->state() & Qt::ControlModifier) insilmaril@2: { insilmaril@2: if (typeid(*selection)==typeid(BranchObj) ) insilmaril@2: { insilmaril@2: copyingObj=true; insilmaril@2: mapCenter->addBranch ((BranchObj*)selection); insilmaril@2: unselect(); insilmaril@2: selection=mapCenter->getLastBranch(); insilmaril@2: selection->select(); insilmaril@2: mapCenter->reposition(); insilmaril@2: } insilmaril@2: } insilmaril@2: 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@2: 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@2: 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@2: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@2: insilmaril@0: // Move the selected MapObj insilmaril@0: if ( selection && movingObj) insilmaril@0: { insilmaril@2: // To avoid jumping of the CanvasView, only insilmaril@2: // ensureSelectionVisible, if not tmp linked insilmaril@2: if (!selection->hasParObjTmp()) insilmaril@2: ensureSelectionVisible (); insilmaril@0: insilmaril@2: // Now move the selection, but add relative position insilmaril@2: // (movingObj_start) where selection was chosen with insilmaril@2: // 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@2: 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@2: 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@16: //TODO undocom insilmaril@16: 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@2: 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@2: p.y()-movingObj_start.y() +lmosel->getTopPad() ); insilmaril@0: else insilmaril@2: 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@2: //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@2: 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@2: 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@2: 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@2: // Draw a link from one branch to another insilmaril@2: if (drawingLink) insilmaril@2: { insilmaril@2: tmpXLink->setEnd (p); insilmaril@2: tmpXLink->updateXLink(); insilmaril@2: } insilmaril@2: insilmaril@0: // Move CanvasView insilmaril@2: 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@2: 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@2: if (e->state() & Qt::ShiftModifier) insilmaril@0: { insilmaril@2: ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor()); insilmaril@2: ((BranchObj*)selection)->setLinkColor (); insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@2: ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor()); insilmaril@2: ((BranchObj*)selection)->setLinkColor (); insilmaril@0: } insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@2: insilmaril@2: // Have we been drawing a link? insilmaril@2: if (drawingLink) insilmaril@2: { insilmaril@2: drawingLink=false; insilmaril@2: // Check if we are over another branch insilmaril@2: dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL); insilmaril@2: if (dst && selection) insilmaril@2: { insilmaril@2: tmpXLink->setEnd ( ((BranchObj*)(dst)) ); insilmaril@2: tmpXLink->updateXLink(); insilmaril@2: tmpXLink->activate(); insilmaril@16: saveStateComplete(QString("Activate xLink from %1 to %2").arg(getName(tmpXLink->getBegin())).arg(getName(tmpXLink->getEnd())) ); //TODO undoCommand insilmaril@2: } else insilmaril@2: { insilmaril@2: delete(tmpXLink); insilmaril@2: tmpXLink=NULL; insilmaril@2: } insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@0: // Have we been moving something? insilmaril@0: if ( selection && movingObj ) insilmaril@0: { insilmaril@2: // Moved FloatObj? Maybe we need to reposition insilmaril@2: if(typeid(*selection)==typeid (FloatImageObj)) insilmaril@2: { insilmaril@20: FloatImageObj *fo=(FloatImageObj*)selection; insilmaril@20: QString pold=qpointToString(movingObj_orgRelPos); insilmaril@20: QString pnow=qpointToString(fo->getRelPos()); insilmaril@20: saveStateConstSelection( insilmaril@20: "moveRel "+pold, insilmaril@20: "moveRel "+pnow, insilmaril@20: QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow)); insilmaril@20: insilmaril@2: selection->getParObj()->requestReposition(); insilmaril@2: mapCenter->reposition(); insilmaril@2: } insilmaril@2: 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@2: ((LinkableMapObj*)selection) ); insilmaril@2: insilmaril@2: 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@2: ((LinkableMapObj*)selection)->unsetParObjTmp(); insilmaril@2: insilmaril@18: // For Redo we may need to save original selection insilmaril@20: QString preSelStr=selection->getSelectString(); insilmaril@2: insilmaril@2: copyingObj=false; insilmaril@0: if (dst ) insilmaril@2: { insilmaril@18: BranchObj* bsel=(BranchObj*)selection; insilmaril@18: BranchObj* bdst=(BranchObj*)dst; insilmaril@18: insilmaril@20: QString preParStr=(bsel->getParObj())->getSelectString(); insilmaril@20: QString preNum=QString::number (bsel->getNum(),10); insilmaril@20: QString preDstParStr; insilmaril@20: insilmaril@20: if (e->state() & Qt::ShiftModifier && dst->getParObj()) insilmaril@20: { // Link above dst insilmaril@20: preDstParStr=dst->getParObj()->getSelectString(); insilmaril@18: bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()); insilmaril@2: } else insilmaril@20: if (e->state() & Qt::ControlModifier && dst->getParObj()) insilmaril@20: { insilmaril@20: // Link below dst insilmaril@20: preDstParStr=dst->getParObj()->getSelectString(); insilmaril@18: bsel->moveBranchTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1); insilmaril@2: } else insilmaril@20: { // Append to dst insilmaril@20: preDstParStr=dst->getSelectString(); insilmaril@18: bsel->moveBranchTo (bdst,-1); insilmaril@20: if (dst->getDepth()==0) bsel->move (savePos); insilmaril@2: } insilmaril@20: QString postSelStr=selection->getSelectString(); insilmaril@20: QString postNum=QString::number (bsel->getNum(),10); insilmaril@20: insilmaril@20: QString undoCom="linkBranchToPos (\""+ insilmaril@20: preParStr+ "\"," + preNum +"," + insilmaril@20: QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; insilmaril@20: insilmaril@18: QString redoCom="linkBranchToPos (\""+ insilmaril@20: preDstParStr + "\"," + postNum + "," + insilmaril@20: QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; insilmaril@18: insilmaril@18: saveState ( insilmaril@20: postSelStr,undoCom, insilmaril@20: preSelStr, redoCom, insilmaril@18: QString("Relink %1 to %2").arg(getName(bsel)).arg(getName(dst)) ); insilmaril@2: } else insilmaril@2: if (selection->getDepth()==1) insilmaril@18: { insilmaril@18: // The select string might be different _after_ moving around. insilmaril@18: // Therefor reposition and then use string of old selection, too insilmaril@18: mapCenter->reposition(); insilmaril@18: insilmaril@20: QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() ); insilmaril@18: saveState( insilmaril@20: selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos), insilmaril@20: preSelStr, "moveRel "+ps, insilmaril@20: QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps)); insilmaril@2: insilmaril@18: } 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@19: insilmaril@19: // Just make sure, that actions are still ok,e.g. the move branch up/down buttons... insilmaril@19: updateActions(); insilmaril@0: } else insilmaril@2: // maybe we moved View: set old cursor insilmaril@2: setCursor (Qt::ArrowCursor); insilmaril@2: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e) insilmaril@0: { insilmaril@2: 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@17: mainWindow->editHeading(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::resizeEvent (QResizeEvent* e) insilmaril@0: { insilmaril@2: Q3CanvasView::resizeEvent( e ); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@2: void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) insilmaril@2: { insilmaril@2: insilmaril@2: // for (unsigned int i=0;event->format(i);i++) // Debug mime type insilmaril@2: // cerr << event->format(i) << endl; insilmaril@2: insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj))) { insilmaril@2: insilmaril@2: // If QImageDrag can decode mime type insilmaril@2: if (Q3ImageDrag::canDecode(event)) { insilmaril@2: event->accept(); insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@2: // If image are dragged from firefox insilmaril@2: if (event->provides("application/x-moz-file-promise-url") && insilmaril@2: event->provides("application/x-moz-nativeimage")) { insilmaril@2: event->accept(true); insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@2: // If QUriDrag can decode mime type insilmaril@2: if (Q3UriDrag::canDecode(event)) { insilmaril@2: event->accept(); insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@2: // If Uri are dragged from firefox insilmaril@2: if (event->provides("_NETSCAPE_URL")){ insilmaril@2: event->accept(); insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@2: // If QTextDrag can decode mime type insilmaril@2: if (Q3TextDrag::canDecode(event)) { insilmaril@2: event->accept(); insilmaril@2: return; insilmaril@2: } insilmaril@2: insilmaril@2: } insilmaril@2: event->ignore(); insilmaril@2: } insilmaril@2: insilmaril@2: bool isUnicode16(const QByteArray &d) insilmaril@2: { insilmaril@2: // TODO: make more precise check for unicode 16. insilmaril@2: // Guess unicode16 if any of second bytes are zero insilmaril@2: unsigned int length = max(0,d.size()-2)/2; insilmaril@2: for (unsigned int i = 0; iprovides("image/png")) insilmaril@2: { insilmaril@2: QPixmap pix; insilmaril@2: if (Q3ImageDrag::decode(event, pix)) insilmaril@2: { insilmaril@2: addFloatImage(pix); insilmaril@2: event->accept(); insilmaril@2: update=true; insilmaril@2: } else insilmaril@2: event->ignore(); insilmaril@2: insilmaril@2: } else if (event->provides("application/x-moz-file-promise-url") && insilmaril@2: event->provides("application/x-moz-nativeimage")) insilmaril@2: { insilmaril@2: // Contains url to the img src in unicode16 insilmaril@2: QByteArray d = event->encodedData("application/x-moz-file-promise-url"); insilmaril@2: QString url = QString((const QChar*)d.data(),d.size()/2); insilmaril@2: fetchImage(url); insilmaril@2: event->accept(); insilmaril@2: update=true; insilmaril@2: } else if (event->provides ("text/uri-list")) insilmaril@2: { // Uris provided e.g. by konqueror insilmaril@2: Q3UriDrag::decode (event,uris); insilmaril@2: } else if (event->provides ("_NETSCAPE_URL")) insilmaril@2: { // Uris provided by Mozilla insilmaril@2: QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); insilmaril@2: uris.append(l[0]); insilmaril@2: heading = l[1]; insilmaril@2: } else if (event->provides("text/html")) { insilmaril@2: insilmaril@2: // Handels text mime types insilmaril@2: // Look like firefox allways handle text as unicode16 (2 bytes per char.) insilmaril@2: QByteArray d = event->encodedData("text/html"); insilmaril@2: QString text; insilmaril@2: if (isUnicode16(d)) insilmaril@2: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@2: else insilmaril@2: text = QString(d); insilmaril@2: insilmaril@2: textEditor->setText(text); insilmaril@2: insilmaril@2: event->accept(); insilmaril@2: update=true; insilmaril@2: } else if (event->provides("text/plain")) { insilmaril@2: QByteArray d = event->encodedData("text/plain"); insilmaril@2: QString text; insilmaril@2: if (isUnicode16(d)) insilmaril@2: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@2: else insilmaril@2: text = QString(d); insilmaril@2: insilmaril@2: textEditor->setText(text); insilmaril@2: insilmaril@2: event->accept(); insilmaril@2: update= true; insilmaril@2: } insilmaril@2: insilmaril@2: if (uris.count()>0) insilmaril@2: { insilmaril@2: QStringList files; insilmaril@2: QStringList urls; insilmaril@2: QString s; insilmaril@2: BranchObj *bo; insilmaril@2: for (const char* u=uris.first(); u; u=uris.next()) insilmaril@2: { insilmaril@2: bo=((BranchObj*)selection)->addBranch(); insilmaril@2: if (bo) insilmaril@2: { insilmaril@2: s=Q3UriDrag::uriToLocalFile(u); insilmaril@2: if (!s.isEmpty()) insilmaril@2: { insilmaril@2: QString file = QDir::convertSeparators(s); insilmaril@2: heading = QFileInfo(file).baseName(); insilmaril@2: files.append(file); insilmaril@2: if (file.endsWith(".vym", false)) insilmaril@2: bo->setVymLink(file); insilmaril@2: else insilmaril@2: bo->setURL(u); insilmaril@2: } else insilmaril@2: { insilmaril@2: urls.append (u); insilmaril@2: bo->setURL(u); insilmaril@2: } insilmaril@2: insilmaril@2: if (!heading.isEmpty()) insilmaril@2: bo->setHeading(heading); insilmaril@2: else insilmaril@2: bo->setHeading(u); insilmaril@2: } insilmaril@2: } insilmaril@2: update=true; insilmaril@2: } insilmaril@2: insilmaril@2: if (update) insilmaril@2: { insilmaril@2: //FIXME saveState has to be called earlier for each of the drops... insilmaril@16: saveStateComplete("Drop Event"); //TODO undo Command insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: canvas()->update(); insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::addFloatImage(const QPixmap &img) insilmaril@2: { insilmaril@2: if (selection && insilmaril@2: (typeid(*selection) == typeid(BranchObj)) || insilmaril@2: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@2: { insilmaril@2: BranchObj *bo=((BranchObj*)selection); insilmaril@16: saveStatePart(selection,QString("Add floatimage to %1").arg(getName(bo))); insilmaril@2: //QString fn=fd->selectedFile(); insilmaril@2: //lastImageDir=fn.left(fn.findRev ("/")); insilmaril@2: bo->addFloatImage(); insilmaril@2: // FIXME check if load was successful insilmaril@2: bo->getLastFloatImage()->load(img); insilmaril@2: //bo->getLastFloatImage()->setOriginalFilename(fn); insilmaril@2: mapCenter->reposition(); insilmaril@2: adjustCanvasSize(); insilmaril@2: canvas()->update(); insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: insilmaril@2: void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/) insilmaril@2: { insilmaril@2: if (!imageBuffer) imageBuffer = new QBuffer(); insilmaril@2: if (!imageBuffer->isOpen()) { insilmaril@2: imageBuffer->open(QIODevice::WriteOnly | QIODevice::Append); insilmaril@2: } insilmaril@2: imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a)); insilmaril@2: } insilmaril@2: insilmaril@2: insilmaril@2: void MapEditor::imageDataFinished(Q3NetworkOperation *nop) insilmaril@2: { insilmaril@2: if (nop->state()==Q3NetworkProtocol::StDone) { insilmaril@2: QPixmap img(imageBuffer->buffer()); insilmaril@2: addFloatImage(img); insilmaril@2: } insilmaril@2: insilmaril@2: if (imageBuffer) { insilmaril@2: imageBuffer->close(); insilmaril@2: if (imageBuffer) { insilmaril@2: imageBuffer->close(); insilmaril@2: delete imageBuffer; insilmaril@2: imageBuffer = 0; insilmaril@2: } insilmaril@2: } insilmaril@2: } insilmaril@2: insilmaril@2: void MapEditor::fetchImage(const QString &url) insilmaril@2: { insilmaril@2: if (urlOperator) { insilmaril@2: urlOperator->stop(); insilmaril@2: disconnect(urlOperator); insilmaril@2: delete urlOperator; insilmaril@2: } insilmaril@2: insilmaril@2: urlOperator = new Q3UrlOperator(url); insilmaril@2: connect(urlOperator, SIGNAL(finished(Q3NetworkOperation *)), insilmaril@2: this, SLOT(imageDataFinished(Q3NetworkOperation*))); insilmaril@2: insilmaril@2: connect(urlOperator, SIGNAL(data(const QByteArray &, Q3NetworkOperation *)), insilmaril@2: this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *))); insilmaril@2: urlOperator->get(); insilmaril@2: }