hideLinkInExport for Branches (Floats still missing). Floats are now OrnamentedObj.
3 #include <qstatusbar.h>
4 #include <qmessagebox.h>
5 #include <qapplication.h>
7 #include <qpopupmenu.h>
9 #include <qpaintdevicemetrics.h>
11 #include <qfiledialog.h>
14 #include <qcolordialog.h>
17 #include <qinputdialog.h>
18 #include <qdragobject.h>
19 #include <qurloperator.h>
20 #include <qnetworkprotocol.h>
30 #include "editxlinkdialog.h"
32 #include "extrainfodialog.h"
34 #include "linkablemapobj.h"
35 #include "mainwindow.h"
38 #include "texteditor.h"
42 extern TextEditor *textEditor;
43 extern int statusbarTime;
44 extern Main *mainWindow;
45 extern QString tmpVymDir;
46 extern QString clipboardDir;
47 extern bool clipboardEmpty;
48 extern FlagRowObj *systemFlagsDefault;
49 extern FlagRowObj *standardFlagsDefault;
51 extern QPtrList <QAction> actionListBranches;
53 extern QAction *actionFileSave;
54 extern QAction *actionEditUndo;
55 extern QAction *actionEditCopy;
56 extern QAction *actionEditCut;
57 extern QAction *actionEditPaste;
58 extern QAction *actionEditMoveUp;
59 extern QAction *actionEditMoveDown;
60 extern QAction *actionEditToggleScroll;
61 extern QAction *actionEditOpenURL;
62 extern QAction *actionEditURL;
63 extern QAction *actionEditHeading2URL;
64 extern QAction *actionEditBugzilla2URL;
65 extern QAction *actionEditFATE2URL;
66 extern QAction *actionEditOpenVymLink;
67 extern QAction *actionEditVymLink;
68 extern QAction *actionEditDeleteVymLink;
69 extern QAction *actionEditToggleHideExport;
70 extern QAction *actionEditHeading;
71 extern QAction *actionEditDelete;
72 extern QAction *actionEditAddBranch;
73 extern QAction *actionEditAddBranchAbove;
74 extern QAction *actionEditAddBranchBelow;
75 extern QAction *actionEditRemoveBranchHere;
76 extern QAction *actionEditRemoveChilds;
77 extern QAction *actionEditImportAdd;
78 extern QAction *actionEditImportReplace;
79 extern QAction *actionEditSaveBranch;
80 extern QAction *actionEditSelectFirst;
81 extern QAction *actionEditSelectLast;
82 extern QAction *actionEditLoadImage;
83 extern QAction *actionEditToggleFloatExport;
85 extern QAction* actionFormatPickColor;
86 extern QAction* actionFormatColorBranch;
87 extern QAction* actionFormatColorSubtree;
88 extern QAction *actionFormatLinkColorHint;
89 extern QAction *actionFormatBackColor;
90 extern QAction *actionFormatLinkColor;
92 extern QActionGroup* actionGroupModModes;
93 extern QAction* actionModModeColor;
94 extern QAction* actionModModeLink;
95 extern QAction* actionModModeCopy;
97 extern QActionGroup *actionGroupFormatFrameTypes;
98 extern QAction *actionFormatFrameNone;
99 extern QAction *actionFormatFrameRectangle;
101 extern QActionGroup *actionGroupFormatLinkStyles;
102 extern QAction *actionFormatIncludeImagesVer;
103 extern QAction *actionFormatIncludeImagesHor;
104 extern QAction *actionFormatHideLinkUnselected;
105 extern QAction *actionFormatLinkStyleLine;
106 extern QAction *actionFormatLinkStyleParabel;
107 extern QAction *actionFormatLinkStylePolyLine;
108 extern QAction *actionFormatLinkStylePolyParabel;
110 extern QAction *actionViewToggleNoteEditor;
112 extern QAction *actionSettingsAutoedit;
113 extern QAction *actionSettingsAutoselectHeading;
114 extern QAction *actionSettingsAutoselectText;
115 extern QAction *actionSettingsPasteNewHeading;
116 extern QAction *actionSettingsUseFlagGroups;
118 extern QPopupMenu *branchContextMenu;
119 extern QPopupMenu *branchLinksContextMenu;
120 extern QPopupMenu *branchLinksContextMenuDup;
121 extern QPopupMenu *floatimageContextMenu;
122 extern QPopupMenu *saveImageFormatMenu;
123 extern QPopupMenu *exportImageFormatMenu;
124 extern QPopupMenu *canvasContextMenu;
126 extern Settings settings;
128 int MapEditor::mapNum=0; // make instance
130 ///////////////////////////////////////////////////////////////////////
131 ///////////////////////////////////////////////////////////////////////
132 MapEditor::MapEditor(
133 QWidget* parent, bool interactive, const char* name, WFlags f) :
134 QCanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
136 //cout << "Constructor ME "<<this<<endl;
139 viewport()->setAcceptDrops(true);
141 mapCanvas = new QCanvas(1000,800);
142 mapCanvas->setAdvancePeriod(30);
143 mapCanvas->setBackgroundColor (white);
145 setCanvas (mapCanvas);
147 // Always show scroll bars (automatic would flicker sometimes)
148 setVScrollBarMode ( QScrollView::AlwaysOn );
149 setHScrollBarMode ( QScrollView::AlwaysOn );
151 mapCenter = new MapCenterObj(mapCanvas);
152 mapCenter->setVisibility (true);
153 mapCenter->setMapEditor (this);
154 mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
155 mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
159 lineedit = new QLineEdit(this, "lineedit" );
160 connect( lineedit, SIGNAL( returnPressed() ), SLOT( finishedLineEditNoSave() ) );
163 actColor=black; setColor (actColor);
164 defLinkColor=QColor (0,0,255);
165 defXLinkColor=QColor (180,180,180);
166 linkcolorhint=DefaultColor;
167 linkstyle=StylePolyParabel;
169 // Create bitmap cursors, patform dependant
170 #if defined(Q_OS_MACX)
171 #include "icons/cursorhandopen16.xpm"
172 #include "icons/cursorcolorpicker16.xpm"
173 QBitmap cb( 16, 16, chandopen, TRUE );
174 QBitmap cm( 16, 16, chandopenmask, TRUE );
175 handOpenCursor=QCursor ( cb, cm );
176 // set hot spot to tip of picker
177 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 1,15 );
179 #include "icons/cursorhandopen.xpm"
180 #include "icons/cursorcolorpicker.xpm"
182 QBitmap cb( 32, 32, chandopen, TRUE );
183 QBitmap cm( 32, 32, chandopenmask, TRUE );
184 handOpenCursor=QCursor ( cb, cm );
185 // set hot spot to tip of picker
186 pickColorCursor=QCursor ( cursorcolorpicker_xpm, 5,27 );
199 defXLinkColor=QColor (230,230,230);
210 undosTotal=settings.readNumEntry("/vym/mapeditor/undoLevels",50);
214 // Initialize find routine
221 blockReposition=false;
222 blockSaveState=false;
223 isInteractive=interactive;
225 // Create temporary files
228 // Initially set movingCentre
231 mapCenter->reposition(); // for positioning heading
234 MapEditor::~MapEditor()
236 if (imageBuffer) delete imageBuffer;
242 //cout <<"Destructor MapEditor\n";
245 //settings.writeEntry( "/vym/mapeditor/editmode/autoselect", );
249 QColor MapEditor::color()
254 QColor MapEditor::backgroundColor()
256 return mapCanvas->backgroundColor();
259 MapCenterObj* MapEditor::getMapCenter()
264 QCanvas* MapEditor::getCanvas()
269 void MapEditor::adjustCanvasSize()
271 // To adjust the canvas to map, viewport size and position, we have to
272 // do some coordinate magic...
274 // Get rectangle of (scroll-)view.
275 // We want to be in canvas coords, so
276 // we map. Important if view is zoomed...
277 QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
278 visibleWidth(), visibleHeight()) );
280 // Now we need the bounding box of view AND map to calc the correct canvas size.
281 // Why? Because if the map itself is moved out of view, the view has to be enlarged
282 // to avoid jumping aroung...
283 QRect map=mapCenter->getTotalBBox();
285 // right edge - left edge
286 int cw= max(map.x() + map.width(), view.x() + view.width()) - min(map.x(), view.x());
287 int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
290 if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
291 !mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
294 // move the map on canvas (in order to not move it on screen) this is neccessary
295 // a) if topleft corner of canvas is left or above topleft corner of view and also left of
296 // above topleft corner of map. E.g. if map is completly inside view, but it would be possible
297 // to scroll to an empty area of canvas to the left.
298 // b) if topleft corner of map left of or above topleft of canvas
302 if (cw > mapCanvas->width() )
304 if (map.x()<0) dx=-map.x();
306 if (cw < mapCanvas->width() )
307 dx=-min (view.x(),map.x());
308 if (ch > mapCanvas->height() )
310 if (map.y()<0) dy=-map.y();
312 if (ch < mapCanvas->height() )
314 dy=-min (view.y(),map.y());
316 // We really have to resize now. Let's go...
317 mapCanvas->resize (cw,ch);
318 if ( (dx!=0) || (dy!=0) )
320 mapCenter->moveAllBy(dx,dy);
321 mapCenter->reposition();
323 // scroll the view (in order to not move map on screen)
329 bool MapEditor::isRepositionBlocked()
331 return blockReposition;
334 void MapEditor::makeTmpDirs()
336 // Create unique temporary directories
337 tmpMapDir=tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
339 d.mkdir (tmpMapDir,true);
342 void MapEditor::delTmpDirs()
344 removeDir (QDir(tmpMapDir));
347 QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSelection)
349 // tmpdir temporary directory to which data will be written
350 // prefix mapname, which will be appended to images etc.
351 // writeflags Only write flags for "real" save of map, not undo
352 // offset offset of bbox of whole map in canvas.
353 // Needed for XML export
369 ls="StylePolyParabel";
373 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
375 if (linkcolorhint==HeadingColor)
376 colhint=attribut("linkColorHint","HeadingColor");
378 QString mapAttr=attribut("version",__VYM_VERSION);
380 mapAttr+= attribut("author",mapCenter->getAuthor()) +
381 attribut("comment",mapCenter->getComment()) +
382 attribut("date",mapCenter->getDate()) +
383 attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
384 attribut("linkStyle", ls ) +
385 attribut("linkColor", defLinkColor.name() ) +
386 attribut("defXLinkColor", defXLinkColor.name() ) +
387 attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
389 s+=beginElement("vymmap",mapAttr);
392 // Find the used flags while traversing the tree
393 standardFlagsDefault->resetUsedCounter();
395 // Reset the counters before saving
396 FloatImageObj (mapCanvas).resetSaveCounter();
398 // Build xml recursivly
400 s+=mapCenter->saveToDir(tmpdir,prefix,writeflags,offset);
403 if ( typeid(*saveSelection) == typeid(BranchObj) )
404 s+=((BranchObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
405 else if ( typeid(*saveSelection) == typeid(FloatImageObj) )
406 s+=((FloatImageObj*)(saveSelection))->saveToDir(tmpdir,prefix,offset);
408 else if (selection && typeid(*selection)==typeid(BranchObj))
409 // This is used if selected branch is saved from mainwindow
410 s+=((BranchObj*)selection)->saveToDir(tmpdir,prefix,offset);
413 // Save local settings
414 s+=settings.getXMLData (destPath);
417 if (selection && !saveSelection )
418 s+=valueElement("select",selection->getSelectString());
421 s+=endElement("vymmap");
424 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
428 void MapEditor::saveState()
431 saveState (CompleteMap,"",NULL,"",NULL);
434 void MapEditor::saveState(LinkableMapObj *undoSel)
436 // save the given part of the map
437 saveState (PartOfMap,"",undoSel,"",NULL);
440 void MapEditor::saveState(const QString &uc, const QString &rc)
442 // selection does not change during action,
443 // so just save commands for undo and redo
444 LinkableMapObj *unsel;
449 saveState (UndoCommand,uc,unsel,rc,unsel);
452 void MapEditor::saveState(const QString & uncom, LinkableMapObj *unsel)
454 saveState (UndoCommand,uncom,unsel,"FIXME-redoCom",NULL);
457 void MapEditor::saveState(const SaveMode &savemode, const QString &undoCom, LinkableMapObj *undoSel, const QString &redoCom, LinkableMapObj *redoSel)
461 if (blockSaveState) return;
463 /* TODO remove after testing
464 cout << "ME::saveState() begin\n"<<endl;
465 cout << " undosTotal="<<undosTotal<<endl;
466 cout << " undosAvail="<<undosAvail<<endl;
467 cout << " undoNum="<<undoNum<<endl;
468 cout << " ---------------------------"<<endl;
472 // Find out current undo directory
473 if (undosAvail<undosTotal) undosAvail++;
475 if (undoNum>undosTotal) undoNum=1;
478 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
479 QString bakMapPath=QDir::convertSeparators(bakMapDir+"/map.xml");
481 // Create bakMapDir if not available
484 makeSubDirs (bakMapDir);
486 // Save current selection
487 QString redoSelection="";
489 redoSelection=redoSel->getSelectString();
491 // Save the object, which should be undone
492 QString undoSelection="";
494 undoSelection=undoSel->getSelectString();
496 // Save depending on how much needs to be saved
497 QString undoCommand="";
498 if (savemode==UndoCommand)
503 else if (savemode==PartOfMap && undoSel)
505 undoCommand="undoPart (\""+ undoSelection+"\",\""+bakMapPath+"\")";
506 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),undoSel);
509 undoCommand="undoMap (\""+bakMapPath+"\")";
510 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
513 if (!backupXML.isEmpty())
514 // Write XML Data to disk
515 saveStringToDisk (QString(bakMapPath),backupXML);
518 set.setEntry (QString("undoCommand"),undoCommand);
519 set.setEntry (QString("undoSelection"),undoSelection);
520 set.setEntry (QString("redoCommand"),redoCom);
521 set.setEntry (QString("redoSelection"),redoSelection);
522 set.writeSettings(QString(bakMapDir+"/commands"));
524 /* TODO remove after testing
525 cout << " into="<< bakMapDir<<endl;
526 cout << " undosAvail="<<undosAvail<<endl;
527 cout << " undoNum="<<undoNum<<endl;
528 cout << " ---------------------------"<<endl;
529 cout << " undoCom="<<undoCommand<<endl;
530 cout << " undoSel="<<undoSelection<<endl;
531 cout << " ---------------------------"<<endl;
532 cout << " redoCom="<<redoCom<<endl;
533 cout << " redoSel="<<redoSelection<<endl;
534 cout << " ---------------------------"<<endl<<endl;
538 void MapEditor::parseAtom(const QString &atom)
545 // Split string s into command and parameters
546 api.parseCommand (atom);
547 QString com=api.command();
550 if (com=="moveBranchUp")
552 else if (com=="moveBranchDown")
554 else if (com=="move")
556 if (api.checkParamCount(2) && selection )
566 else if (com=="linkBranchToPos")
568 if (selection && typeid(*selection) == typeid(BranchObj) )
570 if (api.checkParamCount(4))
572 s=api.parString(ok,0);
573 LinkableMapObj *dst=mapCenter->findObjBySelect (s);
576 if (typeid(*dst) == typeid(BranchObj) )
578 // Get number in parent
581 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),x);
582 } else if (typeid(*dst) == typeid(MapCenterObj) )
584 ((BranchObj*)selection)->moveBranchTo ((BranchObj*)(dst),-1);
585 // Get coordinates of mainbranch
590 if (ok) ((BranchObj*)selection)->move (x,y);
596 } else if (com=="setHeading")
598 if (api.checkParamCount(1))
600 s=api.parString (ok,0);
601 if (ok) setHeading (s);
603 } else if (com=="setURL")
605 if (api.checkParamCount(1))
607 s=api.parString (ok,0);
610 } else if (com=="setVymLink")
612 if (api.checkParamCount(1))
614 s=api.parString (ok,0);
615 if (ok) setVymLink(s);
618 // Internal commands, used for undo etc.
619 else if (com==QString("undoMap"))
621 if (api.checkParamCount(1))
622 undoXML("",api.parString (ok,0));
623 } else if (com==QString("undoPart"))
625 if (api.checkParamCount(2))
627 s=api.parString (ok,0);
628 t=api.parString (ok,1);
631 } else if (com=="select")
632 if (api.checkParamCount(1))
634 s=api.parString(ok,0);
639 api.setError ("Unknown command in: "+atom);
640 cout << "ME::parse api should have error now...\n";
646 cout << "MapEditor::parseAtom: Error!\n";
647 cout << " "<<api.errorDesc()<<endl;
652 void MapEditor::finishedLineEditNoSave()
654 // This is called by finishedLineEdit or any MapEditor method,
655 // which wants to assure, that lineedits finish, before e.g. a branch is
658 // After calling LineEdit and using the clipboard, the
659 // focus is not any longer on the main widget, we
660 // have to restore it using parentWidget()->setFocus()
664 editingBO->setHeading(lineedit->text() );
666 lineedit->releaseKeyboard();
668 parentWidget()->setFocus();
669 mapCenter->reposition();
671 ensureSelectionVisible();
676 bool MapEditor::isDefault()
681 bool MapEditor::isUnsaved()
686 bool MapEditor::hasChanged()
691 void MapEditor::setChanged()
696 actionEditUndo->setEnabled (true);
697 actionFileSave->setEnabled (true);
701 void MapEditor::closeMap()
703 // Finish open lineEdits
704 if (lineedit) finishedLineEditNoSave();
706 // Unselect before disabling the toolbar actions
707 if (selection) selection->unselect();
715 void MapEditor::setFilePath(QString fname)
717 setFilePath (fname,fname);
720 void MapEditor::setFilePath(QString fname, QString destname)
722 if (fname.isEmpty() || fname=="")
729 filePath=fname; // becomes absolute path
730 fileName=fname; // gets stripped of path
731 destPath=destname; // needed for vymlinks
733 // If fname is not an absolute path, complete it
734 filePath=QDir(fname).absPath();
735 fileDir=filePath.left (1+filePath.findRev ("/"));
737 // Set short name, too. Search from behind:
738 int i=fileName.findRev("/");
739 if (i>=0) fileName=fileName.remove (0,i+1);
741 // Forget the .vym (or .xml) for name of map
742 mapName=fileName.left(fileName.findRev(".",-1,true) );
746 QString MapEditor::getFilePath()
751 QString MapEditor::getFileName()
756 QString MapEditor::getMapName()
761 QString MapEditor::getDestPath()
766 ErrorCode MapEditor::load (QString fname, LoadMode lmode)
768 // Finish open lineEdits
769 if (lineedit) finishedLineEditNoSave();
771 ErrorCode err=success;
775 if (selection) selection->unselect();
778 mapCenter->setMapEditor(this);
779 // (map state is set later at end of load...)
782 saveState(selection);
786 mapBuilderHandler handler;
789 // I am paranoid: file should exist anyway
790 // according to check in mainwindow.
793 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
794 tr("Couldn't open map " +fname)+".");
798 blockReposition=true;
799 QXmlInputSource source( file);
800 QXmlSimpleReader reader;
801 reader.setContentHandler( &handler );
802 reader.setErrorHandler( &handler );
803 handler.setMapEditor( this );
804 handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path
805 handler.setInputFile (file.name());
806 handler.setLoadMode (lmode);
808 bool ok = reader.parse( source );
809 blockReposition=false;
810 blockSaveState=false;
814 mapCenter->reposition();
824 QMessageBox::critical( 0, tr( "Critical Parse Error" ),
825 tr( handler.errorProtocol() ) );
827 // Still return "success": the map maybe at least
828 // partially read by the parser
835 int MapEditor::save (const SaveMode &savemode)
837 // Finish open lineEdits
838 if (lineedit) finishedLineEditNoSave();
842 // The SaveMode UndoCommand is not supported here
843 if (savemode==UndoCommand) return 1;
845 // Create mapName and fileDir
846 makeSubDirs (fileDir);
850 fname=mapName+".xml";
852 // use name given by user, even if he chooses .doc
857 if (savemode==CompleteMap || selection==NULL)
858 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
860 saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
862 if (!saveStringToDisk(fileDir+fname,saveFile))
869 actionFileSave->setEnabled(false);
875 void MapEditor::setZipped (bool z)
880 bool MapEditor::saveZipped ()
885 void MapEditor::print()
887 // Finish open lineEdits
888 if (lineedit) finishedLineEditNoSave();
892 printer = new QPrinter;
893 printer->setColorMode (QPrinter::Color);
894 printer->setPrinterName (settings.readEntry("/vym/mainwindow/printerName",printer->printerName()));
897 QRect totalBBox=mapCenter->getTotalBBox();
899 // Try to set orientation automagically
900 // Note: Interpretation of generated postscript is amibiguous, if
901 // there are problems with landscape mode, see
902 // http://sdb.suse.de/de/sdb/html/jsmeix_print-cups-landscape-81.html
904 if (totalBBox.width()>totalBBox.height())
905 // recommend landscape
906 printer->setOrientation (QPrinter::Landscape);
908 // recommend portrait
909 printer->setOrientation (QPrinter::Portrait);
911 if ( printer->setup(this) )
912 // returns false, if printing is canceled
914 QPainter pp(printer);
916 // Don't print the visualisation of selection
917 LinkableMapObj *oldselection=NULL;
920 oldselection=selection;
921 selection->unselect();
924 // Handle sizes of map and paper:
926 // setWindow defines which part of the canvas will be transformed
927 // setViewport defines area on paper in device coordinates (dpi)
928 // e.g. (0,50,700,700) is upper part on A4
929 // see also /usr/lib/qt3/doc/html/coordsys.html
931 QPaintDeviceMetrics metrics (printer);
933 double paperAspect = (double)metrics.width() / (double)metrics.height();
934 double mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
936 QRect mapRect=totalBBox;
937 QCanvasRectangle *frame=NULL;
938 QCanvasText *footerFN=NULL;
939 QCanvasText *footerDate=NULL;
940 if (printFrame || printFooter)
945 // Print frame around map
946 mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10,
947 totalBBox.width()+20, totalBBox.height()+20);
948 frame=new QCanvasRectangle (mapRect,mapCanvas);
949 frame->setBrush (QColor(white));
950 frame->setPen (QColor(black));
954 /* TODO remove after testing
955 QCanvasLine *l=new QCanvasLine (mapCanvas);
956 l->setPoints (0,0,mapRect.width(),mapRect.height());
957 l->setPen (QPen(QColor(black), 1));
964 // Print footer below map
966 font.setPointSize(10);
967 footerFN=new QCanvasText (mapCanvas);
968 footerFN->setText ("VYM - " + fileName);
969 footerFN->setFont(font);
970 footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
971 footerFN->setZ(Z_TEXT);
973 footerDate=new QCanvasText (mapCanvas);
974 footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
975 footerDate->setFont(font);
976 footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
977 footerDate->setZ(Z_TEXT);
980 pp.setWindow (mapRect.x(), mapRect.y(), mapRect.width(), mapRect.height()+20);
983 pp.setWindow (mapRect);
986 if (mapAspect>=paperAspect)
988 // Fit horizontally to paper width
989 pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );
992 // Fit vertically to paper height
993 pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());
996 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to printer
998 // Delete Frame and footer
1002 delete (footerDate);
1004 if (frame) delete (frame);
1006 // Restore selection
1009 selection=oldselection;
1010 selection->select();
1013 // Save settings in vymrc
1014 settings.writeEntry("/vym/mainwindow/printerName",printer->printerName());
1018 QPixmap MapEditor::getPixmap()
1020 QRect mapRect=mapCenter->getTotalBBox();
1021 QPixmap pix (mapRect.size());
1024 // Don't print the visualisation of selection
1025 LinkableMapObj *oldselection=NULL;
1028 oldselection=selection;
1029 selection->unselect();
1032 pp.setWindow (mapRect);
1034 mapCanvas->drawArea(mapRect, &pp); // draw Canvas to painter
1037 // Restore selection
1040 selection=oldselection;
1041 selection->select();
1047 void MapEditor::exportImage(QString fn)
1049 // Finish open lineEdits
1050 if (lineedit) finishedLineEditNoSave();
1052 QPixmap pix (getPixmap());
1053 pix.save(fn, "PNG");
1056 void MapEditor::exportImage(QString fn, int item)
1058 // Finish open lineEdits
1059 if (lineedit) finishedLineEditNoSave();
1061 QPixmap pix (getPixmap());
1062 pix.save(fn, exportImageFormatMenu->text(item) );
1065 void MapEditor::exportOOPresentation(const QString &fn, const QString &cf)
1069 ex.setMapCenter(mapCenter);
1070 if (ex.setConfigFile(cf)) ex.exportPresentation();
1075 void MapEditor::exportXML(const QString &dir)
1077 // Create subdirectories
1080 // write to directory
1081 QString saveFile=saveToDir (dir,mapName+"-",true,mapCenter->getTotalBBox().topLeft() ,NULL);
1084 file.setName ( dir + "/"+mapName+".xml");
1085 if ( !file.open( IO_WriteOnly ) )
1087 // This should neverever happen
1088 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1092 // Write it finally, and write in UTF8, no matter what
1093 QTextStream ts( &file );
1094 ts.setEncoding (QTextStream::UnicodeUTF8);
1098 // Now write image, too
1099 exportImage (dir+"/images/"+mapName+".png");
1102 void MapEditor::clear()
1106 selection->unselect();
1113 void MapEditor::copy()
1115 // Finish open lineEdits
1116 if (lineedit) finishedLineEditNoSave();
1120 // write to directory
1121 QString clipfile="part";
1122 QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
1125 file.setName ( clipboardDir + "/"+clipfile+".xml");
1126 if ( !file.open( IO_WriteOnly ) )
1128 // This should neverever happen
1129 QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
1133 // Write it finally, and write in UTF8, no matter what
1134 QTextStream ts( &file );
1135 ts.setEncoding (QTextStream::UnicodeUTF8);
1139 clipboardEmpty=false;
1144 void MapEditor::redo()
1146 // Finish open lineEdits
1147 if (lineedit) finishedLineEditNoSave();
1149 blockSaveState=true;
1151 // Find out current undo directory
1152 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1154 // Restore variables
1155 QString undoCommand;
1156 QString undoSelection;
1157 QString redoCommand;
1158 QString redoSelection;
1160 set.readSettings(QString(bakMapDir+"/commands"));
1161 undoCommand=set.readEntry ("undoCommand");
1162 undoSelection=set.readEntry ("undoSelection");
1163 redoCommand=set.readEntry ("redoCommand");
1164 redoSelection=set.readEntry ("redoSelection");
1166 // select object before redo
1167 if (!redoSelection.isEmpty())
1168 select (redoSelection);
1170 /* TODO remove testing
1171 cout << "ME::redo() begin\n";
1172 cout << " undosTotal="<<undosTotal<<endl;
1173 cout << " undosAvail="<<undosAvail<<endl;
1174 cout << " undoNum="<<undoNum<<endl;
1175 cout << " ---------------------------"<<endl;
1176 cout << " undoCom="<<undoCommand<<endl;
1177 cout << " undoSel="<<undoSelection<<endl;
1178 cout << " ---------------------------"<<endl;
1179 cout << " redoCom="<<redoCommand<<endl;
1180 cout << " redoSel="<<redoSelection<<endl;
1181 cout << " ---------------------------"<<endl;
1183 parseAtom (undoCommand);
1184 mapCenter->reposition();
1186 //if (!redoSelection.isEmpty())
1187 // select (redoSelection);
1191 // Undo not longer available now
1192 actionEditUndo->setEnabled (false);
1194 undoNum--; if (undoNum<1) undoNum=undosTotal;
1196 blockSaveState=false;
1197 /* TODO remove testing
1198 cout << "ME::redo() end\n";
1199 cout << " undosAvail="<<undosAvail<<endl;
1200 cout << " undoNum="<<undoNum<<endl;
1201 cout << " ---------------------------"<<endl<<endl;
1205 void MapEditor::undo()
1207 // Finish open lineEdits
1208 if (lineedit) finishedLineEditNoSave();
1210 blockSaveState=true;
1212 // Find out current undo directory
1213 QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(undoNum));
1215 // Restore variables
1216 QString undoCommand;
1217 QString undoSelection;
1218 QString redoCommand;
1219 QString redoSelection;
1221 set.readSettings(QString(bakMapDir+"/commands"));
1222 undoCommand= set.readEntry ("undoCommand");
1223 undoSelection=set.readEntry ("undoSelection");
1224 redoCommand= set.readEntry ("redoCommand");
1225 redoSelection=set.readEntry ("redoSelection");
1227 // select object before undo
1228 if (!undoSelection.isEmpty())
1229 select (undoSelection);
1232 cout << "ME::undo() begin\n";
1233 cout << " undosTotal="<<undosTotal<<endl;
1234 cout << " undosAvail="<<undosAvail<<endl;
1235 cout << " undoNum="<<undoNum<<endl;
1236 cout << " ---------------------------"<<endl;
1237 cout << " undoCom="<<undoCommand<<endl;
1238 cout << " undoSel="<<undoSelection<<endl;
1239 cout << " ---------------------------"<<endl;
1240 cout << " redoCom="<<redoCommand<<endl;
1241 cout << " redoSel="<<redoSelection<<endl;
1242 cout << " ---------------------------"<<endl;
1244 parseAtom (undoCommand);
1245 mapCenter->reposition();
1247 //if (!redoSelection.isEmpty())
1248 // select (redoSelection);
1252 // Undo not longer available now
1253 actionEditUndo->setEnabled (false);
1255 undoNum--; if (undoNum<1) undoNum=undosTotal;
1257 blockSaveState=false;
1258 /* TODO remove testing
1259 cout << "ME::undo() end\n";
1260 cout << " undosAvail="<<undosAvail<<endl;
1261 cout << " undoNum="<<undoNum<<endl;
1262 cout << " ---------------------------"<<endl<<endl;
1266 void MapEditor::undoXML(const QString &undoSel, const QString &bakMapPath)
1268 QString bakMapDir=bakMapPath.left(bakMapPath.findRev("/"));
1270 QFile file (bakMapPath);
1274 // We need to parse saved XML data
1275 mapBuilderHandler handler;
1276 QXmlInputSource source( file);
1277 QXmlSimpleReader reader;
1278 reader.setContentHandler( &handler );
1279 reader.setErrorHandler( &handler );
1280 handler.setMapEditor( this );
1281 handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1282 if (undoSel.isEmpty())
1286 handler.setLoadMode (NewMap);
1290 handler.setLoadMode (ImportReplace);
1292 blockReposition=true;
1293 bool ok = reader.parse( source );
1294 blockReposition=false;
1297 // This should never ever happen
1298 QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1299 tr( handler.errorProtocol() )+" in "+bakMapDir );
1303 QMessageBox::critical( 0, tr( "Critical Error" ),
1304 tr("Temporary directory %1 used for undo is gone. \n"
1305 "I will create a new one, but at the moment no undo is available.\n"
1306 "Maybe you want to reload your original data.\n\n"
1307 "Sorry for any inconveniences.").arg(bakMapDir) );
1312 void MapEditor::pasteNoSave()
1314 // Finish open lineEdits
1315 if (lineedit) finishedLineEditNoSave();
1317 load (clipboardDir+"/part.xml",ImportAdd);
1320 void MapEditor::cutNoSave()
1326 void MapEditor::paste()
1328 if (selection && (typeid(*selection) == typeid(BranchObj) ||
1329 typeid(*selection) == typeid(MapCenterObj)))
1331 saveState(selection);
1333 mapCenter->reposition();
1338 void MapEditor::cut()
1340 saveState(selection->getParObj());
1343 mapCenter->reposition();
1347 void MapEditor::move(const int &x, const int &y)
1349 // TODO no saveState, because this is only internal at undo so far
1350 if (selection) selection->move(x,y);
1351 if (typeid(*selection) == typeid(FloatImageObj))
1352 ((FloatImageObj*)selection)->setRelPos();
1355 void MapEditor::moveBranchUp()
1357 // Finish open lineEdits
1358 if (lineedit) finishedLineEditNoSave();
1362 if (typeid(*selection) == typeid(BranchObj) )
1364 bo=(BranchObj*)selection;
1365 par=(BranchObj*)(bo->getParObj());
1366 selection->unselect();
1367 selection=par->moveBranchUp (bo);
1368 selection->select();
1369 saveState("moveBranchDown ()",bo);
1370 mapCenter->reposition();
1371 ensureSelectionVisible();
1375 void MapEditor::moveBranchDown()
1377 // Finish open lineEdits
1378 if (lineedit) finishedLineEditNoSave();
1382 if (typeid(*selection) == typeid(BranchObj) )
1384 bo=(BranchObj*)selection;
1385 par=(BranchObj*)(bo->getParObj());
1386 selection->unselect();
1387 selection=par->moveBranchDown(bo);
1388 selection->select();
1389 saveState("moveBranchUp ()",bo);
1390 mapCenter->reposition();
1391 ensureSelectionVisible();
1395 void MapEditor::editHeading()
1397 // Finish open lineEdits
1398 if (lineedit) finishedLineEditNoSave();
1401 (typeid(*selection) == typeid(BranchObj) ||
1402 typeid(*selection) == typeid(MapCenterObj) ) )
1404 editingBO=(BranchObj*)selection;
1405 saveState("setHeading (\""+((BranchObj*)selection)->getHeading()+"\")",editingBO );
1407 ensureSelectionVisible();
1408 QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
1409 lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
1410 QString s=editingBO->getHeading();
1411 lineedit->setText(s);
1412 lineedit->setCursorPosition(1);
1413 if (actionSettingsAutoselectText->isOn() && !s.isEmpty() && actionSettingsPasteNewHeading->isOn() )
1414 lineedit->selectAll();
1416 lineedit->grabKeyboard();
1417 lineedit->setFocus();
1421 void MapEditor::setHeading(const QString &s)
1423 // Internal function, no saveState needed
1425 (typeid(*selection) == typeid(BranchObj) ||
1426 typeid(*selection) == typeid(MapCenterObj) ) )
1428 ((BranchObj*)selection)->setHeading(s);
1429 mapCenter->reposition();
1431 ensureSelectionVisible();
1435 void MapEditor::setURL (const QString &s)
1437 // Internal function, no saveState needed
1439 (typeid(*selection) == typeid(BranchObj) ||
1440 typeid(*selection) == typeid(MapCenterObj) ) )
1442 ((BranchObj*)selection)->setURL(s);
1443 mapCenter->reposition();
1445 ensureSelectionVisible();
1449 void MapEditor::setVymLink (const QString &s)
1451 // Internal function, no saveState needed
1453 (typeid(*selection) == typeid(BranchObj) ||
1454 typeid(*selection) == typeid(MapCenterObj) ) )
1456 ((BranchObj*)selection)->setVymLink(s);
1457 mapCenter->reposition();
1459 ensureSelectionVisible();
1463 void MapEditor::addNewBranch(int pos)
1465 // Finish open lineEdits
1466 if (lineedit) finishedLineEditNoSave();
1469 (typeid(*selection) == typeid(BranchObj) ||
1470 typeid(*selection) == typeid(MapCenterObj) ) )
1472 saveState(selection); //TODO undoCommand
1474 BranchObj* bo1 = (BranchObj*) selection;
1475 bool wasScrolled=false;
1476 BranchObj *newbo=NULL;
1479 // save scroll state. If scrolled, automatically select
1480 // new branch in order to tmp unscroll parent...
1481 wasScrolled=bo1->isScrolled();
1482 newbo=bo1->addBranch();
1485 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1489 // add above selection
1490 newbo=parbo->insertBranch(bo1->getNum());
1492 // add below selection
1493 newbo=parbo->insertBranch(bo1->getNum()+1);
1495 // This should not happen...
1500 LinkableMapObj *oldselection=selection;
1502 mapCenter->reposition();
1504 if (actionSettingsAutoedit->isOn() ||
1505 actionSettingsAutoselectHeading->isOn() )
1507 selection->unselect();
1509 selection->select();
1510 if (actionSettingsPasteNewHeading->isOn() )
1512 BranchObj *bo2= (BranchObj*)selection;
1513 bo2->setHeading("");
1515 if (actionSettingsAutoedit->isOn() )
1517 if (!actionSettingsAutoselectHeading->isOn()
1520 selection->unselect();
1521 selection=oldselection;
1522 selection->select();
1529 void MapEditor::addNewBranchHere()
1531 // Finish open lineEdits
1532 if (lineedit) finishedLineEditNoSave();
1535 (typeid(*selection) == typeid(BranchObj) ) )
1537 saveState(selection);
1539 BranchObj* bo1 = (BranchObj*) selection;
1540 bool wasScrolled=false;
1541 BranchObj *newbo=NULL;
1542 BranchObj *parbo=(BranchObj*)(selection->getParObj());
1545 // add below selection
1546 newbo=parbo->insertBranch(bo1->getNum()+1);
1549 LinkableMapObj *oldselection=selection;
1550 ((BranchObj*)selection)->moveBranchTo (newbo,-1);
1552 mapCenter->reposition();
1554 if (actionSettingsAutoedit->isOn() ||
1555 actionSettingsAutoselectHeading->isOn() )
1557 selection->unselect();
1559 selection->select();
1560 if (actionSettingsPasteNewHeading->isOn() )
1562 BranchObj *bo2= (BranchObj*)selection;
1563 bo2->setHeading("");
1565 if (actionSettingsAutoedit->isOn() )
1567 if (!actionSettingsAutoselectHeading->isOn()
1570 selection->unselect();
1571 selection=oldselection;
1572 selection->select();
1578 void MapEditor::deleteSelection()
1580 // Finish open lineEdits
1581 if (lineedit) finishedLineEditNoSave();
1583 if (selection && typeid(*selection) ==typeid(BranchObj) )
1585 if (selection->getDepth()>1)
1586 // Normal branch, save parent with childs
1587 saveState(selection->getParObj());
1589 // Mainbranch, save whole map
1590 // TODO Better would be to insert mainbranch again at pos
1591 // But undoCommand is missing right now
1593 BranchObj* bo=dynamic_cast <BranchObj*> (selection);
1594 BranchObj* par=(BranchObj*)(bo->getParObj());
1597 par->removeBranch(bo);
1599 selection->select();
1600 ensureSelectionVisible();
1601 mapCenter->reposition();
1604 if (selection && typeid(*selection) ==typeid(FloatImageObj) )
1606 saveState(selection->getParObj());
1607 FloatImageObj* fio=dynamic_cast <FloatImageObj*> (selection);
1608 BranchObj* par=(BranchObj*)(fio->getParObj());
1611 par->removeFloatImage(fio);
1613 selection->select();
1614 ensureSelectionVisible();
1615 mapCenter->reposition();
1620 LinkableMapObj* MapEditor::getSelection()
1625 bool MapEditor::select (const QString &s)
1627 LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
1629 // Finally select the found object
1632 if (selection) unselect();
1634 selection->select();
1636 ensureSelectionVisible();
1642 void MapEditor::unselect()
1646 selectionLast=selection;
1647 selection->unselect();
1652 void MapEditor::reselect()
1656 selection=selectionLast;
1657 selection->select();
1662 void MapEditor::selectNextBranch()
1664 // Increase number of branch
1667 QString s=selection->getSelectString();
1673 part=s.section(",",-1);
1675 num=part.right(part.length() - 3);
1677 s=s.left (s.length() -num.length());
1680 num=QString ("%1").arg(num.toUInt()+1);
1684 // Try to select this one
1685 if (select (s)) return;
1687 // We have no direct successor,
1688 // try to increase the parental number in order to
1689 // find a successor with same depth
1691 int d=selection->getDepth();
1696 while (!found && d>0)
1698 s=s.section (",",0,d-1);
1699 // replace substring of current depth in s with "1"
1700 part=s.section(",",-1);
1702 num=part.right(part.length() - 3);
1706 // increase number of parent
1707 num=QString ("%1").arg(num.toUInt()+1);
1708 s=s.section (",",0,d-2) + ","+ typ+num;
1711 // Special case, look at orientation
1712 if (selection->getOrientation()==OrientRightOfCenter)
1713 num=QString ("%1").arg(num.toUInt()+1);
1715 num=QString ("%1").arg(num.toUInt()-1);
1720 // pad to oldDepth, select the first branch for each depth
1721 for (i=d;i<oldDepth;i++)
1726 if ( ((BranchObj*)selection)->countBranches()>0)
1734 // try to select the freshly built string
1742 void MapEditor::selectPrevBranch()
1744 // Decrease number of branch
1747 QString s=selection->getSelectString();
1753 part=s.section(",",-1);
1755 num=part.right(part.length() - 3);
1757 s=s.left (s.length() -num.length());
1760 num=QString ("%1").arg(num.toUInt()-1);
1764 // Try to select this one
1765 if (select (s)) return;
1767 // We have no direct precessor,
1768 // try to decrease the parental number in order to
1769 // find a precessor with same depth
1771 int d=selection->getDepth();
1776 while (!found && d>0)
1778 s=s.section (",",0,d-1);
1779 // replace substring of current depth in s with "1"
1780 part=s.section(",",-1);
1782 num=part.right(part.length() - 3);
1786 // decrease number of parent
1787 num=QString ("%1").arg(num.toUInt()-1);
1788 s=s.section (",",0,d-2) + ","+ typ+num;
1791 // Special case, look at orientation
1792 if (selection->getOrientation()==OrientRightOfCenter)
1793 num=QString ("%1").arg(num.toUInt()-1);
1795 num=QString ("%1").arg(num.toUInt()+1);
1800 // pad to oldDepth, select the last branch for each depth
1801 for (i=d;i<oldDepth;i++)
1805 if ( ((BranchObj*)selection)->countBranches()>0)
1806 s+=",bo:"+ QString ("%1").arg( ((BranchObj*)selection)->countBranches()-1 );
1813 // try to select the freshly built string
1821 void MapEditor::selectUpperBranch()
1823 // Finish open lineEdits
1824 if (lineedit) finishedLineEditNoSave();
1828 if (typeid(*selection) == typeid(BranchObj))
1830 if (selection->getOrientation()==OrientRightOfCenter)
1833 if (selection->getDepth()==1)
1841 void MapEditor::selectLowerBranch()
1843 // Finish open lineEdits
1844 if (lineedit) finishedLineEditNoSave();
1848 if (typeid(*selection) == typeid(BranchObj))
1850 if (selection->getOrientation()==OrientRightOfCenter)
1853 if (selection->getDepth()==1)
1862 void MapEditor::selectLeftBranch()
1864 // Finish open lineEdits
1865 if (lineedit) finishedLineEditNoSave();
1871 if (typeid(*selection) == typeid(MapCenterObj))
1873 par= (BranchObj*) selection;
1874 bo=par->getLastSelectedBranch();
1877 // Workaround for reselecting on left and right side
1878 if (bo->getOrientation()==OrientRightOfCenter)
1880 bo=par->getLastBranch();
1886 selection->select();
1888 ensureSelectionVisible();
1893 par=(BranchObj*)(selection->getParObj());
1894 if (selection->getOrientation()==OrientRightOfCenter)
1896 if (typeid(*selection) == typeid(BranchObj) ||
1897 typeid(*selection) == typeid(FloatImageObj))
1899 selection->unselect();
1901 selection->select();
1903 ensureSelectionVisible();
1907 if (typeid(*selection) == typeid(BranchObj) )
1909 bo=((BranchObj*)selection)->getLastSelectedBranch();
1912 selection->unselect();
1914 selection->select();
1916 ensureSelectionVisible();
1924 void MapEditor::selectRightBranch()
1926 // Finish open lineEdits
1927 if (lineedit) finishedLineEditNoSave();
1934 if (typeid(*selection) == typeid(MapCenterObj))
1936 par= (BranchObj*) selection;
1937 bo=par->getLastSelectedBranch();
1940 // Workaround for relecting on left and right side
1941 if (bo->getOrientation()==OrientLeftOfCenter)
1942 bo=par->getFirstBranch();
1947 selection->select();
1948 ensureSelectionVisible();
1953 par=(BranchObj*)(selection->getParObj());
1954 if (selection->getOrientation()==OrientLeftOfCenter)
1956 if (typeid(*selection) == typeid(BranchObj) ||
1957 typeid(*selection) == typeid(FloatImageObj))
1959 selection->unselect();
1961 selection->select();
1963 ensureSelectionVisible();
1967 if (typeid(*selection) == typeid(BranchObj) )
1969 bo=((BranchObj*)selection)->getLastSelectedBranch();
1972 selection->unselect();
1974 selection->select();
1976 ensureSelectionVisible();
1984 void MapEditor::selectFirstBranch()
1986 // Finish open lineEdits
1987 if (lineedit) finishedLineEditNoSave();
1993 if (typeid(*selection) == typeid(BranchObj))
1995 bo1= (BranchObj*) selection;
1996 par=(BranchObj*)(bo1->getParObj());
1997 bo2=par->getFirstBranch();
2001 selection->select();
2002 ensureSelectionVisible();
2009 void MapEditor::selectLastBranch()
2011 // Finish open lineEdits
2012 if (lineedit) finishedLineEditNoSave();
2018 if (typeid(*selection) == typeid(BranchObj))
2020 bo1= (BranchObj*) selection;
2021 par=(BranchObj*)(bo1->getParObj());
2022 bo2=par->getLastBranch();
2026 selection->select();
2027 ensureSelectionVisible();
2034 void MapEditor::setColor(QColor c)
2039 void MapEditor::selectBackgroundColor()
2041 // Finish open lineEdits
2042 if (lineedit) finishedLineEditNoSave();
2044 QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
2045 if ( !col.isValid() ) return;
2046 setBackgroundColor( col );
2050 void MapEditor::setBackgroundColor(QColor c)
2052 mapCanvas->setBackgroundColor (c);
2055 QColor MapEditor::pickColor()
2059 if (typeid(*selection) == typeid(BranchObj) ||
2060 typeid(*selection) == typeid(MapCenterObj))
2062 BranchObj *bo=(BranchObj*)selection;
2063 actColor=bo->getColor();
2069 void MapEditor::colorItem()
2073 if (typeid(*selection) == typeid(BranchObj) ||
2074 typeid(*selection) == typeid(MapCenterObj))
2076 saveState(selection); //TODO undoCommand
2077 BranchObj *bo=(BranchObj*)selection;
2078 bo->setColor(actColor); // color branch
2083 void MapEditor::colorBranch()
2087 if (typeid(*selection) == typeid(BranchObj) ||
2088 typeid(*selection) == typeid(MapCenterObj))
2090 saveState(selection); //TODO undoCommand
2091 BranchObj *bo=(BranchObj*)selection;
2092 bo->setColorChilds(actColor); // color links, color childs
2098 void MapEditor::toggleStandardFlag(QString f)
2102 saveState(selection);// TODO undoCommand
2103 ((BranchObj*)selection)->toggleStandardFlag (f,actionSettingsUseFlagGroups);
2108 void MapEditor::setViewCenter()
2110 // transform to CanvasView Coord:
2111 QPoint p=worldMatrix().map(movingCenter);
2112 center ( p.x(), p.y());
2116 BranchObj* MapEditor::findText (QString s, bool cs)
2119 { // Nothing found or new find process
2121 // nothing found, start again
2123 itFind=mapCenter->first();
2125 bool searching=true;
2126 bool foundNote=false;
2127 while (searching && !EOFind)
2131 // Searching in Note
2132 if (itFind->getNote().contains(s,cs))
2134 if (selection!=itFind)
2136 if (selection) ((BranchObj*)selection)->unselect();
2138 selection->select();
2140 ensureSelectionVisible();
2142 if (textEditor->findText(s,cs))
2148 // Searching in Heading
2149 if (searching && itFind->getHeading().contains (s,cs) )
2151 if (selection) ((BranchObj*)selection)->unselect();
2153 selection->select();
2155 ensureSelectionVisible();
2161 itFind=itFind->next();
2162 if (!itFind) EOFind=true;
2168 return (BranchObj*)selection;
2173 void MapEditor::findReset()
2174 { // Necessary if text to find changes during a find process
2179 void MapEditor::openURL()
2183 if (typeid(*selection) == typeid(BranchObj) ||
2184 typeid(*selection) == typeid(MapCenterObj))
2186 QString url=((BranchObj*)selection)->getURL();
2188 QProcess *proc = new QProcess( this );
2190 proc->addArgument( settings.readEntry("/vym/mainwindow/readerURL" ));
2191 proc->addArgument( url);
2193 if ( !proc->start() )
2195 if (mainWindow->settingsURL() )
2201 void MapEditor::editURL()
2203 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2204 typeid(*selection) == typeid(MapCenterObj)) )
2207 BranchObj *bo=(BranchObj*)selection;
2208 QString text = QInputDialog::getText(
2209 "VYM", tr("Enter URL:"), QLineEdit::Normal,
2210 bo->getURL(), &ok, this );
2213 // user entered something and pressed OK
2214 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")");
2221 void MapEditor::editHeading2URL()
2223 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2224 typeid(*selection) == typeid(MapCenterObj)) )
2226 BranchObj *bo=(BranchObj*)selection;
2227 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")");
2228 bo->setURL (bo->getHeading());
2233 void MapEditor::editBugzilla2URL()
2235 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2236 typeid(*selection) == typeid(MapCenterObj)) )
2238 BranchObj *bo=(BranchObj*)selection;
2239 QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading();
2240 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2246 void MapEditor::editFATE2URL()
2248 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2249 typeid(*selection) == typeid(MapCenterObj)) )
2251 BranchObj *bo=(BranchObj*)selection;
2252 QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading();
2253 saveState("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")");
2259 void MapEditor::editVymLink()
2261 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2262 typeid(*selection) == typeid(MapCenterObj)) )
2264 BranchObj *bo=(BranchObj*)selection;
2265 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Link to another map"));
2266 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2267 fd->setCaption(__VYM " - " +tr("Link to another map"));
2268 if (! bo->getVymLink().isEmpty() )
2269 fd->setSelection( bo->getVymLink() );
2273 if ( fd->exec() == QDialog::Accepted )
2275 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")");
2276 bo->setVymLink (fd->selectedFile() );
2278 mapCenter->reposition();
2285 void MapEditor::deleteVymLink()
2287 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2288 typeid(*selection) == typeid(MapCenterObj)) )
2290 BranchObj *bo=(BranchObj*)selection;
2291 saveState("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")");
2292 bo->setVymLink ("" );
2294 mapCenter->reposition();
2300 void MapEditor::toggleHideExport()
2302 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2303 typeid(*selection) == typeid(MapCenterObj)) //||
2304 // (typeid(*selection)==typeid(FloatImageObj))
2307 saveState(); //TODO undoCommand
2308 BranchObj *bo=(BranchObj*)selection;
2309 bo->setHideInExport(actionEditToggleHideExport->isOn());
2311 mapCenter->reposition();
2317 QString MapEditor::getVymLink()
2319 if (selection && (typeid(*selection) == typeid(BranchObj) ||
2320 typeid(*selection) == typeid(MapCenterObj)) )
2322 return ((BranchObj*)selection)->getVymLink();
2328 void MapEditor::removeBranchHere()
2330 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2332 BranchObj* bo=(BranchObj*)selection;
2333 BranchObj* par=(BranchObj*)(bo->getParObj());
2334 if (bo->getDepth()==1)
2337 saveState(selection->getParObj()); // TODO undoCommand
2338 QString sel=selection->getSelectString();
2340 par->removeBranchHere(bo);
2341 mapCenter->reposition();
2346 void MapEditor::removeChilds()
2348 if (selection && (typeid(*selection) == typeid(BranchObj) ))
2350 saveState(selection->getParObj());
2351 ((BranchObj*)selection)->removeChilds();
2352 mapCenter->reposition();
2356 void MapEditor::editMapInfo()
2358 ExtraInfoDialog dia;
2359 dia.setMapName (getFileName() );
2360 dia.setAuthor (mapCenter->getAuthor() );
2361 dia.setComment(mapCenter->getComment() );
2366 QCanvasItemList l=canvas()->allItems();
2367 for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
2369 stats+=QString ("%1 items on canvas\n").arg (i,6);
2376 bo=mapCenter->first();
2379 if (!bo->getNote().isEmpty() ) n++;
2380 f+= bo->countFloatImages();
2382 xl+=bo->countXLinks();
2385 stats+=QString ("%1 branches\n").arg (b-1,6);
2386 stats+=QString ("%1 xLinks \n").arg (xl,6);
2387 stats+=QString ("%1 notes\n").arg (n,6);
2388 stats+=QString ("%1 images\n").arg (f,6);
2389 dia.setStats (stats);
2391 // Finally show dialog
2392 if (dia.exec() == QDialog::Accepted)
2394 saveState(); //TODO undoCommand
2395 mapCenter->setAuthor (dia.getAuthor() );
2396 mapCenter->setComment (dia.getComment() );
2400 void MapEditor::updateActions()
2403 if (getLinkColorHint()==HeadingColor)
2404 actionFormatLinkColorHint->setOn(true);
2406 actionFormatLinkColorHint->setOn(false);
2411 actionFormatLinkStyleLine->setOn(true);
2414 actionFormatLinkStyleParabel->setOn(true);
2417 actionFormatLinkStylePolyLine->setOn(true);
2419 case StylePolyParabel:
2420 actionFormatLinkStylePolyParabel->setOn(true);
2426 QPixmap pix( 16, 16 );
2427 pix.fill( mapCanvas->backgroundColor() );
2428 actionFormatBackColor->setIconSet( pix );
2429 pix.fill( defLinkColor );
2430 actionFormatLinkColor->setIconSet( pix );
2432 actionEditUndo->setEnabled( mapChanged );
2433 actionFileSave->setEnabled( mapUnsaved );
2437 if ( (typeid(*selection) == typeid(BranchObj)) ||
2438 (typeid(*selection) == typeid(MapCenterObj)) )
2440 BranchObj *bo=(BranchObj*)selection;
2441 // Take care of links
2442 if (bo->countXLinks()==0)
2444 branchLinksContextMenu->clear();
2445 branchLinksContextMenu->insertItem ("No xLink available");
2446 branchLinksContextMenuDup->clear();
2447 branchLinksContextMenuDup->insertItem ("No xLink available");
2453 branchLinksContextMenu->clear();
2454 branchLinksContextMenuDup->clear();
2455 for (int i=0; i<=bo->countXLinks();i++)
2457 bot=bo->XLinkTargetAt(i);
2460 s=bot->getHeading();
2463 branchLinksContextMenu->insertItem (s);
2464 branchLinksContextMenuDup->insertItem (s);
2469 standardFlagsDefault->setEnabled (true);
2471 if ( bo->getURL().isEmpty() )
2472 actionEditOpenURL->setEnabled (false);
2474 actionEditOpenURL->setEnabled (true);
2476 if ( bo->getVymLink().isEmpty() )
2478 actionEditOpenVymLink->setEnabled (false);
2479 actionEditDeleteVymLink->setEnabled (false);
2482 actionEditOpenVymLink->setEnabled (true);
2483 actionEditDeleteVymLink->setEnabled (true);
2485 actionEditToggleHideExport->setEnabled (true);
2486 actionEditToggleHideExport->setOn (bo->hideInExport() );
2488 actionEditCopy->setEnabled (true);
2489 actionEditCut->setEnabled (true);
2490 if (!clipboardEmpty)
2491 actionEditPaste->setEnabled (true);
2493 actionEditPaste->setEnabled (false);
2494 for (a=actionListBranches.first();a;a=actionListBranches.next())
2495 a->setEnabled(true);
2496 actionEditDelete->setEnabled (true);
2497 actionEditToggleFloatExport->setEnabled (false);
2498 switch (selection->getFrameType())
2501 actionFormatFrameNone->setOn(true);
2504 actionFormatFrameRectangle->setOn(true);
2509 actionFormatIncludeImagesVer->setOn
2510 ( ((BranchObj*)selection)->getIncludeImagesVer());
2511 actionFormatIncludeImagesHor->setOn
2512 ( ((BranchObj*)selection)->getIncludeImagesHor());
2513 actionFormatHideLinkUnselected->setOn
2514 (selection->getHideLinkUnselected());
2516 if ( (typeid(*selection) == typeid(FloatImageObj)) )
2518 standardFlagsDefault->setEnabled (false);
2520 actionEditOpenURL->setEnabled (false);
2521 actionEditOpenVymLink->setEnabled (false);
2522 actionEditDeleteVymLink->setEnabled (false);
2523 actionEditToggleHideExport->setEnabled (false);
2525 actionEditCopy->setEnabled (true);
2526 actionEditCut->setEnabled (true);
2527 actionEditPaste->setEnabled (false);
2528 for (a=actionListBranches.first();a;a=actionListBranches.next())
2529 a->setEnabled(false);
2530 actionEditDelete->setEnabled (true);
2531 actionEditToggleFloatExport->setOn
2532 ( ((FloatImageObj*)selection)->getFloatExport() );
2533 actionFormatHideLinkUnselected->setOn
2534 ( selection->getHideLinkUnselected());
2539 standardFlagsDefault->setEnabled (false);
2541 actionEditCopy->setEnabled (false);
2542 actionEditCut->setEnabled (false);
2543 actionEditPaste->setEnabled (false);
2544 for (a=actionListBranches.first();a;a=actionListBranches.next())
2545 a->setEnabled(false);
2547 actionEditOpenURL->setEnabled (false);
2548 actionEditOpenVymLink->setEnabled (false);
2549 actionEditDeleteVymLink->setEnabled (false);
2550 actionEditHeading2URL->setEnabled (false);
2551 actionEditDelete->setEnabled (false);
2552 actionEditToggleFloatExport->setEnabled (false);
2556 void MapEditor::updateNoteFlag()
2559 if ( (typeid(*selection) == typeid(BranchObj)) ||
2560 (typeid(*selection) == typeid(MapCenterObj)) )
2561 ((BranchObj*)selection)->updateNoteFlag();
2564 void MapEditor::setLinkStyle (LinkStyle ls)
2568 saveState(); // TODO undoCommand
2570 bo=mapCenter->first();
2574 bo->setLinkStyle(bo->getDefLinkStyle());
2577 mapCenter->reposition();
2580 LinkStyle MapEditor::getLinkStyle ()
2585 void MapEditor::setLinkColor(QColor c)
2591 void MapEditor::setLinkColorHint()
2593 // called from setLinkColorHint(lch) or at end of parse
2595 bo=mapCenter->first();
2603 void MapEditor::setLinkColorHint(LinkColorHint lch)
2609 void MapEditor::toggleLinkColorHint()
2611 if (linkcolorhint==HeadingColor)
2612 linkcolorhint=DefaultColor;
2614 linkcolorhint=HeadingColor;
2616 bo=mapCenter->first();
2624 LinkColorHint MapEditor::getLinkColorHint()
2626 return linkcolorhint;
2629 QColor MapEditor::getDefLinkColor()
2631 return defLinkColor;
2634 void MapEditor::setDefXLinkColor(QColor col)
2639 QColor MapEditor::getDefXLinkColor()
2641 return defXLinkColor;
2644 void MapEditor::setDefXLinkWidth (int w)
2649 int MapEditor::getDefXLinkWidth()
2651 return defXLinkWidth;
2654 void MapEditor::selectLinkColor()
2656 // Finish open lineEdits
2657 if (lineedit) finishedLineEditNoSave();
2659 QColor col = QColorDialog::getColor( defLinkColor, this );
2660 if ( !col.isValid() ) return;
2661 setLinkColor( col );
2662 saveState(); //TODO undoCommand
2666 void MapEditor::toggleScroll()
2668 if (selection && (typeid(*selection) == typeid(BranchObj)) )
2670 BranchObj *bo=((BranchObj*)selection);
2671 if (bo->countBranches()==0) return;
2672 if (bo->getDepth()==0) return;
2673 saveState(selection);
2680 void MapEditor::unScrollAll()
2683 bo=mapCenter->first();
2686 if (bo->isScrolled()) bo->toggleScroll();
2691 void MapEditor::loadFloatImage ()
2694 (typeid(*selection) == typeid(BranchObj)) ||
2695 (typeid(*selection) == typeid(MapCenterObj)) )
2697 BranchObj *bo=((BranchObj*)selection);
2699 QFileDialog *fd=new QFileDialog( this);
2700 fd->setMode (QFileDialog::ExistingFiles);
2701 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2702 ImagePreview *p =new ImagePreview (fd);
2703 fd->setContentsPreviewEnabled( TRUE );
2704 fd->setContentsPreview( p, p );
2705 fd->setPreviewMode( QFileDialog::Contents );
2706 fd->setCaption(__VYM " - " +tr("Load image"));
2707 fd->setDir (lastImageDir);
2711 if ( fd->exec() == QDialog::Accepted )
2713 saveState(selection);
2714 lastImageDir=fn.left(fn.findRev ("/"));
2715 QStringList flist = fd->selectedFiles();
2716 QStringList::Iterator it = flist.begin();
2717 while( it != flist.end() )
2720 bo->addFloatImage();
2721 // TODO check if load was successful
2722 bo->getLastFloatImage()->load(*it);
2723 bo->getLastFloatImage()->setOriginalFilename(fn);
2727 mapCenter->reposition();
2736 void MapEditor::saveFloatImage (int item)
2739 (typeid(*selection) == typeid(FloatImageObj)) )
2741 FloatImageObj *fio=((FloatImageObj*)selection);
2742 const char* fmt = saveImageFormatMenu->text(item);
2744 QFileDialog *fd=new QFileDialog( this, tr("vym - save image as") + fmt);
2745 fd->addFilter ("PNG (*.png)");
2746 fd->addFilter ("BMP (*.bmp)");
2747 fd->addFilter ("XBM (*.xbm)");
2748 fd->addFilter ("JPG (*.jpg)");
2749 fd->addFilter ("XPM (*.xpm)");
2750 fd->addFilter ("GIF (*.gif)");
2751 fd->addFilter ("PNM (*.pnm)");
2752 fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
2753 fd->setCaption(__VYM " - " +tr("Save image as %1").arg(fmt));
2754 fd->setMode( QFileDialog::AnyFile );
2755 fd->setSelection (fio->getOriginalFilename());
2759 if ( fd->exec() == QDialog::Accepted )
2761 if (QFile (fd->selectedFile()).exists() )
2763 QMessageBox mb( __VYM,
2764 tr("The file %1 exists already.\n"
2765 "Do you want to overwrite it?").arg(fd->selectedFile()),
2766 QMessageBox::Warning,
2767 QMessageBox::Yes | QMessageBox::Default,
2768 QMessageBox::Cancel | QMessageBox::Escape,
2769 QMessageBox::QMessageBox::NoButton );
2771 mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
2772 mb.setButtonText( QMessageBox::No, tr("Cancel"));
2775 case QMessageBox::Yes:
2778 case QMessageBox::Cancel:
2784 fio->save (fd->selectedFile(),fmt);
2789 void MapEditor::toggleFloatExport()
2792 (typeid(*selection) == typeid(FloatImageObj))||
2793 (typeid(*selection) == typeid(FloatObj)) )
2795 FloatImageObj *fio=((FloatImageObj*)selection);
2796 fio->setFloatExport (actionEditToggleFloatExport->isOn() );
2800 void MapEditor::setFrame(const FrameType &t)
2803 (typeid(*selection) == typeid(BranchObj)) ||
2804 (typeid(*selection) == typeid(MapCenterObj)) )
2806 selection->setFrameType (t);
2807 mapCenter->reposition();
2808 selection->updateLink();
2812 void MapEditor::setIncludeImagesVer(bool b)
2815 (typeid(*selection) == typeid(BranchObj)) ||
2816 (typeid(*selection) == typeid(MapCenterObj)) )
2817 ((BranchObj*)selection)->setIncludeImagesVer(b);
2818 mapCenter->reposition();
2821 void MapEditor::setIncludeImagesHor(bool b)
2824 (typeid(*selection) == typeid(BranchObj)) ||
2825 (typeid(*selection) == typeid(MapCenterObj)) )
2826 ((BranchObj*)selection)->setIncludeImagesHor(b);
2827 mapCenter->reposition();
2830 void MapEditor::setHideLinkUnselected (bool b)
2833 (typeid(*selection) == typeid(BranchObj)) ||
2834 (typeid(*selection) == typeid(MapCenterObj)) ||
2835 (typeid(*selection) == typeid(FloatImageObj)) )
2836 selection->setHideLinkUnselected(b);
2839 void MapEditor::importDir(BranchObj *dst, QDir d)
2842 (typeid(*selection) == typeid(BranchObj)) ||
2843 (typeid(*selection) == typeid(MapCenterObj)) )
2847 // Traverse directories
2848 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
2849 const QFileInfoList *dirlist = d.entryInfoList();
2850 QFileInfoListIterator itdir( *dirlist );
2853 while ( (fi = itdir.current()) != 0 )
2855 if (fi->fileName() != "." && fi->fileName() != ".." )
2858 bo=dst->getLastBranch();
2859 bo->setHeading (fi->fileName() );
2860 bo->setColor (QColor("blue"));
2862 if ( !d.cd(fi->fileName()) )
2863 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi->fileName()));
2866 // Recursively add subdirs
2874 d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
2875 const QFileInfoList *filelist = d.entryInfoList();
2876 QFileInfoListIterator itfile( *filelist );
2878 while ( (fi = itfile.current()) != 0 )
2881 bo=dst->getLastBranch();
2882 bo->setHeading (fi->fileName() );
2883 bo->setColor (QColor("black"));
2884 if (fi->fileName().right(4) == ".vym" )
2885 bo->setVymLink (fi->filePath());
2892 void MapEditor::importDir()
2895 (typeid(*selection) == typeid(BranchObj)) ||
2896 (typeid(*selection) == typeid(MapCenterObj)) )
2898 QFileDialog *fd=new QFileDialog( this,__VYM " - " +tr("Choose directory structure to import"));
2899 fd->setMode (QFileDialog::DirectoryOnly);
2900 fd->addFilter (QString (tr("vym map") + " (*.vym)"));
2901 fd->setCaption(__VYM " - " +tr("Choose directory structure to import"));
2905 if ( fd->exec() == QDialog::Accepted )
2907 BranchObj *bo=((BranchObj*)selection);
2908 importDir (bo,QDir(fd->selectedFile()) );
2909 mapCenter->reposition();
2916 void MapEditor::followXLink(int i)
2919 (typeid(*selection) == typeid(BranchObj)) ||
2920 (typeid(*selection) == typeid(MapCenterObj)) )
2922 BranchObj *bo=((BranchObj*)selection)->XLinkTargetAt(i);
2925 selection->unselect();
2927 selection->select();
2928 ensureSelectionVisible();
2933 void MapEditor::editXLink(int i)
2936 (typeid(*selection) == typeid(BranchObj)) ||
2937 (typeid(*selection) == typeid(MapCenterObj)) )
2939 XLinkObj *xlo=((BranchObj*)selection)->XLinkAt(i);
2942 EditXLinkDialog dia;
2944 dia.setSelection(selection);
2945 if (dia.exec() == QDialog::Accepted)
2947 if (dia.useSettingsGlobal() )
2949 setDefXLinkColor (xlo->getColor() );
2950 setDefXLinkWidth (xlo->getWidth() );
2952 if (dia.deleteXLink())
2953 ((BranchObj*)selection)->deleteXLinkAt(i);
2954 saveState(); //TODO undoCommand
2960 void MapEditor::testFunction()
2962 cout << "MapEditor::testFunction() called\n";
2966 if (selection && (typeid(*selection) == typeid(BranchObj)))
2968 cout << "Note:\n"<<((BranchObj*)selection)->getNoteOpenDoc()<<endl;
2973 void MapEditor::ensureSelectionVisible()
2977 LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
2979 if (selection->getOrientation() == OrientLeftOfCenter)
2980 p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
2982 p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
2983 ensureVisible (p.x(), p.y() );
2988 void MapEditor::updateViewCenter()
2990 // Update movingCenter, so that we can zoom comfortably later
2991 QRect rc = QRect( contentsX(), contentsY(),
2992 visibleWidth(), visibleHeight() );
2993 QRect canvasRect = inverseWorldMatrix().mapRect(rc);
2994 movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
2995 movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
2998 void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
3000 // Lineedits are already closed by preceding
3001 // mouseEvent, we don't need to close here.
3003 QPoint p = inverseWorldMatrix().map(e->pos());
3004 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3007 { // MapObj was found
3008 if (selection != lmo)
3010 // select the MapObj
3011 if (selection) selection->unselect();
3013 selection->select();
3019 if (typeid(*selection)==typeid(BranchObj) ||
3020 typeid(*selection)==typeid(MapCenterObj) )
3022 // Context Menu on branch or mapcenter
3024 branchContextMenu->popup(e->globalPos() );
3026 if (typeid(*selection)==typeid(FloatImageObj))
3028 // Context Menu on floatimage
3030 floatimageContextMenu->popup(e->globalPos() );
3034 { // No MapObj found, we are on the Canvas itself
3035 // Context Menu on Canvas
3037 canvasContextMenu->popup(e->globalPos() );
3041 void MapEditor::contentsMousePressEvent(QMouseEvent* e)
3043 // Finish open lineEdits
3044 if (lineedit) finishedLineEditNoSave();
3046 QPoint p = inverseWorldMatrix().map(e->pos());
3047 LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
3049 // Special case: CTRL is pressed
3050 if (e->state() & QMouseEvent::ControlButton)
3052 if (actionModModeColor->isOn())
3054 if (e->state() & QMouseEvent::ControlButton)
3057 setCursor (pickColorCursor);
3061 if (actionModModeLink->isOn())
3063 BranchObj *bo_begin=NULL;
3065 bo_begin=(BranchObj*)(lmo);
3068 ((typeid(*selection) == typeid(BranchObj)) ||
3069 (typeid(*selection) == typeid(MapCenterObj))) )
3070 bo_begin=(BranchObj*)selection;
3074 linkingObj_src=bo_begin;
3075 tmpXLink=new XLinkObj (mapCanvas);
3076 tmpXLink->setBegin (bo_begin);
3077 tmpXLink->setEnd (p);
3078 tmpXLink->setColor(defXLinkColor);
3079 tmpXLink->setWidth(defXLinkWidth);
3080 tmpXLink->updateXLink();
3081 tmpXLink->setVisibility (true);
3088 { // MapObj was found
3089 if (selection != lmo)
3091 // select the MapObj
3092 if (selection) selection->unselect();
3094 selection->select();
3099 // Check, if systemFlag clicked
3100 if (typeid(*selection)==typeid(BranchObj) ||
3101 typeid(*selection)==typeid(MapCenterObj) )
3103 QString foname=((BranchObj*)selection)->getSystemFlagName(p);
3104 if (!foname.isEmpty())
3106 // Do not move, if systemFlag clicked
3110 if (foname=="vymLink")
3112 mainWindow->editOpenVymLink();
3113 // tabWidget may change, better return now
3114 // before segfaulting...
3118 mainWindow->windowToggleNoteEditor();
3120 if (foname=="hideInExport") toggleHideExport();
3124 // Left Button Move Branches
3125 if (e->button() == QMouseEvent::LeftButton )
3127 movingObj_start.setX( p.x() - selection->x() );
3128 movingObj_start.setY( p.y() - selection->y() );
3129 movingObj_orgPos.setX (lmo->x() );
3130 movingObj_orgPos.setY (lmo->y() );
3132 // If modMode==copy, then we want to "move" the _new_ object around
3133 // then we need the offset from p to the _old_ selection, because of tmp
3134 if (actionModModeCopy->isOn() &&
3135 e->state() & QMouseEvent::ControlButton)
3137 if (typeid(*selection)==typeid(BranchObj) )
3140 mapCenter->addBranch ((BranchObj*)selection);
3142 selection=mapCenter->getLastBranch();
3143 selection->select();
3144 mapCenter->reposition();
3147 movingObj=selection;
3149 // Middle Button Toggle Scroll
3150 // (On Mac OS X this won't work, but we still have
3151 // a button in the toolbar)
3152 if (e->button() == QMouseEvent::MidButton )
3156 { // No MapObj found, we are on the Canvas itself
3157 // Left Button move Pos of CanvasView
3158 if (e->button() == QMouseEvent::LeftButton )
3160 movingObj=NULL; // move Content not Obj
3161 movingObj_start=e->globalPos();
3162 movingCont_start=QPoint (contentsX(), contentsY() );
3163 movingVec=QPoint(0,0);
3164 setCursor(handOpenCursor);
3169 void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
3171 QPoint p = inverseWorldMatrix().map(e->pos());
3173 // Move the selected MapObj
3174 if ( selection && movingObj)
3176 // To avoid jumping of the CanvasView, only
3177 // ensureSelectionVisible, if not tmp linked
3178 if (!selection->hasParObjTmp())
3179 ensureSelectionVisible ();
3181 // Now move the selection, but add relative position
3182 // (movingObj_start) where selection was chosen with
3183 // mousepointer. (This avoids flickering resp. jumping
3184 // of selection back to absPos)
3186 LinkableMapObj *lmosel;
3187 lmosel = dynamic_cast <LinkableMapObj*> (selection);
3189 // Check if we could link
3190 LinkableMapObj* lmo=mapCenter->findMapObj(p, lmosel);
3193 if (typeid(*selection) == typeid(FloatImageObj))
3195 FloatObj *fo=(FloatObj*)selection;
3196 saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
3197 fo->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3201 // Relink float to new mapcenter or branch, if shift is pressed
3202 // Only relink, if selection really has a new parent
3203 if ( (e->state() & QMouseEvent::ShiftButton) && lmo &&
3204 ( (typeid(*lmo)==typeid(BranchObj)) ||
3205 (typeid(*lmo)==typeid(MapCenterObj)) ) &&
3206 ( lmo != fo->getParObj())
3209 if (typeid(*fo) == typeid(FloatImageObj))
3212 FloatImageObj *fio=(FloatImageObj*)(fo);
3213 ((BranchObj*)(lmo))->addFloatImage (fio);
3215 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
3216 fio=((BranchObj*)(lmo))->getLastFloatImage();
3219 selection=(LinkableMapObj*)(fio);
3220 selection->select();
3221 movingObj=(MapObj*)(fio);
3224 } else // selection != a FloatObj
3226 if (lmosel->getDepth()==0)
3228 if (e->state() == (LeftButton | !ShiftButton))
3229 // If mapCenter is moved, move all the rest by default, too.
3230 mapCenter->moveAll(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3232 mapCenter->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3235 if (lmosel->getDepth()==1)
3237 // depth==1, mainbranch
3238 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
3242 if (lmosel->getOrientation() == OrientLeftOfCenter)
3243 // Add width of bbox here, otherwise alignRelTo will cause jumping around
3244 lmosel->move(p.x() -movingObj_start.x()+lmosel->getBBox().width(),
3245 p.y()-movingObj_start.y() +lmosel->getTopPad() );
3247 lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() -lmosel->getTopPad());
3249 // reposition subbranch
3250 lmosel->reposition();
3251 //ensureSelectionVisible();
3253 if (lmo && (lmo!=selection) &&
3254 (typeid(*lmo) == typeid(BranchObj) ||
3255 (typeid(*lmo) == typeid(MapCenterObj) )
3258 if (e->state() & QMouseEvent::ControlButton)
3260 // Special case: CTRL to link below lmo
3261 lmosel->setParObjTmp (lmo,p,+1);
3263 else if (e->state() & QMouseEvent::ShiftButton)
3264 lmosel->setParObjTmp (lmo,p,-1);
3266 lmosel->setParObjTmp (lmo,p,0);
3269 lmosel->unsetParObjTmp();
3270 /* FIXME not needed anymore?
3271 if (lmo &&(lmo==selection))
3272 // Could link to myself (happens sometimes...)
3273 lmosel->unsetParObjTmp();
3275 // no Obj under selection, go back to original Parent
3276 lmosel->unsetParObjTmp();
3281 } // no FloatImageObj
3285 } // selection && moving_obj
3287 // Draw a link from one branch to another
3290 tmpXLink->setEnd (p);
3291 tmpXLink->updateXLink();
3295 if (!movingObj && !pickingColor &&!drawingLink)
3297 QPoint p=e->globalPos();
3298 movingVec.setX(-p.x() + movingObj_start.x() );
3299 movingVec.setY(-p.y() + movingObj_start.y() );
3300 setContentsPos( movingCont_start.x() + movingVec.x(),
3301 movingCont_start.y() + movingVec.y());
3308 void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
3310 LinkableMapObj *dst;
3311 // Have we been picking color?
3315 setCursor (ArrowCursor);
3316 // Check if we are over another branch
3317 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3318 if (dst && selection)
3320 if (e->state() & QMouseEvent::ShiftButton)
3322 ((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
3323 ((BranchObj*)selection)->setLinkColor ();
3327 ((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
3328 ((BranchObj*)selection)->setLinkColor ();
3334 // Have we been drawing a link?
3338 // Check if we are over another branch
3339 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
3340 if (dst && selection)
3342 tmpXLink->setEnd ( ((BranchObj*)(dst)) );
3343 tmpXLink->updateXLink();
3344 tmpXLink->activate();
3345 saveState(); //TODO undoCommand
3354 // Have we been moving something?
3355 if ( selection && movingObj )
3357 // Moved FloatObj? Maybe we need to reposition
3358 if(typeid(*selection)==typeid (FloatImageObj))
3360 selection->getParObj()->requestReposition();
3361 mapCenter->reposition();
3364 // Check if we are over another branch, but ignore
3365 // any found LMOs, which are FloatObjs
3366 dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ),
3367 ((LinkableMapObj*)selection) );
3370 (typeid(*dst)!=typeid(BranchObj)&&typeid(*dst)!=typeid(MapCenterObj)))
3373 // Now check, if we have been moving a branch
3374 if (typeid(*selection) == typeid(BranchObj) )
3376 // save the position in case we link to mapcenter
3377 QPoint savePos=QPoint (selection->x(),selection->y() );
3379 // Reset the temporary drawn link to the original one
3380 ((LinkableMapObj*)selection)->unsetParObjTmp();
3386 BranchObj* bs=((BranchObj*)selection);
3387 QString undoCom="linkBranchToPos (\""+
3388 (bs->getParObj())->getSelectString()+
3390 QString("%1").arg(bs->getNum())+
3392 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
3394 // TODO we also could check, if dest and src are on same branch,
3395 // then it would be sufficient to saveState of this branch
3397 // Modifiers allow to insert above/below dst
3398 if (e->state() & QMouseEvent::ShiftButton)
3400 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
3402 if (e->state() & QMouseEvent::ControlButton)
3404 bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
3407 bs->moveBranchTo ((BranchObj*)(dst),-1);
3408 if (dst->getDepth()==0)
3411 saveState (undoCom,bs->getSelectString() );
3413 if (selection->getDepth()==1)
3414 // If we have moved mainbranch only save endposition
3415 saveState("move "+qpointToString(movingObj_orgPos), selection->getSelectString() );
3417 // Draw the original link, before selection was moved around
3418 mapCenter->reposition();
3420 // Finally resize canvas, if needed
3425 // maybe we moved View: set old cursor
3426 setCursor (ArrowCursor);
3430 void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
3432 // Finish open lineEdits
3433 if (lineedit) finishedLineEditNoSave();
3435 if (e->button() == QMouseEvent::LeftButton )
3437 QPoint p = inverseWorldMatrix().map(e->pos());
3438 LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
3439 if (lmo) { // MapObj was found
3440 // First select the MapObj than edit heading
3441 if (selection) selection->unselect();
3443 selection->select();
3444 saveState(selection);
3450 void MapEditor::resizeEvent (QResizeEvent* e)
3452 QCanvasView::resizeEvent( e );
3456 void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event)
3459 // for (unsigned int i=0;event->format(i);i++) // Debug mime type
3460 // cerr << event->format(i) << endl;
3463 (typeid(*selection) == typeid(BranchObj)) ||
3464 (typeid(*selection) == typeid(MapCenterObj))) {
3466 // If QImageDrag can decode mime type
3467 if (QImageDrag::canDecode(event)) {
3472 // If image are dragged from firefox
3473 if (event->provides("application/x-moz-file-promise-url") &&
3474 event->provides("application/x-moz-nativeimage")) {
3475 event->accept(true);
3479 // If QUriDrag can decode mime type
3480 if (QUriDrag::canDecode(event)) {
3485 // If Uri are dragged from firefox
3486 if (event->provides("_NETSCAPE_URL")){
3491 // If QTextDrag can decode mime type
3492 if (QTextDrag::canDecode(event)) {
3501 bool isUnicode16(const QByteArray &d)
3503 // TODO: make more precise check for unicode 16.
3504 // Guess unicode16 if any of second bytes are zero
3505 unsigned int length = max(0,d.size()-2)/2;
3506 for (unsigned int i = 0; i<length ; i++)
3507 if (d.at(i*2+1)==0) return true;
3511 void MapEditor::contentsDropEvent(QDropEvent *event)
3514 (typeid(*selection) == typeid(BranchObj)) ||
3515 (typeid(*selection) == typeid(MapCenterObj)))
3520 if (event->provides("image/png"))
3523 if (QImageDrag::decode(event, pix))
3531 } else if (event->provides("application/x-moz-file-promise-url") &&
3532 event->provides("application/x-moz-nativeimage"))
3534 // Contains url to the img src in unicode16
3535 QByteArray d = event->encodedData("application/x-moz-file-promise-url");
3536 QString url = QString((const QChar*)d.data(),d.size()/2);
3540 } else if (event->provides ("text/uri-list"))
3541 { // Uris provided e.g. by konqueror
3542 QUriDrag::decode (event,uris);
3543 } else if (event->provides ("_NETSCAPE_URL"))
3544 { // Uris provided by Mozilla
3545 QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
3548 } else if (event->provides("text/html")) {
3550 // Handels text mime types
3551 // Look like firefox allways handle text as unicode16 (2 bytes per char.)
3552 QByteArray d = event->encodedData("text/html");
3555 text = QString((const QChar*)d.data(),d.size()/2);
3559 textEditor->setText(text);
3563 } else if (event->provides("text/plain")) {
3564 QByteArray d = event->encodedData("text/plain");
3567 text = QString((const QChar*)d.data(),d.size()/2);
3571 textEditor->setText(text);
3583 for (const char* u=uris.first(); u; u=uris.next())
3585 bo=((BranchObj*)selection)->addBranch();
3588 s=QUriDrag::uriToLocalFile(u);
3590 QString file = QDir::convertSeparators(s);
3591 heading = QFileInfo(file).baseName();
3593 if (file.endsWith(".vym", false))
3594 bo->setVymLink(file);
3603 bo->setHeading(heading);
3613 saveState(); //TODO undo Command
3614 mapCenter->reposition();
3621 void MapEditor::addFloatImage(const QPixmap &img)
3624 (typeid(*selection) == typeid(BranchObj)) ||
3625 (typeid(*selection) == typeid(MapCenterObj)) )
3627 BranchObj *bo=((BranchObj*)selection);
3628 saveState(selection);
3629 //QString fn=fd->selectedFile();
3630 //lastImageDir=fn.left(fn.findRev ("/"));
3631 bo->addFloatImage();
3632 // FIXME check if load was successful
3633 bo->getLastFloatImage()->load(img);
3634 //bo->getLastFloatImage()->setOriginalFilename(fn);
3635 mapCenter->reposition();
3642 void MapEditor::imageDataFetched(const QByteArray &a, QNetworkOperation */*nop*/)
3644 if (!imageBuffer) imageBuffer = new QBuffer();
3645 if (!imageBuffer->isOpen()) {
3646 imageBuffer->open(IO_WriteOnly | IO_Append);
3648 imageBuffer->at(imageBuffer->at()+imageBuffer->writeBlock(a));
3652 void MapEditor::imageDataFinished(QNetworkOperation *nop)
3654 if (nop->state()==QNetworkProtocol::StDone) {
3655 QPixmap img(imageBuffer->buffer());
3660 imageBuffer->close();
3662 imageBuffer->close();
3669 void MapEditor::fetchImage(const QString &url)
3672 urlOperator->stop();
3673 disconnect(urlOperator);
3677 urlOperator = new QUrlOperator(url);
3678 connect(urlOperator, SIGNAL(finished(QNetworkOperation *)),
3679 this, SLOT(imageDataFinished(QNetworkOperation*)));
3681 connect(urlOperator, SIGNAL(data(const QByteArray &, QNetworkOperation *)),
3682 this, SLOT(imageDataFetched(const QByteArray &, QNetworkOperation *)));