insilmaril@0: #include "mapeditor.h" insilmaril@0: insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@119: #include insilmaril@119: #include insilmaril@119: #include insilmaril@129: #include insilmaril@0: insilmaril@0: #include insilmaril@95: #include insilmaril@0: #include insilmaril@0: insilmaril@0: #include "version.h" insilmaril@0: insilmaril@105: #include "api.h" insilmaril@0: #include "xml.h" insilmaril@0: #include "texteditor.h" insilmaril@0: #include "linkablemapobj.h" insilmaril@0: #include "exports.h" insilmaril@0: #include "misc.h" insilmaril@0: #include "mainwindow.h" insilmaril@0: #include "extrainfodialog.h" insilmaril@95: #include "editxlinkdialog.h" insilmaril@0: #include "settings.h" insilmaril@0: insilmaril@0: #include "icons/flag-note.xpm" insilmaril@0: #include "icons/flag-url.xpm" insilmaril@0: #include "icons/flag-vymlink.xpm" insilmaril@0: #include "icons/flag-scrolled-right.xpm" insilmaril@0: #include "icons/flag-tmpUnscrolled-right.xpm" insilmaril@0: #include "icons/flag-questionmark.xpm" insilmaril@0: #include "icons/flag-exclamationmark.xpm" insilmaril@0: #include "icons/flag-hook-green.xpm" insilmaril@0: #include "icons/flag-cross-red.xpm" insilmaril@0: #include "icons/flag-stopsign.xpm" insilmaril@0: #include "icons/flag-smiley-good.xpm" insilmaril@0: #include "icons/flag-smiley-sad.xpm" insilmaril@0: #include "icons/flag-clock.xpm" insilmaril@0: #include "icons/flag-lamp.xpm" insilmaril@0: #include "icons/flag-arrow-up.xpm" insilmaril@0: #include "icons/flag-arrow-down.xpm" insilmaril@0: #include "icons/flag-thumb-up.xpm" insilmaril@0: #include "icons/flag-thumb-down.xpm" insilmaril@0: #include "icons/flag-heart.xpm" insilmaril@0: #include "icons/flag-flash.xpm" insilmaril@0: #include "icons/flag-lifebelt.xpm" insilmaril@0: insilmaril@0: extern TextEditor *textEditor; insilmaril@0: extern int statusbarTime; insilmaril@0: extern Main *mainWindow; insilmaril@0: extern FlagRowObj *systemFlagsDefault; insilmaril@0: extern FlagRowObj *standardFlagsDefault; insilmaril@0: extern MapEditor *clipboardME; insilmaril@0: insilmaril@98: extern QPtrList actionListBranches; insilmaril@98: insilmaril@0: extern QAction *actionFileSave; insilmaril@0: extern QAction *actionEditUndo; 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@0: extern QAction *actionEditURL; insilmaril@0: extern QAction *actionEditHeading2URL; insilmaril@0: extern QAction *actionEditBugzilla2URL; insilmaril@0: extern QAction *actionEditOpenVymLink; insilmaril@0: extern QAction *actionEditVymLink; insilmaril@0: extern QAction *actionEditDeleteVymLink; insilmaril@0: extern QAction *actionEditHeading; insilmaril@0: extern QAction *actionEditDelete; insilmaril@0: extern QAction *actionEditAddBranch; insilmaril@0: extern QAction *actionEditAddBranchAbove; insilmaril@0: extern QAction *actionEditAddBranchBelow; insilmaril@98: extern QAction *actionEditRemoveBranchHere; insilmaril@98: extern QAction *actionEditRemoveChilds; insilmaril@0: extern QAction *actionEditImportAdd; insilmaril@0: extern QAction *actionEditImportReplace; insilmaril@0: extern QAction *actionEditSaveBranch; insilmaril@0: extern QAction *actionEditSelectFirst; insilmaril@0: extern QAction *actionEditSelectLast; insilmaril@0: extern QAction *actionEditLoadImage; insilmaril@0: extern QAction *actionEditToggleFloatExport; insilmaril@0: insilmaril@0: extern QAction* actionFormatPickColor; insilmaril@0: extern QAction* actionFormatColorBranch; insilmaril@0: extern QAction* actionFormatColorSubtree; insilmaril@0: extern QAction *actionFormatLinkColorHint; insilmaril@0: extern QAction *actionFormatBackColor; insilmaril@0: extern QAction *actionFormatLinkColor; insilmaril@0: insilmaril@89: extern QActionGroup* actionGroupModModes; insilmaril@89: extern QAction* actionModModeColor; insilmaril@89: extern QAction* actionModModeLink; insilmaril@93: extern QAction* actionModModeCopy; insilmaril@89: insilmaril@0: extern QActionGroup *actionGroupFormatFrameTypes; insilmaril@0: extern QAction *actionFormatFrameNone; insilmaril@0: extern QAction *actionFormatFrameRectangle; insilmaril@0: insilmaril@0: extern QActionGroup *actionGroupFormatLinkStyles; insilmaril@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@0: extern QAction *actionSettingsPasteNewHeading; insilmaril@103: extern QAction *actionSettingsUseFlagGroups; insilmaril@0: insilmaril@0: extern QPopupMenu *branchContextMenu; insilmaril@89: extern QPopupMenu *branchLinksContextMenu; insilmaril@94: extern QPopupMenu *branchLinksContextMenuDup; insilmaril@0: extern QPopupMenu *floatimageContextMenu; insilmaril@0: extern QPopupMenu *saveImageFormatMenu; insilmaril@0: extern QPopupMenu *exportImageFormatMenu; insilmaril@0: extern QPopupMenu *canvasContextMenu; insilmaril@0: insilmaril@0: extern Settings settings; insilmaril@0: insilmaril@0: insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: /////////////////////////////////////////////////////////////////////// insilmaril@0: MapEditor::MapEditor( insilmaril@0: QWidget* parent, bool interactive, const char* name, WFlags f) : insilmaril@119: QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0) insilmaril@0: { insilmaril@0: //cout << "Constructor ME "<setAcceptDrops(true); insilmaril@119: insilmaril@0: mapCanvas = new QCanvas(1000,800); insilmaril@0: mapCanvas->setAdvancePeriod(30); insilmaril@0: insilmaril@0: setCanvas (mapCanvas); insilmaril@0: insilmaril@0: setVScrollBarMode ( QScrollView::AlwaysOn ); insilmaril@0: setHScrollBarMode ( QScrollView::AlwaysOn ); insilmaril@0: insilmaril@0: // Now create the _global_ system flags _once_: insilmaril@0: // (Later all OrnamentedObj copy from this insilmaril@0: // and set their own canvas) insilmaril@0: if (!systemFlagsDefault) insilmaril@0: { insilmaril@0: systemFlagsDefault = new FlagRowObj (mapCanvas); insilmaril@0: systemFlagsDefault->setVisibility (false); insilmaril@0: systemFlagsDefault->setName ("systemFlagsDef"); insilmaril@0: insilmaril@0: FlagObj *fo = new FlagObj (mapCanvas); insilmaril@0: fo->load(QPixmap(flag_note_xpm)); insilmaril@0: fo->setName("note"); insilmaril@93: fo->setToolTip(tr("Note","Systemflag")); insilmaril@0: systemFlagsDefault->addFlag (fo); // makes deep copy insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_url_xpm)); insilmaril@0: fo->setName("url"); insilmaril@93: fo->setToolTip(tr("WWW Document (external)","Systemflag")); insilmaril@0: systemFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_vymlink_xpm)); insilmaril@0: fo->setName("vymLink"); insilmaril@93: fo->setToolTip(tr("Link to another vym map","Systemflag")); insilmaril@0: systemFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_scrolled_right_xpm)); insilmaril@0: fo->setName("scrolledright"); insilmaril@93: fo->setToolTip(tr("subtree is scrolled","Systemflag")); insilmaril@0: systemFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_tmpUnscrolled_right_xpm)); insilmaril@0: fo->setName("tmpUnscrolledright"); insilmaril@93: fo->setToolTip(tr("subtree is temporary scrolled","Systemflag")); insilmaril@0: systemFlagsDefault->addFlag (fo); insilmaril@0: delete (fo); insilmaril@0: } insilmaril@0: if (!standardFlagsDefault) insilmaril@0: { insilmaril@0: standardFlagsDefault = new FlagRowObj (mapCanvas); insilmaril@0: standardFlagsDefault->setVisibility (false); insilmaril@0: standardFlagsDefault->setName ("standardFlagsDef"); insilmaril@0: insilmaril@0: FlagObj *fo = new FlagObj (mapCanvas); insilmaril@0: fo->load(QPixmap(flag_exclamationmark_xpm)); insilmaril@103: fo->setName ("exclamationmark"); insilmaril@103: fo->setGroup("standard-mark"); insilmaril@93: fo->setToolTip(tr("Take care!","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); // makes deep copy insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_questionmark_xpm)); insilmaril@0: fo->setName("questionmark"); insilmaril@103: fo->setGroup("standard-mark"); insilmaril@93: fo->setToolTip(tr("Really?","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_hook_green_xpm)); insilmaril@0: fo->setName("hook-green"); insilmaril@103: fo->setGroup("standard-hook"); insilmaril@93: fo->setToolTip(tr("ok!","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_cross_red_xpm)); insilmaril@0: fo->setName("cross-red"); insilmaril@103: fo->setGroup("standard-hook"); insilmaril@93: fo->setToolTip(tr("Not ok!","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_stopsign_xpm)); insilmaril@0: fo->setName("stopsign"); insilmaril@93: fo->setToolTip(tr("This won't work!","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_smiley_good_xpm)); insilmaril@0: fo->setName("smiley-good"); insilmaril@103: fo->setGroup("standard-smiley"); insilmaril@93: fo->setToolTip(tr("Good","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_smiley_sad_xpm)); insilmaril@0: fo->setName("smiley-sad"); insilmaril@103: fo->setGroup("standard-smiley"); insilmaril@93: fo->setToolTip(tr("Bad","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_clock_xpm)); insilmaril@0: fo->setName("clock"); insilmaril@93: fo->setToolTip(tr("Time critical","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_lamp_xpm)); insilmaril@0: fo->setName("lamp"); insilmaril@93: fo->setToolTip(tr("Idea!","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_arrow_up_xpm)); insilmaril@0: fo->setName("arrow-up"); insilmaril@103: fo->setGroup("standard-arrow"); insilmaril@93: fo->setToolTip(tr("Important","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_arrow_down_xpm)); insilmaril@0: fo->setName("arrow-down"); insilmaril@103: fo->setGroup("standard-arrow"); insilmaril@93: fo->setToolTip(tr("Unimportant","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_thumb_up_xpm)); insilmaril@0: fo->setName("thumb-up"); insilmaril@103: fo->setGroup("standard-thumb"); insilmaril@93: fo->setToolTip(tr("I like this","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_thumb_down_xpm)); insilmaril@0: fo->setName("thumb-down"); insilmaril@103: fo->setGroup("standard-thumb"); insilmaril@103: fo->setToolTip(tr("I like this","Standardflag")); insilmaril@93: fo->setToolTip(tr("I do not like this","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_heart_xpm)); insilmaril@0: fo->setName("heart"); insilmaril@93: fo->setToolTip(tr("I just love... ","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_flash_xpm)); insilmaril@0: fo->setName("flash"); insilmaril@93: fo->setToolTip(tr("Dangerous","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_lifebelt_xpm)); insilmaril@0: fo->setName("lifebelt"); insilmaril@93: fo->setToolTip(tr("This will help","Standardflag")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: delete (fo); insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: mapCenter = new MapCenterObj(mapCanvas); insilmaril@0: mapCenter->setVisibility (true); insilmaril@0: mapCenter->setMapEditor (this); insilmaril@93: mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map")); insilmaril@0: insilmaril@0: printer=NULL; insilmaril@0: insilmaril@0: lineedit = new QLineEdit(this, "lineedit" ); insilmaril@0: connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) ); insilmaril@0: lineedit->hide(); insilmaril@0: insilmaril@0: actColor=black; setColor (actColor); insilmaril@97: defLinkColor=QColor (0,0,255); insilmaril@97: defXLinkColor=QColor (180,180,180); insilmaril@0: linkcolorhint=DefaultColor; insilmaril@0: linkstyle=StylePolyParabel; insilmaril@0: mapCanvas->setBackgroundColor (white); insilmaril@0: insilmaril@0: // Create bitmap cursors, patform dependant insilmaril@0: #if defined(Q_OS_MACX) insilmaril@0: #include "icons/cursorhandopen16.xpm" insilmaril@0: #include "icons/cursorcolorpicker16.xpm" insilmaril@0: QBitmap cb( 16, 16, chandopen, TRUE ); insilmaril@0: QBitmap cm( 16, 16, chandopenmask, TRUE ); insilmaril@0: handOpenCursor=QCursor ( cb, cm ); insilmaril@0: // set hot spot to tip of picker insilmaril@0: pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 ); insilmaril@0: #else insilmaril@0: #include "icons/cursorhandopen.xpm" insilmaril@0: #include "icons/cursorcolorpicker.xpm" insilmaril@0: insilmaril@0: QBitmap cb( 32, 32, chandopen, TRUE ); insilmaril@0: QBitmap cm( 32, 32, chandopenmask, TRUE ); insilmaril@0: handOpenCursor=QCursor ( cb, cm ); insilmaril@0: // set hot spot to tip of picker insilmaril@0: pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 ); insilmaril@0: #endif insilmaril@0: insilmaril@0: pickingColor=false; insilmaril@91: drawingLink=false; insilmaril@93: copyingObj=false; insilmaril@0: insilmaril@0: editingBO=NULL; insilmaril@0: selection=NULL; insilmaril@0: selectionLast=NULL; insilmaril@0: movingObj=NULL; insilmaril@0: insilmaril@102: defXLinkWidth=1; insilmaril@102: defXLinkColor=QColor (230,230,230); insilmaril@102: insilmaril@0: mapChanged=false; insilmaril@0: mapDefault=true; insilmaril@0: mapUnsaved=false; insilmaril@0: insilmaril@0: zipped=true; insilmaril@0: filePath=""; insilmaril@0: fileName="unnamed"; insilmaril@0: mapName=""; insilmaril@0: insilmaril@0: // Initialize find routine insilmaril@0: itFind=NULL; insilmaril@0: EOFind=false; insilmaril@0: insilmaril@0: printFrame=true; insilmaril@0: printFooter=true; insilmaril@0: insilmaril@139: blockReposition=false; insilmaril@139: blockSaveState=false; insilmaril@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@0: mapCenter->reposition(); // for positioning heading insilmaril@0: } insilmaril@0: insilmaril@0: MapEditor::~MapEditor() insilmaril@0: { insilmaril@119: if (imageBuffer) delete imageBuffer; insilmaril@119: if (urlOperator) { insilmaril@119: urlOperator->stop(); insilmaril@119: delete urlOperator; insilmaril@119: } insilmaril@119: insilmaril@0: //cout <<"Destructor MapEditor\n"; insilmaril@0: if (isInteractive) delTmpDirs(); insilmaril@0: insilmaril@0: // Save Settings insilmaril@0: //settings.writeEntry( "/vym/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@0: QCanvas* 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@0: insilmaril@0: // scroll the view (in order to not move map on screen) insilmaril@0: scrollBy (dx,dy); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@139: bool MapEditor::isRepositionBlocked() insilmaril@0: { insilmaril@139: return blockReposition; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::makeTmpDirs() insilmaril@0: { insilmaril@0: // Create unique temporary directories insilmaril@0: char tmpdir[]="/tmp/vym-XXXXXX"; insilmaril@0: bakMapDir=mkdtemp(tmpdir); insilmaril@0: makeSubDirs(bakMapDir); insilmaril@106: // FIXME set permissions and maybe use QT method for portability insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::delTmpDirs() insilmaril@0: { insilmaril@0: //FIXME delete tmp directory, better use QT methods here: insilmaril@0: system ( "rm -rf "+ bakMapDir ); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::makeSubDirs(const QString &s) insilmaril@0: { insilmaril@0: QDir d(s); insilmaril@0: d.mkdir ("images"); insilmaril@0: d.mkdir ("flags"); insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@106: QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection) insilmaril@0: { insilmaril@0: // tmpdir temporary directory to which data will be writte 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: // completeMap if false, only vympart will be written, without insilmaril@0: // mapcenter 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@0: QString mapAttr=attribut("version",__VYM_VERSION__); insilmaril@106: if (!saveSelection) insilmaril@0: mapAttr+= attribut("author",mapCenter->getAuthor()) + insilmaril@0: attribut("comment",mapCenter->getComment()) + insilmaril@0: attribut("date",mapCenter->getDate()) + insilmaril@0: attribut("backgroundColor", mapCanvas->backgroundColor().name() ) + insilmaril@0: attribut("linkStyle", ls ) + insilmaril@97: attribut("linkColor", defLinkColor.name() ) + insilmaril@102: attribut("defXLinkColor", defXLinkColor.name() ) + insilmaril@102: attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) + insilmaril@0: colhint; insilmaril@0: s+=beginElement("vymmap",mapAttr); insilmaril@0: incIndent(); insilmaril@0: insilmaril@0: // Find the used flags while traversing the tree insilmaril@0: standardFlagsDefault->resetUsedCounter(); insilmaril@0: insilmaril@0: // Build xml recursivly insilmaril@106: if (!saveSelection) insilmaril@0: s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset); insilmaril@0: else insilmaril@0: { insilmaril@106: if ( typeid(*saveSelection) == typeid(BranchObj) ) insilmaril@106: s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset); insilmaril@94: else insilmaril@94: if (selection && typeid(*selection)==typeid(BranchObj)) insilmaril@106: // This is used if selected branch is saved from mainwindow insilmaril@94: 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@139: if (selection && !saveSelection ) 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@0: void MapEditor::saveState() insilmaril@0: { insilmaril@139: saveState (CompleteMap,NULL,"",""); insilmaril@0: } insilmaril@0: insilmaril@106: void MapEditor::saveState(LinkableMapObj *undoSel) insilmaril@0: { insilmaril@139: saveState (PartOfMap,undoSel,"",""); insilmaril@105: } insilmaril@105: insilmaril@139: void MapEditor::saveState(const QString & uc, const QString &rc) insilmaril@105: { insilmaril@136: LinkableMapObj *undoSel; insilmaril@136: if (selection) insilmaril@136: undoSel=selection; insilmaril@136: else insilmaril@136: undoSel=NULL; insilmaril@139: saveState (UndoCommand,undoSel,uc,rc); insilmaril@106: } insilmaril@106: insilmaril@139: void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, const QString &redoCom) insilmaril@106: { insilmaril@139: if (blockSaveState) return; insilmaril@139: insilmaril@131: setChanged(); insilmaril@136: insilmaril@139: // Save current selection insilmaril@139: redoCommand=redoCom; insilmaril@139: if (selection) insilmaril@139: redoSelection=selection->getSelectString(); insilmaril@139: else insilmaril@139: redoSelection=""; insilmaril@139: insilmaril@139: // Save the object, which should be undone insilmaril@136: if (undoSel) insilmaril@136: undoSelection=undoSel->getSelectString(); insilmaril@136: else insilmaril@136: undoSelection=""; insilmaril@136: insilmaril@136: // Save depending on how much needs to be saved insilmaril@106: if (savemode==UndoCommand) insilmaril@0: { insilmaril@105: undoCommand=undoCom; insilmaril@106: backupXML=""; insilmaril@106: } insilmaril@106: else if (savemode==PartOfMap && undoSel) insilmaril@0: { insilmaril@136: undoCommand="undoPart (\""+undoSelection+"\")"; insilmaril@106: backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel); insilmaril@106: } else insilmaril@106: { insilmaril@106: undoCommand="undoMap ()"; insilmaril@106: backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL); insilmaril@139: undoSelection=""; insilmaril@106: } insilmaril@106: /* FIXME testing insilmaril@106: cout << "ME::saveState()\n"; insilmaril@106: cout << " undoCom="<findObjBySelect (s); insilmaril@129: if (dst) insilmaril@129: { insilmaril@129: if (typeid(*dst) == typeid(BranchObj) ) insilmaril@139: { insilmaril@139: // Get number in parent insilmaril@139: x=api.parInt (ok,1); insilmaril@139: if (ok) insilmaril@139: ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),x); insilmaril@139: } else if (typeid(*dst) == typeid(MapCenterObj) ) insilmaril@129: { insilmaril@129: ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); insilmaril@139: // Get coordinates of mainbranch insilmaril@129: x=api.parInt (ok,2); insilmaril@129: if (ok) insilmaril@129: { insilmaril@129: y=api.parInt (ok,3); insilmaril@129: if (ok) ((BranchObj*)(selection))->move (x,y); insilmaril@129: } insilmaril@129: } insilmaril@129: } insilmaril@129: } insilmaril@129: } insilmaril@129: } else if (com=="setHeading") insilmaril@129: { insilmaril@129: if (api.checkParamCount(1)) insilmaril@129: { insilmaril@129: s=api.parString (ok,0); insilmaril@129: if (ok) setHeading (s); insilmaril@129: } insilmaril@143: } else if (com=="setURL") insilmaril@143: { insilmaril@143: if (api.checkParamCount(1)) insilmaril@143: { insilmaril@143: s=api.parString (ok,0); insilmaril@143: if (ok) setURL(s); insilmaril@143: } insilmaril@143: } else if (com=="setVymLink") insilmaril@143: { insilmaril@143: if (api.checkParamCount(1)) insilmaril@143: { insilmaril@143: s=api.parString (ok,0); insilmaril@143: if (ok) setVymLink(s); insilmaril@143: } insilmaril@143: } insilmaril@143: insilmaril@106: // Internal commands, used for undo etc. insilmaril@129: else if (com==QString("undoMap")) insilmaril@139: { insilmaril@139: if (api.checkParamCount(0)) insilmaril@139: undoXML(""); insilmaril@139: } else if (com==QString("undoPart")) insilmaril@129: { insilmaril@129: if (api.checkParamCount(1)) insilmaril@129: { insilmaril@129: s=api.parString (ok,0); insilmaril@129: undoXML(s); insilmaril@129: } insilmaril@129: } else if (com=="select") insilmaril@129: if (api.checkParamCount(1)) insilmaril@129: { insilmaril@129: s=api.parString(ok,0); insilmaril@129: if (ok) select (s); insilmaril@129: } insilmaril@106: else insilmaril@129: api.setError ("Unknown command in: "+atom); insilmaril@129: insilmaril@129: // Any errors? insilmaril@129: if (api.error()) insilmaril@106: { insilmaril@106: cout << "MapEditor::parseAtom: Error!\n"; insilmaril@129: cout << " "<setFocus() insilmaril@0: insilmaril@0: if (editingBO!=NULL) insilmaril@0: { insilmaril@0: editingBO->setHeading(lineedit->text() ); insilmaril@0: editingBO=NULL; insilmaril@0: lineedit->releaseKeyboard(); insilmaril@0: lineedit->hide(); insilmaril@0: parentWidget()->setFocus(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: 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: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); 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@106: if (fname.isEmpty()) insilmaril@106: { insilmaril@106: filePath=""; insilmaril@106: fileName=""; insilmaril@106: destPath=""; insilmaril@106: } else insilmaril@106: { insilmaril@106: filePath=fname; // becomes absolute path insilmaril@106: fileName=fname; // gets stripped of path insilmaril@106: destPath=destname; // needed for vymlinks insilmaril@106: insilmaril@106: // If fname is not an absolute path, complete it insilmaril@106: filePath=QDir(fname).absPath(); insilmaril@106: fileDir=filePath.left (1+filePath.findRev ("/")); insilmaril@106: insilmaril@106: // Set short name, too. Search from behind: insilmaril@106: int i=fileName.findRev("/"); insilmaril@106: if (i>=0) fileName=fileName.remove (0,i+1); insilmaril@106: insilmaril@106: // Forget the .vym (or .xml) for name of map insilmaril@106: mapName=fileName.left(fileName.findRev(".",-1,true) ); insilmaril@106: } insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getFilePath() insilmaril@0: { insilmaril@0: return filePath; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getFileName() insilmaril@0: { insilmaril@0: return fileName; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getMapName() insilmaril@0: { insilmaril@0: return mapName; insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getDestPath() insilmaril@0: { insilmaril@0: return destPath; insilmaril@0: } insilmaril@0: insilmaril@0: int MapEditor::load (QString &fname, const LoadMode &lmode) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: int returnCode=0; 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@106: saveState(selection); 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@0: returnCode=1; insilmaril@0: } else insilmaril@0: { insilmaril@139: blockReposition=true; insilmaril@0: QXmlInputSource source( file); insilmaril@0: QXmlSimpleReader reader; insilmaril@0: reader.setContentHandler( &handler ); insilmaril@0: reader.setErrorHandler( &handler ); insilmaril@0: handler.setMapEditor( this ); insilmaril@0: handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path insilmaril@0: handler.setLoadMode (lmode); insilmaril@0: bool ok = reader.parse( source ); insilmaril@139: blockReposition=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@0: return returnCode; insilmaril@0: } insilmaril@0: insilmaril@0: int MapEditor::save (const SaveMode &savemode) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: int returnCode=0; insilmaril@0: insilmaril@106: // The SaveMode UndoCommand is not supported here insilmaril@106: if (savemode==UndoCommand) return 1; insilmaril@106: insilmaril@0: // Create mapName and fileDir insilmaril@0: makeSubDirs (fileDir); insilmaril@0: QString fname; insilmaril@0: if (saveZipped()) insilmaril@0: // save as .xml insilmaril@0: fname=mapName+".xml"; insilmaril@0: else insilmaril@0: // use name given by user, even if he chooses .doc insilmaril@0: fname=fileName; insilmaril@0: insilmaril@0: insilmaril@0: // Check if fname is writeable insilmaril@0: QFile file( fileDir+fname); insilmaril@0: if (!file.open( IO_WriteOnly ) ) insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Save Error" ), insilmaril@0: tr("Couldn't write to ") +fileDir+fname); insilmaril@0: return 1; insilmaril@0: } insilmaril@0: file.close(); insilmaril@0: insilmaril@0: QString saveFile; insilmaril@106: if (savemode==CompleteMap || selection==NULL) insilmaril@106: saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL); insilmaril@106: else insilmaril@106: saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection); insilmaril@0: insilmaril@0: file.setName ( fileDir + fname); insilmaril@0: if ( !file.open( IO_WriteOnly ) ) insilmaril@0: { insilmaril@0: // This should neverever happen insilmaril@94: QMessageBox::critical(0, tr("Critcal Save error"),"MapEditor::save() Couldn't open "+file.name()); insilmaril@0: return 1; 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: 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: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if ( !printer ) insilmaril@0: { insilmaril@0: printer = new QPrinter; insilmaril@0: printer->setColorMode (QPrinter::Color); insilmaril@119: printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName())); 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@0: QPaintDeviceMetrics metrics (printer); insilmaril@0: insilmaril@0: double paperAspect = (double)metrics.width() / (double)metrics.height(); insilmaril@0: double mapAspect = (double)totalBBox.width() / (double)totalBBox.height(); insilmaril@0: insilmaril@102: QRect mapRect=totalBBox; insilmaril@0: QCanvasRectangle *frame=NULL; insilmaril@0: QCanvasText *footerFN=NULL; insilmaril@0: QCanvasText *footerDate=NULL; insilmaril@0: if (printFrame || printFooter) insilmaril@0: { insilmaril@0: insilmaril@0: if (printFrame) insilmaril@0: { insilmaril@0: // Print frame around map insilmaril@102: mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, insilmaril@102: totalBBox.width()+20, totalBBox.height()+20); insilmaril@0: frame=new QCanvasRectangle (mapRect,mapCanvas); insilmaril@0: frame->setBrush (QColor(white)); insilmaril@0: frame->setPen (QColor(black)); insilmaril@0: frame->setZ(0); insilmaril@0: frame->show(); insilmaril@0: } insilmaril@102: /* FIXME testing insilmaril@102: QCanvasLine *l=new QCanvasLine (mapCanvas); insilmaril@102: l->setPoints (0,0,mapRect.width(),mapRect.height()); insilmaril@102: l->setPen (QPen(QColor(black), 1)); insilmaril@102: l->setZ (200); insilmaril@102: l->show(); insilmaril@131: */ insilmaril@102: insilmaril@0: if (printFooter) insilmaril@0: { insilmaril@0: // Print footer below map insilmaril@0: QFont font; insilmaril@0: font.setPointSize(10); insilmaril@0: footerFN=new QCanvasText (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@0: footerDate=new QCanvasText (mapCanvas); insilmaril@0: footerDate->setText (QDate::currentDate().toString(Qt::TextDate)); insilmaril@0: footerDate->setFont(font); insilmaril@0: footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() ); insilmaril@0: footerDate->setZ(Z_TEXT); insilmaril@0: footerDate->show(); insilmaril@0: } insilmaril@102: pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20); insilmaril@0: } else insilmaril@0: { insilmaril@0: pp.setWindow (mapRect); insilmaril@0: } insilmaril@0: insilmaril@0: if (mapAspect>=paperAspect) insilmaril@0: { insilmaril@0: // Fit horizontally to paper width insilmaril@0: pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) ); insilmaril@0: } else insilmaril@0: { insilmaril@0: // Fit vertically to paper height insilmaril@0: pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height()); insilmaril@0: } insilmaril@0: insilmaril@0: mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer insilmaril@0: insilmaril@0: // Delete Frame and footer insilmaril@0: if (footerFN) insilmaril@0: { insilmaril@0: delete (footerFN); insilmaril@0: delete (footerDate); insilmaril@0: } insilmaril@0: if (frame) delete (frame); insilmaril@0: insilmaril@0: // Restore selection insilmaril@0: if (oldselection) insilmaril@0: { insilmaril@0: selection=oldselection; insilmaril@0: selection->select(); insilmaril@0: } insilmaril@119: insilmaril@119: // Save settings in vymrc insilmaril@119: settings.writeEntry("/vym/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@0: void MapEditor::exportImage(QString fn) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: QPixmap pix (getPixmap()); insilmaril@0: pix.save(fn, "PNG"); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::exportImage(QString fn, int item) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: QPixmap pix (getPixmap()); insilmaril@0: pix.save(fn, exportImageFormatMenu->text(item) ); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::exportASCII() insilmaril@0: { insilmaril@0: // FIXME still experimental insilmaril@131: Export ex; insilmaril@131: ex.setMapCenter(mapCenter); insilmaril@131: insilmaril@0: QFileDialog *fd=new QFileDialog( this, tr("VYM - Export (ASCII)")); insilmaril@0: fd->addFilter ("TXT (*.txt)"); insilmaril@0: fd->setCaption("VYM - Export (ASCII) (still experimental)"); insilmaril@0: fd->setMode( QFileDialog::AnyFile ); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: if (QFile (fd->selectedFile()).exists() ) insilmaril@0: { insilmaril@0: QMessageBox mb( "VYM", insilmaril@0: tr("The file ") + fd->selectedFile() + insilmaril@0: tr(" exists already. Do you want to overwrite it?"), insilmaril@0: QMessageBox::Warning, insilmaril@0: QMessageBox::Yes | QMessageBox::Default, insilmaril@0: QMessageBox::Cancel | QMessageBox::Escape, insilmaril@0: QMessageBox::NoButton ); insilmaril@0: insilmaril@0: mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); insilmaril@0: mb.setButtonText( QMessageBox::No, tr("Cancel")); insilmaril@0: Export ex; insilmaril@0: switch( mb.exec() ) insilmaril@0: { insilmaril@0: case QMessageBox::Yes: insilmaril@0: // save insilmaril@0: break;; insilmaril@0: case QMessageBox::Cancel: insilmaril@131: // return, do nothing insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@0: ex.setPath (fd->selectedFile() ); insilmaril@0: ex.exportMap(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::exportXML(const QString &dir) insilmaril@0: { insilmaril@0: // Create subdirectories insilmaril@0: makeSubDirs (dir); insilmaril@0: insilmaril@0: // write to directory insilmaril@106: QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL); insilmaril@0: QFile file; insilmaril@0: insilmaril@0: file.setName ( dir + "/"+mapName+".xml"); insilmaril@0: if ( !file.open( IO_WriteOnly ) ) insilmaril@0: { insilmaril@0: // This should neverever happen insilmaril@0: QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open ")+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@0: } insilmaril@0: insilmaril@0: void MapEditor::clear() insilmaril@0: { insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=NULL; insilmaril@0: } insilmaril@0: insilmaril@0: mapCenter->clear(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::copy() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@0: BranchObj* to; insilmaril@0: BranchObj* from; insilmaril@0: clipboardME->clear(); insilmaril@0: clipboardME->getMapCenter()->addBranch(); insilmaril@0: to=clipboardME->getMapCenter()->getLastBranch(); insilmaril@0: if (to) insilmaril@0: { insilmaril@0: from=(BranchObj*)(selection); insilmaril@0: to->copy(from); insilmaril@0: insilmaril@0: // keep position relative to parent insilmaril@0: to->move2RelPos ( from->getRelPos()); insilmaril@0: insilmaril@0: // select data in clipboard insilmaril@0: clipboardME->select ("bo:0"); insilmaril@0: insilmaril@0: // repositioning makes testing nicer, insilmaril@0: // but is not needed usually: insilmaril@0: if (clipboardME->isVisible()) insilmaril@0: { insilmaril@0: clipboardME->getMapCenter()->reposition(); insilmaril@0: } insilmaril@0: else insilmaril@0: clipboardME->hide(); insilmaril@0: } insilmaril@0: } insilmaril@0: if (typeid(*selection) == typeid(FloatImageObj) ) insilmaril@0: { insilmaril@0: FloatImageObj* to; insilmaril@0: FloatImageObj* from; insilmaril@0: clipboardME->clear(); insilmaril@0: clipboardME->getMapCenter()->addFloatImage(); insilmaril@0: to=clipboardME->getMapCenter()->getLastFloatImage(); insilmaril@0: if (to) insilmaril@0: { insilmaril@0: from=(FloatImageObj*)(selection); insilmaril@0: to->copy(from); insilmaril@0: insilmaril@0: // select data in clipboard insilmaril@0: clipboardME->select ("fi:0"); insilmaril@0: insilmaril@0: // repositioning makes testing nicer, insilmaril@0: // but is not needed usually: insilmaril@0: if (clipboardME->isVisible()) insilmaril@0: { insilmaril@0: clipboardME->getMapCenter()->reposition(); insilmaril@0: } insilmaril@0: else insilmaril@0: clipboardME->hide(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@106: void MapEditor::undo() insilmaril@106: { insilmaril@106: // Finish open lineEdits insilmaril@106: if (lineedit) finishedLineEditNoSave(); insilmaril@106: insilmaril@136: // select object before undo insilmaril@136: if (!undoSelection.isEmpty()) insilmaril@136: select (undoSelection); insilmaril@136: insilmaril@106: parseAtom (undoCommand); insilmaril@106: mapCenter->reposition(); insilmaril@106: insilmaril@106: // Undo not longer available now insilmaril@106: actionEditUndo->setEnabled (false); insilmaril@106: mapChanged=false; insilmaril@106: insilmaril@139: if (!redoSelection.isEmpty()) insilmaril@139: select (redoSelection); insilmaril@106: } insilmaril@106: insilmaril@106: void MapEditor::undoXML(const QString &undoSel) insilmaril@106: { insilmaril@106: QDir d; insilmaril@106: d.setPath(bakMapDir); insilmaril@106: if (d.exists() ) insilmaril@106: { insilmaril@106: // We need to parse saved XML data insilmaril@106: mapBuilderHandler handler; insilmaril@106: QXmlInputSource source; insilmaril@106: source.setData(backupXML); insilmaril@106: QXmlSimpleReader reader; insilmaril@106: reader.setContentHandler( &handler ); insilmaril@106: reader.setErrorHandler( &handler ); insilmaril@106: handler.setMapEditor( this ); insilmaril@106: handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path insilmaril@106: if (undoSel.isEmpty()) insilmaril@106: { insilmaril@139: unselect(); insilmaril@106: mapCenter->clear(); insilmaril@106: handler.setLoadMode (NewMap); insilmaril@106: } else insilmaril@106: { insilmaril@106: select (undoSel); insilmaril@106: handler.setLoadMode (ImportReplace); insilmaril@106: } insilmaril@139: blockReposition=true; insilmaril@139: blockSaveState=true; insilmaril@106: bool ok = reader.parse( source ); insilmaril@139: blockReposition=false; insilmaril@139: blockSaveState=false; insilmaril@106: if (! ok ) insilmaril@106: { insilmaril@106: // This should never ever happen insilmaril@106: QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), insilmaril@106: tr( handler.errorProtocol() )+" in "+backupXML ); insilmaril@106: } insilmaril@106: } else insilmaril@106: { insilmaril@106: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@106: "Temporary directory " +bakMapDir + insilmaril@106: tr (" used for undo is gone. \n" insilmaril@106: "I will create a new one, but at the moment no undo is available.\n" insilmaril@106: "Maybe you want to reload your original data.\n\n" insilmaril@106: "Sorry for any inconveniences.") ); insilmaril@106: makeTmpDirs(); insilmaril@106: } insilmaril@106: } insilmaril@106: insilmaril@0: LinkableMapObj* MapEditor::pasteNoSave() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: LinkableMapObj *fromLMO=clipboardME->getSelection(); insilmaril@0: LinkableMapObj *returnLMO=NULL; insilmaril@0: insilmaril@0: if (selection && fromLMO) insilmaril@0: { insilmaril@0: if (typeid(*fromLMO) == typeid(BranchObj) ) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(MapCenterObj)) insilmaril@0: { insilmaril@0: returnLMO=mapCenter->addBranch( (BranchObj*)(fromLMO) ); insilmaril@0: ((BranchObj*)(returnLMO))->move2RelPos(normalise(fromLMO->getRelPos() ) ); insilmaril@0: } insilmaril@0: if (typeid(*selection) == typeid(BranchObj)) insilmaril@0: returnLMO=((BranchObj*)(selection))->addBranch((BranchObj*)(fromLMO) ); insilmaril@0: } insilmaril@0: insilmaril@0: if (typeid(*fromLMO) == typeid(FloatImageObj) && insilmaril@0: (typeid(*selection) == typeid (BranchObj) || insilmaril@0: typeid(*selection)==typeid(MapCenterObj)) ) insilmaril@0: returnLMO=((BranchObj*) (selection))->addFloatImage ((FloatImageObj*)(fromLMO)); insilmaril@0: insilmaril@0: } insilmaril@0: return returnLMO; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cutNoSave() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@0: if (selection != NULL) { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@0: bo=(BranchObj*)(selection); insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@0: bo->unselect(); insilmaril@0: selection=NULL; insilmaril@0: par->removeBranch(bo); insilmaril@0: selection=par; insilmaril@0: selection->select(); insilmaril@0: } insilmaril@0: if (typeid(*selection) == typeid(FloatImageObj) ) insilmaril@0: { insilmaril@0: FloatImageObj* fio=(FloatImageObj*)(selection); insilmaril@0: par=(BranchObj*)(fio->getParObj()); insilmaril@0: fio->unselect(); insilmaril@0: selection=NULL; insilmaril@0: par->removeFloatImage(fio); insilmaril@0: selection=par; insilmaril@0: selection->select(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::paste() insilmaril@0: { insilmaril@106: saveState(selection); insilmaril@0: pasteNoSave(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cut() insilmaril@0: { insilmaril@106: saveState(selection->getParObj()); insilmaril@0: copy(); insilmaril@0: cutNoSave(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@130: void MapEditor::move(const int &x, const int &y) insilmaril@130: { insilmaril@130: // FIXME no saveState, because this is only internal at undo so far insilmaril@130: if (selection) selection->move(x,y); insilmaril@130: if (typeid(*selection) == typeid(FloatImageObj)) insilmaril@130: ((FloatImageObj*)(selection))->setRelPos(); insilmaril@130: } insilmaril@130: insilmaril@0: void MapEditor::moveBranchUp() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@0: bo=(BranchObj*)(selection); insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@0: selection->unselect(); insilmaril@0: selection=par->moveBranchUp (bo); insilmaril@0: selection->select(); insilmaril@139: saveState("moveBranchDown ()",bo->getSelectString()); insilmaril@0: mapCenter->reposition(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::moveBranchDown() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: BranchObj* bo; insilmaril@0: BranchObj* par; insilmaril@0: if (typeid(*selection) == typeid(BranchObj) ) insilmaril@0: { insilmaril@0: bo=(BranchObj*)(selection); insilmaril@0: par=(BranchObj*)(bo->getParObj()); insilmaril@0: selection->unselect(); insilmaril@0: selection=par->moveBranchDown(bo); insilmaril@0: selection->select(); insilmaril@139: saveState("moveBranchUp ()",bo->getSelectString()); insilmaril@0: mapCenter->reposition(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::editHeading() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@0: { insilmaril@139: editingBO=(BranchObj*)(selection); insilmaril@139: saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")",editingBO->getSelectString() ); insilmaril@0: insilmaril@0: ensureSelectionVisible(); insilmaril@93: QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y())); insilmaril@0: lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25); insilmaril@93: QString s=editingBO->getHeading(); insilmaril@0: lineedit->setText(s); insilmaril@0: lineedit->setCursorPosition(1); insilmaril@0: if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() ) insilmaril@0: lineedit->selectAll(); insilmaril@0: lineedit->show(); insilmaril@0: insilmaril@0: lineedit->grabKeyboard(); insilmaril@0: lineedit->setFocus(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@106: void MapEditor::setHeading(const QString &s) insilmaril@106: { insilmaril@106: // Internal function, no saveState needed insilmaril@106: if (selection && insilmaril@106: (typeid(*selection) == typeid(BranchObj) || insilmaril@106: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@106: { insilmaril@106: ((BranchObj*)(selection))->setHeading(s); insilmaril@106: mapCenter->reposition(); insilmaril@106: adjustCanvasSize(); insilmaril@106: ensureSelectionVisible(); insilmaril@106: } insilmaril@106: } insilmaril@106: insilmaril@143: void MapEditor::setURL (const QString &s) insilmaril@143: { insilmaril@143: // Internal function, no saveState needed insilmaril@143: if (selection && insilmaril@143: (typeid(*selection) == typeid(BranchObj) || insilmaril@143: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@143: { insilmaril@143: ((BranchObj*)(selection))->setURL(s); insilmaril@143: mapCenter->reposition(); insilmaril@143: adjustCanvasSize(); insilmaril@143: ensureSelectionVisible(); insilmaril@143: } insilmaril@143: } insilmaril@143: insilmaril@143: void MapEditor::setVymLink (const QString &s) insilmaril@143: { insilmaril@143: // Internal function, no saveState needed insilmaril@143: if (selection && insilmaril@143: (typeid(*selection) == typeid(BranchObj) || insilmaril@143: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@143: { insilmaril@143: ((BranchObj*)(selection))->setVymLink(s); insilmaril@143: mapCenter->reposition(); insilmaril@143: adjustCanvasSize(); insilmaril@143: ensureSelectionVisible(); insilmaril@143: } insilmaril@143: } insilmaril@143: insilmaril@0: void MapEditor::addNewBranch(int pos) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj) ) ) insilmaril@0: { insilmaril@143: saveState(selection); //FIXME undoCommand insilmaril@0: insilmaril@0: BranchObj* bo1 = (BranchObj*) (selection); insilmaril@0: bool wasScrolled=false; insilmaril@0: BranchObj *newbo=NULL; insilmaril@0: if (pos==0) insilmaril@0: { insilmaril@0: // save scroll state. If scrolled, automatically select insilmaril@0: // new branch in order to tmp unscroll parent... insilmaril@0: wasScrolled=bo1->isScrolled(); insilmaril@0: newbo=bo1->addBranch(); insilmaril@0: } else insilmaril@0: { insilmaril@0: BranchObj *parbo=(BranchObj*)(selection->getParObj()); insilmaril@0: if (parbo) insilmaril@0: { insilmaril@0: if (pos<0) insilmaril@0: // add above selection insilmaril@0: newbo=parbo->insertBranch(bo1->getNum()); insilmaril@0: else insilmaril@0: // add below selection insilmaril@0: newbo=parbo->insertBranch(bo1->getNum()+1); insilmaril@0: } else insilmaril@0: // This should not happen... insilmaril@0: return; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: LinkableMapObj *oldselection=selection; insilmaril@0: insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: if (actionSettingsAutoedit->isOn() || insilmaril@0: actionSettingsAutoselectHeading->isOn() ) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=newbo; insilmaril@0: selection->select(); insilmaril@0: if (actionSettingsPasteNewHeading->isOn() ) insilmaril@0: { insilmaril@0: BranchObj *bo2= (BranchObj*)(selection); insilmaril@0: bo2->setHeading(""); insilmaril@0: } insilmaril@0: if (actionSettingsAutoedit->isOn() ) insilmaril@0: 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@98: insilmaril@98: void MapEditor::addNewBranchHere() insilmaril@98: { insilmaril@98: // Finish open lineEdits insilmaril@98: if (lineedit) finishedLineEditNoSave(); insilmaril@98: insilmaril@98: if (selection && insilmaril@98: (typeid(*selection) == typeid(BranchObj) ) ) insilmaril@98: { insilmaril@106: saveState(selection); insilmaril@98: insilmaril@98: BranchObj* bo1 = (BranchObj*) (selection); insilmaril@98: bool wasScrolled=false; insilmaril@98: BranchObj *newbo=NULL; insilmaril@98: BranchObj *parbo=(BranchObj*)(selection->getParObj()); insilmaril@98: if (parbo) insilmaril@98: { insilmaril@98: // add below selection insilmaril@98: newbo=parbo->insertBranch(bo1->getNum()+1); insilmaril@98: } insilmaril@98: insilmaril@98: LinkableMapObj *oldselection=selection; insilmaril@98: ((BranchObj*)(selection))->moveBranchTo (newbo,-1); insilmaril@98: insilmaril@98: mapCenter->reposition(); insilmaril@98: adjustCanvasSize(); insilmaril@98: if (actionSettingsAutoedit->isOn() || insilmaril@98: actionSettingsAutoselectHeading->isOn() ) insilmaril@98: { insilmaril@98: selection->unselect(); insilmaril@98: selection=newbo; insilmaril@98: selection->select(); insilmaril@98: if (actionSettingsPasteNewHeading->isOn() ) insilmaril@98: { insilmaril@98: BranchObj *bo2= (BranchObj*)(selection); insilmaril@98: bo2->setHeading(""); insilmaril@98: } insilmaril@98: if (actionSettingsAutoedit->isOn() ) insilmaril@98: editHeading(); insilmaril@98: if (!actionSettingsAutoselectHeading->isOn() insilmaril@98: && !wasScrolled) insilmaril@98: { insilmaril@98: selection->unselect(); insilmaril@98: selection=oldselection; insilmaril@98: selection->select(); insilmaril@98: } insilmaril@98: } insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@0: void MapEditor::deleteSelection() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (selection && typeid(*selection) ==typeid(BranchObj) ) insilmaril@0: { insilmaril@139: if (selection->getDepth()>1) insilmaril@139: // Normal branch, save parent with childs insilmaril@139: saveState(selection->getParObj()); insilmaril@139: else insilmaril@139: // Mainbranch, save whole map insilmaril@139: // FIXME Better would be to insert mainbranch again at pos insilmaril@139: // But undoCommand is missing right now insilmaril@139: saveState(); insilmaril@0: BranchObj* bo=dynamic_cast (selection); insilmaril@0: BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@0: bo->unselect(); 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@106: saveState(selection->getParObj()); insilmaril@0: FloatImageObj* fio=dynamic_cast (selection); insilmaril@0: BranchObj* par=(BranchObj*)(fio->getParObj()); 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@83: bool MapEditor::select (const QString &s) insilmaril@83: { insilmaril@106: LinkableMapObj *lmo=mapCenter->findObjBySelect(s); insilmaril@0: insilmaril@0: // Finally select the found object insilmaril@0: if (lmo) insilmaril@0: { insilmaril@98: if (selection) unselect(); insilmaril@0: selection=lmo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: return true; insilmaril@139: } insilmaril@139: return false; insilmaril@0: } insilmaril@0: insilmaril@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@0: void MapEditor::selectNextBranch() 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@0: void MapEditor::selectPrevBranch() 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@0: 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: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj)) insilmaril@0: { insilmaril@0: if (selection->getOrientation()==OrientRightOfCenter) insilmaril@0: selectPrevBranch(); insilmaril@0: else insilmaril@0: if (selection->getDepth()==1) insilmaril@0: selectNextBranch(); insilmaril@0: else insilmaril@0: selectPrevBranch(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLowerBranch() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj)) insilmaril@0: { insilmaril@0: if (selection->getOrientation()==OrientRightOfCenter) insilmaril@0: selectNextBranch(); insilmaril@0: else insilmaril@0: if (selection->getDepth()==1) insilmaril@0: selectPrevBranch(); insilmaril@0: else insilmaril@0: selectNextBranch(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::selectLeftBranch() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); 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@0: 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@0: 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: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); 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@0: par= (BranchObj*) (selection); insilmaril@0: bo=par->getLastSelectedBranch(); insilmaril@0: if (bo) insilmaril@0: { insilmaril@0: // Workaround for relecting 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@0: 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: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); 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@0: 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: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); 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@0: 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: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: setBackgroundColor( col ); insilmaril@131: saveState(); 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@0: 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@143: saveState(selection); //FIXME undoCommand insilmaril@0: BranchObj *bo=(BranchObj*)(selection); insilmaril@0: bo->setColor(actColor, false); // color links, color childs 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@106: saveState(selection); insilmaril@0: BranchObj *bo=(BranchObj*)(selection); insilmaril@0: bo->setColor(actColor, true); // 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@143: saveState(selection);// FIXME undoCommand insilmaril@103: ((BranchObj*)(selection))->toggleStandardFlag (f,actionSettingsUseFlagGroups); 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@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@0: if (selection) ((BranchObj*)(selection))->unselect(); insilmaril@0: selection=itFind; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: } insilmaril@0: if (textEditor->findText(s,cs)) 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@0: 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@0: 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::openURL() insilmaril@0: { insilmaril@0: if (selection ) insilmaril@0: { insilmaril@0: if (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) insilmaril@0: { insilmaril@0: QString url=((BranchObj*)(selection))->getURL(); insilmaril@0: insilmaril@0: QProcess *proc = new QProcess( this ); insilmaril@0: insilmaril@0: #if !defined(Q_OS_MACX) insilmaril@0: proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL","konqueror" )); insilmaril@0: #else insilmaril@0: proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL", insilmaril@0: "/Applications/Safari.app/Contents/MacOS/Safari" )); insilmaril@0: #endif insilmaril@0: insilmaril@0: proc->addArgument( url); insilmaril@0: insilmaril@0: if ( !proc->start() ) insilmaril@0: // error handling insilmaril@0: if (mainWindow->settingsURL() ) insilmaril@0: openURL(); insilmaril@0: } insilmaril@0: } 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@143: BranchObj *bo=(BranchObj*)(selection); insilmaril@0: QString text = QInputDialog::getText( insilmaril@0: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@143: bo->getURL(), &ok, this ); insilmaril@0: if ( ok) insilmaril@0: { insilmaril@0: // user entered something and pressed OK insilmaril@143: saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")"); insilmaril@143: bo->setURL (text); insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::editHeading2URL() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@143: BranchObj *bo=(BranchObj*)(selection); insilmaril@143: saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")"); insilmaril@143: bo->setURL (bo->getHeading()); insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::editBugzilla2URL() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@143: BranchObj *bo=(BranchObj*)(selection); insilmaril@143: QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); insilmaril@143: saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")"); insilmaril@143: bo->setURL (url); insilmaril@0: 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@143: BranchObj *bo=(BranchObj*)(selection); insilmaril@0: QFileDialog *fd=new QFileDialog( this,tr("VYM - Link to another map")); insilmaril@0: fd->addFilter (QString (tr("vym map") + " (*.vym)")); insilmaril@0: fd->setCaption(tr("VYM - Link to another map")); insilmaril@143: if (! bo->getVymLink().isEmpty() ) insilmaril@143: fd->setSelection( bo->getVymLink() ); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@143: { insilmaril@143: saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")"); insilmaril@143: bo->setVymLink (fd->selectedFile() ); insilmaril@143: updateActions(); insilmaril@143: mapCenter->reposition(); insilmaril@143: adjustCanvasSize(); insilmaril@143: canvas()->update(); insilmaril@143: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::deleteVymLink() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@143: BranchObj *bo=(BranchObj*)(selection); insilmaril@143: saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")"); insilmaril@143: bo->setVymLink ("" ); insilmaril@0: updateActions(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: QString MapEditor::getVymLink() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj) || insilmaril@0: typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@0: return ((BranchObj*)(selection))->getVymLink(); insilmaril@0: } insilmaril@0: return ""; insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@98: void MapEditor::removeBranchHere() insilmaril@98: { insilmaril@98: if (selection && (typeid(*selection) == typeid(BranchObj) )) insilmaril@98: { insilmaril@98: BranchObj* bo=(BranchObj*)(selection); insilmaril@98: BranchObj* par=(BranchObj*)(bo->getParObj()); insilmaril@139: if (bo->getDepth()==1) insilmaril@139: saveState(); insilmaril@139: else insilmaril@139: saveState(selection->getParObj()); // FIXME undoCommand insilmaril@139: QString sel=selection->getSelectString(); insilmaril@98: unselect(); insilmaril@98: par->removeBranchHere(bo); insilmaril@98: mapCenter->reposition(); insilmaril@98: select (sel); insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@98: void MapEditor::removeChilds() insilmaril@98: { insilmaril@98: if (selection && (typeid(*selection) == typeid(BranchObj) )) insilmaril@98: { insilmaril@106: saveState(selection->getParObj()); insilmaril@98: ((BranchObj*)(selection))->removeChilds(); insilmaril@98: mapCenter->reposition(); insilmaril@98: } insilmaril@98: } insilmaril@98: insilmaril@0: void MapEditor::editMapInfo() insilmaril@0: { insilmaril@0: ExtraInfoDialog dia; insilmaril@0: dia.setMapName (getFileName() ); insilmaril@0: dia.setAuthor (mapCenter->getAuthor() ); insilmaril@0: dia.setComment(mapCenter->getComment() ); insilmaril@0: insilmaril@0: // Calc some stats insilmaril@0: QString stats; insilmaril@0: int i=0; insilmaril@0: QCanvasItemList l=canvas()->allItems(); insilmaril@0: for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) insilmaril@0: i++; insilmaril@0: stats+=QString ("%1 items on canvas\n").arg (i,6); insilmaril@0: insilmaril@0: uint b=0; insilmaril@0: uint f=0; insilmaril@0: uint n=0; insilmaril@103: uint xl=0; insilmaril@0: BranchObj *bo; insilmaril@0: bo=mapCenter->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: if (!bo->getNote().isEmpty() ) n++; insilmaril@0: f+= bo->countFloatImages(); insilmaril@0: b++; insilmaril@103: xl+=bo->countXLinks(); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@0: stats+=QString ("%1 branches\n").arg (b-1,6); insilmaril@104: stats+=QString ("%1 xLinks \n").arg (xl,6); insilmaril@0: stats+=QString ("%1 notes\n").arg (n,6); insilmaril@0: stats+=QString ("%1 images\n").arg (f,6); insilmaril@0: dia.setStats (stats); insilmaril@0: insilmaril@0: // Finally show dialog insilmaril@0: if (dia.exec() == QDialog::Accepted) insilmaril@0: { insilmaril@139: saveState(); //FIXME undoCommand insilmaril@0: mapCenter->setAuthor (dia.getAuthor() ); insilmaril@0: mapCenter->setComment (dia.getComment() ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::updateActions() insilmaril@0: { insilmaril@98: QAction *a; insilmaril@0: if (getLinkColorHint()==HeadingColor) insilmaril@0: actionFormatLinkColorHint->setOn(true); insilmaril@0: else insilmaril@0: actionFormatLinkColorHint->setOn(false); insilmaril@0: insilmaril@0: switch (linkstyle) insilmaril@0: { insilmaril@0: case StyleLine: insilmaril@0: actionFormatLinkStyleLine->setOn(true); insilmaril@0: break; insilmaril@0: case StyleParabel: insilmaril@0: actionFormatLinkStyleParabel->setOn(true); insilmaril@0: break; insilmaril@0: case StylePolyLine: insilmaril@0: actionFormatLinkStylePolyLine->setOn(true); insilmaril@0: break; insilmaril@0: case StylePolyParabel: insilmaril@0: actionFormatLinkStylePolyParabel->setOn(true); insilmaril@0: break; insilmaril@0: default: insilmaril@0: break; insilmaril@0: } insilmaril@0: insilmaril@0: QPixmap pix( 16, 16 ); insilmaril@0: pix.fill( mapCanvas->backgroundColor() ); insilmaril@0: actionFormatBackColor->setIconSet( pix ); insilmaril@97: pix.fill( defLinkColor ); insilmaril@0: actionFormatLinkColor->setIconSet( pix ); insilmaril@0: insilmaril@0: actionEditUndo->setEnabled( mapChanged ); insilmaril@0: actionFileSave->setEnabled( mapUnsaved ); insilmaril@0: insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if ( (typeid(*selection) == typeid(BranchObj)) || insilmaril@0: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@0: { insilmaril@89: BranchObj *bo=(BranchObj*)(selection); insilmaril@89: // Take care of links insilmaril@95: if (bo->countXLinks()==0) insilmaril@89: { insilmaril@89: branchLinksContextMenu->clear(); insilmaril@125: branchLinksContextMenu->insertItem ("No xLink available"); insilmaril@94: branchLinksContextMenuDup->clear(); insilmaril@125: branchLinksContextMenuDup->insertItem ("No xLink available"); insilmaril@89: insilmaril@89: } else insilmaril@89: { insilmaril@89: BranchObj *bot; insilmaril@89: QString s; insilmaril@89: branchLinksContextMenu->clear(); insilmaril@94: branchLinksContextMenuDup->clear(); insilmaril@95: for (int i=0; i<=bo->countXLinks();i++) insilmaril@89: { insilmaril@95: bot=bo->XLinkTargetAt(i); insilmaril@89: if (bot) insilmaril@89: { insilmaril@89: s=bot->getHeading(); insilmaril@89: if (s.length()>25) insilmaril@89: s=s.left(25)+"..."; insilmaril@89: branchLinksContextMenu->insertItem (s); insilmaril@94: branchLinksContextMenuDup->insertItem (s); insilmaril@89: } insilmaril@89: } insilmaril@89: } insilmaril@89: insilmaril@0: standardFlagsDefault->setEnabled (true); insilmaril@0: insilmaril@89: if ( bo->getURL().isEmpty() ) insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@0: else insilmaril@0: actionEditOpenURL->setEnabled (true); insilmaril@0: insilmaril@89: if ( bo->getVymLink().isEmpty() ) insilmaril@0: { insilmaril@0: actionEditOpenVymLink->setEnabled (false); insilmaril@0: actionEditDeleteVymLink->setEnabled (false); insilmaril@0: } else insilmaril@0: { insilmaril@0: actionEditOpenVymLink->setEnabled (true); insilmaril@0: actionEditDeleteVymLink->setEnabled (true); insilmaril@0: } insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (true); insilmaril@0: actionEditCut->setEnabled (true); insilmaril@119: if (clipboardME->getMapCenter()->countBranches()>0 || clipboardME->getMapCenter()->countFloatImages()>0) insilmaril@119: actionEditPaste->setEnabled (true); insilmaril@119: else insilmaril@119: actionEditPaste->setEnabled (false); insilmaril@119: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@119: a->setEnabled(true); insilmaril@0: actionEditDelete->setEnabled (true); insilmaril@0: actionEditToggleFloatExport->setEnabled (false); 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@0: } insilmaril@0: if ( (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@0: { insilmaril@0: standardFlagsDefault->setEnabled (false); insilmaril@0: insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@0: actionEditOpenVymLink->setEnabled (false); insilmaril@0: actionEditDeleteVymLink->setEnabled (false); insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (true); insilmaril@0: actionEditCut->setEnabled (true); insilmaril@0: actionEditPaste->setEnabled (false); //FIXME insilmaril@98: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@98: a->setEnabled(false); insilmaril@0: actionEditDelete->setEnabled (true); insilmaril@0: actionEditToggleFloatExport->setOn insilmaril@0: ( ((FloatImageObj*)(selection))->getFloatExport() ); insilmaril@0: } insilmaril@0: insilmaril@0: } else insilmaril@0: { insilmaril@0: standardFlagsDefault->setEnabled (false); insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (false); insilmaril@0: actionEditCut->setEnabled (false); insilmaril@0: actionEditPaste->setEnabled (false); insilmaril@98: for (a=actionListBranches.first();a;a=actionListBranches.next()) insilmaril@98: a->setEnabled(false); insilmaril@98: insilmaril@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@0: actionEditToggleFloatExport->setEnabled (false); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setLinkStyle (LinkStyle ls) insilmaril@0: { insilmaril@0: linkstyle=ls; insilmaril@0: insilmaril@139: saveState(); // FIXME undoCommand insilmaril@0: BranchObj *bo; insilmaril@0: bo=mapCenter->first(); insilmaril@0: bo=bo->next(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkStyle(bo->getDefLinkStyle()); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@102: mapCenter->reposition(); insilmaril@0: } insilmaril@0: insilmaril@0: LinkStyle MapEditor::getLinkStyle () insilmaril@0: { insilmaril@0: return linkstyle; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setLinkColor(QColor c) insilmaril@0: { insilmaril@97: defLinkColor=c; insilmaril@0: updateActions(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setLinkColorHint() insilmaril@0: { insilmaril@0: // called from setLinkColorHint(lch) or at end of parse insilmaril@0: BranchObj *bo; insilmaril@0: bo=mapCenter->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setLinkColorHint(LinkColorHint lch) insilmaril@0: { insilmaril@0: linkcolorhint=lch; insilmaril@0: setLinkColorHint(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::toggleLinkColorHint() insilmaril@0: { insilmaril@0: if (linkcolorhint==HeadingColor) insilmaril@0: linkcolorhint=DefaultColor; insilmaril@0: else insilmaril@0: linkcolorhint=HeadingColor; insilmaril@0: BranchObj *bo; insilmaril@0: bo=mapCenter->first(); insilmaril@0: while (bo) insilmaril@0: { insilmaril@0: bo->setLinkColor(); insilmaril@0: bo=bo->next(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: LinkColorHint MapEditor::getLinkColorHint() insilmaril@0: { insilmaril@0: return linkcolorhint; insilmaril@0: } insilmaril@0: insilmaril@0: QColor MapEditor::getDefLinkColor() insilmaril@0: { insilmaril@97: return defLinkColor; insilmaril@97: } insilmaril@97: insilmaril@97: void MapEditor::setDefXLinkColor(QColor col) insilmaril@97: { insilmaril@97: defXLinkColor=col; insilmaril@97: } insilmaril@97: insilmaril@97: QColor MapEditor::getDefXLinkColor() insilmaril@97: { insilmaril@97: return defXLinkColor; insilmaril@97: } insilmaril@97: insilmaril@97: void MapEditor::setDefXLinkWidth (int w) insilmaril@97: { insilmaril@97: defXLinkWidth=w; insilmaril@97: } insilmaril@97: insilmaril@97: int MapEditor::getDefXLinkWidth() insilmaril@97: { insilmaril@97: return defXLinkWidth; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLinkColor() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@97: QColor col = QColorDialog::getColor( defLinkColor, this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: setLinkColor( col ); insilmaril@131: saveState(); //FIXME undoCommand insilmaril@131: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::toggleScroll() insilmaril@0: { insilmaril@0: if (selection && (typeid(*selection) == typeid(BranchObj)) ) insilmaril@0: { insilmaril@0: BranchObj *bo=((BranchObj*)(selection)); insilmaril@0: if (bo->countBranches()==0) return; insilmaril@0: if (bo->getDepth()==0) return; insilmaril@106: saveState(selection); 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@0: BranchObj *bo=((BranchObj*)(selection)); insilmaril@0: insilmaril@0: QFileDialog *fd=new QFileDialog( this,tr("vym - load image")); 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@0: fd->setPreviewMode( QFileDialog::Contents ); insilmaril@0: fd->setCaption(tr("vym - 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@106: saveState(selection); insilmaril@0: QString fn=fd->selectedFile(); insilmaril@0: lastImageDir=fn.left(fn.findRev ("/")); insilmaril@0: bo->addFloatImage(); insilmaril@0: // FIXME check if load was successful insilmaril@0: bo->getLastFloatImage()->load(fn); insilmaril@0: bo->getLastFloatImage()->setOriginalFilename(fn); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::saveFloatImage (int item) insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@0: { insilmaril@0: FloatImageObj *fio=((FloatImageObj*)(selection)); insilmaril@0: const char* fmt = saveImageFormatMenu->text(item); insilmaril@0: insilmaril@0: QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt); insilmaril@0: fd->addFilter ("PNG (*.png)"); insilmaril@0: fd->addFilter ("BMP (*.bmp)"); insilmaril@0: fd->addFilter ("XBM (*.xbm)"); insilmaril@0: fd->addFilter ("JPG (*.jpg)"); insilmaril@0: fd->addFilter ("XPM (*.xpm)"); insilmaril@0: fd->addFilter ("GIF (*.gif)"); insilmaril@0: fd->addFilter ("PNM (*.pnm)"); insilmaril@0: fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); insilmaril@0: fd->setCaption(tr("vym - Save image as ") + fmt); insilmaril@0: fd->setMode( QFileDialog::AnyFile ); insilmaril@0: 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@0: QMessageBox mb( "VYM", insilmaril@0: tr("The file ") + fd->selectedFile() + insilmaril@0: tr(" exists already. " insilmaril@0: "Do you want to overwrite it?"), 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@0: fio->save (fd->selectedFile(),fmt); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::toggleFloatExport() insilmaril@0: { insilmaril@0: if (selection && insilmaril@0: (typeid(*selection) == typeid(FloatImageObj))|| insilmaril@0: (typeid(*selection) == typeid(FloatObj)) ) insilmaril@0: { insilmaril@0: FloatImageObj *fio=((FloatImageObj*)(selection)); insilmaril@0: fio->setFloatExport (actionEditToggleFloatExport->isOn() ); 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@0: void MapEditor::importDir(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@0: const QFileInfoList *dirlist = d.entryInfoList(); insilmaril@0: QFileInfoListIterator itdir( *dirlist ); insilmaril@0: QFileInfo *fi; insilmaril@0: insilmaril@0: while ( (fi = itdir.current()) != 0 ) insilmaril@0: { insilmaril@0: if (fi->fileName() != "." && fi->fileName() != ".." ) insilmaril@0: { insilmaril@0: dst->addBranch(); insilmaril@0: bo=dst->getLastBranch(); insilmaril@0: bo->setHeading (fi->fileName() ); insilmaril@0: bo->setColor (QColor("blue"),false); insilmaril@0: bo->toggleScroll(); insilmaril@0: if ( !d.cd(fi->fileName()) ) insilmaril@0: QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory")); insilmaril@0: else insilmaril@0: { insilmaril@103: // Recursively add subdirs insilmaril@0: importDir (bo,d); insilmaril@0: d.cdUp(); insilmaril@0: } insilmaril@0: } insilmaril@0: ++itdir; insilmaril@0: } insilmaril@0: // Traverse files insilmaril@0: d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks ); insilmaril@0: const QFileInfoList *filelist = d.entryInfoList(); insilmaril@0: QFileInfoListIterator itfile( *filelist ); insilmaril@0: insilmaril@0: while ( (fi = itfile.current()) != 0 ) insilmaril@0: { insilmaril@0: dst->addBranch(); insilmaril@0: bo=dst->getLastBranch(); insilmaril@0: bo->setHeading (fi->fileName() ); insilmaril@0: bo->setColor (QColor("black"),false); insilmaril@103: if (fi->fileName().right(4) == ".vym" ) insilmaril@103: bo->setVymLink (fi->filePath()); insilmaril@103: insilmaril@0: ++itfile; 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@0: QFileDialog *fd=new QFileDialog( this,tr("VYM - Choose directory structur to import")); insilmaril@0: fd->setMode (QFileDialog::DirectoryOnly); insilmaril@0: fd->addFilter (QString (tr("vym map") + " (*.vym)")); insilmaril@0: fd->setCaption(tr("VYM - Choose directory structur to import")); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: { insilmaril@0: BranchObj *bo=((BranchObj*)(selection)); insilmaril@0: importDir (bo,QDir(fd->selectedFile()) ); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@95: void MapEditor::followXLink(int i) insilmaril@89: { insilmaril@97: if (selection && insilmaril@97: (typeid(*selection) == typeid(BranchObj)) || insilmaril@97: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@89: { insilmaril@97: BranchObj *bo=((BranchObj*)(selection))->XLinkTargetAt(i); insilmaril@97: if (bo) insilmaril@97: { insilmaril@97: selection->unselect(); insilmaril@97: selection=bo; insilmaril@97: selection->select(); insilmaril@97: ensureSelectionVisible(); insilmaril@97: } insilmaril@89: } insilmaril@89: } insilmaril@89: insilmaril@95: void MapEditor::editXLink(int i) insilmaril@94: { insilmaril@97: if (selection && insilmaril@97: (typeid(*selection) == typeid(BranchObj)) || insilmaril@97: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@94: { insilmaril@97: XLinkObj *xlo=((BranchObj*)(selection))->XLinkAt(i); insilmaril@97: if (xlo) insilmaril@94: { insilmaril@97: EditXLinkDialog dia; insilmaril@97: dia.setXLink (xlo); insilmaril@102: dia.setSelection(selection); insilmaril@97: if (dia.exec() == QDialog::Accepted) insilmaril@97: { insilmaril@97: if (dia.useSettingsGlobal() ) insilmaril@97: { insilmaril@97: setDefXLinkColor (xlo->getColor() ); insilmaril@97: setDefXLinkWidth (xlo->getWidth() ); insilmaril@97: } insilmaril@97: if (dia.deleteXLink()) insilmaril@97: ((BranchObj*)(selection))->deleteXLinkAt(i); insilmaril@131: saveState(); //FIXME undoCommand insilmaril@97: } insilmaril@97: } insilmaril@97: } insilmaril@94: } insilmaril@94: insilmaril@0: void MapEditor::testFunction() insilmaril@0: { insilmaril@0: cout << "MapEditor::testFunction() called\n"; insilmaril@105: if (selection && insilmaril@105: (typeid(*selection) == typeid(BranchObj)) ) insilmaril@105: { insilmaril@105: QString s=((BranchObj*)(selection))->getHeading(); insilmaril@106: parseAtom(s); insilmaril@105: } insilmaril@105: } insilmaril@105: insilmaril@0: void MapEditor::ensureSelectionVisible() insilmaril@0: { insilmaril@98: if (selection) insilmaril@98: { insilmaril@98: LinkableMapObj* lmo= dynamic_cast (selection); insilmaril@98: QPoint p; insilmaril@98: if (selection->getOrientation() == OrientLeftOfCenter) insilmaril@98: p= worldMatrix().map(QPoint (lmo->x(),lmo->y())); insilmaril@98: else insilmaril@98: p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height())); insilmaril@98: ensureVisible (p.x(), p.y() ); insilmaril@98: } insilmaril@0: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::updateViewCenter() insilmaril@0: { insilmaril@0: // Update movingCenter, so that we can zoom comfortably later insilmaril@0: QRect rc = QRect( contentsX(), contentsY(), insilmaril@0: visibleWidth(), visibleHeight() ); insilmaril@0: QRect canvasRect = inverseWorldMatrix().mapRect(rc); insilmaril@0: movingCenter.setX((canvasRect.right() + canvasRect.left())/2); insilmaril@0: movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e ) insilmaril@0: { insilmaril@0: // Lineedits are already closed by preceding insilmaril@0: // mouseEvent, we don't need to close here. insilmaril@0: insilmaril@0: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: insilmaril@0: if (lmo) insilmaril@0: { // MapObj was found insilmaril@0: if (selection != lmo) insilmaril@0: { insilmaril@0: // select the MapObj insilmaril@0: if (selection) selection->unselect(); insilmaril@0: selection=lmo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: // Context Menu insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: if (typeid(*selection)==typeid(BranchObj) || insilmaril@0: typeid(*selection)==typeid(MapCenterObj) ) insilmaril@0: { insilmaril@0: // Context Menu on branch or mapcenter insilmaril@0: updateActions(); insilmaril@0: branchContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@0: if (typeid(*selection)==typeid(FloatImageObj)) insilmaril@0: { insilmaril@0: // Context Menu on floatimage insilmaril@0: updateActions(); insilmaril@0: floatimageContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@0: } insilmaril@0: } else insilmaril@0: { // No MapObj found, we are on the Canvas itself insilmaril@0: // Context Menu on Canvas insilmaril@0: updateActions(); insilmaril@0: canvasContextMenu->popup(e->globalPos() ); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMousePressEvent(QMouseEvent* e) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL); insilmaril@0: insilmaril@83: // Special case: CTRL is pressed insilmaril@0: if (e->state() & QMouseEvent::ControlButton) insilmaril@0: { insilmaril@89: if (actionModModeColor->isOn()) insilmaril@83: { insilmaril@83: if (e->state() & QMouseEvent::ControlButton) insilmaril@83: { insilmaril@83: pickingColor=true; insilmaril@83: setCursor (pickColorCursor); insilmaril@83: return; insilmaril@83: } insilmaril@83: } insilmaril@89: if (actionModModeLink->isOn()) insilmaril@83: { insilmaril@90: BranchObj *bo_begin=NULL; insilmaril@90: if (lmo) insilmaril@90: bo_begin=(BranchObj*)(lmo); insilmaril@90: else insilmaril@90: if (selection && insilmaril@90: ((typeid(*selection) == typeid(BranchObj)) || insilmaril@90: (typeid(*selection) == typeid(MapCenterObj))) ) insilmaril@90: bo_begin=(BranchObj*)(selection); insilmaril@90: if (bo_begin) insilmaril@83: { insilmaril@83: drawingLink=true; insilmaril@90: linkingObj_src=bo_begin; insilmaril@95: tmpXLink=new XLinkObj (mapCanvas); insilmaril@95: tmpXLink->setBegin (bo_begin); insilmaril@95: tmpXLink->setEnd (p); insilmaril@97: tmpXLink->setColor(defXLinkColor); insilmaril@97: tmpXLink->setWidth(defXLinkWidth); insilmaril@95: tmpXLink->updateXLink(); insilmaril@95: tmpXLink->setVisibility (true); insilmaril@83: return; insilmaril@89: } insilmaril@83: } insilmaril@0: } 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: insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@0: // Check, if systemFlag clicked insilmaril@0: if (typeid(*selection)==typeid(BranchObj) || insilmaril@0: typeid(*selection)==typeid(MapCenterObj) ) insilmaril@0: { insilmaril@0: QString foname=((BranchObj*)(selection))->getSystemFlagName(p); insilmaril@0: if (!foname.isEmpty()) insilmaril@0: { insilmaril@0: // Do not move, if systemFlag clicked insilmaril@0: if (foname=="url") insilmaril@0: openURL(); insilmaril@0: else insilmaril@0: if (foname=="vymLink") insilmaril@0: { insilmaril@0: mainWindow->editOpenVymLink(); insilmaril@0: // tabWidget may change, better return now insilmaril@0: // before segfaulting... insilmaril@0: return; insilmaril@0: } else insilmaril@0: if (foname=="note") insilmaril@0: mainWindow->windowToggleNoteEditor(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: // Left Button Move Branches insilmaril@0: if (e->button() == QMouseEvent::LeftButton ) insilmaril@0: { insilmaril@129: movingObj_start.setX( p.x() - selection->x() ); insilmaril@129: movingObj_start.setY( p.y() - selection->y() ); insilmaril@129: movingObj_orgPos.setX (lmo->x() ); insilmaril@129: movingObj_orgPos.setY (lmo->y() ); insilmaril@129: insilmaril@93: // If modMode==copy, then we want to "move" the _new_ object around insilmaril@93: // then we need the offset from p to the _old_ selection, because of tmp insilmaril@93: if (actionModModeCopy->isOn() && insilmaril@93: e->state() & QMouseEvent::ControlButton) insilmaril@93: { insilmaril@93: if (typeid(*selection)==typeid(BranchObj) ) insilmaril@93: { insilmaril@93: copyingObj=true; insilmaril@93: mapCenter->addBranch ((BranchObj*)(selection)); insilmaril@93: unselect(); insilmaril@93: selection=mapCenter->getLastBranch(); insilmaril@93: selection->select(); insilmaril@104: mapCenter->reposition(); insilmaril@93: } insilmaril@129: } insilmaril@0: movingObj=selection; insilmaril@0: } else insilmaril@0: // Middle Button Toggle Scroll insilmaril@0: // (On Mac OS X this won't work, but we still have insilmaril@0: // a button in the toolbar) insilmaril@0: if (e->button() == QMouseEvent::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@0: if (e->button() == QMouseEvent::LeftButton ) insilmaril@0: { insilmaril@0: movingObj=NULL; // move Content not Obj insilmaril@0: movingObj_start=e->globalPos(); insilmaril@0: movingCont_start=QPoint (contentsX(), contentsY() ); insilmaril@0: movingVec=QPoint(0,0); insilmaril@0: setCursor(handOpenCursor); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMouseMoveEvent(QMouseEvent* e) insilmaril@0: { insilmaril@83: QPoint p = inverseWorldMatrix().map(e->pos()); insilmaril@83: insilmaril@0: // Move the selected MapObj insilmaril@0: if ( selection && movingObj) insilmaril@0: { insilmaril@89: ensureVisible (p.x(),p.y()); insilmaril@0: insilmaril@83: // Now move the selection, but add relative position insilmaril@83: // (movingObj_start) where selection was chosen with insilmaril@83: // mousepointer. (This avoids flickering resp. jumping insilmaril@0: // of selection back to absPos) insilmaril@0: insilmaril@0: LinkableMapObj *lmosel; insilmaril@0: lmosel = dynamic_cast (selection); insilmaril@0: insilmaril@0: // Check if we could link insilmaril@0: LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel); insilmaril@0: insilmaril@0: insilmaril@0: if (typeid(*selection) == typeid(FloatImageObj)) insilmaril@0: { insilmaril@0: FloatObj *fo=(FloatObj*)(selection); insilmaril@139: saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() ); insilmaril@0: if (fo->getLinkStyle()==StyleUndef) insilmaril@0: { insilmaril@0: fo->setLinkStyle(fo->getDefLinkStyle()); insilmaril@0: fo->setLinkColor(fo->getParObj()->getLinkColor()); insilmaril@0: } 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@0: if ( (e->state() & QMouseEvent::ShiftButton) && 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@131: saveState(); 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: // setLinkStyle calls updateLink, only set it once insilmaril@0: if (fio->getLinkStyle()!=fio->getDefLinkStyle() ) insilmaril@0: fio->setLinkStyle (fio->getDefLinkStyle()); insilmaril@0: } insilmaril@0: // TODO if (typeid(*selection) == typeid(FloatTextObj)) insilmaril@0: } insilmaril@0: } else // selection != a FloatObj insilmaril@0: { insilmaril@0: if (lmosel->getDepth()==0) insilmaril@0: { insilmaril@0: if (e->state() == (LeftButton | !ShiftButton)) 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@139: saveState("move "+qpointToString(movingObj_orgPos), lmosel->getSelectString() ); 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@0: p.y()-movingObj_start.y() ); insilmaril@0: else insilmaril@0: lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); insilmaril@0: } insilmaril@0: // reposition subbranch insilmaril@0: lmosel->reposition(); insilmaril@89: //ensureSelectionVisible(); insilmaril@0: insilmaril@0: if (lmo && (lmo!=selection) && insilmaril@0: (typeid(*lmo) == typeid(BranchObj) || insilmaril@0: (typeid(*lmo) == typeid(MapCenterObj) ) insilmaril@0: ) ) insilmaril@0: { insilmaril@0: if (e->state() & QMouseEvent::ControlButton) insilmaril@0: { insilmaril@0: // Special case: CTRL to link below lmo insilmaril@0: lmosel->setParObjTmp (lmo,p,+1); insilmaril@0: } insilmaril@0: else if (e->state() & QMouseEvent::ShiftButton) insilmaril@0: lmosel->setParObjTmp (lmo,p,-1); insilmaril@0: else insilmaril@0: lmosel->setParObjTmp (lmo,p,0); insilmaril@0: } else insilmaril@0: { insilmaril@93: lmosel->unsetParObjTmp(); insilmaril@93: /* insilmaril@0: if (lmo &&(lmo==selection)) insilmaril@0: // Could link to myself (happens sometimes...) insilmaril@0: lmosel->unsetParObjTmp(); insilmaril@0: if (!lmo) insilmaril@0: // no Obj under selection, go back to original Parent insilmaril@0: lmosel->unsetParObjTmp(); insilmaril@93: */ insilmaril@0: } insilmaril@0: } // depth>0 insilmaril@0: insilmaril@0: } // no FloatImageObj insilmaril@0: insilmaril@0: canvas()->update(); insilmaril@0: return; insilmaril@0: } // selection && moving_obj insilmaril@0: insilmaril@83: // Draw a link from one branch to another insilmaril@83: if (drawingLink) insilmaril@83: { insilmaril@95: tmpXLink->setEnd (p); insilmaril@95: tmpXLink->updateXLink(); insilmaril@83: } insilmaril@83: insilmaril@0: // Move CanvasView insilmaril@83: if (!movingObj && !pickingColor &&!drawingLink) insilmaril@0: { insilmaril@0: QPoint p=e->globalPos(); insilmaril@0: movingVec.setX(-p.x() + movingObj_start.x() ); insilmaril@0: movingVec.setY(-p.y() + movingObj_start.y() ); insilmaril@0: setContentsPos( movingCont_start.x() + movingVec.x(), insilmaril@0: movingCont_start.y() + movingVec.y()); insilmaril@0: insilmaril@0: updateViewCenter(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: insilmaril@0: void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e) insilmaril@0: { insilmaril@0: LinkableMapObj *dst; insilmaril@0: // Have we been picking color? insilmaril@0: if (pickingColor) insilmaril@0: { insilmaril@0: pickingColor=false; insilmaril@0: setCursor (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@0: if (e->state() & QMouseEvent::ShiftButton) insilmaril@0: { insilmaril@0: ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),false); insilmaril@0: ((BranchObj*)(selection))->setLinkColor (); insilmaril@0: } insilmaril@0: else insilmaril@0: { insilmaril@0: ((BranchObj*)(selection))->setColor (((BranchObj*)(dst))->getColor(),true); insilmaril@0: ((BranchObj*)(selection))->setLinkColor (); insilmaril@0: } insilmaril@0: } insilmaril@0: return; insilmaril@0: } insilmaril@83: insilmaril@83: // Have we been drawing a link? insilmaril@83: if (drawingLink) insilmaril@83: { insilmaril@83: drawingLink=false; insilmaril@83: // Check if we are over another branch insilmaril@83: dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL); insilmaril@83: if (dst && selection) insilmaril@83: { insilmaril@95: tmpXLink->setEnd ( ((BranchObj*)(dst)) ); insilmaril@95: tmpXLink->updateXLink(); insilmaril@95: tmpXLink->activate(); insilmaril@131: saveState(); //FIXME undoCommand insilmaril@83: } else insilmaril@83: { insilmaril@95: delete(tmpXLink); insilmaril@95: tmpXLink=NULL; insilmaril@83: } insilmaril@83: return; insilmaril@83: } insilmaril@83: insilmaril@0: // Have we been moving something? insilmaril@0: if ( selection && movingObj ) insilmaril@0: { 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@0: ((LinkableMapObj*)(selection)) ); insilmaril@0: insilmaril@0: if (dst && insilmaril@0: (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj))) insilmaril@0: { insilmaril@0: dst=NULL; insilmaril@0: } 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@0: ((LinkableMapObj*)(selection))->unsetParObjTmp(); insilmaril@0: insilmaril@93: insilmaril@94: copyingObj=false; insilmaril@129: if (dst ) insilmaril@93: { insilmaril@129: BranchObj* bs=((BranchObj*)(selection)); insilmaril@139: QString undoCom="linkBranchToPos (\""+ insilmaril@129: (bs->getParObj())->getSelectString()+ insilmaril@129: "\","+ insilmaril@129: QString("%1").arg(bs->getNum())+ insilmaril@129: ","+ insilmaril@129: QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ insilmaril@139: ")"; insilmaril@0: // TODO we also could check, if dest and src are on same branch, insilmaril@0: // then it would be sufficient to saveState of this branch insilmaril@0: insilmaril@0: // Modifiers allow to insert above/below dst insilmaril@0: if (e->state() & QMouseEvent::ShiftButton) insilmaril@0: { insilmaril@139: bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()); insilmaril@83: } else insilmaril@93: if (e->state() & QMouseEvent::ControlButton) insilmaril@93: { insilmaril@139: bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1); insilmaril@93: } else insilmaril@93: { insilmaril@129: bs->moveBranchTo ((BranchObj*)(dst),-1); insilmaril@93: if (dst->getDepth()==0) insilmaril@129: bs->move (savePos); insilmaril@93: } insilmaril@139: saveState (undoCom,bs->getSelectString() ); insilmaril@93: } 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@0: } else insilmaril@83: // maybe we moved View: set old cursor insilmaril@0: setCursor (ArrowCursor); insilmaril@83: insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (e->button() == QMouseEvent::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@106: saveState(selection); insilmaril@0: editHeading(); insilmaril@0: } insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::resizeEvent (QResizeEvent* e) insilmaril@0: { insilmaril@0: QCanvasView::resizeEvent( e ); insilmaril@0: insilmaril@0: QString s=""; insilmaril@0: if (!fileName.isEmpty()) s=fileName; insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@128: void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) insilmaril@119: { insilmaril@129: insilmaril@129: // for (unsigned int i=0;event->format(i);i++) // Debug mime type insilmaril@129: // cerr << event->format(i) << endl; insilmaril@129: insilmaril@119: if (selection && insilmaril@119: (typeid(*selection) == typeid(BranchObj)) || insilmaril@119: (typeid(*selection) == typeid(MapCenterObj))) { insilmaril@119: insilmaril@119: // If QImageDrag can decode mime type insilmaril@119: if (QImageDrag::canDecode(event)) { insilmaril@119: event->accept(); insilmaril@119: return; insilmaril@119: } insilmaril@119: insilmaril@128: // If image are dragged from firefox insilmaril@119: if (event->provides("application/x-moz-file-promise-url") && insilmaril@119: event->provides("application/x-moz-nativeimage")) { insilmaril@119: event->accept(true); insilmaril@119: return; insilmaril@119: } insilmaril@125: insilmaril@128: // If QUriDrag can decode mime type insilmaril@128: if (QUriDrag::canDecode(event)) { insilmaril@128: event->accept(); insilmaril@128: return; insilmaril@128: } insilmaril@128: insilmaril@128: // If Uri are dragged from firefox insilmaril@129: if (event->provides("_NETSCAPE_URL")){ insilmaril@128: event->accept(); insilmaril@128: return; insilmaril@128: } insilmaril@129: insilmaril@129: // If QTextDrag can decode mime type insilmaril@129: if (QTextDrag::canDecode(event)) { insilmaril@129: event->accept(); insilmaril@129: return; insilmaril@129: } insilmaril@129: insilmaril@119: } insilmaril@119: event->ignore(); insilmaril@119: } insilmaril@129: insilmaril@129: bool isUnicode16(const QByteArray &d) insilmaril@129: { insilmaril@129: // FIXME: make more precise check for unicode 16. insilmaril@129: // Guess unicode16 if any of second bytes are zero insilmaril@129: unsigned int length = max(0,d.size()-2)/2; insilmaril@129: for (unsigned int i = 0; iprovides("image/png")) insilmaril@128: { insilmaril@128: QPixmap pix; insilmaril@128: if (QImageDrag::decode(event, pix)) insilmaril@128: { insilmaril@128: addFloatImage(pix); insilmaril@128: event->accept(); insilmaril@128: update=true; insilmaril@128: } else insilmaril@128: event->ignore(); insilmaril@128: insilmaril@128: } else if (event->provides("application/x-moz-file-promise-url") && insilmaril@128: event->provides("application/x-moz-nativeimage")) insilmaril@128: { insilmaril@129: // Contains url to the img src in unicode16 insilmaril@128: QByteArray d = event->encodedData("application/x-moz-file-promise-url"); insilmaril@128: QString url = QString((const QChar*)d.data(),d.size()/2); insilmaril@128: fetchImage(url); insilmaril@128: event->accept(); insilmaril@128: update=true; insilmaril@128: } else if (event->provides ("text/uri-list")) insilmaril@128: { // Uris provided e.g. by konqueror insilmaril@128: QUriDrag::decode (event,uris); insilmaril@129: } else if (event->provides ("_NETSCAPE_URL")) insilmaril@128: { // Uris provided by Mozilla insilmaril@129: QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL")); insilmaril@129: uris.append(l[0]); insilmaril@129: heading = l[1]; insilmaril@129: } else if (event->provides("text/html")) { insilmaril@129: insilmaril@129: // Handels text mime types insilmaril@129: // Look like firefox allways handle text as unicode16 (2 bytes per char.) insilmaril@129: QByteArray d = event->encodedData("text/html"); insilmaril@129: QString text; insilmaril@129: if (isUnicode16(d)) insilmaril@129: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@129: else insilmaril@129: text = QString(d); insilmaril@129: insilmaril@129: textEditor->setText(text); insilmaril@129: insilmaril@129: event->accept(); insilmaril@129: update=true; insilmaril@129: } else if (event->provides("text/plain")) { insilmaril@129: QByteArray d = event->encodedData("text/plain"); insilmaril@129: QString text; insilmaril@129: if (isUnicode16(d)) insilmaril@129: text = QString((const QChar*)d.data(),d.size()/2); insilmaril@129: else insilmaril@129: text = QString(d); insilmaril@129: insilmaril@129: textEditor->setText(text); insilmaril@129: insilmaril@129: event->accept(); insilmaril@129: update= true; insilmaril@128: } insilmaril@128: insilmaril@128: if (uris.count()>0) insilmaril@128: { insilmaril@128: QStringList files; insilmaril@128: QStringList urls; insilmaril@128: QString s; insilmaril@128: BranchObj *bo; insilmaril@128: for (const char* u=uris.first(); u; u=uris.next()) insilmaril@128: { insilmaril@128: bo=((BranchObj*)(selection))->addBranch(); insilmaril@128: if (bo) insilmaril@128: { insilmaril@128: s=QUriDrag::uriToLocalFile(u); insilmaril@129: if (s) { insilmaril@129: QString file = QDir::convertSeparators(s); insilmaril@129: heading = QFileInfo(file).baseName(); insilmaril@129: files.append(file); insilmaril@129: if (file.endsWith(".vym", false)) insilmaril@129: bo->setVymLink(file); insilmaril@129: else insilmaril@129: bo->setURL(u); insilmaril@129: } else { insilmaril@129: urls.append (u); insilmaril@129: bo->setURL(u); insilmaril@129: } insilmaril@129: insilmaril@129: if (heading) insilmaril@129: bo->setHeading(heading); insilmaril@129: else insilmaril@129: bo->setHeading(u); insilmaril@128: } insilmaril@128: } insilmaril@128: update=true; insilmaril@128: } insilmaril@128: insilmaril@128: if (update) insilmaril@128: { insilmaril@131: saveState(); //FIXME undo Command insilmaril@128: mapCenter->reposition(); insilmaril@128: adjustCanvasSize(); insilmaril@128: canvas()->update(); insilmaril@128: } insilmaril@128: } insilmaril@119: } insilmaril@119: insilmaril@125: void MapEditor::addFloatImage(const QPixmap &img) insilmaril@119: { insilmaril@119: if (selection && insilmaril@119: (typeid(*selection) == typeid(BranchObj)) || insilmaril@119: (typeid(*selection) == typeid(MapCenterObj)) ) insilmaril@119: { insilmaril@119: BranchObj *bo=((BranchObj*)(selection)); insilmaril@119: saveState(selection); insilmaril@119: //QString fn=fd->selectedFile(); insilmaril@119: //lastImageDir=fn.left(fn.findRev ("/")); insilmaril@119: bo->addFloatImage(); insilmaril@119: // FIXME check if load was successful insilmaril@119: bo->getLastFloatImage()->load(img); insilmaril@119: //bo->getLastFloatImage()->setOriginalFilename(fn); insilmaril@119: mapCenter->reposition(); insilmaril@119: adjustCanvasSize(); insilmaril@119: canvas()->update(); insilmaril@119: } insilmaril@119: } insilmaril@119: insilmaril@119: insilmaril@129: void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/) insilmaril@119: { insilmaril@119: if (!imageBuffer) imageBuffer = new QBuffer(); insilmaril@119: if (!imageBuffer->isOpen()) { insilmaril@119: imageBuffer->open(IO_WriteOnly | IO_Append); insilmaril@119: } insilmaril@119: imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a)); insilmaril@119: } insilmaril@119: insilmaril@119: insilmaril@129: void MapEditor::imageDataFinished(QNetworkOperation *nop) insilmaril@119: { insilmaril@129: if (nop->state()==QNetworkProtocol::StDone) { insilmaril@129: QPixmap img(imageBuffer->buffer()); insilmaril@129: addFloatImage(img); insilmaril@129: } insilmaril@129: insilmaril@129: if (imageBuffer) { insilmaril@129: imageBuffer->close(); insilmaril@129: if (imageBuffer) { insilmaril@129: imageBuffer->close(); insilmaril@129: delete imageBuffer; insilmaril@129: imageBuffer = 0; insilmaril@129: } insilmaril@129: } insilmaril@119: } insilmaril@119: insilmaril@129: void MapEditor::fetchImage(const QString &url) insilmaril@119: { insilmaril@119: if (urlOperator) { insilmaril@119: urlOperator->stop(); insilmaril@119: disconnect(urlOperator); insilmaril@119: delete urlOperator; insilmaril@119: } insilmaril@119: insilmaril@119: urlOperator = new QUrlOperator(url); insilmaril@119: connect(urlOperator, SIGNAL(finished(QNetworkOperation *)), insilmaril@119: this, SLOT(imageDataFinished(QNetworkOperation*))); insilmaril@119: insilmaril@119: connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)), insilmaril@119: this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *))); insilmaril@119: urlOperator->get(); insilmaril@119: }