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@0: insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: insilmaril@0: #include "version.h" insilmaril@0: 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@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@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@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@89: extern QAction *actionEditNoLink; 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@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@0: insilmaril@0: extern QPopupMenu *branchContextMenu; insilmaril@89: extern QPopupMenu *branchLinksContextMenu; 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@0: QCanvasView(parent,name,f) insilmaril@0: { insilmaril@0: //cout << "Constructor ME "<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@0: fo->setToolTip(tr("Note")); insilmaril@0: systemFlagsDefault->addFlag (fo); // makes deep copy insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_url_xpm)); insilmaril@0: fo->setName("url"); insilmaril@0: fo->setToolTip(tr("WWW Document (external)")); insilmaril@0: systemFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_vymlink_xpm)); insilmaril@0: fo->setName("vymLink"); insilmaril@0: fo->setToolTip(tr("Link to another vym map")); insilmaril@0: systemFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_scrolled_right_xpm)); insilmaril@0: fo->setName("scrolledright"); insilmaril@0: fo->setToolTip(tr("subtree is scrolled")); insilmaril@0: systemFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_tmpUnscrolled_right_xpm)); insilmaril@0: fo->setName("tmpUnscrolledright"); insilmaril@0: fo->setToolTip(tr("subtree is temporary scrolled")); 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@0: fo->setName("exclamationmark"); insilmaril@0: fo->setToolTip(tr("Take care!")); insilmaril@0: standardFlagsDefault->addFlag (fo); // makes deep copy insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_questionmark_xpm)); insilmaril@0: fo->setName("questionmark"); insilmaril@0: fo->setToolTip(tr("Really?")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_hook_green_xpm)); insilmaril@0: fo->setName("hook-green"); insilmaril@0: fo->setToolTip(tr("ok!")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_cross_red_xpm)); insilmaril@0: fo->setName("cross-red"); insilmaril@0: fo->setToolTip(tr("Not ok!")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_stopsign_xpm)); insilmaril@0: fo->setName("stopsign"); insilmaril@0: fo->setToolTip(tr("This won't work!")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_smiley_good_xpm)); insilmaril@0: fo->setName("smiley-good"); insilmaril@0: fo->setToolTip(tr("Good")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_smiley_sad_xpm)); insilmaril@0: fo->setName("smiley-sad"); insilmaril@0: fo->setToolTip(tr("Bad")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_clock_xpm)); insilmaril@0: fo->setName("clock"); insilmaril@0: fo->setToolTip(tr("Time critical")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_lamp_xpm)); insilmaril@0: fo->setName("lamp"); insilmaril@0: fo->setToolTip(tr("Idea!")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_arrow_up_xpm)); insilmaril@0: fo->setName("arrow-up"); insilmaril@0: fo->setToolTip(tr("Important")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_arrow_down_xpm)); insilmaril@0: fo->setName("arrow-down"); insilmaril@0: fo->setToolTip(tr("Unimportant")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_thumb_up_xpm)); insilmaril@0: fo->setName("thumb-up"); insilmaril@0: fo->setToolTip(tr("I like this")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_thumb_down_xpm)); insilmaril@0: fo->setName("thumb-down"); insilmaril@0: fo->setToolTip(tr("I do not like this")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_heart_xpm)); insilmaril@0: fo->setName("heart"); insilmaril@0: fo->setToolTip(tr("I just love... ")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_flash_xpm)); insilmaril@0: fo->setName("flash"); insilmaril@0: fo->setToolTip(tr("Dangerous")); insilmaril@0: standardFlagsDefault->addFlag (fo); insilmaril@0: insilmaril@0: fo->load(QPixmap(flag_lifebelt_xpm)); insilmaril@0: fo->setName("lifebelt"); insilmaril@0: fo->setToolTip(tr("This will help")); 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@0: mapCenter->setHeading (tr("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@0: deflinkcolor=QColor (0,0,255); 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@0: insilmaril@0: editingBO=NULL; insilmaril@0: selection=NULL; insilmaril@0: selectionLast=NULL; insilmaril@0: movingObj=NULL; insilmaril@0: insilmaril@0: mapChanged=false; insilmaril@0: mapDefault=true; insilmaril@0: mapUnsaved=false; insilmaril@0: undoSelection=NULL; 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@0: blockreposition=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@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@0: bool MapEditor::blockReposition() insilmaril@0: { insilmaril@0: 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@0: // FIXME set permissions insilmaril@0: // 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@0: QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, SaveMode savemode) 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@0: if (savemode==CompleteMap) 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@0: attribut("linkColor", deflinkcolor.name() ) + 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@0: if (savemode==CompleteMap) insilmaril@0: s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset); insilmaril@0: else insilmaril@0: { insilmaril@0: if ( undoSelection && insilmaril@0: typeid(*undoSelection) == typeid(BranchObj) ) insilmaril@0: s+=((BranchObj*)(undoSelection))->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@0: if (selection) 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: insilmaril@0: return s; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::saveState() insilmaril@0: { insilmaril@0: saveState (CompleteMap,NULL); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part) insilmaril@0: { insilmaril@0: // all binary data is saved in bakMapDir (created in Constructor) insilmaril@0: // the xml data itself is kept in memory in backupXML insilmaril@0: // insilmaril@0: // For faster write/read of data, a part of the map can be insilmaril@0: // written. Then the undoSelection will mark, which part of the insilmaril@0: // map should be replaced if an undo is wanted later. insilmaril@0: insilmaril@0: if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) ) insilmaril@0: { insilmaril@0: // Writing a vympart only is useful for BranchObj insilmaril@0: undoSelection=part; insilmaril@0: backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap); insilmaril@0: } else insilmaril@0: { insilmaril@0: undoSelection=NULL; insilmaril@0: backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::finishedLineEditNoSave() insilmaril@0: { insilmaril@0: // This is called by finishedLineEdit or any MapEditor method, insilmaril@0: // which wants to assure, that lineedits finish, before e.g. a branch is insilmaril@0: // deleted insilmaril@0: insilmaril@0: // After calling LineEdit and using the clipboard, the insilmaril@0: // focus is not any longer on the main widget, we insilmaril@0: // have to restore it using parentWidget()->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@0: filePath=fname; insilmaril@0: fileName=fname; insilmaril@0: destPath=destname; insilmaril@0: insilmaril@0: // If fname is not an absolute path, complete it insilmaril@0: filePath=QDir(fname).absPath(); insilmaril@0: fileDir=filePath.left (1+filePath.findRev ("/")); insilmaril@0: insilmaril@0: // Set short name, too. Search from behind: insilmaril@0: int i=fileName.findRev("/"); insilmaril@0: if (i>=0) fileName=fileName.remove (0,i+1); insilmaril@0: insilmaril@0: // Forget the .vym (or .xml) for name of map insilmaril@0: mapName=fileName.left(fileName.findRev(".",-1,true) ); 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,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@0: 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@0: 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@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@0: saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),savemode); insilmaril@0: insilmaril@0: file.setName ( fileDir + fname); insilmaril@0: if ( !file.open( IO_WriteOnly ) ) insilmaril@0: { insilmaril@0: // This should neverever happen insilmaril@0: 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@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@0: QRect mapRect=mapCenter->getTotalBBox(); 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@0: mapRect.setRect (mapRect.x()-10, mapRect.y()-10, insilmaril@0: mapRect.width()+20, mapRect.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@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: mapRect.setRect (mapRect.x(), mapRect.y(), insilmaril@0: mapRect.width(), mapRect.height()+20); insilmaril@0: } insilmaril@0: pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()); 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@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@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: if (!ex.setOutputDir ("out")) insilmaril@0: { insilmaril@0: QMessageBox::critical (0,tr("Critical Export Error "),tr("Couldn't create directory ") + "out"); insilmaril@0: return; insilmaril@0: } insilmaril@0: break;; insilmaril@0: case QMessageBox::Cancel: insilmaril@0: // do nothing insilmaril@0: return; insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@0: Export ex; insilmaril@0: ex.setPath (fd->selectedFile() ); insilmaril@0: ex.setMapCenter(mapCenter); 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@0: QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,CompleteMap); 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::undo() insilmaril@0: { insilmaril@0: QDir d; insilmaril@0: d.setPath(bakMapDir); insilmaril@0: if (d.exists() ) insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: if (selection) insilmaril@0: { insilmaril@0: selection->unselect(); insilmaril@0: selection=NULL; insilmaril@0: } insilmaril@0: insilmaril@0: mapBuilderHandler handler; insilmaril@0: QXmlInputSource source; insilmaril@0: source.setData(backupXML); insilmaril@0: QXmlSimpleReader reader; insilmaril@0: reader.setContentHandler( &handler ); insilmaril@0: reader.setErrorHandler( &handler ); insilmaril@0: handler.setMapEditor( this ); insilmaril@0: handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path insilmaril@0: if (undoSelection) insilmaril@0: { insilmaril@0: selection=undoSelection; insilmaril@0: selection->select(); insilmaril@0: handler.setLoadMode (ImportReplace); insilmaril@0: insilmaril@0: } else insilmaril@0: { insilmaril@0: mapCenter->clear(); insilmaril@0: handler.setLoadMode (NewMap); insilmaril@0: } insilmaril@0: blockreposition=true; insilmaril@0: bool ok = reader.parse( source ); insilmaril@0: blockreposition=false; insilmaril@0: if ( ok ) insilmaril@0: mapCenter->reposition(); insilmaril@0: insilmaril@0: else insilmaril@0: { insilmaril@0: // This should never ever happen insilmaril@0: QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), insilmaril@0: tr( handler.errorProtocol() )+" in "+backupXML ); insilmaril@0: } insilmaril@0: // Undo not longer available now insilmaril@0: actionEditUndo->setEnabled (false); insilmaril@0: undoSelection=false; insilmaril@0: mapChanged=false; insilmaril@0: return; insilmaril@0: } else insilmaril@0: { insilmaril@0: QMessageBox::critical( 0, tr( "Critical Error" ), insilmaril@0: "Temporary directory " +bakMapDir + insilmaril@0: tr (" used for undo is gone. \n" insilmaril@0: "I will create a new one, but at the moment no undo is available.\n" insilmaril@0: "Maybe you want to reload your original data.\n\n" insilmaril@0: "Sorry for any inconveniences.") ); insilmaril@0: makeTmpDirs(); insilmaril@0: } 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@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: 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,selection); insilmaril@0: pasteNoSave(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::cut() insilmaril@0: { insilmaril@0: setChanged(); insilmaril@0: saveState(PartOfMap,selection->getParObj()); insilmaril@0: copy(); insilmaril@0: cutNoSave(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: } insilmaril@0: 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: setChanged(); insilmaril@0: saveState(PartOfMap,selection->getParObj()); 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@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: setChanged(); insilmaril@0: saveState(PartOfMap,selection->getParObj()); 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@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@0: setChanged(); insilmaril@0: saveState(PartOfMap,selection); insilmaril@0: insilmaril@0: ensureSelectionVisible(); insilmaril@0: BranchObj *bo=(BranchObj*)(selection); insilmaril@0: editingBO=(BranchObj*)(selection); insilmaril@0: QPoint p = worldMatrix().map(QPoint (bo->x(),bo->y())); insilmaril@0: lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25); insilmaril@0: QString s=bo->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@0: 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,selection); 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@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@0: setChanged(); insilmaril@0: saveState(PartOfMap,selection->getParObj()); 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,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: LinkableMapObj* MapEditor::findObj (QString s) insilmaril@0: { insilmaril@0: LinkableMapObj *lmo=mapCenter; insilmaril@0: QString part; insilmaril@0: QString typ; insilmaril@0: QString num; insilmaril@0: while (!s.isEmpty() ) insilmaril@0: { insilmaril@0: part=s.section(",",0,0); insilmaril@0: typ=part.left (3); insilmaril@0: num=part.right(part.length() - 3); insilmaril@0: insilmaril@0: if (typ=="mc:") insilmaril@0: { insilmaril@0: if (num=="") insilmaril@0: break; insilmaril@0: else insilmaril@0: lmo=mapCenter->getBranchNum (num.toUInt()); insilmaril@0: } else insilmaril@0: if (typ=="bo:") insilmaril@0: lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt()); insilmaril@0: else insilmaril@0: if (typ=="fi:") insilmaril@0: lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt()); insilmaril@0: if (!lmo) break; insilmaril@0: insilmaril@0: if (s.contains(",")) insilmaril@0: s=s.right(s.length() - part.length() -1 ); insilmaril@0: else insilmaril@0: break; insilmaril@0: } insilmaril@83: return lmo; insilmaril@83: } insilmaril@83: insilmaril@83: bool MapEditor::select (const QString &s) insilmaril@83: { insilmaril@83: LinkableMapObj *lmo=findObj(s); insilmaril@0: insilmaril@0: // Finally select the found object insilmaril@0: if (lmo) insilmaril@0: { insilmaril@0: if (selection) selection->unselect(); insilmaril@0: selection=lmo; insilmaril@0: selection->select(); insilmaril@0: adjustCanvasSize(); insilmaril@0: ensureSelectionVisible(); insilmaril@0: return true; insilmaril@0: } else insilmaril@0: 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@0: setChanged(); 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,selection); 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,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@0: setChanged(); insilmaril@0: saveState(PartOfMap,selection); insilmaril@0: ((BranchObj*)(selection))->toggleStandardFlag (f); 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@0: QString text = QInputDialog::getText( insilmaril@0: "VYM", tr("Enter URL:"), QLineEdit::Normal, insilmaril@0: ((BranchObj*)(selection))->getURL(), &ok, this ); insilmaril@0: if ( ok) insilmaril@0: { insilmaril@0: // user entered something and pressed OK insilmaril@0: ((BranchObj*)(selection))->setURL (text); insilmaril@0: updateActions(); insilmaril@0: setChanged(); 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@0: BranchObj *b=(BranchObj*)(selection); insilmaril@0: b->setURL (b->getHeading()); insilmaril@0: updateActions(); insilmaril@0: setChanged(); 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@0: BranchObj *b=(BranchObj*)(selection); insilmaril@0: b->setURL ("http://bugzilla.suse.de/show_bug.cgi?id="+b->getHeading()); insilmaril@91: b->setURL ("https://bugzilla.innerweb.novell.com/show_bug.cgi?id="+b->getHeading()); insilmaril@0: updateActions(); insilmaril@0: setChanged(); 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@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@0: if (! ((BranchObj*)(selection))->getVymLink().isEmpty() ) insilmaril@0: fd->setSelection( ((BranchObj*)(selection))->getVymLink() ); insilmaril@0: fd->show(); insilmaril@0: insilmaril@0: QString fn; insilmaril@0: if ( fd->exec() == QDialog::Accepted ) insilmaril@0: ((BranchObj*)(selection))->setVymLink (fd->selectedFile() ); insilmaril@0: updateActions(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: setChanged(); 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@0: ((BranchObj*)(selection))->setVymLink ("" ); insilmaril@0: updateActions(); insilmaril@0: mapCenter->reposition(); insilmaril@0: adjustCanvasSize(); insilmaril@0: canvas()->update(); insilmaril@0: setChanged(); 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@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@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@0: bo=bo->next(); insilmaril@0: } insilmaril@0: stats+=QString ("%1 branches\n").arg (b-1,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@0: mapCenter->setAuthor (dia.getAuthor() ); insilmaril@0: mapCenter->setComment (dia.getComment() ); insilmaril@0: setChanged(); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::updateActions() insilmaril@0: { 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@0: 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@89: if (bo->countLinks()==0) insilmaril@89: { insilmaril@89: branchLinksContextMenu->clear(); insilmaril@89: branchLinksContextMenu->insertItem ("No link available"); insilmaril@89: insilmaril@89: } else insilmaril@89: { insilmaril@89: BranchObj *bot; insilmaril@89: QString s; insilmaril@89: branchLinksContextMenu->clear(); insilmaril@89: for (int i=0; i<=bo->countLinks();i++) insilmaril@89: { insilmaril@89: bot=bo->linkTargetAt(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@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: actionEditURL->setEnabled (true); insilmaril@0: actionEditHeading2URL->setEnabled (true); insilmaril@0: actionEditBugzilla2URL->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: actionEditVymLink->setEnabled (true); insilmaril@0: insilmaril@0: actionEditCopy->setEnabled (true); insilmaril@0: actionEditCut->setEnabled (true); insilmaril@0: actionEditPaste->setEnabled (true); insilmaril@0: actionEditMoveUp->setEnabled (true); insilmaril@0: actionEditMoveDown->setEnabled (true); insilmaril@0: actionEditToggleScroll->setEnabled (true); insilmaril@0: actionEditHeading->setEnabled (true); insilmaril@0: actionEditDelete->setEnabled (true); insilmaril@0: actionEditAddBranch->setEnabled (true); insilmaril@0: actionEditAddBranchAbove->setEnabled (true); insilmaril@0: actionEditAddBranchBelow->setEnabled (true); insilmaril@0: actionEditImportAdd->setEnabled (true); insilmaril@0: actionEditImportReplace->setEnabled (true); insilmaril@0: actionEditSaveBranch->setEnabled (true); insilmaril@0: actionEditSelectFirst->setEnabled (true); insilmaril@0: actionEditSelectLast->setEnabled (true); insilmaril@0: actionEditToggleFloatExport->setEnabled (false); insilmaril@0: actionFormatPickColor->setEnabled (true); insilmaril@0: actionFormatColorBranch->setEnabled (true); insilmaril@0: actionFormatColorSubtree->setEnabled (true); insilmaril@0: switch (selection->getFrameType()) insilmaril@0: { insilmaril@0: case NoFrame: insilmaril@0: actionFormatFrameNone->setOn(true); insilmaril@0: break; insilmaril@0: case Rectangle: insilmaril@0: actionFormatFrameRectangle->setOn(true); insilmaril@0: break; insilmaril@0: default: insilmaril@0: break; insilmaril@0: } insilmaril@0: } insilmaril@0: if ( (typeid(*selection) == typeid(FloatImageObj)) ) insilmaril@0: { insilmaril@0: standardFlagsDefault->setEnabled (false); insilmaril@0: insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@0: actionEditURL->setEnabled (false); insilmaril@0: actionEditHeading2URL->setEnabled (false); insilmaril@0: actionEditBugzilla2URL->setEnabled (false); insilmaril@0: actionEditOpenVymLink->setEnabled (false); insilmaril@0: actionEditVymLink->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@0: actionEditMoveUp->setEnabled (false); insilmaril@0: actionEditMoveDown->setEnabled (false); insilmaril@0: actionEditToggleScroll->setEnabled (false); insilmaril@0: actionEditHeading->setEnabled (false); insilmaril@0: actionEditDelete->setEnabled (true); insilmaril@0: actionEditAddBranch->setEnabled (false); insilmaril@0: actionEditAddBranchAbove->setEnabled (false); insilmaril@0: actionEditAddBranchBelow->setEnabled (false); insilmaril@0: actionEditImportAdd->setEnabled (false); insilmaril@0: actionEditSaveBranch->setEnabled (false); insilmaril@0: actionEditImportReplace->setEnabled (false); insilmaril@0: actionEditSelectFirst->setEnabled (false); insilmaril@0: actionEditSelectLast->setEnabled (false); insilmaril@0: actionEditToggleFloatExport->setOn insilmaril@0: ( ((FloatImageObj*)(selection))->getFloatExport() ); insilmaril@0: actionFormatPickColor->setEnabled (false); insilmaril@0: actionFormatColorBranch->setEnabled (false); insilmaril@0: actionFormatColorSubtree->setEnabled (false); 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@0: actionEditMoveUp->setEnabled (false); insilmaril@0: actionEditMoveDown->setEnabled (false); insilmaril@0: actionEditToggleScroll->setEnabled (false); insilmaril@0: actionEditOpenURL->setEnabled (false); insilmaril@0: actionEditURL->setEnabled (false); insilmaril@0: actionEditOpenVymLink->setEnabled (false); insilmaril@0: actionEditVymLink->setEnabled (false); insilmaril@0: actionEditDeleteVymLink->setEnabled (false); insilmaril@0: actionEditHeading2URL->setEnabled (false); insilmaril@0: actionEditBugzilla2URL->setEnabled (false); insilmaril@0: actionEditHeading->setEnabled (false); insilmaril@0: actionEditDelete->setEnabled (false); insilmaril@0: actionEditAddBranch->setEnabled (false); insilmaril@0: actionEditAddBranchAbove->setEnabled (false); insilmaril@0: actionEditAddBranchBelow->setEnabled (false); insilmaril@0: actionEditSaveBranch->setEnabled (false); insilmaril@0: actionEditImportReplace->setEnabled (false); insilmaril@0: actionEditSelectFirst->setEnabled (false); insilmaril@0: actionEditSelectLast->setEnabled (false); insilmaril@0: actionEditToggleFloatExport->setEnabled (false); insilmaril@0: actionFormatPickColor->setEnabled (false); insilmaril@0: actionFormatColorBranch->setEnabled (false); insilmaril@0: actionFormatColorSubtree->setEnabled (false); insilmaril@0: } insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::setLinkStyle (LinkStyle ls) insilmaril@0: { insilmaril@0: linkstyle=ls; insilmaril@0: 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@0: //setChanged(); insilmaril@0: //saveState(); 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@0: 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@0: return deflinkcolor; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::selectLinkColor() insilmaril@0: { insilmaril@0: // Finish open lineEdits insilmaril@0: if (lineedit) finishedLineEditNoSave(); insilmaril@0: insilmaril@0: QColor col = QColorDialog::getColor( deflinkcolor, this ); insilmaril@0: if ( !col.isValid() ) return; insilmaril@0: setLinkColor( col ); insilmaril@0: setChanged(); 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,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@0: setChanged(); insilmaril@0: saveState(PartOfMap,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@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@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@89: void MapEditor::followLink(int i) insilmaril@89: { insilmaril@89: BranchObj *bo=((BranchObj*)(selection))->linkTargetAt(i); insilmaril@89: if (bo) insilmaril@89: { insilmaril@89: selection->unselect(); insilmaril@89: selection=bo; insilmaril@89: selection->select(); insilmaril@89: ensureSelectionVisible(); insilmaril@89: } insilmaril@89: } insilmaril@89: insilmaril@0: void MapEditor::testFunction() insilmaril@0: { insilmaril@0: cout << "MapEditor::testFunction() called\n"; insilmaril@0: } insilmaril@0: insilmaril@0: void MapEditor::ensureSelectionVisible() insilmaril@0: { insilmaril@0: LinkableMapObj* lmo= dynamic_cast (selection); insilmaril@0: QPoint p; insilmaril@0: if (selection->getOrientation() == OrientLeftOfCenter) insilmaril@0: p= worldMatrix().map(QPoint (lmo->x(),lmo->y())); insilmaril@0: else insilmaril@0: p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height())); insilmaril@0: ensureVisible (p.x(), p.y() ); 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@83: tmpLink=new LinkObj (mapCanvas); insilmaril@90: tmpLink->setBegin (bo_begin); insilmaril@83: tmpLink->setEnd (p); insilmaril@83: tmpLink->updateLink(); insilmaril@83: tmpLink->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@0: movingObj=selection; insilmaril@0: movingObj_start.setX( p.x() - selection->x() ); insilmaril@0: movingObj_start.setY( p.y() - selection->y() ); 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: { insilmaril@0: toggleScroll(); insilmaril@0: } 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: setChanged(); insilmaril@0: saveState(); insilmaril@0: FloatObj *fo=(FloatObj*)(selection); 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@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: } 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,lmosel); 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@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@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@83: tmpLink->setEnd (p); insilmaril@83: tmpLink->updateLink(); 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@83: tmpLink->setEnd ( ((BranchObj*)(dst)) ); insilmaril@83: tmpLink->updateLink(); insilmaril@83: tmpLink->activate(); insilmaril@90: setChanged(); insilmaril@83: insilmaril@83: } else insilmaril@83: { insilmaril@83: delete(tmpLink); insilmaril@83: tmpLink=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@0: if (dst ) insilmaril@0: { insilmaril@0: setChanged(); insilmaril@0: saveState(); 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@83: ((BranchObj*)(selection))->moveBranchTo insilmaril@83: ( insilmaril@83: (BranchObj*)(dst), insilmaril@83: ((BranchObj*)(dst))->getNum() insilmaril@83: ); insilmaril@83: //if (selection) selection->select(); insilmaril@83: } else insilmaril@83: if (e->state() & QMouseEvent::ControlButton) insilmaril@83: { insilmaril@83: ((BranchObj*)(selection))->moveBranchTo insilmaril@83: ( insilmaril@83: (BranchObj*)(dst), insilmaril@83: ((BranchObj*)(dst))->getNum()+1 insilmaril@83: ); insilmaril@83: //if (selection) selection->select(); insilmaril@83: } else insilmaril@83: { insilmaril@83: ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); insilmaril@83: if (dst->getDepth()==0) insilmaril@83: ((BranchObj*)(selection))->move (savePos); insilmaril@83: } insilmaril@0: } 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@0: setChanged(); insilmaril@0: saveState(PartOfMap,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: